示例#1
0
        /// <summary>
        /// Gets the offset point for edge parallelization
        /// </summary>
        /// <param name="source">Source vertex</param>
        /// <param name="target">Target vertex</param>
        /// <param name="sideDistance">Distance between edges</param>
        internal Point GetParallelOffset(VertexControl source, VertexControl target, int sideDistance)
        {
            var sourcepos = source.GetPosition();
            var targetpos = target.GetPosition();

            var mainVector = new Vector(targetpos.X - sourcepos.X, targetpos.Y - sourcepos.Y);
            //get new point coordinate
            var joint = new Point(
                sourcepos.X + source.DesiredSize.Width * .5 + sideDistance * (mainVector.Y / mainVector.Length),
                sourcepos.Y + source.DesiredSize.Height * .5 - sideDistance * (mainVector.X / mainVector.Length));

            return(joint);
        }
示例#2
0
        private Point GetOffset(VertexControl source, VertexControl target, int side_distance)
        {
            var sourcepos = source.GetPosition();
            var targetpos = target.GetPosition();

            var main_vector = new Vector(targetpos.X - sourcepos.X, targetpos.Y - sourcepos.Y);
            //get new point coordinate
            var joint = new Point(
                sourcepos.X + side_distance * (main_vector.Y / main_vector.Length),
                sourcepos.Y - side_distance * (main_vector.X / main_vector.Length));

            return(joint);
        }
示例#3
0
        /// <summary>
        /// Gets the offset point for edge parallelization
        /// </summary>
        /// <param name="source">Source vertex</param>
        /// <param name="target">Target vertex</param>
        /// <param name="sideDistance">Distance between edges</param>
        internal Point GetParallelOffset(VertexControl source, VertexControl target, int sideDistance)
        {
            var sourcepos = source.GetPosition();
            var targetpos = target.GetPosition();

            var mainVector = new Vector(targetpos.X - sourcepos.X, targetpos.Y - sourcepos.Y);
            //get new point coordinate
            var joint = new Point(
                 sourcepos.X + source.DesiredSize.Width * .5 + sideDistance * (mainVector.Y / mainVector.Length),
                 sourcepos.Y + source.DesiredSize.Height * .5 - sideDistance * (mainVector.X / mainVector.Length));
            return joint;
        }
示例#4
0
        void dg_Area_VertexSelectedForED(object sender, GraphX.Models.VertexSelectedEventArgs args)
        {
            if (_isInEDMode)
            {
                if (_edVertex == null) //select starting vertex
                {
                    _edVertex = args.VertexControl;
                    _edFakeDV = new DataVertex() { ID = -666 };
                    _edGeo = new PathGeometry(new PathFigureCollection() { new PathFigure() { IsClosed = false, StartPoint = _edVertex.GetPosition(), Segments = new PathSegmentCollection() { new PolyLineSegment(new List<Point>() { new Point() }, true) } } });
                    var dedge = new DataEdge(_edVertex.Vertex as DataVertex, _edFakeDV);
                    _edEdge = new EdgeControl(_edVertex, null, dedge) { ManualDrawing = true };
                    dg_Area.AddEdge(dedge, _edEdge);
                    dg_Area.LogicCore.Graph.AddVertex(_edFakeDV);
                    dg_Area.LogicCore.Graph.AddEdge(dedge);
                    _edEdge.SetEdgePathManually(_edGeo);
                }
                else if (_edVertex != args.VertexControl) //finish draw
                {
                    _edEdge.Target = args.VertexControl;
                    var dedge = _edEdge.Edge as DataEdge;
                    dedge.Target = args.VertexControl.Vertex as DataVertex;
                    var fig = _edGeo.Figures[0];
                    var seg = fig.Segments[_edGeo.Figures[0].Segments.Count - 1] as PolyLineSegment;

                    if (seg.Points.Count > 0)
                    {
                        var targetPos = _edEdge.Target.GetPosition();
                        var sourcePos = _edEdge.Source.GetPosition();
                        //get the size of the source
                        var sourceSize = new Size()
                        {
                            Width = _edEdge.Source.ActualWidth,
                            Height = _edEdge.Source.ActualHeight
                        };
                        var targetSize = new Size()
                        {
                            Width = _edEdge.Target.ActualWidth,
                            Height = _edEdge.Target.ActualHeight
                        };

                        var src_start = seg.Points.Count == 0 ? fig.StartPoint : seg.Points[0];
                        var src_end = seg.Points.Count > 1 ? (seg.Points[seg.Points.Count - 1] == targetPos ? seg.Points[seg.Points.Count - 2] : seg.Points[seg.Points.Count - 1]) : fig.StartPoint;
                        Point p1 = GeometryHelper.GetEdgeEndpoint(sourcePos, new Rect(sourceSize), src_start, _edEdge.Source.MathShape);
                        Point p2 = GeometryHelper.GetEdgeEndpoint(targetPos, new Rect(targetSize), src_end, _edEdge.Target.MathShape);

                        fig.StartPoint = p1;
                        if (seg.Points.Count > 1)
                            seg.Points[seg.Points.Count - 1] = p2;
                    }
                    GeometryHelper.TryFreeze(_edGeo);
                    _edEdge.SetEdgePathManually(new PathGeometry(_edGeo.Figures));
                    _isInEDMode = false;
                    clearEdgeDrawing();
                }
            }
        }
示例#5
0
 private void CenterOnVertex(VertexControl vc)
 {
     var x = zoom_control.Position.X + vc.GetPosition().X;
     var y = zoom_control.Position.Y + vc.GetPosition().Y;
     var of = System.Windows.Media.VisualTreeHelper.GetOffset(vc);
     var new_point = new Point(
         (of.X
         * zoom_control.Scale
         + vc.ActualWidth / 2
         * zoom_control.Scale
         - zoom_control.ActualWidth / 2
         )
         ,
         (of.Y
         * zoom_control.Scale
         + vc.ActualHeight / 2
         * zoom_control.Scale
         - zoom_control.ActualHeight / 2
         )
         );
     zoom_control.ZoomTo(new_point);
 }
示例#6
0
        private void CreateEdgeControl(VertexControl vc)
        {
            if(_ecFrom == null)
            {
                _editorManager.CreateVirtualEdge(vc, vc.GetPosition());
                _ecFrom = vc;
                HighlightBehaviour.SetHighlighted(_ecFrom, true);
                return;
            }
            if(_ecFrom == vc) return;

            var data = new DataEdge((DataVertex)_ecFrom.Vertex, (DataVertex)vc.Vertex);
            graphArea.LogicCore.Graph.AddEdge(data);
            var ec = new EdgeControl(_ecFrom, vc, data);
            graphArea.InsertEdge(data, ec);

            HighlightBehaviour.SetHighlighted(_ecFrom, false);
            _ecFrom = null;
            _editorManager.DestroyVirtualEdge();
        }