示例#1
0
        /// <summary>
        /// Initializes a new constructor for <see cref="LineRoutingVM"/> class.
        /// </summary>
        public LineRoutingVM()
        {
            //Initialize the nodes and connectors collection
            this.Nodes      = new ObservableCollection <RoutingNodeViewModel>();
            this.Connectors = new ObservableCollection <ConnectorViewModel>();

            //Enable bridging and routing constraints.
            this.Constraints = GraphConstraints.Default | GraphConstraints.Bridging | GraphConstraints.Routing;

            //Initialize the command to bring the elements to the center of the page.
            ViewPortChangedCommand = new DelegateCommand(OnViewPortChangedCommandExecute);

            //Create and add nodes
            RoutingNodeViewModel start     = CreateNodes("start", 115, 110, "Start", "#D5535D", "Terminator");
            RoutingNodeViewModel process   = CreateNodes("process", 115, 255, "Process", "#65B091", "Process");
            RoutingNodeViewModel document  = CreateNodes("document", 115, 400, "Document", "#5BA5F0", "Document");
            RoutingNodeViewModel decision  = CreateNodes("decision", 390, 110, "Decision", "#9A8AF7", "Decision");
            RoutingNodeViewModel document2 = CreateNodes("document2", 390, 255, "Document", "#5BA5F0", "Document");
            RoutingNodeViewModel end       = CreateNodes("end", 390, 400, "End", "#D5535D", "Terminator");
            RoutingNodeViewModel process2  = CreateNodes("process2", 640, 110, "Process", "#65B091", "Process");
            RoutingNodeViewModel card      = CreateNodes("card", 640, 255, "Card", "#76C3F0", "Card");

            //Add Node to Nodes property of the Diagram
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(start);
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(process);
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(document);
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(decision);
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(document2);
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(end);
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(process2);
            (this.Nodes as ObservableCollection <RoutingNodeViewModel>).Add(card);

            CreateNodePort(start, "startPort1", 0, 0.5);
            CreateNodePort(document, "documentPort1", 0, 0.5);
            CreateNodePort(card, "cardPort1", 1, 0.5);
            CreateNodePort(card, "cardPort2", 0.5, 1);

            //Create and add connectors
            CreateConnectors("start", "process", null, null);
            CreateConnectors("process", "document", null, null);
            CreateConnectors("document", "end", null, null);
            CreateConnectors("start", "decision", null, null);
            CreateConnectors("decision", "process2", null, null);
            CreateConnectors("process2", "card", null, null);
            CreateConnectors("process", "document2", null, null);
            CreateConnectors("document2", "card", null, null);
            CreateConnectors("start", "card", "startPort1", "cardPort1");
            CreateConnectors("card", "document", "cardPort2", "documentPort1");
        }
示例#2
0
        /// <summary>
        /// Create and add the nodes.
        /// </summary>
        /// <param name="id">ID of the Node</param>
        /// <param name="offsetx">Offset-x value of the node.</param>
        /// <param name="offsety">Offset-y value of the node.</param>
        /// <param name="text">Text to the node.</param>
        private RoutingNodeViewModel CreateNodes(string id, double offsetx, double offsety, string text, string fillColor, string shape)
        {
            RoutingNodeViewModel node = new RoutingNodeViewModel()
            {
                ID          = id,
                UnitHeight  = 50,
                UnitWidth   = 120,
                OffsetX     = offsetx,
                OffsetY     = offsety,
                Shape       = resourceDictionary[shape],
                Fill        = new SolidColorBrush((Color)ColorConverter.ConvertFromString(fillColor)),
                Annotations = new ObservableCollection <IAnnotation>()
                {
                    new TextAnnotationViewModel()
                    {
                        Text       = text,
                        FontSize   = 15,
                        Foreground = new SolidColorBrush(Colors.White),
                    }
                },
            };

            return(node);
        }