예제 #1
0
        private void btnGCode_Click(object sender, EventArgs e)
        {
            if ((Map != null) && (cntReceived == cntSent))
            {
                Vector2 tmp;
                //          double z;
                float gcodeZFeed = (float)Properties.Settings.Default.importGCZFeed;
                float gcodeZUp   = (float)Properties.Settings.Default.importGCZUp;

                scanCode = new StringBuilder();
                StringBuilder tmpCode = new StringBuilder();
                tmp = Map.GetCoordinates(0, 0);

                tmpCode.AppendFormat("G90 G0 F{0} Z{1}\r\n", gcode.frmtNum(gcodeZFeed), gcode.frmtNum(gcodeZUp));
                tmpCode.AppendFormat("X{0} Y{1}\r\n", gcode.frmtNum((float)tmp.X), gcode.frmtNum((float)tmp.Y));
                tmpCode.AppendFormat("G1\r\n");

                for (int iy = 0; iy < Map.SizeY; iy++)
                {
                    for (int ix = 0; ix < Map.SizeX; ix++)
                    {
                        moveXYZ(tmpCode, ix, iy);
                    }
                    if (iy < Map.SizeY - 1)
                    {
                        iy++;
                        for (int ix = Map.SizeX - 1; ix >= 0; ix--)
                        {
                            moveXYZ(tmpCode, ix, iy);
                        }
                    }
                }
                tmpCode.AppendFormat("G0 Z{0}\r\n", gcode.frmtNum(gcodeZUp));
                tmp = Map.GetCoordinates(0, 0);
                tmpCode.AppendFormat("G0 X{0} Y{1}\r\n", gcode.frmtNum((float)tmp.X), gcode.frmtNum((float)tmp.Y));

                scanCode.AppendFormat("{0}", gcode.GetHeader("Height Map"));
                scanCode.Append(tmpCode);
                scanCode.AppendFormat("{0}", gcode.GetFooter());
            }
        }
예제 #2
0
        private void btnStartHeightScan_Click(object sender, EventArgs e)
        {
            enableControls(scanStarted);
            if (!scanStarted)
            {
                isMapOk  = false;
                timeInit = DateTime.UtcNow;
                elapsed  = TimeSpan.Zero;
                btnStartHeightScan.Text = "STOP scanning Height Map";
                decimal x1, x2, y1, y2;
                x1 = Math.Min(nUDX1.Value, nUDX2.Value);
                x2 = Math.Max(nUDX1.Value, nUDX2.Value);
                y1 = Math.Min(nUDY1.Value, nUDY2.Value);
                y2 = Math.Max(nUDY1.Value, nUDY2.Value);
                if (x1 == x2)
                {
                    x2 = x1 + 10;
                }
                if (y1 == y2)
                {
                    y2 = y1 + 10;
                }
                nUDX1.Value = x1; nUDX2.Value = x2; nUDY1.Value = y1; nUDY2.Value = y2;
                decimal stepX = (x2 - x1) / (nUDGridX.Value - 1);
                decimal stepY = (y2 - y1) / (nUDGridY.Value - 1);
                cntSent           = 0; cntReceived = 0;
                gcode.reduceGCode = true;   // reduce number format to #.# in gcode.frmtNum()

                Map      = new HeightMap((double)nUDGridX.Value, new Vector2((double)x1, (double)y1), new Vector2((double)x2, (double)y2));
                MapIndex = new List <Point>();

                lblXDim.Text = string.Format("X Min:{0} Max:{1} Step:{2}", Map.Min.X, Map.Max.X, Map.SizeX);
                lblYDim.Text = string.Format("Y Min:{0} Max:{1} Step:{2}", Map.Min.Y, Map.Max.Y, Map.SizeY);

                textBox1.Clear();
                textBox1.Text += Map.SizeX.ToString() + "  " + Map.SizeY.ToString();
                int pixX, pixY;
                BMPsizeX     = 240;
                BMPsizeY     = Map.SizeY * BMPsizeX / Map.SizeX;
                heightMapBMP = new Bitmap(BMPsizeX, BMPsizeY);
                using (Graphics graph = Graphics.FromImage(heightMapBMP))
                {
                    Rectangle ImageSize = new Rectangle(0, 0, BMPsizeX, BMPsizeY);
                    graph.FillRectangle(Brushes.White, ImageSize);
                }
                Vector2 tmp;

                scanCode = new StringBuilder();
                scanCode.AppendFormat("G90F{0}\r\n", gcode.frmtNum((float)nUDProbeSpeed.Value));
                for (int iy = 0; iy < Map.SizeY; iy++)
                {
                    tmp = Map.GetCoordinates(0, iy);
                    scanCode.AppendFormat("G0Y{0}\r\n", gcode.frmtNum((float)tmp.Y));
                    pixY = iy * BMPsizeY / Map.SizeY;
                    for (int ix = 0; ix < Map.SizeX; ix++)
                    {
                        pixX = ix * BMPsizeX / Map.SizeX;
                        heightMapBMP.SetPixel(pixX, pixY, Color.FromArgb(255, 00, 00));
                        tmp = Map.GetCoordinates(ix, iy);
                        MapIndex.Add(new Point(ix, iy));
                        scanCode.AppendFormat("G0Z{0}\r\n", gcode.frmtNum((float)nUDProbeUp.Value));
                        scanCode.AppendFormat("X{0}\r\n", gcode.frmtNum((float)tmp.X));
                        scanCode.AppendFormat("G38.3Z{0}\r\n", gcode.frmtNum((float)nUDProbeDown.Value));
                        cntSent++;
                    }
                    if (iy < Map.SizeY - 1)
                    {
                        iy++;
                        tmp = Map.GetCoordinates(0, iy);
                        scanCode.AppendFormat("G0Y{0}\r\n", gcode.frmtNum((float)tmp.Y));
                        for (int ix = Map.SizeX - 1; ix >= 0; ix--)
                        {
                            pixX = ix * BMPsizeX / Map.SizeX;
                            heightMapBMP.SetPixel(pixX, pixY, Color.FromArgb(100, 100, 100));
                            tmp = Map.GetCoordinates(ix, iy);
                            MapIndex.Add(new Point(ix, iy));
                            scanCode.AppendFormat("G0Z{0}\r\n", gcode.frmtNum((float)nUDProbeUp.Value));
                            scanCode.AppendFormat("X{0}\r\n", gcode.frmtNum((float)tmp.X));
                            scanCode.AppendFormat("G38.3Z{0}\r\n", gcode.frmtNum((float)nUDProbeDown.Value));
                            cntSent++;
                        }
                    }
                }
                scanCode.AppendFormat("G0 Z{0}\r\n", gcode.frmtNum((float)nUDProbeUp.Value));
                tmp = Map.GetCoordinates(0, 0);
                scanCode.AppendFormat("G0 X{0} Y{1}\r\n", gcode.frmtNum((float)tmp.X), gcode.frmtNum((float)tmp.Y));

                textBox1.Text       += "Code sent\r\n";// scanCode.ToString();
                progressBar1.Maximum = cntSent;
                lblProgress.Text     = string.Format("{0}%", (100 * cntReceived / progressBar1.Maximum));
                pictureBox1.Image    = new Bitmap(heightMapBMP);
                pictureBox1.Refresh();
            }
            else
            {
                btnStartHeightScan.Text = "Generate Height Map";
            }
            scanStarted = !scanStarted;
        }