コード例 #1
0
        private void BuildPath()
        {
            int polyindex = cmbPolyPath.SelectedIndex;

            if (polyindex == -1)
            {
                return;
            }

            // Get Path

            double lat, lat_next;
            double lon, lon_next;
            double alt = Convert.ToDouble(txtAltPolyPath.Text);
            double head;
            int    gimblemode  = 0;
            double gimblepitch = 0;
            double curvesize   = 0;
            double rotdir      = 0;

            int[,] actions = new int[, ] {
                { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }
            };
            Models.Shape           poly      = _wpg.ShapeAt(polyindex);
            LinkedList <PolyPoint> points    = poly.points;
            LinkedList <WayPoints> waypoints = new LinkedList <WayPoints>();
            string path_name = poly.name;

            for (int i = 0; i < points.Count; i++)
            {
                lat = points.ElementAt(i).lat;
                lon = points.ElementAt(i).lon;
                if (i < (points.Count - 1))
                {
                    lat_next = points.ElementAt(i + 1).lat;
                    lon_next = points.ElementAt(i + 1).lon;
                    head     = GPS.GPS_Bearing(lat, lon, lat_next, lon_next);
                }
                else
                {
                    lat_next = points.ElementAt(0).lat;
                    lon_next = points.ElementAt(0).lon;
                    head     = GPS.GPS_Bearing(lat, lon, lat_next, lon_next);
                }
                _wp.Add_Waypoint_List(waypoints, lat, lon, alt, head, curvesize, rotdir, gimblemode, gimblepitch, actions);
            }

            // Add Path

            if (_current_path_index != -1)
            {
                _wpg.DeletePath(_wpg.PathAt(_current_path_index));
            }

            int index = cmbPolyPath.SelectedIndex;

            path_name = _wpg.ShapeAt(index).name;
            if (path_name == "")
            {
                path_name = "Untitled - Perimeter";
            }
            _path.Add_Path(_wpg, _gmap, path_name, "Perimeter", waypoints);
            index = _wpg.PathCount() - 1;
            _current_path_index = index;

            Models.Path path          = _wpg.PathAt(index);
            string      exist_type    = path.type;
            bool        exist_select  = path.selected;
            bool        exist_visible = path.visible;

            if (exist_type == "Perimeter")
            {
                _wpg.ChangePathWP(index, waypoints);
                string pathname = path.name;
                int    id       = path.id;
                string type     = path.type;
                _gmap.Delete_gMapPath(path);
                Models.Path newpath = new Models.Path();
                newpath.name      = pathname;
                newpath.id        = id;
                newpath.type      = type;
                newpath.selected  = exist_select;
                newpath.visible   = exist_visible;
                newpath.waypoints = waypoints;
                _gmap.Add_gMapPath(path, false);
            }

            _gmap.ReDrawgMap();
        }
コード例 #2
0
        private void BuildKMLPath()
        {
            // Create Path

            if (_current_path_index != -1)
            {
                _wpg.DeletePath(_wpg.PathAt(_current_path_index));
            }

            string path_name = txtKMLName.Text;

            if (path_name == "")
            {
                path_name = _kml_filename;
            }

            LinkedList <WayPoints> wp_list = new LinkedList <WayPoints>();

            double lat, lon, alt;
            int    gimblemode  = 0;
            double gimblepitch = 0;
            double curvesize   = 0;
            double rotdir      = 0;

            int[,] actions = new int[, ] {
                { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }, { -1, 0 }
            };

            LinkedList <WayPoints> new_list = new LinkedList <WayPoints>();

            /* Generate Waypoints for each coordinate */

            for (int i = 0; i < _kml_point_count; i++)
            {
                lat = _kml_points[i, 0];
                lon = _kml_points[i, 1];
                alt = _kml_points[i, 2];
                double heading = 0.0;
                double poi_lat = 0;
                double poi_lon = 0;

                /* Calculate Heading for each Waypoint */
                if (chKLMPOI.Checked)
                {
                    int poi_index = cmbKLMPOI.SelectedIndex;
                    if (poi_index == -1)
                    {
                        poi_lat = _lat;
                        poi_lon = _lon;
                    }
                    else
                    {
                        POIPoints tmp_point = _wpg.POIPointAt(poi_index);
                        poi_lat = tmp_point.lat;
                        poi_lon = tmp_point.lon;
                    }
                    heading    = GPS.GPS_Bearing(lat, lon, poi_lat, poi_lon);
                    gimblemode = 2;
                    double distance = GPS.GPS_Distance(lat, lon, poi_lat, poi_lon, Form1.Globals.gps_radius);
                    gimblepitch = -GPS.RadiansToDegrees(Math.Atan(alt / distance));
                    gimblemode  = 2;
                }
                else
                {
                    if (i != _kml_point_count - 1)
                    {
                        double lat_next = _kml_points[i + 1, 0];
                        double lon_next = _kml_points[i + 1, 1];
                        heading = GPS.GPS_Bearing(lat, lon, lat_next, lon_next);
                    }
                }
                _wp.Add_Waypoint_List(new_list, lat, lon, alt, heading, curvesize, rotdir, gimblemode, gimblepitch, actions);
                //dgvWaypoints.Rows.Add(Globals.waypoint_count + i+1, Convert.ToString(lat), Convert.ToString(lon), Convert.ToString(alt));
            }

            _path.Add_Path(_wpg, _gmap, path_name, "KML", new_list);
            int index = _wpg.PathCount() - 1;

            _current_path_index = index;

            Models.Path path          = _wpg.PathAt(index);
            string      exist_type    = path.type;
            bool        exist_select  = path.selected;
            bool        exist_visible = path.visible;

            if (exist_type == "KML")
            {
                _wpg.ChangePathWP(index, new_list);
                string pathname = path.name;
                int    id       = path.id;
                string type     = path.type;
                _gmap.Delete_gMapPath(path);
                Models.Path newpath = new Models.Path();
                newpath.name      = pathname;
                newpath.id        = id;
                newpath.type      = type;
                newpath.selected  = exist_select;
                newpath.visible   = exist_visible;
                newpath.waypoints = new_list;
                _gmap.Add_gMapPath(path, false);
            }

            _gmap.ReDrawgMap();
            GMAPTree.Update_GMapTree(_wpg, _treeview);
        }