private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lastSelectedIndex >= 0)
     {
         if (Nodes[lastSelectedIndex].status == DrillNode.DrillNodeStatus.Selected)
         {
             Nodes[lastSelectedIndex].status = lastSelectedStatus;
         }
     }
     lastSelectedStatus = Nodes[listBox1.SelectedIndex].status;
     Nodes[listBox1.SelectedIndex].status = DrillNode.DrillNodeStatus.Selected;
     lastSelectedIndex = listBox1.SelectedIndex;
     UpdateNodeColors();
     OutputLabel.Refresh();
 }
        private void RebuildListBoxAndViewerFromNodes()
        {
            listBox1.Items.Clear();
            lastSelectedStatus  = DrillNode.DrillNodeStatus.Idle;
            lastSelectedIndex   = -1;
            nodeViewer.Elements = new List <IViewerElements>
            {
                drawingPageBox,
                CNCTableBox,
                moveTarget,
                drillCrossHair,
                cursorCrossHair
            };

            if ((Nodes != null) && (Nodes.Count > 0))
            {
                for (var i = 0; i < Nodes.Count; i++)
                {
                    nodeViewer.Elements.Add(new Node(Nodes[i].location, NodeDiameter, Nodes[i].Color, i));
                    listBox1.Items.Add(Nodes[i].Location);
                    Nodes[i].ID = i;
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            ExtLog.Logger = logger1;

            if (ApplicationDeployment.IsNetworkDeployed)
            {
                Text += ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(4);
            }
            else
            {
                Text += Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }

            #region View initialization

            cursorCrossHair      = new CrossHair(0, 0, Color.Blue);
            drillCrossHair       = new CrossHair(0, 0, Color.Red);
            CNCTableBox          = new Box(0, 0, 6, 6, Color.LightGray);
            drawingPageBox       = new Box(0, 0, 8.5f, 11, Color.GhostWhite);
            moveTarget           = new Cross(0, 0, Color.Yellow);
            nodeViewer           = new Viewer(OutputLabel, new PointF(11.0f, 11.0f));
            nodeViewer.OnSelect += OnSelect;
            lastSelectedStatus   = DrillNode.DrillNodeStatus.Idle;
            lastSelectedIndex    = -1;
            RebuildListBoxAndViewerFromNodes();

            #endregion

            #region UI Initialization

            AxisOffsetComboBox.SelectedIndex = 0;
            AxisOffsetCount       = 1;
            XScaleTextBox.Text    = GlobalProperties.X_Scale.ToString("D");
            YScaleTextBox.Text    = GlobalProperties.Y_Scale.ToString("D");
            XBacklastTextbox.Text = GlobalProperties.X_Backlash.ToString("D");
            YBacklastTextbox.Text = GlobalProperties.Y_Backlash.ToString("D");

            #endregion

            #region USB interface initialization

            USBdevicesComboBox.Items.Clear();

            var USBDevices = USB.GetDevicesList();
            if (USBDevices.Count > 0)
            {
                foreach (var uDev in USBDevices)
                {
                    USBdevicesComboBox.Items.Add(uDev);
                }
                USBdevicesComboBox.SelectedIndex = 0;
            }
            else
            {
                USBdevicesComboBox.Items.Add("[None]");
                USB = new USB_Control_Emulator();
            }

            USB.OnProgress      = OnProgress;
            USB.OnMove          = onMove;
            USB.OnMoveCompleted = OnMoveCompleted;

            USB.X_StepMotor_Driver_Enable = checkBoxX.Checked;
            USB.Y_StepMotor_Driver_Enable = checkBoxY.Checked;
            USB.TQA_Driver_Enable         = checkBoxT.Checked;
            USB.Cycle_Drill = checkBoxD.Checked;

            USB.Inhibit_Backlash_Compensation = IgnoreBacklashBox.Checked;

            TaskRunner = new TaskContainer(this, USB, taskDialog)
            {
                UpdateNodes = OnUpdateNode
            };

            #endregion
        }
        private void LoadFileButton_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (dtypeDialog.ShowDialog() == DialogResult.OK)
                {
                    if (File.Exists(openFileDialog1.FileName))
                    {
                        ExtLog.AddLine("Opening File: " + openFileDialog1.FileName);

                        var loader = (INodeLoader)null;
                        if (openFileDialog1.FileName.ToUpperInvariant().EndsWith(".VDX"))
                        {
                            loader = new VDXLoader();
                        }
                        else if (openFileDialog1.FileName.ToUpperInvariant().EndsWith(".SVG"))
                        {
                            loader = new SVGLoader();
                        }
                        else
                        {
                            ExtLog.AddLine("File Type not supported.");
                        }

                        if (loader != null)
                        {
                            loader.PageWidth  = 11.0f;
                            loader.PageHeight = 11.0f;
                            loader.DrillNodes = new List <DrillNode>();

                            var dresult = dtypeDialog.DrawingConfig;
                            loader.Load(openFileDialog1.FileName, dresult);

                            Nodes = loader.DrillNodes;

                            if (dresult.reset_origin)
                            {
                                var leftmost = loader.PageWidth;
                                var topmost  = loader.PageHeight;

                                for (var i = 0; i < Nodes.Count; i++)
                                {
                                    if (Nodes[i].location.X < leftmost)
                                    {
                                        leftmost = Nodes[i].location.X;
                                    }
                                    if (Nodes[i].location.Y < topmost)
                                    {
                                        topmost = Nodes[i].location.Y;
                                    }
                                }

                                XoriginTextbox.Text = (leftmost - dresult.origin_x).ToString("F4");
                                YoriginTextbox.Text = (topmost - dresult.origin_y).ToString("F4");
                                OffsetOriginBtton_Click(sender, e);
                            }

                            ExtLog.AddLine(Nodes.Count.ToString("D") + " Nodes loaded.");
                            ExtLog.AddLine("Page Width: " + loader.PageWidth.ToString("F1"));
                            ExtLog.AddLine("Page Height: " + loader.PageHeight.ToString("F1"));

                            drawingPageBox     = new Box(0, 0, loader.PageWidth, loader.PageHeight, Color.GhostWhite);
                            lastSelectedStatus = DrillNode.DrillNodeStatus.Idle;
                            RebuildListBoxAndViewerFromNodes();
                            lastSelectedIndex = -1;
                        }
                    }
                }
            }
        }
 private void updateNodeCallback(int nodeIndex, DrillNode.DrillNodeStatus newStatus)
 {
     Nodes[nodeIndex].status = newStatus;
     UpdateNodeColors();
 }
 public void OnUpdateNode(int nodeIndex, DrillNode.DrillNodeStatus newStatus)
 {
     Invoke(UpdateNodeCallback, new object[] { nodeIndex, newStatus });
 }