示例#1
0
        protected override bool WorldDraw(WorldDraw draw)
        {
            //draw.Geometry.Draw(myline);
            for (int i = 0; i < pts.Count; i++)
            {
                if (mypl.NumberOfVertices > i)
                {
                    mypl.SetPointAt(i, pts[i]);
                }
                else
                {
                    mypl.AddVertexAt(i, pts[i], 0, 0, 0);
                }
            }
            while (pts.Count < mypl.NumberOfVertices)
            {
                mypl.RemoveVertexAt(pts.Count - 1);
            }

            draw.Geometry.Draw(mypl);
            return(true);
        }
示例#2
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();
            }
        }
示例#3
0
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Matrix3d mt = ed.CurrentUserCoordinateSystem;
            JigPromptPointOptions optJigPoint = new JigPromptPointOptions("\n请指定矩形的另一角点")
            {
                Cursor            = CursorType.Crosshair,
                UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted | UserInputControls.NoNegativeResponseAccepted,
                BasePoint         = m_Pt1.TransformBy(mt),
                UseBasePoint      = true
            };
            PromptPointResult resJigPoint = prompts.AcquirePoint(optJigPoint);
            Point3d           tempPt      = resJigPoint.Value;

            if (resJigPoint.Status == PromptStatus.Cancel)
            {
                return(SamplerStatus.Cancel);
            }
            if (m_Pt2 != tempPt)
            {
                m_Pt2 = tempPt;
                Point3d ucsPt2 = m_Pt2.TransformBy(mt.Inverse());
                m_Polyline.Normal    = Vector3d.ZAxis;
                m_Polyline.Elevation = 0.0;
                m_Polyline.SetPointAt(0, new Point2d(m_Pt1.X, m_Pt1.Y));
                m_Polyline.SetPointAt(1, new Point2d(ucsPt2.X, m_Pt1.Y));
                m_Polyline.SetPointAt(2, new Point2d(ucsPt2.X, ucsPt2.Y));
                m_Polyline.SetPointAt(3, new Point2d(m_Pt1.X, ucsPt2.Y));
                m_Polyline.TransformBy(mt);
                Point3d  cenPt   = GeTools.MidPoint(m_Pt1.TransformBy(mt), m_Pt2);
                Point3d  majorPt = new Point3d(ucsPt2.X, m_Pt1.Y, 0);
                Vector3d vecX    = GeTools.MidPoint(majorPt, ucsPt2).TransformBy(mt) - cenPt;
                try
                {
                    if (Math.Abs(ucsPt2.X - m_Pt1.X) < 0.0000001 | Math.Abs(ucsPt2.Y - m_Pt1.Y) < 0.000001)
                    {
                        m_Ellipse = new Ellipse(Point3d.Origin, Vector3d.ZAxis, new Vector3d(0.00000001, 0, 0), 1.0, 0.0, 0.0);
                    }
                    else
                    {
                        double radiusRatio = Math.Abs((ucsPt2.X - m_Pt1.X) / (ucsPt2.Y - m_Pt1.Y));
                        if (radiusRatio < 1.0)
                        {
                            majorPt = new Point3d(m_Pt1.X, ucsPt2.Y, 0.0);
                            vecX    = GeTools.MidPoint(majorPt, ucsPt2).TransformBy(mt) - cenPt;
                        }
                        else
                        {
                            radiusRatio = 1.0 / radiusRatio;
                        }
                        m_Ellipse.Set(cenPt, mt.CoordinateSystem3d.Zaxis, vecX, radiusRatio, 0, 2 * Math.PI);
                    }
                }
                catch { }
                return(SamplerStatus.OK);
            }
            else
            {
                return(SamplerStatus.NoChange);
            }
        }