コード例 #1
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);
 }
コード例 #2
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;
            //}
        }
コード例 #3
0
 public override void Remove(ConnectorViewModel output, ConnectorViewModel input)
 {
 }
コード例 #4
0
        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));
        }
コード例 #5
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;
            //}
        }
コード例 #6
0
 public override void Remove(ConnectorViewModel output, ConnectorViewModel input)
 {
     InvertGraphEditor.DesignerWindow.DiagramViewModel.GraphData.RemoveConnection(output.DataObject as IConnectable, input.DataObject as IConnectable);
 }
コード例 #7
0
        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));
        }