Example #1
0
        public void run()
        {
            OpenFileDialog ddOpenFile = new OpenFileDialog();

            ddOpenFile.Title      = "Vermessungspunkte importieren";
            ddOpenFile.Filter     = "Punktwolke|*.csv|Punktwolke|*.dat";
            ddOpenFile.DefaultExt = m_Settings.Extention;
            Editor m_ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            DialogResult diagRes = DialogResult.None;

            if (!m_Settings.openExportFile)
            {
                diagRes = ddOpenFile.ShowDialog();
            }
            else
            {
                ddOpenFile.FileName = m_Settings.ExportFile;
                diagRes             = DialogResult.OK;
            }

            if (diagRes == DialogResult.OK)
            {
                bool fileOK = true;
                m_Filename = ddOpenFile.FileName;

                try
                {
                    StreamReader sr = new StreamReader(m_Filename, Encoding.Default);
                    m_Text = sr.ReadToEnd();
                    sr.Close();
                }
                catch { fileOK = false; }

                if (fileOK)
                {
                    m_Extention = m_Filename.Substring(m_Filename.LastIndexOf('.') + 1).ToLower();
                    string[] arZeile;

                    string PNum;
                    double Rechtswert = new double();
                    double Hochwert   = new double();
                    double Höhe       = new double();
                    double?Höhenwert  = new Double();

                    myRegistry.regIO objRegIO   = new myRegistry.regIO();
                    string           Basislayer = (string)objRegIO.readValue("blocks", "Basislayer");

                    //Basislayer ggf. anlegen
                    myAutoCAD.myLayer objLayer = myAutoCAD.myLayer.Instance;
                    objLayer.checkLayer(Basislayer, true);

                    int Zähler = 0;
                    int iZeile = 1;

                    switch (m_Extention)
                    {
                    case "dat":
                        bool bDatFehler = false;

                        m_arText = m_Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                        //Zeilen von MP in Array einfügen
                        foreach (string Zeile in m_arText)
                        {
                            arZeile = Zeile.Split(new char[] { (char)32 }, StringSplitOptions.RemoveEmptyEntries);
                            m_arPunkte.Add(arZeile);

                            if (arZeile.Length < 3)
                            {
                                bDatFehler = true;
                                break;
                            }
                            iZeile++;
                        }

                        if (!bDatFehler)
                        {
                            foreach (string[] Zeile in m_arPunkte)
                            {
                                bool bFehler = false;

                                PNum = Zeile[0];
                                if (m_Util.convertToDouble(Zeile[1], ref Rechtswert, null) != Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                                {
                                    bFehler = true;
                                }
                                if (m_Util.convertToDouble(Zeile[2], ref Hochwert, null) != Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                                {
                                    bFehler = true;
                                }

                                Autodesk.AutoCAD.Runtime.ErrorStatus eSHöhe = m_Util.convertToDouble(Zeile[3], ref Höhe, null);

                                if (!(eSHöhe == Autodesk.AutoCAD.Runtime.ErrorStatus.OK || eSHöhe == Autodesk.AutoCAD.Runtime.ErrorStatus.NullExtents))
                                {
                                    bFehler = true;
                                }

                                //Nachkommastellen Höhe
                                myAutoCAD.myUtilities objUtil = new myAutoCAD.myUtilities();
                                int    Precision = objUtil.Precision(Zeile[3]);
                                double CASHöhe   = Höhe;

                                Höhe = Math.Round(Höhe, Convert.ToInt32(m_objRegIO.readValue("blocks", "Kommastellen")));

                                //Att3 (Datum)
                                string Att3 = String.Empty;
                                try
                                {
                                    if (Zeile[4] != "" && Zeile[4] != "\r")
                                    {
                                        Att3 = Zeile[4];
                                    }
                                }
                                catch { }

                                //Att4 (Code)
                                string Att4 = String.Empty;
                                try
                                {
                                    if (Zeile[5] != "" && Zeile[5] != "\r")
                                    {
                                        Att4 = Zeile[5];
                                    }
                                }
                                catch { }

                                //Att5 (Hersteller)
                                string Att5 = String.Empty;
                                try
                                {
                                    if (Zeile[6] != "" && Zeile[6] != "\r")
                                    {
                                        Att5 = Zeile[6];
                                    }
                                }
                                catch { }

                                if (!bFehler)
                                {
                                    //Höhe
                                    if (eSHöhe == Autodesk.AutoCAD.Runtime.ErrorStatus.NullExtents)
                                    {
                                        Höhenwert = null;
                                    }
                                    else
                                    {
                                        Höhenwert = Höhe;
                                    }

                                    myAutoCAD.Messpunkt objMP = new Messpunkt(PNum, Rechtswert, Hochwert, Höhenwert, CASHöhe, Precision);

                                    if (Att3 != String.Empty)
                                    {
                                        objMP.Att3_Wert = Att3;
                                    }

                                    if (Att4 != String.Empty)
                                    {
                                        objMP.Att4_Wert = Att4;
                                    }

                                    if (Att5 != String.Empty)
                                    {
                                        objMP.Att5_Wert = Att5;
                                    }

                                    if (objMP.draw("MP", Basislayer) == Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                                    {
                                        Zähler += 1;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Fehler in dat File! (Zeile: " + iZeile.ToString());
                        }

                        break;

                    case "csv":
                        m_arText = m_Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                        //Zeilen von MP in Array einfügen
                        foreach (string Zeile in m_arText)
                        {
                            arZeile = Zeile.Split(new char[] { ';' }, StringSplitOptions.None);
                            m_arPunkte.Add(arZeile);
                        }

                        foreach (string[] Zeile in m_arPunkte)
                        {
                            bool bFehler = false;
                            Rechtswert = new Double();
                            Hochwert   = new Double();
                            Höhe       = new Double();
                            string Blockname = String.Empty;

                            PNum = Zeile[0];
                            if (m_Util.convertToDouble(Zeile[1], ref Rechtswert, null) != Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                            {
                                bFehler = true;
                            }
                            if (m_Util.convertToDouble(Zeile[2], ref Hochwert, null) != Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                            {
                                bFehler = true;
                            }

                            Autodesk.AutoCAD.Runtime.ErrorStatus eSHöhe = m_Util.convertToDouble(Zeile[3], ref Höhe, null);
                            if (!(eSHöhe == Autodesk.AutoCAD.Runtime.ErrorStatus.OK || eSHöhe == Autodesk.AutoCAD.Runtime.ErrorStatus.NullExtents))
                            {
                                bFehler = true;
                            }

                            //Nachkommastellen Höhe
                            myAutoCAD.myUtilities objUtil = new myAutoCAD.myUtilities();
                            int    Precision = objUtil.Precision(Zeile[3]);
                            double CASHöhe   = Höhe;

                            Höhe = Math.Round(Höhe, Convert.ToInt32(m_objRegIO.readValue("blocks", "Kommastellen")));

                            //Blockname
                            try
                            {
                                if (Zeile[4] != "" && Zeile[4] != "\r")
                                {
                                    Blockname = Zeile[4];
                                }
                            }
                            catch { }

                            //Att3 (Datum)
                            string Att3 = String.Empty;
                            try
                            {
                                if (Zeile[4] != "" && Zeile[4] != "\r")
                                {
                                    Att3 = Zeile[4];
                                }
                            }
                            catch { }

                            //Att4 (Code)
                            string Att4 = String.Empty;
                            try
                            {
                                if (Zeile[5] != "" && Zeile[5] != "\r")
                                {
                                    Att4 = Zeile[5];
                                }
                            }
                            catch { }

                            //Att5 (Hersteller)
                            string Att5 = String.Empty;
                            try
                            {
                                if (Zeile[6] != "" && Zeile[6] != "\r")
                                {
                                    Att5 = Zeile[6];
                                }
                            }
                            catch { }

                            //Att6
                            string Att6 = String.Empty;
                            try
                            {
                                if (Zeile[7] != "" && Zeile[7] != "\r")
                                {
                                    Att6 = Zeile[7];
                                }
                            }
                            catch { }

                            //Att7
                            string Att7 = String.Empty;
                            try
                            {
                                if (Zeile[8] != "" && Zeile[8] != "\r")
                                {
                                    Att7 = Zeile[8];
                                }
                            }
                            catch { }

                            //Att8
                            string Att8 = String.Empty;
                            try
                            {
                                if (Zeile[9] != "" && Zeile[9] != "\r")
                                {
                                    Att8 = Zeile[9];
                                }
                            }
                            catch { }

                            //Att9
                            string Att9 = String.Empty;
                            try
                            {
                                if (Zeile[10] != "" && Zeile[10] != "\r")
                                {
                                    Att9 = Zeile[10];
                                }
                            }
                            catch { }

                            //Att10
                            string Att10 = String.Empty;
                            try
                            {
                                if (Zeile[11] != "" && Zeile[11] != "\r")
                                {
                                    Att10 = Zeile[11];
                                }
                            }
                            catch { }

                            if (!bFehler)
                            {
                                //Höhe
                                if (eSHöhe == Autodesk.AutoCAD.Runtime.ErrorStatus.NullExtents)
                                {
                                    Höhenwert = null;
                                }
                                else
                                {
                                    Höhenwert = Höhe;
                                }

                                myAutoCAD.Messpunkt objMP = new Messpunkt(PNum, Rechtswert, Hochwert, Höhenwert, CASHöhe, Precision, Blockname);

                                if (Att3 != String.Empty)
                                {
                                    objMP.Att3_Wert = Att3;
                                }

                                if (Att4 != String.Empty)
                                {
                                    objMP.Att4_Wert = Att4;
                                }

                                if (Att5 != String.Empty)
                                {
                                    objMP.Att5_Wert = Att5;
                                }

                                if (Att6 != String.Empty)
                                {
                                    objMP.Att6_Wert = Att6;
                                }

                                if (Att7 != String.Empty)
                                {
                                    objMP.Att7_Wert = Att7;
                                }

                                if (Att8 != String.Empty)
                                {
                                    objMP.Att8_Wert = Att8;
                                }

                                if (Att9 != String.Empty)
                                {
                                    objMP.Att9_Wert = Att9;
                                }

                                if (Att10 != String.Empty)
                                {
                                    objMP.Att10_Wert = Att10;
                                }

                                if (objMP.draw("MP", Basislayer) == Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                                {
                                    Zähler += 1;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }

                        break;
                    }

                    MessageBox.Show(Zähler.ToString() + " Punkte importiert!");
                    m_ed.Regen();

                    //Object acadObject = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
                    //acadObject.GetType().InvokeMember("ZoomExtents", BindingFlags.InvokeMethod, null, acadObject, null);
                }
                else
                {
                    MessageBox.Show(m_Filename + " kann nicht geöffnet werden!");
                }
            }
        }
Example #2
0
        ///<summary>
        ///Bogenkleinpunkte
        ///</summary>
        public List <Point3d> calcBogenKleinpunkte3d(Point2d ptZentrum, double dRadius, Point3d ptAnfang, Point3d ptEnde, double dStich)
        {
            List <Point3d> lsPunkte   = new List <Point3d>();
            Point2d        ptAnfang2d = new Point2d(ptAnfang.X, ptAnfang.Y);
            Point2d        ptEnde2d   = new Point2d(ptEnde.X, ptEnde.Y);

            //erforderliche Sehnenlänge berechnen
            myAutoCAD.myUtilities objUtil = new myAutoCAD.myUtilities();
            double dSehne = objUtil.calcSehne(dRadius, dStich);

            //Berechnung Bogenlänge
            double dAbstandSE = ptAnfang2d.GetDistanceTo(ptEnde2d);
            double dPhi       = 2 * Math.Asin(dAbstandSE / (2 * dRadius));
            double dBL        = dRadius * dPhi;

            //Berechnung der Bogenlänge für Kleinpunkte
            double dPhi1 = 0;

            dPhi1 = 2 * Math.Asin(dSehne / (2 * dRadius));
            double dBL1 = dRadius * dPhi1;

            //Vorzeichen für Phi1 festlegen (je nach Drehsinn)
            double dAlphaStart = objUtil.RiWi(ptZentrum, ptAnfang2d);
            double dAlphaEnde  = objUtil.RiWi(ptZentrum, ptEnde2d);

            if (dAlphaStart > dAlphaEnde)
            {
                dPhi1 = -dPhi1;
            }

            //Richtungswinkel
            Vector2d v2dRiWi = ptZentrum.GetVectorTo(ptAnfang2d);
            double   dRiWi   = v2dRiWi.Angle;

            dRiWi = objUtil.RiWi(ptZentrum, ptAnfang2d);

            //solange Endpunkt nicht erreicht ist, Kleinpunkte berechnen
            double dStation = dBL1;
            double dWinkel  = dRiWi;

            //dH für Höheninterpolation
            double dH = (ptEnde.Z - ptAnfang.Z) / dBL * dBL1;
            double dz = 0;

            while (dStation < dBL)
            {
                dWinkel += dPhi1;

                //dx, dy und dz berechnen
                double dx = dRadius * Math.Sin(dWinkel);
                double dy = dRadius * Math.Cos(dWinkel);
                dz += dH;

                //Kleinpunkt berechnen
                Point3d ptPunkt = new Point3d(ptZentrum.X + dx, ptZentrum.Y + dy, ptAnfang.Z + dz);

                //Punkt zu Liste hinzufügen
                lsPunkte.Add(ptPunkt);

                dStation += dBL1;
            }

            return(lsPunkte);
        }
Example #3
0
        private void bt_OpenPTFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ddOpenFile = new OpenFileDialog();

            ddOpenFile.Title      = "Vermessungspunkte importieren";
            ddOpenFile.Filter     = "Punktwolke|*.csv";
            ddOpenFile.DefaultExt = "csv";

            string[]        arText;                           //Array mit Zeilen
            List <string[]> arPunkte = new List <string[]>();

            arPunkte.Clear();
            m_lsMP.Clear();
            tB_nPTÜbereinstimmung.Text = "";
            m_lsMPÜbereinstimmung.Clear();

            Editor m_ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            if (ddOpenFile.ShowDialog() == DialogResult.OK)
            {
                m_Filename = ddOpenFile.FileName;
                StreamReader sr = new StreamReader(m_Filename, Encoding.Default);
                m_Text = sr.ReadToEnd();
                sr.Close();

                m_Extention = m_Filename.Substring(m_Filename.LastIndexOf('.') + 1).ToLower();
                string[] arZeile;
                int      iZeile = 1;

                switch (m_Extention)
                {
                case "csv":
                    arText = m_Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    //Zeilen von MP in Array einfügen
                    foreach (string Zeile in arText)
                    {
                        arZeile = Zeile.Split(new char[] { ';' }, StringSplitOptions.None);
                        arPunkte.Add(arZeile);
                    }

                    foreach (string[] Zeile in arPunkte)
                    {
                        string PNum;
                        double Rechtswert = new double();
                        double Hochwert   = new double();
                        double Höhe       = new double();
                        double?Höhenwert  = null;
                        bool   bFehler    = false;
                        Autodesk.AutoCAD.Runtime.ErrorStatus es;

                        PNum = Zeile[0];
                        if (m_Util.convertToDouble(Zeile[1], ref Rechtswert, iZeile) != Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                        {
                            bFehler = true;
                        }
                        if (m_Util.convertToDouble(Zeile[2], ref Hochwert, iZeile) != Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                        {
                            bFehler = true;
                        }
                        es = m_Util.convertToDouble(Zeile[3], ref Höhe, iZeile);
                        if (es == Autodesk.AutoCAD.Runtime.ErrorStatus.OK)
                        {
                            Höhenwert = Höhe;
                        }

                        if (es != Autodesk.AutoCAD.Runtime.ErrorStatus.OK || es != Autodesk.AutoCAD.Runtime.ErrorStatus.NullPtr)
                        {
                            bFehler = false;
                        }

                        //Nachkommastellen Höhe
                        myAutoCAD.myUtilities objUtil = new myAutoCAD.myUtilities();
                        int Precision = objUtil.Precision(Zeile[3]);

                        if (!bFehler)
                        {
                            myAutoCAD.Messpunkt objMP = new Messpunkt(PNum, Rechtswert, Hochwert, Höhenwert, Höhenwert, Precision);
                            objMP.Att4_Wert = myUtilities.Global.Owner;

                            m_lsMP.Add(objMP);
                        }
                        iZeile++;
                    }

                    //Bestimmen der Punkte mit Übereinstimmung Punktdatenfile mit Zeichnung
                    foreach (Messpunkt MP in m_lsMP)
                    {
                        Messpunkt objMP = new Messpunkt();
                        if (m_Blöcke.findPos(ref objMP, new Autodesk.AutoCAD.Geometry.Point2d(MP.Position.X, MP.Position.Y), 0.01) == ErrorStatus.OK)
                        {
                            m_lsMPÜbereinstimmung.Add(objMP);
                        }
                    }

                    //Ausgabe Dialogbox
                    tB_PTFilename.Text         = m_Filename;
                    tb_nPunkteFile.Text        = m_lsMP.Count.ToString();
                    tB_nPTÜbereinstimmung.Text = m_lsMPÜbereinstimmung.Count.ToString();

                    if (m_lsMPÜbereinstimmung.Count > 0)
                    {
                        bt_markieren.Enabled = true;
                        bt_löschen.Enabled   = true;
                    }

                    break;
                }
            }
        }