Commit 949dd19e authored by Sylvain Renault's avatar Sylvain Renault
Browse files

Redesign of all windows (server/trackable/anchor/link).

Added world link window.
Completion and implementation of all API parameters (tbd: to be tested).
parent bc319d21
Loading
Loading
Loading
Loading
+113 −69
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
//

#define USING_OPENAPI_GENERATOR // alt. is Swagger
//#define isDEBUG
#define isDEBUG

using System.Collections;
using System.Collections.Generic;
@@ -47,14 +47,19 @@ namespace ETSI.ARF.WorldStorage.UI

        bool groupEnabled;

        // Trackable params
        string UUID = System.Guid.Empty.ToString();
        string customName = "NotDefined";
        string creatorUUID = System.Guid.Empty.ToString();
        string type = "Unknow";
        string unit = "Unknow";
        Vector2Int dim;

        private Trackable currentTrackable;
        Trackable.TrackableTypeEnum type = Trackable.TrackableTypeEnum.OTHER;
        UnitSystem unit = UnitSystem.CM;
        Vector3 trackableSize;
        Vector3 localCRS_pos;
        Vector3 localCRS_rot;
        byte[] trackablePayload = new byte[1] { 0 };
        [SerializeField] Dictionary<string, List<string>> keyValueTags = new Dictionary<string, List<string>>();

        // UI stuffs
        private Vector2 scrollPos;
        private Color ori;
        private GUIStyle gsTest;
@@ -69,7 +74,6 @@ namespace ETSI.ARF.WorldStorage.UI
        public TrackableWindow()
        {
            // init somne stuffs
            //currentTrackable = new Trackable();
        }

        void OnGUI()
@@ -95,7 +99,7 @@ namespace ETSI.ARF.WorldStorage.UI

        void DrawTrackableStuffs()// Trackable trackable)
        {
            GUILayout.BeginVertical("AR Trackable", gsTest);
            GUILayout.BeginVertical("Trackable Editor", gsTest);
            //
            GUILayout.Label("Server: " + worldStorageServer.serverName, EditorStyles.whiteLargeLabel);
            GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel);
@@ -121,59 +125,117 @@ namespace ETSI.ARF.WorldStorage.UI
                Trackable obj = TrackableRequest.GetTrackable(worldStorageServer, UUID);
                customName = obj.Name;
                creatorUUID = obj.CreatorUUID.ToString();
                type = obj.TrackableType.ToString();
                unit = obj.Unit.ToString();
                type = obj.TrackableType;
                unit = obj.Unit;
                if (obj.TrackableSize.Count == 3)
                {
                    trackableSize = new Vector3((float)obj.TrackableSize[0], (float)obj.TrackableSize[1], (float)obj.TrackableSize[2]);
                }
                else trackableSize = Vector3.zero;
                if (obj.LocalCRS.Count == 16)
                {
                    Matrix4x4 localCRS = new Matrix4x4();
                    localCRS.m00 = obj.LocalCRS[0]; localCRS.m01 = obj.LocalCRS[1]; localCRS.m02 = obj.LocalCRS[2]; localCRS.m03 = obj.LocalCRS[3];
                    localCRS.m10 = obj.LocalCRS[4]; localCRS.m11 = obj.LocalCRS[5]; localCRS.m12 = obj.LocalCRS[6]; localCRS.m13 = obj.LocalCRS[7];
                    localCRS.m20 = obj.LocalCRS[8]; localCRS.m21 = obj.LocalCRS[9]; localCRS.m22 = obj.LocalCRS[10]; localCRS.m23 = obj.LocalCRS[11];
                    localCRS.m30 = obj.LocalCRS[12]; localCRS.m31 = obj.LocalCRS[13]; localCRS.m32 = obj.LocalCRS[14]; localCRS.m33 = obj.LocalCRS[15];
                    localCRS_pos = localCRS.GetPosition();
                    localCRS_rot = localCRS.rotation.eulerAngles;
                }
                else
                {
                    localCRS_pos = Vector3.zero;
                    localCRS_rot = Vector3.zero;
                }
                keyValueTags = obj.KeyvalueTags;
                this.Repaint(); // TODO
            }
            GUI.backgroundColor = ori;

            type = EditorGUILayout.TextField("Trackable Type", type);
            unit = EditorGUILayout.TextField("Unit System", unit);
            type = (Trackable.TrackableTypeEnum)EditorGUILayout.EnumPopup("Trackable Type:", type);
            unit = (UnitSystem)EditorGUILayout.EnumPopup("Unit System:", unit);

            EditorGUILayout.Space(10);
            dim = EditorGUILayout.Vector2IntField("Dimension", dim);
            trackableSize = EditorGUILayout.Vector3Field("Trackable Size:", trackableSize);

            EditorGUILayout.Space(10);
            GUILayout.Label("Local CRS:");
            localCRS_pos = EditorGUILayout.Vector3Field("Position:", localCRS_pos);
            localCRS_rot = EditorGUILayout.Vector3Field("Rotation:", localCRS_rot);

            EditorGUILayout.Space();
            GUILayout.Button("Payload from Asset...");
            if (GUILayout.Button("Generate Dummy Payload"))
            {
                // dummy
                trackablePayload = new byte[100];
                for (int i = 0; i < trackablePayload.Length; i++)
                {
                    trackablePayload[i] = (byte)i;
                }
            }

            EditorGUILayout.Space();
            groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled);
            EditorGUILayout.IntField("Number of KeyValues", 0);
            EditorGUILayout.Space();
            EditorGUILayout.TextField("Key", "");
            EditorGUILayout.TextField("Value", "");
            //EditorGUILayout.IntField("Number of KeyValues", 0);
            //EditorGUILayout.Space();
            //EditorGUILayout.TextField("Key", "");
            //EditorGUILayout.TextField("Value", "");
            if (GUILayout.Button("Generate Dummy Key Values"))
            {
                // dummy
                keyValueTags.Clear();
                keyValueTags.Add("Location", new List<string> { "Room1" });
            }
            // Test
            //keyValueTags.Add("1", "a");
            //ScriptableObject target = this;
            //SerializedObject so = new SerializedObject(target);
            //SerializedProperty stringsProperty = so.FindProperty("trackables");
            //EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
            //so.ApplyModifiedProperties(); // Remember to apply modified properties
            EditorGUILayout.EndToggleGroup();
            //
            
            GUILayout.EndVertical();

            // ###########################################################
            GUI.backgroundColor = WorldStorageWindow.arfColors[2];
            if (GUILayout.Button("Create/Update Trackable"))
            GUI.backgroundColor = WorldStorageWindow.arfColors[1];
            if (GUILayout.Button("Create New Trackable"))
            {
                Debug.Log("PostAddTrackable");
                Debug.Log("POST Trackable");

                UUID = "0";
                if (string.IsNullOrEmpty(UUID) || UUID == "0") UUID = System.Guid.Empty.ToString();
                Trackable obj = GenerateTrackable(UUID, customName, worldStorageUser.UUID);
                TrackableRequest.AddTrackable(worldStorageServer, obj);
                WorldStorageWindow.WorldStorageWindowSingleton.UpdateListTrackables();
                Trackable obj = GenerateTrackable();
                UUID = TrackableRequest.AddTrackable(worldStorageServer, obj);
                WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            }

                UUID = obj.UUID.ToString();
                customName = obj.Name;
                type = obj.TrackableType.ToString();
                unit = obj.Unit.ToString();
            GUI.backgroundColor = WorldStorageWindow.arfColors[2];
            if (GUILayout.Button("Modify Trackable"))
            {
                Debug.Log("PUT Trackable");

                if (!string.IsNullOrEmpty(UUID) && UUID != "0")
                {
                    Trackable obj = GenerateTrackable();
                    UUID = TrackableRequest.UpdateTrackable(worldStorageServer, obj);
                }
                WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            }

            // ###########################################################
            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            if (GUILayout.Button("Delete Trackable"))
            {
                Debug.Log("Deleting Trackable");
                Debug.Log("Delete Trackable");
                TrackableRequest.DeleteTrackable(worldStorageServer, UUID);
                UUID = System.Guid.Empty.ToString();
                creatorUUID = System.Guid.Empty.ToString();
                type = "";
                unit = "";
                WorldStorageWindow.WorldStorageWindowSingleton.UpdateListTrackables();
                type = Trackable.TrackableTypeEnum.OTHER;
                unit = UnitSystem.CM;
                WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            }
            GUI.backgroundColor = ori;
@@ -187,52 +249,34 @@ namespace ETSI.ARF.WorldStorage.UI
        }


        static public Trackable GenerateTrackable(string uuid, string name, string creatorUID)
        public Trackable GenerateTrackable()
        {
            EncodingInformationStructure trackableEncodingInformation =
                new EncodingInformationStructure(EncodingInformationStructure.DataFormatEnum.ARCORE, "1.0");
            EncodingInformationStructure trackableEncodingInformation = new EncodingInformationStructure(EncodingInformationStructure.DataFormatEnum.ARCORE, "1.0");
            Debug.Log("Created encoding information");

#if USING_OPENAPI_GENERATOR
            List<double> size = new List<double>();
            List<double> _trackableSize = new List<double>();
#else
    List<double?> trackableDimension = new List<double?>();
    List<double?> _trackableSize = new List<double?>();
#endif
            size.Add(5);
            size.Add(5);
            _trackableSize.Add(trackableSize.x);
            _trackableSize.Add(trackableSize.y);
            _trackableSize.Add(trackableSize.z);
            Debug.Log("Created dimension");

            byte[] bytes = new byte[100];

            for (int i = 0; i < bytes.Length; i++)
            {
                bytes[i] = (byte)i;
            }

            List<float> crs = new List<float>
            Matrix4x4 localCRS = new Matrix4x4();
            localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one);
            List<float> _localCRS = new List<float>
            {
                -2,    1,    -3,    4,
                4,    4,    4,    2,
                1,    0,    -2,    1,
                -1,    -2,    0,    0
                localCRS.m00,    localCRS.m01,    localCRS.m02,    localCRS.m03,
                localCRS.m10,    localCRS.m11,    localCRS.m12,    localCRS.m13,
                localCRS.m20,    localCRS.m21,    localCRS.m22,    localCRS.m23,
                localCRS.m30,    localCRS.m31,    localCRS.m32,    localCRS.m33,
            };

            Dictionary<string, List<string>> kv = new Dictionary<string, List<string>>();
            kv.Add("Scenario", new List<string> { "ETSI Trackable" });

            System.Guid _uuid = System.Guid.Parse(uuid);
            Trackable t = new Trackable(
                _uuid,
                name,
                System.Guid.Parse(creatorUID),
                Trackable.TrackableTypeEnum.IMAGEMARKER,
                trackableEncodingInformation,
                bytes,
                crs,
                UnitSystem.M,
                size,
                kv);
            t.UUID = _uuid;
            System.Guid _uuid = System.Guid.Parse(UUID);
            System.Guid _creator = System.Guid.Parse(worldStorageUser.UUID);
            Trackable t = new Trackable(_uuid, customName, _creator, type, trackableEncodingInformation, trackablePayload, _localCRS, unit, _trackableSize, keyValueTags);
            return t;
        }
    }
+88 −57
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
//

#define USING_OPENAPI_GENERATOR // alt. is Swagger
//#define isDEBUG
#define isDEBUG

using System.Collections;
using System.Collections.Generic;
@@ -46,12 +46,17 @@ namespace ETSI.ARF.WorldStorage.UI

        bool groupEnabled;

        // World Anchors params
        string UUID = System.Guid.Empty.ToString();
        string customName = "NotDefined";
        string creatorUUID = System.Guid.Empty.ToString();
        string unit = "Unknow";
        Vector2Int dim;
        UnitSystem unit = UnitSystem.CM;
        Vector3 worldAnchorSize;
        Vector3 localCRS_pos;
        Vector3 localCRS_rot;
        [SerializeField] Dictionary<string, List<string>> keyValueTags = new Dictionary<string, List<string>>();

        // UI stuffs
        private Vector2 scrollPos;
        private Color ori;
        private GUIStyle gsTest;
@@ -71,6 +76,7 @@ namespace ETSI.ARF.WorldStorage.UI
        void OnGUI()
        {
            ori = GUI.backgroundColor; // remember ori color

            gsTest = new GUIStyle("window");
            gsTest.normal.textColor = WorldStorageWindow.arfColors[0];
            gsTest.fontStyle = FontStyle.Bold;
@@ -90,7 +96,7 @@ namespace ETSI.ARF.WorldStorage.UI

        void DrawAnchorStuffs()
        {
            GUILayout.BeginVertical("AR World Anchor", gsTest);
            GUILayout.BeginVertical("World Anchor Editor", gsTest);
            //
            GUILayout.Label("Server: " + worldStorageServer.serverName, EditorStyles.whiteLargeLabel);
            GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel);
@@ -116,53 +122,96 @@ namespace ETSI.ARF.WorldStorage.UI
                WorldAnchor obj = WorldAnchorRequest.GetWorldAnchor(worldStorageServer, UUID);
                customName = obj.Name;
                creatorUUID = obj.CreatorUUID.ToString();
                unit = obj.Unit.ToString();
                unit = obj.Unit;
                if (obj.WorldAnchorSize.Count == 3)
                {
                    worldAnchorSize = new Vector3((float)obj.WorldAnchorSize[0], (float)obj.WorldAnchorSize[1], (float)obj.WorldAnchorSize[2]);
                }
                else worldAnchorSize = Vector3.zero;
                if (obj.LocalCRS.Count == 16)
                {
                    Matrix4x4 localCRS = new Matrix4x4();
                    localCRS.m00 = obj.LocalCRS[0]; localCRS.m01 = obj.LocalCRS[1]; localCRS.m02 = obj.LocalCRS[2]; localCRS.m03 = obj.LocalCRS[3];
                    localCRS.m10 = obj.LocalCRS[4]; localCRS.m11 = obj.LocalCRS[5]; localCRS.m12 = obj.LocalCRS[6]; localCRS.m13 = obj.LocalCRS[7];
                    localCRS.m20 = obj.LocalCRS[8]; localCRS.m21 = obj.LocalCRS[9]; localCRS.m22 = obj.LocalCRS[10]; localCRS.m23 = obj.LocalCRS[11];
                    localCRS.m30 = obj.LocalCRS[12]; localCRS.m31 = obj.LocalCRS[13]; localCRS.m32 = obj.LocalCRS[14]; localCRS.m33 = obj.LocalCRS[15];
                    localCRS_pos = localCRS.GetPosition();
                    localCRS_rot = localCRS.rotation.eulerAngles;
                }
                else
                {
                    localCRS_pos = Vector3.zero;
                    localCRS_rot = Vector3.zero;
                }
                keyValueTags = obj.KeyvalueTags;
                this.Repaint(); // TODO
            }
            GUI.backgroundColor = ori;
            //GUILayout.EndHorizontal();

            unit = EditorGUILayout.TextField("Unit System", unit);
            unit = (UnitSystem)EditorGUILayout.EnumPopup("Unit System:", unit);

            EditorGUILayout.Space(10);
            worldAnchorSize = EditorGUILayout.Vector3Field("Trackable Size:", worldAnchorSize);

            EditorGUILayout.Space(10);
            dim = EditorGUILayout.Vector2IntField("Dimension", dim);
            GUILayout.Label("Local CRS:");
            localCRS_pos = EditorGUILayout.Vector3Field("Position:", localCRS_pos);
            localCRS_rot = EditorGUILayout.Vector3Field("Rotation:", localCRS_rot);

            EditorGUILayout.Space();
            groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled);
            EditorGUILayout.IntField("Number of KeyValues", 0);
            EditorGUILayout.Space();
            EditorGUILayout.TextField("Key", "");
            EditorGUILayout.TextField("Value", "");
            //EditorGUILayout.IntField("Number of KeyValues", 0);
            //EditorGUILayout.Space();
            //EditorGUILayout.TextField("Key", "");
            //EditorGUILayout.TextField("Value", "");
            if (GUILayout.Button("Generate Dummy Key Values"))
            {
                // dummy
                keyValueTags.Clear();
                keyValueTags.Add("Location", new List<string> { "Room1" });
            }
            EditorGUILayout.EndToggleGroup();
            //
            GUILayout.EndVertical();

            // ###########################################################
            GUI.backgroundColor = WorldStorageWindow.arfColors[2];
            if (GUILayout.Button("Create/Update World Anchor"))
            GUI.backgroundColor = WorldStorageWindow.arfColors[1];
            if (GUILayout.Button("Create New World Anchor"))
            {
                Debug.Log("PostAddWorldAnchor");
                Debug.Log("POST World Anchor");

                UUID = "0";
                if (string.IsNullOrEmpty(UUID) || UUID == "0") UUID = System.Guid.Empty.ToString();
                WorldAnchor obj = GenerateWorldAnchor(UUID, customName, worldStorageUser.UUID);
                WorldAnchorRequest.AddWorldAnchor(worldStorageServer, obj);
                WorldStorageWindow.WorldStorageWindowSingleton.UpdateListWorldAnchors();
                WorldAnchor obj = GenerateWorldAnchor();
                UUID = WorldAnchorRequest.AddWorldAnchor(worldStorageServer, obj);
                WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            }

                UUID = obj.UUID.ToString();
                customName = obj.Name;
                unit = obj.Unit.ToString();
            GUI.backgroundColor = WorldStorageWindow.arfColors[2];
            if (GUILayout.Button("Modify World Anchor"))
            {
                Debug.Log("PUT World Anchor");

                if (!string.IsNullOrEmpty(UUID) && UUID != "0")
                {
                    WorldAnchor obj = GenerateWorldAnchor();
                    UUID = WorldAnchorRequest.UpdateWorldAnchor(worldStorageServer, obj);
                    WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                    WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                }
            }

            // ###########################################################
            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            if (GUILayout.Button("Delete World Anchor"))
            {
                Debug.Log("Deleting World Anchor");
                Debug.Log("Delete World Anchor");
                WorldAnchorRequest.DeleteWorldAnchor(worldStorageServer, UUID);
                UUID = System.Guid.Empty.ToString();
                creatorUUID = System.Guid.Empty.ToString();
                unit = "";
                WorldStorageWindow.WorldStorageWindowSingleton.UpdateListWorldAnchors();
                unit = UnitSystem.CM;
                WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            }
            GUI.backgroundColor = ori;
@@ -175,49 +224,31 @@ namespace ETSI.ARF.WorldStorage.UI
            GUI.backgroundColor = ori;
        }

        static public WorldAnchor GenerateWorldAnchor(string uuid, string name, string creatorUID)
        public WorldAnchor GenerateWorldAnchor()
        {
            EncodingInformationStructure trackableEncodingInformation =
                new EncodingInformationStructure(EncodingInformationStructure.DataFormatEnum.ARCORE, "1.0");
            Debug.Log("Created encoding information");

#if USING_OPENAPI_GENERATOR
            List<double> size = new List<double>();
            List<double> _worldAnchorSize = new List<double>();
#else
    List<double?> trackableDimension = new List<double?>();
#endif
            size.Add(5);
            size.Add(5);
            _worldAnchorSize.Add(worldAnchorSize.x);
            _worldAnchorSize.Add(worldAnchorSize.x);
            _worldAnchorSize.Add(worldAnchorSize.y);
            Debug.Log("Created dimension");

            byte[] bytes = new byte[100];

            for (int i = 0; i < bytes.Length; i++)
            {
                bytes[i] = (byte)i;
            }

            List<float> crs = new List<float>
            Matrix4x4 localCRS = new Matrix4x4();
            localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one);
            List<float> _localCRS = new List<float>
            {
                -2,    1,    -3,    4,
                4,    4,    4,    2,
                1,    0,    -2,    1,
                -1,    -2,    0,    0
                localCRS.m00,    localCRS.m01,    localCRS.m02,    localCRS.m03,
                localCRS.m10,    localCRS.m11,    localCRS.m12,    localCRS.m13,
                localCRS.m20,    localCRS.m21,    localCRS.m22,    localCRS.m23,
                localCRS.m30,    localCRS.m31,    localCRS.m32,    localCRS.m33,
            };

            Dictionary<string, List<string>> kv = new Dictionary<string, List<string>>();
            kv.Add("Scenario", new List<string> { "ETSI WorldAnchor" });

            System.Guid _uuid = System.Guid.Parse(uuid);
            WorldAnchor t = new WorldAnchor(
                _uuid,
                name,
                System.Guid.Parse(creatorUID),
                crs,
                UnitSystem.M,
                size,
                kv);
            t.UUID = _uuid;
            System.Guid _uuid = System.Guid.Parse(UUID);
            System.Guid _creator = System.Guid.Parse(worldStorageUser.UUID);
            WorldAnchor t = new WorldAnchor(_uuid, customName, _creator, _localCRS, unit, _worldAnchorSize, keyValueTags);
            return t;
        }
    }
+248 −0

File added.

Preview size limit exceeded, changes collapsed.

+11 −0
Original line number Diff line number Diff line
fileFormatVersion: 2
guid: f66d40f8781c5784cbe1013328d78ae6
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 
+178 −105

File changed.

Preview size limit exceeded, changes collapsed.

Loading