//public override void GetConnections(List<ConnectionViewModel> connections, ConnectorInfo info)
        //{
        //    base.GetConnections(connections, info);
        //    foreach (var item in info.Outputs.Where(p => p.ConnectorFor.DataObject is ITypedItem))
        //    {
        //        var referenceItem = item.ConnectorFor.DataObject as ITypedItem;
        //        if (referenceItem == null) continue;
        //        var sourceObject = referenceItem.RelatedNode();
        //        if (sourceObject == null) continue;
        //        foreach (var input in info.Inputs.Where(p => p.ConnectorFor.DataObject == sourceObject))
        //        {
        //            connections.Add(new ConnectionViewModel(info.DiagramViewModel)
        //            {
        //                Remove = Remove,
        //                Name = item.Name + "->" + input.Name,
        //                ConnectorA = item,
        //                ConnectorB = input,
        //                Color = new Color(0.3f, 0.4f, 0.75f)
        //            });
        //        }
        //    }
        //}

        public override void Remove(ConnectionViewModel connectionViewModel)
        {
            base.Remove(connectionViewModel);
            var obj = connectionViewModel.ConnectorA.ConnectorFor.DataObject as ITypedItem;

            if (obj != null)
            {
                obj.RelatedType = null;
            }
        }
Ejemplo n.º 2
0
        public void QueryContextMenu(ContextMenuUI ui, MouseEvent evt, params object[] obj)
        {
            var connector = obj.FirstOrDefault() as ConnectorViewModel;

            if (connector != null)
            {
                var connections =
                    InvertGraphEditor.CurrentDiagramViewModel.GraphItems.OfType <ConnectionViewModel>()
                    .Where(p => p.ConnectorA == connector || p.ConnectorB == connector).ToArray();

                foreach (var connection in connections)
                {
                    ConnectionViewModel connection1 = connection;
                    ui.AddCommand(new ContextMenuItem()
                    {
                        Title   = string.Format("Remove {0}", connection1.Name),
                        Group   = "Remove",
                        Command = new LambdaCommand("Remove Connection", () => { connection1.Remove(connection1); })
                    });
                }
            }
        }
        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;
                }
            }
        }