diff --git a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs new file mode 100644 index 0000000000000000000000000000000000000000..d2b6004d6deebebf7460b17bee54f4ad393439f5 --- /dev/null +++ b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs @@ -0,0 +1,117 @@ +// +// ARF - Augmented Reality Framework (ETSI ISG ARF) +// +// Copyright 2024 ETSI +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Last change: June 2024 +// + +#define isDEBUG + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +using UnityEngine; +using UnityEditor; +using TMPro; + +using ETSI.ARF.WorldStorage.REST; +using ETSI.ARF.OpenAPI.WorldStorage; + +namespace ETSI.ARF.WorldStorage.UI +{ + public abstract class BaseWindow<T> : EditorWindow + { + [HideInInspector] public WorldStorageServer worldStorageServer; + [HideInInspector] public WorldStorageUser worldStorageUser; + + [SerializeField] public List<string> trackables = new List<string>(); + + // + // Keyvalues + // + [SerializeField] protected KeyvalueTagList keyValueTags = new KeyvalueTagList(); + protected List<(string, string)> keyValuesFixed = new List<(string, string)>(3) + { + ("", ""),("", ""),("", "") + }; + protected void OutputKeyValue(int n) + { + string i1 = keyValuesFixed[n].Item1; + string i2 = keyValuesFixed[n].Item2; + i1 = EditorGUILayout.TextField("Key " + n, i1); + i2 = EditorGUILayout.TextField("Value " + n, i2); + keyValuesFixed[n] = (i1, i2); + } + + // + // UI stuffs + // + protected bool groupEnabled; + protected bool repaint = false; + protected Vector2 scrollPos; + protected Color ori; + protected GUIStyle gsTest; + + public void Update() + { + if (repaint) + { + Repaint(); + repaint = false; + } + } + + void OnGUI() + { + ori = GUI.backgroundColor; // remember ori color + + gsTest = new GUIStyle("window"); + //gsTest.normal.textColor = WorldStorageWindow.arfColors[0]; + gsTest.fontStyle = FontStyle.Bold; + gsTest.alignment = TextAnchor.UpperLeft; + gsTest.fontSize = 16; + + scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true)); + WorldStorageWindow.DrawCopyright(); + + DrawUIStuffs(); + + EditorGUILayout.EndScrollView(); + + if (GUILayout.Button("Close Window")) + { + Close(); + } + } + + public abstract void DrawUIStuffs(); + + public virtual void GetParams() + { + } + + public virtual void AddObject() + { + } + + public virtual T GenerateObject() + { + return default(T); + } + } +} \ No newline at end of file diff --git a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs.meta b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..eed84fadb615b82bec15c5f19ee92935b2d96a72 --- /dev/null +++ b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: b879c85f4eccbee40a78e1a01aaf77ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - m_ViewDataDictionary: {instanceID: 0} + - worldStorageServer: {fileID: 11400000, guid: 4f997253243de534dad12937f1284975, type: 2} + - worldStorageUser: {instanceID: 0} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/TrackableWindow.cs b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/TrackableWindow.cs index 2d225394d97b4bab2890232657d512ad955cabb7..889700734cf428dc9978676194ccd26238a1a19a 100644 --- a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/TrackableWindow.cs +++ b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/TrackableWindow.cs @@ -34,21 +34,15 @@ using ETSI.ARF.OpenAPI.WorldStorage; namespace ETSI.ARF.WorldStorage.UI { - public class TrackableWindow : EditorWindow + public class TrackableWindow : BaseWindow<Trackable> { static public TrackableWindow winSingleton; - [HideInInspector] public WorldStorageServer worldStorageServer; - [HideInInspector] public WorldStorageUser worldStorageUser; - - [SerializeField] public List<string> trackables = new List<string>(); - - bool groupEnabled; - // Trackable params string UUID = System.Guid.Empty.ToString(); string customName = "NotDefined"; string creatorUUID = System.Guid.Empty.ToString(); + double confidence = 0f; TrackableType type = TrackableType.OTHER; UnitSystem unit = UnitSystem.CM; Vector3 trackableSize; @@ -56,20 +50,16 @@ namespace ETSI.ARF.WorldStorage.UI Vector3 localCRS_rot; byte[] trackablePayload = new byte[1] { 0 }; - [SerializeField] KeyvalueTagList keyValueTags = new KeyvalueTagList(); - string key1 = ""; - string value1 = ""; - - // UI stuffs - private Vector2 scrollPos; - private Color ori; - private GUIStyle gsTest; - //graph params to generate the node public bool useCoord; public float nodePosX = 0; public float nodePosY = 0; + public TrackableWindow() + { + // init somne stuffs + } + public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "") { winSingleton = EditorWindow.GetWindow(typeof(TrackableWindow), false, "ETSI ARF - Trackable") as TrackableWindow; @@ -78,12 +68,12 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(UUID)) { winSingleton.UUID = UUID; - winSingleton.GetTrackableParams(); + winSingleton.GetParams(); } else { // Create new one - winSingleton.AddTrackable(); + winSingleton.AddObject(); } } @@ -108,11 +98,6 @@ namespace ETSI.ARF.WorldStorage.UI return visual; } - public TrackableWindow() - { - // init somne stuffs - } - void OnGUI() { ori = GUI.backgroundColor; // remember ori color @@ -126,7 +111,7 @@ namespace ETSI.ARF.WorldStorage.UI scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true)); WorldStorageWindow.DrawCopyright(); - DrawTrackableStuffs(); + DrawUIStuffs(); EditorGUILayout.EndScrollView(); @@ -136,7 +121,7 @@ namespace ETSI.ARF.WorldStorage.UI } } - void DrawTrackableStuffs()// Trackable trackable) + public override void DrawUIStuffs()// Trackable trackable) { GUILayout.BeginVertical(); // "Trackable Editor", gsTest); EditorGUILayout.Space(); @@ -157,11 +142,12 @@ namespace ETSI.ARF.WorldStorage.UI GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel); EditorGUILayout.Space(); - customName = EditorGUILayout.TextField("Name of Trackable:", customName); #if isDEBUG GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly + EditorGUILayout.Space(); #endif + customName = EditorGUILayout.TextField("Name of Trackable:", customName); EditorGUILayout.Space(); // --------------------- @@ -175,7 +161,7 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(UUID) && UUID != "0" && UUID != System.Guid.Empty.ToString()) { - Trackable obj = GenerateTrackable(); + Trackable obj = GenerateObject(); TrackableRequest.UpdateTrackableAsync(worldStorageServer, obj, (response) => { UUID = response.result; @@ -184,7 +170,7 @@ namespace ETSI.ARF.WorldStorage.UI if (WorldStorageWindow.WorldStorageWindowSingleton != null) { WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); + WorldStorageWindow.WorldStorageWindowSingleton.repaint = true; } Close(); }); @@ -194,21 +180,25 @@ namespace ETSI.ARF.WorldStorage.UI GUI.backgroundColor = WorldStorageWindow.arfColors[3]; if (GUILayout.Button("Delete")) { - Debug.Log("Delete Trackable"); - TrackableRequest.DeleteTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) => + if (EditorUtility.DisplayDialog("Delete", "Are you sure you want to delete this Trackable?", "Delete", "Cancel")) { - UUID = System.Guid.Empty.ToString(); - customName = "Warning: Object deleted !"; - creatorUUID = System.Guid.Empty.ToString(); - type = TrackableType.OTHER; - unit = UnitSystem.CM; - if (WorldStorageWindow.WorldStorageWindowSingleton != null) + Debug.Log("Delete Trackable"); + TrackableRequest.DeleteTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) => { - WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); - } - Close(); - }); + UUID = System.Guid.Empty.ToString(); + customName = "Warning: Object deleted !"; + creatorUUID = System.Guid.Empty.ToString(); + confidence = 0f; + type = TrackableType.OTHER; + unit = UnitSystem.CM; + if (WorldStorageWindow.WorldStorageWindowSingleton != null) + { + WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables(); + WorldStorageWindow.WorldStorageWindowSingleton.repaint = true; + } + Close(); + }); + } } GUI.backgroundColor = ori; @@ -226,6 +216,7 @@ namespace ETSI.ARF.WorldStorage.UI // --------------------- type = (TrackableType)EditorGUILayout.EnumPopup("Trackable Type:", type); unit = (UnitSystem)EditorGUILayout.EnumPopup("Unit System:", unit); + confidence = EditorGUILayout.DoubleField("Confidence:", confidence); EditorGUILayout.Space(); trackableSize = EditorGUILayout.Vector3Field("Trackable Size:", trackableSize); @@ -246,17 +237,26 @@ namespace ETSI.ARF.WorldStorage.UI } } + // --------------------- + // Keyvalues + // --------------------- EditorGUILayout.Space(); groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled); - key1 = EditorGUILayout.TextField("Key 1", key1); - value1 = EditorGUILayout.TextField("Value 1", value1); + if (keyValuesFixed.Count > 0) + { + OutputKeyValue(0); + OutputKeyValue(1); + OutputKeyValue(2); + } EditorGUILayout.EndToggleGroup(); // GUILayout.EndVertical(); } - private void GetTrackableParams() + public override void GetParams() { + customName = "Requesting information..."; + TrackableRequest.GetTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) => { Trackable obj = response.result; @@ -264,6 +264,7 @@ namespace ETSI.ARF.WorldStorage.UI creatorUUID = obj.CreatorUUID.ToString(); type = obj.TrackableType; unit = obj.Unit; + confidence = obj.Confidence; if (obj.TrackableSize.Count == 3) { trackableSize = new Vector3((float)obj.TrackableSize[0], (float)obj.TrackableSize[1], (float)obj.TrackableSize[2]); @@ -282,32 +283,44 @@ namespace ETSI.ARF.WorldStorage.UI localCRS_rot = Vector3.zero; } - // Read a key value (demo) - var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags); - key1 = first.Item1; - value1 = first.Item2; + // --------------------- + // Keyvalues + // --------------------- + //var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags); + //keyValuesFixed.Clear(); // no + for (int i = 0; i < keyValuesFixed.Count; i++) keyValuesFixed[i] = ("", ""); - this.Repaint(); + if (obj.KeyvalueTags.Count > 0) + { + int cnt = 0; + foreach (var item in obj.KeyvalueTags) + { + if (item.Key == "unityAuthoringPosX" || item.Key == "unityAuthoringPosY") continue; // ignore internal params + if (cnt < keyValuesFixed.Count) keyValuesFixed[cnt] = (item.Key, item.Value[0]); + cnt++; + } + } + repaint = true; }); } - public void AddTrackable() + public override void AddObject() { Debug.Log("POST Trackable"); UUID = System.Guid.Empty.ToString(); customName = "Default Trackable"; - Trackable obj = GenerateTrackable(); + Trackable obj = GenerateObject(); TrackableRequest.CreateTrackableAsync(worldStorageServer, obj, (response) => { UUID = response.result; UUID = UUID.Trim('"'); //Bugfix: remove " from server return value WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); + WorldStorageWindow.WorldStorageWindowSingleton.repaint = true; }); } - public Trackable GenerateTrackable() + public override Trackable GenerateObject() { EncodingInformationStructure trackableEncodingInformation = new EncodingInformationStructure() { @@ -327,9 +340,23 @@ namespace ETSI.ARF.WorldStorage.UI localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one); Transform3D _localCRS = WorldStorageUnityHelper.ConvertUnityToETSIARFTransform3D(localCRS); - // Create a key value (one from demo) + // Remember the position of the Unity graph node + var posX = new Collection<String>(); + posX.Add(nodePosX.ToString()); + var posY = new Collection<String>(); + posY.Add(nodePosY.ToString()); + + // --------------------- + // Keyvalues + // --------------------- keyValueTags.Clear(); - keyValueTags.Add(key1, new Collection<string> { value1 }); + keyValueTags.Add("unityAuthoringPosX", posX); + keyValueTags.Add("unityAuthoringPosY", posY); + if (keyValuesFixed.Count > 0) + foreach (var item in keyValuesFixed) + { + if (!string.IsNullOrEmpty(item.Item1)) keyValueTags.Add(item.Item1, new Collection<string> { item.Item2 }); + } System.Guid _uuid = System.Guid.Parse(UUID); System.Guid _creator = System.Guid.Parse(worldStorageUser.UUID); @@ -342,17 +369,10 @@ namespace ETSI.ARF.WorldStorage.UI TrackablePayload = trackablePayload, LocalCRS = _localCRS, Unit = unit, + Confidence = confidence, TrackableSize = _trackableSize, KeyvalueTags = keyValueTags }; - - var posX = new Collection<String>(); - posX.Add(nodePosX.ToString()); - t.KeyvalueTags["unityAuthoringPosX"] = posX; - var posY = new Collection<String>(); - posY.Add(nodePosY.ToString()); - t.KeyvalueTags["unityAuthoringPosY"] = posY; - return t; } } diff --git a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldAnchorWindow.cs b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldAnchorWindow.cs index cdaf1319829572bb9032d37220506744e405705a..a4a5418a6bb65796120a0c2658a807c43e737680 100644 --- a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldAnchorWindow.cs +++ b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldAnchorWindow.cs @@ -34,17 +34,10 @@ using ETSI.ARF.OpenAPI.WorldStorage; namespace ETSI.ARF.WorldStorage.UI { - public class WorldAnchorWindow : EditorWindow + public class WorldAnchorWindow : BaseWindow<WorldAnchor> { static public WorldAnchorWindow winSingleton; - [HideInInspector] public WorldStorageServer worldStorageServer; - [HideInInspector] public WorldStorageUser worldStorageUser; - - [SerializeField] public List<string> anchors = new List<string>(); - - bool groupEnabled; - // World Anchors params string UUID = System.Guid.Empty.ToString(); string customName = "NotDefined"; @@ -54,20 +47,16 @@ namespace ETSI.ARF.WorldStorage.UI Vector3 localCRS_pos; Vector3 localCRS_rot; - [SerializeField] KeyvalueTagList keyValueTags = new KeyvalueTagList(); - string key1 = ""; - string value1 = ""; - - // UI stuffs - private Vector2 scrollPos; - private Color ori; - private GUIStyle gsTest; - //graph params to generate the node public bool useCoord; public float nodePosX = 0; public float nodePosY = 0; + public WorldAnchorWindow() + { + // init somne stuffs + } + public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "") { winSingleton = EditorWindow.GetWindow(typeof(WorldAnchorWindow), false, "ETSI ARF - World Anchor") as WorldAnchorWindow; @@ -76,12 +65,12 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(UUID)) { winSingleton.UUID = UUID; - winSingleton.GetWorldAnchorParams(); + winSingleton.GetParams(); } else { // Create new one - winSingleton.AddAnchor(); + winSingleton.AddObject(); } } @@ -106,11 +95,6 @@ namespace ETSI.ARF.WorldStorage.UI return visual; } - public WorldAnchorWindow() - { - // init somne stuffs - } - void OnGUI() { ori = GUI.backgroundColor; // remember ori color @@ -124,7 +108,7 @@ namespace ETSI.ARF.WorldStorage.UI scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true)); WorldStorageWindow.DrawCopyright(); - DrawAnchorStuffs(); + DrawUIStuffs(); EditorGUILayout.EndScrollView(); @@ -134,7 +118,7 @@ namespace ETSI.ARF.WorldStorage.UI } } - void DrawAnchorStuffs() + public override void DrawUIStuffs() { GUILayout.BeginVertical(); // "World Anchor Editor", gsTest); EditorGUILayout.Space(); @@ -155,11 +139,12 @@ namespace ETSI.ARF.WorldStorage.UI GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel); EditorGUILayout.Space(); - customName = EditorGUILayout.TextField("Name of Anchor:", customName); #if isDEBUG GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly + EditorGUILayout.Space(); #endif + customName = EditorGUILayout.TextField("Name of Anchor:", customName); EditorGUILayout.Space(); // --------------------- @@ -173,38 +158,40 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(UUID) && UUID != "0" && UUID != System.Guid.Empty.ToString()) { - WorldAnchor obj = GenerateWorldAnchor(); + WorldAnchor obj = GenerateObject(); WorldAnchorRequest.UpdateWorldAnchorAsync(worldStorageServer, obj, (response) => { UUID = response.result; UUID = UUID.Trim('"'); //Bugfix: remove " from server return value + if (WorldStorageWindow.WorldStorageWindowSingleton != null) { WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); } + Close(); }); } - Close(); } GUI.backgroundColor = WorldStorageWindow.arfColors[3]; if (GUILayout.Button("Delete")) { - Debug.Log("Delete World Anchor"); - WorldAnchorRequest.DeleteWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) => + if (EditorUtility.DisplayDialog("Delete", "Are you sure you want to delete this World Anchor?", "Delete", "Cancel")) { - UUID = System.Guid.Empty.ToString(); - customName = "Warning: Object deleted !"; - creatorUUID = System.Guid.Empty.ToString(); - unit = UnitSystem.CM; - if (WorldStorageWindow.WorldStorageWindowSingleton != null) + Debug.Log("Delete World Anchor"); + WorldAnchorRequest.DeleteWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) => { - WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); - } - Close(); - }); + UUID = System.Guid.Empty.ToString(); + customName = "Warning: Object deleted !"; + creatorUUID = System.Guid.Empty.ToString(); + unit = UnitSystem.CM; + if (WorldStorageWindow.WorldStorageWindowSingleton != null) + { + WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors(); + } + Close(); + }); + } } GUI.backgroundColor = ori; @@ -230,16 +217,23 @@ namespace ETSI.ARF.WorldStorage.UI localCRS_pos = EditorGUILayout.Vector3Field(" Position:", localCRS_pos); localCRS_rot = EditorGUILayout.Vector3Field(" Rotation:", localCRS_rot); + // --------------------- + // Keyvalues + // --------------------- EditorGUILayout.Space(); groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled); - key1 = EditorGUILayout.TextField("Key 1", key1); - value1 = EditorGUILayout.TextField("Value 1", value1); + if (keyValuesFixed.Count > 0) + { + OutputKeyValue(0); + OutputKeyValue(1); + OutputKeyValue(2); + } EditorGUILayout.EndToggleGroup(); // GUILayout.EndVertical(); } - private void GetWorldAnchorParams() + public override void GetParams() { WorldAnchorRequest.GetWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) => { @@ -265,32 +259,43 @@ namespace ETSI.ARF.WorldStorage.UI localCRS_rot = Vector3.zero; } - // Read a key value (demo) - var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags); - key1 = first.Item1; - value1 = first.Item2; + // --------------------- + // Keyvalues + // --------------------- + //var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags); + //keyValuesFixed.Clear(); // no + for (int i = 0; i < keyValuesFixed.Count; i++) keyValuesFixed[i] = ("", ""); - this.Repaint(); + if (obj.KeyvalueTags.Count > 0) + { + int cnt = 0; + foreach (var item in obj.KeyvalueTags) + { + if (item.Key == "unityAuthoringPosX" || item.Key == "unityAuthoringPosY") continue; // ignore internal params + if (cnt < keyValuesFixed.Count) keyValuesFixed[cnt] = (item.Key, item.Value[0]); + cnt++; + } + } + repaint = true; }); } - public void AddAnchor() + public override void AddObject() { Debug.Log("POST World Anchor"); UUID = System.Guid.Empty.ToString(); customName = "Default Anchor"; - WorldAnchor obj = GenerateWorldAnchor(); + WorldAnchor obj = GenerateObject(); WorldAnchorRequest.CreateWorldAnchorAsync(worldStorageServer, obj, (response) => { UUID = response.result; UUID = UUID.Trim('"'); //Bugfix: remove " from server return value WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); }); } - public WorldAnchor GenerateWorldAnchor() + public override WorldAnchor GenerateObject() { Size _worldAnchorSize = new Size(); _worldAnchorSize.Add(worldAnchorSize.x); @@ -302,9 +307,23 @@ namespace ETSI.ARF.WorldStorage.UI localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one); Transform3D _localCRS = WorldStorageUnityHelper.ConvertUnityToETSIARFTransform3D(localCRS); - // Create a key value (one from demo) + // Remember the position of the Unity graph node + var posX = new Collection<String>(); + posX.Add(nodePosX.ToString()); + var posY = new Collection<String>(); + posY.Add(nodePosY.ToString()); + + // --------------------- + // Keyvalues + // --------------------- keyValueTags.Clear(); - keyValueTags.Add(key1, new Collection<string> { value1 }); + keyValueTags.Add("unityAuthoringPosX", posX); + keyValueTags.Add("unityAuthoringPosY", posY); + if (keyValuesFixed.Count > 0) + foreach (var item in keyValuesFixed) + { + if (!string.IsNullOrEmpty(item.Item1)) keyValueTags.Add(item.Item1, new Collection<string> { item.Item2 }); + } Guid _uuid = Guid.Parse(UUID); Guid _creator = Guid.Parse(worldStorageUser.UUID); @@ -315,16 +334,8 @@ namespace ETSI.ARF.WorldStorage.UI LocalCRS = _localCRS, Unit = unit, WorldAnchorSize = _worldAnchorSize, - KeyvalueTags = keyValueTags + KeyvalueTags = keyValueTags }; - - var posX = new Collection<String>(); - posX.Add(nodePosX.ToString()); - t.KeyvalueTags["unityAuthoringPosX"] = posX; - var posY = new Collection<String>(); - posY.Add(nodePosY.ToString()); - t.KeyvalueTags["unityAuthoringPosY"] = posY; - return t; } } diff --git a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldLinkWindow.cs b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldLinkWindow.cs index 711564401e75b27e5194ff1a55a6d1cdabedb027..e9b4bc46e777133c25ec802f54b7bd6f32c5b116 100644 --- a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldLinkWindow.cs +++ b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldLinkWindow.cs @@ -34,8 +34,10 @@ using ETSI.ARF.OpenAPI.WorldStorage; namespace ETSI.ARF.WorldStorage.UI { - public class WorldLinkWindow : EditorWindow + public class WorldLinkWindow : BaseWindow<WorldLink> { + static public WorldLinkWindow winSingleton; + public class Element { public string UUID = System.Guid.Empty.ToString(); @@ -43,15 +45,9 @@ namespace ETSI.ARF.WorldStorage.UI public TypeWorldStorage type = TypeWorldStorage.UNKNOWN; public Vector3 pos = Vector3.zero; } - - static public WorldLinkWindow winSingleton; - - [HideInInspector] public WorldStorageServer worldStorageServer; - [HideInInspector] public WorldStorageUser worldStorageUser; - + [SerializeField] public List<string> anchors = new List<string>(); - bool groupEnabled; private static GUILayoutOption miniButtonWidth = GUILayout.Width(50); // World Anchors params @@ -69,14 +65,10 @@ namespace ETSI.ARF.WorldStorage.UI Vector3 transf_pos; Vector3 transf_rot; - [SerializeField] KeyvalueTagList keyValueTags = new KeyvalueTagList(); - string key1 = ""; - string value1 = ""; - - // UI stuffs - private Vector2 scrollPos; - private Color ori; - private GUIStyle gsTest; + public WorldLinkWindow() + { + // init somne stuffs + } public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "") { @@ -86,12 +78,12 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(UUID)) { winSingleton.UUID = UUID; - winSingleton.GetWorldLinkParams(); + winSingleton.GetParams(); } else { // Create new one - winSingleton.AddLink(); + winSingleton.AddObject(); } } @@ -135,11 +127,7 @@ namespace ETSI.ARF.WorldStorage.UI return visual; } - public WorldLinkWindow() - { - // init somne stuffs - } - + void OnGUI() { ori = GUI.backgroundColor; // remember ori color @@ -154,7 +142,7 @@ namespace ETSI.ARF.WorldStorage.UI scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true)); WorldStorageWindow.DrawCopyright(); - DrawAnchorStuffs(); + DrawUIStuffs(); EditorGUILayout.EndScrollView(); @@ -243,7 +231,7 @@ namespace ETSI.ARF.WorldStorage.UI }); } - void DrawAnchorStuffs() + public override void DrawUIStuffs() { GUILayout.BeginVertical(); // "World Link Editor", gsTest); EditorGUILayout.Space(); @@ -269,7 +257,6 @@ namespace ETSI.ARF.WorldStorage.UI GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly #endif - EditorGUILayout.Space(); // --------------------- @@ -283,13 +270,17 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(UUID) && UUID != "0" && UUID != System.Guid.Empty.ToString()) { - WorldLink obj = GenerateWorldLink(); + WorldLink obj = GenerateObject(); WorldLinkRequest.UpdateWorldLinkAsync(worldStorageServer, obj, (response) => { UUID = response.result; UUID = UUID.Trim('"'); //Bugfix: remove " from server return value - WorldStorageWindow.WorldStorageWindowSingleton.GetWorldLinks(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); + + if (WorldStorageWindow.WorldStorageWindowSingleton != null) + { + WorldStorageWindow.WorldStorageWindowSingleton.GetWorldLinks(); + } + Close(); }); } } @@ -297,16 +288,18 @@ namespace ETSI.ARF.WorldStorage.UI GUI.backgroundColor = WorldStorageWindow.arfColors[3]; if (GUILayout.Button("Delete")) { - Debug.Log("Delete World Link"); - WorldLinkRequest.DeleteWorldLinkAsync(worldStorageServer, Guid.Parse(UUID), (response) => + if (EditorUtility.DisplayDialog("Delete", "Are you sure you want to delete this World Link?", "Delete", "Cancel")) { - UUID = System.Guid.Empty.ToString(); - customName = "Warning: Object deleted !"; - creatorUUID = System.Guid.Empty.ToString(); - unit = UnitSystem.CM; - WorldStorageWindow.WorldStorageWindowSingleton.GetWorldLinks(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); - }); + Debug.Log("Delete World Link"); + WorldLinkRequest.DeleteWorldLinkAsync(worldStorageServer, Guid.Parse(UUID), (response) => + { + UUID = System.Guid.Empty.ToString(); + customName = "Warning: Object deleted !"; + creatorUUID = System.Guid.Empty.ToString(); + unit = UnitSystem.CM; + WorldStorageWindow.WorldStorageWindowSingleton.GetWorldLinks(); + }); + } } GUI.backgroundColor = ori; @@ -397,16 +390,23 @@ namespace ETSI.ARF.WorldStorage.UI transf_pos = EditorGUILayout.Vector3Field("Position:", transf_pos); transf_rot = EditorGUILayout.Vector3Field("Rotation:", transf_rot); + // --------------------- + // Keyvalues + // --------------------- EditorGUILayout.Space(); groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled); - key1 = EditorGUILayout.TextField("Key 1", key1); - value1 = EditorGUILayout.TextField("Value 1", value1); + if (keyValuesFixed.Count > 0) + { + OutputKeyValue(0); + OutputKeyValue(1); + OutputKeyValue(2); + } EditorGUILayout.EndToggleGroup(); // GUILayout.EndVertical(); } - private void GetWorldLinkParams() + public override void GetParams() { WorldLinkRequest.GetWorldLinkAsync(worldStorageServer, Guid.Parse(UUID), (response) => { @@ -432,41 +432,65 @@ namespace ETSI.ARF.WorldStorage.UI transf_pos = Vector3.zero; transf_rot = Vector3.zero; } - keyValueTags = obj.KeyvalueTags; // Get here the params of the from/to elements (GET) GetElementFROM(); GetElementTO(); - this.Repaint(); + // --------------------- + // Keyvalues + // --------------------- + //var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags); + //keyValuesFixed.Clear(); // no + for (int i = 0; i < keyValuesFixed.Count; i++) keyValuesFixed[i] = ("", ""); + + if (obj.KeyvalueTags.Count > 0) + { + int cnt = 0; + foreach (var item in obj.KeyvalueTags) + { + if (item.Key == "unityAuthoringPosX" || item.Key == "unityAuthoringPosY") continue; // ignore internal params + if (cnt < keyValuesFixed.Count) keyValuesFixed[cnt] = (item.Key, item.Value[0]); + cnt++; + } + } + repaint = true; }); } - public void AddLink() + public override void AddObject() { Debug.Log("POST World Link"); UUID = System.Guid.Empty.ToString(); customName = "Default Link"; - WorldLink obj = GenerateWorldLink(); + WorldLink obj = GenerateObject(); WorldLinkRequest.CreateWorldLinkAsync(worldStorageServer, obj, (response) => { UUID = response.result; UUID = UUID.Trim('"'); //Bugfix: remove " from server return value WorldStorageWindow.WorldStorageWindowSingleton.GetWorldLinks(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); + WorldStorageWindow.WorldStorageWindowSingleton.repaint = true; }); } - public WorldLink GenerateWorldLink() + public override WorldLink GenerateObject() { Matrix4x4 localCRS = new Matrix4x4(); localCRS = Matrix4x4.TRS(transf_pos, Quaternion.Euler(transf_rot), Vector3.one); Transform3D transform3d = WorldStorageUnityHelper.ConvertUnityToETSIARFTransform3D(localCRS); - // Create a key value (one from demo) + // --------------------- + // Keyvalues + // --------------------- keyValueTags.Clear(); - keyValueTags.Add(key1, new Collection<string> { value1 }); + //keyValueTags.Add("unityAuthoringPosX", posX); + //keyValueTags.Add("unityAuthoringPosY", posY); + if (keyValuesFixed.Count > 0) + foreach (var item in keyValuesFixed) + { + if (!string.IsNullOrEmpty(item.Item1)) keyValueTags.Add(item.Item1, new Collection<string> { item.Item2 }); + } System.Guid _uuid = System.Guid.Parse(UUID); System.Guid _creator = System.Guid.Parse(worldStorageUser.UUID); diff --git a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldStorageWindow.cs b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldStorageWindow.cs index 40ed1a93a4ce2ab44f185790bbc07ddb7cb708c0..119b4535e377ea6aa39287785e5600d23ea25511 100644 --- a/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldStorageWindow.cs +++ b/Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldStorageWindow.cs @@ -50,6 +50,7 @@ namespace ETSI.ARF.WorldStorage.UI string state = "Unknow"; string vers = "Unknow"; + public bool repaint = false; private Vector2 scrollPos; private Color ori; private GUIStyle gsTest; @@ -82,12 +83,25 @@ namespace ETSI.ARF.WorldStorage.UI //[MenuItem("[ ISG-ARF ]/World Storage Editor")] public static void ShowWindow() { - EditorWindow.GetWindow(typeof(WorldStorageWindow), false, WorldStorageWindow.winName); + WorldStorageWindowSingleton = EditorWindow.GetWindow(typeof(WorldStorageWindow), false, WorldStorageWindow.winName) as WorldStorageWindow; + OpenAPI.ResponseObject<string> ro = AdminRequest.PingAsync(WorldStorageWindowSingleton.worldStorageServer, (response) => + { + WorldStorageWindowSingleton.ping = response.result; + WorldStorageWindowSingleton.repaint = true; + }); + } + + public void Update() + { + if (repaint) + { + Repaint(); + repaint = false; + } } public WorldStorageWindow() { - WorldStorageWindowSingleton = this; } static public void DrawCopyright() @@ -125,7 +139,7 @@ namespace ETSI.ARF.WorldStorage.UI GUILayout.Label("Port: " + worldStorageServer.port); #endif - GUI.backgroundColor = WorldStorageWindow.arfColors[4]; + GUI.backgroundColor = WorldStorageWindow.arfColors[1]; if (GUILayout.Button("Open World Representation Graph Window...")) { WorldGraphWindow.ShowWindowFromWorldStorageWindow(worldStorageServer, worldStorageUser); @@ -204,7 +218,7 @@ namespace ETSI.ARF.WorldStorage.UI // ########################################################### #region Get all creator UUID EditorGUILayout.Space(); - GUI.backgroundColor = WorldStorageWindow.arfColors[0]; + GUI.backgroundColor = WorldStorageWindow.arfColors[4]; if (GUILayout.Button("Request UUID of Creators")) GetCreators(); GUI.backgroundColor = ori; @@ -231,6 +245,14 @@ namespace ETSI.ARF.WorldStorage.UI #region Get all trackable objects EditorGUILayout.Space(); + GUI.backgroundColor = WorldStorageWindow.arfColors[0]; + if (GUILayout.Button("Request All")) + { + GetTrackables(); + GetWorldAnchors(); + GetWorldLinks(); + } + GUILayout.BeginHorizontal(); GUI.backgroundColor = WorldStorageWindow.arfColors[7]; Texture trackableImage = (Texture)AssetDatabase.LoadAssetAtPath("Assets/ETSI.ARF/ARF World Storage API/Images/trackable.png", typeof(Texture)); @@ -277,7 +299,7 @@ namespace ETSI.ARF.WorldStorage.UI } GetTrackables(); - WorldStorageWindow.WorldStorageWindowSingleton.Repaint(); + WorldStorageWindow.WorldStorageWindowSingleton.repaint = true; } } GUI.backgroundColor = ori; @@ -308,7 +330,7 @@ namespace ETSI.ARF.WorldStorage.UI TrackableRequest.DeleteTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) => { WorldStorageWindowSingleton.GetTrackables(); - WorldStorageWindowSingleton.Repaint(); + WorldStorageWindowSingleton.repaint = true; }); } } @@ -367,11 +389,9 @@ namespace ETSI.ARF.WorldStorage.UI if (++n > 3) WorldAnchorRequest.DeleteWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) => { WorldStorageWindowSingleton.GetWorldAnchors(); - WorldStorageWindowSingleton.Repaint(); + WorldStorageWindowSingleton.repaint = true; }); } - //WorldStorageWindowSingleton.GetWorldAnchors(); - //WorldStorageWindowSingleton.Repaint(); } } GUI.backgroundColor = ori; @@ -402,7 +422,6 @@ namespace ETSI.ARF.WorldStorage.UI WorldAnchorRequest.DeleteWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) => { WorldStorageWindowSingleton.GetWorldAnchors(); - WorldStorageWindowSingleton.Repaint(); }); } } @@ -461,11 +480,8 @@ namespace ETSI.ARF.WorldStorage.UI if (++n > 3) WorldLinkRequest.DeleteWorldLinkAsync(worldStorageServer, Guid.Parse(UUID), (response) => { WorldStorageWindowSingleton.GetWorldLinks(); - WorldStorageWindowSingleton.Repaint(); }); } - //WorldStorageWindowSingleton.GetWorldLinks(); - //WorldStorageWindowSingleton.Repaint(); } } GUI.backgroundColor = ori; @@ -497,7 +513,6 @@ namespace ETSI.ARF.WorldStorage.UI WorldLinkRequest.DeleteWorldLinkAsync(worldStorageServer, Guid.Parse(UUID), (response) => { WorldStorageWindowSingleton.GetWorldLinks(); - WorldStorageWindowSingleton.Repaint(); }); } } @@ -563,6 +578,7 @@ namespace ETSI.ARF.WorldStorage.UI Debug.Log("Get all server objects"); TrackableRequest.GetTrackablesAsync(worldStorageServer, (response) => { + Debug.Log("Get objects num = " + response.result.Count); trackables.Clear(); foreach (var item in response.result) { @@ -574,6 +590,7 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(item.Name)) trackables.Add(item.Name + " [" + item.UUID.ToString() + "]"); else trackables.Add(item.UUID.ToString()); } + repaint = true; }); } @@ -594,6 +611,7 @@ namespace ETSI.ARF.WorldStorage.UI if (!string.IsNullOrEmpty(item.Name)) anchors.Add(item.Name + " [" + item.UUID.ToString() + "]"); else anchors.Add(item.UUID.ToString()); } + repaint = true; }); } @@ -608,6 +626,7 @@ namespace ETSI.ARF.WorldStorage.UI { links.Add(item.UUID.ToString()); } + repaint = true; }); } #endregion diff --git a/Assets/ETSI.ARF/ARF World Storage API/World Storage/HHI Server - sylvain dev.asset b/Assets/ETSI.ARF/ARF World Storage API/World Storage/HHI Server - sylvain dev.asset new file mode 100644 index 0000000000000000000000000000000000000000..935094918b9b2d82c5881f611ff22186a06f03ea --- /dev/null +++ b/Assets/ETSI.ARF/ARF World Storage API/World Storage/HHI Server - sylvain dev.asset @@ -0,0 +1,19 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e4b7be4c33f68d0418c3b4e1a7053d91, type: 3} + m_Name: HHI Server - sylvain dev + m_EditorClassIdentifier: + serverName: HHI Server (Sylvain) + company: Fraunhofer HHI + basePath: https://localhost + port: 44301 + currentUser: {fileID: 11400000, guid: ce0f40be06008b14283766424922b729, type: 2} diff --git a/Assets/ETSI.ARF/ARF World Storage API/World Storage/HHI Server - sylvain dev.asset.meta b/Assets/ETSI.ARF/ARF World Storage API/World Storage/HHI Server - sylvain dev.asset.meta new file mode 100644 index 0000000000000000000000000000000000000000..218e3c60458ff581dc471e0b1e9c713190675189 --- /dev/null +++ b/Assets/ETSI.ARF/ARF World Storage API/World Storage/HHI Server - sylvain dev.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: db0064cecabb1b244a4e158d43602781 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: