Exemplo n.º 1
0
        private void OnSceneMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                var position = this.zoomControl.TranslatePoint(e.GetPosition(this.zoomControl), this.graphArea);
                if (this.elementProvider.Element?.InstanceMetatype == Repo.Metatype.Node)
                {
                    this.position = position;
                    this.CreateNewNode(this.elementProvider.Element);
                    this.ElementManipulationDone?.Invoke(this, EventArgs.Empty);
                }

                if (this.elementProvider.Element?.InstanceMetatype == Repo.Metatype.Edge)
                {
                    var vertexData    = new NodeViewModel();
                    var virtualVertex = this.AddVirtualVertexControl(vertexData);
                    if (this.previosVertex != null)
                    {
                        var virtualEdgeData    = new EdgeViewModel(previosVertex.GetDataVertex <NodeViewModel>(), virtualVertex.GetDataVertex <NodeViewModel>());
                        var virtualEdgeControl = new EdgeControl(previosVertex, virtualVertex, virtualEdgeData);
                        this.graphArea.AddEdge(virtualEdgeData, virtualEdgeControl);
                        this.editorManager.DestroyVirtualEdge();
                        this.previosVertex = null;
                        this.ElementManipulationDone?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        this.editorManager.CreateVirtualEdge(virtualVertex, virtualVertex.GetPosition());
                        this.previosVertex = virtualVertex;
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Should be replaced
        public void InitModel(string modelName)
        {
            var model = this.model.Repo.Model(modelName);

            if (model == null)
            {
                return;
            }

            foreach (var node in model.Nodes)
            {
                this.CreateNodeWithoutPos(node);
            }

            foreach (var edge in model.Edges)
            {
                var sourceNode = edge.From as INode;
                var targetNode = edge.To as INode;
                if (sourceNode == null || targetNode == null)
                {
                    // Editor does not support edges linked to edges. Yet.
                    continue;
                }

                if (this.DataGraph.Vertices.Count(v => v.Node == sourceNode) == 0 ||
                    this.DataGraph.Vertices.Count(v => v.Node == targetNode) == 0)
                {
                    // Link to an attribute node. TODO: It's ugly.
                    continue;
                }

                var source = this.DataGraph.Vertices.First(v => v.Node == sourceNode);
                var target = this.DataGraph.Vertices.First(v => v.Node == targetNode);

                var newEdge = new EdgeViewModel(source, target, Convert.ToDouble(false))
                {
                    Edge     = edge,
                    EdgeType = EdgeViewModel.EdgeTypeEnum.Association
                };
                var attributeInfos = edge.Attributes.Select(x => new AttributeViewModel(x, x.Name, x.Kind.ToString())
                {
                    Value = x.StringValue
                });
                var attributes = attributeInfos as IList <AttributeViewModel> ?? attributeInfos.ToList();
                attributes.ForEach(x => newEdge.Attributes.Add(x));
                var value = attributes.SingleOrDefault(x => x.Name == "Value");
                if (value != null)
                {
                    newEdge.EdgeType = EdgeViewModel.EdgeTypeEnum.Attribute;
                    newEdge.Text     = value.Value;
                }

                this.DataGraph.AddEdge(newEdge);
                this.ElementAdded?.Invoke(this, new ElementAddedEventArgs {
                    Element = edge
                });
            }

            this.DrawGraph?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 3
0
        private Line CreateLine(EdgeViewModel edgeViewModel)
        {
            var line = new Line();

            line.Stroke          = Brushes.Black;
            line.StrokeThickness = 4;
            line.SetValue(Panel.ZIndexProperty, -1);
            Binding x1Binding = CreateBinding("X1", edgeViewModel);

            BindingOperations.SetBinding(line, Line.X1Property, x1Binding);

            Binding y1Binding = CreateBinding("Y1", edgeViewModel);

            BindingOperations.SetBinding(line, Line.Y1Property, y1Binding);

            Binding x2Binding = CreateBinding("X2", edgeViewModel);

            BindingOperations.SetBinding(line, Line.X2Property, x2Binding);

            Binding y2Binding = CreateBinding("Y2", edgeViewModel);

            BindingOperations.SetBinding(line, Line.Y2Property, y2Binding);

            return(line);
        }
Exemplo n.º 4
0
        public void CreateEdge(IEdge edge, IElement prevVer, IElement ctrlVer)
        {
            _ = prevVer ?? throw new ArgumentNullException(nameof(prevVer));
            _ = ctrlVer ?? throw new ArgumentNullException(nameof(prevVer));

            var sourceViewModel = this.DataGraph.Vertices.FirstOrDefault(x => x.Node == prevVer);
            var targetViewModel = this.DataGraph.Vertices.FirstOrDefault(x => x.Node == ctrlVer);

            _ = sourceViewModel ?? throw new InvalidOperationException();
            _ = targetViewModel ?? throw new InvalidOperationException();

            var newEdge = new EdgeViewModel(sourceViewModel, targetViewModel, Convert.ToDouble(true))
            {
                Edge = edge
            };

            this.DataGraph.AddEdge(newEdge);

            var args = new DataEdgeArgs
            {
                EdgeViewModel = newEdge
            };

            this.AddNewEdgeControl?.Invoke(this, args);
            this.ElementAdded?.Invoke(this, new ElementAddedEventArgs {
                Element = edge
            });
        }
        public void ChangedGraphFastExecutionTest()
        {
            var state1 = new NodeViewModel()
            {
                ID = 1, IsInitial = true
            };
            var state2 = new NodeViewModel()
            {
                ID = 2, IsFinal = true
            };

            graph.AddVertex(state1);
            graph.AddVertex(state2);
            var transition = new EdgeViewModel(state1, state2)
            {
                TransitionTokensString = "1"
            };

            graph.AddEdge(transition);
            var executor = new FAExecutor(graph);

            executor.Execute("1");

            transition.TransitionTokensString = "0";
            Assert.AreEqual(ResultEnum.Passed, executor.Execute("0"));
            Assert.AreEqual(ResultEnum.Failed, executor.Execute("1"));
        }
Exemplo n.º 6
0
        private void AddNewEdgeControlWithoutVCP(EdgeViewModel edgeViewModel)
        {
            var previousVertex = this.graphArea.VertexList.First(vc => vc.Key == edgeViewModel.Source).Value;
            var currentVertex  = this.graphArea.VertexList.First(vc => vc.Key == edgeViewModel.Target).Value;
            var ec             = new EdgeControl(previousVertex, currentVertex, edgeViewModel);

            this.graphArea.InsertEdge(edgeViewModel, ec);
        }
Exemplo n.º 7
0
        private void AddNewEdgeControl(EdgeViewModel edgeViewModel)
        {
            var ec = new EdgeControl(this.prevVer, this.ctrlVer, edgeViewModel);

            this.scene.InsertEdge(edgeViewModel, ec);
            this.prevVer = null;
            this.editorManager.DestroyVirtualEdge();
        }
Exemplo n.º 8
0
        private void AddNewEdgeControl(EdgeViewModel edgeViewModel)
        {
            var ec = new EdgeControl(this.previosVertex, this.currentVertex, edgeViewModel);

            this.graphArea.InsertEdge(edgeViewModel, ec);
            this.previosVertex = null;
            this.EditorManager.DestroyVirtualEdge();
        }
 public FrameworkElement CreateEdge(EdgeViewModel edgeViewModel)
 {
     return new Path
     {
         Data = edgeViewModel.Data,
         Stroke = new SolidColorBrush(Colors.Black),
         StrokeThickness = 1,
     };
 }
Exemplo n.º 10
0
 public FrameworkElement CreateEdge(EdgeViewModel edgeViewModel)
 {
     return(new Path
     {
         Data = edgeViewModel.Data,
         Stroke = new SolidColorBrush(Colors.Blue /*edgeViewModel.color*/),
         StrokeThickness = 1,
     });
 }
Exemplo n.º 11
0
        public EdgesController(ApplicationDbContext db)
        {
            this.db = db;

            EdgeVM = new EdgeViewModel()
            {
                Edge  = new IntercityLink(),
                Nodes = db.TransportVertices.ToList()
            };
            EdgeVM.Edge.NodesPair = new VerticesPair();
        }
Exemplo n.º 12
0
        private Line GetLineFromViewModel(EdgeViewModel edgeViewModel)
        {
            Line foundLine = null;

            foreach (var child in _canvas.Children)
            {
                if (child is Line line && line.DataContext == edgeViewModel)
                {
                    foundLine = line;
                }
            }
            return(foundLine);
        }
        public void SceneSerializationTest()
        {
            var newWindowThread = new Thread(new ThreadStart(() =>
            {
                Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
                var scene           = new Scene();
                var help            = new ErrorReporterViewModel();
                scene.ErrorReporter = help;
                const string path   = "../../../Files/NotEmptyScene.xml";
                var state1          = new NodeViewModel {
                    Name = "S1", IsInitial = true
                };
                var state2 = new NodeViewModel {
                    Name = "S2", IsFinal = true
                };
                help.Graph.AddVertex(state1);
                help.Graph.AddVertex(state2);
                var transition1 = new EdgeViewModel(state1, state2)
                {
                    IsEpsilon = true, TransitionTokensString = "1"
                };
                var transition2 = new EdgeViewModel(state1, state1)
                {
                    TransitionTokensString = "0"
                };
                help.Graph.AddEdge(transition1);
                help.Graph.AddEdge(transition2);
                scene.Save(path);
                help.Graph.RemoveVertex(state1);
                help.Graph.RemoveVertex(state2);
                help.Graph.RemoveEdge(transition1);
                help.Graph.RemoveEdge(transition2);
                scene.Open(path);
                Assert.True(help.Graph.VertexCount == 2 && help.Graph.EdgeCount == 2);
                Assert.True(help.Graph.Vertices.FirstOrDefault(v => v.Name == "S1").IsInitial);
                Assert.True(help.Graph.Vertices.FirstOrDefault(v => v.Name == "S2").IsFinal);
                Assert.True(help.Graph.Edges.FirstOrDefault(v => v.TransitionTokensString == "1").IsEpsilon);
                Assert.True(help.Graph.Edges.Any(v => v.TransitionTokensString == "0"));
                // start the Dispatcher processing
                System.Windows.Threading.Dispatcher.Run();
            }));

            // set the apartment state
            newWindowThread.SetApartmentState(ApartmentState.STA);

            // make the thread a background thread
            newWindowThread.IsBackground = true;

            // start the thread
            newWindowThread.Start();
        }
Exemplo n.º 14
0
        public void CreateEdge(IEdge edge, NodeViewModel prevVer, NodeViewModel ctrlVer)
        {
            if (prevVer == null || ctrlVer == null)
            {
                return;
            }

            var newEdge = new EdgeViewModel(prevVer, ctrlVer, Convert.ToDouble(true));
            var args    = new DataEdgeArgs
            {
                EdgeViewModel = newEdge
            };

            this.AddNewEdgeControl?.Invoke(this, args);
            this.ElementAdded?.Invoke(this, new ElementAddedEventArgs {
                Element = edge
            });
        }
Exemplo n.º 15
0
        /// <summary>
        /// Handling of adding new routing point.
        /// </summary>
        /// <param name="edge">Edge.</param>
        /// <param name="mousePosition">Position of mouse.</param>
        private void HandleRoutingPoints(EdgeViewModel edge, GraphX.Measure.Point mousePosition)
        {
            if (edge.RoutingPoints == null)
            {
                var sourcePos = this.edgeControl.Source.GetPosition().ToGraphX();
                var targetPos = this.edgeControl.Target.GetPosition().ToGraphX();

                edge.RoutingPoints          = new GraphX.Measure.Point[] { sourcePos, mousePosition, targetPos };
                edge.IndexOfInflectionPoint = 1;
                return;
            }

            var isRoutingPoint = edge.RoutingPoints.Where(point => Geometry.GetDistance(point, mousePosition).CompareTo(3) <= 0).ToArray().Length != 0;

            if (isRoutingPoint)
            {
                edge.IndexOfInflectionPoint = Array.FindIndex(edge.RoutingPoints, point => Geometry.GetDistance(point, mousePosition).CompareTo(3) <= 0);
            }
            else
            {
                var numberOfRoutingPoints = edge.RoutingPoints.Length;

                for (var i = 0; i < numberOfRoutingPoints - 1; ++i)
                {
                    if (Geometry.BelongsToLine(edge.RoutingPoints[i], edge.RoutingPoints[i + 1], mousePosition))
                    {
                        edge.IndexOfInflectionPoint = i + 1;
                        var oldRoutingPoints = edge.RoutingPoints;
                        var newRoutingPoints = new GraphX.Measure.Point[numberOfRoutingPoints + 1];
                        Array.Copy(oldRoutingPoints, 0, newRoutingPoints, 0, i + 1);
                        Array.Copy(oldRoutingPoints, i + 1, newRoutingPoints, i + 2, numberOfRoutingPoints - i - 1);
                        newRoutingPoints[i + 1] = mousePosition;
                        edge.RoutingPoints      = newRoutingPoints;
                        return;
                    }
                }
            }
        }
Exemplo n.º 16
0
 public override NodeViewModel GetNextNode(NodeViewModel node, MultirotorClient client)
 {
     if (graph.DataGraph.OutEdges(node).Count() != 2)
     {
         writeToMessageBox("Error: ifNode out edges count is not equal 2 ");
         client.Dispose();
         return(null);
     }
     if (condition)
     {
         EdgeViewModel edge = graph.DataGraph.OutEdges(node).ToList()[0];
         return(edge.Attributes[0].Value == "true"
             ? edge.Target
             : graph.DataGraph.OutEdges(node).ToList()[1].Target);
     }
     else
     {
         EdgeViewModel edge = graph.DataGraph.OutEdges(node).ToList()[0];
         return(edge.Attributes[0].Value == "false"
             ? edge.Target
             : graph.DataGraph.OutEdges(node).ToList()[1].Target);
     }
 }
Exemplo n.º 17
0
 private void UpdateEdgePositions(EdgeViewModel edgeModel, double _deltaX, double _deltaY)
 {
     edgeModel.X += _deltaX;
     edgeModel.Y += _deltaY;
 }
Exemplo n.º 18
0
 public void SetTargetVCPId(EdgeViewModel edgeViewModel, int id)
 {
     edgeViewModel.TargetConnectionPointId = id;
 }
Exemplo n.º 19
0
 public void SetSourceVCPId(EdgeViewModel edgeViewModel, int id)
 {
     edgeViewModel.SourceConnectionPointId = id;
 }
Exemplo n.º 20
0
 public FrameworkElement CreateEdge(EdgeViewModel edgeViewModel)
 {
     return new ContentPresenter { Content = edgeViewModel };
 }
 public FrameworkElement CreateEdge(EdgeViewModel edgeViewModel)
 {
     return(new ContentPresenter {
         Content = edgeViewModel
     });
 }
Exemplo n.º 22
0
        private void VertexSelectedAction(object sender, VertexSelectedEventArgs args)
        {
            this.currentVertex = args.VertexControl;
            if (this.elementProvider.Element?.InstanceMetatype == Repo.Metatype.Edge)
            {
                if (IsVertexVirtual(currentVertex))
                {
                    return;
                }
                if (this.previosVertex == null)
                {
                    this.editorManager.CreateVirtualEdge(this.currentVertex, this.currentVertex.GetPosition());
                    this.previosVertex = this.currentVertex;
                }
                else if (this.previosVertex.GetDataVertex <NodeViewModel>().IsVirtual)
                {
                    var virtualEdgeData    = new EdgeViewModel(previosVertex.GetDataVertex <NodeViewModel>(), currentVertex.GetDataVertex <NodeViewModel>());
                    var virtualEdgeControl = new EdgeControl(previosVertex, currentVertex, virtualEdgeData);
                    this.graphArea.AddEdge(virtualEdgeData, virtualEdgeControl);
                    this.editorManager.DestroyVirtualEdge();
                    this.previosVertex = null;
                    this.ElementManipulationDone?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    var command = new Commands.CreateEdgeCommand(
                        this.model,
                        this.elementProvider.Element,
                        (this.previosVertex?.Vertex as NodeViewModel)?.Node,
                        (this.currentVertex?.Vertex as NodeViewModel)?.Node);
                    this.controller.Execute(command);
                    this.ElementManipulationDone?.Invoke(this, EventArgs.Empty);
                }

                return;
            }

            this.NodeSelected?.Invoke(
                this,
                new NodeSelectedEventArgs {
                Node = this.currentVertex.GetDataVertex <NodeViewModel>()
            });

            this.graphArea.GetAllVertexControls().ToList().ForEach(x => x.GetDataVertex <NodeViewModel>().
                                                                   Color = Brushes.Green);

            this.currentVertex.GetDataVertex <NodeViewModel>().Color = Brushes.LightBlue;
            if (this.previosVertex != null)
            {
                this.previosVertex.GetDataVertex <NodeViewModel>().Color = Brushes.Yellow;
            }

            if (args.MouseArgs.RightButton == MouseButtonState.Pressed)
            {
                args.VertexControl.ContextMenu = new ContextMenu();
                var mi = new MenuItem {
                    Header = "Delete item", Tag = args.VertexControl
                };
                if (IsVertexVirtual(args.VertexControl))
                {
                    mi.Click += (senderObj, eventArgs) => this.MenuItemClickedOnVirtualVertex(args.VertexControl, EventArgs.Empty);
                }
                else
                {
                    mi.Click += this.MenuItemClickedOnVertex;
                }
                args.VertexControl.ContextMenu.Items.Add(mi);
                args.VertexControl.ContextMenu.IsOpen = true;
            }
        }
Exemplo n.º 23
0
        private void AddNewEdgeControl(EdgeViewModel edgeViewModel)
        {
            var prevVerVertex = this.previosVertex?.Vertex as NodeViewModel;
            var ctrlVerVertex = this.currentVertex?.Vertex as NodeViewModel;

            if (this.currentVertex is VertexControlWithVCP && this.previosVertex is VertexControlWithVCP)
            {
                VertexConnectionPoint targetVCP = null;
                foreach (var x in this.currentVertex.VertexConnectionPointsList)
                {
                    var aVCPforGH = x as VertexConnectionPoint;
                    if (aVCPforGH != null && aVCPforGH.IsOccupied == false && aVCPforGH.IsSource == false)
                    {
                        aVCPforGH.IsOccupied = true;
                        targetVCP            = aVCPforGH;
                        break;
                    }
                }

                if (targetVCP != null)
                {
                    this.Graph.SetTargetVCPId(edgeViewModel, targetVCP.Id);
                }
                else
                {
                    if (ctrlVerVertex.Node.Name == "aInterval")
                    {
                        this.editorManager.DestroyVirtualEdge();
                        return;
                    }

                    var newId = this.currentVertex.VertexConnectionPointsList.Last().Id + 1;
                    targetVCP = new VertexConnectionPoint()
                    {
                        Id = newId, IsOccupied = true, IsSource = false
                    };
                    var ctrl = new Border
                    {
                        Margin = new Thickness(0, 2, 2, 0), Padding = new Thickness(0), Child = targetVCP
                    };
                    ((VertexControlWithVCP)this.currentVertex).VCPTargetRoot.Children.Add(ctrl);
                    this.currentVertex.VertexConnectionPointsList.Add(targetVCP);
                    this.Graph.SetTargetVCPId(edgeViewModel, targetVCP.Id);
                }

                VertexConnectionPoint sourceVCP = null;
                foreach (var x in this.previosVertex.VertexConnectionPointsList)
                {
                    var aVCPforGH = x as VertexConnectionPoint;
                    if (aVCPforGH != null && aVCPforGH.IsOccupied == false && aVCPforGH.IsSource == true)
                    {
                        aVCPforGH.IsOccupied = true;
                        sourceVCP            = aVCPforGH;
                        break;
                    }
                }

                if (sourceVCP != null)
                {
                    this.Graph.SetSourceVCPId(edgeViewModel, sourceVCP.Id);
                }
                else
                {
                    var newId = this.previosVertex.VertexConnectionPointsList.Last().Id + 1;
                    sourceVCP = new VertexConnectionPoint()
                    {
                        Id = newId, IsOccupied = true, IsSource = true
                    };
                    var ctrl = new Border
                    {
                        Margin = new Thickness(0, 2, 2, 0), Padding = new Thickness(0), Child = sourceVCP
                    };
                    ((VertexControlWithVCP)this.previosVertex).VCPSourceRoot.Children.Add(ctrl);
                    this.previosVertex.VertexConnectionPointsList.Add(sourceVCP);
                    this.Graph.SetSourceVCPId(edgeViewModel, newId);
                }
            }

            var ec = new EdgeControl(this.previosVertex, this.currentVertex, edgeViewModel);

            this.previosVertex = null;
            this.editorManager.DestroyVirtualEdge();
            this.graphArea.InsertEdge(edgeViewModel, ec);
        }
 // For changing the current state of the diagram.
 public AddEdgeCommand(ObservableCollection <EdgeViewModel> edges, EdgeViewModel edge)
 {
     this.edges = edges;
     this.edge  = edge;
 }
Exemplo n.º 25
0
 private void SetEdgePositions(EdgeViewModel edgeModel, double x, double y)
 {
     edgeModel.X = x;
     edgeModel.Y = y;
 }