void TryMapShapeToTightLooseCouple(Shape shape, TightLooseCouple tightLooseCouple) {
            if (ShapeIsInsideOfPoly(shape, tightLooseCouple.TightPolyline))
                ShapesToTightLooseCouples[shape] = tightLooseCouple;
#if TEST_MSAGL
            tightLooseCouple.LooseShape.UserData = (string) shape.UserData + "x";
#endif
        }
Beispiel #2
0
        void PathToShape(Path path)
        {
            var shape = new Shape(PolylineFromPath(path));

            InsertShapeIntoHierarchy(shape);
            pathsToShapes[path] = shape;
        }
 internal ShapeObstacleCalculator(Shape shape, double tightPadding, double loosePadding, 
     Dictionary<Shape, TightLooseCouple> shapeToTightLooseCouples) {
     MainShape = shape;
     TightPadding = tightPadding;
     LoosePadding = loosePadding;
     ShapesToTightLooseCouples = shapeToTightLooseCouples;
 }
Beispiel #4
0
 private void OrientUnderShape(Shape shape, bool clockwise)
 {
     shape.BoundaryCurve = OrientPolyline(shape.BoundaryCurve as Polyline, clockwise);
     foreach (var sh in shape.Children)
     {
         OrientUnderShape(sh, !clockwise);
     }
 }
Beispiel #5
0
 private void SubdivideUnderShape(Shape shape, double minLength)
 {
     SubdividePolyline((Polyline)shape.BoundaryCurve, minLength);
     foreach (var ch in shape.Children)
     {
         SubdivideUnderShape(ch, minLength);
     }
 }
Beispiel #6
0
 private void CleanUpTriangles(Shape shape, ref Set <CdtTriangle> triangles, Cdt cdt)
 {
     CleanUpExternalTriangles(shape, ref triangles, cdt);
     foreach (var sh in shape.Children)
     {
         CleanUpInternalTriangles(sh, ref triangles, cdt);
     }
 }
Beispiel #7
0
        void FindChildren(Shape shape)
        {
            Set <Shape> successors = GetShapeSuccessors(shape);

            foreach (var s in successors)
            {
                if (s.Parents.All(h => !successors.Contains(h)))
                {
                    shape.AddChild(s);
                }
            }
        }
Beispiel #8
0
        void FindParents(Shape shape)
        {
            Set <Shape> ancestors = GetShapeAncestors(shape);

            foreach (var s in ancestors)
            {
                if (s.Children.All(h => !ancestors.Contains(h)))
                {
                    s.AddChild(shape);
                }
            }
        }
Beispiel #9
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;
            }
        }
Beispiel #10
0
        Set <Shape> GetShapeSuccessors(Shape shape)
        {
            var ret = new Set <Shape>();

            foreach (var sh in pathsToShapes.Values)
            {
                if (CurveInsideOther(sh.BoundaryCurve, shape.BoundaryCurve))
                {
                    ret.Insert(sh);
                }
            }
            return(ret);
        }
Beispiel #11
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;
            }
        }
Beispiel #12
0
        private void CleanUpExternalTriangles(Shape shape, ref Set <CdtTriangle> triangles, Cdt cdt)
        {
            Set <CdtTriangle> removedTriangles = new Set <CdtTriangle>();
            var poly = (Polyline)shape.BoundaryCurve;

            for (var p = poly.StartPoint; p.Next != null; p = p.Next)
            {
                FillRemovedForExternalTriangle(p, p.Next, removedTriangles, cdt);
            }

            FillRemovedForExternalTriangle(poly.EndPoint, poly.StartPoint, removedTriangles, cdt);
            //var l = new List<DebugCurve>();
            //l.Add(new DebugCurve(100, 1, "black", poly));
            //l.AddRange(removedTriangles.Select(t => new DebugCurve(100, 0.1, "red", new Polyline(t.Sites.Select(s => s.Point).ToArray()) { Closed = true })));
            //LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l);
            triangles -= removedTriangles;
        }
Beispiel #13
0
        private void TesselateUnderShape(Shape shape)
        {
            var polys = new List <Polyline>(shape.Children.Select(sh => (Polyline)sh.BoundaryCurve));

            polys.Add(shape.BoundaryCurve as Polyline);
            var cdt = new Cdt(shapesToInnerPoints[shape], polys, null);

            cdt.Run();
            Set <CdtTriangle> triangles = cdt.GetTriangles();

            cdt.SetInEdges();
            CleanUpTriangles(shape, ref triangles, cdt);
            foreach (var t in triangles)
            {
                AddTriangleToCanvas(t);
            }
        }
 private bool IsInsideShape(Shape shape, Point p) {
     return Curve.PointRelativeToCurveLocation(p, shape.BoundaryCurve) == PointLocation.Inside &&
         shape.Children.All(ch => Curve.PointRelativeToCurveLocation(p, ch.BoundaryCurve) == PointLocation.Outside);
 }
 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;
     }
 }
        private void ReadUnpaddedObstacles()
        {
            this.VerifyIsNextLine(RectFileStrings.BeginUnpaddedObstacles);

            // Get to the first line for consistency with the lookahead for children which will end up
            // reading the following line.
            this.NextLine();

            for (;;)
            {
                int id;
                Shape shape;
                if (this.IsLine(RectFileStrings.BeginCurve))
                {
                    id = ParseNextId();
                    shape = new Shape(this.ReadCurve()) { UserData = id };
                }
                else if (this.IsLine(RectFileStrings.BeginEllipse))
                {
                    id = ParseNextId();
                    shape = new Shape(this.ReadEllipse()) { UserData = id };
                }
                else if (this.IsLine(RectFileStrings.BeginRoundedRect))
                {
                    id = ParseNextId();
                    shape = new Shape(this.ReadRoundedRect()) { UserData = id };
                }
                else if (this.IsLine(RectFileStrings.BeginPolyline))
                {
                    id = ParseNextId();
                    shape = new Shape(this.ReadPolyline()) { UserData = id };
                }
                else
                {
                    this.VerifyIsLine(RectFileStrings.EndUnpaddedObstacles);
                    return;
                }

                this.UnpaddedObstacles.Add(shape);
                idToShapeMap.Add(id, shape);
                shapeToIdMap.Add(shape, id);

                this.NextLine();
                TryParseChildren(shape);
                this.TryParseClumpId(id);
                this.TryParseConvexHullId(id);
            }
        }
 Polyline LoosePolyOfOriginalShape(Shape s) {
     return (Polyline)(LooseShapeOfOriginalShape(s).BoundaryCurve);
 }
 Polyline TightPolyOfOriginalShape(Shape s) {
     if (s == root)
         return null;
     return shapesToTightLooseCouples[s].TightPolyline;
 }
        /*
        /// <summary>
        /// it is the set of parents with all children being obstacle candidates
        /// </summary>
        /// <param name="port"></param>
        /// <param name="shape"></param>
        /// <param name="otherShape"></param>
        /// <returns></returns>
        IEnumerable<Shape> FindMinimalParents(Port port, Shape shape, Shape otherShape) {
            if (shape == null)
                yield return rootOfLooseShapes;
            else if (port is CurvePort) {
                if (IsLgAncestor(shape, otherShape))
                    yield return shape;
                else
                    foreach (Shape parent in shape.Parents)
                        yield return parent;
            } else if (PortIsInsideOfShape(port, shape) && shape.Children.Any())
                yield return shape;
            else
                foreach (Shape parent in shape.Parents)
                    yield return parent;
        }
*/

        bool IsAncestor(Shape possibleAncestor, Shape possiblePredecessor) {
            Set<Shape> ancestors;
            return possiblePredecessor != null &&
                   ancestorSets.TryGetValue(possiblePredecessor, out ancestors) && ancestors != null &&
                   ancestors.Contains(possibleAncestor);
        }
Beispiel #20
0
 void InsertShapeIntoHierarchy(Shape shape)
 {
     FindParents(shape);
     FindChildren(shape);
 }
 Set<Shape> GetShapeSuccessors(Shape shape) {
     var ret = new Set<Shape>();
     foreach (var sh in pathsToShapes.Values)
         if (CurveInsideOther(sh.BoundaryCurve, shape.BoundaryCurve))
             ret.Insert(sh);
     return ret;
 }
 void FindParents(Shape shape) {
     Set<Shape> ancestors = GetShapeAncestors(shape);
     foreach (var s in ancestors)
         if (s.Children.All(h => !ancestors.Contains(h)))
             s.AddChild(shape);
 }
 void FindChildren(Shape shape) {
     Set<Shape> successors = GetShapeSuccessors(shape);
     foreach (var s in successors)
         if (s.Parents.All(h => !successors.Contains(h)))
             shape.AddChild(s);
 }
 void InsertShapeIntoHierarchy(Shape shape) {
     FindParents(shape);
     FindChildren(shape);
 }
 void PathToShape(Path path) {
     var shape= new Shape(PolylineFromPath(path));
     InsertShapeIntoHierarchy(shape);
     pathsToShapes[path] = shape;
 }
 private void TryParseChildren(Shape shape)
 {
     if (!IsLine(RectFileStrings.Children))
     {
         return;
     }
     int id;
     while (TryParseNextId(out id))
     {
         shape.AddChild(idToShapeMap[id]);
     }
 }
 private void OrientUnderShape(Shape shape, bool clockwise) {
     shape.BoundaryCurve = OrientPolyline(shape.BoundaryCurve as Polyline, clockwise);
     foreach(var sh in shape.Children)
         OrientUnderShape(sh,!clockwise);
 }
 void BindLooseShapesUnderShape(Shape shape) {
     var loose = shapesToTightLooseCouples[shape].LooseShape;
     foreach (var child in shape.Children) {
         var childLooseShape = shapesToTightLooseCouples[child].LooseShape;
         loose.AddChild(childLooseShape);
         BindLooseShapesUnderShape(child);
     }
 }
 void TryToCreateNewEdgeAndSetIsPassable(VisibilityEdge edge, Shape looseShape) {
     var e = visGraph.FindEdge(edge.SourcePoint, edge.TargetPoint);
     if (e != null) return;
     e = visGraph.AddEdge(edge.SourcePoint, edge.TargetPoint);
     if (looseShape != null)
         e.IsPassable = () => looseShape.IsTransparent;
 }
        /// <summary>
        /// this function might change the shape's loose polylines by inserting new points
        /// </summary>
        void FillVisibilityGraphUnderShape(Shape shape) {
            //going depth first 
            var children = shape.Children;
            foreach (Shape child in children)
                FillVisibilityGraphUnderShape(child);
            TightLooseCouple tightLooseCouple;
            Polyline looseBoundary = shapesToTightLooseCouples.TryGetValue(shape, out tightLooseCouple) ? tightLooseCouple.LooseShape.BoundaryCurve as Polyline : null;
            Shape looseShape = tightLooseCouple != null ? tightLooseCouple.LooseShape : looseRoot;
            var obstacles = new Set<Polyline>(looseShape.Children.Select(c => c.BoundaryCurve as Polyline));

            var portLocations = RemoveInsidePortsAndSplitBoundaryIfNeeded(looseBoundary);
            //this run will split the polyline enough to route later from the inner ports
            var tmpVisGraph = new VisibilityGraph();
            var coneSpanner = new ConeSpanner(new Polyline[] {}, tmpVisGraph, coneAngle, portLocations, looseBoundary);
            coneSpanner.Run();
            //now run the spanner again to create the correct visibility graph around the inner obstacles
            tmpVisGraph = new VisibilityGraph();
            coneSpanner = new ConeSpanner(obstacles, tmpVisGraph, coneAngle, portLocations, looseBoundary) {
                Bidirectional = Bidirectional && obstacles.Count>0
            };
            coneSpanner.Run();

            ProgressStep();

            foreach (VisibilityEdge edge in tmpVisGraph.Edges)
                TryToCreateNewEdgeAndSetIsPassable(edge, looseShape);
           
            AddBoundaryEdgesToVisGraph(looseBoundary);
//            if (obstacles.Count > 0)
//                SplineRouter.ShowVisGraph(tmpVisGraph, obstacles, null, null);
        }
Beispiel #31
0
 private bool IsInsideShape(Shape shape, Point p)
 {
     return(Curve.PointRelativeToCurveLocation(p, shape.BoundaryCurve) == PointLocation.Inside &&
            shape.Children.All(ch => Curve.PointRelativeToCurveLocation(p, ch.BoundaryCurve) == PointLocation.Outside));
 }
 IEnumerable<Shape> GetTransparentShapes(
     Port sourcePort,
     Port targetPort, Shape sourceShape, Shape targetShape) {
     foreach (var s in ancestorSets[sourceShape])
         yield return s;
     foreach (var s in ancestorSets[targetShape])
         yield return s;
     var routingOutsideOfSourceBoundary = EdgesAttachedToPortAvoidTheNode(sourcePort);
     var routingOutsideOfTargetBoundary = EdgesAttachedToPortAvoidTheNode(targetPort);
     if (!routingOutsideOfSourceBoundary && !routingOutsideOfTargetBoundary) {
         yield return sourceShape;
         yield return targetShape;
     } else if (routingOutsideOfSourceBoundary) {
         if (IsAncestor(sourceShape, targetShape))
             yield return sourceShape;
     }
     else {
         if (IsAncestor(targetShape, sourceShape))
             yield return targetShape;
     }
 }
 Shape LooseShapeOfOriginalShape(Shape s) {
     if (s == root)
         return looseRoot;
     return shapesToTightLooseCouples[s].LooseShape;
 }
        private void CleanUpExternalTriangles(Shape shape, ref Set<CdtTriangle> triangles, Cdt cdt) {
            Set<CdtTriangle> removedTriangles = new Set<CdtTriangle>();
            var poly = (Polyline)shape.BoundaryCurve;
            for (var p = poly.StartPoint; p.Next != null; p = p.Next)
                FillRemovedForExternalTriangle(p, p.Next, removedTriangles, cdt);

            FillRemovedForExternalTriangle(poly.EndPoint, poly.StartPoint, removedTriangles, cdt);
            //var l = new List<DebugCurve>();
            //l.Add(new DebugCurve(100, 1, "black", poly));
            //l.AddRange(removedTriangles.Select(t => new DebugCurve(100, 0.1, "red", new Polyline(t.Sites.Select(s => s.Point).ToArray()) { Closed = true })));
            //LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(l);
            triangles -= removedTriangles;
        }
        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;
            }
              

        }
 static void FixPortAtSource(Shape shape, Port port, Edge e) {
     if (e.SourcePort == null)
         e.SourcePort = port;
     else
         shape.Ports.Insert(e.SourcePort);
 }
 public TightLooseCouple(Polyline tightPolyline, Shape looseShape, double distance)
 {
     TightPolyline = tightPolyline;
     LooseShape = looseShape;
     Distance=distance;
 }
        void CalculateShapeToBoundaries(Shape shape) {
            ProgressStep();
            if (!shape.Children.Any()) return;

            foreach (Shape child in shape.Children)
                CalculateShapeToBoundaries(child);

            var obstacleCalculator = new ShapeObstacleCalculator(shape, tightPadding, AdjustedLoosePadding,
                                                                 shapesToTightLooseCouples);
            obstacleCalculator.Calculate();

#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=370
            //SharpKit/Colin - not supported directly!
            OverlapsDetected = OverlapsDetected | obstacleCalculator.OverlapsDetected;
#else
            OverlapsDetected |= obstacleCalculator.OverlapsDetected;
#endif
        }
 private void CleanUpTriangles(Shape shape, ref Set<CdtTriangle> triangles, Cdt cdt) {
     CleanUpExternalTriangles(shape, ref triangles, cdt);
     foreach (var sh in shape.Children)
         CleanUpInternalTriangles(sh, ref triangles, cdt);
 }
 private void SubdivideUnderShape(Shape shape, double minLength) {
     SubdividePolyline((Polyline)shape.BoundaryCurve, minLength);
     foreach (var ch in shape.Children)
         SubdivideUnderShape(ch, minLength);
 }
 void CreateTheMapToParentLooseShapes(Shape shape, Dictionary<ICurve, Shape> loosePolylinesToLooseParentShapeMap) {
     foreach (var childShape in shape.Children) {
         var tightLooseCouple = shapesToTightLooseCouples[childShape];
         var poly = tightLooseCouple.LooseShape.BoundaryCurve;
         loosePolylinesToLooseParentShapeMap[poly] = shape;
         CreateTheMapToParentLooseShapes(childShape, loosePolylinesToLooseParentShapeMap);
     }
 }
 static void FixPortAtTarget(Shape shape, Port port, Edge e) {
     if (e.TargetPort == null)
         e.TargetPort = port;
     else 
         shape.Ports.Insert(e.TargetPort);
 }
        private void TesselateUnderShape(Shape shape) {
            var polys=new List<Polyline>(shape.Children.Select(sh=>(Polyline)sh.BoundaryCurve));
            polys.Add(shape.BoundaryCurve as Polyline);
            var cdt=new Cdt(shapesToInnerPoints[shape], polys,null);
            cdt.Run();
            Set<CdtTriangle> triangles=cdt.GetTriangles();
            cdt.SetInEdges();
            CleanUpTriangles(shape, ref triangles,cdt);
            foreach(var t in triangles){
                AddTriangleToCanvas(t);
            }

        }