private void btnAccept_Click(object sender, EventArgs e)
        {
            _wp.alt         = Convert.ToDouble(txtwpalt.Text);
            _wp.head        = Convert.ToDouble(txtwphead.Text);
            _wp.curvesize   = Convert.ToDouble(txtwpcurvesize.Text);
            _wp.rotationdir = Convert.ToDouble(txtwprotdirection.Text);
            _wp.gimblemode  = Convert.ToInt16(txtwpgimblemode.Text);
            _wp.gimblepitch = Convert.ToDouble(txtgimblepitch.Text);
            int action_id = cmbActions.SelectedIndex;

            Models.Action action = _wpg.ActionAt(action_id);
            string        name   = action.name;

            int[,] actions = action.actions;
            _wp.actions    = actions;
            _gmap.ReDrawgMap();
            this.Close();
        }
        private void btnNextWP_Click(object sender, EventArgs e)
        {
            // Save current wp

            _wp.alt         = Convert.ToDouble(txtwpalt.Text);
            _wp.head        = Convert.ToDouble(txtwphead.Text);
            _wp.curvesize   = Convert.ToDouble(txtwpcurvesize.Text);
            _wp.rotationdir = Convert.ToDouble(txtwprotdirection.Text);
            _wp.gimblemode  = Convert.ToInt16(txtwpgimblemode.Text);
            _wp.gimblepitch = Convert.ToDouble(txtgimblepitch.Text);
            int action_id = cmbActions.SelectedIndex;

            Models.Action action = _wpg.ActionAt(action_id);
            string        name   = action.name;

            int[,] actions = action.actions;
            _wp.actions    = actions;
            _wp.selected   = false;

            // Go to next wp

            _wp_index++;
            if (_wp_index >= _wp_list.Count)
            {
                _wp_index = _wp_list.Count - 1;
            }
            _wp                    = _wp_list.ElementAt(_wp_index);
            txtWPIndex.Text        = Convert.ToString(_wp_index);
            txtwplat.Text          = Convert.ToString(_wp.lat);
            txtwplon.Text          = Convert.ToString(_wp.lon);
            txtwpalt.Text          = Convert.ToString(_wp.alt);
            txtwphead.Text         = Convert.ToString(_wp.head);
            txtwpcurvesize.Text    = Convert.ToString(_wp.curvesize);
            txtwprotdirection.Text = Convert.ToString(_wp.rotationdir);
            txtwpgimblemode.Text   = Convert.ToString(_wp.gimblemode);
            txtgimblepitch.Text    = Convert.ToString(_wp.gimblepitch);
            trkHeading.Value       = Convert.ToInt16(_wp.head);
            trkCurveSize.Value     = Convert.ToInt16(_wp.curvesize);
            _wp.selected           = true;

            _gmap.ReDrawgMap();
        }
        private void cmbActionsList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = cmbActionsList.SelectedIndex;

            Models.Action action = _wpg.ActionAt(index);
            string        name   = action.name;

            int[,] actions        = action.actions;
            txtNewActionName.Text = name;
            txtActionID.Text      = Convert.ToString(action.internal_id);

            cmbAction1.SelectedIndex  = actions[0, 0] + 1;
            txtActionParam1.Text      = Convert.ToString(actions[0, 1]);
            cmbAction2.SelectedIndex  = actions[1, 0] + 1;
            txtActionParam2.Text      = Convert.ToString(actions[1, 1]);
            cmbAction3.SelectedIndex  = actions[2, 0] + 1;
            txtActionParam3.Text      = Convert.ToString(actions[2, 1]);
            cmbAction4.SelectedIndex  = actions[3, 0] + 1;
            txtActionParam4.Text      = Convert.ToString(actions[3, 1]);
            cmbAction5.SelectedIndex  = actions[4, 0] + 1;
            txtActionParam5.Text      = Convert.ToString(actions[4, 1]);
            cmbAction6.SelectedIndex  = actions[5, 0] + 1;
            txtActionParam6.Text      = Convert.ToString(actions[5, 1]);
            cmbAction7.SelectedIndex  = actions[6, 0] + 1;
            txtActionParam7.Text      = Convert.ToString(actions[6, 1]);
            cmbAction8.SelectedIndex  = actions[7, 0] + 1;
            txtActionParam8.Text      = Convert.ToString(actions[7, 1]);
            cmbAction9.SelectedIndex  = actions[8, 0] + 1;
            txtActionParam9.Text      = Convert.ToString(actions[8, 1]);
            cmbAction10.SelectedIndex = actions[9, 0] + 1;
            txtActionParam10.Text     = Convert.ToString(actions[9, 1]);
            cmbAction11.SelectedIndex = actions[10, 0] + 1;
            txtActionParam11.Text     = Convert.ToString(actions[10, 1]);
            cmbAction12.SelectedIndex = actions[11, 0] + 1;
            txtActionParam12.Text     = Convert.ToString(actions[11, 1]);
            cmbAction13.SelectedIndex = actions[12, 0] + 1;
            txtActionParam13.Text     = Convert.ToString(actions[12, 1]);
            cmbAction14.SelectedIndex = actions[13, 0] + 1;
            txtActionParam14.Text     = Convert.ToString(actions[13, 1]);
            cmbAction15.SelectedIndex = actions[14, 0] + 1;
            txtActionParam15.Text     = Convert.ToString(actions[14, 1]);
        }
        private void btnSaveAction_Click(object sender, EventArgs e)
        {
            int[,] actions = new int[15, 2];

            actions[0, 0]  = cmbAction1.SelectedIndex - 1;
            actions[0, 1]  = Convert.ToInt16(txtActionParam1.Text);
            actions[1, 0]  = cmbAction2.SelectedIndex - 1;
            actions[1, 1]  = Convert.ToInt16(txtActionParam2.Text);
            actions[2, 0]  = cmbAction3.SelectedIndex - 1;
            actions[2, 1]  = Convert.ToInt16(txtActionParam3.Text);
            actions[3, 0]  = cmbAction4.SelectedIndex - 1;
            actions[3, 1]  = Convert.ToInt16(txtActionParam4.Text);
            actions[4, 0]  = cmbAction5.SelectedIndex - 1;
            actions[4, 1]  = Convert.ToInt16(txtActionParam5.Text);
            actions[5, 0]  = cmbAction6.SelectedIndex - 1;
            actions[5, 1]  = Convert.ToInt16(txtActionParam6.Text);
            actions[6, 0]  = cmbAction7.SelectedIndex - 1;
            actions[6, 1]  = Convert.ToInt16(txtActionParam7.Text);
            actions[7, 0]  = cmbAction8.SelectedIndex - 1;
            actions[7, 1]  = Convert.ToInt16(txtActionParam8.Text);
            actions[8, 0]  = cmbAction9.SelectedIndex - 1;
            actions[8, 1]  = Convert.ToInt16(txtActionParam9.Text);
            actions[9, 0]  = cmbAction10.SelectedIndex - 1;
            actions[9, 1]  = Convert.ToInt16(txtActionParam10.Text);
            actions[10, 0] = cmbAction11.SelectedIndex - 1;
            actions[10, 1] = Convert.ToInt16(txtActionParam11.Text);
            actions[11, 0] = cmbAction12.SelectedIndex - 1;
            actions[11, 1] = Convert.ToInt16(txtActionParam12.Text);
            actions[12, 0] = cmbAction13.SelectedIndex - 1;
            actions[12, 1] = Convert.ToInt16(txtActionParam13.Text);
            actions[13, 0] = cmbAction14.SelectedIndex - 1;
            actions[13, 1] = Convert.ToInt16(txtActionParam14.Text);
            actions[14, 0] = cmbAction15.SelectedIndex - 1;
            actions[14, 1] = Convert.ToInt16(txtActionParam15.Text);

            Models.Action action = new Models.Action();
            action.name    = txtNewActionName.Text;
            action.actions = actions;
            _wpg.AddAction(action);
            Update_Actioncmb();
        }
        private void btnApplyAction_Click(object sender, EventArgs e)
        {
            string text;
            // Get action to Apply
            int index = cmbActionsWaypoints.SelectedIndex;

            if (index == -1)
            {
                MessageBox.Show("No Action Selected ...", "Apply Actions");
                return;
            }

            LinkedList <WayPoints> waypoints = _path.waypoints;

            int wpcount = waypoints.Count();

            // Get start and End waypoints

            int  wp_start = Convert.ToInt16(txtWPStart.Text);
            int  wp_end   = Convert.ToInt16(txtWPEnd.Text);
            bool err      = false;

            if (wp_start < 0 | wp_end < 0)
            {
                err = true;
            }
            if (wp_start > wpcount - 1 | wp_end > wpcount - 1)
            {
                err = true;
            }
            if (wp_start > wp_end & wp_end != 0)
            {
                err = true;
            }
            if (err)
            {
                text = "Error in start and end Way point.\n";
                MessageBox.Show(text, "Apply Actions");
                return;
            }

            Models.Action action = _wpg.ActionAt(index);
            string        name   = action.name;

            int[,] actions = action.actions;

            LinkedListNode <WayPoints> node = waypoints.First;
            LinkedListNode <WayPoints> nextnode;
            int count = 0;

            while (node != null)
            {
                nextnode = node.Next;
                if (count >= wp_start & count <= wp_end)
                {
                    WayPoints wppoint = new WayPoints();
                    wppoint.lat         = node.Value.lat;
                    wppoint.lon         = node.Value.lon;
                    wppoint.alt         = node.Value.alt;
                    wppoint.head        = node.Value.head;
                    wppoint.curvesize   = node.Value.curvesize;
                    wppoint.rotationdir = node.Value.rotationdir;
                    wppoint.gimblemode  = node.Value.gimblemode;
                    wppoint.gimblepitch = node.Value.gimblepitch;
                    wppoint.actions     = actions;
                    waypoints.AddBefore(node, wppoint);
                    waypoints.Remove(node);
                }
                count++;
                node = nextnode;
            }

            // Clear for next round

            txtWPStart.Text = "0";
            txtWPEnd.Text   = "0";
            cmbActionsWaypoints.SelectedIndex = 0;

            // Redo dgv

            //Globals.ActionWaypoint_Handler = false;
            dgvActionsWaypoints.Rows.Clear();
            //Globals.ActionWaypoint_Handler = true;
            int wp_count = waypoints.Count;

            count = 0;
            int path_wcount = waypoints.Count();

            while (count < path_wcount)
            {
                double lat         = waypoints.ElementAt(count).lat;
                double lon         = waypoints.ElementAt(count).lon;
                double alt         = waypoints.ElementAt(count).alt;
                double head        = waypoints.ElementAt(count).head;
                int    gimblemode  = waypoints.ElementAt(count).gimblemode;
                double gimblepitch = waypoints.ElementAt(count).gimblepitch;
                double curvesize   = waypoints.ElementAt(count).curvesize;
                double rotdir      = waypoints.ElementAt(count).rotationdir;
                int[,] wpactions = waypoints.ElementAt(count).actions;
                if (head < 0.0)
                {
                    head = head + 360.0;
                }
                dgvActionsWaypoints.Rows.Add(count, Convert.ToString(lat), Convert.ToString(lon), Convert.ToString(alt), Convert.ToString(head),
                                             Convert.ToString(curvesize), Convert.ToString(rotdir), Convert.ToString(gimblemode), Convert.ToString(gimblepitch)
                                             , Convert.ToString(wpactions[0, 0]), Convert.ToString(wpactions[0, 1])
                                             , Convert.ToString(wpactions[1, 0]), Convert.ToString(wpactions[1, 1])
                                             , Convert.ToString(wpactions[2, 0]), Convert.ToString(wpactions[2, 1])
                                             , Convert.ToString(wpactions[3, 0]), Convert.ToString(wpactions[3, 1])
                                             );
                count++;
            }
        }