public virtual List <Port> GetCompatiblePorts(IGTFPortModel startPort, NodeAdapter nodeAdapter)
 {
     return(ports.ToList().Where(nap =>
                                 nap.PortModel.Direction != startPort.Direction &&
                                 nap.PortModel.NodeModel != startPort.NodeModel &&
                                 nodeAdapter.GetAdapter(nap.PortModel, startPort) != null)
            .ToList());
 }
Esempio n. 2
0
        void Connect(IEdgeModel edgeModel, IGTFPortModel output, IGTFPortModel input)
        {
            var edge = GraphElementFactory.CreateUI <Edge>(m_GraphView, m_Store, edgeModel as IGTFEdgeModel);

            AddToGraphView(edge);

            m_GraphView.AddPositionDependency(edge.VSEdgeModel);
        }
 void Reset()
 {
     m_Active = false;
     m_Edge   = null;
     m_ConnectedEdgeDragHelper = null;
     m_DetachedPort            = null;
     m_DetachedFromInputPort   = false;
 }
 public CreateEdgeAction(IGTFPortModel inputPortModel, IGTFPortModel outputPortModel,
                         IEnumerable <IGTFEdgeModel> edgeModelsToDelete = null, PortAlignmentType portAlignment = PortAlignmentType.None)
 {
     Assert.IsTrue(inputPortModel.Direction == Direction.Input);
     Assert.IsTrue(outputPortModel.Direction == Direction.Output);
     InputPortModel     = inputPortModel;
     OutputPortModel    = outputPortModel;
     EdgeModelsToDelete = edgeModelsToDelete;
     PortAlignment      = portAlignment;
 }
        public static TState DefaultReducer <TState>(TState previousState, CreateEdgeAction action) where TState : State
        {
            var graphModel = previousState.GraphModel;

            if (action.EdgeModelsToDelete != null)
            {
                graphModel.DeleteElements(action.EdgeModelsToDelete);
            }

            IGTFPortModel outputPortModel = action.OutputPortModel;
            IGTFPortModel inputPortModel  = action.InputPortModel;

            graphModel.CreateEdgeGTF(inputPortModel, outputPortModel);

            return(previousState);
        }
Esempio n. 6
0
        object GetPortSource(IGTFPortModel portModel)
        {
            if (s_PortSources == null)
            {
                s_PortSources = new Dictionary <Type, object>();
            }

            if (s_PortSources.TryGetValue(portModel.PortDataType, out var source))
            {
                return(source);
            }

            Type genericClass     = typeof(PortSource <>);
            Type constructedClass = genericClass.MakeGenericType(portModel.PortDataType);

            source = Activator.CreateInstance(constructedClass);
            s_PortSources[portModel.PortDataType] = source;
            return(source);
        }
Esempio n. 7
0
        public static IGraphElement CreatePort(this ElementBuilder elementBuilder, IStore store, IGTFPortModel model)
        {
            var ui = new Port();

            ui.Setup(model, store, elementBuilder.GraphView);
            return(ui);
        }
Esempio n. 8
0
        public MethodInfo GetAdapter(IGTFPortModel portA, IGTFPortModel portB)
        {
            if (portA == null || portB == null)
            {
                return(null);
            }

            var a = GetPortSource(portA);
            var b = GetPortSource(portB);

            if (a == null || b == null)
            {
                return(null);
            }

            if (s_NodeAdapterDictionary == null)
            {
                s_NodeAdapterDictionary = new Dictionary <int, MethodInfo>();

                // add extension methods
                AppDomain currentDomain = AppDomain.CurrentDomain;
                foreach (Assembly assembly in currentDomain.GetAssemblies())
                {
                    IEnumerable <MethodInfo> methods;

                    try
                    {
                        methods = GetExtensionMethods(assembly, typeof(NodeAdapter));
                    }
                    // Invalid DLLs might raise this exception, simply ignore it
                    catch (ReflectionTypeLoadException)
                    {
                        continue;
                    }

                    foreach (MethodInfo method in methods)
                    {
                        ParameterInfo[] methodParams = method.GetParameters();
                        if (methodParams.Length == 3)
                        {
                            string pa   = methodParams[1].ParameterType + methodParams[2].ParameterType.ToString();
                            int    hash = pa.GetHashCode();
                            if (s_NodeAdapterDictionary.ContainsKey(hash))
                            {
                                Debug.Log("NodeAdapter: multiple extensions have the same signature:\n" +
                                          "1: " + method + "\n" +
                                          "2: " + s_NodeAdapterDictionary[hash]);
                            }
                            else
                            {
                                s_NodeAdapterDictionary.Add(hash, method);
                            }
                        }
                    }
                }
            }

            string s = a.GetType().ToString() + b.GetType();

            return(s_NodeAdapterDictionary.TryGetValue(s.GetHashCode(), out var methodInfo) ? methodInfo : null);
        }
        protected void OnMouseMove(MouseMoveEvent evt)
        {
            // If the left mouse button is not down then return
            if (m_Edge == null)
            {
                return;
            }

            evt.StopPropagation();

            bool alreadyDetached = (m_DetachedPort != null);

            // If one end of the edge is not already detached then
            if (!alreadyDetached)
            {
                float delta = (evt.mousePosition - m_PressPos).sqrMagnitude;

                if (delta < (s_StartDragDistance * s_StartDragDistance))
                {
                    return;
                }

                var graphView    = m_Edge.GetFirstAncestorOfType <GraphView>();
                var outputPortUI = m_Edge.Output.GetUI <Port>(graphView);
                var inputPortUI  = m_Edge.Input.GetUI <Port>(graphView);

                if (outputPortUI == null || inputPortUI == null)
                {
                    return;
                }

                // Determine which end is the nearest to the mouse position then detach it.
                Vector2 outputPos = new Vector2(outputPortUI.GetGlobalCenter().x, outputPortUI.GetGlobalCenter().y);
                Vector2 inputPos  = new Vector2(inputPortUI.GetGlobalCenter().x, inputPortUI.GetGlobalCenter().y);

                float distanceFromOutput = (m_PressPos - outputPos).sqrMagnitude;
                float distanceFromInput  = (m_PressPos - inputPos).sqrMagnitude;

                if (distanceFromInput > 50 * 50 && distanceFromOutput > 50 * 50)
                {
                    return;
                }

                m_DetachedFromInputPort = distanceFromInput < distanceFromOutput;

                IGTFPortModel connectedPort;
                Port          connectedPortUI;

                if (m_DetachedFromInputPort)
                {
                    connectedPort   = m_Edge.Output;
                    connectedPortUI = outputPortUI;

                    m_DetachedPort = m_Edge.Input;
                }
                else
                {
                    connectedPort   = m_Edge.Input;
                    connectedPortUI = inputPortUI;

                    m_DetachedPort = m_Edge.Output;
                }

                // Use the edge drag helper of the still connected port
                m_ConnectedEdgeDragHelper = connectedPortUI.EdgeConnector.edgeDragHelper;
                m_ConnectedEdgeDragHelper.originalEdge = m_Edge;
                m_ConnectedEdgeDragHelper.draggedPort  = connectedPort;
                m_ConnectedEdgeDragHelper.CreateEdgeCandidate(connectedPort.GraphModel);
                m_ConnectedEdgeDragHelper.edgeCandidateModel.EndPoint = evt.mousePosition;

                // Redirect the last mouse down event to active the drag helper

                if (m_ConnectedEdgeDragHelper.HandleMouseDown(m_LastMouseDownEvent))
                {
                    m_Active = true;
                }
                else
                {
                    Reset();
                }

                m_LastMouseDownEvent = null;
            }

            if (m_Active)
            {
                m_ConnectedEdgeDragHelper.HandleMouseMove(evt);
            }
        }
Esempio n. 10
0
 public DropEdgeInEmptyRegionAction(IGTFPortModel portController, Vector2 position, IEnumerable <IGTFEdgeModel> edgesToDelete)
 {
     PortController = portController;
     Position       = position;
     EdgesToDelete  = edgesToDelete;
 }