예제 #1
0
        public void ReadXml_Path(string file_name)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(file_name);

            string dialog_text = "XMLReadPath\n\n";


            // Get Paths

            XmlNodeList pathlist   = xmlDoc.DocumentElement.SelectNodes("/WPG/Path");
            int         path_count = pathlist.Count;

            dialog_text = dialog_text + "Path Count : " + path_count + "\n";

            ClearPath();

            foreach (XmlNode path_node in pathlist)
            {
                Models.Path path = new Models.Path();

                path.name        = path_node.SelectSingleNode("Name").InnerText;
                path.type        = path_node.SelectSingleNode("Type").InnerText;
                path.internal_id = Convert.ToInt16(path_node.SelectSingleNode("InternalId").InnerText);

                if (path.type == "Circular")
                {
                    CircularGUI gui      = new CircularGUI();
                    XmlNodeList GUI_node = path_node.SelectNodes("./GUI");
                    foreach (XmlNode node in GUI_node)
                    {
                        gui.CW          = Convert.ToBoolean(node.SelectSingleNode("CW").InnerText);
                        gui.name        = node.SelectSingleNode("Name").InnerText;
                        gui.lat         = Convert.ToDouble(node.SelectSingleNode("Lat").InnerText);
                        gui.lon         = Convert.ToDouble(node.SelectSingleNode("Lon").InnerText);
                        gui.altitude    = Convert.ToDouble(node.SelectSingleNode("Altitude").InnerText);
                        gui.radius      = Convert.ToDouble(node.SelectSingleNode("Radius").InnerText);
                        gui.numpoints   = Convert.ToInt16(node.SelectSingleNode("NumPoints").InnerText);
                        gui.fullcirc    = Convert.ToBoolean(node.SelectSingleNode("FullCircle").InnerText);
                        gui.start_angle = Convert.ToDouble(node.SelectSingleNode("StartAngle").InnerText);
                        gui.circ_span   = Convert.ToDouble(node.SelectSingleNode("CircleSpan").InnerText);
                        gui.startend    = Convert.ToBoolean(node.SelectSingleNode("StartEnd").InnerText);
                        gui.poimode     = Convert.ToBoolean(node.SelectSingleNode("POIMode").InnerText);
                        gui.poiname     = node.SelectSingleNode("POIName").InnerText;
                    }
                    path.circgui = gui;
                }

                if (path.type == "Helical")
                {
                    HelicalGUI  gui      = new HelicalGUI();
                    XmlNodeList GUI_node = path_node.SelectNodes("./GUI");
                    foreach (XmlNode node in GUI_node)
                    {
                        gui.CW          = Convert.ToBoolean(node.SelectSingleNode("CW").InnerText);
                        gui.name        = node.SelectSingleNode("Name").InnerText;
                        gui.lat         = Convert.ToDouble(node.SelectSingleNode("Lat").InnerText);
                        gui.lon         = Convert.ToDouble(node.SelectSingleNode("Lon").InnerText);
                        gui.start_alt   = Convert.ToDouble(node.SelectSingleNode("StartAltitude").InnerText);
                        gui.end_alt     = Convert.ToDouble(node.SelectSingleNode("EndAltitude").InnerText);
                        gui.start_rad   = Convert.ToDouble(node.SelectSingleNode("StartRadius").InnerText);
                        gui.end_rad     = Convert.ToDouble(node.SelectSingleNode("EndRadius").InnerText);
                        gui.start_angle = Convert.ToDouble(node.SelectSingleNode("StartAngle").InnerText);
                        gui.helix_span  = Convert.ToDouble(node.SelectSingleNode("HelixSpan").InnerText);
                        gui.num_points  = Convert.ToInt16(node.SelectSingleNode("NumPoints").InnerText);
                        gui.startend    = Convert.ToBoolean(node.SelectSingleNode("StartEnd").InnerText);
                        gui.poimode     = Convert.ToBoolean(node.SelectSingleNode("POIMode").InnerText);
                        gui.poiname     = node.SelectSingleNode("POIName").InnerText;
                    }
                    path.helixgui = gui;
                }

                if (path.type == "Rectangular")
                {
                    RectanglarGUI gui      = new RectanglarGUI();
                    XmlNodeList   GUI_node = path_node.SelectNodes("./GUI");
                    foreach (XmlNode node in GUI_node)
                    {
                        gui.name     = node.SelectSingleNode("Name").InnerText;
                        gui.video    = Convert.ToBoolean(node.SelectSingleNode("Video").InnerText);
                        gui.startend = Convert.ToBoolean(node.SelectSingleNode("StartEnd").InnerText);
                        gui.altitude = Convert.ToDouble(node.SelectSingleNode("Altitude").InnerText);
                        gui.heading  = Convert.ToDouble(node.SelectSingleNode("Heading").InnerText);
                        gui.length   = Convert.ToDouble(node.SelectSingleNode("Length").InnerText);
                        gui.width    = Convert.ToDouble(node.SelectSingleNode("Width").InnerText);
                        gui.single   = Convert.ToBoolean(node.SelectSingleNode("SinglePath").InnerText);
                        gui.poimode  = Convert.ToBoolean(node.SelectSingleNode("POIMode").InnerText);
                        gui.poiname  = node.SelectSingleNode("POIName").InnerText;
                    }
                    path.rectanglegui = gui;
                }

                if (path.type == "Polygon")
                {
                    PolygonGridGUI gui      = new PolygonGridGUI();
                    XmlNodeList    GUI_node = path_node.SelectNodes("./GUI");
                    foreach (XmlNode node in GUI_node)
                    {
                        gui.name             = node.SelectSingleNode("Name").InnerText;
                        gui.video            = Convert.ToBoolean(node.SelectSingleNode("Video").InnerText);
                        gui.startend         = Convert.ToBoolean(node.SelectSingleNode("StartEnd").InnerText);
                        gui.altitude         = Convert.ToDouble(node.SelectSingleNode("Altitude").InnerText);
                        gui.heading          = Convert.ToDouble(node.SelectSingleNode("Heading").InnerText);
                        gui.polyname         = node.SelectSingleNode("PolyName").InnerText;
                        gui.poly_internal_id = Convert.ToInt16(node.SelectSingleNode("Poly_IntID").InnerText);
                    }
                    path.polygridgui = gui;
                }

                path.selected = false;
                path.visible  = false;
                LinkedList <WayPoints> way_list = new LinkedList <WayPoints>();

                XmlNodeList way_nodes = path_node.SelectNodes("./Waypoint");
                int         way_count = way_nodes.Count;

                dialog_text = dialog_text + "Path : " + path.name + "Type : " + path.type + "\n";
                dialog_text = dialog_text + "Waypoint Count : " + Convert.ToString(way_count) + "\n";
                //MessageBox.Show(dialog_text, "xxx");
                way_count = 0;
                foreach (XmlNode wp_node in way_nodes)
                {
                    WayPoints waypoint = new WayPoints();
                    waypoint.lat         = Convert.ToDouble(wp_node.SelectSingleNode("Lat").InnerText);
                    waypoint.lon         = Convert.ToDouble(wp_node.SelectSingleNode("Lon").InnerText);
                    waypoint.alt         = Convert.ToDouble(wp_node.SelectSingleNode("Alt").InnerText);
                    waypoint.head        = Convert.ToDouble(wp_node.SelectSingleNode("Heading").InnerText);
                    waypoint.curvesize   = Convert.ToDouble(wp_node.SelectSingleNode("CurveSize").InnerText);
                    waypoint.rotationdir = Convert.ToDouble(wp_node.SelectSingleNode("RotationDir").InnerText);
                    waypoint.gimblemode  = Convert.ToInt16(wp_node.SelectSingleNode("GimbleMode").InnerText);
                    waypoint.gimblepitch = Convert.ToDouble(wp_node.SelectSingleNode("GimblePitch").InnerText);

                    XmlNodeList action_nodes = wp_node.SelectNodes("./Action");
                    int         action_count = action_nodes.Count;
                    dialog_text = dialog_text + "Waypoint : " + Convert.ToString(way_count) + "\n";
                    dialog_text = dialog_text + "Action Count : " + Convert.ToString(action_count) + "\n";

                    int[,] actions_arr = new int[100, 2];
                    int i = 0;
                    int act_type, act_param;
                    foreach (XmlNode act_node in action_nodes)
                    {
                        act_type          = Convert.ToInt16(act_node.SelectSingleNode("Type").InnerText);
                        act_param         = Convert.ToInt16(act_node.SelectSingleNode("Param").InnerText);
                        dialog_text       = dialog_text + "Action Count : " + Convert.ToString(i);
                        dialog_text       = dialog_text + ", Action Type : " + Convert.ToString(act_type);
                        dialog_text       = dialog_text + ", Action Param : " + Convert.ToString(act_param) + "\n";
                        actions_arr[i, 0] = act_type;
                        actions_arr[i, 1] = act_param;
                        i++;
                    }
                    waypoint.actions = actions_arr;

                    way_list.AddLast(waypoint);
                    way_count++;
                }
                //MessageBox.Show(dialog_text, "xxx");
                path.waypoints = way_list;
                AddPathId(path.internal_id, path);
                path_count++;
            }
        }
예제 #2
0
        public void WriteXml(string file_name)
        {
            string name;
            double lat, lon, alt, elev, cam_alt, head, rotdir, gimble_pitch, curvesize;
            int    gimble_mode, int_id;

            int[,] actions;
            Models.Action action;

            // Generate XML

            if (File.Exists(file_name))
            {
                File.Delete(file_name);
            }

            using (XmlWriter xml_writer = XmlWriter.Create(file_name))
            {
                xml_writer.WriteStartDocument();
                xml_writer.WriteStartElement("WPG");


                // Write Configuration
                xml_writer.WriteStartElement("Config"); // Start of Config
                                                        //MessageBox.Show(Globals.default_location);
                xml_writer.WriteElementString("Default_Location", Form1.Globals.default_location);
                xml_writer.WriteElementString("Default_Altitude", Convert.ToString(_options.def_altitude));
                xml_writer.WriteElementString("Out_CVS_Path", _options.def_csv_path);
                xml_writer.WriteElementString("Out_KML_Path", _options.def_kml_path);
                xml_writer.WriteElementString("Cam_Hor_Angle", Form1.Globals.default_cam_hor_ang);
                xml_writer.WriteElementString("Cam_Ver_Angle", Form1.Globals.default_cam_ver_ang);
                xml_writer.WriteElementString("Cam_Hor_OverLap", Form1.Globals.default_cam_hor_over);
                xml_writer.WriteElementString("Cam_Ver_OverLap", Form1.Globals.default_cam_ver_over);
                xml_writer.WriteElementString("Earth_Radius", Convert.ToString(_options.earth_radius));
                xml_writer.WriteEndElement(); // End of Config

                // Write POI

                for (int i = 0; i < poi_list.Count; i++)
                {
                    xml_writer.WriteStartElement("POI"); // Start of POI
                    name    = poi_list.ElementAt(i).name;
                    int_id  = poi_list.ElementAt(i).internal_id;
                    lat     = poi_list.ElementAt(i).lat;
                    lon     = poi_list.ElementAt(i).lon;
                    elev    = poi_list.ElementAt(i).elev;
                    alt     = poi_list.ElementAt(i).alt;
                    cam_alt = poi_list.ElementAt(i).cam_alt;
                    xml_writer.WriteElementString("Name", name);
                    xml_writer.WriteElementString("InternalId", Convert.ToString(int_id));
                    xml_writer.WriteElementString("Lat", Convert.ToString(lat));
                    xml_writer.WriteElementString("Lon", Convert.ToString(lon));
                    xml_writer.WriteElementString("Elev", Convert.ToString(elev));
                    xml_writer.WriteElementString("Alt", Convert.ToString(alt));
                    xml_writer.WriteElementString("Cam_Alt", Convert.ToString(cam_alt));
                    xml_writer.WriteEndElement(); // End of POI
                }

                // Write Actions

                xml_writer.WriteStartElement("WP_Action_List"); // Start of Action_List

                for (int i = 0; i < action_list.Count; i++)
                {
                    action  = action_list.ElementAt(i);
                    name    = action.name;
                    actions = action.actions;
                    xml_writer.WriteStartElement("WP_Action");   // Start of Action
                    xml_writer.WriteElementString("Name", name);
                    xml_writer.WriteStartElement("Action_List"); // Start of Element Action List
                    for (int k = 0; k < 15; k++)
                    {
                        xml_writer.WriteStartElement("Action"); // Start of Action
                        xml_writer.WriteElementString("Type", Convert.ToString(actions[k, 0]));
                        xml_writer.WriteElementString("Param", Convert.ToString(actions[k, 1]));
                        xml_writer.WriteEndElement(); // End of Action
                    }
                    xml_writer.WriteEndElement();     // End of Element Action List
                    xml_writer.WriteEndElement();     // End of Action
                }
                xml_writer.WriteEndElement();         // End of Action_List

                // Write Polygons

                int          shape_count = ShapeCount();
                Models.Shape shape;
                PolyPoint    point;

                if (shape_count > 0)
                {
                    xml_writer.WriteStartElement("Polygon_List"); // Start of Polygon_List
                    for (int i = 0; i < shape_list.Count(); i++)
                    {
                        shape  = shape_list.ElementAt(i);
                        int_id = shape.internal_id;
                        xml_writer.WriteStartElement("Polygon"); // Start of Polygon
                        xml_writer.WriteElementString("Name", shape.name);
                        xml_writer.WriteElementString("InternalId", Convert.ToString(int_id));
                        LinkedList <PolyPoint> points = shape.points;
                        xml_writer.WriteStartElement("Vertex_List"); // Start of Vertex List
                        for (int j = 0; j < points.Count; j++)
                        {
                            point = points.ElementAt(j);
                            xml_writer.WriteStartElement("Vertex"); // Start of Vertex
                            xml_writer.WriteElementString("Lat", Convert.ToString(point.lat));
                            xml_writer.WriteElementString("Lon", Convert.ToString(point.lon));
                            xml_writer.WriteElementString("Alt", Convert.ToString(point.alt));
                            xml_writer.WriteEndElement(); // End of Vertex
                        }
                        xml_writer.WriteEndElement();     // End of Vertex_List
                        xml_writer.WriteEndElement();     // End of Polygon
                    }
                    xml_writer.WriteEndElement();         // End of Polygon_List
                }

                // Write Paths

                for (int i = 0; i < path_list.Count; i++)
                {
                    xml_writer.WriteStartElement("Path"); // Start of Path
                    Path path = path_list.ElementAt(i);
                    int_id = path.internal_id;
                    name   = path.name;
                    string path_type = path.type;
                    xml_writer.WriteElementString("Name", name);
                    xml_writer.WriteElementString("Type", path_type);
                    xml_writer.WriteElementString("InternalId", Convert.ToString(int_id));

                    // Path GUI Configuration

                    if (path_type == "Circular")
                    {
                        CircularGUI gui = path.circgui;
                        xml_writer.WriteStartElement("GUI"); // Start of Gui
                        xml_writer.WriteElementString("CW", Convert.ToString(gui.CW));
                        xml_writer.WriteElementString("Name", gui.name);
                        xml_writer.WriteElementString("Lat", Convert.ToString(gui.lat));
                        xml_writer.WriteElementString("Lon", Convert.ToString(gui.lon));
                        xml_writer.WriteElementString("Altitude", Convert.ToString(gui.altitude));
                        xml_writer.WriteElementString("Radius", Convert.ToString(gui.radius));
                        xml_writer.WriteElementString("NumPoints", Convert.ToString(gui.numpoints));
                        xml_writer.WriteElementString("FullCircle", Convert.ToString(gui.fullcirc));
                        xml_writer.WriteElementString("StartAngle", Convert.ToString(gui.start_angle));
                        xml_writer.WriteElementString("CircleSpan", Convert.ToString(gui.circ_span));
                        xml_writer.WriteElementString("StartEnd", Convert.ToString(gui.startend));
                        xml_writer.WriteElementString("POIMode", Convert.ToString(gui.poimode));
                        xml_writer.WriteElementString("POIName", gui.poiname);
                        xml_writer.WriteEndElement(); // End of GUI
                    }

                    if (path_type == "Helical")
                    {
                        HelicalGUI gui = path.helixgui;
                        xml_writer.WriteStartElement("GUI"); // Start of Gui
                        xml_writer.WriteElementString("CW", Convert.ToString(gui.CW));
                        xml_writer.WriteElementString("Name", gui.name);
                        xml_writer.WriteElementString("Lat", Convert.ToString(gui.lat));
                        xml_writer.WriteElementString("Lon", Convert.ToString(gui.lon));
                        xml_writer.WriteElementString("StartAltitude", Convert.ToString(gui.start_alt));
                        xml_writer.WriteElementString("EndAltitude", Convert.ToString(gui.end_alt));
                        xml_writer.WriteElementString("StartRadius", Convert.ToString(gui.start_rad));
                        xml_writer.WriteElementString("EndRadius", Convert.ToString(gui.end_rad));
                        xml_writer.WriteElementString("StartAngle", Convert.ToString(gui.start_angle));
                        xml_writer.WriteElementString("HelixSpan", Convert.ToString(gui.helix_span));
                        xml_writer.WriteElementString("NumPoints", Convert.ToString(gui.num_points));
                        xml_writer.WriteElementString("StartEnd", Convert.ToString(gui.startend));
                        xml_writer.WriteElementString("POIMode", Convert.ToString(gui.poimode));
                        xml_writer.WriteElementString("POIName", gui.poiname);
                        xml_writer.WriteEndElement(); // End of GUI
                    }

                    if (path_type == "Rectangular")
                    {
                        RectanglarGUI gui = path.rectanglegui;
                        xml_writer.WriteStartElement("GUI"); // Start of Gui
                        xml_writer.WriteElementString("Name", gui.name);
                        xml_writer.WriteElementString("Video", Convert.ToString(gui.video));
                        xml_writer.WriteElementString("StartEnd", Convert.ToString(gui.startend));
                        xml_writer.WriteElementString("Altitude", Convert.ToString(gui.altitude));
                        xml_writer.WriteElementString("Heading", Convert.ToString(gui.heading));
                        xml_writer.WriteElementString("Length", Convert.ToString(gui.length));
                        xml_writer.WriteElementString("Width", Convert.ToString(gui.width));
                        xml_writer.WriteElementString("SinglePath", Convert.ToString(gui.single));
                        xml_writer.WriteElementString("POIMode", Convert.ToString(gui.poimode));
                        xml_writer.WriteElementString("POIName", gui.poiname);
                        xml_writer.WriteEndElement(); // End of GUI
                    }

                    if (path_type == "Polygon")
                    {
                        PolygonGridGUI gui = path.polygridgui;
                        xml_writer.WriteStartElement("GUI"); // Start of Gui
                        xml_writer.WriteElementString("Name", gui.name);
                        xml_writer.WriteElementString("Video", Convert.ToString(gui.video));
                        xml_writer.WriteElementString("StartEnd", Convert.ToString(gui.startend));
                        xml_writer.WriteElementString("Altitude", Convert.ToString(gui.altitude));
                        xml_writer.WriteElementString("Heading", Convert.ToString(gui.heading));
                        xml_writer.WriteElementString("PolyName", gui.polyname);
                        xml_writer.WriteElementString("Poly_IntID", Convert.ToString(gui.poly_internal_id));
                        xml_writer.WriteEndElement(); // End of GUI
                    }

                    //xml_writer.WriteStartElement("Waypoint_List"); // Start of Waypoint List
                    LinkedList <WayPoints> waypoint = path_list.ElementAt(i).waypoints;
                    for (int j = 0; j < waypoint.Count; j++)
                    {
                        xml_writer.WriteStartElement("Waypoint"); // Start of Waypoint
                        lat          = waypoint.ElementAt(j).lat;
                        lon          = waypoint.ElementAt(j).lon;
                        alt          = waypoint.ElementAt(j).alt;
                        head         = waypoint.ElementAt(j).head;
                        rotdir       = waypoint.ElementAt(j).rotationdir;
                        curvesize    = waypoint.ElementAt(j).curvesize;
                        gimble_mode  = waypoint.ElementAt(j).gimblemode;
                        gimble_pitch = waypoint.ElementAt(j).gimblepitch;
                        actions      = waypoint.ElementAt(j).actions;
                        xml_writer.WriteElementString("Lat", Convert.ToString(lat));
                        xml_writer.WriteElementString("Lon", Convert.ToString(lon));
                        xml_writer.WriteElementString("Alt", Convert.ToString(alt));
                        xml_writer.WriteElementString("Heading", Convert.ToString(head));
                        xml_writer.WriteElementString("CurveSize", Convert.ToString(curvesize));
                        xml_writer.WriteElementString("RotationDir", Convert.ToString(curvesize));
                        xml_writer.WriteElementString("GimbleMode", Convert.ToString(gimble_mode));
                        xml_writer.WriteElementString("GimblePitch", Convert.ToString(gimble_pitch));
                        //xml_writer.WriteStartElement("Action_List"); // Start of Action List
                        for (int k = 0; k < 15; k++)
                        {
                            xml_writer.WriteStartElement("Action"); // Start of Action
                            xml_writer.WriteElementString("Type", Convert.ToString(actions[k, 0]));
                            xml_writer.WriteElementString("Param", Convert.ToString(actions[k, 1]));
                            xml_writer.WriteEndElement(); // End of Action
                        }
                        //xml_writer.WriteEndElement(); // End of Action List
                        xml_writer.WriteEndElement(); // End of Waypoint
                    }

                    //xml_writer.WriteEndElement(); // End of Waypoints
                    xml_writer.WriteEndElement(); // End of Path
                }

                xml_writer.WriteEndElement(); // End of WPG
                xml_writer.WriteEndDocument();
            }
        }