Example #1
0
            public PromptResult StartJig(Polyline pLine)
            {
                _pLine      = pLine;
                _prevPoint  = _pLine.GetPoint3dAt(0);
                _startPoint = _pLine.GetPoint3dAt(0);

                return(Application.DocumentManager.MdiActiveDocument.Editor.Drag(this));
            }
Example #2
0
            protected override bool WorldDraw(WorldDraw draw)
            {
                var mods    = System.Windows.Forms.Control.ModifierKeys;
                var control = (mods & System.Windows.Forms.Keys.Control) > 0;
                var pt      = _polyline.GetClosestPointTo(_currentPoint, false);
                var param   = _polyline.GetParameterAtPoint(pt);

                _vertex = Convert.ToInt32(Math.Truncate(param));
                var maxVx = _polyline.NumberOfVertices - 1;

                if (control)
                {
                    if (_vertex < maxVx)
                    {
                        _vertex++;
                    }
                }

                if (_vertex != maxVx)
                {
                    // Если вершина не последня
                    var line1 = new Line(_polyline.GetPoint3dAt(_vertex), _currentPoint)
                    {
                        ColorIndex = PlinesEditFunction.HelpGeometryColor
                    };
                    draw.Geometry.Draw(line1);
                    var line2 = new Line(_polyline.GetPoint3dAt(_vertex + 1), _currentPoint)
                    {
                        ColorIndex = PlinesEditFunction.HelpGeometryColor
                    };
                    draw.Geometry.Draw(line2);
                }
                else
                {
                    var line1 = new Line(_polyline.GetPoint3dAt(_vertex), _currentPoint)
                    {
                        ColorIndex = PlinesEditFunction.HelpGeometryColor
                    };
                    draw.Geometry.Draw(line1);
                    if (_polyline.Closed)
                    {
                        // Если полилиния замкнута, то рисуем отрезок к первой вершине
                        var line2 = new Line(_polyline.GetPoint3dAt(0), _currentPoint)
                        {
                            ColorIndex = PlinesEditFunction.HelpGeometryColor
                        };
                        draw.Geometry.Draw(line2);
                    }
                }

                return(true);
            }
Example #3
0
        /// <summary>
        /// 剪切矩形区内的图形
        /// </summary>
        /// <param name="cutBox"></param>
        public static void TrimMap(Polyline cutBox)
        {
            //关闭对象捕捉功能避免误删除
            cadApplication.SetSystemVariable("SNAPMODE", 0);
            cadApplication.SetSystemVariable("MODEMACRO", "正在修剪");
            ////获取最小与最大点
            Point3d minPoint = cutBox.GeometricExtents.MinPoint;
            Point3d maxPoint = cutBox.GeometricExtents.MaxPoint;
            ////设置缩放视口
            //设置缩放视口
            //CADTools.RunCommand(true, "Zoom", "e",
            //    new Point3d(minPoint.X - 10, minPoint.Y - 10, 0), new Point3d(maxPoint.X + 10, maxPoint.Y + 10, 0));
            //CADTools.RunCommand(false, "Zoom", "W"
            //    , new Point3d(minPoint.X - 10, minPoint.Y - 10, 0), new Point3d(maxPoint.X + 10, maxPoint.Y + 10, 0));
            //裁剪精度
            Polyline offsetBox = cutBox.GetOffsetCurves(0.2)[0] as Polyline;

            if (offsetBox.Area < cutBox.Area)
            {
                offsetBox = cutBox.GetOffsetCurves(-0.2)[0] as Polyline;
            }
            //裁剪
            for (int i = 0; i < offsetBox.NumberOfVertices; i++)
            {
                Point3d p1 = offsetBox.GetPoint3dAt(i);
                Point3d p2 = new Point3d();
                if (i == offsetBox.NumberOfVertices - 1)
                {
                    p2 = offsetBox.GetPoint3dAt(0);
                }
                else
                {
                    p2 = offsetBox.GetPoint3dAt(i + 1);
                }

                //调用Line命令,由用户结束
                //CADTools.RunCommand(true, "_.line");
                //调用Line命令并结束
                // CADTools.RunCommand(false, "_.line", Point3d.Origin, new Point3d(10, 10, 0));


                //CADTools.RunCommand(false,new ResultTree
                // CADTools.RunCommand(false, params new object[]{});
                //CADTools.RunCommand(true, ".trim"
                //    , cutBox.ObjectId, "", "F", p1, p2, "", "");
            }
            offsetBox.Dispose();
            cadApplication.SetSystemVariable("MODEMACRO", "修剪完成");
        }
Example #4
0
        public bool canAddPolyline(bool isInverted, List <Point3d> boundary, Polyline pline)
        {
            if (boundary.Count == 0 || boundary.Count == 1)
            {
                return(true);
            }
            if (boundary.Count == 2)
            {
                boundary = createRectangleForXclip(boundary);
            }
            int numberofVertex = pline.NumberOfVertices;

            if (numberofVertex == 0)
            {
                return(false);
            }
            int inSideTime = 0;

            for (int i = 0; i < numberofVertex; i++)
            {
                bool    ans;
                Point3d point = pline.GetPoint3dAt(i);
                if (isInverted)
                {
                    ans = !IsPointInPolygon(point, boundary);
                }
                else
                {
                    ans = IsPointInPolygon(point, boundary);
                }

                if (ans)
                {
                    inSideTime++;
                }
            }

            if (inSideTime == 0)
            {
                return(false);
            }
            return((double)inSideTime / numberofVertex >= 0.5);
        }
        private static Path ToPath(Autodesk.AutoCAD.DatabaseServices.Polyline pline, SpatialReference spRef)
        {
            Path path = new Path();

            if (pline.IsOnlyLines)
            {
                List <Point> list = new List <Point>();
                for (int i = 0; i < pline.NumberOfVertices; i++)
                {
                    Point3d point3dAt = pline.GetPoint3dAt(i);
                    PointN  pointN    = GIS2CAD.ToPointN(point3dAt, spRef);
                    if (pointN != null)
                    {
                        list.Add(pointN);
                    }
                }
                path.PointArray = list.ToArray();
                return(path);
            }
            return(null);
        }
Example #6
0
        public void Cmd2()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Autodesk.AutoCAD.DatabaseServices.Polyline pyLine = new Autodesk.AutoCAD.DatabaseServices.Polyline();


            var bsPointRes = ed.GetPoint(new PromptPointOptions("\n请输入圆心"));

            if (bsPointRes.Status == PromptStatus.OK)
            {
                pyLine.AddVertexAt(pyLine.NumberOfVertices, new Point2d(bsPointRes.Value.X, bsPointRes.Value.Y), 0, 0, 0);
                var jigPtOpts = new JigPromptPointOptions();

                var dimAlign = new AlignedDimension();

                var donut = new JigHelper();

                donut.SetEntities(new Entity[] { pyLine, dimAlign });

                for (int i = 1; i < int.MaxValue; i++)
                {
                    donut.PrapareForNextInput(jigPtOpts, "\n请输入下一个点");


                    donut.SetUpdate(jig =>
                    {
                        if (pyLine.NumberOfVertices == i)
                        {
                            pyLine.AddVertexAt(pyLine.NumberOfVertices, new Point2d(jig.Point.X, jig.Point.Y), 0, 0, 0);
                        }
                        else
                        {
                            pyLine.SetPointAt(i, new Point2d(jig.Point.X, jig.Point.Y));
                        }

                        Point3d pt1 = pyLine.GetPoint3dAt(i - 1);
                        Point3d pt2 = pyLine.GetPoint3dAt(i);

                        var vec3d  = pt1 - pt2;
                        var vec3d2 = vec3d.RotateBy(Math.PI / 2, Vector3d.ZAxis);



                        Point3d cPoint3d = new Point3d((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2, 0);

                        dimAlign.XLine1Point = pt1;
                        dimAlign.XLine2Point = pt2;

                        dimAlign.DimLinePoint = cPoint3d + vec3d2 * 0.5;

                        dimAlign.DimensionText = null;

                        dimAlign.DimensionStyle = ObjectId.Null;
                    });
                    dimAlign.ToSpace();
                    dimAlign = new AlignedDimension();

                    var status = donut.Drag();
                    if (status == PromptStatus.Cancel)
                    {
                        break;
                    }
                    else if (status != PromptStatus.OK)
                    {
                        return;
                    }
                }

                pyLine.ToSpace();
            }
        }
            protected override bool WorldDraw(WorldDraw draw)
            {
                var line = new Line(_startPoint, _currentPoint)
                {
                    ColorIndex = PlinesEditFunction.HelpGeometryColor
                };

                draw.Geometry.Draw(line);
                _polyline.SetBulgeAt(_vertex, _startBulge);

                // polyline edit
                var tangent = _currentPoint - _startPoint;
                int?nextVertex;

                if (_vertex != _polyline.NumberOfVertices - 1)
                {
                    nextVertex = _vertex + 1;
                }
                else if (_polyline.Closed)
                {
                    nextVertex = 0;
                }
                else
                {
                    return(true);
                }

                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (nextVertex != null)
                {
                    var chordVector = _polyline.GetPoint3dAt(nextVertex.Value) - _startPoint;

                    // По касательной
                    if (_workType.Equals("Tangent"))
                    {
                        var bulge = Math.Tan(tangent.GetAngleTo(chordVector) / 2);
                        if (tangent.GetAngleTo(chordVector, _polyline.Normal) > Math.PI)
                        {
                            bulge = -bulge;
                        }

                        _polyline.SetBulgeAt(_vertex, bulge);
                        draw.Geometry.Draw(_polyline);
                    }

                    // По точке прохождения
                    else if (_workType.Equals("Point"))
                    {
                        // Строим вспомогательную геометрию в виде дуги для получения полного угла
                        var cArc  = new CircularArc3d(_startPoint, _currentPoint, _polyline.GetPoint3dAt(nextVertex.Value));
                        var angle = cArc.ReferenceVector.AngleOnPlane(new Plane(cArc.Center, cArc.Normal));
                        var arc   = new Arc(cArc.Center, cArc.Normal, cArc.Radius,
                                            cArc.StartAngle + angle, cArc.EndAngle + angle);

                        var bulge = Math.Tan(arc.TotalAngle / 4);
                        if (tangent.GetAngleTo(chordVector, _polyline.Normal) > Math.PI)
                        {
                            bulge = -bulge;
                        }

                        _polyline.SetBulgeAt(_vertex, bulge);
                        draw.Geometry.Draw(_polyline);
                    }
                }

                return(true);
            }
Example #8
0
        public void Coord()
        {
            if (!CheckLicense.Check())
            {
                return;
            }

            Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Autodesk.AutoCAD.DatabaseServices.Database    db  = doc.Database;

            if (!init)
            {
                if (!ShowSettings())
                {
                    return;
                }
            }

            bool flag = true;

            ObjectId textStyleId = ObjectId.Null;

            using (Transaction tr = db.TransactionManager.StartTransaction())
                using (TextStyleTable tt = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead))
                {
                    if (tt.Has(TextStyleName))
                    {
                        textStyleId = tt[TextStyleName];
                    }
                    tr.Commit();
                }
            Matrix3d ucs2wcs = AcadUtility.AcadGraphics.UcsToWcs;

            while (flag)
            {
                PromptPointResult pointRes = null;
                if (AutoNumbering)
                {
                    PromptPointOptions pointOpts = new PromptPointOptions("\n" + CurrentNumber.ToString() + ". Koordinat yeri: [Reset/Liste/Seç]", "Reset List Select");
                    pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pointOpts);
                }
                else
                {
                    PromptPointOptions pointOpts = new PromptPointOptions("\nKoordinat yeri: [Reset/Seç]", "Reset Select");
                    pointRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(pointOpts);
                }

                if (pointRes.Status == PromptStatus.Cancel)
                {
                    return;
                }
                else if (pointRes.Status == PromptStatus.Keyword && pointRes.StringResult == "Reset")
                {
                    Reset();
                    return;
                }
                else if (pointRes.Status == PromptStatus.Keyword && pointRes.StringResult == "List")
                {
                    PromptPointOptions listOpts = new PromptPointOptions("\nListe yeri: ");
                    PromptPointResult  listRes  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint(listOpts);
                    ShowList(listRes.Value);
                    return;
                }
                else if (pointRes.Status == PromptStatus.Keyword && pointRes.StringResult == "Select")
                {
                    using (SelectObjectsForm form = new SelectObjectsForm())
                    {
                        if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(form) == System.Windows.Forms.DialogResult.OK)
                        {
                            // Select objects
                            List <TypedValue> tvs = new List <TypedValue>();
                            switch (form.SelectObjects)
                            {
                            case SelectObjectsForm.SelectCoordinateObjects.Polyline:
                                tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR"));
                                tvs.Add(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"));
                                tvs.Add(new TypedValue((int)DxfCode.Start, "POLYLINE"));
                                tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>"));
                                break;

                            case SelectObjectsForm.SelectCoordinateObjects.Circle:
                                tvs.Add(new TypedValue((int)DxfCode.Operator, "<OR"));
                                tvs.Add(new TypedValue((int)DxfCode.Start, "CIRCLE"));
                                tvs.Add(new TypedValue((int)DxfCode.Start, "ARC"));
                                tvs.Add(new TypedValue((int)DxfCode.Start, "ELLIPSE"));
                                tvs.Add(new TypedValue((int)DxfCode.Operator, "OR>"));
                                break;

                            case SelectObjectsForm.SelectCoordinateObjects.Block:
                                tvs.Add(new TypedValue((int)DxfCode.Start, "INSERT"));
                                break;

                            case SelectObjectsForm.SelectCoordinateObjects.Point:
                                tvs.Add(new TypedValue((int)DxfCode.Start, "POINT"));
                                break;

                            case SelectObjectsForm.SelectCoordinateObjects.Line:
                                tvs.Add(new TypedValue((int)DxfCode.Start, "LINE"));
                                break;
                            }
                            SelectionFilter filter = new SelectionFilter(tvs.ToArray());

                            PromptSelectionResult selRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(filter);
                            if (selRes.Status == PromptStatus.OK)
                            {
                                using (Transaction tr = db.TransactionManager.StartTransaction())
                                    using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite))
                                    {
                                        TextPositioner positioner = new TextPositioner(ucs2wcs, TextRotation * Math.PI / 180, LineLength);

                                        // Read object coordinates
                                        List <TextPositioner.SelectedObjectCoordinate> objectPoints = new List <TextPositioner.SelectedObjectCoordinate>();
                                        foreach (ObjectId id in selRes.Value.GetObjectIds())
                                        {
                                            if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline)))
                                            {
                                                Autodesk.AutoCAD.DatabaseServices.Polyline obj = tr.GetObject(id, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline;

                                                positioner.ClearPoints();
                                                for (int i = 0; i < obj.NumberOfVertices; i++)
                                                {
                                                    positioner.AddPoint(obj.GetPoint3dAt(i));
                                                }
                                                objectPoints.AddRange(positioner.GetPositions());
                                            }
                                            else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Circle)))
                                            {
                                                Circle obj = tr.GetObject(id, OpenMode.ForRead) as Circle;
                                                objectPoints.Add(positioner.GetPosition(obj.Center));
                                            }
                                            else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Arc)))
                                            {
                                                Arc obj = tr.GetObject(id, OpenMode.ForRead) as Arc;
                                                objectPoints.Add(positioner.GetPosition(obj.Center));
                                            }
                                            else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Ellipse)))
                                            {
                                                Ellipse obj = tr.GetObject(id, OpenMode.ForRead) as Ellipse;
                                                objectPoints.Add(positioner.GetPosition(obj.Center));
                                            }
                                            else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.BlockReference)))
                                            {
                                                BlockReference obj = tr.GetObject(id, OpenMode.ForRead) as BlockReference;
                                                objectPoints.Add(positioner.GetPosition(obj.Position));
                                            }
                                            else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.DBPoint)))
                                            {
                                                DBPoint obj = tr.GetObject(id, OpenMode.ForRead) as DBPoint;
                                                objectPoints.Add(positioner.GetPosition(obj.Position));
                                            }
                                            else if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line)))
                                            {
                                                Line obj = tr.GetObject(id, OpenMode.ForRead) as Line;
                                                positioner.ClearPoints();
                                                positioner.AddPoint(obj.StartPoint);
                                                positioner.AddPoint(obj.EndPoint);
                                                objectPoints.AddRange(positioner.GetPositions());
                                            }
                                        }
                                        // Sort coordinates
                                        objectPoints.Sort((p1, p2) =>
                                        {
                                            switch (form.Ordering)
                                            {
                                            case SelectObjectsForm.CoordinateOrdering.IncreasingX:
                                                return(p1.BasePoint.X < p2.BasePoint.X ? -1 : 1);

                                            case SelectObjectsForm.CoordinateOrdering.IncreasingY:
                                                return(p1.BasePoint.Y < p2.BasePoint.Y ? -1 : 1);

                                            case SelectObjectsForm.CoordinateOrdering.DecreasingX:
                                                return(p1.BasePoint.X > p2.BasePoint.X ? -1 : 1);

                                            case SelectObjectsForm.CoordinateOrdering.DecreasingY:
                                                return(p1.BasePoint.Y > p2.BasePoint.Y ? -1 : 1);

                                            default:
                                                return(0);
                                            }
                                        });
                                        // Write coordinates
                                        foreach (TextPositioner.SelectedObjectCoordinate coord in objectPoints)
                                        {
                                            MText mtext = CreateText(textStyleId, coord.TextPoint);
                                            btr.AppendEntity(mtext);
                                            tr.AddNewlyCreatedDBObject(mtext, true);

                                            // Rotate text
                                            if (coord.TextToLeft)
                                            {
                                                mtext.Attachment = (AutoNumbering ? AttachmentPoint.BottomRight : AttachmentPoint.MiddleRight);
                                            }
                                            else
                                            {
                                                mtext.Attachment = (AutoNumbering ? AttachmentPoint.BottomLeft : AttachmentPoint.MiddleLeft);
                                            }

                                            Line line = new Line();
                                            line.StartPoint = coord.BasePoint;
                                            line.EndPoint   = coord.TextPoint;
                                            btr.AppendEntity(line);
                                            tr.AddNewlyCreatedDBObject(line, true);

                                            points.Add(new CoordPoint(CurrentNumber, coord.BasePoint));
                                            if (AutoNumbering)
                                            {
                                                CurrentNumber = CurrentNumber + 1;
                                            }
                                        }

                                        tr.Commit();
                                    }
                            }
                        }
                    }
                    return;
                }
                else
                {
                    Point3d pCoord = pointRes.Value.TransformBy(ucs2wcs);

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                        using (BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite))
                        {
                            MText mtext = CreateText(textStyleId, pCoord);

                            btr.AppendEntity(mtext);
                            tr.AddNewlyCreatedDBObject(mtext, true);

                            if (CoordinateJig.Jig(pointRes.Value, mtext, AutoLine, LineLength, AutoRotateText, TextRotation))
                            {
                                points.Add(new CoordPoint(CurrentNumber, pCoord));
                                if (AutoNumbering)
                                {
                                    CurrentNumber = CurrentNumber + 1;
                                }

                                Line line = new Line();
                                line.StartPoint = pCoord;
                                line.EndPoint   = mtext.Location;

                                btr.AppendEntity(line);
                                tr.AddNewlyCreatedDBObject(line, true);

                                tr.Commit();
                            }
                            else
                            {
                                mtext.Dispose();
                                tr.Abort();
                                return;
                            }
                        }
                }
            }
        }
Example #9
0
        static public void transformToTunnel()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;
            PromptSelectionResult res = ed.SelectAll();

            if (res.Status == PromptStatus.Error)
            {
                return;
            }

            Autodesk.AutoCAD.EditorInput.SelectionSet SS = res.Value;

            var tmpidarray = SS.GetObjectIds();
            var idArray    = SS.GetObjectIds();

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            List <DBTunnel> inList = new List <DBTunnel>();

            Utils.TransactionControl(() =>
            {
                foreach (ObjectId id in tmpidarray)
                {
                    Entity entity = (Entity)tm.GetObject(id, OpenMode.ForWrite, true);

                    if (!(entity is Line) && !(entity is Autodesk.AutoCAD.DatabaseServices.Polyline))
                    {
                        continue;
                    }

                    if (entity is Line)
                    {
                        Line line           = entity as Line;
                        DBTunnel dbTunnel   = new DBTunnel();
                        dbTunnel.BasePoints = new List <DBVertice>
                        {
                            new DBVertice(line.StartPoint), new DBVertice(line.EndPoint)
                        };
                        inList.Add(dbTunnel);
                        line.Erase();
                    }
                    else if (entity is Autodesk.AutoCAD.DatabaseServices.Polyline)
                    {
                        Autodesk.AutoCAD.DatabaseServices.Polyline polyline =
                            entity as Autodesk.AutoCAD.DatabaseServices.Polyline;

                        DBTunnel dbTunnel   = new DBTunnel();
                        dbTunnel.BasePoints = new List <DBVertice>();

                        for (int i = 0; i < polyline.NumberOfVertices; i++)
                        {
                            dbTunnel.BasePoints.Add(new DBVertice(polyline.GetPoint3dAt(i)));
                        }

                        if (polyline.Closed == true)
                        {
                            dbTunnel.IsClosed = true;
                        }

                        inList.Add(dbTunnel);
                        polyline.Erase();
                    }
                }
            });
            var resList = DrawTunnel.StaticDrawSquareTunnel(inList);
        }