Exemplo n.º 1
0
 private static double getDragRadius(GCodeMotion entity)
 {
     if (!Properties.Settings.Default.importGCDragKnifePercentEnable)
     {
         return((double)Properties.Settings.Default.importGCDragKnifeLength);
     }
     else
     {
         double useZ = (double)Properties.Settings.Default.importGCZDown;
         if (graphicInformation.OptionZFromWidth)
         {
             useZ = Graphic2GCode.calculateZFromRange(graphicInformation.PenWidthMin, graphicInformation.PenWidthMax, entity.Depth);
         }
         return(Math.Abs(useZ * (double)Properties.Settings.Default.importGCDragKnifePercent / 100));
     }
 }
Exemplo n.º 2
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            saveSettings();
            gcode.setup(false);                                         // load defaults from setup-tab
            gcode.gcodeXYFeed       = (float)nUDToolFeedXY.Value;       // override devault values
            gcode.gcodeZFeed        = (float)nUDToolFeedZ.Value;        // override devault values
            gcode.gcodeSpindleSpeed = (float)nUDToolSpindleSpeed.Value; // override devault values
            gcode.gcodeZDown        = (float)nUDImportGCZDown.Value;
            gcodeTangEnable         = Properties.Settings.Default.importGCTangentialEnable;

            Logger.Debug("Create GCode {0}", gcode.getSettings());

            gcodeString.Clear();

            gcode.Tool(gcodeString, tprop.toolnr, tprop.name);
            //       if (!Properties.Settings.Default.importGCSpindleToggle) gcode.SpindleOn(gcodeString, "Start");

            float x, y, rShape, d, dTool, overlap, rTool, zStep;
            float zStart = 0;

            x       = (float)nUDShapeX.Value;
            y       = (float)nUDShapeY.Value;
            rShape  = (float)nUDShapeR.Value;
            d       = 2 * rShape;
            dTool   = (float)nUDToolDiameter.Value;              // tool diameter;
            overlap = dTool * (float)nUDToolOverlap.Value / 100; // tool overlap
            if (rBToolpath1.Checked)
            {
                dTool = 0;
            }                                                   // engrave
            if (rBToolpath3.Checked)
            {
                dTool = -dTool;
            }                                                   // outside
            rTool = dTool / 2;                                  // tool radius

            int   counter = 0, safety = 100;
            int   zStepCount = 0;
            float dx = 0, dy = 0, rDelta = 0;
            int   passCount   = 0;
            int   figureCount = 1;

            gcode.jobStart(gcodeString, "StartJob");
            //    gcode.PenUp(gcodeString);

            bool inOneStep = (nUDToolZStep.Value >= -nUDImportGCZDown.Value);

            gcode.Comment(gcodeString, xmlMarker.figureStart + " Id=\"" + figureCount.ToString() + "\" >");
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            if (rBShape1.Checked)                               // rectangle
            {
                getOffset(x, y);
                offsetX -= rTool; offsetY -= rTool;
                x       += dTool; y += dTool;                   // width +/- tool diameter (outline / inline)
                zStep    = zStart;
                while (zStep > (float)nUDImportGCZDown.Value)   // nUDImportGCZDown.Value e.g. -2
                {
                    zStep -= (float)nUDToolZStep.Value;         // nUDToolZStep.Value e.g.  0.5
                    if (zStep < (float)nUDImportGCZDown.Value)
                    {
                        zStep = (float)nUDImportGCZDown.Value;
                    }

                    if ((overlap > x / 2) || (overlap > y / 2))
                    {
                        overlap = (float)(Math.Min(x, y) / 2.1);
                    }

                    //if ((zStepCount++ == 0) || !cBNoZUp.Checked)    // move up the 1st time
                    if (!(zStepCount++ == 0) && !cBNoZUp.Checked)     // move up the 1st time
                    {
                        gcode.PenUp(gcodeString);
                        if (!inOneStep)
                        {
                            gcode.Comment(gcodeString, xmlMarker.passEnd + ">");             //+ "  " + passCount.ToString() + ">");
                        }
                    }
                    passCount++;

                    if (gcodeTangEnable)
                    {
                        gcode.setTangential(gcodeString, 90, true);
                    }

                    if (!inOneStep)
                    {
                        gcode.Comment(gcodeString, string.Format("{0} Nr=\"{1}\" step=\"{2:0.000}\" final=\"{3:0.000}\">", xmlMarker.passStart, passCount, zStep, nUDImportGCZDown.Value));
                    }

                    if (cBToolpathPocket.Checked)
                    {
                        gcode.MoveToRapid(gcodeString, offsetX + overlap, offsetY + overlap, "");
                    }
                    else
                    {
                        gcode.MoveToRapid(gcodeString, offsetX, offsetY, "");
                    }
                    gcode.gcodeZDown = zStep;                               // adapt Z-deepth
                    gcode.PenDown(gcodeString);
                    if (cBToolpathPocket.Checked)                           // 1st pocket
                    {
                        if ((x > Math.Abs(dTool)) && (y > Math.Abs(dTool))) // wide enough for pocket
                        {
                            dx = overlap; dy = overlap;
                            while (((dx < x / 2) && (dy < y / 2)) && (counter++ < safety))
                            {
                                makeRect(offsetX + dx, offsetY + dy, offsetX + x - dx, offsetY + y - dy, 0, false);  // rectangle clockwise
                                dx += overlap; dy += overlap;
                                if ((dx < x / 2) && (dy < y / 2))
                                {
                                    gcode.MoveTo(gcodeString, offsetX + dx, offsetY + dy, "Pocket");
                                }
                            }
                            if (cBNoZUp.Checked)
                            {
                                gcode.MoveTo(gcodeString, offsetX, offsetY, "Pocket finish");
                            }
                            else
                            {
                                gcode.PenUp(gcodeString, "Pocket finish");
                                gcode.MoveToRapid(gcodeString, offsetX, offsetY, "Pocket finish");
                                gcode.PenDown(gcodeString);
                            }
                        }
                    }

                    makeRect(offsetX, offsetY, offsetX + x, offsetY + y, 0, true);  // final rectangle clockwise
                }
                gcode.PenUp(gcodeString);
                if (!inOneStep)
                {
                    gcode.Comment(gcodeString, xmlMarker.passEnd + ">");             //+ " " + passCount.ToString() + ">");
                }
            }
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            else if (rBShape2.Checked)           // rectangle with round edge
            {
                getOffset(x, y);
                offsetX -= rTool; offsetY -= rTool;
                x       += dTool; y += dTool;

                if ((overlap > x / 2) || (overlap > y / 2))
                {
                    overlap = (float)(Math.Min(x, y) / 2.1);
                }
                //                   gcode.Move(gcodeString, 0, offsetX, offsetY + r, false, "");
                zStep = zStart;
                while (zStep > (float)nUDImportGCZDown.Value)
                {
                    zStep -= (float)nUDToolZStep.Value;
                    if (zStep < (float)nUDImportGCZDown.Value)
                    {
                        zStep = (float)nUDImportGCZDown.Value;
                    }

                    //                    if ((zStepCount++ == 0) || !cBNoZUp.Checked)    // move up the 1st time
                    if (!(zStepCount++ == 0) && !cBNoZUp.Checked)     // move up the 1st time
                    {
                        gcode.PenUp(gcodeString);
                        if (!inOneStep)
                        {
                            gcode.Comment(gcodeString, xmlMarker.passEnd + ">");             //+ " " + passCount.ToString() + ">");
                        }
                    }
                    passCount++;

                    if (gcodeTangEnable)
                    {
                        gcode.setTangential(gcodeString, 90, true);
                    }

                    if (!inOneStep)
                    {
                        gcode.Comment(gcodeString, string.Format("{0} Nr=\"{1}\" step=\"{2:0.000}\" final=\"{3:0.000}\">", xmlMarker.passStart, passCount, zStep, nUDImportGCZDown.Value));
                    }

                    if (cBToolpathPocket.Checked)
                    {
                        gcode.MoveToRapid(gcodeString, offsetX + overlap, offsetY + rShape, "");
                    }
                    else
                    {
                        gcode.MoveToRapid(gcodeString, offsetX, offsetY + rShape, "");
                    }
                    gcode.gcodeZDown = zStep;               // adapt Z-deepth
                    gcode.PenDown(gcodeString);
                    if (cBToolpathPocket.Checked)
                    {
                        dx = overlap; dy = overlap; rDelta = rShape - overlap;
                        while (((dx < x / 2) && (dy < y / 2)) && (counter++ < safety))
                        {
                            makeRect(offsetX + dx, offsetY + dy, offsetX + x - dx, offsetY + y - dy, rDelta, false);  // rectangle clockwise
                            dx += overlap; dy += overlap; rDelta -= overlap;
                            if (dx > x / 2)
                            {
                                dx = x / 2;
                            }
                            if (dy > x / 2)
                            {
                                dy = y / 2;
                            }
                            if (rDelta < 0)
                            {
                                rDelta = 0;
                            }
                            if ((dx < x / 2) && (dy < y / 2))
                            {
                                gcode.MoveTo(gcodeString, offsetX + dx, offsetY + dy + rDelta, "");
                            }
                        }
                        if (cBNoZUp.Checked)
                        {
                            gcode.MoveTo(gcodeString, offsetX, offsetY + rShape, "");
                        }
                        else
                        {
                            gcode.PenUp(gcodeString);
                            gcode.MoveToRapid(gcodeString, offsetX, offsetY + rShape, "");
                            gcode.PenDown(gcodeString);
                        }
                    }
                    makeRect(offsetX, offsetY, offsetX + x, offsetY + y, rShape, true);  // rectangle clockwise
                }
                gcode.PenUp(gcodeString);
                if (!inOneStep)
                {
                    gcode.Comment(gcodeString, xmlMarker.passEnd + ">");             //+ " " + passCount.ToString() + ">");
                }
            }
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            else if (rBShape3.Checked)           // circle
            {
                getOffset(d, d);
                offsetX -= rTool; offsetY -= rTool;
                rShape  += rTool;                   // take care of tool diameter if set

                if (overlap > rShape)
                {
                    overlap = (float)(rShape / 2.1);
                }

                zStep = zStart;
                while (zStep > (float)nUDImportGCZDown.Value)
                {
                    //if ((zStepCount++ == 0) || !cBNoZUp.Checked)    // move up the 1st time
                    if (!(zStepCount++ == 0) && !cBNoZUp.Checked)     // move up the 1st time
                    {
                        gcode.PenUp(gcodeString);
                        if (!inOneStep)
                        {
                            gcode.Comment(gcodeString, xmlMarker.passEnd + ">");             //+ " " + passCount.ToString() + ">");
                        }
                    }
                    passCount++;

                    if (gcodeTangEnable)
                    {
                        gcode.setTangential(gcodeString, 90, true);
                    }


                    if (!inOneStep)
                    {
                        gcode.Comment(gcodeString, string.Format("{0} Nr=\"{1}\" step=\"{2:0.000}\" final=\"{3:0.000}\">", xmlMarker.passStart, passCount, zStep, nUDImportGCZDown.Value));
                    }

                    if (cBToolpathPocket.Checked)
                    {
                        gcode.MoveToRapid(gcodeString, offsetX + rShape - overlap, offsetY + rShape, "");
                    }
                    else
                    {
                        gcode.MoveToRapid(gcodeString, offsetX, offsetY + rShape, "");
                    }
                    zStep -= (float)nUDToolZStep.Value;
                    if (zStep < (float)nUDImportGCZDown.Value)
                    {
                        zStep = (float)nUDImportGCZDown.Value;
                    }
                    gcode.gcodeZDown = zStep;               // adapt Z-deepth
                    gcode.PenDown(gcodeString);
                    rDelta  = overlap;
                    counter = 0;
                    if ((cBToolpathPocket.Checked) && (rShape > 2 * rTool))
                    {
                        while ((rDelta < rShape) && (counter++ < safety))
                        {
                            gcode.setTangential(gcodeString, -270, false);  //
                            gcode.Arc(gcodeString, 2, offsetX + rShape - rDelta, offsetY + rShape, rDelta, 0, "");
                            rDelta += overlap;
                            if (rDelta < rShape)
                            {
                                gcode.MoveTo(gcodeString, offsetX + rShape - rDelta, offsetY + rShape, "");
                            }
                        }
                        gcode.MoveTo(gcodeString, offsetX, offsetY + rShape, "");
                    }
                    gcode.setTangential(gcodeString, -270, false);  //
                    gcode.Arc(gcodeString, 2, offsetX, offsetY + rShape, rShape, 0, "");
                }
                gcode.PenUp(gcodeString);
                if (!inOneStep)
                {
                    gcode.Comment(gcodeString, xmlMarker.passEnd + ">");             //+ " " + passCount.ToString() + ">");
                }
            }
            gcode.Comment(gcodeString, Graphic2GCode.SetFigureEnd(figureCount));

            gcode.jobEnd(gcodeString, "EndJob");      // Spindle / laser off
            //    if (Properties.Settings.Default.importGCZEnable)
            //         gcode.SpindleOff(gcodeString, "Finish - Spindle off");

            string header = gcode.GetHeader("Simple Shape");
            string footer = gcode.GetFooter();

            gcodeString.Replace(',', '.');
            shapegcode = header + gcodeString.ToString() + footer;
        }