Beispiel #1
0
        private List <G.Line> getGeometry()
        {
            List <G.Line> polys = new List <G.Line>();

            _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions();
            opts.MessageForAdding = "\nSelect Geometry: ";

            _Ed.PromptSelectionResult userSelection = _c.doc.Editor.GetSelection(opts);

            if (userSelection.Status != _Ed.PromptStatus.OK)
            {
                throw new DMTException("[ERROR] Geometry - cancelled");
            }

            _Ed.SelectionSet selectionSet = userSelection.Value;

            foreach (_Ed.SelectedObject currentObject in selectionSet)
            {
                if (currentObject == null)
                {
                    continue;
                }
                _Db.Entity currentEntity = _c.trans.GetObject(currentObject.ObjectId, _Db.OpenMode.ForRead) as _Db.Entity;
                if (currentEntity == null)
                {
                    continue;
                }

                if (currentEntity is _Db.Polyline)
                {
                    _Db.Polyline poly   = _c.trans.GetObject(currentEntity.ObjectId, _Db.OpenMode.ForRead) as _Db.Polyline;
                    int          points = poly.NumberOfVertices;

                    for (int i = 1; i < points; i++)
                    {
                        _Ge.Point2d p1 = poly.GetPoint2dAt(i - 1);
                        _Ge.Point2d p2 = poly.GetPoint2dAt(i);

                        G.Point new_p1 = new G.Point(p1.X, p1.Y);
                        G.Point new_p2 = new G.Point(p2.X, p2.Y);

                        if (new_p1 == new_p2)
                        {
                            continue;
                        }

                        G.Line line = new G.Line(new_p1, new_p2);
                        if (!polys.Contains(line))
                        {
                            polys.Add(line);
                        }
                    }

                    if (poly.Closed)
                    {
                        _Ge.Point2d p1     = poly.GetPoint2dAt(points - 1);
                        _Ge.Point2d p2     = poly.GetPoint2dAt(0);
                        G.Point     new_p1 = new G.Point(p1.X, p1.Y);
                        G.Point     new_p2 = new G.Point(p2.X, p2.Y);

                        if (new_p1 == new_p2)
                        {
                            continue;
                        }

                        G.Line line = new G.Line(new_p1, new_p2);
                        if (!polys.Contains(line))
                        {
                            polys.Add(line);
                        }
                    }
                }
            }

            if (polys.Count < 3)
            {
                throw new DMTException("[ERROR] Geometry - less then 3");
            }

            return(polys);
        }