예제 #1
0
        public ConnectionHandler(DiagramViewModel diagramViewModel, ConnectorViewModel startConnector)
            : base(diagramViewModel)
        {
            StartConnector      = startConnector;
            PossibleConnections = new List <ConnectorViewModel>();
            //InvertApplication.Log("YUP YUP YUP");
            var items = diagramViewModel.GraphItems.OfType <ConnectorViewModel>().ToArray();

            foreach (var connector in items)
            {
                foreach (var strategy in InvertGraphEditor.ConnectionStrategies)
                {
                    if (strategy.Connect(diagramViewModel, StartConnector, connector) != null)
                    {
                        PossibleConnections.Add(connector);
                    }
                }
            }
            foreach (var a in PossibleConnections)
            {
                a.IsMouseOver = true;
            }
        }
예제 #2
0
 public virtual void OnMouseMove(MouseEvent e)
 {
     ConnectorAtMouse = null;
     ViewModelAtMouse = null;
     foreach (var source in DiagramViewModel.GraphItems.Reverse())
     {
         if (source.Bounds.Contains(e.MousePosition))
         {
             if (source is ConnectorViewModel)
             {
                 ConnectorAtMouse = (ConnectorViewModel)source;
             }
             else
             {
                 ViewModelAtMouse = ConnectorAtMouse;
             }
         }
         if (ConnectorAtMouse != null)
         {
             break;
         }
     }
 }
예제 #3
0
 public override void Remove(ConnectorViewModel output, ConnectorViewModel input)
 {
     InvertGraphEditor.DesignerWindow.DiagramViewModel.GraphData.RemoveConnection(output.DataObject as IConnectable, input.DataObject as IConnectable);
 }
        public override ConnectionViewModel Connect(DiagramViewModel diagramViewModel, ConnectorViewModel a, ConnectorViewModel b)
        {
            var typedItem = a.DataObject as GenericTypedChildItem;
            var clsType   = b.DataObject as IClassTypeNode;

            if (clsType != null && typedItem != null)
            {
                if (a.Direction == ConnectorDirection.Output && b.Direction == ConnectorDirection.Input)
                {
                    return(CreateConnection(diagramViewModel, a, b, Apply));
                }
            }
            return(null);

            return(base.Connect(diagramViewModel, a, b));
        }
예제 #5
0
 public override ConnectionViewModel Connect(DiagramViewModel diagramViewModel, ConnectorViewModel a, ConnectorViewModel b)
 {
     if (ConnectionTypes.Any(p => p.CanConnect(a.DataObject as IConnectable, b.DataObject as IConnectable)))
     {
         return(base.Connect(diagramViewModel, a, b));
     }
     return(null);
 }
예제 #6
0
 public override void Remove(ConnectorViewModel output, ConnectorViewModel input)
 {
 }
예제 #7
0
        public override void OnMouseMove(MouseEvent e)
        {
            base.OnMouseMove(e);
            _startPos = StartConnector.Bounds.center;

            _endPos = e.MousePosition;

            endViewModel = ConnectorAtMouse;
            color        = Color.green;

            if (endViewModel == null)
            {
                var nodeAtMouse = ViewModelAtMouse as DiagramNodeViewModel;

                if (nodeAtMouse != null)
                {
                    foreach (var connector in nodeAtMouse.Connectors)
                    {
                        // Skip anything that might still be visible but not "visible"
                        if (nodeAtMouse.IsCollapsed)
                        {
                            if (connector != connector.InputConnector || connector != connector.OutputConnector)
                            {
                                continue;
                            }
                        }
                        ConnectionViewModel connection = null;
                        foreach (var strategy in InvertGraphEditor.ConnectionStrategies)
                        {
                            //try and connect them
                            connection = strategy.Connect(DiagramViewModel, StartConnector, connector);
                            if (connection != null)
                            {
                                break;
                            }
                        }
                        if (connection != null)
                        {
                            CurrentConnection        = connection;
                            _endPos                  = connector.Bounds.center;
                            connector.HasConnections = true;
                            break;
                        }
                    }
                    if (CurrentConnection != null)
                    {
                        // Grab the default connector
                        var adjustedBounds = new Rect(nodeAtMouse.Bounds.x - 9, nodeAtMouse.Bounds.y + 1,
                                                      nodeAtMouse.Bounds.width + 19, nodeAtMouse.Bounds.height + 9);


                        //InvertGraphEditor.PlatformDrawer.DrawStretchBox(adjustedBounds.Scale(InvertGraphEditor.DesignerWindow.Scale),InvertStyles.NodeBackground,20);
                    }
                }
                else
                {
                    CurrentConnection = null;
                }
            }
            else
            {
                foreach (var strategy in InvertGraphEditor.ConnectionStrategies)
                {
                    //try and connect them
                    var connection = strategy.Connect(DiagramViewModel, StartConnector, endViewModel);
                    if (connection != null)
                    {
                        CurrentConnection = connection;
                        break;
                    }
                }
                if (CurrentConnection == null)
                {
                    color = Color.red;
                }
                else
                {
                    _endPos = endViewModel.Bounds.center;
                }
            }
        }
예제 #8
0
        protected static void ApplyInputConfiguration(GraphItemConfiguration inputConfig, IGraphItem dataItem, ConnectorViewModel connector, bool alwaysVisible = false)
        {
            if (connector != null)
            {
                connector.AlwaysVisible = alwaysVisible;
            }

            //var slot = dataItem as IDiagramNodeItem;
            //if (slot != null)
            //{
            //    connector.Validator = slot.ValidateInput;
            //}
        }
예제 #9
0
        public void QueryPossibleConnections(SelectionMenu menu, DiagramViewModel diagramViewModel,
                                             ConnectorViewModel startConnector,
                                             Vector2 mousePosition)
        {
            var currentGraph       = InvertApplication.Container.Resolve <WorkspaceService>().CurrentWorkspace.CurrentGraph;
            var allowedFilterNodes = FilterExtensions.AllowedFilterNodes[currentGraph.CurrentFilter.GetType()];

            foreach (var item in allowedFilterNodes)
            {
                if (item.IsInterface)
                {
                    continue;
                }
                if (item.IsAbstract)
                {
                    continue;
                }

                var node = Activator.CreateInstance(item) as IDiagramNode;
                node.Repository = diagramViewModel.CurrentRepository;
                node.GraphId    = currentGraph.Identifier;

                var vm = InvertGraphEditor.Container.GetNodeViewModel(node, diagramViewModel) as DiagramNodeViewModel;


                if (vm == null)
                {
                    continue;
                }
                vm.IsCollapsed = false;
                var connectors = new List <ConnectorViewModel>();
                vm.GetConnectors(connectors);

                var config = InvertGraphEditor.Container.Resolve <NodeConfigBase>(item.Name);
                var name   = config == null ? item.Name : config.Name;
                foreach (var connector in connectors)
                {
                    foreach (var strategy in InvertGraphEditor.ConnectionStrategies)
                    {
                        var connection = strategy.Connect(diagramViewModel, startConnector, connector);
                        if (connection == null)
                        {
                            continue;
                        }
                        var node1   = node;
                        var message = string.Format("Create {0}", name);
                        //if (!string.IsNullOrEmpty(connector.Name))
                        //{
                        //    message += string.Format(" and connect to {0}", connector.Name);
                        //}
                        var value = new KeyValuePair <IDiagramNode, ConnectionViewModel>(node1, connection);

                        var qaItem = new SelectionMenuItem("Connect", message, () =>
                        {
                            diagramViewModel.AddNode(value.Key, mousePosition);
                            connection.Apply(value.Value as ConnectionViewModel);
                            value.Key.IsSelected = true;
                            value.Key.IsEditing  = true;
                            value.Key.Name       = "";
                        });
                        menu.AddItem(qaItem);
                    }
                }
            }
        }
예제 #10
0
        public void RefreshConnectors()
        {
            if (IsLoading)
            {
                return;
            }
            var remove = GraphItems.OfType <ConnectionViewModel>().ToArray();

            foreach (var item in remove)
            {
                GraphItems.Remove(item);
            }


            var strategies = InvertGraphEditor.ConnectionStrategies;

            var outputs = GraphItems.OfType <ConnectorViewModel>().Where(p => p.Direction == ConnectorDirection.Output).ToArray();
            var inputs  = GraphItems.OfType <ConnectorViewModel>().Where(p => p.Direction != ConnectorDirection.Output).ToArray();

            foreach (var output in outputs)
            {
                foreach (var input in inputs)
                {
                    foreach (var strategy in strategies)
                    {
                        if (strategy.IsConnected(output, input))
                        {
                            var strategy1 = strategy;
                            var output1   = output;
                            var input1    = input;
                            output.HasConnections = true;
                            input.HasConnections  = true;
                            GraphItems.Add(new ConnectionViewModel(this)
                            {
                                ConnectorA = output,
                                ConnectorB = input,
                                Color      = strategy.ConnectionColor,
                                DataObject = output.DataObject,
                                Remove     = (a) =>
                                {
                                    //a.Remove(a);
                                    strategy1.Remove(output1, input1);
                                }
                            });
                        }
                    }
                }
            }
            var connectors = GraphItems.OfType <ConnectorViewModel>().ToArray();

            foreach (var connection in CurrentRepository.All <ConnectionData>())
            {
                ConnectorViewModel startConnector = null;
                ConnectorViewModel endConnector   = null;

                for (int i = 0; i < connectors.Length; i++)
                {
                    if (startConnector != null && endConnector != null)
                    {
                        break;
                    }
                    var p = connectors[i];
                    if (p.Direction == ConnectorDirection.Output && p.Identifier == connection.OutputIdentifier)
                    {
                        startConnector = p;
                    }
                    else if (p.Direction == ConnectorDirection.Input && p.Identifier == connection.InputIdentifier)
                    {
                        endConnector = p;
                    }
                }

//                var startConnector = connectors.FirstOrDefault(p =>  p.Direction == ConnectorDirection.Output && p.Identifier == connection.OutputIdentifier);
//                var endConnector = connectors.FirstOrDefault(p => p.Direction == ConnectorDirection.Input && p.Identifier == connection.InputIdentifier);


                if (startConnector == null || endConnector == null)
                {
                    continue;
                }

                var vm = endConnector.ConnectorFor.DataObject as IDiagramNodeItem;


                startConnector.HasConnections = true;
                endConnector.HasConnections   = true;
                var connection1 = connection;
                GraphItems.Add(new ConnectionViewModel(this)
                {
                    ConnectorA = endConnector,
                    ConnectorB = startConnector,
                    Color      = startConnector.Color,
                    DataObject = connection,
                    Remove     = (a) =>
                    {
                        GraphData.RemoveConnection(a.ConnectorB.DataObject as IConnectable, a.ConnectorA.DataObject as IConnectable);
                    }
                });
            }
            //var endTime = DateTime.Now;
            //var diff = new TimeSpan(endTime.Ticks - startTime.Ticks);
            //Debug.Log(string.Format("{0} took {1} seconds {2} milliseconds", "New Strategy", diff.Seconds, diff.Milliseconds));

            //var connections = new List<ConnectionViewModel>();
            //var connectorInfo = new ConnectorInfo(connectors.ToArray(), this, CurrentRepository);
            //foreach (var strategy in InvertGraphEditor.ConnectionStrategies)
            //{
            //    var startTime = DateTime.Now;
            //    strategy.GetConnections(connections, connectorInfo);
            //    var endTime = DateTime.Now;
            //    var diff = new TimeSpan(endTime.Ticks - startTime.Ticks);
            //    Debug.Log(string.Format("{0} took {1} seconds {2} milliseconds", strategy.GetType().Name, diff.Seconds, diff.Milliseconds));
            //}

            //foreach (var item in connections)
            //{
            //    GraphItems.Add(item);
            //    item.ConnectorA.HasConnections = true;
            //    item.ConnectorB.HasConnections = true;
            //}
        }
        public override ConnectionViewModel Connect(DiagramViewModel diagramViewModel, ConnectorViewModel a, ConnectorViewModel b)
        {
            //if (a.Validator != null)
            //    if (!a.Validator(a.DataObject as IDiagramNodeItem, b.DataObject as IDiagramNodeItem))
            //    {
            //        // Debug.Log("Output validator denied this connection");
            //        return null;
            //    }

            //if (b.Validator != null)
            //    if (!b.Validator(a.DataObject as IDiagramNodeItem, b.DataObject as IDiagramNodeItem))
            //    {
            //        // Debug.Log("Input validator denied this connection");
            //        return null;
            //    }

            return(TryConnect <TOutputData, TInputData>(diagramViewModel, a, b, Apply, CanConnect));
        }