Commit 3f515d05 authored by Nathan Chambron's avatar Nathan Chambron
Browse files

feat: added indicators when an elem is not in sync with WS

parent 31142395
Loading
Loading
Loading
Loading
+37 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows;
using Org.OpenAPITools.Model;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
@@ -30,6 +31,9 @@ namespace Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph
    {
        public WorldLink worldLink;
        public string GUID;

        public Image savedIcon;

        public ARFEdgeLink()
        {
            var doubleClickManipulator = new Clickable(Clicked);
@@ -37,11 +41,43 @@ namespace Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph
            doubleClickManipulator.activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse, clickCount = 2 });
            this.AddManipulator(doubleClickManipulator);
        }

        public void Clicked()
        {
            Debug.Log(worldLink.ToJson());
            GraphEditorWindow.ShowWindow(this);
        }
        public void MarkUnsaved()
        {
            if (savedIcon == null)
            {
                //the icon to add if the node does not correspond to an element in the server
                Texture2D warningImage = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/ETSI.ARF/ARF World Storage API/Images/cloud.png", typeof(Texture2D));
                savedIcon = new Image
                {
                    image = warningImage
                };
                savedIcon.style.width = 18;
                savedIcon.style.height = 18;
                savedIcon.style.minWidth = 18;
                savedIcon.style.minHeight = 18;
                savedIcon.style.flexGrow = 1;
                savedIcon.style.alignSelf = Align.Center;

            }
            if (!edgeControl.Contains(savedIcon))
            {
                edgeControl.Add(savedIcon);
            }
            tooltip = "This element is not synchronized with the World Storage";
        }

        public void MarkSaved()
        {
            if (edgeControl.Contains(savedIcon))
            {
                edgeControl.Remove(savedIcon);
                tooltip = "";
            }
        }
    }
}
 No newline at end of file
+49 −12
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph;
using ETSI.ARF.WorldStorage.REST;
using UnityEditor;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows;
using System.Linq;

namespace ETSI.ARF.WorldStorage.UI
{
@@ -133,9 +134,7 @@ namespace ETSI.ARF.WorldStorage.UI
                    if (ServerAndLocalDifferent())
                    {
                        SaveInServer();
                    }/*
                    Reload();
                    SaveInfo.instance.toReFrame = true;*/
                    }
                }, (DropdownMenuAction a) => DropdownMenuAction.Status.Normal);
                evt.menu.AppendAction("Reload graph", delegate
                {
@@ -164,10 +163,29 @@ namespace ETSI.ARF.WorldStorage.UI
                        trackableSize.Add(0);
                    }

                    Trackable trackable = new Trackable(Guid.NewGuid(), "Defaulttrackable", Guid.Parse(worldStorageUser.UUID), Trackable.TrackableTypeEnum.OTHER, trackableEncodingInformation, new byte[64], localCRS, UnitSystem.CM, trackableSize, new Dictionary<string, List<string>>());
                    string name = "DefaultTrackable";

                    //trying to add number after default name
                    var defaultNodes = nodes.ToList().Where(node => node.title.StartsWith("DefaultTrackable"));
                    if (defaultNodes.Any())
                    {
                        for (int i = 0; i < defaultNodes.Count(); i++)
                        {
                            Debug.Log($"{i} : " + defaultNodes.ElementAt(i).title);
                            if (!(defaultNodes.Where(node => node.title.EndsWith((i + 1).ToString() + ")")).Any()))
                            {
                                name = name + " (" + (i + 1).ToString() + ")";
                                break;
                            }
                        }                 
                    }

                    Trackable trackable = new Trackable(Guid.NewGuid(), name, Guid.Parse(worldStorageUser.UUID), Trackable.TrackableTypeEnum.OTHER, trackableEncodingInformation, new byte[64], localCRS, UnitSystem.CM, trackableSize, new Dictionary<string, List<string>>());

                    selection.Clear();
                    AddToSelection(CreateTrackableNode(trackable, actualGraphPosition.x, actualGraphPosition.y));
                    var node = CreateTrackableNode(trackable, actualGraphPosition.x, actualGraphPosition.y);
                    node.MarkUnsaved();
                    GraphEditorWindow.ShowWindow((ARFNodeTrackable)node);

                }, (DropdownMenuAction a) => DropdownMenuAction.Status.Normal);
                evt.menu.AppendAction("Create World Anchor", delegate
@@ -186,8 +204,28 @@ namespace ETSI.ARF.WorldStorage.UI
                        worldAnchorSize.Add(0);
                    }

                    WorldAnchor anchor = new WorldAnchor(Guid.NewGuid(), "DefaultWorldAnchor", Guid.Parse(worldStorageUser.UUID), localCRS, UnitSystem.CM, worldAnchorSize, new Dictionary<string, List<string>>());
                    CreateAnchorNode(anchor, actualGraphPosition.x, actualGraphPosition.y);
                    string name = "DefaultWorldAnchor";

                    //trying to add number after default name
                    var defaultNodes = nodes.ToList().Where(node => node.title.StartsWith("DefaultWorldAnchor"));
                    if (defaultNodes.Any())
                    {
                        for (int i = 0; i < defaultNodes.Count(); i++)
                        {
                            if (!(defaultNodes.Where(node => node.title.EndsWith((i + 1).ToString() + ")")).Any()))
                            {
                                name = name + " (" + (i + 1).ToString() + ")";
                                break;
                            }
                        }
                    }

                    WorldAnchor anchor = new WorldAnchor(Guid.NewGuid(), name, Guid.Parse(worldStorageUser.UUID), localCRS, UnitSystem.CM, worldAnchorSize, new Dictionary<string, List<string>>());
                    
                    selection.Clear();
                    var node = CreateAnchorNode(anchor, actualGraphPosition.x, actualGraphPosition.y);
                    node.MarkUnsaved();
                    GraphEditorWindow.ShowWindow((ARFNodeWorldAnchor)node);

                }, (DropdownMenuAction a) => DropdownMenuAction.Status.Normal);
            }
@@ -201,9 +239,6 @@ namespace ETSI.ARF.WorldStorage.UI
                }, (DropdownMenuAction a) => canDeleteSelection ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled);
                evt.menu.AppendSeparator();
            }
            if (evt.target is GraphView)
            {
            }
        }

        public bool ServerAndLocalDifferent()
@@ -585,6 +620,7 @@ namespace ETSI.ARF.WorldStorage.UI
                        }
                    }
                }
                node.MarkSaved();
            }
            foreach (ARFEdgeLink edge in edges)
            {
@@ -604,6 +640,7 @@ namespace ETSI.ARF.WorldStorage.UI
                        WorldLink worldLink = aRFEdgeLink.worldLink;
                        WorldLinkRequest.UpdateWorldLink(worldStorageServer, worldLink);
                    }
                    aRFEdgeLink.MarkSaved();
                }
            }
            SaveInfo.instance.InitNodePos(worldStorageServer, worldStorageUser);
+39 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph;
using System;
using UnityEngine;

namespace ETSI.ARF.WorldStorage.UI
{
@@ -42,9 +43,11 @@ namespace ETSI.ARF.WorldStorage.UI
        public ARFPort portOut;
        public ARFPort portIn;
        public GUID id;

        public Image savedIcon;

        public ARFNode()
        {
            
        }
        public override Port InstantiatePort(Orientation orientation, Direction direction, Port.Capacity capacity, Type type)
        {
@@ -101,6 +104,41 @@ namespace ETSI.ARF.WorldStorage.UI
        }

        public abstract ObjectType GetElemType();
        public void MarkUnsaved()
        {
            if(savedIcon == null)
            {
                //the icon to add if the node does not correspond to an element in the server
                Texture2D warningImage = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/ETSI.ARF/ARF World Storage API/Images/cloud.png", typeof(Texture2D));
                savedIcon = new Image
                {
                    image = warningImage,
                    scaleMode = ScaleMode.ScaleToFit
                };
                savedIcon.style.width = 25;
                savedIcon.style.height = 25;
                savedIcon.style.minWidth = 25;
                savedIcon.style.minHeight = 25;
                savedIcon.style.left = 8;
                savedIcon.style.paddingRight = 8;
                savedIcon.style.alignSelf = Align.Center;

            }
            if (!titleContainer.Contains(savedIcon))
            {
                titleContainer.Insert(0,savedIcon);
            }
            tooltip = "This element is not synchronized with the World Storage";
        }

        public void MarkSaved()
        {
            if (titleContainer.Contains(savedIcon))
            {
                titleContainer.Remove(savedIcon);
                tooltip = "";
            }
        }

    }
}
 No newline at end of file
+4 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ using IO.Swagger.Model;
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows;
using UnityEditor;

namespace ETSI.ARF.WorldStorage.UI
{
@@ -49,7 +50,9 @@ namespace ETSI.ARF.WorldStorage.UI
            colorRectangle.style.height = 160;
            colorRectangle.style.height = 5;
            colorRectangle.style.backgroundColor = new Color(1, 0.31f, 0.31f, 0.9f);
            mainContainer.Insert(1, colorRectangle);
            //get the index of the title container
            int titleIndex = mainContainer.hierarchy.IndexOf(titleContainer);
            mainContainer.Insert(titleIndex+1, colorRectangle);

            /*PORTS*/
            var portIn = GeneratePort(this, Direction.Input, Port.Capacity.Multi);
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ using Org.OpenAPITools.Model;
using System;
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;

namespace Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph
Loading