Ejemplo n.º 1
0
        private void setToolChangeCoordinates(int cmdTNr, string line = "")
        {
            toolProp toolInfo = toolTable.getToolProperties(cmdTNr);

            gcodeVariable["TOAN"] = cmdTNr;
            if (toolInfo.toolnr != cmdTNr)
            {
                gcodeVariable["TOAX"] = gcodeVariable["TOAY"] = gcodeVariable["TOAZ"] = gcodeVariable["TOAA"] = 0;
                if (cBStatus1.Checked || cBStatus.Checked)
                {
                    addToLog("\r[Tool change: " + cmdTNr.ToString() + " no Information found! (" + line + ")]");
                }
            }
            else
            {   // get new values
                double tx, ty, tz, ta;
                gcodeVariable["TOAX"] = tx = (double)toolInfo.X + (double)Properties.Settings.Default.toolTableOffsetX;
                gcodeVariable["TOAY"] = ty = (double)toolInfo.Y + (double)Properties.Settings.Default.toolTableOffsetY;
                gcodeVariable["TOAZ"] = tz = (double)toolInfo.Z + (double)Properties.Settings.Default.toolTableOffsetZ;
                gcodeVariable["TOAA"] = ta = (double)toolInfo.A + (double)Properties.Settings.Default.toolTableOffsetA;
                string coord = string.Format("X:{0:0.0} Y:{1:0.0} Z:{2:0.0} A:{3:0.0}", tx, ty, tz, ta);
                if (cBStatus1.Checked || cBStatus.Checked)
                {
                    addToLog("\r[set tool coordinates " + cmdTNr.ToString() + " " + coord + "]");
                }
            }
        }
Ejemplo n.º 2
0
        public static void Init()
        {
            logFlags       = (uint)Properties.Settings.Default.importLoggerSettings;
            logEnable      = Properties.Settings.Default.guiExtendedLoggingEnabled && ((logFlags & (uint)LogEnable.Level3) > 0);
            logDetailed    = logEnable && ((logFlags & (uint)LogEnable.Detailed) > 0);
            logCoordinates = logEnable && ((logFlags & (uint)LogEnable.Coordinates) > 0);

            Logger.Trace("Init Graphic2GCode   loggerTrace:{0}", Convert.ToString(logFlags, 2));

            pauseBeforePath    = Properties.Settings.Default.importPauseElement;
            pauseBeforePenDown = Properties.Settings.Default.importPausePenDown;
            comments           = Properties.Settings.Default.importSVGAddComments;
            penIsDown          = false;

            gcodeString.Clear();
            finalGcodeString.Clear();

            PathCount          = 0;
            FigureEndTagWasSet = true;
            gcode.setup();                              // initialize GCode creation (get stored settings for export)
            pathInfo = new PathInformation();

            if (!Properties.Settings.Default.importGroupObjects)       // Load initial tool
            {
                toolProp tmpTool = toolTable.getToolProperties((int)Properties.Settings.Default.importGCToolDefNr);
                gcode.Tool(gcodeString, tmpTool.toolnr, tmpTool.name);    // add tool change commands (if enabled) and set XYFeed etc.
            }
        }
Ejemplo n.º 3
0
        private void cBTool_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tmp = cBTool.SelectedItem.ToString();

            if (tmp.IndexOf(")") > 0)
            {
                int tnr = int.Parse(tmp.Substring(0, tmp.IndexOf(")")));
                Properties.Settings.Default.importGCToolDefNr = tnr;
                if (cBToolSet.Checked)
                {
                    tprop = toolTable.getToolProperties(tnr);
                    Logger.Info("Tool dia:{0}, feedXY:{1}, finalZ:{2}, stepZ:{3}, feedZ:{4}, overlap:{5}, spindle:{6}", tprop.diameter, tprop.feedXY, tprop.finalZ, tprop.stepZ, tprop.feedZ, tprop.overlap, tprop.spindleSpeed);
                    try
                    {
                        checkSetValue(nUDToolDiameter, (decimal)tprop.diameter);
                        checkSetValue(nUDToolFeedXY, (decimal)tprop.feedXY);
                        checkSetValue(nUDImportGCZDown, (decimal)tprop.finalZ);
                        checkSetValue(nUDToolZStep, (decimal)Math.Abs(tprop.stepZ));
                        checkSetValue(nUDToolFeedZ, (decimal)tprop.feedZ);
                        checkSetValue(nUDToolOverlap, (decimal)tprop.overlap);
                        checkSetValue(nUDToolSpindleSpeed, (decimal)tprop.spindleSpeed);
                    }
                    catch (Exception err)
                    { Logger.Error(err, "Set numeric Up Downs"); }
                }
            }
        }
Ejemplo n.º 4
0
 public static toolProp getColorWidth(char find, double val, toolProp deflt)
 {
     Array.Sort <toolProp>(toolTableArray, (x, y) => x.toolnr.CompareTo(y.toolnr));    // sort by tool nr
     for (int i = 1; i < toolTableArray.Length; i++)
     {
         if (find == 'S')         // direct hit
         {
             if (val == toolTableArray[i].spindleSpeed)
             {
                 return(toolTableArray[i]);
             }
         }
         if (find == 'Z')         // direct hit
         {
             if (val == toolTableArray[i].finalZ)
             {
                 return(toolTableArray[i]);
             }
         }
         if (find == 'F')         // direct hit
         {
             if (val == toolTableArray[i].feedXY)
             {
                 return(toolTableArray[i]);
             }
         }
     }
     return(deflt);
 }
Ejemplo n.º 5
0
        public static toolProp setDefault()
        {
            toolProp tmp = new toolProp();

            tmp.X     = 0; tmp.Y = 0; tmp.Z = 0; tmp.diameter = 3; tmp.feedXY = 100; tmp.feedZ = 100;
            tmp.stepZ = -1; tmp.spindleSpeed = 1000; tmp.overlap = 100;
            return(tmp);
        }
Ejemplo n.º 6
0
      public static void Tool(StringBuilder gcodeString, int toolnr, string cmt = "")
      {
          string toolCmd = "";

          if (gcodeToolChange)                  // otherweise no command needed
          {
              if (gcodeZApply)
              {
                  gcode.SpindleOff(gcodeString, "Stop spindle - Option Z-Axis");
              }
              if (cmt.Length > 0)
              {
                  cmt = string.Format("({0})", cmt);
              }
              toolCmd = string.Format("T{0:D2} M{1} {2}", toolnr, frmtCode(6), cmt);
              if (gcodeToolChangeM0)
              {
                  gcodeString.AppendFormat("M0 ({0})\r\n", toolCmd);
              }
              else
              {
                  gcodeString.AppendFormat("{0}\r\n", toolCmd);
              }
              gcodeToolCounter++;
              gcodeLines++;
              gcodeToolText += string.Format("( {0}) ToolNr: {1:D2}, Name: {2})\r\n", gcodeToolCounter, toolnr, cmt);

              remainingC = (float)Properties.Settings.Default.importGCLineSegmentLength;

              toolProp toolInfo = toolTable.getToolProperties(toolnr);
              if (Properties.Settings.Default.importGCTTSSpeed)
              {
                  gcodeSpindleSpeed = toolInfo.spindleSpeed;
              }
              if (Properties.Settings.Default.importGCTTXYFeed)
              {
                  gcodeXYFeed = toolInfo.feedXY;
              }
              if (Properties.Settings.Default.importGCTTZFeed)
              {
                  gcodeZFeed = toolInfo.feedZ;
              }
              if (Properties.Settings.Default.importGCTTZDeepth)
              {
                  gcodeZDown = toolInfo.stepZ;
              }

              if (Properties.Settings.Default.importGCDragKnifePercentEnable)
              {
                  gcodeDragRadius = Math.Abs(gcodeZDown * (float)Properties.Settings.Default.importGCDragKnifePercent / 100);
              }

              if (gcodeZApply)
              {
                  gcode.SpindleOn(gcodeString, "Start spindle - Option Z-Axis");
              }
          }
      }
Ejemplo n.º 7
0
        public static void StartCode()
        {
            Logger.Trace("startCode()");
            pauseBeforePath    = Properties.Settings.Default.importPauseElement;
            pauseBeforePenDown = Properties.Settings.Default.importPausePenDown;
            groupObjects       = Properties.Settings.Default.importGroupObjects;     // DXF-Import group objects
            sortOption         = Properties.Settings.Default.importGroupSort;        // SVG-Import sort by tool
            sortInvert         = Properties.Settings.Default.importGroupSortInvert;
            gcodeUseSpindle    = Properties.Settings.Default.importGCZEnable;
            gcodeReduce        = Properties.Settings.Default.importRemoveShortMovesEnable;
            gcodeReduceVal     = (float)Properties.Settings.Default.importRemoveShortMovesLimit;
            gcodeTangEnable    = Properties.Settings.Default.importGCTangentialEnable;
            gcodeTangName      = Properties.Settings.Default.importGCTangentialAxis;
            gcodeTangTurn      = (double)Properties.Settings.Default.importGCTangentialTurn;
            comments           = Properties.Settings.Default.importSVGAddComments;
            lastSetGroup       = -1;
            penIsDown          = false;

            gcodeMath.resetAngles();
            posStartAngle = 0;

            isStartPathIsPending = false;

            gcodeStringIndex    = 0;
            gcodeStringIndexOld = -1;
            for (int i = 0; i < gcodeStringMax; i++)        // hold gcode snippes for later sorting
            {
                gcodeString[i] = new StringBuilder();
                gcodeString[i].Clear();
                gcodeDimension[i] = new Dimensions();
            }
            finalGcodeString.Clear();

            PathCount       = 0;
            PathToolNr      = 0;
            IsPathReduceOk  = false;
            IsPathAvoidG23  = false;
            IsPathFigureEnd = true;
            PathId          = "";
            PathName        = "";
            pathColor       = "";
            PathComment     = "";
            DocTitle        = "";
            DocDescription  = "";

            amountOfTools = toolTable.init();
            gcode.setup();           // initialize GCode creation (get stored settings for export)

            if (!groupObjects)       // Load initial tool
            {
                toolProp tmpTool = toolTable.getToolProperties((int)Properties.Settings.Default.importGCToolDefNr);
                gcode.Tool(gcodeString[gcodeStringIndex], tmpTool.toolnr, tmpTool.name);    // add tool change commands (if enabled) and set XYFeed etc.
            }
            else
            {
            }
        }
Ejemplo n.º 8
0
        public static toolProp setDefault()
        {
            toolProp tmp = new toolProp();

            tmp.X      = 0; tmp.Y = 0; tmp.Z = 0; tmp.A = 0; tmp.diameter = 3; tmp.feedXY = 1000; tmp.feedZ = 500;
            tmp.saveZ  = 2; tmp.finalZ = -1; tmp.stepZ = 1; tmp.spindleSpeed = 1000; tmp.overlap = 100; tmp.gcode = "";
            tmp.toolnr = 1;
            return(tmp);
        }
Ejemplo n.º 9
0
        private void btnToolUpdate_Click(object sender, EventArgs e)
        {
            int      toolCount = toolTable.init();
            toolProp tmpTool;

            cBTool.Items.Clear();
            for (int i = 1; i < toolCount; i++)
            {
                tmpTool = toolTable.getToolProperties(i);
                cBTool.Items.Add(i.ToString() + ") " + tmpTool.name);
            }
            cBTool.SelectedIndex = 0;
            tprop = toolTable.getToolProperties(1);
            cBTool_SelectedIndexChanged(sender, e);
        }
Ejemplo n.º 10
0
        private void cBTool_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tmp = cBTool.SelectedItem.ToString();

            if (tmp.IndexOf(")") > 0)
            {
                int tnr = int.Parse(tmp.Substring(0, tmp.IndexOf(")")));
                Properties.Settings.Default.importGCToolDefNr = tnr;
                if (cBToolSet.Checked)
                {
                    tprop = toolTable.getToolProperties(tnr);
                    nUDToolDiameter.Value     = (decimal)tprop.diameter;
                    nUDToolFeedXY.Value       = (decimal)tprop.feedXY;
                    nUDToolZStep.Value        = (decimal)Math.Abs(tprop.stepZ);
                    nUDToolFeedZ.Value        = (decimal)tprop.feedZ;
                    nUDToolOverlap.Value      = (decimal)tprop.overlap;
                    nUDToolSpindleSpeed.Value = (decimal)tprop.spindleSpeed;
                }
            }
        }
Ejemplo n.º 11
0
        public static toolProp findToolByFSZ(double valF, double valS, double valZ, toolProp deflt)
        {
            int tmpIndex = -1;

            Array.Sort <toolProp>(toolTableArray, (x, y) => x.toolnr.CompareTo(y.toolnr));    // sort by tool nr
            for (int i = 1; i < toolTableArray.Length; i++)
            {
                if (valF == toolTableArray[i].feedXY)
                {
                    tmpIndex = i;
                    if (((valS > 0) && (valS == toolTableArray[i].spindleSpeed)) || ((valZ < double.MaxValue) && (valZ == toolTableArray[i].finalZ)))
                    {
                        return(toolTableArray[i]);
                    }
                }
            }
            if (tmpIndex >= 0)
            {
                return(toolTableArray[tmpIndex]);
            }

            deflt.toolnr = -1;
            return(deflt);
        }
Ejemplo n.º 12
0
        private static string convertDXF(string txt)
        {
            drawingList      = new ArrayList();
            objectIdentifier = new ArrayList();
            gcodeStringIndex = 0;
            gcodeString[gcodeStringIndex] = new StringBuilder();
            gcodeString[gcodeStringIndex].Clear();
            importUnitmm = Properties.Settings.Default.importUnitmm;

            dxfBezierAccuracy = (int)Properties.Settings.Default.importSVGBezier;
            gcodeReduce       = Properties.Settings.Default.importSVGReduce;
            gcodeReduceVal    = (double)Properties.Settings.Default.importSVGReduceLimit;

            gcodeZIncEnable = Properties.Settings.Default.importGCZIncEnable;
            gcodeZIncrement = (double)Properties.Settings.Default.importGCZIncrement;

            dxfPauseElement = Properties.Settings.Default.importSVGPauseElement;
            dxfPausePenDown = Properties.Settings.Default.importSVGPausePenDown;
            dxfComments     = Properties.Settings.Default.importSVGAddComments;

            gcodeToolChange = Properties.Settings.Default.importGCTool;
            gcodeUseSpindle = Properties.Settings.Default.importGCZEnable;
            gcodeToolChange = Properties.Settings.Default.importGCTool;         // Add tool change command
            dxfImportToolNr = Properties.Settings.Default.importDXFToolIndex;

            dxfColor    = -1;
            entityCount = 0;

            int dxfToolIndex = toolTable.init();

            gcode.setup();  // initialize GCode creation (get stored settings for export)
            if (gcodeToolChange && !dxfImportToolNr)
            {
                toolProp tmpTool = toolTable.getToolProperties((int)Properties.Settings.Default.importGCToolDefNr);
                gcode.Tool(gcodeString[gcodeStringIndex], tmpTool.toolnr, tmpTool.name);
            }

            GetVectorDXF();

            string header = gcode.GetHeader("DXF import", txt);
            string footer = gcode.GetFooter();

            finalString.Clear();

            if (gcodeUseSpindle && !gcodeToolChange)
            {
                gcode.SpindleOn(finalString, "Start spindle - Option Z-Axis");
            }
            finalString.Append(gcodeString[0]);     //.Replace(',', '.')
            if (gcodeUseSpindle)
            {
                gcode.SpindleOff(finalString, "Stop spindle - Option Z-Axis");
            }

            string output = "";

            if (Properties.Settings.Default.importSVGRepeatEnable)
            {
                for (int i = 0; i < Properties.Settings.Default.importSVGRepeat; i++)
                {
                    output += finalString.ToString().Replace(',', '.');
                }

                return(header + output + footer);
            }
            else
            {
                return(header + finalString.ToString().Replace(',', '.') + footer);
            }
        }
Ejemplo n.º 13
0
        public static bool getCode(StringBuilder gcodeString)
        {
            double scale = gcHeight / 21;
            string tmp1  = gcText.Replace('\r', '|');

            gcodeString.AppendFormat("( Text: {0} )\r\n", tmp1.Replace('\n', ' '));
            string[] fileContent = new string[] { "" };

            string fileName = "";

            if (gcFontName.IndexOf(@"fonts\") >= 0)
            {
                fileName = gcFontName;
            }
            else
            {
                fileName = @"fonts\" + gcFontName + ".lff";
            }
            bool fontFound = false;

            if (gcFontName != "")
            {
                if (File.Exists(fileName))
                {
                    fileContent    = File.ReadAllLines(fileName);
                    scale          = gcHeight / 9;
                    useLFF         = true;
                    offsetY        = 0;
                    gcLineDistance = 1.667 * gcSpacing;
                    fontFound      = true;
                    foreach (string line in fileContent)
                    {
                        if (line.IndexOf("LetterSpacing") >= 0)
                        {
                            string[] tmp = line.Split(':');
                            gcLetterSpacing = double.Parse(tmp[1].Trim(), CultureInfo.InvariantCulture.NumberFormat);//Convert.ToDouble(tmp[1].Trim());
                        }
                        if (line.IndexOf("WordSpacing") >= 0)
                        {
                            string[] tmp = line.Split(':');
                            gcWordSpacing = double.Parse(tmp[1].Trim(), CultureInfo.InvariantCulture.NumberFormat);//Convert.ToDouble(tmp[1].Trim());
                        }
                    }
                }
                else
                {
                    gcodeString.AppendFormat("( Font '{0}' not found )\r\n", gcFontName);
                    gcodeString.Append("( Using alternative font )\r\n");
                }
            }

            if (Properties.Settings.Default.importGCTool)
            {
                toolProp tmpTool = toolTable.getToolProperties((int)Properties.Settings.Default.importGCToolDefNr);
                gcode.Tool(gcodeString, tmpTool.toolnr, tmpTool.name);
            }
            if ((gcAttachPoint == 2) || (gcAttachPoint == 5) || (gcAttachPoint == 8))
            {
                gcOffX -= gcWidth / 2;
            }
            if ((gcAttachPoint == 3) || (gcAttachPoint == 6) || (gcAttachPoint == 9))
            {
                gcOffX -= gcWidth;
            }
            if ((gcAttachPoint == 4) || (gcAttachPoint == 5) || (gcAttachPoint == 6))
            {
                gcOffY -= gcHeight / 2;
            }
            if ((gcAttachPoint == 1) || (gcAttachPoint == 2) || (gcAttachPoint == 3))
            {
                gcOffY -= gcHeight;
            }

            string[] lines;
            if (gcText.IndexOf("\\P") >= 0)
            {
                gcText = gcText.Replace("\\P", "\n");
            }
            lines   = gcText.Split('\n');
            offsetX = 0;
            offsetY = 9 * scale + ((double)lines.Length - 1) * gcHeight * gcLineDistance;// (double)nUDFontLine.Value;
            if (useLFF)
            {
                offsetY = ((double)lines.Length - 1) * gcHeight * gcLineDistance;// (double)nUDFontLine.Value;
            }
            isSameWord = false;
            for (int txtIndex = 0; txtIndex < gcText.Length; txtIndex++)
            {
                gcodePenUp(gcodeString);
                int chrIndex    = (int)gcText[txtIndex] - 32;
                int chrIndexLFF = (int)gcText[txtIndex];

                if (gcText[txtIndex] == '\n')                   // next line
                {
                    offsetX    = 0;
                    offsetY   -= gcHeight * gcLineDistance;
                    isSameWord = false;
                    if (gcPauseLine)
                    {
                        gcode.Pause(gcodeString, "Pause before line");
                    }
                }
                else if (useLFF)
                {
                    if (chrIndexLFF > 32)
                    {
                        gcode.Comment(gcodeString, xmlMarker.figureStart + (++pathCount) + ">");
                        gcode.Comment(gcodeString, string.Format("Char: {0}", gcText[txtIndex]));
                    }
                    drawLetterLFF(gcodeString, ref fileContent, chrIndexLFF, scale);//, string.Format("Char: {0}", gcText[txtIndex])); // regular char
                    gcodePenUp(gcodeString);
                    if (chrIndexLFF > 32)
                    {
                        gcode.Comment(gcodeString, xmlMarker.figureEnd + (pathCount) + ">");
                    }
                }
                else
                {
                    if ((chrIndex < 0) || (chrIndex > 95))     // no valid char
                    {
                        offsetX   += 2 * gcSpacing;            // apply space
                        isSameWord = false;
                        if (gcPauseWord)
                        {
                            gcode.Pause(gcodeString, "Pause before word");
                        }
                    }
                    else
                    {
                        //gcodeString.AppendFormat("( Char: {0})\r\n", gcText[txtIndex]);
                        if (gcPauseChar)
                        {
                            gcode.Pause(gcodeString, "Pause before char");
                        }
                        if (gcPauseChar && (gcText[txtIndex] == ' '))
                        {
                            gcode.Pause(gcodeString, "Pause before word");
                        }
                        drawLetter(gcodeString, hersheyFonts[gcFontName][chrIndex], scale, string.Format("Char: {0}", gcText[txtIndex])); // regular char
                    }
                }
            }
            if (!useLFF)
            {
                gcode.PenUp(gcodeString);
                gcode.Comment(gcodeString, xmlMarker.figureEnd + pathCount + ">");
            }
            return(fontFound);
        }