Skip to content
Snippets Groups Projects
Commit 15284940 authored by Nathan Chambron's avatar Nathan Chambron
Browse files

first commit

parent 8ccb356a
No related branches found
No related tags found
1 merge request!4Add GraphView module & the World Storage inspector window into the main branch
Showing
with 2024 additions and 683 deletions
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;
namespace Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph
{
public class ARFEdgeLink : Edge
{
public WorldLink worldLink;
public string GUID;
public ARFEdgeLink()
{
var doubleClickManipulator = new Clickable(clicked);
doubleClickManipulator.activators.Clear();
doubleClickManipulator.activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse, clickCount = 2 });
this.AddManipulator(doubleClickManipulator);
this.style.color = new Color(239, 239, 239);
}
public void clicked()
{
NodeEditorWindow.ShowWindow(this);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 81a94cf483be20040aa4fe8d9f93d5c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 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 2022
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
namespace ETSI.ARF.WorldStorage.UI
{
public class ARFNode : Node
{
public string GUID;
public string text;
public bool entryPoint = false;
public ARFNode()
{
}
}
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 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 2022
//
#define USING_OPENAPI_GENERATOR // alt. is Swagger
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using ETSI.ARF.WorldStorage.REST;
#if USING_OPENAPI_GENERATOR
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
#else
using IO.Swagger.Api;
using IO.Swagger.Model;
#endif
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph;
using System;
namespace ETSI.ARF.WorldStorage.UI
{
public class ARFNode : Node
{
public string GUID;
public bool entryPoint = false;
public Port portOut;
public Port portIn;
public GUID id;
public ARFNode()
{
}
public override Port InstantiatePort(Orientation orientation, Direction direction, Port.Capacity capacity, Type type)
{
switch (direction)
{
case Direction.Input:
portIn = Port.Create<ARFEdgeLink>(orientation, direction, capacity, type);
return portIn;
case Direction.Output:
portOut = Port.Create<ARFEdgeLink>(orientation, direction, capacity, type);
return portOut;
default:
return null;
}
}
public void DisconnectAllPorts(ARFGraphView graphView)
{
DisconnectInputPorts(graphView);
DisconnectOutputPorts(graphView);
}
private void DisconnectInputPorts(ARFGraphView graphView)
{
DisconnectPorts(inputContainer, graphView);
}
private void DisconnectOutputPorts(ARFGraphView graphView)
{
DisconnectPorts(outputContainer, graphView);
}
private void DisconnectPorts(VisualElement container, ARFGraphView graphView)
{
foreach (Port port in container.Children())
{
if (!port.connected)
{
continue;
}
graphView.DeleteElements(port.connections);
}
}
public Port GeneratePort(ARFNode node, Direction portDirection, Port.Capacity capacity = Port.Capacity.Multi)
{
return node.InstantiatePort(Orientation.Horizontal, portDirection, capacity, typeof(int)); // dummy
}
}
}
\ No newline at end of file
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 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 2022
//
#define USING_OPENAPI_GENERATOR // alt. is Swagger
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using ETSI.ARF.WorldStorage.REST;
#if USING_OPENAPI_GENERATOR
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
#else
using IO.Swagger.Api;
using IO.Swagger.Model;
#endif
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph;
namespace ETSI.ARF.WorldStorage.UI
{
public class ARFNodeTrackable : ARFNode
{
public Trackable trackable;
public ARFNodeTrackable(Trackable trackable)
{
this.trackable = trackable;
this.GUID = trackable.UUID.ToString();
this.title = trackable.Name;
/*COLOR*/
var colorRectangle = new VisualElement();
colorRectangle.style.height = 160;
colorRectangle.style.height = 5;
colorRectangle.style.backgroundColor = new Color(0.9f, 0.78f, 0.54f, 0.9f);
mainContainer.Insert(1, colorRectangle);
/*PORTS*/
var portIn = GeneratePort(this, Direction.Input, Port.Capacity.Multi);
portIn.portColor = new Color(0.77f, 0.77f, 0.77f, 0.77f);
portIn.portName = "Target"; // "Input"
portIn.AddManipulator(new EdgeConnector<ARFEdgeLink>(new WorldLinkListener()));
inputContainer.Add(portIn);
var portOut = GeneratePort(this, Direction.Output, Port.Capacity.Multi);
portOut.portColor = new Color(0.77f, 0.77f, 0.77f, 0.77f);
portOut.portName = "Source"; // "Output";
portOut.AddManipulator(new EdgeConnector<ARFEdgeLink>(new WorldLinkListener())); ;
outputContainer.Add(portOut);
RefreshExpandedState();
RefreshPorts();
/*MANIPULATOR*/
var doubleClickManipulator = new Clickable(clicked);
doubleClickManipulator.activators.Clear();
doubleClickManipulator.activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse, clickCount = 2 });
this.AddManipulator(doubleClickManipulator);
}
public void clicked()
{
NodeEditorWindow.ShowWindow(this);
Debug.Log(trackable.ToString());
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 01bfb1a0a4a788c48a6c6675034ba8d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 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 2022
//
#define USING_OPENAPI_GENERATOR // alt. is Swagger
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using ETSI.ARF.WorldStorage.REST;
#if USING_OPENAPI_GENERATOR
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
#else
using IO.Swagger.Api;
using IO.Swagger.Model;
#endif
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows;
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph;
namespace ETSI.ARF.WorldStorage.UI
{
public class ARFNodeWorldAnchor : ARFNode
{
public WorldAnchor worldAnchor;
public ARFNodeWorldAnchor(WorldAnchor worldAnchor)
{
this.worldAnchor = worldAnchor;
this.GUID = worldAnchor.UUID.ToString();
this.title = worldAnchor.Name;
/*COLOR*/
var colorRectangle = new VisualElement();
colorRectangle.style.height = 160;
colorRectangle.style.height = 5;
colorRectangle.style.backgroundColor = new Color(0.76f, 0.9f, 0.46f, 0.9f);
mainContainer.Insert(1, colorRectangle);
/*PORTS*/
var portIn = GeneratePort(this, Direction.Input, Port.Capacity.Multi);
portIn.portColor = new Color(0.77f,0.77f,0.77f, 0.77f);
portIn.portName = "Target"; // "Input";
portIn.AddManipulator(new EdgeConnector<ARFEdgeLink>(new WorldLinkListener()));
inputContainer.Add(portIn);
var portOut = GeneratePort(this, Direction.Output, Port.Capacity.Multi);
portOut.portColor = new Color(0.77f, 0.77f, 0.77f, 0.77f);
portOut.portName = "Source"; // "Output";
portOut.AddManipulator(new EdgeConnector<ARFEdgeLink>(new WorldLinkListener()));
outputContainer.Add(portOut);
RefreshExpandedState();
RefreshPorts();
/*MANIPULATOR*/
var doubleClickManipulator = new Clickable(clicked);
doubleClickManipulator.activators.Clear();
doubleClickManipulator.activators.Add(new ManipulatorActivationFilter { button = MouseButton.LeftMouse, clickCount = 2 });
this.AddManipulator(doubleClickManipulator);
}
public void clicked()
{
Debug.Log(worldAnchor.ToString());
NodeEditorWindow.ShowWindow(this);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 21e22c1ed011b7a4da95fad83be1d9fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -3,7 +3,10 @@ guid: 8dd64e8d8a545ab45b424402550b55a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
defaultReferences:
- m_ViewDataDictionary: {instanceID: 0}
- worldStorageServer: {fileID: 11400000, guid: 3a9ba82f4e8dd124ca2b005861c64d01, type: 2}
- worldStorageUser: {fileID: 11400000, guid: c0696089e4a855b46ad490437919b1e8, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
......
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows;
using ETSI.ARF.WorldStorage;
using ETSI.ARF.WorldStorage.UI;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
namespace Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph
{
public class WorldLinkListener : IEdgeConnectorListener
{
public void OnDrop(GraphView graphView, Edge edge)
{
ARFNode fromNode = edge.output.node as ARFNode;
ARFNode toNode = edge.input.node as ARFNode;
NodeEditorWindow.ShowWindow((ARFEdgeLink)edge);
//WorldLinkWindow.preFill(fromNode, toNode);
}
public void OnDropOutsidePort(Edge edge, Vector2 position)
{
Debug.Log("OnDropOutsidePort");
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 54dbfcfdc75de1b46bc7da09df52db34
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Graph;
using ETSI.ARF.WorldStorage;
using ETSI.ARF.WorldStorage.UI;
using Org.OpenAPITools.Model;
using System;
using UnityEditor;
using UnityEngine;
namespace Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows
{
public class NodeEditorWindow : EditorWindow
{
public enum GraphEditorType
{
TRACKABLE,
WORLDANCHOR,
WORLDLINK
}
public GraphEditorType type;
// UI stuffs
private Vector2 scrollPos;
static public NodeEditorWindow winSingleton;
public static void ShowWindow(ARFNodeTrackable trackableNode)
{
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
winSingleton = GetWindow<NodeEditorWindow>("Trackable Editor", true, inspectorType);
winSingleton.type = GraphEditorType.TRACKABLE;
}
public static void ShowWindow(ARFNodeWorldAnchor worldAnchorNode)
{
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
winSingleton = GetWindow<NodeEditorWindow>("Anchor Editor", true, inspectorType);
winSingleton.type = GraphEditorType.WORLDANCHOR;
}
public static void ShowWindow(ARFEdgeLink graphEdge)
{
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
winSingleton = GetWindow<NodeEditorWindow>("Link Editor", true, inspectorType);
winSingleton.type = GraphEditorType.WORLDLINK;
}
public void OnGUI()
{
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true));
switch (type)
{
case GraphEditorType.WORLDLINK:
GUILayout.Label("link");
break;
case GraphEditorType.TRACKABLE:
GUILayout.Label("tra");
break;
case GraphEditorType.WORLDANCHOR:
GUILayout.Label("wa");
break;
default:
break;
}
EditorGUILayout.EndScrollView();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: e219817d65c8b1f40ad85e6185e89e92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -26,7 +26,8 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using ETSI.ARF.WorldStorage.REST;
using System;
#if USING_OPENAPI_GENERATOR
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
......@@ -66,8 +67,15 @@ namespace ETSI.ARF.WorldStorage.UI
private Color ori;
private GUIStyle gsTest;
//graph params to generate the node
public bool useCoord;
public float nodePosX = 0;
public float nodePosY = 0;
public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
{
{
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
GetWindow<TrackableWindow>("Menu Editor", true, inspectorType);
winSingleton = EditorWindow.GetWindow(typeof(TrackableWindow), false, WorldStorageWindow.winName) as TrackableWindow;
winSingleton.worldStorageServer = ws;
winSingleton.worldStorageUser = user;
......@@ -184,8 +192,18 @@ namespace ETSI.ARF.WorldStorage.UI
if (string.IsNullOrEmpty(UUID) || UUID == "0") UUID = System.Guid.Empty.ToString();
Trackable obj = GenerateTrackable();
UUID = TrackableRequest.AddTrackable(worldStorageServer, obj);
WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
if (WorldStorageWindow.WorldStorageWindowSingleton != null)
{
WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
}
if (GraphWindow.graphWindowSingleton != null)
{
UUID = UUID.Replace("\"", "");
GraphWindow.graphWindowSingleton.createTrackableNode(UUID, nodePosX, nodePosY);
}
Close();
}
GUI.backgroundColor = WorldStorageWindow.arfColors[2];
......@@ -198,8 +216,16 @@ namespace ETSI.ARF.WorldStorage.UI
Trackable obj = GenerateTrackable();
UUID = TrackableRequest.UpdateTrackable(worldStorageServer, obj);
}
WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
if (WorldStorageWindow.WorldStorageWindowSingleton != null)
{
WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
}
if (GraphWindow.graphWindowSingleton != null)
{
GraphWindow.graphWindowSingleton.Reload();
}
Close();
}
// ###########################################################
......@@ -212,8 +238,16 @@ namespace ETSI.ARF.WorldStorage.UI
creatorUUID = System.Guid.Empty.ToString();
type = Trackable.TrackableTypeEnum.OTHER;
unit = UnitSystem.CM;
WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
if (WorldStorageWindow.WorldStorageWindowSingleton != null)
{
WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
}
if (GraphWindow.graphWindowSingleton != null)
{
GraphWindow.graphWindowSingleton.Reload();
}
Close();
}
GUI.backgroundColor = ori;
......@@ -283,7 +317,15 @@ namespace ETSI.ARF.WorldStorage.UI
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);
Trackable t = new Trackable(_uuid, customName, _creator, type, trackableEncodingInformation, trackablePayload, _localCRS, unit, _trackableSize, keyValueTags);
var posX = new List<String>();
posX.Add(nodePosX.ToString());
t.KeyvalueTags["unityAuthoringPosX"] = posX;
var posY = new List<String>();
posY.Add(nodePosY.ToString());
t.KeyvalueTags["unityAuthoringPosY"] = posY;
return t;
}
}
......
......@@ -3,7 +3,10 @@ guid: 229d5ea484d30f945b9318581fb4f2da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
defaultReferences:
- m_ViewDataDictionary: {instanceID: 0}
- worldStorageServer: {fileID: 11400000, guid: 4f997253243de534dad12937f1284975, type: 2}
- worldStorageUser: {instanceID: 0}
executionOrder: 0
icon: {instanceID: 0}
userData:
......
......@@ -26,7 +26,8 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using ETSI.ARF.WorldStorage.REST;
using System;
#if USING_OPENAPI_GENERATOR
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
......@@ -63,8 +64,15 @@ namespace ETSI.ARF.WorldStorage.UI
private Color ori;
private GUIStyle gsTest;
//graph params to generate the node
public bool useCoord;
public float nodePosX = 0;
public float nodePosY = 0;
public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
{
{
Type inspectorType = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
GetWindow<WorldAnchorWindow>("WorldAnchor Editor", true, inspectorType);
winSingleton = EditorWindow.GetWindow(typeof(WorldAnchorWindow), false, WorldStorageWindow.winName) as WorldAnchorWindow;
winSingleton.worldStorageServer = ws;
winSingleton.worldStorageUser = user;
......@@ -162,8 +170,17 @@ namespace ETSI.ARF.WorldStorage.UI
if (string.IsNullOrEmpty(UUID) || UUID == "0") UUID = System.Guid.Empty.ToString();
WorldAnchor obj = GenerateWorldAnchor();
UUID = WorldAnchorRequest.AddWorldAnchor(worldStorageServer, obj);
WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
if (WorldStorageWindow.WorldStorageWindowSingleton != null)
{
WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
}
if (GraphWindow.graphWindowSingleton != null)
{
UUID = UUID.Replace("\"", "");
GraphWindow.graphWindowSingleton.createAnchorNode(UUID, nodePosX, nodePosY);
}
Close();
}
GUI.backgroundColor = WorldStorageWindow.arfColors[2];
......@@ -174,10 +191,18 @@ namespace ETSI.ARF.WorldStorage.UI
if (!string.IsNullOrEmpty(UUID) && UUID != "0")
{
WorldAnchor obj = GenerateWorldAnchor();
UUID = WorldAnchorRequest.UpdateWorldAnchor(worldStorageServer, obj);
WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
UUID = WorldAnchorRequest.UpdateWorldAnchor(worldStorageServer, obj);
if (WorldStorageWindow.WorldStorageWindowSingleton != null)
{
WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
}
if (GraphWindow.graphWindowSingleton != null)
{
GraphWindow.graphWindowSingleton.Reload();
}
}
Close();
}
// ###########################################################
......@@ -189,8 +214,16 @@ namespace ETSI.ARF.WorldStorage.UI
UUID = System.Guid.Empty.ToString();
creatorUUID = System.Guid.Empty.ToString();
unit = UnitSystem.CM;
WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
if (WorldStorageWindow.WorldStorageWindowSingleton != null)
{
WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
}
if (GraphWindow.graphWindowSingleton != null)
{
GraphWindow.graphWindowSingleton.Reload();
}
Close();
}
GUI.backgroundColor = ori;
......@@ -239,9 +272,9 @@ namespace ETSI.ARF.WorldStorage.UI
#else
List<double?> trackableDimension = new List<double?>();
#endif
_worldAnchorSize.Add(worldAnchorSize.x);
_worldAnchorSize.Add(worldAnchorSize.x);
_worldAnchorSize.Add(worldAnchorSize.y);
_worldAnchorSize.Add(worldAnchorSize.z);
Debug.Log("Created dimension");
Matrix4x4 localCRS = new Matrix4x4();
......@@ -256,7 +289,15 @@ namespace ETSI.ARF.WorldStorage.UI
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);
WorldAnchor t = new WorldAnchor(_uuid, customName, _creator, _localCRS, unit, _worldAnchorSize, keyValueTags);
var posX = new List<String>();
posX.Add(nodePosX.ToString());
t.KeyvalueTags["unityAuthoringPosX"] = posX;
var posY = new List<String>();
posY.Add(nodePosY.ToString());
t.KeyvalueTags["unityAuthoringPosY"] = posY;
return t;
}
}
......
using ETSI.ARF.WorldStorage;
using ETSI.ARF.WorldStorage.REST;
using ETSI.ARF.WorldStorage.UI;
using Org.OpenAPITools.Model;
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace Assets.ETSI.ARF.ARF_World_Storage_API.Editor.Windows
{
public class WorldGraphWindow : EditorWindow
{
[HideInInspector] public WorldStorageServer worldStorageServer;
[HideInInspector] public WorldStorageUser worldStorageUser;
private ARFGraphView myGraph;
[MenuItem("ARFWorldStorage/Edit Graph...")]
public static void ShowWindow()
{
GetWindow<WorldGraphWindow>("Graph Editor", true, typeof(SceneView));
}
public void OnEnable()
{
if (SaveInfo.instance.nodePositions == null)
{
SaveInfo.instance.initNodePos(worldStorageServer);
}
rootVisualElement.Add(GenerateToolbar());
ConstructGraphView();
myGraph.style.top = Length.Percent(11);
rootVisualElement.Add(myGraph);
}
//initiate the graphView Attribute
public void ConstructGraphView()
{
myGraph = new ARFGraphView
{
name = "ARF Graph",
worldStorageServer = worldStorageServer,
worldStorageUser = worldStorageUser
};
//top offset so that the graph does'nt overlap with the rest of the ui
myGraph.style.top = Length.Percent(11);
myGraph.paintWorldStorage();
myGraph.StretchToParentSize();
SaveInfo.instance.toReFrame = true;
}
void OnGUI()
{
EditorGUILayout.BeginVertical();
EditorGUILayout.Space(24);
EditorGUI.BeginChangeCheck();
worldStorageServer = (WorldStorageServer)EditorGUILayout.ObjectField("World Storage Server", worldStorageServer, typeof(WorldStorageServer), false, GUILayout.Width(500));
if (EditorGUI.EndChangeCheck())
{
myGraph.saveElemPositionsInServer();
rootVisualElement.Remove(myGraph);
SaveInfo.instance.initNodePos(worldStorageServer);
ConstructGraphView();
myGraph.style.top = Length.Percent(11);
rootVisualElement.Add(myGraph);
}
//reframe all elements to see them all
if (SaveInfo.instance.toReFrame)
{
myGraph.FrameAllElements();
SaveInfo.instance.toReFrame = false;
}
EditorGUILayout.EndVertical();
}
private bool localAndServerDifferent()
{
foreach (ARFNode node in myGraph.nodes)
{
float nodeX = node.GetPosition().x;
float nodeY = node.GetPosition().y;
if (SaveInfo.instance.nodePositions.ContainsKey(node.GUID)){
float dataX = SaveInfo.instance.nodePositions[node.GUID].x;
float dataY = SaveInfo.instance.nodePositions[node.GUID].y;
if ((nodeX != dataX) || (nodeY != dataY))
{
return true;
}
}
else
{
return true;
}
}
return false;
}
//generate the window's top toolbar
private Toolbar GenerateToolbar()
{
var toolbar = new Toolbar();
var createNodeT = new Button(clickEvent: () =>
{
TrackableWindow.ShowWindow(worldStorageServer, worldStorageUser);
TrackableWindow.winSingleton.nodePosX = 0;
TrackableWindow.winSingleton.nodePosY = 0;
});
createNodeT.text = "Create Trackable";
toolbar.Add(createNodeT);
var createNodeWA = new Button(clickEvent: () =>
{
WorldAnchorWindow.ShowWindow(worldStorageServer, worldStorageUser);
WorldAnchorWindow.winSingleton.nodePosX = 0;
WorldAnchorWindow.winSingleton.nodePosY = 0;
});
createNodeWA.text = "Create World Anchor";
toolbar.Add(createNodeWA);
toolbar.Add(new ToolbarSpacer()
{
flex = true
});
var save = new Button(clickEvent: () =>
{
myGraph.saveElemPositionsInServer();
})
{
text = "Save"
};
toolbar.Add(save);
return toolbar;
}
}
public class SaveInfo : ScriptableSingleton<SaveInfo>
{
[SerializeField]
public Dictionary<String, Rect> nodePositions;
public List<String> linkIds;
public List<String> elemsToRemove;
//keep the info of the graph reframe
public Boolean toReFrame = false;
public WorldStorageServer worldStorageServer;
public void initNodePos(WorldStorageServer server)
{
worldStorageServer = server;
instance.nodePositions = new Dictionary<string, Rect>();
foreach (Trackable track in TrackableRequest.GetAllTrackables(worldStorageServer))
{
if (track.KeyvalueTags.ContainsKey("unityAuthoringPosX") && track.KeyvalueTags.ContainsKey("unityAuthoringPosY"))
{
var posX = RoundToNearestHalf(float.Parse(track.KeyvalueTags["unityAuthoringPosX"][0]));
var posY = RoundToNearestHalf(float.Parse(track.KeyvalueTags["unityAuthoringPosY"][0]));
Rect trackPos = new Rect(posX, posY, 135, 77);
instance.nodePositions[track.UUID.ToString()] = trackPos;
}
else
{
Rect trackPos = new Rect(0, 0, 135, 77);
instance.nodePositions[track.UUID.ToString()] = trackPos;
}
}
foreach (WorldAnchor wa in WorldAnchorRequest.GetAllWorldAnchors(worldStorageServer))
{
if (wa.KeyvalueTags.ContainsKey("unityAuthoringPosX") && wa.KeyvalueTags.ContainsKey("unityAuthoringPosY"))
{
var posX = RoundToNearestHalf(float.Parse(wa.KeyvalueTags["unityAuthoringPosX"][0]));
var posY = RoundToNearestHalf(float.Parse(wa.KeyvalueTags["unityAuthoringPosY"][0]));
Rect waPos = new Rect(posX, posY, 135, 77);
instance.nodePositions[wa.UUID.ToString()] = waPos;
}
else
{
Rect trackPos = new Rect(0, 0, 135, 77);
instance.nodePositions[wa.UUID.ToString()] = trackPos;
}
}
instance.linkIds = new List<string>();
foreach (WorldLink link in WorldLinkRequest.GetAllWorldLinks(worldStorageServer))
{
instance.linkIds.Add(link.UUID.ToString());
}
instance.toReFrame = true;
instance.elemsToRemove = new List<string>();
}
//method to predict the position of a node (the float that will be saved in the PositionInfo singleton)
public static float RoundToNearestHalf(float a)
{
return a = Mathf.Round(a * 2f) * 0.5f;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2c1a0c92306453d46897c1af6cb5c2f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_ViewDataDictionary: {instanceID: 0}
- worldStorageServer: {fileID: 11400000, guid: 777684ed8f62c9d408a1813e8382c676, type: 2}
- worldStorageUser: {fileID: 11400000, guid: c0696089e4a855b46ad490437919b1e8, type: 2}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment