public HatchSegmentGraph(double start, double end, HatchData hd, Editor ed)
            {
                this.hd    = hd;
                this.start = start;
                this.end   = end;
                //this.db = db;
                //получить все точки пересечений полигонов с вертикалями в начале и в конце (интересуют только полноценные пересечения, не касания)
                //все полученные точки пересечений поместить в несколько отсортированных коллекций:
                //по координате Y начало (должно быть четное количество),
                //по координате Y конец (должно быть четное количество),
                //для каждого полигона контуров штриховки - по параметру композитной кривой
                startVert = new Line2d(new Point2d(start, 0), Vector2d.YAxis);
                endVert   = new Line2d(new Point2d(end, 0), Vector2d.YAxis);
                GetIntersections(hd.Root);//первоначально заполняются SortedSet
                //если на одной из вертикалей только одна точка пересечения, то не учитывать ее
                //if (startVertSorted.Count==1)
                //{
                //    Node node = startVertSorted.First();
                //    notVisited.Remove(node);
                //    boundariesSorted[node.Boundary].Remove(node);
                //    startVertSorted.Clear();
                //}
                //if (endVertSorted.Count == 1)
                //{
                //    Node node = endVertSorted.First();
                //    notVisited.Remove(node);
                //    boundariesSorted[node.Boundary].Remove(node);
                //    endVertSorted.Clear();
                //}

                //переместить узлы в LinkedList и заполнить свойство VerticalJunction узлов (нужен переход между соседними узлами в списках)
                MoveToLinkedLists();


                //получить набор полигонов, которые должны быть вставлены в 3d профиль на текущем отрезке
                //для этого совершается обход точек пересечения
                while (notVisited.Count > 1)//В обходе может быть не менее 2 узлов
                {
                    try
                    {
                        Traverse();
                    }
                    catch (Exception ex)
                    {
                        Utils.ErrorToCommandLine(ed,
                                                 "Ошибка при при обходе полигона", ex);
                        break;
                    }
                }

                //Контуры, котрые полностью находятся внутри текущего диапазона добавляются в набор без изменений
                //(скорее всего для создания М-полигона вложенность запоминать не нужно)

                foreach (HatchNestingNode boundaryWithNoIntersections in boundariesWithNoIntersections)
                {
                    Result.Add(new List <Point2d>(boundaryWithNoIntersections.Point2dCollection.ToArray()));
                }
            }
Exemple #2
0
        /// <summary>
        /// Gets the intersection points between the triangle and the line.
        /// </summary>
        /// <param name="le2d">The line with which intersections are searched.</param>
        /// <param name="tol">The tolerance used in comparisons.</param>
        /// <returns>The intersection points list (an empty list if none).</returns>
        public List <Point2d> IntersectWith(LinearEntity2d le2d, Tolerance tol)
        {
            List <Point2d> result = new List <Point2d>();

            for (int i = 0; i < 3; i++)
            {
                Point2d[] inters = le2d.IntersectWith(this.GetSegmentAt(i), tol);
                if (inters != null && inters.Length != 0 && !result.Contains(inters[0]))
                {
                    result.Add(inters[0]);
                }
            }
            return(result);
        }
Exemple #3
0
        public List <Point2d> IntersectWith(LinearEntity2d le2d)
        {
            var result = new List <Point2d>();

            for (var i = 0; i < 3; i++)
            {
                var inters = le2d.IntersectWith(GetSegmentAt(i));
                if (inters != null && inters.Length != 0 && !result.Contains(inters[0]))
                {
                    result.Add(inters[0]);
                }
            }

            return(result);
        }
            private bool AddIntersection(LineSegment2d intersectionSeg, LinearEntity2d vert, HatchNestingNode hatchNode, SortedSet <Node> vertSorted)
            {
                bool result = false;
                CurveCurveIntersector2d intersector = new CurveCurveIntersector2d(intersectionSeg, vert);

                if (intersector.NumberOfIntersectionPoints > 0)
                {
                    Point2d intersectionPt = intersector.GetPointOnCurve1(0).Point;
                    //если точка пересечения контура и вертикали имеет ту же координату X,
                    //что и начало или конец контура, то это пересечение не учитывается!
                    if (!Utils.LengthIsEquals(intersectionPt.X, hatchNode.Extents.MinPoint.X) &&
                        !Utils.LengthIsEquals(intersectionPt.X, hatchNode.Extents.MaxPoint.X))   //допуск
                    {
                        double param = hatchNode.Boundary.GetParameterOf(intersectionPt);

                        Node newIntersectionNode = new Node(hatchNode, param, intersectionPt);
                        if (!vertSorted.Contains(newIntersectionNode))//TODO: Нужен учет допуска???
                        {
                            result = true;
                            notVisited.Add(newIntersectionNode);

                            vertSorted.Add(newIntersectionNode);
                            SortedSet <Node> boundarySorted = null;
                            boundariesSorted.TryGetValue(hatchNode, out boundarySorted);
                            if (boundarySorted == null)
                            {
                                boundarySorted = new SortedSet <Node>(new NodeParamComparer());//сортировка по параметру!!!
                                boundariesSorted.Add(hatchNode, boundarySorted);
                            }

                            if (boundarySorted.Contains(newIntersectionNode))
                            {
                                throw new Exception("Ошибка логики обхода полигона. Получены 2 точки с одинаковым параметром на одной кривой");
                            }

                            boundarySorted.Add(newIntersectionNode);
                        }
                    }
                }
                return(result);
            }
Exemple #5
0
        private ObjectId ProcessEntity(Hatch hatch, BlockTable bt)
        {
            //Для создания контура штриховки
            //Hatch.NumberOfLoops
            //Hatch.GetLoopAt
            //HatchLoop.Polyline!!!

            //Получить полилинии
            List <Polyline> polylines = new List <Polyline>();

            for (int i = 0; i < hatch.NumberOfLoops; i++)
            {
                HatchLoop             hl  = hatch.GetLoopAt(i);
                BulgeVertexCollection bvc = hl.Polyline;
                Curve2dCollection     cc  = hl.Curves;
                Polyline poly             = null;

                if (bvc != null && bvc.Count > 0)
                {
                    //сюда попадет если контур состоит из отрезков и круговых дуг
                    poly = new Polyline();
                    int vertNum = 0;
                    foreach (BulgeVertex bv in bvc)
                    {
                        poly.AddVertexAt(vertNum, bv.Vertex, bv.Bulge, 0, 0);
                        vertNum++;
                    }
                }
                else if (cc != null && cc.Count > 0)
                {
                    //сюда попадет если контур состоит только из отрезков или включает сложные линии (сплайны, эллипсы)
                    poly = new Polyline();
                    //добавить первую вершину
                    //poly.AddVertexAt(0, cc[0].StartPoint, 0, 0, 0);
                    int vertNum = 0;
                    foreach (Curve2d c in cc)
                    {
                        if (c is LinearEntity2d)
                        {
                            //добавить сегмент без кривизны
                            LinearEntity2d l2d = c as LinearEntity2d;
                            poly.AddVertexAt(vertNum, l2d.EndPoint, 0, 0, 0);
                            vertNum++;
                        }
                        else
                        {
                            //просто пропустить эту кривую (может это сплайн или еще чего)
                            //throw new System.Exception("Неверный тип 2d кривой - " + c.GetType().ToString());
                        }
                    }
                }



                if (poly != null && poly.NumberOfVertices > 1)
                {
                    //присвоить слой штриховки
                    poly.LayerId = hatch.LayerId;
                    //замкнуть
                    poly.Closed = true;

                    polylines.Add(poly);
                }
            }

            //Создать новый блок и сохранить в него полилинии
            ObjectId createdBtrId = ObjectId.Null;
            Database db           = bt.Database;

            if (polylines.Count > 0)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    //Создать новый блок для сохранения замкнутых контуров

                    BlockTableRecord btr = new BlockTableRecord();
                    btr.Name = n.ToString();
                    n++;
                    createdBtrId = bt.Add(btr);
                    tr.AddNewlyCreatedDBObject(btr, true);

                    if (createdBtrId != ObjectId.Null)
                    {
                        foreach (Polyline p in polylines)
                        {
                            btr.AppendEntity(p);
                            tr.AddNewlyCreatedDBObject(p, true);
                        }
                    }


                    tr.Commit();
                }
            }



            return(createdBtrId);
        }