public void Ali2pro()
        {
            Alignment selectedAli = GetAlignment();

            if (selectedAli != null)
            {
                ObjectIdCollection prfIds = selectedAli.GetProfileViewIds();

                try
                {
                    Boolean loopControl = true;
                    while (loopControl)
                    {
                        foreach (ObjectId item in prfIds)
                        {
                            using (Transaction ts = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
                            {
                                PromptPointOptions pntOpt = new PromptPointOptions("\nSelect a point");
                                pntOpt.AllowNone = true;
                                pntOpt.Message   = "dogruSec";
                                PromptPointResult pnt = Ed.GetPoint("\nSelect the point");
                                if (pnt.Status != PromptStatus.OK)
                                {
                                    return;
                                }
                                ;
                                Double km    = 0;
                                Double ofset = 0;
                                double x     = 0;
                                double y     = 0;
                                selectedAli.StationOffset(pnt.Value.X, pnt.Value.Y, ref km, ref ofset);
                                ProfileView pv = ts.GetObject(item, OpenMode.ForRead) as ProfileView;

                                pv.FindXYAtStationAndElevation(km, pv.Location.Y, ref x, ref y);

                                Point3d p1 = new Point3d(x, pv.Location.Y, 0);
                                Point3d p2 = new Point3d(x, pv.Location.Y + pv.ElevationMax, 0);
                                Xline   xl = new Xline();
                                xl.BasePoint   = p1;
                                xl.SecondPoint = p2;
                                BlockTable acBlkTbl;
                                acBlkTbl = ts.GetObject(Db.BlockTableId, OpenMode.ForRead) as BlockTable;
                                BlockTableRecord acBlkTblRec;
                                acBlkTblRec = ts.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                                acBlkTblRec.AppendEntity(xl);
                                ts.AddNewlyCreatedDBObject(xl, true);
                                ts.Commit();
                            }
                        }
                    }
                }
                catch (System.Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 2
0
File: Prof.cs Progetto: 15831944/EM
        getProfileViewOriginAndScale(ObjectId idPView, out double scale)
        {
            double x1 = 0;
            double y1 = 0;
            double x2 = 0;
            double y2 = 0;

            List <Point3d> pnts3d = new List <Point3d>();
            ProfileView    pview  = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    pview = (ProfileView)tr.GetObject(idPView, OpenMode.ForWrite);
                    if (pview.ElevationRangeMode == ElevationRangeType.Automatic)
                    {
                        pview.ElevationRangeMode = ElevationRangeType.UserSpecified;
                        pview.FindXYAtStationAndElevation(pview.StationStart, pview.ElevationMin, ref x1, ref y1);
                        pview.FindXYAtStationAndElevation(pview.StationEnd, pview.ElevationMax, ref x2, ref y2);
                    }
                    else
                    {
                        pview.FindXYAtStationAndElevation(pview.StationStart, pview.ElevationMin, ref x1, ref y1);
                        pview.FindXYAtStationAndElevation(pview.StationEnd, pview.ElevationMax, ref x2, ref y2);
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(string.Format("{0} Prof.cs: line: 258", ex.Message));
            }

            scale = (y2 - y1) / (pview.ElevationMax - pview.ElevationMin);
            pnts3d.Add(new Point3d(x1, y1, 0.0));
            pnts3d.Add(new Point3d(x2, y2, 0.0));

            return(pnts3d);
        }
Esempio n. 3
0
        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            if (drawable is CogoPoint)
            {
                CogoPoint cogoPt = drawable as CogoPoint;

                Database      db       = HostApplicationServices.WorkingDatabase;
                CivilDocument cdoc     = CivilDocument.GetCivilDocument(db);
                ObjectId[]    alignIds = cdoc.GetAlignmentIds().Cast <ObjectId>().ToArray();

                // Проходим по трассам четрежа
                foreach (ObjectId alignId in alignIds)
                {
                    // Если трассы нет
                    if (NotExist(alignId))
                    {
                        // Переходим к следующей
                        continue;
                    }

                    // Пикетаж и смещение точки
                    double station = 0.0, offset = 0.0;

                    // Открываем трассу на чтение
#pragma warning disable 618
                    using (Alignment align = alignId.Open
                                                 (OpenMode.ForRead, false, true) as Alignment)
#pragma warning restore 618
                    {
                        align.StationOffset(cogoPt.Location.X, cogoPt.Location.Y, ref station, ref offset);

                        // Получаем виды профилей трассы
                        ObjectId[] alignPViewIds = align.GetProfileViewIds().Cast <ObjectId>().ToArray();

                        // проходим по видам профилей
                        foreach (ObjectId pViewId in alignPViewIds)
                        {
                            if (NotExist(pViewId))
                            {
                                continue;
                            }
#pragma warning disable 618
                            using (ProfileView pView = pViewId.Open
                                                           (OpenMode.ForRead, false, true) as ProfileView)
#pragma warning restore 618
                            {
                                double pViewCoordX = 0.0, pViewCoordY = 0.0;

                                // Если тока проецируется на вид профиля
                                if (pView.FindXYAtStationAndElevation(station, cogoPt.Location.Z, ref pViewCoordX, ref pViewCoordY))
                                {
                                    // Рисуем отображение окружности в этой точке
                                    // Здесь можно отобразить любой объект (кроме маскировки), в том числе и блок
                                    using (Circle ci = new Circle
                                                           (new Point3d(pViewCoordX, pViewCoordY, pView.Location.Z),
                                                           Vector3d.ZAxis, 2.0))
                                    {
                                        ci.WorldDraw(wd);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(base.WorldDraw(drawable, wd));
        }
Esempio n. 4
0
        public void profilefrompolyline()
        {
            docCol   = Application.DocumentManager;
            database = docCol.MdiActiveDocument.Database;
            editor   = docCol.MdiActiveDocument.Editor;
            doc      = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            using (Transaction tx = database.TransactionManager.StartTransaction())
            {
                try
                {
                    PromptEntityOptions promptEntityOptions1 = new PromptEntityOptions("\n Select a polyline : ");
                    promptEntityOptions1.SetRejectMessage("\n Not a polyline");
                    promptEntityOptions1.AddAllowedClass(typeof(Polyline), true);
                    PromptEntityResult entity1 = editor.GetEntity(promptEntityOptions1);
                    if (((PromptResult)entity1).Status != PromptStatus.OK)
                    {
                        return;
                    }
                    Autodesk.AutoCAD.DatabaseServices.ObjectId plObjId = entity1.ObjectId;
                    PromptEntityOptions promptEntityOptions2           = new PromptEntityOptions("\n Select a ProfileView: ");
                    promptEntityOptions2.SetRejectMessage("\n Not a ProfileView");
                    promptEntityOptions2.AddAllowedClass(typeof(ProfileView), true);
                    PromptEntityResult entity2 = editor.GetEntity(promptEntityOptions2);
                    if (((PromptResult)entity2).Status != PromptStatus.OK)
                    {
                        return;
                    }

                    ProfileView profileView = tx.GetObject(entity2.ObjectId, OpenMode.ForWrite) as ProfileView;
                    double      x           = 0.0;
                    double      y           = 0.0;
                    if (profileView.ElevationRangeMode == ElevationRangeType.Automatic)
                    {
                        profileView.ElevationRangeMode = ElevationRangeType.UserSpecified;
                        profileView.FindXYAtStationAndElevation(profileView.StationStart, profileView.ElevationMin, ref x, ref y);
                    }
                    else
                    {
                        profileView.FindXYAtStationAndElevation(profileView.StationStart, profileView.ElevationMin, ref x, ref y);
                    }

                    ProfileViewStyle profileViewStyle = tx
                                                        .GetObject(((Autodesk.Aec.DatabaseServices.Entity)profileView)
                                                                   .StyleId, OpenMode.ForRead) as ProfileViewStyle;

                    Autodesk.AutoCAD.DatabaseServices.ObjectId layerId =
                        ((Autodesk.Aec.DatabaseServices.Entity)
                             (tx.GetObject(profileView.AlignmentId, OpenMode.ForRead) as Alignment)).LayerId;

                    Autodesk.AutoCAD.DatabaseServices.ObjectId profileStyleId = ((StyleCollectionBase)doc.Styles.ProfileStyles).FirstOrDefault();

                    Autodesk.AutoCAD.DatabaseServices.ObjectId profileLabelSetStylesId =
                        ((StyleCollectionBase)doc.Styles.LabelSetStyles.ProfileLabelSetStyles).FirstOrDefault();

                    Autodesk.AutoCAD.DatabaseServices.ObjectId profByLayout =
                        Profile.CreateByLayout("New Profile", profileView.AlignmentId, layerId, profileStyleId, profileLabelSetStylesId);

                    Profile profile = tx.GetObject(profByLayout, OpenMode.ForWrite) as Profile;

                    BlockTableRecord blockTableRecord = tx.GetObject(database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                    Polyline polyline = tx.GetObject(plObjId, OpenMode.ForRead, false) as Polyline;

                    if (polyline != null)
                    {
                        int     numOfVert = polyline.NumberOfVertices - 1;
                        Point2d point2d1;
                        Point2d point2d2;
                        Point2d point2d3;

                        for (int i = 0; i < numOfVert; i++)
                        {
                            switch (polyline.GetSegmentType(i))
                            {
                            case SegmentType.Line:
                                LineSegment2d lineSegment2dAt = polyline.GetLineSegment2dAt(i);
                                point2d1 = lineSegment2dAt.StartPoint;
                                double x1   = point2d1.X;
                                double y1   = point2d1.Y;
                                double num4 = x1 - x;
                                double num5 = (y1 - y) / profileViewStyle.GraphStyle.VerticalExaggeration + profileView.ElevationMin;
                                point2d2 = new Point2d(num4, num5);

                                point2d1 = lineSegment2dAt.EndPoint;
                                double x2   = point2d1.X;
                                double y2   = point2d1.Y;
                                double num6 = x2 - x;
                                double num7 = (y2 - y) / profileViewStyle.GraphStyle.VerticalExaggeration + profileView.ElevationMin;
                                point2d3 = new Point2d(num6, num7);

                                profile.Entities.AddFixedTangent(point2d2, point2d3);
                                break;

                            case SegmentType.Arc:
                                CircularArc2d arcSegment2dAt = polyline.GetArcSegment2dAt(i);

                                point2d1 = arcSegment2dAt.StartPoint;
                                double x3 = point2d1.X;
                                double y3 = point2d1.Y;
                                point2d1 = arcSegment2dAt.EndPoint;
                                double x4 = point2d1.X;
                                double y4 = point2d1.Y;

                                double num8  = x3 - x;
                                double num9  = (y3 - y) / profileViewStyle.GraphStyle.VerticalExaggeration + profileView.ElevationMin;
                                double num10 = x4 - x;
                                double num11 = (y4 - y) / profileViewStyle.GraphStyle.VerticalExaggeration + profileView.ElevationMin;

                                Point2d samplePoint = ((Curve2d)arcSegment2dAt).GetSamplePoints(11)[5];     //<-- was (10)[6] here, is wrong?
                                double  num12       = samplePoint.X - x;
                                double  num13       = (samplePoint.Y - y) / profileViewStyle.GraphStyle.VerticalExaggeration + profileView.ElevationMin;

                                Point2d point2d4 = new Point2d(num12, num13);
                                point2d3 = new Point2d(num10, num11);
                                point2d2 = new Point2d(num8, num9);
                                profile.Entities.AddFixedSymmetricParabolaByThreePoints(point2d2, point2d4, point2d3);

                                break;

                            case SegmentType.Coincident:
                                break;

                            case SegmentType.Point:
                                break;

                            case SegmentType.Empty:
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    editor.WriteMessage("\n" + ex.Message);
                }
                tx.Commit();
            }
        }