Use xml load / save toolset toolgroup (visionpro toolgroup breakthrough thinking) (V)

Because often work with xml, and he has better scalability on the Internet, so the tool group toolgroup saved and loaded in the dll will naturally think of him. First, take into account that the tool set toolgroup are some of the rectangular box and wiring, do not think too much, so the problem becomes simple. Demonstrate save:

 XmlDocument xmlDoc = new XmlDocument (); // instantiate the XML file, see this, often reminds me of the times mfc file serialization Archive
            XmlElement root = xmlDoc.createElement ( "Roi"); // tool set we played a man named roi, you can also freely
            xmlDoc.AppendChild (root);
            String str = string.Empty;
            ////////////////////////// first a tool, Grab
            the XmlElement XE1 = xmlDoc.createElement ( "grabroi");
            root.AppendChild (XE1);

            XmlElement xe = xmlDoc.CreateElement("ptx");          
            str = "0";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("pty");         
            str = "0";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("w");         
            str = "100";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("h");         
            str = "15";
            xe.InnerText = str;
            xe1.AppendChild(xe);

   //////////////////////////////// second tool, Calibration
             XE1 = xmlDoc.createElement ( "caliroi");
            the root .AppendChild (xe1);

             xe = xmlDoc.CreateElement("ptx");
            str = "0";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("pty");
            str = "40";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("w");
            str = "100";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("h");
            str = "15";
            xe.InnerText = str;
            xe1.AppendChild(xe);

  ////////////////////////////// PointF [] globarraypointfca = null; // grab the Calibration
            XE1 = xmlDoc.createElement ( "grab2cali "); // the Grab connection to calibration records, three segments
            root.AppendChild (xe1);

            for (int i = 0; i < globarraypointfca.GetLength(0); i++)
            {
                xe = xmlDoc.CreateElement("x"+i.ToString());
                str = globarraypointfca[i].X.ToString();
                xe.InnerText = str;
                xe1.AppendChild(xe);

                xe = xmlDoc.CreateElement("y"+i.ToString());
                str = globarraypointfca[i].Y.ToString();
                xe.InnerText = str;
                xe1.AppendChild(xe);
            }
            //////////////////////////////0, 120, 100, 15//第三个工具,blob
            xe1 = xmlDoc.CreateElement("blobroi");
            root.AppendChild(xe1);

            xe = xmlDoc.CreateElement("ptx");
            str = "0";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("pty");
            str = "120";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("w");
            str = "100";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("h");
            str = "15";
            xe.InnerText = str;
            xe1.AppendChild(xe);
            //////////////////////////////  PointF[] globarraypointfMa;//calibration到blob
            xe1 = xmlDoc.CreateElement("cali2blob");//calibration到blob的连线记录,三条线段
            root.AppendChild(xe1);
            for (int i = 0; i < globarraypointfMa.GetLength(0); i++)
            {
                xe = xmlDoc.CreateElement("x" + i.ToString());
                str = globarraypointfMa[i].X.ToString();
                xe.InnerText = str;
                xe1.AppendChild(xe);

                xe = xmlDoc.CreateElement("y" + i.ToString());
                str = globarraypointfMa[i].Y.ToString();
                xe.InnerText = str;
                xe1.AppendChild(xe);
            }
            //////////////
            //////////////////////////////0, 160, 100, 15//第四个工具,fixture
            xe1 = xmlDoc.CreateElement("fixtureroi");
            root.AppendChild(xe1);

            xe = xmlDoc.CreateElement("ptx");
            str = "0";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("pty");
            str = "160";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("w");
            str = "100";
            xe.InnerText = str;
            xe1.AppendChild(xe);

            xe = xmlDoc.CreateElement("h");
            str = "15";
            xe.InnerText = str;
            xe1.AppendChild(xe);
            //////////////////////////////  PointF[] globarraypointfMF;//blob到fix
            xe1 = xmlDoc.CreateElement("blob2fixture");//blob到fixture的连线记录,三条线段
            root.AppendChild(xe1);
            for (int i = 0; i < globarraypointfMF.GetLength(0); i++)
            {
                xe = xmlDoc.CreateElement("x" + i.ToString());
                str = globarraypointfMF[i].X.ToString();
                xe.InnerText = str;
                xe1.AppendChild(xe);

                xe = xmlDoc.CreateElement("y" + i.ToString());
                str = globarraypointfMF[i].Y.ToString();
                xe.InnerText = str;
                xe1.AppendChild(xe);
            }
            //////////////
            xmlDoc.Save(@"c:\toolsgroup.xml");

We demonstrate save a fixed four tool box frame lines , it is very simple, this is the foundation, and you need further consideration is that you need tools exist to automatically identify the interface (if a little scary? Difficult? In fact, since you come this far, you will be able to manage him), he may be random, for example, have to find the line tool, find circle tools. (Here often think of Hou Jie, easy to understand analysis mfc automatically create classes and clues technology, weird Microsoft mfc Monster , I feel that this is what I learned first AI technology, and the first contact with wps text search , and later Baidu, this is the essence of AI's originator, but has no intention Bale.)

Secondly, we must consider saving save tools form the parameters and images. (Can be completed jobs)

Third, load the load on the tool set toolgroup (he was the save of the reverse, not demonstrated), is to load the line wire frame, the key is in the Paint drawn to him, demonstrate it:

  Graphics g = e.Graphics;
            Pen p = new Pen(Color.Black);
            if (m_bAddgrab)
                toolitemgrab.m_RoiBase1.Draw(g, p, "ImageSource", false);
            if (m_bAdd_ca)
                toolitemCA.m_RoiBase1.Draw(g, p, "Calibrate", false);
            if (m_bAdd1ine)
                toolitemline.m_RoiBase1.Draw(g, p, "GaugeLine1", false);
            if (m_bAdd_Ma)
            {
                toolitemMa.m_RoiBase1.Draw(g, p, "BlobMatch", false);
            }
            if (m_bAdd_Cir)
            {
                toolitemCir.m_RoiBase1.Draw(g, p, "GaugeCircle1", false);
            }
            IF (m_bAdd_fix)
            {
                toolitemFixture.m_RoiBase1.Draw (G, P, "Fixture", to false);
            }
            IF (m_bAdd_Con)
            {
                toolitemContour.m_RoiBase1.Draw (G, P, "ContourMatch", to false);
            } // more exemplary tool set toolgroup draw
            IF (globarraypointfca = null!)
            {
                the Random new new RAN = the Random ();
                int = Rn of ran.Next (100, 200 is);
                g.DrawLines (new new Pen (Color.FromArgb (0, Rn of, 0 )), globarraypointfca);              
            } // only exemplary of the calibration objects to grab

           ....................
          

Continued (slowly! ...........) a little small change every day ☺

My mailbox [email protected]; [email protected]

Published 66 original articles · won praise 12 · views 10000 +

Guess you like

Origin blog.csdn.net/ganggangwawa/article/details/96962210