Esempio n. 1
0
        public void ImportSdrDataCivil()
        {
            System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo("ru-RU");
            SdrReader rd = new SdrReader();

            wnd.OpenFileDialog opfWndDia = new wnd.OpenFileDialog();
            opfWndDia.AddExtension = true;
            opfWndDia.Filter       = "Text files (*.txt)|*.txt|Sdr files (*.sdr)|*.sdr|All files (*.*)|*.*";
            opfWndDia.FilterIndex  = 2;

            if (opfWndDia.ShowDialog() == wnd.DialogResult.OK)
            {
                string path   = opfWndDia.FileName;
                var    points = rd._SdrCoordParser(path);
                if (points == null)
                {
                    return;
                }
                foreach (var p in points)
                {
                    IgorKL.ACAD3.Model.CogoPoints.CogoPointFactory.CreateCogoPoints(new Point3d(p.y, p.x, p.h), p.name, p.code2);
                }
            }
        }
Esempio n. 2
0
        public void ImportSdrData()
        {
            System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo("ru-RU");
            SdrReader rd = new SdrReader();

            wnd.OpenFileDialog opfWndDia = new wnd.OpenFileDialog();
            opfWndDia.AddExtension = true;
            opfWndDia.Filter       = "Text files (*.txt)|*.txt|Sdr files (*.sdr)|*.sdr|All files (*.*)|*.*";
            opfWndDia.FilterIndex  = 2;
            if (opfWndDia.ShowDialog() == wnd.DialogResult.OK)
            {
                PromptIntegerOptions scaleOpt = new PromptIntegerOptions("\nУкажите маштаб, 1:");
                scaleOpt.UseDefaultValue = true;
                scaleOpt.DefaultValue    = 1000;
                scaleOpt.AllowNegative   = false;
                scaleOpt.AllowZero       = false;
                scaleOpt.AllowNone       = false;
                PromptIntegerResult scaleRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(scaleOpt);
                if (scaleRes.Status != PromptStatus.OK)
                {
                    return;
                }
                double scale = scaleRes.Value / 1000d;

                PromptIntegerOptions digCountOpt = new PromptIntegerOptions("\nЗнаков после запятой");
                digCountOpt.UseDefaultValue = true;
                digCountOpt.DefaultValue    = 2;
                digCountOpt.AllowNegative   = false;
                PromptIntegerResult digCountRes = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetInteger(digCountOpt);
                if (digCountRes.Status != PromptStatus.OK)
                {
                    return;
                }

                string path   = opfWndDia.FileName;
                var    points = rd._SdrCoordParser(path);
                if (points == null)
                {
                    return;
                }
                string lname     = "__SDRP_" + System.IO.Path.GetFileNameWithoutExtension(opfWndDia.SafeFileName);
                string lnameElev = lname + "__Elevations";
                string lnameName = lname + "__Names";
                Layers.LayerTools.CreateHiddenLayer(lname);
                Layers.LayerTools.CreateHiddenLayer(lnameElev);
                Layers.LayerTools.CreateHiddenLayer(lnameName);

                using (Transaction trans = Tools.StartTransaction())
                {
                    BlockTable acBlkTbl;
                    acBlkTbl = trans.GetObject(Application.DocumentManager.MdiActiveDocument.Database.BlockTableId,
                                               OpenMode.ForRead) as BlockTable;
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                  OpenMode.ForWrite) as BlockTableRecord;

                    foreach (var p in points)
                    {
                        DBPoint acPoint = new DBPoint(new Point3d(p.y, p.x, p.h));
                        acPoint.Layer = lname;
                        acPoint.SetDatabaseDefaults();
                        Group gr = new Group();

                        string format = digCountRes.Value == 0 ? "#0" : ((Func <string>)(() => { format = "#0."; for (int i = 0; i < digCountRes.Value; i++)
                                                                                                 {
                                                                                                     format += "0";
                                                                                                 }
                                                                                                 return(format); })).Invoke();

                        var text = _CreateText(new Point3d(p.y + 2.0 * scale, p.x, 0), Math.Round(p.h, digCountRes.Value, MidpointRounding.AwayFromZero).ToString(format, culture), lnameElev, scale);

                        var nameText = _CreateText(text, p.name, lnameName, scale);

                        acBlkTblRec.AppendEntity(acPoint);
                        trans.AddNewlyCreatedDBObject(acPoint, true);

                        ObjectId elevId = acBlkTblRec.AppendEntity(text);
                        trans.AddNewlyCreatedDBObject(text, true);


                        ObjectId nameId = acBlkTblRec.AppendEntity(nameText);
                        trans.AddNewlyCreatedDBObject(nameText, true);

                        gr.Append(elevId);
                        gr.Append(nameId);
                        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.AddDBObject(gr);

                        trans.AddNewlyCreatedDBObject(gr, true);
                    }
                    Application.DocumentManager.MdiActiveDocument.Database.Pdmode = 32;
                    Application.DocumentManager.MdiActiveDocument.Database.Pdsize = 2 * scale;
                    trans.Commit();
                }
            }
        }