Esempio n. 1
0
//convert graphic to gcode ##################################################################
        private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInformation graphicInfo)
        {
            if (logDetailed)
            {
                Logger.Trace("ProcessPathObject start");
            }
            figureEnable = graphicInfo.FigureEnable;
            float origZ = gcode.gcodeZDown;

/* Create Dot */
            if (pathObject is ItemDot)
            {
                ItemDot DotData = (ItemDot)pathObject;
                if (DotData.UseZ)
                {
                    double setZ = calculateZFromRange(graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.Z);//-Math.Abs(DotData.Z);      // be sure for right sign
                    if (logEnable)
                    {
                        Logger.Trace("---Dot DotData.UseZ: RangeMin:{0:0.00}  RangeMax:{1:0.00}  DotData.Z:{2:0.00}  -> setZ:{3:0.00}", graphicInfo.DotZMin, graphicInfo.DotZMax, DotData.Z, setZ);
                    }
                    setZ = Math.Max(origZ, setZ);    // don't go deeper than set Z
                    if (logCoordinates)
                    {
                        Logger.Trace("  PenDownWithZ z:{0:0.00}  setZ:{1:0.00}  gcodeZDown:{2:0.00}", DotData.Z, setZ, origZ);
                    }
                    gcode.gcodeZDown = (float)setZ;
                    penIsDown        = false;
                }

                else if (graphicInfo.OptionZFromWidth)
                {
                    double newZ = calculateZFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.Z);
                    if (logEnable)
                    {
                        Logger.Trace("---Dot OptionZFromWidth: RangeMin:{0:0.00}  RangeMax:{1:0.00}  DotData.Z:{2:0.00}  -> setZ:{3:0.00}", graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.Z, newZ);
                    }
                    newZ             = Math.Max(origZ, newZ); // don't go deeper than set Z
                    gcode.gcodeZDown = (float)newZ;
                    penIsDown        = false;
                }

                pathObject.FigureId = StartPath(DotData);
                PenDown();
                StopPath();
                gcode.gcodeZDown = origZ;
            }
            else
            {
                if (graphicInfo.OptionZFromWidth)
                {
                    gcode.gcodeZDown = 0;
                }

                ItemPath PathData = (ItemPath)pathObject;
                if (logDetailed)
                {
                    Logger.Trace(" {0}  cnt:{1}", PathData.Info.List(), PathData.path.Count);
                }

                if (PathData.path.Count == 0)
                {
                    if (logEnable)
                    {
                        Logger.Trace("--ProcessPathObject: Empty path ID:{0}", PathData.Info.id);
                    }
                    return;
                }
                pathObject.FigureId = StartPath(PathData);
                PathDashArray       = PathData.dashArray;

                double newZ = gcode.gcodeZDown;                           // default

                for (int index = 1; index < PathData.path.Count; index++) // 0 was already processed in StartPath
                {
                    GCodeMotion entity = PathData.path[index];
                    if (graphicInfo.OptionZFromWidth)
                    {
                        newZ             = calculateZFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, entity.Depth);
                        newZ             = Math.Max(origZ, newZ); // don't go deeper than set Z
                        gcode.gcodeZDown = (float)newZ;
                        if (!Properties.Settings.Default.importDepthFromWidthRamp)
                        {
                            penIsDown = false;
                        }
                        if (logEnable)
                        {
                            Logger.Trace("--ProcessPathObject: penWidth:{0:0.00}  -> setZ:{1:0.00}", entity.Depth, newZ);
                        }
                    }

/* Create Line */
                    if (entity is GCodeLine)
                    {
                        MoveTo(entity.MoveTo, newZ, entity.Angle, "");
                    }
                    else if (entity is GCodeArc)
                    {
/* Create Arc */
                        GCodeArc ArcData = (GCodeArc)entity;
                        Arc(ArcData.IsCW, ArcData.MoveTo, ArcData.CenterIJ, newZ, ArcData.AngleStart, ArcData.Angle, "");                        // entity.comment);
                    }
                }
                StopPath("");
            }
            gcode.gcodeZDown = origZ;
            if (logDetailed)
            {
                Logger.Trace("ProcessPathObject end");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create GCode from already sorted paths, no further sorting needed.
        /// </summary>
        public static string CreateGCode(List <Graphic.PathObject> completeGraphic, List <string> headerInfo, Graphic.GraphicInformation graphicInfo) //("DXF import", txt);
        {
            Init();                                                                                                                                   // initalize variables, toolTable.init(), gcode.setup()
            useIndividualZ = graphicInfo.OptionZFromWidth;
            foreach (string info in headerInfo)                                                                                                       // set header info
            {
                gcode.AddToHeader(info);
            }

            if (logEnable)
            {
                Logger.Trace("-CreateGCode from paths");
            }

            int    toolNr   = 1;
            string toolName = "";

            foreach (PathObject pathObject in completeGraphic)          // go through all graphics elements
            {
// get tool-nr by color or use color-id
                if (Properties.Settings.Default.importDXFToolIndex)
                {
                    toolNr = pathObject.Info.penColorId + 1;
                }                                                  // avoid ID=0 to start tool-table with index 1
                else
                {
                    toolNr   = toolTable.getToolNrByToolColor(pathObject.Info.groupAttributes[(int)GroupOptions.ByColor], 0);
                    toolName = toolTable.getToolName(toolNr);
                }

// real tool to use: default or from graphic
                int toolToUse = toolNr;
                if (Properties.Settings.Default.importGCToolTableUse && Properties.Settings.Default.importGCToolDefNrUse)
                {
                    toolToUse = (int)Properties.Settings.Default.importGCToolDefNr;
                }

                toolName = toolTable.getToolName(toolToUse);

                ToolChange(toolToUse, toolName);            // add tool change commands (if enabled) and set XYFeed etc.

                ProcessPathObject(pathObject, graphicInfo); // create Dot or Path GCode
            }
            PenUp(" CreateGCode 2", true);                  // set xmlMarker.figureEnd

            gcode.jobStart(finalGcodeString, "StartJob");
            finalGcodeString.Append(gcodeString);
            gcode.jobEnd(finalGcodeString, "EndJob");      // Spindle / laser off

            return(FinalGCode(graphicInfo.Title, graphicInfo.FilePath));
        }
Esempio n. 3
0
        /// <summary>
        /// Create GCode from already sorted groups, no further sorting needed.
        /// </summary>
        public static string CreateGCode(List <Graphic.GroupObject> completeGraphic, List <string> headerInfo, Graphic.GraphicInformation graphicInfo) //("DXF import", txt);
        {
            Init();                                                                                                                                    // initalize variables, toolTable.init(), gcode.setup()
            useIndividualZ = graphicInfo.OptionZFromWidth;
            foreach (string info in headerInfo)                                                                                                        // set header info
            {
                gcode.AddToHeader(info);
            }

            int    groupID = 0;
            string groupAttributes;

            if (logEnable)
            {
                Logger.Trace("-CreateGCode from Groups");
            }

            foreach (GroupObject groupObject in completeGraphic)
            {
                groupAttributes = getGroupAttributes(groupObject, graphicInfo);

                groupID++;
                gcode.Comment(finalGcodeString, string.Format("{0} Id=\"{1}\"{2}>", xmlMarker.groupStart, groupID, groupAttributes));
                if (logEnable)
                {
                    Logger.Trace("-CreateGCode {0} Id=\"{1}\"{2}>", xmlMarker.groupStart, groupID, groupAttributes);
                }

                if (graphicInfo.GroupOption == GroupOptions.ByTile)
                {
                    if (logEnable)
                    {
                        Logger.Trace("-CreateGCode  try to insert Tile command {0}", groupObject.key);
                    }
                    if (Graphic.tileCommands.ContainsKey(groupObject.key))
                    {
                        finalGcodeString.AppendLine(Graphic.tileCommands[groupObject.key]);
                    }
                }
                else
                {
                    gcode.Tool(finalGcodeString, groupObject.toolNr, groupObject.toolName);                     // add tool change commands (if enabled) and set XYFeed etc.
                }
                foreach (PathObject pathObject in groupObject.groupPath)
                {
                    if (logEnable)
                    {
                        Logger.Trace(" ProcessPathObject id:{0} ", pathObject.Info.id);
                    }
                    ProcessPathObject(pathObject, graphicInfo); // create Dot or Path GCode
                }
                PenUp(" CreateGCode 1", true);                  // set xmlMarker.figureEnd

                finalGcodeString.Append(gcodeString);
                gcodeString.Clear();                // don't add gcode a 2nd time

                gcode.Comment(finalGcodeString, xmlMarker.groupEnd + ">");
                if (logEnable)
                {
                    Logger.Trace("-CreateGCode {0} >", xmlMarker.groupEnd);
                }
            }
            return(FinalGCode(graphicInfo.Title, graphicInfo.FilePath));
        }
        /// <summary>
        /// Create GCode from already sorted groups, no further sorting needed.
        /// </summary>
        public static string CreateGCode(List <Graphic.GroupObject> completeGraphic, List <string> headerInfo, Graphic.GraphicInformation graphicInfo) //("DXF import", txt);
        {
            Init();                                                                                                                                    // initalize variables, toolTable.init(), gcode.setup()
            overWriteId    = graphicInfo.ReProcess;                                                                                                    // keep IDs from previous conversion
            useIndividualZ = graphicInfo.OptionZFromWidth;
            foreach (string info in headerInfo)                                                                                                        // set header info
            {
                gcode.AddToHeader(info);
            }

            int    groupID = 0;
            int    iDToSet = 0;
            string groupAttributes;

            if (logEnable)
            {
                Logger.Trace("-CreateGCode from Groups");
            }
            gcode.jobStart(finalGcodeString, "StartJob");

            foreach (GroupObject groupObject in completeGraphic)
            {
                groupAttributes = getGroupAttributes(groupObject, graphicInfo);

                groupID++;
                iDToSet = groupID;

                if (overWriteId && (groupObject.GroupId > 0))
                {
                    iDToSet = groupObject.GroupId;
                }

                groupObject.GroupId = iDToSet;  // track id
                gcode.Comment(finalGcodeString, string.Format("{0} Id=\"{1}\"{2}>", xmlMarker.groupStart, iDToSet, groupAttributes));
                if (logEnable)
                {
                    Logger.Trace("-CreateGCode {0} Id=\"{1}\"{2}>", xmlMarker.groupStart, iDToSet, groupAttributes);
                }

                if (graphicInfo.GroupOption == GroupOptions.ByTile)
                {
                    if (logEnable)
                    {
                        Logger.Trace("-CreateGCode  try to insert Tile command {0}", groupObject.key);
                    }
                    if (Graphic.tileCommands.ContainsKey(groupObject.key))
                    {
                        finalGcodeString.AppendLine(Graphic.tileCommands[groupObject.key]);
                    }
                }
                else
                {
                    if (logEnable)
                    {
                        Logger.Trace("CreateGCode-Group  toolNr:{0}  name:{1}", groupObject.toolNr, groupObject.toolName);
                    }

                    ToolChange(groupObject.toolNr, groupObject.toolName);   // add tool change commands (if enabled) and set XYFeed etc.
                }
                foreach (PathObject pathObject in groupObject.groupPath)
                {
                    if (logEnable)
                    {
                        Logger.Trace(" ProcessPathObject id:{0} ", pathObject.Info.id);
                    }
                    ProcessPathObject(pathObject, graphicInfo, -1, ""); // create Dot or Path GCode, but no tool change
                }
                PenUp(" CreateGCode 1", true);                          // set xmlMarker.figureEnd

                finalGcodeString.Append(gcodeString);
                gcodeString.Clear();                            // don't add gcode a 2nd time

                gcode.Comment(finalGcodeString, xmlMarker.groupEnd + ">");
                if (logEnable)
                {
                    Logger.Trace("-CreateGCode {0} >", xmlMarker.groupEnd);
                }
            }
            gcode.jobEnd(finalGcodeString, "EndJob");       // Spindle / laser off
            return(FinalGCode(graphicInfo.Title, graphicInfo.FilePath));
        }
Esempio n. 5
0
        /// <summary>
        /// Create GCode from already sorted paths, no further sorting needed.
        /// </summary>
        public static bool CreateGCode(List <Graphic.PathObject> completeGraphic, List <string> headerInfo, Graphic.GraphicInformation graphicInfo, bool useTiles = false)
        {
//            Init();                                   // initalize variables, toolTable.init(), gcode.setup()
            overWriteId    = graphicInfo.ReProcess;             // keep IDs from previous conversion
            useIndividualZ = graphicInfo.OptionZFromWidth;

            if (logEnable)
            {
                Logger.Trace("-CreateGCode from paths");
            }

            if (!useTiles)
            {
                Init();                                 // initalize variables, toolTable.init(), gcode.setup()
                foreach (string info in headerInfo)     // set header info
                {
                    gcode.AddToHeader(info);
                }
            }

            int    toolNr    = 1;
            string toolName  = "";
            string toolColor = "";

            foreach (PathObject pathObject in completeGraphic)          // go through all graphics elements
            {
// get tool-nr by color or use color-id
                if (Properties.Settings.Default.importDXFToolIndex)
                {
                    toolNr = pathObject.Info.penColorId + 1;
                }                                                  // avoid ID=0 to start tool-table with index 1
                else
                {
                    toolColor = pathObject.Info.groupAttributes[(int)GroupOptions.ByColor];
                    toolNr    = toolTable.getToolNrByToolColor(toolColor, 0);
                }

                // real tool to use: default or from graphic
                int toolToUse = toolNr;
                if (Properties.Settings.Default.importGCToolTableUse && Properties.Settings.Default.importGCToolDefNrUse)
                {
                    toolToUse = (int)Properties.Settings.Default.importGCToolDefNr;
                }

                toolName  = toolTable.getToolName(toolToUse);
                toolColor = toolTable.getToolColor(toolNr);

                if (logEnable)
                {
                    Logger.Trace("CreateGCode2  toolNr:{0}  name:{1}", toolToUse, toolName);
                }
// add tool change after <Figure tag
                ProcessPathObject(pathObject, graphicInfo, toolToUse, toolName + " = " + toolColor); // create Dot or Path GCode
            }
            PenUp(" CreateGCode 2", true);                                                           // set xmlMarker.figureEnd

            if (!useTiles)
            {
                gcode.jobStart(finalGcodeString, "StartJob");
                finalGcodeString.Append(gcodeString);
                gcode.jobEnd(finalGcodeString, "EndJob");      // Spindle / laser off
                return(FinalGCode(graphicInfo.Title, graphicInfo.FilePath));
            }
            else
            {
                finalGcodeString.Append(gcodeString);
                gcodeString.Clear();                            // don't add gcode a 2nd time
                return(true);                                   // go on with next tile
            }
        }
Esempio n. 6
0
        public static bool CreateGCode(List <Graphic.TileObject> tiledGraphic, List <string> headerInfo, Graphic.GraphicInformation graphicInfo)
        {
            string xmlTag  = "";
            int    iDToSet = 1;

            mainGroupID = 0;

            if (logEnable)
            {
                Logger.Trace("-CreateGCode from Tiles");
            }

            Init();                                         // initalize variables, toolTable.init(), gcode.setup()
            foreach (string info in headerInfo)             // set header info
            {
                gcode.AddToHeader(info);
            }
            gcode.jobStart(finalGcodeString, "StartJob");

            foreach (TileObject tileObject in tiledGraphic)
            {
                xmlTag = string.Format("{0} Id=\"{1}\" Pos=\"{2}\">", xmlMarker.tileStart, iDToSet, tileObject.key);
                gcode.Comment(finalGcodeString, xmlTag);
                if (logEnable)
                {
                    Logger.Trace("-CreateGCode {0} ", xmlTag);
                }

                if (tileObject.tileRelatedGCode != "")
                {
                    string[] commands = { };
                    commands = tileObject.tileRelatedGCode.Split(';');
                    foreach (string cmd in commands)
                    {
                        finalGcodeString.AppendLine(cmd);
                    }
                }

                if (graphicInfo.GroupEnable)
                {
                    CreateGCode(tileObject.tile, headerInfo, graphicInfo, true);        // create grouped code
                }
                else
                {
                    CreateGCode(tileObject.groupPath, headerInfo, graphicInfo, true);   // create path code
                }
                gcode.Comment(finalGcodeString, xmlMarker.tileEnd + ">");
                iDToSet++;
            }

            gcode.jobEnd(finalGcodeString, "EndJob");       // Spindle / laser off

            return(FinalGCode(graphicInfo.Title, graphicInfo.FilePath));
        }