public DialogKMLPath(Waypoint_Path_Gen wpg, GMAP gmap, TreeView treeview, double lat, double lon) { _lat = lat; _lon = lon; _wpg = wpg; _gmap = gmap; _treeview = treeview; _current_path_index = -1; _path = new Models.Path(); _wp = new WayPoints(); InitializeComponent(); // Fill POI combobox cmbKLMPOI.Items.Clear(); for (int i = 0; i < _wpg.POICount(); i++) { cmbKLMPOI.Items.Add(_wpg.POIPointAt(i).name); } // Generate EMpty Path _path.Add_Empty_Path(_wpg, _gmap, "Empty Path", "KML"); _current_path_index = _wpg.PathCount() - 1; }
public DialogAddHelixPath(Waypoint_Path_Gen wpg, GMAP gmap, Path path, double lat, double lon) { _wp = new WayPoints(); _wpg = wpg; _gmap = gmap; _lat = lat; _lon = lon; InitializeComponent(); if (path == null) { _new_path = true; _first_pass = true; _path = new Path(); _path.visible = true; _build = true; } else { _new_path = false; _first_pass = false; _build = false; _path = path; HelicalGUI gui = _path.helixgui; txtAddHelixPathName.Text = gui.name; _lat = gui.lat; _lon = gui.lon; txtHelixStartAlt.Text = Convert.ToString(gui.start_alt); txtHelixEndAlt.Text = Convert.ToString(gui.end_alt); txtHelixStartRadius.Text = Convert.ToString(gui.start_rad); txtHelixEndRadius.Text = Convert.ToString(gui.end_rad); txtHelixStartAngle.Text = Convert.ToString(gui.start_angle); txtHelixSpan.Text = Convert.ToString(gui.helix_span); txtHelixNumPoints.Text = Convert.ToString(gui.num_points); chkHelicalHome.Checked = gui.startend; chkHelixPOI.Checked = gui.poimode; cmbHelixPOI.SelectedText = gui.poiname; _build = true; _path.selected = false; } buildHelicalPath(); _gmap.ReDrawgMap(); //_current_path_index = _wpg.PathCount() - 1; cmbHelixPOI.Items.Clear(); for (int i = 0; i < _wpg.POICount(); i++) { cmbHelixPOI.Items.Add(_wpg.POIPointAt(i).name); } }
// Add POI at this location private void btnAddPOI_Click(object sender, EventArgs e) { // Get the POI Name string poi_name = txtAddPOIName.Text; if (poi_name == null | poi_name == "") { MessageBox.Show("Enter a POI Name"); return; } // Make sure POI Name is Unique for (int i = 0; i < _wpg.POICount(); i++) { POIPoints pnt = _wpg.POIPointAt(i); if (poi_name == pnt.name) { MessageBox.Show("Name previously used, Enter a unique name"); return; } } POIPoints poipoint = new POIPoints(); poipoint.name = poi_name; poipoint.lat = _lat; poipoint.lon = _lon; poipoint.elev = Convert.ToDouble(txtAddPOIElev.Text); poipoint.alt = Convert.ToDouble(txtAddPOIAlt.Text); poipoint.cam_alt = Convert.ToDouble(txtAddPOICamAlt.Text); poipoint.visible = true; poipoint.selected = false; _wpg.AddPOI(poipoint); _gmap.Add_gMapPOI(poipoint); //_gmap.ReDrawgMap(); this.Close(); }
public dialogAddCircularPath(Waypoint_Path_Gen wpg, GMAP gmap, Options options, Path path, double lat, double lon) { // Save arguments _wp = new WayPoints(); _wpg = wpg; _gmap = gmap; _options = options; _lat = lat; _lon = lon; // Initialize Dialog InitializeComponent(); // Setup Dialog GUI txtDiaAddCircPathAlt.Text = Convert.ToString(_options.def_altitude); cmbCircPOI.Items.Clear(); cmbCircPOI.Items.Add(""); for (int i = 0; i < _wpg.POICount(); i++) { cmbCircPOI.Items.Add(_wpg.POIPointAt(i).name); } // See if new path if (path == null) { _new_path = true; _first_pass = true; _path = new Path(); //_current_path_index = -1; _path.visible = true; _path.selected = false; double altitude = Convert.ToDouble(txtDiaAddCircPathAlt.Text); double circle_radius = Convert.ToDouble(txtDiaAddCircPathRadius.Text); double start_angle = Convert.ToDouble(txtCircStartAngle.Text); double circle_span = Convert.ToDouble(txtCircSpan.Text); int circle_num_points = Convert.ToInt16(txtCircNumPoints.Text); bool startend = chkCircHome.Checked; CircularGUI gui = new CircularGUI(); gui.CW = startend; gui.name = txtDiaAddCircPathName.Text; gui.lat = _lat; gui.lon = _lon; gui.altitude = altitude; gui.radius = circle_radius; gui.numpoints = circle_num_points; gui.fullcirc = chkFullCircle.Checked; gui.start_angle = start_angle; gui.circ_span = circle_span; gui.startend = startend; gui.poimode = chkCircPOI.Checked; gui.poiname = cmbCircPOI.GetItemText(cmbCircPOI.SelectedItem); _path.circgui = gui; } else { _build = false; _new_path = false; _path = path; _path.selected = false; _path.visible = true; //_current_path_index = _path.id; CircularGUI gui = _path.circgui; txtDiaAddCircPathName.Text = gui.name; _lat = gui.lat; _lon = gui.lon; txtDiaAddCircPathAlt.Text = Convert.ToString(gui.altitude); txtDiaAddCircPathRadius.Text = Convert.ToString(gui.radius); txtCircNumPoints.Text = Convert.ToString(gui.numpoints); chkFullCircle.Checked = gui.fullcirc; txtCircStartAngle.Text = Convert.ToString(gui.start_angle); txtCircSpan.Text = Convert.ToString(gui.circ_span); chkCircHome.Checked = gui.startend; chkCircPOI.Checked = gui.poimode; int index = cmbCircPOI.Items.IndexOf(gui.poiname); cmbCircPOI.SelectedIndex = index; _first_pass = false; _build = true; } buildCircPath(); }
private void buildCircPath() { if (!_build) { return; } // Get Parameters double lat_home = _lat; double lon_home = _lon; double lat_center = _lat; double lon_center = _lon; double altitude = Convert.ToDouble(txtDiaAddCircPathAlt.Text); double circle_radius = Convert.ToDouble(txtDiaAddCircPathRadius.Text); double start_angle = Convert.ToDouble(txtCircStartAngle.Text); double circle_span = Convert.ToDouble(txtCircSpan.Text); int circle_num_points = Convert.ToInt16(txtCircNumPoints.Text); bool startend = chkCircHome.Checked; int[,] no_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 } }; 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 } }; // Get Camera Location double lat_camera = lat_center; double lon_camera = lon_center; String cam_poi_name = cmbCircPOI.GetItemText(cmbCircPOI.SelectedItem); for (int i = 0; i < _wpg.POICount(); i++) { POIPoints tmp_point = _wpg.POIPointAt(i); string name = tmp_point.name; if (cam_poi_name == name) { lat_camera = tmp_point.lat; lon_camera = tmp_point.lon; } } // Generate Full 360 degree circle LinkedList <WayPoints> new_list = new LinkedList <WayPoints>(); int gimblemode = 0; double gimplepitch = -GPS.RadiansToDegrees(Math.Atan(altitude / circle_radius)); double curvesize = 0; double rotdir = 0; if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, 0.0, curvesize, rotdir, 0, 0.0, no_actions); } int count = 0; double heading = 0; double distance; double angle = start_angle; double angle_increment = circle_span / (circle_num_points); bool full_circle = chkFullCircle.Checked; if (circle_span == 360.0) { full_circle = true; } double circ_lat; double circ_lon; double start_lat = 0; double start_lon = 0; double start_head = 0; if (full_circle) { angle_increment = 360.0 / circle_num_points; } if (radioCCW.Checked) { angle_increment = -angle_increment; } int num_points = circle_num_points; if (!full_circle) { num_points++; } do { circ_lat = GPS.GPS_Lat_BearDist(lat_center, lon_center, angle, circle_radius, Form1.Globals.gps_radius); circ_lon = GPS.GPS_Lon_BearDist(lat_center, lon_center, circ_lat, angle, circle_radius, Form1.Globals.gps_radius); if (chkCircPOI.Checked) { heading = GPS.GPS_Bearing(circ_lat, circ_lon, lat_camera, lon_camera); distance = GPS.GPS_Distance(circ_lat, circ_lon, lat_camera, lon_camera, Form1.Globals.gps_radius); gimplepitch = -GPS.RadiansToDegrees(Math.Atan(altitude / distance)); gimblemode = 2; } else { heading = GPS.Mod_Angle(angle + 90); if (radioCCW.Checked) { heading = GPS.Mod_Angle(heading + 180.0); } gimplepitch = 0; gimblemode = 0; } if (count == 0) { start_lat = circ_lat; start_lon = circ_lon; start_head = heading; } _wp.Add_Waypoint_List(new_list, circ_lat, circ_lon, altitude, heading, curvesize, rotdir, gimblemode, gimplepitch, actions); angle = angle + angle_increment; count++; } while (count < num_points); if (full_circle) { _wp.Add_Waypoint_List(new_list, start_lat, start_lon, altitude, start_head, curvesize, rotdir, gimblemode, gimplepitch, actions); } ; if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, 0.0, curvesize, rotdir, gimblemode, 0.0, no_actions); } // Save Path if (_new_path & _first_pass) { string path_name = txtDiaAddCircPathName.Text; if (path_name == "") { path_name = "Untitled - Circular"; } _path.Add_Path(_wpg, _gmap, path_name, "Circular", new_list); _path = _wpg.PathAt(_wpg.PathCount() - 1); _first_pass = false; //Models.Path newpath = _wpg.PathAt(_current_path_index); //newpath.visible = true; //newpath.selected = true; } else { _path.waypoints = new_list; //_wpg.ChangePathWP(_path, new_list); //Models.Path path = _wpg.PathAt(_current_path_index); //_gmap.Delete_gMapPath(path); //_gmap.Add_gMapPath(path, false); } _path.visible = true; _path.selected = false; //_gmap.BuildgMap(); _gmap.ReDrawgMap(); }
public DialogAddRectPath(Waypoint_Path_Gen wpg, GMAP gmap, Options options, Path path, double lat, double lon) { _wp = new WayPoints(); _wpg = wpg; _gmap = gmap; _options = options; _lat = lat; _lon = lon; _camera_angle_hor = _options.focal_angle_hor; _camera_angle_ver = _options.focal_angle_ver; //_overlap_width = over_wid; //_overlap_height = over_hgt; _overlap_width = _options.hor_overlap_percent; _overlap_height = _options.ver_overlap_percent; _poly = new Shape(); InitializeComponent(); // Fill POI combobox cmbRectCamPOI.Items.Clear(); for (int i = 0; i < _wpg.POICount(); i++) { cmbRectCamPOI.Items.Add(_wpg.POIPointAt(i).name); } // New or Redefine Path if (path == null) { _new_path = true; _first_pass = true; _path = new Path(); _path.visible = true; _path.selected = false; _build = true; txtPathAlt.Text = Convert.ToString(_options.def_altitude); trkRectAlt.Value = Convert.ToInt16(_options.def_altitude); } else { _new_path = false; _path = path; _path.selected = false; _current_intid = path.internal_id; RectanglarGUI gui = _path.rectanglegui; _build = false; txtRectPathName.Text = gui.name; radioVideo.Checked = Convert.ToBoolean(gui.video); chkRectHome.Checked = Convert.ToBoolean(gui.startend); txtPathAlt.Text = Convert.ToString(gui.altitude); txtGridRotation.Text = Convert.ToString(gui.heading); txtGridLength.Text = Convert.ToString(gui.length); txtGridWidth.Text = Convert.ToString(gui.width); chkOnePass.Checked = Convert.ToBoolean(gui.single); chkRectCamPOI.Checked = Convert.ToBoolean(gui.poimode); int index = cmbRectCamPOI.Items.IndexOf(gui.poiname); cmbRectCamPOI.SelectedIndex = index; _build = true; } _build = true; BuildRectPath(); }
private void BuildRectPath() { if (!_build) { return; } // Get center position double lat_home = _lat; double lon_home = _lon; double lat_center = _lat; double lon_center = _lon; string path_name = txtRectPathName.Text; /* * int poi_count = _wpg.POICount(); * POIPoints tmp_point; * for (int i = 0; i < poi_count; i++) * { * tmp_point = _wpg.POIPointAt(i); * string name = tmp_point.name; * if (home_name == name) * { * * lat_home = tmp_point.lat; * lon_home = tmp_point.lon; * } * } */ double lat_camera; double lon_camera; LinkedList <WayPoints> new_list = new LinkedList <WayPoints>(); // Get Values from input Boxes _video = radioVideo.Checked; bool OnePass = chkOnePass.Checked; bool startend = chkRectHome.Checked; bool camerapoi = chkRectCamPOI.Checked; int poi_count; if (camerapoi) { string poi_name = cmbRectCamPOI.GetItemText(cmbRectCamPOI.SelectedItem); poi_count = _wpg.POICount(); for (int i = 0; i < poi_count; i++) { POIPoints tmp_point = _wpg.POIPointAt(i); string name = tmp_point.name; if (poi_name == name) { lat_camera = tmp_point.lat; lon_camera = tmp_point.lon; } } } double box_width = Convert.ToDouble(txtGridLength.Text); double box_height = Convert.ToDouble(txtGridWidth.Text); double altitude = Convert.ToDouble(txtPathAlt.Text); _camera_width = (2 * (Math.Tan(GPS.DegreesToRadians(_camera_angle_hor / 2)) * altitude)); _camera_height = (2 * (Math.Tan(GPS.DegreesToRadians(_camera_angle_ver / 2)) * altitude)); if (!Form1.Globals.UnitsMetric) { box_width = FeetToMeters(box_width); box_height = FeetToMeters(box_height); _camera_width = FeetToMeters(_camera_width); _camera_height = FeetToMeters(_camera_height); } //double box_rotate = Convert.ToDouble(txtGridRotation.Text); double box_rotate = Convert.ToDouble(txtGridRotation.Text) - 90.0; //double box_rotate = 0.0; double hor_overlap = _overlap_width / 100; double ver_overlap = _overlap_height / 100; double gps_radius = Form1.Globals.gps_radius; int[,] actions = new int[, ] { { 0, 2000 }, { 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 } }; int[,] no_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 } }; /* Start Calculating */ double diagonal_length = Math.Sqrt((box_width / 2) * (box_width / 2) + (box_height / 2) * (box_height / 2)); double diagonal_angle = GPS.RadiansToDegrees(Math.Atan((box_width / 2) / (box_height / 2))); /* Calculate Top, Bottom, Left & Right Center Positions */ double lat_top; double lon_top; double lat_bottom; double lon_bottom; double lat_left; double lon_left; double lat_right; double lon_right; lat_top = GPS.GPS_Lat_BearDist(lat_center, lon_center, 0, box_height / 2, gps_radius); lon_top = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, 0, box_height / 2, gps_radius); lat_bottom = GPS.GPS_Lat_BearDist(lat_center, lon_center, 180, box_height / 2, gps_radius); lon_bottom = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_bottom, 180, box_height / 2, gps_radius); lat_left = GPS.GPS_Lat_BearDist(lat_center, lon_center, 270, box_width / 2, gps_radius); lon_left = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_left, 270, box_width / 2, gps_radius); lat_right = GPS.GPS_Lat_BearDist(lat_center, lon_center, 90, box_width / 2, gps_radius); lon_right = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_right, 90, box_width / 2, gps_radius); /* Calculate 4 corner locations */ double lat_top_left; double lon_top_left; double lat_bottom_left; double lon_bottom_left; double lat_top_right; double lon_top_right; double lat_bottom_right; double lon_bottom_right; double[,] polypnt = new double[4, 2]; lat_top_left = GPS.GPS_Lat_BearDist(lat_center, lon_center, -diagonal_angle, diagonal_length, gps_radius); lon_top_left = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, -diagonal_angle, diagonal_length, gps_radius); polypnt[0, 0] = lat_top_left; polypnt[0, 1] = lon_top_left; lat_top_right = GPS.GPS_Lat_BearDist(lat_center, lon_center, diagonal_angle, diagonal_length, gps_radius); lon_top_right = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, diagonal_angle, diagonal_length, gps_radius); polypnt[1, 0] = lat_top_right; polypnt[1, 1] = lon_top_right; lat_bottom_right = GPS.GPS_Lat_BearDist(lat_center, lon_center, 180 - diagonal_angle, diagonal_length, gps_radius); lon_bottom_right = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, 180 - diagonal_angle, diagonal_length, gps_radius); polypnt[2, 0] = lat_bottom_right; polypnt[2, 1] = lon_bottom_right; lat_bottom_left = GPS.GPS_Lat_BearDist(lat_center, lon_center, 180 + diagonal_angle, diagonal_length, gps_radius); lon_bottom_left = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, 180 + diagonal_angle, diagonal_length, gps_radius); polypnt[3, 0] = lat_bottom_left; polypnt[3, 1] = lon_bottom_left; // Rotate Points double new_lat, new_lon; for (int i = 0; i < 4; i++) { double rot_bearing = GPS.GPS_Bearing(lat_center, lon_center, polypnt[i, 0], polypnt[i, 1]); double rot_distance = GPS.GPS_Distance(lat_center, lon_center, polypnt[i, 0], polypnt[i, 1], gps_radius); // Calculate a new location by increasing the bearing new_lat = GPS.GPS_Lat_BearDist(lat_center, lon_center, rot_bearing + box_rotate, rot_distance, gps_radius); new_lon = GPS.GPS_Lon_BearDist(lat_center, lon_center, new_lat, rot_bearing + box_rotate, rot_distance, gps_radius); polypnt[i, 0] = new_lat; polypnt[i, 1] = new_lon; } // Generate Rectangle Polygon _poly.name = "temp"; _poly.visible = true; LinkedList <PolyPoint> shape_points = new LinkedList <PolyPoint>(); for (int i = 0; i <= 3; i++) { PolyPoint newpnt = new PolyPoint(); newpnt.lat = polypnt[i, 0]; newpnt.lon = polypnt[i, 1]; newpnt.alt = 10; shape_points.AddLast(newpnt); } PolyPoint pnt = new PolyPoint(); pnt.lat = polypnt[0, 0]; pnt.lon = polypnt[0, 1]; pnt.alt = 10; shape_points.AddLast(pnt); _poly.points = shape_points; // Get Direction Flags double drone_heading = 90.0; int ver_dir_flag = 1; if (radioUpLeft.Checked) { ver_dir_flag = 1; } if (radioUpRight.Checked) { ver_dir_flag = 1; drone_heading = 270; } if (radioLowLeft.Checked) { ver_dir_flag = -1; } if (radioLowRight.Checked) { ver_dir_flag = -1; drone_heading = 270; } // Grid Calculations double lat_next; double next_lon_start; double next_lon_end; double lon_tmp; double row_increment = _camera_width * (1.0 - hor_overlap); int num_rows = Convert.ToInt16(box_height / row_increment); box_rotate = 0.0; // Create Waypoints int gimblemode = 2; double gimblepitch = -90.0; double curvesize = 0; double rotdir = 0; if (OnePass | num_rows == 1) { if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, no_actions); } if (radioUpLeft.Checked | radioLowLeft.Checked) { _wp.Add_Leg_List(new_list, lat_left, lon_left, lat_right, lon_right, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); } else { _wp.Add_Leg_List(new_list, lat_right, lon_right, lat_left, lon_left, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); } if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, no_actions); } } else { /* More than one row */ if (num_rows == 2) { double offset = row_increment; double diagonal_length_2 = Math.Sqrt((box_width / 2) * (box_width / 2) + (offset / 2) * (offset / 2)); double diagonal_angle_2 = GPS.RadiansToDegrees(Math.Atan((box_width / 2) / (offset / 2))); lat_top_left = GPS.GPS_Lat_BearDist(lat_center, lon_center, -diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); lon_top_left = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, -diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); lat_top_right = GPS.GPS_Lat_BearDist(lat_center, lon_center, diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); lon_top_right = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); lat_bottom_left = GPS.GPS_Lat_BearDist(lat_center, lon_center, 180 + diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); lon_bottom_left = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, 180 + diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); lat_bottom_right = GPS.GPS_Lat_BearDist(lat_center, lon_center, 180 - diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); lon_bottom_right = GPS.GPS_Lon_BearDist(lat_center, lon_center, lat_top, 180 - diagonal_angle_2 + box_rotate, diagonal_length_2, gps_radius); if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, no_actions); } if (radioLowLeft.Checked) { _wp.Add_Leg_List(new_list, lat_bottom_left, lon_bottom_left, lat_bottom_right, lon_bottom_right, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); _wp.Add_Leg_List(new_list, lat_top_right, lon_top_right, lat_top_left, lon_top_left, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); } if (radioLowRight.Checked) { _wp.Add_Leg_List(new_list, lat_bottom_right, lon_bottom_right, lat_bottom_left, lon_bottom_left, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); _wp.Add_Leg_List(new_list, lat_top_left, lon_top_left, lat_top_right, lon_top_right, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); } if (radioUpLeft.Checked) { _wp.Add_Leg_List(new_list, lat_top_left, lon_top_left, lat_top_right, lon_top_right, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); _wp.Add_Leg_List(new_list, lat_bottom_right, lon_bottom_right, lat_bottom_left, lon_bottom_left, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); } if (radioUpRight.Checked) { _wp.Add_Leg_List(new_list, lat_top_right, lon_top_right, lat_top_left, lon_top_left, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); _wp.Add_Leg_List(new_list, lat_bottom_left, lon_bottom_left, lat_bottom_right, lon_bottom_right, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); } if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, no_actions); } } else { /* More than 2 rows */ double row_span = (num_rows - 1) * row_increment; lat_top = GPS.GPS_Lat_BearDist(lat_center, lon_center, 0 + box_rotate, row_span / 2, gps_radius); lat_bottom = GPS.GPS_Lat_BearDist(lat_center, lon_center, 180 + box_rotate, row_span / 2, gps_radius); double degrees_per_foot = (lat_top - lat_bottom) / row_span; if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, no_actions); } int row_count = 0; next_lon_start = 0.0; next_lon_end = 0.0; double lat_current = 0.0; do { /* First Row */ if (row_count == 0) { if (radioLowLeft.Checked) { _wp.Add_Leg_List(new_list, lat_bottom, lon_left, lat_bottom, lon_right, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); lat_current = lat_bottom; next_lon_start = lon_right; next_lon_end = lon_left; } if (radioLowRight.Checked) { _wp.Add_Leg_List(new_list, lat_bottom, lon_right, lat_bottom, lon_left, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); lat_current = lat_bottom; next_lon_start = lon_left; next_lon_end = lon_right; } if (radioUpLeft.Checked) { _wp.Add_Leg_List(new_list, lat_top, lon_left, lat_top, lon_right, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); lat_current = lat_top; next_lon_start = lon_right; next_lon_end = lon_left; } if (radioUpRight.Checked) { _wp.Add_Leg_List(new_list, lat_top, lon_right, lat_top, lon_left, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); lat_current = lat_top; next_lon_start = lon_left; next_lon_end = lon_right; } } else { /* Output 2nd, 3rd, etc. */ //lat_current = Globals.waypoints[Globals.waypoint_count - 1, 0]; lat_next = lat_current + (-ver_dir_flag * (degrees_per_foot * row_increment)); _wp.Add_Leg_List(new_list, lat_next, next_lon_start, lat_next, next_lon_end, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, actions, _video, _camera_height, _overlap_height); lon_tmp = next_lon_start; next_lon_start = next_lon_end; next_lon_end = lon_tmp; lat_current = lat_next; } row_count++; } while (row_count < num_rows); if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, altitude, drone_heading, curvesize, rotdir, gimblemode, gimblepitch, no_actions); } } } // Rotate WayPoints about Center int count = 0; double lat, lon, alt, head, bearing, distance; double lat_first = lat_center; double lon_first = lon_center; LinkedListNode <WayPoints> node = new_list.First; //LinkedListNode<WayPoints> next_node = node.Next; LinkedListNode <WayPoints> save_node; //lat_first = node.Value.lat; //lon_first = node.Value.lon; //alt_first = node.Value.alt; //head_first = node.Value.head; while (node != null) { if (count != 0) { // Get Waypoint values lat = node.Value.lat; lon = node.Value.lon; alt = node.Value.alt; head = node.Value.head; gimblemode = node.Value.gimblemode; gimblepitch = node.Value.gimblepitch; curvesize = node.Value.curvesize; rotdir = node.Value.rotationdir; actions = node.Value.actions; box_rotate = Convert.ToDouble(txtGridRotation.Text) - 90.0; // Calculate Bearing and distance from first waypoint bearing = GPS.GPS_Bearing(lat_first, lon_first, lat, lon); distance = GPS.GPS_Distance(lat_first, lon_first, lat, lon, gps_radius); // Calculate a new location by increasing the bearing new_lat = GPS.GPS_Lat_BearDist(lat_first, lon_first, bearing + box_rotate, distance, gps_radius); new_lon = GPS.GPS_Lon_BearDist(lat_first, lon_first, new_lat, bearing + box_rotate, distance, gps_radius); // Set new waypoint WayPoints new_wp = new WayPoints(); new_wp.lat = new_lat; new_wp.lon = new_lon; new_wp.alt = alt; new_wp.head = head + box_rotate; new_wp.gimblemode = gimblemode; new_wp.gimblepitch = gimblepitch; new_wp.curvesize = curvesize; new_wp.rotationdir = rotdir; new_wp.actions = actions; save_node = node; new_list.AddBefore(node, new_wp); node = node.Next; new_list.Remove(save_node); } count++; } // Redo start and end points if (startend) { WayPoints wp = new_list.First.Value; new_list.RemoveFirst(); wp.lat = lat_home; wp.lon = lon_home; new_list.AddFirst(wp); wp = new_list.Last.Value; new_list.RemoveLast(); wp.lat = lat_home; wp.lon = lon_home; new_list.AddLast(wp); } // Save Path if (_new_path & _first_pass) { path_name = txtRectPathName.Text; if (path_name == "") { path_name = "Untitled - Rectangular"; } _path.Add_Path(_wpg, _gmap, path_name, "Rectangular", new_list); Path newpath = _wpg.PathAt(_wpg.PathCount() - 1); _current_intid = newpath.internal_id; _first_pass = false; } else { _wpg.ChangePathWPIntId(_current_intid, new_list); //Models.Path path = _wpg.PathAt(_current_path_index); //_gmap.Delete_gMapPath(path); //_gmap.Add_gMapPath(path, false); } _gmap.ReDrawgMap(); _gmap.Add_gMapPoly(_poly, true); }
private void buildHelicalPath() { if (!_build) { return; } bool startend = chkHelicalHome.Checked; double lat_home = _lat; double lon_home = _lon; double lat_center = _lat; double lon_center = _lon; double helix_start_alt = Convert.ToDouble(txtHelixStartAlt.Text); double helix_end_alt = Convert.ToDouble(txtHelixEndAlt.Text); double helix_start_radius = Convert.ToDouble(txtHelixStartRadius.Text); double helix_end_radius = Convert.ToDouble(txtHelixEndRadius.Text); double helix_start_angle = Convert.ToDouble(txtHelixStartAngle.Text); double helix_span = Convert.ToDouble(txtHelixSpan.Text); int helix_num_points = Convert.ToInt16(txtHelixNumPoints.Text); int[,] no_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 } }; 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 } }; double cw = 1.0; if (radioCCW.Checked) { cw = -1.0; } double lat_camera = lat_center; double lon_camera = lon_center; String cam_poi_name = cmbHelixPOI.GetItemText(cmbHelixPOI.SelectedItem); for (int i = 0; i < _wpg.POICount(); i++) { POIPoints tmp_point = _wpg.POIPointAt(i); string name = tmp_point.name; if (cam_poi_name == name) { lat_camera = tmp_point.lat; lon_camera = tmp_point.lon; } } LinkedList <WayPoints> new_list = new LinkedList <WayPoints>(); int count = 0; double angle = helix_start_angle; double angle_increment = cw * helix_span / helix_num_points; double circ_lat; double circ_lon; //if (chkFullCircle.Checked) angle_increment = 360.0 / helix_num_points; //if (radioCCW.Checked) angle_increment = -angle_increment; double alt_diff = helix_end_alt - helix_start_alt; int alt_dir; if (helix_start_alt > helix_end_alt) { alt_dir = -1; } else { alt_dir = 1; } double alt_increment = (helix_end_alt - helix_start_alt) / helix_num_points; double radius_increment = (helix_end_radius - helix_start_radius) / helix_num_points; double helix_radius; double helix_altitude; int gimblemode = 0; double gimplepitch = 0; double distance; double curvesize = 0; double rotdir = 0; if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, helix_start_alt, 0.0, curvesize, rotdir, gimblemode, gimplepitch, no_actions); } do { double heading = GPS.Mod_Angle(angle + 180.0); helix_radius = helix_start_radius + (count * radius_increment); helix_altitude = helix_start_alt + (count * alt_increment); //norm_angle = 180.0*(angle / (helix_end_angle - helix_start_angle)); //helix_altitude = helix_start_alt + (alt_diff * alt_dir * (1+Math.Cos(DegreesToRadians(norm_angle)))/2); circ_lat = GPS.GPS_Lat_BearDist(lat_center, lon_center, angle, helix_radius, Form1.Globals.gps_radius); circ_lon = GPS.GPS_Lon_BearDist(lat_center, lon_center, circ_lat, angle, helix_radius, Form1.Globals.gps_radius); if (chkHelixPOI.Checked) { heading = GPS.GPS_Bearing(circ_lat, circ_lon, lat_camera, lon_camera); distance = GPS.GPS_Distance(circ_lat, circ_lon, lat_camera, lon_camera, Form1.Globals.gps_radius); gimplepitch = -GPS.RadiansToDegrees(Math.Atan(helix_altitude / distance)); gimblemode = 2; } else { heading = GPS.Mod_Angle(angle + 90); if (radioCCW.Checked) { heading = GPS.Mod_Angle(heading + 180.0); } } _wp.Add_Waypoint_List(new_list, circ_lat, circ_lon, helix_altitude, heading, curvesize, rotdir, gimblemode, gimplepitch, actions); angle = angle + angle_increment; count++; } while (count <= helix_num_points); if (startend) { _wp.Add_Waypoint_List(new_list, lat_home, lon_home, helix_start_alt, 0.0, curvesize, rotdir, gimblemode, gimplepitch, no_actions); } // Save Path if (_new_path & _first_pass) { string path_name = txtAddHelixPathName.Text; if (path_name == "") { path_name = "Untitled - Helical"; } _path.Add_Path(_wpg, _gmap, path_name, "Helical", new_list); _path = _wpg.PathAt(_wpg.PathCount() - 1); _first_pass = false; } else { _path.waypoints = new_list; //_gmap.Delete_gMapPath(_path); //_gmap.Add_gMapPath(_path, false); } /* * if (_current_path_index != -1) * { * _wpg.DeletePath(_wpg.PathAt(_current_path_index)); * } * string path_name = txtAddHelixPathName.Text; * if (path_name == "") path_name = "Untitled - Helical"; * _path.Add_Path(_wpg, _gmap, path_name, "Helical", new_list); * int index = _wpg.PathCount() - 1; * _current_path_index = index; * Models.Path path = _wpg.PathAt(index); * _path = path; * string exist_type = path.type; * bool exist_select = path.selected; * bool exist_visible = path.visible; * if (exist_type == "Helical") * { * _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(); //_wpg.ChangePathWP(index, new_list); //cmbCircReuse.ResetText(); }
public void BuildgMap() { /* * switch (index) * { * case 0: * _mapcontrol.MapProvider = global::GMap.NET.MapProviders.BingSatelliteMapProvider.Instance; * break; * case 1: * _mapcontrol.MapProvider = global::GMap.NET.MapProviders.GoogleMapProvider.Instance; * break; * case 2: * _mapcontrol.MapProvider = global::GMap.NET.MapProviders.GoogleTerrainMapProvider.Instance; * break; * case 3: * _mapcontrol.MapProvider = global::GMap.NET.MapProviders.GoogleHybridMapProvider.Instance; * break; * case 4: * _mapcontrol.MapProvider = global::GMap.NET.MapProviders.ArcGIS_Topo_US_2D_MapProvider.Instance; * break; * case 5: * _mapcontrol.MapProvider = global::GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance; * break; * } * * * * global::GMap.NET.GMaps.Instance.Mode = global::GMap.NET.AccessMode.ServerOnly; */ _markers.Clear(); _mapcontrol.Overlays.Clear(); //_mapcontrol.ShowCenter = false; _overmarkers = new GMapOverlay("markers"); _overroutes = new GMapOverlay("routes"); _overpolys = new GMapOverlay("polygons"); _mapcontrol.Overlays.Add(_overmarkers); _mapcontrol.Overlays.Add(_overroutes); _mapcontrol.Overlays.Add(_overpolys); _drone_image_notselected = (Bitmap)Image.FromFile("drone.png", true); _drone_image_selected = (Bitmap)Image.FromFile("drone_selected.png", true); // Map POI int poicount = _wpg.POICount(); for (int i = 0; i < poicount; i++) { GMapMarker marker; POIPoints pnt = _wpg.POIPointAt(i); string poiname = pnt.name; if (i == 0) { _mapcontrol.Position = new global::GMap.NET.PointLatLng(pnt.lat, pnt.lon); } if (pnt.selected) { marker = new GMarkerGoogle(new PointLatLng(pnt.lat, pnt.lon), _poi_selected_image); } else { marker = new GMarkerGoogle(new PointLatLng(pnt.lat, pnt.lon), _poi_image); } // GMarkerGoogleType.blue_pushpin); //marker.Size = new Size(32, 32); marker.Offset = new Point(-16, -16); marker.ToolTipText = poiname; marker.Tag = poiname; marker.IsVisible = pnt.visible; marker.IsHitTestVisible = true; _overmarkers.Markers.Add(marker); } // Map Path int pathcount = _wpg.PathCount(); for (int i = 0; i < pathcount; i++) { Path path = _wpg.PathAt(i); string name = path.name; bool visible = path.visible; LinkedList <WayPoints> wplist = path.waypoints; int wpcount = wplist.Count; List <PointLatLng> points = new List <PointLatLng>(); int count = 0; foreach (WayPoints wp in wplist) { bool selected = wp.selected; points.Add(new PointLatLng(wp.lat, wp.lon)); GMapMarker marker; if (selected) { _drone_image = _drone_image_selected; _drone_image = RotateImage(_drone_image_selected, wp.head); marker = new GMarkerGoogle(new PointLatLng(wp.lat, wp.lon), _drone_image); //GMarkerGoogleType.red_pushpin); } else { _drone_image = _drone_image_notselected; _drone_image = RotateImage(_drone_image_notselected, wp.head); marker = new GMarkerGoogle(new PointLatLng(wp.lat, wp.lon), _drone_image); //GMarkerGoogleType.blue_pushpin); } //marker.Size = new Size(64,64); marker.Position = new PointLatLng(wp.lat, wp.lon); marker.Offset = new Point(-16, -16); marker.Tag = Convert.ToString(i) + "." + Convert.ToString(count); marker.IsVisible = visible; marker.ToolTipText = "WP(" + Convert.ToString(count) + ") - Alt:" + Convert.ToString(wp.alt); _overmarkers.Markers.Add(marker); wp.marker = marker; GMAPWPMarker wpmarker = new GMAPWPMarker(); wpmarker.path = i; wpmarker.wp = count; wpmarker.marker = marker; wpmarker.selected = wp.selected; _markers.Add(wpmarker); count++; } GMapRoute route = new GMapRoute(points, name); route.Stroke = new Pen(Color.Blue, 2); route.Tag = i; route.IsVisible = visible; route.IsHitTestVisible = true; _overroutes.Routes.Add(route); //mapcontrol.Overlays.Add(overroutes); //mapcontrol.Overlays.Add(markers); } //mapcontrol.Overlays.Add(markers); // Map Polygon int polycount = _wpg.ShapeCount(); for (int i = 0; i < polycount; i++) { Shape polyshape = _wpg.ShapeAt(i); string name = polyshape.name; bool visible = polyshape.visible; LinkedList <PolyPoint> wplist = polyshape.points; int wpcount = wplist.Count; List <PointLatLng> points = new List <PointLatLng>(); foreach (PolyPoint wp in wplist) { points.Add(new PointLatLng(wp.lat, wp.lon)); } GMapPolygon poly = new GMapPolygon(points, name); if (polyshape.selected) { poly.Stroke = new Pen(Color.Red, 1); } else { poly.Stroke = new Pen(Color.Yellow, 1); } poly.Fill = new SolidBrush(Color.FromArgb(25, Color.Yellow)); poly.Tag = polyshape.name; poly.IsVisible = visible; _overpolys.Polygons.Add(poly); } if (!Form1.Globals.Map_FirstDraw) { _mapcontrol.Position = Form1.Globals.map_center; Form1.Globals.Map_FirstDraw = false; } _center = _mapcontrol.Position; }