Commit b1eaa0a7 authored by Sylvain Renault's avatar Sylvain Renault
Browse files

Changes to new NSwag system was done.

REST calls are async now BUT have to be tested (should produce problems with Unity UI thread...)
parent 35a74bd3
Loading
Loading
Loading
Loading
+104 −81
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

using UnityEngine;
@@ -304,10 +305,9 @@ namespace ETSI.ARF.WorldStorage.UI

        public void PaintWorldStorage()
        {
            List<Trackable> trackables = TrackableRequest.GetAllTrackables(worldStorageServer);
            List<WorldAnchor> worldAnchors = WorldAnchorRequest.GetAllWorldAnchors(worldStorageServer);
            List<WorldLink> worldLinks = WorldLinkRequest.GetAllWorldLinks(worldStorageServer);

            WorldAnchorRequest.GetWorldAnchorsAsync(worldStorageServer, (response) =>
            {
                List<WorldAnchor> worldAnchors = response.result;
                foreach (WorldAnchor worldAnchor in worldAnchors)
                {
                    var waNode = new ARFNodeWorldAnchor(worldAnchor);
@@ -318,7 +318,11 @@ namespace ETSI.ARF.WorldStorage.UI

                    AddElement(waNode);
                }
            });

            TrackableRequest.GetTrackablesAsync(worldStorageServer, (response) =>
            {
                List<Trackable> trackables = response.result;
                foreach (Trackable trackable in trackables)
                {
                    var tracknode = new ARFNodeTrackable(trackable);
@@ -329,6 +333,11 @@ namespace ETSI.ARF.WorldStorage.UI

                    AddElement(tracknode);
                }
            });

            WorldLinkRequest.GetWorldLinksAsync(worldStorageServer, (response) =>
            {
                List<WorldLink> worldLinks = response.result;
                foreach (WorldLink worldLink in worldLinks)
                {
                    var portPair = GetPortsFromWorldLink(worldLink);
@@ -338,7 +347,7 @@ namespace ETSI.ARF.WorldStorage.UI

                    AddElement(edge);
                }

            });
        }

        internal ARFNodeTrackable CreateTrackableNode(Trackable track, float posX, float posY)
@@ -529,14 +538,14 @@ namespace ETSI.ARF.WorldStorage.UI
                switch (typeName)
                {
                    case nameof(Trackable):
                        TrackableRequest.DeleteTrackable(worldStorageServer, elemToRemove.Key);
                        TrackableRequest.DeleteTrackableAsync(worldStorageServer, Guid.Parse(elemToRemove.Key), (response) => { });
                        break;
                    case nameof(WorldAnchor):
                        Debug.Log("delete worldanchor");
                        WorldAnchorRequest.DeleteWorldAnchor(worldStorageServer, elemToRemove.Key);
                        WorldAnchorRequest.DeleteWorldAnchorAsync(worldStorageServer, Guid.Parse(elemToRemove.Key), (response) => { });
                        break;
                    case nameof(WorldLink):
                        WorldLinkRequest.DeleteWorldLink(worldStorageServer, elemToRemove.Key);
                        WorldLinkRequest.DeleteWorldLinkAsync(worldStorageServer, Guid.Parse(elemToRemove.Key), (response) => { });
                        break;
                    default:
                        Debug.Log("oops");
@@ -552,16 +561,18 @@ namespace ETSI.ARF.WorldStorage.UI
                    // POST TRACKABLE
                    if (node is ARFNodeTrackable aRFNodeTrackable)
                    {
                        var posX = new List<String>();
                        var posX = new Collection<String>();
                        posX.Add(aRFNodeTrackable.GetPosition().x.ToString());
                        var posY = new List<String>();
                        var posY = new Collection<String>();
                        posY.Add(aRFNodeTrackable.GetPosition().y.ToString());
                        Trackable trackable = aRFNodeTrackable.trackable;
                        trackable.KeyvalueTags["unityAuthoringPosX"] = posX;
                        trackable.KeyvalueTags["unityAuthoringPosY"] = posY;
                        String uuid = TrackableRequest.AddTrackable(worldStorageServer, trackable);

                        TrackableRequest.CreateTrackableAsync(worldStorageServer, trackable, (response) =>
                        {
                            //change the uuid in its edges, if there is a new edge to be added in the world storage it needs to have the correct uuid
                            String uuid = response.result;

                            uuid = uuid.Replace("\"", "");
                            foreach (ARFEdgeLink edge in aRFNodeTrackable.portIn.connections)
                            {
@@ -574,20 +585,24 @@ namespace ETSI.ARF.WorldStorage.UI
                            aRFNodeTrackable.trackable.UUID = Guid.Parse(uuid);
                            aRFNodeTrackable.GUID = uuid;
                            aRFNodeTrackable.title = trackable.Name;
                        });
                    }

                    // POST WORLDANCHOR
                    if (node is ARFNodeWorldAnchor aRFNodeWorldAnchor)
                    {
                        var posX = new List<String>();
                        var posX = new Collection<String>();
                        posX.Add(aRFNodeWorldAnchor.GetPosition().x.ToString());
                        var posY = new List<String>();
                        var posY = new Collection<String>();
                        posY.Add(aRFNodeWorldAnchor.GetPosition().y.ToString());
                        WorldAnchor worldAnchor = aRFNodeWorldAnchor.worldAnchor;
                        worldAnchor.KeyvalueTags["unityAuthoringPosX"] = posX;
                        worldAnchor.KeyvalueTags["unityAuthoringPosY"] = posY;

                        String uuid = WorldAnchorRequest.AddWorldAnchor(worldStorageServer, worldAnchor);
                        WorldAnchorRequest.CreateWorldAnchorAsync(worldStorageServer, worldAnchor, (response) =>
                        {

                            String uuid = response.result;
                            //change the uuid in its edges, if there is a new edge to be added in the world storage it needs to have the correct uuid
                            uuid = uuid.Replace("\"", "");
                            foreach (ARFEdgeLink edge in aRFNodeWorldAnchor.portIn.connections)
@@ -601,6 +616,7 @@ namespace ETSI.ARF.WorldStorage.UI
                            aRFNodeWorldAnchor.worldAnchor.UUID = Guid.Parse(uuid);
                            aRFNodeWorldAnchor.GUID = uuid;
                            aRFNodeWorldAnchor.title = worldAnchor.Name;
                        });
                    }
                }
                else
@@ -613,27 +629,31 @@ namespace ETSI.ARF.WorldStorage.UI
                    {
                        if (node is ARFNodeTrackable aRFNodeTrackable)
                        {
                            var posX = new List<String>();
                            var posX = new Collection<String>();
                            posX.Add(aRFNodeTrackable.GetPosition().x.ToString());
                            var posY = new List<String>();
                            var posY = new Collection<String>();
                            posY.Add(aRFNodeTrackable.GetPosition().y.ToString());
                            Trackable trackable = aRFNodeTrackable.trackable;
                            trackable.KeyvalueTags["unityAuthoringPosX"] = posX;
                            trackable.KeyvalueTags["unityAuthoringPosY"] = posY;
                            TrackableRequest.UpdateTrackable(worldStorageServer, trackable);
                            TrackableRequest.UpdateTrackableAsync(worldStorageServer, trackable, (response) =>
                            {
                                aRFNodeTrackable.title = trackable.Name;
                            });
                        }
                        if (node is ARFNodeWorldAnchor aRFNodeWorldAnchor)
                        {
                            var posX = new List<String>();
                            var posX = new Collection<String>();
                            posX.Add(aRFNodeWorldAnchor.GetPosition().x.ToString());
                            var posY = new List<String>();
                            var posY = new Collection<String>();
                            posY.Add(aRFNodeWorldAnchor.GetPosition().y.ToString());
                            WorldAnchor worldAnchor = aRFNodeWorldAnchor.worldAnchor;
                            worldAnchor.KeyvalueTags["unityAuthoringPosX"] = posX;
                            worldAnchor.KeyvalueTags["unityAuthoringPosY"] = posY;
                            WorldAnchorRequest.UpdateWorldAnchor(worldStorageServer, worldAnchor);
                            WorldAnchorRequest.UpdateWorldAnchorAsync(worldStorageServer, worldAnchor, (response) =>
                            {
                                aRFNodeWorldAnchor.title = worldAnchor.Name;
                            });
                        }
                    }
                }
@@ -646,16 +666,19 @@ namespace ETSI.ARF.WorldStorage.UI
                    if (!SaveInfo.instance.linkIds.Contains(aRFEdgeLink.GUID))
                    {
                        WorldLink worldLink = aRFEdgeLink.worldLink;
                        string uuid = WorldLinkRequest.AddWorldLink(worldStorageServer, worldLink);
                        WorldLinkRequest.CreateWorldLinkAsync(worldStorageServer, worldLink, (response) =>
                        {
                            string uuid = response.result;
                            uuid = uuid.Replace("\"", "");

                            aRFEdgeLink.worldLink.UUID = Guid.Parse(uuid);
                            aRFEdgeLink.GUID = uuid;
                        });
                    }
                    else if (SaveInfo.instance.elemsToUpdate.Contains(aRFEdgeLink.GUID))
                    {
                        WorldLink worldLink = aRFEdgeLink.worldLink;
                        WorldLinkRequest.UpdateWorldLink(worldStorageServer, worldLink);
                        WorldLinkRequest.UpdateWorldLinkAsync(worldStorageServer, worldLink, (response) => { });
                    }
                    aRFEdgeLink.MarkSaved();
                }
+125 −77
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ using ETSI.ARF.WorldStorage.REST;
using ETSI.ARF.WorldStorage.UI;
using ETSI.ARF.WorldStorage.Editor.Graph;
using ETSI.ARF.OpenAPI.WorldStorage;
using System.Collections.ObjectModel;

namespace ETSI.ARF.WorldStorage.Editor.Windows
{
@@ -210,7 +211,8 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
        //BUILD UI FOR MODIYING THE WORLDANCHOR
        private void BuildWorldAnchorUI()
        {
            if(worldAnchor != null) {
            if (worldAnchor != null)
            {

                //
                //HEADER
@@ -448,9 +450,12 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                    {
                        if (SaveInfo.instance.elemsToUpdate.Contains(worldAnchor.UUID.ToString()) && EditorUtility.DisplayDialog("Reset elements", "Are you sure you want to lose all your changes ?", "Yes", "No"))
                        {
                            worldAnchor = WorldAnchorRequest.GetWorldAnchor(SaveInfo.instance.worldStorageServer, worldAnchor.UUID.ToString());
                            WorldAnchorRequest.GetWorldAnchorAsync(SaveInfo.instance.worldStorageServer, worldAnchor.UUID, (response) =>
                            {
                                worldAnchor =
                                worldAnchorNode.worldAnchor = worldAnchor;
                                ShowWindow(worldAnchorNode);
                            });
                        }
                    }
                    else
@@ -470,7 +475,15 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                            {
                                worldAnchorSize.Add(0);
                            }
                            worldAnchor = new WorldAnchor(Guid.NewGuid(), "DefaultWorldAnchor", Guid.Parse(SaveInfo.instance.worldStorageUser.UUID), localCRS, UnitSystem.CM, worldAnchorSize, new Dictionary<string, List<string>>());
                            worldAnchor = new WorldAnchor("DefaultWorldAnchor")
                            {
                                UUID = Guid.NewGuid(),
                                CreatorUUID = Guid.Parse(SaveInfo.instance.worldStorageUser.UUID),
                                LocalCRS = localCRS,
                                Unit = UnitSystem.CM,
                                WorldAnchorSize = worldAnchorSize,
                                KeyvalueTags = new KeyvalueTagList()
                            };
                            worldAnchorNode.worldAnchor = worldAnchor;
                            ShowWindow(worldAnchorNode);
                        }
@@ -485,21 +498,25 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                    {
                        if (SaveInfo.instance.elemsToUpdate.Contains(worldAnchor.UUID.ToString()))
                        {
                            WorldAnchorRequest.UpdateWorldAnchor(SaveInfo.instance.worldStorageServer, worldAnchor);
                            WorldAnchorRequest.UpdateWorldAnchorAsync(SaveInfo.instance.worldStorageServer, worldAnchor, (response) =>
                            {
                                SaveInfo.instance.elemsToUpdate.Remove(worldAnchor.UUID.ToString());
                            });
                        }
                    }
                    else
                    {
                        var posX = new List<String>();
                        var posX = new Collection<String>();
                        posX.Add(worldAnchorNode.GetPosition().x.ToString());
                        var posY = new List<String>();
                        var posY = new Collection<String>();
                        posY.Add(worldAnchorNode.GetPosition().y.ToString());
                        WorldAnchor worldAnchor = worldAnchorNode.worldAnchor;
                        worldAnchor.KeyvalueTags["unityAuthoringPosX"] = posX;
                        worldAnchor.KeyvalueTags["unityAuthoringPosY"] = posY;

                        String uuid = WorldAnchorRequest.AddWorldAnchor(SaveInfo.instance.worldStorageServer, worldAnchor);
                        WorldAnchorRequest.CreateWorldAnchorAsync(SaveInfo.instance.worldStorageServer, worldAnchor, (response) =>
                        {
                            String uuid = response.result;

                            //change the uuid in its edges, if there is a new edge to be added in the world storage it needs to have the correct uuid
                            uuid = uuid.Replace("\"", "");
@@ -518,6 +535,7 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                            //Add the newly saved World Anchor to the SaveInfo singleton
                            Rect trackPos = new(worldAnchorNode.GetPosition().x, worldAnchorNode.GetPosition().y, 135, 77);
                            SaveInfo.instance.nodePositions[uuid] = trackPos;
                        });
                    }
                    worldAnchorNode.MarkSaved();
                }
@@ -660,18 +678,18 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Format ", GUILayout.Width(50));
                trackable.TrackableEncodingInformation.DataFormat = (EncodingInformationStructure.DataFormatEnum)EditorGUILayout.EnumPopup(trackable.TrackableEncodingInformation.DataFormat);
                trackable.TrackableEncodingInformation.DataFormat = (EncodingInformationStructureDataFormat)EditorGUILayout.EnumPopup(trackable.TrackableEncodingInformation.DataFormat);
                EditorGUILayout.LabelField("Version ", GUILayout.Width(50));
                float floatVersion;
                if (trackable.TrackableEncodingInformation._Version != null)
                if (trackable.TrackableEncodingInformation.Version != null)
                {
                    floatVersion = EditorGUILayout.DelayedFloatField(float.Parse(trackable.TrackableEncodingInformation._Version.Replace(".",",")));
                    floatVersion = EditorGUILayout.DelayedFloatField(float.Parse(trackable.TrackableEncodingInformation.Version.Replace(".", ",")));
                }
                else
                {
                    floatVersion = EditorGUILayout.DelayedFloatField(0);
                }
                trackable.TrackableEncodingInformation._Version = floatVersion.ToString();
                trackable.TrackableEncodingInformation.Version = floatVersion.ToString();
                EditorGUILayout.EndHorizontal();

                /*//trackable payload
@@ -873,9 +891,12 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                    {
                        if (SaveInfo.instance.elemsToUpdate.Contains(trackable.UUID.ToString()) && EditorUtility.DisplayDialog("Reset elements", "Are you sure you want to lose all your changes ?", "Yes", "No"))
                        {
                            trackable = TrackableRequest.GetTrackable(SaveInfo.instance.worldStorageServer, trackable.UUID.ToString());
                            TrackableRequest.GetTrackableAsync(SaveInfo.instance.worldStorageServer, trackable.UUID, (response) =>
                            {
                                trackable = response.result;
                                trackableNode.trackable = trackable;
                                ShowWindow(trackableNode);
                            });
                        }
                    }
                    else
@@ -883,22 +904,37 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                        if (EditorUtility.DisplayDialog("Reset elements", "Are you sure you want to lose all your changes ?", "Yes", "No"))
                        {
                            //generate the Trackables's attributes
                            EncodingInformationStructure trackableEncodingInformation = new EncodingInformationStructure(EncodingInformationStructure.DataFormatEnum.OTHER, "0");
                            EncodingInformationStructure trackableEncodingInformation = new EncodingInformationStructure()
                            {
                                DataFormat = EncodingInformationStructureDataFormat.OTHER,
                                Version = "0"
                            };

                            List<float> localCRS = new();
                            Transform3D localCRS = new Transform3D();
                            for (int i = 0; i < 15; i++)
                            {
                                localCRS.Add(0);
                            }
                            localCRS.Add(1);

                            List<double> trackableSize = new();
                            Size trackableSize = new Size();
                            for (int i = 0; i < 3; i++)
                            {
                                trackableSize.Add(0);
                            }

                            Trackable trackable = new Trackable(Guid.NewGuid(), "Defaulttrackable", Guid.Parse(SaveInfo.instance.worldStorageUser.UUID), TrackableType.OTHER, trackableEncodingInformation, new byte[64], localCRS, UnitSystem.CM, trackableSize, new Dictionary<string, List<string>>());
                            Trackable trackable = new Trackable("DefaultTrackable")
                            {
                                UUID = Guid.NewGuid(),
                                CreatorUUID = Guid.Parse(SaveInfo.instance.worldStorageUser.UUID),
                                TrackableType = TrackableType.OTHER,
                                TrackableEncodingInformation = trackableEncodingInformation,
                                TrackablePayload = new byte[64],
                                LocalCRS = localCRS,
                                Unit = UnitSystem.CM,
                                TrackableSize = trackableSize,
                                KeyvalueTags = new KeyvalueTagList()
                            };
                            trackableNode.trackable = trackable;
                            ShowWindow(trackableNode);
                        }
@@ -913,20 +949,24 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                    {
                        if (SaveInfo.instance.elemsToUpdate.Contains(trackable.UUID.ToString()))
                        {
                            TrackableRequest.UpdateTrackable(SaveInfo.instance.worldStorageServer, trackable);
                            TrackableRequest.UpdateTrackableAsync(SaveInfo.instance.worldStorageServer, trackable, (response) =>
                            {
                                SaveInfo.instance.elemsToUpdate.Remove(trackable.UUID.ToString());
                            });
                        }
                    }
                    else
                    {
                        var posX = new List<String>();
                        var posX = new Collection<String>();
                        posX.Add(trackableNode.GetPosition().x.ToString());
                        var posY = new List<String>();
                        var posY = new Collection<String>();
                        posY.Add(trackableNode.GetPosition().y.ToString());
                        Trackable trackable = trackableNode.trackable;
                        trackable.KeyvalueTags["unityAuthoringPosX"] = posX;
                        trackable.KeyvalueTags["unityAuthoringPosY"] = posY;
                        String uuid = TrackableRequest.AddTrackable(SaveInfo.instance.worldStorageServer, trackable);
                        TrackableRequest.CreateTrackableAsync(SaveInfo.instance.worldStorageServer, trackable, (response) =>
                        {
                            String uuid = response.result;

                            //change the uuid in its edges, if there is a new edge to be added in the world storage it needs to have the correct uuid
                            uuid = uuid.Replace("\"", "");
@@ -945,6 +985,7 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                            //Add the newly saved Trackable to the SaveInfo singleton
                            Rect trackPos = new(trackableNode.GetPosition().x, trackableNode.GetPosition().y, 135, 77);
                            SaveInfo.instance.nodePositions[uuid] = trackPos;
                        });
                    }
                    trackableNode.MarkSaved();
                }
@@ -1138,17 +1179,19 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                    {
                        if (SaveInfo.instance.elemsToUpdate.Contains(worldLink.UUID.ToString()) && EditorUtility.DisplayDialog("Reset elements", "Are you sure you want to lose all your changes ?", "Yes", "No"))
                        {
                            worldLink = WorldLinkRequest.GetWorldLink(SaveInfo.instance.worldStorageServer, worldLink.UUID.ToString());
                            WorldLinkRequest.GetWorldLinkAsync(SaveInfo.instance.worldStorageServer, worldLink.UUID, (response) =>
                        {
                            worldLink = response.result;
                            worldLinkEdge.worldLink = worldLink;
                            ShowWindow(worldLinkEdge);
                        });
                        }
                    }
                    else
                    {
                        if (EditorUtility.DisplayDialog("Reset elements", "Are you sure you want to lose all your changes ?", "Yes", "No"))
                        {

                            List<float> transform = new List<float>();
                            Transform3D transform = new Transform3D();
                            for (int i = 0; i < 15; i++)
                            {
                                transform.Add(0);
@@ -1173,19 +1216,24 @@ namespace ETSI.ARF.WorldStorage.Editor.Windows
                        {
                            if (SaveInfo.instance.elemsToUpdate.Contains(worldLink.UUID.ToString()))
                            {
                                WorldLinkRequest.UpdateWorldLink(SaveInfo.instance.worldStorageServer, worldLink);
                                WorldLinkRequest.UpdateWorldLinkAsync(SaveInfo.instance.worldStorageServer, worldLink, (response) =>
                                {
                                    SaveInfo.instance.elemsToUpdate.Remove(worldLink.UUID.ToString());
                                });
                            }
                        }
                        else
                        {
                            String uuid = WorldLinkRequest.AddWorldLink(SaveInfo.instance.worldStorageServer, worldLink);
                            WorldLinkRequest.CreateWorldLinkAsync(SaveInfo.instance.worldStorageServer, worldLink, (response) =>
                            {
                                String uuid = response.result;

                                //Add the newly saved WorldLink to the SaveInfo singleton
                                uuid = uuid.Replace("\"", "");
                                worldLink.UUID = Guid.Parse(uuid);
                                worldLinkEdge.GUID = uuid;
                                SaveInfo.instance.linkIds.Add(uuid);
                            });
                        }
                        worldLinkEdge.MarkSaved();
                    }
Loading