Example #1
0
        private void InitRoadwayNode()
        {
            if (_Entity == null)
            {
                _Entity = new RoadwayNodeWrapper();
                _Entity.CreateSphere(15);

                Matrix3d mt = Matrix3d.Displacement(_TransformVector);
                _Entity.TransformBy(mt);
            }
        }
Example #2
0
        static public void DoIt()
        {
            List <RoadwayWrapper> roadwayarray = new List <RoadwayWrapper>();

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //输入名字
            string name = "";
            PromptStringOptions opts2 = new PromptStringOptions("\nEnter Roadway name");
            PromptResult        res2  = ed.GetString(opts2);

            if (res2.Status == PromptStatus.Cancel)
            {
                return;
            }
            else
            {
                name = res2.StringResult;
            }


            //输入起点坐标
            PromptPointOptions opts = new PromptPointOptions("\nEnter Roadway Start Point:");
            PromptPointResult  res  = ed.GetPoint(opts);

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

            Point3d tmpPoint = res.Value;

            while (true)
            {
                //create roadway
                RoadwayJig     jig       = new RoadwayJig(tmpPoint, tmpPoint);
                RoadwayWrapper CurrentRW = (RoadwayWrapper)jig.GetEntity();
                jig.SetName(name);

                jig.setPromptCounter(0);
                PromptResult drag = ed.Drag(jig);
                if (drag.Status == PromptStatus.Cancel || drag.Status == PromptStatus.None)
                {
                    return;
                }
                else if (drag.Status == PromptStatus.OK)
                {
                    Database db = Application.DocumentManager.MdiActiveDocument.Database;

                    Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

                    PROJECT pro = new PROJECT();
                    using (Transaction myT = tm.StartTransaction())
                    {
                        pro.AppendEntity(CurrentRW);

                        RoadwayNodeWrapper sttNd;
                        if (roadwayarray.Count > 0)
                        {
                            RoadwayWrapper PreviousRW =
                                (RoadwayWrapper)myT.GetObject(roadwayarray[roadwayarray.Count - 1].ObjectId, OpenMode.ForRead, false);
                            //Point3dCollection pc = new Point3dCollection();
                            // CurrentRW.IntersectWith(PreviousRW, Intersect.OnBothOperands, pc, IntPtr.Zero, IntPtr.Zero);
                            // CurrentRW.StartNodeHandle = PreviousRW.EndNodeHandle;
                            ObjectId tmpid = db.GetObjectId(false, PreviousRW.EndNodeHandle, 0);
                            sttNd = (RoadwayNodeWrapper)myT.GetObject(tmpid, OpenMode.ForWrite, false);
                            sttNd.appendRoadway(CurrentRW.Handle, 1);

                            CurrentRW.StartNodeHandle = sttNd.Handle;
                        }
                        else
                        {
                            sttNd = new RoadwayNodeWrapper();
                            pro.AppendEntity(sttNd);
                            sttNd.CreateSphere(15);
                            sttNd.init(CurrentRW.Handle, 1);
                            sttNd.Position = CurrentRW.StartPoint;

                            CurrentRW.StartNodeHandle = sttNd.Handle;
                        }

                        RoadwayNodeWrapper endNd = new RoadwayNodeWrapper();
                        pro.AppendEntity(endNd);
                        endNd.CreateSphere(15);
                        endNd.init(CurrentRW.Handle, -1);
                        endNd.Position          = CurrentRW.EndPoint;
                        CurrentRW.EndNodeHandle = endNd.Handle;

                        roadwayarray.Add(CurrentRW);
                        myT.Commit();
                    }

                    tmpPoint = jig.GetEndPoint();
                }
            }
        }