Example #1
0
        void DrawLineSegDilated(Point p1, Point p2)
        {
            var a = PointToPixel(p1);
            var b = PointToPixel(p2);

            _bitmap.DrawFatSeg(a, b, (int)(_insertRectSize / (2 * _pixelSize) + 0.5));
        }
Example #2
0
        void InitSegment(Point p1, Point p2)
        {
            int id0 = _pointsToIndices[p1];
            int id1 = _pointsToIndices[p2];

            _segments.Insert(new SymmetricTuple <int>(id0, id1));
        }
        /// <summary>
        /// Draw new shape
        /// </summary>
        /// <param name="centerLocation"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private Microsoft.Msagl.Drawing.Node Draw(Microsoft.Msagl.Core.Geometry.Point centerLocation)
        {
            graph = gViewer.Graph;
            var id = drawForm.ShapeId;

            Microsoft.Msagl.Drawing.Node node = graph.AddNode(id);
            node.Label.Text     = drawForm.ShapeLabel;
            node.Attr.Shape     = drawForm.ChosenShape;
            node.Attr.Color     = Color.Black;
            node.Attr.FillColor = new Microsoft.Msagl.Drawing.Color(drawForm.ChosenColor.A,
                                                                    drawForm.ChosenColor.R,
                                                                    drawForm.ChosenColor.G,
                                                                    drawForm.ChosenColor.B);
            node.Attr.LineWidth  = MinSize / 5;
            node.Attr.XRadius    = node.Attr.YRadius = MinSize / 2;
            node.Label.FontColor = Color.Black;
            node.Label.FontSize  = drawForm.FontSize;

            NodeWidth  = drawForm.ShapeWidth;
            NodeHeight = drawForm.ShapeHeight;
            NodeCenter = centerLocation;
            node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(DrawCurve);
            //if (drawForm.BackgroundNode)
            //{
            //    node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(GetNodeBoundary);
            //    node.DrawNodeDelegate = new DelegateToOverrideNodeRendering(DrawImageNode);
            //    drawForm.BackgroundNode = false;
            //}
            IViewerNode dNode = gViewer.CreateIViewerNode(node, centerLocation, null);

            gViewer.AddNode(dNode, true);
            // gViewer.ResizeNodeToLabel(node);
            return(node);
        }
Example #4
0
        public Point ScreenToSource(MsaglMouseEventArgs e)
        {
            var p = new Point(e.X, e.Y);
            var m = Transform.Inverse;

            return(m * p);
        }
        void SetTransformOnViewportWithoutRaisingViewChangeEvent(double scale, Point graphCenter, Rectangle vp)
        {
            var dx = vp.Width / 2 - scale * graphCenter.X;
            var dy = vp.Height / 2 + scale * graphCenter.Y;

            SetTransformWithoutRaisingViewChangeEvent(scale, dx, dy);
        }
        void SetTransformOnViewport(double scale, Point graphCenter, Rectangle vp)
        {
            var dx = vp.Width / 2 - scale * graphCenter.X;
            var dy = vp.Height / 2 + scale * graphCenter.Y;

            SetTransform(scale, dx, dy);
        }
        internal Line(DObject tag, P2 start, P2 end, double lw)
            : base(tag) {
            lineWidth = lw;
            P2 dir = end - start;
            if (lineWidth < 0)
                lineWidth = 1;

            double len = dir.Length;
            if (len > ApproximateComparer.IntersectionEpsilon) {
                dir /= (len / (lineWidth / 2));
                dir = dir.Rotate(Math.PI / 2);
            } else {
                dir.X = 0;
                dir.Y = 0;
            }

            this.bBox = new BBox(start + dir);
            this.bBox.Add(start - dir);
            this.bBox.Add(end + dir);
            this.bBox.Add(end - dir);
            this.start = start;
            this.end = end;

            if (this.bBox.LeftTop.X == this.bBox.RightBottom.X) {
                bBox.LeftTop = bBox.LeftTop + new P2(-0.05f, 0);
                bBox.RightBottom = bBox.RightBottom + new P2(0.05f, 0);
            }
            if (this.bBox.LeftTop.Y == this.bBox.RightBottom.Y) {
                bBox.LeftTop = bBox.LeftTop + new P2(0, -0.05f);
                bBox.RightBottom = bBox.RightBottom + new P2(0, 0.05f);
            }

        }
Example #8
0
        public bool FindClosestFreePos(Point p, out Point newPos)
        {
            PixelPoint iPos;
            bool       found = FindClosestFreePixel(p, out iPos);

            newPos = GetWorldCoord(iPos);
            return(found);
        }
Example #9
0
        public static RectangleF getHeaderRectangle(Microsoft.Msagl.Drawing.Node node)
        {
            Microsoft.Msagl.Core.Geometry.Point p = node.GeometryNode.Center;
            float w = (float)node.Width;
            float h = (float)node.Height;

            return(new RectangleF((float)(p.X - w / 2), (float)(p.Y - h / 2), w, WIDTH));
        }
Example #10
0
 void IndexAPoint(Point p)
 {
     if (!_pointsToIndices.ContainsKey(p))
     {
         _pointsToIndices[p] = _pointsToIndices.Count;
         _pointList.Add(p);
         _visGraph.AddVertex(p);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodeId1"></param>
        /// <param name="nodeId2"></param>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="nodeBoxes"></param>
        /// <param name="tRes"></param>
        /// <returns></returns>
        public static double GetIdealDistanceBetweenNodes(int nodeId1, int nodeId2, Point point1, Point point2,
                                                          Size[] nodeBoxes, out double tRes)
        {
            if (nodeBoxes == null)
            {
                throw new ArgumentNullException("nodeBoxes");
            }
            tRes = -1;
            if (nodeBoxes.Length <= nodeId1)
            {
                return(0);
            }
            if (nodeBoxes.Length <= nodeId2)
            {
                return(0);
            }

            const double expandMax = 1.5;
            const double expandMin = 1;
//            double tmax = 0;
//            double tmin = 1E10;

            const double machineAcc = 1.0e-16;
            double       dist       = (point1 - point2).Length;
            double       dx         = Math.Abs(point1.X - point2.X);
            double       dy         = Math.Abs(point1.Y - point2.Y);

            double wx = (nodeBoxes[nodeId1].Width / 2 + nodeBoxes[nodeId2].Width / 2);
            double wy = (nodeBoxes[nodeId1].Height / 2 + nodeBoxes[nodeId2].Height / 2);

            double t;

            if (dx < machineAcc * wx)
            {
                t = wy / dy;
            }
            else if (dy < machineAcc * wy)
            {
                t = wx / dx;
            }
            else
            {
                t = Math.Min(wx / dx, wy / dy);
            }

            if (t > 1)
            {
                t = Math.Max(t, 1.001);        // must be done, otherwise the convergence is very slow
            }
//            tmax = Math.Max(tmax, t);
//            tmin = Math.Min(tmin, t);
            t    = Math.Min(expandMax, t);
            t    = Math.Max(expandMin, t);
            tRes = t;
            return(t * dist);
        }
Example #12
0
        public Point[] GetTranslations()
        {
            Point[] translation = new Point[_moveableRectangles.Length];

            for (int i = 0; i < _moveableRectangles.Length; i++)
            {
                translation[i] = movedRectangles[i].Center - _moveableRectangles[i].Center;
            }
            return(translation);
        }
Example #13
0
        void DrawPortAtLocation(Graphics g, P2 center)
        {
            Brush  brush = Brushes.Brown;
            double rad   = Viewer.UnderlyingPolylineCircleRadius;

            g.FillEllipse(brush, (float)center.X - (float)rad,
                          (float)center.Y - (float)rad,
                          2.0f * (float)rad,
                          2.0f * (float)rad);
        }
Example #14
0
        public void RunTest7()
        {
            Point  p1       = new Point(-497.12352212078628, 1689.84931190121);
            Point  p2       = new Point(198.64235142705752, 2139.4677380013277);
            Point  bl       = new Point(-5191.0147700187063, -4395.7850131819132);
            double gridSize = 553.23948409846571;

            GridTraversal grid  = new GridTraversal(new Rectangle(bl, bl + new Point(gridSize, gridSize)), 20);
            var           tiles = grid.GetTilesIntersectedByLineSeg(p1, p2);
        }
Example #15
0
 public void SetTargetPortForEdgeRouting(Point portLocation)
 {
     if (TargetPortCircle == null)
     {
         TargetPortCircle = CreatePortPath();
         GraphCanvas.Children.Add(TargetPortCircle);
     }
     TargetPortCircle.Width           = TargetPortCircle.Height = UnderlyingPolylineCircleRadius;
     TargetPortCircle.StrokeThickness = TargetPortCircle.Width / 10;
     Wpf2MsaglConverters.PositionFrameworkElement(TargetPortCircle, portLocation, 1);
 }
Example #16
0
        private void insertNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (gViewer == null || gViewer.Graph == null)
            {
                MessageBox.Show("Please create graph first.", "Insert Node Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var tree = RectangleNode <object> .CreateRectangleNodeOnEnumeration(GetRectangleNodesFromGraph());

            if (tree == null)
            {
                return;
            }

            var       numberOfTries = 10000;
            Random    random        = new Random(1);
            double    rectWidth     = 100;
            double    rectHeight    = 100;
            var       delta         = new Point(rectWidth / 2, rectHeight / 2);
            Rectangle bestRectangle = Rectangle.CreateAnEmptyBox();

            Point  hint        = (gViewer.Graph.BoundingBox.LeftBottom + gViewer.Graph.BoundingBox.RightTop) / 2;
            double minDistance = double.PositiveInfinity;

            for (int i = 0; i < numberOfTries; i++)
            {
                Point     randomCenter = GetRandomCenter(rectHeight, rectWidth, random);
                Rectangle r            = new Rectangle(randomCenter);
                r.Add(randomCenter + delta);
                r.Add(randomCenter - delta);
                if (tree.GetNodeItemsIntersectingRectangle(r).Any())
                {
                }
                else
                {
                    var len = (randomCenter - hint).LengthSquared;
                    if (len < minDistance)
                    {
                        minDistance   = len;
                        bestRectangle = r;
                    }
                }
            }

            if (bestRectangle.IsEmpty == false)
            {
                InsertNodeIntoGraph(bestRectangle);
            }
            else
            {
                MessageBox.Show("cannot insert");
            }
        }
Example #17
0
        private void AddStringToShape(Shape shape, Point p, Microsoft.Msagl.Core.Geometry.Rectangle box, double l, Set <Point> points)
        {
            while (p.X <= box.Right)
            {
                if (IsInsideShape(shape, p))
                {
                    points.Insert(p);
                }

                p.X += l;
            }
        }
Example #18
0
        void DrawRectDilated(Rectangle rect)
        {
            Point d          = new Point(_insertRectSize / 2, _insertRectSize / 2);
            var   leftBottom = _worldToMap * (rect.LeftBottom - d);
            var   rightTop   = _worldToMap * (rect.RightTop + d);
            int   ix1        = (int)leftBottom.X;
            int   iy1        = (int)leftBottom.Y;
            int   iw         = (int)(rightTop.X - leftBottom.X);
            int   ih         = (int)(rightTop.Y - leftBottom.Y);

            _bitmap.FillRectangle(ix1, iy1, iw, ih);
        }
        void DrawingPanelSizeChanged(object sender, EventArgs e)
        {
            if (originalGraph == null || panel.ClientRectangle.Width < 2 || panel.ClientRectangle.Height < 2)
            {
                return;
            }
            double oldFitFactor   = Math.Min(prevPanelClientRectangle.Width / originalGraph.Width, prevPanelClientRectangle.Height / originalGraph.Height);
            var    center         = new Point(prevPanelClientRectangle.Width / 2.0, prevPanelClientRectangle.Height / 2.0);
            var    centerOnSource = transformation.Inverse * center;

            SetTransformOnScaleAndCenter(GetFitScale() * CurrentScale / oldFitFactor, centerOnSource);
            prevPanelClientRectangle = panel.ClientRectangle;
        }
Example #20
0
        public static void DrawNode(Microsoft.Msagl.Drawing.Node n, Pen pen, Graphics graphics)
        {
            Brush selPen1 = new SolidBrush(System.Drawing.Color.Blue);

            Microsoft.Msagl.Core.Geometry.Point     p   = n.GeometryNode.Center;
            Microsoft.Msagl.Core.Geometry.Rectangle rec = n.BoundingBox;
            double w     = n.Width;
            double h     = n.Height;
            ICurve curve = n.GeometryNode.BoundaryCurve;

            graphics.DrawLine(pen, (float)(p.X - w / 2), (float)(p.Y - h / 2 + WIDTH),
                              (float)(p.X + w / 2), (float)(p.Y - h / 2 + WIDTH));
            graphics.FillRectangle(selPen1, getHeaderRectangle(n));
        }
Example #21
0
        private void EnterInnerPointsUnderShape(Shape shape, double l, Set <Point> points)
        {
            var  h   = l * Math.Sqrt(3) / 2 * 10;
            var  box = shape.BoundingBox;
            var  p   = shape.BoundingBox.LeftBottom;
            bool odd = false;

            while (p.Y < box.Top)
            {
                AddStringToShape(shape, p, box, l, points);
                p  += new Point(odd? l / 2:-l / 2, h);
                odd = !odd;
            }
        }
        List <Point> GetPointsOverlappingSeg(SymmetricTuple <int> seg, RTree <Point> tree, Point[] indexToPoints)
        {
            Point p0   = indexToPoints[seg.A];
            Point p1   = indexToPoints[seg.B];
            var   rect = new Rectangle(p0, p1);

            rect.Pad(1e-5);

            Point[] vts = tree.GetAllIntersecting(rect).ToArray();

            double t;
            var    vtsOverlapping = vts.Where(p => Point.DistToLineSegment(p, p0, p1, out t) < 1e-5).ToList();

            vtsOverlapping = vtsOverlapping.OrderBy(p => (p - p0).Length).ToList();
            return(vtsOverlapping);
        }
        double AvgEdgeLength()
        {
            int    i             = 0;
            double avgEdgeLength = 0;

            foreach (Edge edge in Graph.Edges)
            {
                Point  sPoint = edge.Source.Center;
                Point  tPoint = edge.Target.Center;
                double euclid = (sPoint - tPoint).Length;
                avgEdgeLength += euclid;
                i++;
            }
            avgEdgeLength /= i;
            return(avgEdgeLength);
        }
Example #24
0
        double AvgEdgeLength(Edge[] edges)
        {
            Debug.Assert(edges.Length > 0);
            int    i             = 0;
            double avgEdgeLength = 0;

            foreach (Edge edge in edges)
            {
                Point  sPoint = edge.Source.Center;
                Point  tPoint = edge.Target.Center;
                double euclid = (sPoint - tPoint).Length;
                avgEdgeLength += euclid;
                i++;
            }
            avgEdgeLength /= i;
            return(avgEdgeLength);
        }
Example #25
0
        internal bool FindClosestFreePixel(Point p, out PixelPoint found)
        {
            var pPixel = PointToPixel(p);

            for (int r = 0; r < MaxSize / 2; r++)
            {
                if (!GetFreePixelInRadius(ref pPixel, r))
                {
                    continue;
                }
                found = pPixel;
                return(true);
            }

            found = new PixelPoint();
            return(false);
        }
        /// <summary>
        /// Determines the edges of the triangulation together with their desired length (distance between nodes).
        /// </summary>
        /// <param name="originalGraph"></param>
        /// <param name="cdt"></param>
        /// <param name="targetSizes"></param>
        /// <param name="desiredEdgeDistances"></param>
        /// <returns></returns>
        public static int GetProximityEdgesWithDistance(GeometryGraph originalGraph, Cdt cdt,
                                                        Size[] targetSizes,
                                                        out List <Tuple <int, int, double, double> > desiredEdgeDistances)
        {
            desiredEdgeDistances = new List <Tuple <int, int, double, double> >();
            int numberOverlappingPairs = 0;
            var edgeSet = new HashSet <CdtEdge>();

            //add edges
            foreach (CdtTriangle triangle in cdt.GetTriangles())
            {
                foreach (CdtEdge triangleEdge in triangle.Edges)
                {
                    CdtSite site1   = triangleEdge.upperSite;
                    CdtSite site2   = triangleEdge.lowerSite;
                    var     nodeId1 = (int)site1.Owner;
                    var     nodeId2 = (int)site2.Owner;
                    if (edgeSet.Contains(triangleEdge))
                    {
                        continue;                                 //edge already included
                    }
                    edgeSet.Add(triangleEdge);

                    Point point1 = site1.Point;
                    Point point2 = site2.Point;

                    double t;
                    double distance = GetIdealDistanceBetweenNodes(nodeId1, nodeId2, point1, point2, targetSizes,
                                                                   out t);
                    if (t > 1)
                    {
                        numberOverlappingPairs++;
                    }
                    int nodeIdSmall = nodeId1;
                    int nodeIdBig   = nodeId2;
                    if (nodeId1 > nodeId2)
                    {
                        nodeIdSmall = nodeId2;
                        nodeIdBig   = nodeId1;
                    }
                    var tuple = new Tuple <int, int, double, double>(nodeIdSmall, nodeIdBig, distance, t);
                    desiredEdgeDistances.Add(tuple);
                }
            }
            return(numberOverlappingPairs);
        }
Example #27
0
 public void DrawRubberLine(Point rubberEnd)
 {
     if (_rubberLinePath == null)
     {
         _rubberLinePath = new Path
         {
             Stroke          = Brushes.Black,
             StrokeThickness = GetBorderPathThickness() * 3
         };
         GraphCanvas.Children.Add(_rubberLinePath);
         //                targetArrowheadPathForRubberLine = new Path {
         //                    Stroke = Brushes.Black,
         //                    StrokeThickness = GetBorderPathThickness()*3
         //                };
         //                graphCanvas.Children.Add(targetArrowheadPathForRubberLine);
     }
     _rubberLinePath.Data = VisualsFactory.CreateEdgePath(new LineSegment(_sourcePortLocationForEdgeRouting, rubberEnd));
 }
        bool TopologyForCallingTriangleIsCorrect()
        {
            Point[] indexToPoints = new Point[_pointsToIndices.Count];
            foreach (var pp in _pointsToIndices)
            {
                indexToPoints[pp.Value] = pp.Key;
            }

            var tree =
                new RTree <Point>(_pointsToIndices.Keys.Select(p => new KeyValuePair <Rectangle, Point>(new Rectangle(p), p)));
            var badSegs = (from e in _segments let overlaps = GetPointsOverlappingSeg(e, tree, indexToPoints) where overlaps.Count > 2 select e).ToList();

// #if TEST_MSAGL
//             if (badSegs.Any())
//                 ShowInputSegments(badSegs, indexToPoints);
// #endif
            return(!badSegs.Any());
        }
        internal Line(DObject tag, MsaglPoint start, MsaglPoint end, double lw)
            : base(tag)
        {
            lineWidth = lw;
            MsaglPoint dir = end - start;

            if (lineWidth < 0)
            {
                lineWidth = 1;
            }

            double len = dir.Length;

            if (len > ApproximateComparer.IntersectionEpsilon)
            {
                dir /= (len / (lineWidth / 2));
                dir  = dir.Rotate(Math.PI / 2);
            }
            else
            {
                dir.X = 0;
                dir.Y = 0;
            }

            this.bBox = new Rectangle(start + dir);
            this.bBox.Add(start - dir);
            this.bBox.Add(end + dir);
            this.bBox.Add(end - dir);
            this.start = start;
            this.end   = end;

            if (this.bBox.LeftTop.X == this.bBox.RightBottom.X)
            {
                bBox.LeftTop     = bBox.LeftTop + new MsaglPoint(-0.05f, 0);
                bBox.RightBottom = bBox.RightBottom + new MsaglPoint(0.05f, 0);
            }
            if (this.bBox.LeftTop.Y == this.bBox.RightBottom.Y)
            {
                bBox.LeftTop     = bBox.LeftTop + new MsaglPoint(0, -0.05f);
                bBox.RightBottom = bBox.RightBottom + new MsaglPoint(0, 0.05f);
            }
        }
Example #30
0
        private void button1_Click(object sender, EventArgs e)  //this is abstract.dot of GraphViz
        {
            var tree = RectangleNode <object> .CreateRectangleNodeOnEnumeration(GetRectangleNodesFromGraph());

            var       numberOfTries = 10000;
            Random    random        = new Random(1);
            double    rectWidth     = 50;
            double    rectHeight    = 200;
            var       delta         = new Point(rectWidth / 2, rectHeight / 2);
            Rectangle bestRectangle = Rectangle.CreateAnEmptyBox();

            Point  hint        = (gViewer.Graph.BoundingBox.LeftBottom + gViewer.Graph.BoundingBox.RightTop) / 2;
            double minDistance = double.PositiveInfinity;

            for (int i = 0; i < numberOfTries; i++)
            {
                Point     randomCenter = GetRandomCenter(rectHeight, rectWidth, random);
                Rectangle r            = new Rectangle(randomCenter);
                r.Add(randomCenter + delta);
                r.Add(randomCenter - delta);
                if (tree.GetNodeItemsIntersectingRectangle(r).Any())
                {
                }
                else
                {
                    var len = (randomCenter - hint).LengthSquared;
                    if (len < minDistance)
                    {
                        minDistance   = len;
                        bestRectangle = r;
                    }
                }
            }
            if (bestRectangle.IsEmpty == false)
            {
                InsertNodeIntoGraph(bestRectangle);
            }
            else
            {
                MessageBox.Show("cannot insert");
            }
        }
        /// <summary>
        ///     Coincidence of points is resolved by randomly moving the second of two points, until the coincidence is resolved.
        ///     Points are also slightly randomized if randomizeAll is true, to avoid degenerate cases which will break the algorithm.
        /// </summary>
        /// <param name="points"></param>
        /// <param name="random"></param>
        /// <param name="epsilon"></param>
        /// <param name="randomizeAll"></param>
        public static void RandomizePoints(Point[] points, Random random, double epsilon, bool randomizeAll)
        {
            var pointSet = new HashSet <Point>();

            for (int i = 0; i < points.Length; i++)
            {
                Point p = points[i];
                if (pointSet.Contains(p) || randomizeAll)
                {
                    do
                    {
                        double newX = p.X + (2 * random.NextDouble() - 1) * epsilon;
                        double newY = p.Y + (2 * random.NextDouble() - 1) + epsilon;
                        p = new Point(newX, newY);
                    } while (pointSet.Contains(p));
                }
                points[i] = p;
                pointSet.Add(p);
            }
        }
        public Rectangle GetVisibleRectangleInGraph() {
            var t = Transform.Inverse;
            var p0 = new Point(0, 0);
            var vp = GetCanvasRenderViewport();
            var p1 = new Point(vp.Width, vp.Height);
            var rect=new Rectangle(t*p0, t*p1);
            if (GeomGraph == null)
                return rect;

            return rect.Intersection(GeomGraph.BoundingBox);
        }
 internal PixelPoint PointToPixel(Point p) {
     var l = _worldToMap*p;
     return new PixelPoint((int) (l.X + 0.5), (int) (l.Y + 0.5));
 }
 public void DrawRubberLine(Point rubberEnd) {
     if (_rubberLinePath == null) {
         _rubberLinePath = new Path
         {
             Stroke = Brushes.Black,
             StrokeThickness = GetBorderPathThickness()*3
         };
         GraphCanvasChildrenAdd(_rubberLinePath);
         //                targetArrowheadPathForRubberLine = new Path {
         //                    Stroke = Brushes.Black,
         //                    StrokeThickness = GetBorderPathThickness()*3
         //                };
         //                graphCanvas.Children.Add(targetArrowheadPathForRubberLine);
     }
     _rubberLinePath.Data =
         GraphmapsEdge.GetICurveWpfGeometry(new LineSegment(_sourcePortLocationForEdgeRouting, rubberEnd));
 }
        static ICurve GetRandomShape(Random random)
        {
            //we support rectangle, roundedRectangle, circle, ellipse, diamond, Octagon, triangle, star            
            int index = random.Next(3);
            var center = new Microsoft.Msagl.Core.Geometry.Point();
            switch (index) {
                case 0:
                    return CurveFactory.CreateRectangle(20 + random.Next(10), 10 + random.Next(10), center);
                case 1:
                    return CurveFactory.CreateRectangleWithRoundedCorners(30 + random.Next(10), 20 + random.Next(10), 1 + random.Next(8), 1 + random.Next(8), center);
                case 2:
                    return CurveFactory.CreateEllipse(26, 18, center);
            }

            return null;
        }
 public bool FindClosestFreePos(Point p, out Point newPos) {
     PixelPoint iPos;
     bool found = FindClosestFreePixel(p, out iPos);
     newPos = GetWorldCoord(iPos);
     return found;
 }
Example #37
0
        private void button1_Click(object sender, EventArgs e) {//this is abstract.dot of GraphViz
            var tree = RectangleNode<object>.CreateRectangleNodeOnEnumeration(GetRectangleNodesFromGraph());

            var numberOfTries=10000;
            Random random=new Random(1);
            double rectWidth=50;
            double rectHeight=200;
            var delta=new Point(rectWidth/2, rectHeight/2);
            Rectangle bestRectangle = Rectangle.CreateAnEmptyBox();

            Point hint = (gViewer.Graph.BoundingBox.LeftBottom + gViewer.Graph.BoundingBox.RightTop) / 2;
            double minDistance=double.PositiveInfinity;
            for(int i=0;i<numberOfTries;i++){
                Point randomCenter=GetRandomCenter(rectHeight,rectWidth,random);
                Rectangle r=new Rectangle(randomCenter);
                r.Add(randomCenter+delta);
                r.Add(randomCenter-delta);
                if(tree.GetNodeItemsIntersectingRectangle(r).Any()){}
                else {
                    var len=(randomCenter-hint).LengthSquared;
                    if(len<minDistance){
                        minDistance = len;
                        bestRectangle=r;
                    }
                }
            }
            if (bestRectangle.IsEmpty == false)
                InsertNodeIntoGraph(bestRectangle);
            else 
                MessageBox.Show("cannot insert");
      
        }
        void SetTransformOnViewport(double scale, Point graphCenter, Rectangle vp)
        {
            var dx = vp.Width/2 - scale*graphCenter.X;
            var dy = vp.Height/2 + scale*graphCenter.Y;

            SetTransform(scale, dx, dy);
        }
 static Rectangle Translate(Rectangle rect, Point delta) {
     return new Rectangle(rect.LeftBottom + delta, rect.RightTop + delta);
 }
 /// <summary>
 /// this function pins the sourcePoint to screenPoint
 /// </summary>
 /// <param name="screenPoint"></param>
 /// <param name="sourcePoint"></param>
 void SetTransformFromTwoPoints(WpfPoint screenPoint, Point sourcePoint) {
     var scale = CurrentScale;
     SetTransform(scale, screenPoint.X - scale*sourcePoint.X, screenPoint.Y + scale*sourcePoint.Y);
 }
 public Point ScreenToSource(MsaglMouseEventArgs e) {
     var p = new Point(e.X, e.Y);
     var m = Transform.Inverse;
     return m*p;
 }
        void GraphCanvasMouseMove(object sender, MouseEventArgs e) {
            if (MouseMove != null)
                MouseMove(this, CreateMouseEventArgs(e));

            if (e.Handled) return;

            if (e.LeftButton == MouseButtonState.Pressed) {
                if (!_panning) {
                    _panning = true;
                    _mouseDownPositionInGraph = Common.MsaglPoint(e.GetPosition(_graphCanvas));
                }
                Pan(e);
            }
            else
                ToolTipService.SetIsEnabled(_graphCanvas, !_graphCanvas.IsMouseDirectlyOver);
        }
        void GraphCanvasMouseLeftButtonDown(object sender, MouseEventArgs e) {
            clickCounter.AddMouseDown();
            if (MouseDown != null)
                MouseDown(this, CreateMouseEventArgs(e));

            if (e.Handled) return;
            _mouseDownPositionInGraph = Common.MsaglPoint(e.GetPosition(_graphCanvas));

            Keyboard.Focus(_graphCanvas);
        }
 public void StartDrawingRubberLine(Point startingPoint) {}
 void DrawLineSegDilated(Point p1, Point p2) {
     var a = PointToPixel(p1);
     var b = PointToPixel(p2);
     _bitmap.DrawFatSeg(a, b, (int) (_insertRectSize/(2*_pixelSize)+0.5));
 }
        void SetTransformOnViewportWithoutRaisingViewChangeEvent(double scale, Point graphCenter, Rectangle vp)
        {
            var dx = vp.Width/2 - scale*graphCenter.X;
            var dy = vp.Height/2 + scale*graphCenter.Y;

            SetTransformWithoutRaisingViewChangeEvent(scale, dx, dy);
        }
 void DrawRectDilated(Rectangle rect) {
     Point d = new Point(_insertRectSize/2, _insertRectSize/2);
     var leftBottom = _worldToMap*(rect.LeftBottom - d);
     var rightTop = _worldToMap*(rect.RightTop + d);
     int ix1 = (int) leftBottom.X;
     int iy1 = (int) leftBottom.Y;
     int iw = (int) (rightTop.X - leftBottom.X);
     int ih = (int) (rightTop.Y - leftBottom.Y);
     _bitmap.FillRectangle(ix1, iy1, iw, ih);
 }
 void SetTransformWithScaleAndCenter(double scale, Point graphCenter)
 {
     var vp = ClientViewportMappedToGraph;
     SetTransformOnViewport(scale, graphCenter, vp);
 }
        public Point[] GetTranslations() {
            Point[] translation = new Point[_moveableRectangles.Length];

            for (int i = 0; i < _moveableRectangles.Length; i++)
                translation[i] = movedRectangles[i].Center - _moveableRectangles[i].Center;
            return translation;
        }
Example #50
0
 void DrawPortAtLocation(Graphics g, P2 center) {
     Brush brush = Brushes.Brown;
     double rad = Viewer.UnderlyingPolylineCircleRadius;
     g.FillEllipse(brush, (float) center.X - (float) rad,
                   (float) center.Y - (float) rad,
                   2.0f*(float) rad,
                   2.0f*(float) rad);
 }
 public bool IsPositionFree(Point p) {
     return IsFree(PointToPixel(p));
 }
Example #52
0
 static void DrawCircleAroungPolylineCorner(Graphics g, P2 p, Pen pen, double radius){
     g.DrawEllipse(pen, (float) (p.X - radius), (float) (p.Y - radius),
                   (float) (2*radius), (float) (2*radius));
 }
 public IViewerNode CreateIViewerNode(DrawingNode drawingNode, Point center, object visualElement)
 {
     throw new NotImplementedException();
 }
 public void SetTargetPortForEdgeRouting(Point portLocation) {
     if (TargetPortCircle == null) {
         TargetPortCircle = CreatePortPath();
         GraphCanvasChildrenAdd(TargetPortCircle);
     }
     TargetPortCircle.Width = TargetPortCircle.Height = UnderlyingPolylineCircleRadius;
     TargetPortCircle.StrokeThickness = TargetPortCircle.Width/10;
     Common.PositionFrameworkElement(TargetPortCircle, portLocation, 1);
 }
Example #55
0
 static PointF P2P(P2 p){
     return new PointF((float) p.X, (float) p.Y);
 }
 public void DrawRubberLine(Point point)
 {
     throw new NotImplementedException();
 }
 public void SetTargetPortForEdgeRouting(Point portLocation)
 {
     throw new NotImplementedException();
 }
 public void StartDrawingRubberLine(Point startingPoint)
 {
     throw new NotImplementedException();
 }
 public void SetSourcePortForEdgeRouting(Point portLocation) {
     _sourcePortLocationForEdgeRouting = portLocation;
     if (_sourcePortCircle == null) {
         _sourcePortCircle = CreatePortPath();
         GraphCanvasChildrenAdd(_sourcePortCircle);
     }
     _sourcePortCircle.Width = _sourcePortCircle.Height = UnderlyingPolylineCircleRadius;
     _sourcePortCircle.StrokeThickness = _sourcePortCircle.Width/10;
     Common.PositionFrameworkElement(_sourcePortCircle, portLocation, 1);
 }
        internal bool FindClosestFreePixel(Point p, out PixelPoint found) {
            var pPixel = PointToPixel(p);

            for (int r = 0; r < MaxSize/2; r++) {
                if (!GetFreePixelInRadius(ref pPixel, r)) continue;
                found = pPixel;
                return true;
            }

            found = new PixelPoint();
            return false;
        }