Ejemplo n.º 1
0
        public Poze()
        {
            InitializeComponent();
            imagini      = new SortedDictionary <int, string>();
            imaginiCheie = new SortedDictionary <int, string>();
            listaFisiere = new List <string>();

            ObjectIdCollection idAxuri = civDoc.GetAlignmentIds();

            db = acadDoc.Database;
            ed = acadDoc.Editor;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId idAx in idAxuri)
                {
                    Axuri.Add((Alignment)trans.GetObject(idAx, OpenMode.ForRead));
                    comboBoxAx.Items.Add(Axuri.Last());
                }
                RegAppTable rat = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite, false);
                if (!rat.Has("OVIDIU"))
                {
                    //rat.UpgradeOpen();
                    RegAppTableRecord ratr = new RegAppTableRecord();
                    ratr.Name = "OVIDIU";
                    rat.Add(ratr);
                    trans.AddNewlyCreatedDBObject(ratr, true);
                }
                trans.Commit();
            }
            comboBoxAx.SelectedIndex = 0;


            //SelectieDirector();
            //AfisarePoze();
        }
Ejemplo n.º 2
0
        public void Speckle()
        {
            // Gets the current document, and prints some basic information about it
            // to the command editor window.



            CivilDocument doc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;

            var bindings = new SpeckleUIBindingsAutoCAD(doc);

            ObjectIdCollection alignments = doc.GetAlignmentIds();
            ObjectIdCollection sites      = doc.GetSiteIds();
            String             docInfo    = String.Format("\nHello Speckle!");

            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(docInfo);

            SpeckleWindow = new SpeckleUiWindow(bindings);

            var helper = new System.Windows.Interop.WindowInteropHelper(SpeckleWindow);

            helper.Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

            SpeckleWindow.Show();
            Launched = true;
        }
        public List <BaseC3dObject> GetAlignmentIds()
        {
            Document             doc       = Application.DocumentManager.MdiActiveDocument;
            Database             db        = doc.Database;
            CivilDocument        civilDoc  = CivilApplication.ActiveDocument;
            ObjectIdCollection   alignIds  = civilDoc.GetAlignmentIds();
            List <BaseC3dObject> alignList = new List <BaseC3dObject>();

            if (alignIds.Count == 0)
            {
                return(null);
            }
            else
            {
                using (Transaction ts = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        foreach (ObjectId id in alignIds)
                        {
                            Alignment     align   = ts.GetObject(id, OpenMode.ForRead) as Alignment;
                            BaseC3dObject bObject = new BaseC3dObject();
                            bObject.Id   = align.ObjectId;
                            bObject.Name = align.Name;
                            alignList.Add(bObject);
                        }
                    }
                    catch (System.Exception)
                    {
                        throw;
                    }
                }
                return(alignList);
            }
        }
        public static void ExportAlignmentName()
        {
            Document      doc    = Application.DocumentManager.MdiActiveDocument;
            CivilDocument civDoc = CivilApplication.ActiveDocument;

            JObject alignNameCol = new JObject();

            using (Transaction trans = doc.TransactionManager.StartTransaction())
            {
                JArray alignName = new JArray();

                foreach (ObjectId alignId in civDoc.GetAlignmentIds())
                {
                    Alignment align = trans.GetObject(alignId, OpenMode.ForRead) as Alignment;
                    alignName.Add(align.Name);
                }

                alignNameCol.Add(new JProperty("name", alignName));
                trans.Commit();
            }

            using (StreamWriter file = File.CreateText("AlignmentName.json"))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    alignNameCol.WriteTo(writer);
                }
        }
Ejemplo n.º 5
0
        public ResultBuffer GetAlignmentIds(ResultBuffer resbuf)
        {
            var nil = new TypedValue((int)LispDataType.Nil);

            if (resbuf == null)
            {
                CivilDocument      currentDocument = CivilApplication.ActiveDocument;
                ObjectIdCollection alignmentIds    = currentDocument.GetAlignmentIds();
                ResultBuffer       returnValue     = ListObjectIds(alignmentIds);
                return(returnValue);
            }
            return(new ResultBuffer(nil));
        }
Ejemplo n.º 6
0
        public static Profile ByAlignmentAndSurface(Autodesk.AutoCAD.DynamoNodes.Document document, Alignment parentAlignment, Surface parentSurface, string name, Styles.ProfileStyle profileStyle, ProfileLabelSet profileLabelSet)
        {
            Autodesk.Civil.DatabaseServices.Profile newProfile = null;
            AcadApp.Document curDoc = document.AcDocument;
            Database         db     = curDoc.Database;

            Autodesk.Civil.DatabaseServices.Surface civilSurface = (Autodesk.Civil.DatabaseServices.Surface)parentSurface.InternalDBObject;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                string oName = name;
                // need to assign these values based on the string inputs
                LayerTable lyrTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);
                //ObjectId layerId = Utilities.GetLayerByName(db, layer.Name); // id of layer to add profile to
                // get the layer name defined in the settings
                ObjectId           layerId       = Utilities.GetLayerByName(db, CivilDynamoTools.Settings.Settings.GetLayerName(document, Autodesk.Civil.Settings.SettingsObjectLayerType.Profile, name));
                ObjectId           styleId       = profileStyle.InternalObjectId;    // id of style to assign the profile
                ObjectId           labelSetId    = profileLabelSet.InternalObjectId; // id of label set to assign
                CivilDocument      civilDocument = Autodesk.Civil.ApplicationServices.CivilDocument.GetCivilDocument(document.AcDocument.Database);
                ObjectIdCollection alignIds      = civilDocument.GetAlignmentIds();
                // make sure the name doesn't already exist for any profile
                int copy = 1;
                foreach (ObjectId aId in alignIds)
                {
                    Autodesk.Civil.DatabaseServices.Alignment civilAlignment = (Autodesk.Civil.DatabaseServices.Alignment)trans.GetObject(aId, OpenMode.ForRead);
                    ObjectIdCollection profIds = civilAlignment.GetProfileIds();
                    foreach (ObjectId pId in profIds)
                    {
                        Autodesk.Civil.DatabaseServices.Profile civilProfile = (Autodesk.Civil.DatabaseServices.Profile)trans.GetObject(pId, OpenMode.ForRead);
                        if (civilProfile.Name == name)
                        {
                            name  = oName + " - " + copy;
                            copy += 1;
                        }
                    }
                }
                ObjectId newProfileId = Autodesk.Civil.DatabaseServices.Profile.CreateFromSurface(name, parentAlignment.InternalObjectId, parentSurface.InternalObjectId, layerId, styleId, labelSetId);
                newProfile = (Autodesk.Civil.DatabaseServices.Profile)trans.GetObject(newProfileId, OpenMode.ForRead);
                trans.Commit();
            }
            if (newProfile == null)
            {
                return(null);
            }
            else
            {
                return(new Profile(newProfile, true));
            }
        }
Ejemplo n.º 7
0
        public static Alignment ByIndex(int index)
        {
            CivilDocument      civilDocument = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
            Alignment          alignment     = null;
            ObjectIdCollection alignIds      = civilDocument.GetAlignmentIds();

            //get the current document and database
            AcadApp.Document doc = AcadApp.Application.DocumentManager.MdiActiveDocument;
            Database         db  = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                alignment = new Alignment((Autodesk.Civil.DatabaseServices.Entity)trans.GetObject(alignIds[index], OpenMode.ForRead), false);
            }
            return(alignment);
        }
Ejemplo n.º 8
0
        [CommandMethod("ep")] //Comanda care exporta punctele din desenul curent in format PSOENZD csv
        public void ExportPoints()
        {
            CivilDocument civDoc = CivilApplication.ActiveDocument;
            Editor        ed     = Application.DocumentManager.MdiActiveDocument.Editor;

            if (civDoc.GetAllPointIds().Count == 0)
            {
                ed.WriteMessage("\nNo Cogo Points found!");
                return;
            }
            if (civDoc.GetAlignmentIds().Count == 0)
            {
                ed.WriteMessage("\nNo Alignments Points found!");
                return;
            }
            Ovidiu.x64.Civil3dUtil.ExportPoints Formular = new ExportPoints();
            Application.ShowModalDialog(Formular);
            ed.WriteMessage(Formular.cmbBoxAlignment.SelectedItem.ToString());
        }
Ejemplo n.º 9
0
        public static IList <Alignment> GetAlignments(Autodesk.AutoCAD.DynamoNodes.Document document)
        {
            CivilDocument      civilDocument = Autodesk.Civil.ApplicationServices.CivilDocument.GetCivilDocument(document.AcDocument.Database);
            ObjectIdCollection alignmentIds  = civilDocument.GetAlignmentIds();

            //get the current document and database
            AcadApp.Document doc        = AcadApp.Application.DocumentManager.MdiActiveDocument;
            Database         db         = doc.Database;
            List <Alignment> alignments = new List <Alignment>();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId objectId in alignmentIds)
                {
                    alignments.Add(new Alignment((Autodesk.Civil.DatabaseServices.Alignment)trans.GetObject(objectId, OpenMode.ForRead), false));
                }
            }
            return(alignments);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Get an alignments in the drawing by name
        /// </summary>
        /// <param name="document">Document</param>
        /// <param name="alignmentName">The name of an alignment</param>
        /// <returns></returns>
        public static Alignment GetAlignmentByName(Document document, string alignmentName)
        {
            if (document is null)
            {
                throw new ArgumentNullException("document is null!");
            }
            if (alignmentName is null)
            {
                throw new ArgumentNullException("alignmentName is null!");
            }

            using (var context = new DocumentContext(document.AcDocument))
            {
                CivilDocument cdoc = CivilDocument
                                     .GetCivilDocument(context.Database);

                Transaction tr = context.Transaction;

                ObjectIdCollection alignIds = cdoc.GetAlignmentIds();

                foreach (ObjectId alignId in alignIds)
                {
                    if (!alignId.IsValid ||
                        alignId.IsErased ||
                        alignId.IsEffectivelyErased)
                    {
                        continue;
                    }

                    if (tr.GetObject(alignId, OpenMode.ForRead, false, true)
                        is C3dDb.Alignment align)
                    {
                        if (align.Name.Equals(alignmentName, StringComparison.OrdinalIgnoreCase))
                        {
                            return(new Alignment(align));
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 11
0
        public Poze()
        {
            civDoc = CivilApplication.ActiveDocument;
            db     = acadDoc.Database;
            ed     = acadDoc.Editor;
            //trans = db.TransactionManager.StartTransaction();
            using (trans = db.TransactionManager.StartTransaction())
            {
                idAxuri = civDoc.GetAlignmentIds();
                InitializeComponent();
                imagini      = new SortedDictionary <int, string>();
                imaginiCheie = new SortedDictionary <int, string>();
                listaFisiere = new List <string>();

                ActualizeazaAxuri();
                //comboBoxAx.SelectedIndex = 0;

                RegAppTable rat = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite, false);
                if (!rat.Has("OVIDIU"))
                {
                    //rat.UpgradeOpen();
                    RegAppTableRecord ratr = new RegAppTableRecord();
                    ratr.Name = "OVIDIU";
                    rat.Add(ratr);
                    trans.AddNewlyCreatedDBObject(ratr, true);
                }
                trans.Commit();
            }

            //Instalare carlig pentru soarece
            MH.RightButtonDown += MH_RightButtonDown;
            MH.LeftButtonDown  += MH_LeftButtonDown;
            if (checkBoxSincr.Checked)
            {
                MH.Install();
            }

            //HookManager.MouseClick += HookManager_MouseClick;
            //SelectieDirector();
            //AfisarePoze();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the names of all alignments in the drawing
        /// </summary>
        /// <param name="document">Drawing document</param>
        /// <param name="allowReference">Include the referenced alignment to the result</param>
        /// <returns>List of alignments names</returns>
        public static IList <string> GetAllAlignmentNames(Document document, bool allowReference)
        {
            if (document is null)
            {
                throw new ArgumentNullException("document is null!");
            }

            IList <string> alignNames = new List <string>();

            using (var context = new DocumentContext(document.AcDocument))
            {
                CivilDocument cdoc = CivilDocument
                                     .GetCivilDocument(context.Database);

                Transaction tr = context.Transaction;

                ObjectIdCollection alignIds = cdoc.GetAlignmentIds();

                foreach (ObjectId alignId in alignIds)
                {
                    if (!alignId.IsValid ||
                        alignId.IsErased ||
                        alignId.IsEffectivelyErased)
                    {
                        continue;
                    }

                    if (tr.GetObject(alignId, OpenMode.ForRead, false, true)
                        is C3dDb.Alignment align)
                    {
                        if (allowReference ||
                            (!align.IsReferenceObject && !align.IsReferenceSubObject))
                        {
                            alignNames.Add(align.Name);
                        }
                    }
                }
            }

            return(alignNames);
        }
Ejemplo n.º 13
0
        public static Alignment ByName(string alignmentName)
        {
            CivilDocument      civilDocument = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument;
            Alignment          alignment     = null;
            ObjectIdCollection alignIds      = civilDocument.GetAlignmentIds();

            //get the current document and database
            AcadApp.Document doc = AcadApp.Application.DocumentManager.MdiActiveDocument;
            Database         db  = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId objectId in alignIds)
                {
                    alignment = new Alignment((Autodesk.Civil.DatabaseServices.Entity)trans.GetObject(objectId, OpenMode.ForRead), false);
                    if (alignment.Name != alignmentName)
                    {
                        alignment = null;
                    }
                }
            }
            return(alignment);
        }
Ejemplo n.º 14
0
        [CommandMethod("ES")] //Comanda care exporta un set de sectiuni in format KmOZD txt
        public void ExportSections()
        {
            CivilDocument civDoc      = CivilApplication.ActiveDocument;
            Document      acadDoc     = Application.DocumentManager.MdiActiveDocument;
            Editor        ed          = Application.DocumentManager.MdiActiveDocument.Editor;
            Database      db          = HostApplicationServices.WorkingDatabase;
            string        caleDocAcad = HostApplicationServices.Current.FindFile(acadDoc.Name, db, FindFileHint.Default);

            //Optiuni pentru selectia unei sectiuni
            PromptEntityOptions PrEntOpt = new PromptEntityOptions("\nSelect a section from the desired set to be exported: ");

            PrEntOpt.SetRejectMessage("\nThe selected object is not a Section object! ");
            PrEntOpt.AddAllowedClass(typeof(CivilDBS.Section), true);

            //Selectia unei sectiuni din setul ce trebuie exportat
            PromptEntityResult PrEntRes = ed.GetEntity(PrEntOpt);

            if (PrEntRes.Status == PromptStatus.OK)
            {
                ObjectId SSID = PrEntRes.ObjectId;
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    //Obtinerea sectiunii din baza de date, aflarea sursei acesteia si a grupului de sectiuni din care face parte
                    CivilDBS.Section SS = (CivilDBS.Section)trans.GetObject(SSID, OpenMode.ForRead);
                    int    SSstart      = SS.Name.LastIndexOf("- ") + 2;
                    int    SSend        = SS.Name.LastIndexOf('(');
                    string SSsource     = SS.Name.Substring(SSstart, SSend - SSstart);
                    ed.WriteMessage("\nSelected sections's source is: {0}", SSsource);

                    CivilDBS.SampleLine      SL  = (CivilDBS.SampleLine)trans.GetObject(SS.SampleLineId, OpenMode.ForRead);
                    CivilDBS.SampleLineGroup SLG = (CivilDBS.SampleLineGroup)trans.GetObject(SL.GroupId, OpenMode.ForRead);

                    //Aflarea aliniamentului de care apartine grupul de sectiuni
                    string             numeAx = String.Empty;
                    ObjectIdCollection ALIDS  = civDoc.GetAlignmentIds();
                    try
                    {
                        foreach (ObjectId ALID in ALIDS)
                        {
                            Alignment AL = (Alignment)trans.GetObject(ALID, OpenMode.ForRead);
                            if (AL.GetSampleLineGroupIds().Contains(SL.GroupId))
                            {
                                numeAx = AL.Name;
                            }
                        }
                    }
                    catch
                    {
                    }

                    string       caleFisSect = caleDocAcad.Remove(caleDocAcad.LastIndexOf('.')) + " - " + numeAx + " - " + SSsource + ".txt";
                    StreamWriter scriitor    = new StreamWriter(caleFisSect);

                    //Exportarea datelor

                    ObjectIdCollection SLIDS = SLG.GetSampleLineIds();
                    foreach (ObjectId SLID in SLIDS)
                    {
                        CivilDBS.SampleLine currSL = (CivilDBS.SampleLine)trans.GetObject(SLID, OpenMode.ForRead);
                        ObjectIdCollection  SIDS   = currSL.GetSectionIds();
                        foreach (ObjectId SID in SIDS)
                        {
                            CivilDBS.Section S = (CivilDBS.Section)trans.GetObject(SID, OpenMode.ForRead);
                            int    Sstart      = S.Name.LastIndexOf("- ") + 2;
                            int    Send        = S.Name.LastIndexOf('(');
                            string Ssource     = S.Name.Substring(Sstart, Send - Sstart);
                            if (SSsource == Ssource)
                            {
                                CivilDBS.SectionPointCollection Spoints = S.SectionPoints;
                                double LO = -999;
                                double RO = 999;
                                try
                                {
                                    LO = S.LeftOffset;
                                    RO = S.RightOffset;
                                }
                                catch
                                {
                                    ed.WriteMessage("\nLimits of section at chainage: {0} cound not be read! Section skipped.", S.Station);
                                    continue;
                                }
                                for (int i = 0; i < Spoints.Count; i++)
                                {
                                    //if (Spoints[i].Location.X >= S.LeftOffset && Spoints[i].Location.X <= S.RightOffset)
                                    if (Spoints[i].Location.X >= LO && Spoints[i].Location.X <= RO)
                                    {
                                        string sectiune = S.Station.ToString() + "," +
                                                          Spoints[i].Location.X.ToString("F4") + "," +
                                                          Spoints[i].Location.Y.ToString("F4") + "," + Ssource;
                                        scriitor.WriteLine(sectiune);
                                    }
                                }
                                //Polyline poly = (Polyline)S.BaseCurve;
                                //for (int i = 0; i < poly.NumberOfVertices; i++)
                                //{
                                //    Point3d p = poly.GetPoint3dAt(i);
                                //    string sectiune = S.Station.ToString() + "," +
                                //    p.X.ToString("F3") + "," +
                                //    p.Y.ToString("F3") + "," + Ssource;
                                //    scriitor.WriteLine(sectiune);
                                //}
                            }
                        }
                    }

                    scriitor.Dispose();
                }
            }
        }
        public static void ExportReport()
        {
            Document      acadDoc = Application.DocumentManager.MdiActiveDocument;
            CivilDocument civDoc  = CivilApplication.ActiveDocument;

            List <MainPoint> mainPointCol = new List <MainPoint>();

            using (Transaction ts = acadDoc.Database.TransactionManager.StartTransaction())
            {
                // JSON に出力した線形名を取得
                dynamic inputParams = JsonConvert.DeserializeObject <dynamic>(File.ReadAllText(".\\AlignmentNameForReport.json"));
                string  alignName   = inputParams.name;

                // 線形を取得
                Alignment align = civDoc.GetAlignmentIds().Cast <ObjectId>()
                                  .Select(item => (Alignment)ts.GetObject(item, OpenMode.ForRead))
                                  .First(item => item.Name == alignName);

                // 線形の測点インデックス増分値を取得
                double stationIndexIncrement = align.StationIndexIncrement;

                // 線形の Entity オブジェクトを取得 -> 測点の順番で並べ替え
                IEnumerable <AlignmentCurve> alignCurveOrderedCol = align.Entities.Cast <AlignmentCurve>().OrderBy(item => item.StartStation);

                // 各測点の MainPoint オブジェクトを mainPointCol に追加
                int lineIndex = 0;
                int scsIndex  = 0;

                foreach (AlignmentCurve alignCurve in alignCurveOrderedCol)
                {
                    switch (alignCurve.EntityType)
                    {
                    case AlignmentEntityType.Line:
                        AlignmentLine alignLine = alignCurve as AlignmentLine;
                        mainPointCol.Add(new MainPoint(alignLine, lineIndex, stationIndexIncrement));
                        lineIndex += 1;
                        break;

                    case AlignmentEntityType.SpiralCurveSpiral:
                        AlignmentSCS alignSCS = alignCurve as AlignmentSCS;
                        mainPointCol.Add(new MainPoint(alignSCS.SpiralIn, scsIndex, stationIndexIncrement)
                        {
                        });
                        mainPointCol.Add(new MainPoint(alignSCS.Arc, scsIndex, stationIndexIncrement)
                        {
                        });
                        mainPointCol.Add(new MainPoint(alignSCS.SpiralOut, scsIndex, stationIndexIncrement)
                        {
                        });
                        scsIndex += 1;
                        break;

                    default:
                        return;
                    }

                    try { _ = alignCurve.EntityAfter; }
                    catch (EntityNotFoundException ex)
                    {
                        AlignmentLine alignLine = alignCurve as AlignmentLine;
                        mainPointCol.Add(new MainPoint(alignLine, -1, stationIndexIncrement)
                        {
                        });
                    }
                }

                ts.Commit();
            }

            List <string> header = new List <string>()
            {
                "主要点名称", "測点", "X 座標", "Y 座標", "要素長", "接線角", "始点半径", "終点半径", "パラメータ A"
            };

            string excelFilePath = ".\\Report.xlsx";

            using (XLWorkbook workbook = new XLWorkbook())
            {
                IXLWorksheet worksheet = workbook.AddWorksheet("Sheet1");
                worksheet.Cell("A1").InsertData(header, true);
                worksheet.Cell("A2").InsertData(mainPointCol);
                workbook.SaveAs(excelFilePath);
            }
        }
Ejemplo n.º 16
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));
        }
Ejemplo n.º 17
0
        private void ExportPoints_Load(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.ApplicationServices.Document AcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            CivilDocument CivilDoc = CivilApplication.ActiveDocument;
            Database      db       = AcadDoc.Database;
            Editor        ed       = AcadDoc.Editor;

            ObjectIdCollection alignmentIds = CivilDoc.GetAlignmentIds(); //lista ID aliniamente
            ObjectIdCollection pointIds     = CivilDoc.GetAllPointIds();  //lista ID puncte

            using (Transaction trans = AcadDoc.TransactionManager.StartTransaction())
            {
                //Popularea listei de aliniamente
                double length           = 0;
                string LongestAlignName = string.Empty;
                foreach (ObjectId alinId in alignmentIds)
                {
                    Alignment alin = (Alignment)trans.GetObject(alinId, OpenMode.ForRead);
                    this.cmbBoxAlignment.Items.Add(alin.Name);
                    alinIdTable.Add(alin.Name, alinId);
                    if (alin.Length > length)
                    {
                        LongestAlignName = alin.Name;
                        length           = alin.Length;
                    }
                }
                this.cmbBoxAlignment.Text = LongestAlignName;

                //Obtinerea listei cu toate punctele din desen
                foreach (ObjectId pointId in pointIds)
                {
                    CogoPoint point = (CogoPoint)trans.GetObject(pointId, OpenMode.ForRead);
                    Ovidiu.StringUtil.Punct3D punct = new StringUtil.Punct3D();
                    Alignment alin = (Alignment)trans.GetObject((ObjectId)alinIdTable[cmbBoxAlignment.Text], OpenMode.ForRead);

                    punct.Nr = (int)point.PointNumber;
                    punct.X  = point.Location.X;
                    punct.Y  = point.Location.Y;
                    punct.Z  = point.Location.Z;
                    punct.D  = point.RawDescription;
                    double kmPunct     = 0;
                    double offsetPunct = 0;
                    try
                    {
                        alin.StationOffset(punct.X, punct.Y, ref kmPunct, ref offsetPunct);
                    }
                    catch
                    {
                        kmPunct     = -999;
                        offsetPunct = -999;
                    }
                    punct.KM     = kmPunct;
                    punct.Offset = offsetPunct;

                    listaPuncte.Add(punct);
                }
                //listaScurta = listaPuncte;

                //Popularea tabelului de previzualizare
                fillTable(listaPuncte);

                ed.WriteMessage(listaPuncte.Count.ToString());
                trans.Commit();
            }
        }
Ejemplo n.º 18
0
        private void textBoxDir_TextChanged(object sender, EventArgs e)
        {
            imagini.Clear();
            imaginiCheie.Clear();
            listaFisiere.Clear();
            pictureBox1.Image = null;

            if (IO.Directory.Exists(textBoxDir.Text))
            {
                //Asociere director cu aliniamentul
                using (acadDoc.LockDocument())
                    using (Transaction trdir = db.TransactionManager.StartTransaction())
                        using (ResultBuffer RB = new ResultBuffer(new TypedValue(1001, "OVIDIU"), new TypedValue(1000, "POZE->" + textBoxDir.Text)))
                        {
                            //Alignment Ax = (Alignment)trans.GetObject(((Alignment)comboBoxAx.SelectedItem).Id, OpenMode.ForWrite);
                            string    nume = ((Alignment)comboBoxAx.SelectedItem).Name;
                            Alignment Ax   = null;
                            foreach (ObjectId idAx in civDoc.GetAlignmentIds())
                            {
                                Ax = (Alignment)trdir.GetObject(idAx, OpenMode.ForRead);
                                if (Ax.Name == nume)
                                {
                                    Ax.UpgradeOpen();
                                    Ax.XData = RB;
                                }
                            }
                            //Ax.UpgradeOpen();
                            //Ax.XData = RB;


                            //Capturare Senzor
                            CapturaSenzor();
                            //CapturaSenzor(trans, Ax);
                            //TypedValue[] TVs = new TypedValue[]
                            //{
                            //    new TypedValue(0, "SOLID"),
                            //    new TypedValue(8, "AR-MArker"),
                            //    new TypedValue(62, "3")
                            //};
                            //SelectionFilter SF = new SelectionFilter(TVs);
                            //PromptSelectionResult PSR = ed.SelectAll(SF);
                            //if (PSR.Status != PromptStatus.OK) return;
                            //SelectionSet SS = PSR.Value;
                            //foreach (SelectedObject SO in SS)
                            //{
                            //    Solid S = (Solid)trans.GetObject(SO.ObjectId, OpenMode.ForRead);
                            //    double[] Xs = { S.GetPointAt(0).X, S.GetPointAt(1).X, S.GetPointAt(2).X };
                            //    double[] Ys = { S.GetPointAt(0).Y, S.GetPointAt(1).Y, S.GetPointAt(2).Y };
                            //    double km = double.NaN;
                            //    double offset = double.NaN;
                            //    try
                            //    {
                            //        Ax.StationOffset(Xs.Average(), Ys.Average(), ref km, ref offset);
                            //    }
                            //    catch { }
                            //    if (offset != double.NaN)
                            //    {
                            //        if (Senzor == null) Senzor = S;
                            //        else
                            //        {
                            //            double[] SenzorXs = { Senzor.GetPointAt(0).X, Senzor.GetPointAt(1).X, Senzor.GetPointAt(2).X };
                            //            double[] SenzorYs = { Senzor.GetPointAt(0).Y, Senzor.GetPointAt(1).Y, Senzor.GetPointAt(2).Y };
                            //            double SenzorKm = double.NaN;
                            //            double SenzorOffset = double.NaN;
                            //            try
                            //            {
                            //                Ax.StationOffset(SenzorXs.Average(), SenzorYs.Average(), ref SenzorKm, ref SenzorOffset);
                            //                if (offset < SenzorOffset) Senzor = S;
                            //            }
                            //            catch { }
                            //        }
                            //    }
                            //}
                            //if (Senzor != null) checkBoxSincr.Checked = true; //

                            trdir.Commit();
                        }//

                //Inregistrare vedere curenta
                VTRcur = ed.GetCurrentView().Clone() as ViewTableRecord;

                //Citire imaginiCheie din fisierul CALIBRARE.TXT daca acesta exista
                if (IO.File.Exists(textBoxDir.Text + @"\CALIBRARE.TXT"))
                {
                    using (IO.StreamReader reader = new IO.FileInfo(textBoxDir.Text + @"\CALIBRARE.TXT").OpenText())
                    {
                        string linie = null;
                        while ((linie = reader.ReadLine()) != null)
                        {
                            if (linie.Contains("********"))
                            {
                                try
                                {
                                    string[] componente = linie.Remove(0, 4).Replace("********", "").Split(new string[] { "-> " }, StringSplitOptions.None);
                                    imaginiCheie.Add(int.Parse(componente[0]), componente[1]);
                                }
                                catch { }
                            }
                        }
                    }
                    //WF.MessageBox.Show("Numar chei citite: " + imaginiCheie.Count.ToString() + ": " + imaginiCheie.ToString());
                }

                ActualizarePoze();
            }
            else
            {
                textBoxDir.Text = @"-";
            }
        }
Ejemplo n.º 19
0
        [CommandMethod("zs")] //Comanda care centreaza imaginea la km solicitat al unui ax
        public void ZoomStation()
        {
            CivilDocument      doc          = CivilApplication.ActiveDocument;
            ObjectIdCollection alignmentIds = doc.GetAlignmentIds(); //lista ID aliniamente
            //ObjectIdCollection sites = doc.GetSiteIds();

            Editor   ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

            ///Alegere ax principal///
            ///Citire fisier de optiuni
            //Cauta fisierul de configurare in calea implicita sau creaza unul
            if (alignmentIds.Count == 0)
            {
                ed.WriteMessage("\nNo alignments found! ");
                return;
            }
            string cale;

            cale = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Optiuni.cfg";
            cale = Path.GetFullPath(cale);
            if (File.Exists(cale) == false)
            {
                try
                {
                    using (StreamWriter scriitor = new StreamWriter(cale))
                    {
                        scriitor.Write("\r\n");
                    }
                }
                catch
                {
                    ed.WriteMessage("\nUnsuccessful selection of Configuration File");
                }
            }
            Ovidiu.x64.General.Configurator config = new x64.General.Configurator(cale);
            string[] optiuni = config.citireConf("@ZoomStation");


            //Cauta prezenta optiunii cu axul implicit si inregistrarea lui
            string axImplicit = "";

            foreach (string optiune in optiuni)
            {
                if (optiune.StartsWith("Ax Implicit"))
                {
                    axImplicit = optiune.Substring(optiune.IndexOf('=') + 1);
                }
            }


            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                ///Selectarea axului
                ObjectId idAx   = new ObjectId();
                double   lungAx = 0;
                foreach (ObjectId alignmentId in alignmentIds)
                {
                    Alignment alin = (Alignment)trans.GetObject(alignmentId, OpenMode.ForRead);
                    if (alin.Name == axImplicit)
                    {
                        idAx = alignmentId;
                        break;
                    }
                    if (alin.Length > lungAx)
                    {
                        lungAx = alin.Length;
                        idAx   = alignmentId;
                    }
                }
                Alignment Ax = (Alignment)trans.GetObject(idAx, OpenMode.ForRead);


                ///Solicitarea pozitiei kilometrice de-a lungul axului
                PromptKeywordOptions prOpt = new PromptKeywordOptions("\nInput Station on alignment " + Ax.Name + ", or \n");
                prOpt.Keywords.Add("List");
                prOpt.Keywords.Add("Select");
                prOpt.Keywords.Add("Name");
                prOpt.Keywords.Add("nUmber");
                prOpt.Keywords.Add("Height");
                prOpt.Keywords.Default        = "Select";
                prOpt.AppendKeywordsToMessage = true;
                prOpt.AllowArbitraryInput     = true;
                prOpt.AllowNone = true;
                PromptResult prRes = ed.GetKeywords(prOpt);

                if (prRes.Status == PromptStatus.OK)
                {
                    string strRes = "";

                    switch (prRes.StringResult)
                    {
                    case "List":
                        for (int i = 1; i <= alignmentIds.Count; i++)
                        {
                            Alignment alin = (Alignment)trans.GetObject(alignmentIds[i - 1], OpenMode.ForRead);
                            ed.WriteMessage("\n" + i + " - " + alin.Name);
                        }
                        return;

                    case "Select":
                    case "":
                        //optiunile si filtrele selectiei noului ax
                        PromptSelectionOptions prSelOpt = new PromptSelectionOptions();
                        prSelOpt.MessageForAdding = "\nSelect Alignment: ";
                        prSelOpt.SingleOnly       = true;

                        TypedValue[]    tvs = { new TypedValue((int)DxfCode.Start, "AECC_ALIGNMENT") };
                        SelectionFilter sf  = new SelectionFilter(tvs);

                        //Realizarea selectiei
                        PromptSelectionResult prSelRes = ed.GetSelection(prSelOpt, sf);
                        if (prSelRes.Status == PromptStatus.OK && prSelRes.Value.Count == 1)
                        {
                            idAx   = prSelRes.Value[0].ObjectId;
                            Ax     = (Alignment)trans.GetObject(idAx, OpenMode.ForRead);
                            strRes = ed.GetString("\nSpecify station to zoom to: ").StringResult;
                        }
                        else
                        {
                            ed.WriteMessage("\nNo Alignment Selected");
                            return;
                        }
                        break;

                    case "Name":
                        PromptStringOptions prStrOpt = new PromptStringOptions("\nAlignment name: ");
                        prStrOpt.AllowSpaces = true;
                        string nume  = ed.GetString(prStrOpt).StringResult;
                        bool   gasit = false;
                        foreach (ObjectId alignmentId in alignmentIds)
                        {
                            Alignment alin = (Alignment)trans.GetObject(alignmentId, OpenMode.ForRead);
                            if (alin.Name == nume)
                            {
                                idAx  = alignmentId;
                                Ax    = (Alignment)trans.GetObject(idAx, OpenMode.ForRead);
                                gasit = true;
                            }
                        }
                        if (gasit == false)
                        {
                            ed.WriteMessage("\nAlignment not found! ");
                            return;
                        }
                        strRes = ed.GetString("\nSpecify station to zoom to: ").StringResult;
                        break;

                    case "nUmber":
                        int numar = ed.GetInteger("\nEnter a number from 1 to " + alignmentIds.Count + ": ").Value;
                        if (numar > 0 && numar <= alignmentIds.Count)
                        {
                            idAx = alignmentIds[numar - 1];
                            Ax   = (Alignment)trans.GetObject(idAx, OpenMode.ForRead);
                        }
                        else
                        {
                            ed.WriteMessage("\nInteger out of range! ");
                            return;
                        }
                        strRes = ed.GetString("\nSpecify station to zoom to: ").StringResult;
                        break;

                    case "Height":
                        string[] scaraNoua = new string[1];
                        scaraNoua[0] = "Scara=" + ed.GetString("\nSet the new zoom height as integer or use \"pan\" to use current! ").StringResult;
                        config.scriereConf("@ZoomStation", scaraNoua);
                        return;

                    default:
                        strRes = prRes.StringResult;
                        break;
                    }

                    try
                    {
                        //Citire pozitie kilometrica
                        double km;
                        if (strRes.Contains('+'))
                        {
                            foreach (string optiune in optiuni)
                            {
                                if (strRes.EndsWith("+") && optiune.StartsWith("Format") && optiune.Contains('+'))
                                {
                                    strRes = strRes + optiune.Substring(optiune.LastIndexOf('+') + 1);
                                }
                            }
                            km = double.Parse(strRes.Replace("+", ""));
                        }
                        else
                        {
                            km = double.Parse(strRes);
                        }

                        //Mutarea imaginii pe noile coordonate
                        if (km >= Ax.StartingStation && km <= Ax.EndingStation)
                        {
                            //Citirea optiunii de scara
                            double scara = 500;
                            bool   pan   = false;
                            foreach (string optiune in optiuni)
                            {
                                if (optiune.StartsWith("Scara") && optiune.Substring(optiune.LastIndexOf("=") + 1) != "pan")
                                {
                                    try
                                    {
                                        scara = double.Parse(optiune.Substring(optiune.IndexOf('=') + 1));
                                        if (scara <= 0)
                                        {
                                            throw new System.Exception();
                                        }
                                        else
                                        {
                                            ed.WriteMessage("\nZoom height set to " + scara.ToString());
                                        }
                                    }
                                    catch { ed.WriteMessage("\nDefault zoom height of 500 is used! "); }
                                }
                                else if (optiune.StartsWith("Scara") && optiune.Substring(optiune.LastIndexOf("=") + 1) == "pan")
                                {
                                    pan = true;
                                }
                            }

                            //Calcularea destinatiei si executia
                            double est  = 0;
                            double nord = 0;
                            Ax.PointLocation(km, 0, ref est, ref nord);

                            string cmd;
                            //Metoda Pan
                            if (pan)
                            {
                                ViewTableRecord view = ed.GetCurrentView();
                                ed.WriteMessage("Current zoom height of " + view.Height + " is used! ");
                                scara = view.Height;
                            }

                            cmd = "_.ZOOM _C " + est.ToString() + "," + nord.ToString() + " " + scara.ToString() + " ";
                            ed.Document.SendStringToExecute(cmd, true, false, false);
                        }
                        else
                        {
                            ed.WriteMessage("\nStation out of range! ");
                        }
                    }

                    catch
                    {
                        ed.WriteMessage("\nStation could not be read or incorrect station! ");
                    }
                }
            }
        }