Beispiel #1
0
        private List <String> generatePrefixGcode(itCut interval)
        {
            List <String> toret = new List <string>();

            toret.Add(";gcode added to set the correct temperature left from the previous layer");
            toret.Add("M109 S" + interval.nozzleTempStart);
            toret.Add("M190 S" + interval.bedTempStart);
            toret.Add("M106 S" + interval.fanStart);

            return(toret);
        }
Beispiel #2
0
        private void btnGen_Click(object sender, EventArgs e)
        {
            filePath = txtPath.Text;
            findLayersidx();

            //copy CutList with intervals, adding start and end interrvals
            List <itCut> itCutList = new List <itCut>();

            itCutList.Add(new itCut(0));
            foreach (var i in CutList.Items)
            {
                itCutList.Add((itCut)i);
            }
            itCutList.Add(new itCut(-1));


            //cutLevel = new List<int>();
            for (int k = 0; k < itCutList.Count; k++)
            {
                itCut i = itCutList[k];
                //cutLevel.Add(i.layer); //add range cut i-1 --> cut i

                int stLine = GetLayerRowOf(i.layer);

                //find  nozzle start temperarture of this layer
                //by seraching backwards (previous lines)
                //the first point in which temperature was set
                int nozzleTStart = findFirstMCmd("M104", "M109", stLine, 0);
                i.nozzleTempStart = nozzleTStart;

                //find bed start temp
                int bedTStart = findFirstMCmd("M140", "M190", stLine, 0);
                i.bedTempStart = bedTStart;

                //find fan speed
                int fanSpeed = findFirstMCmd("M106", "M106", stLine, 0);
                i.fanStart = fanSpeed;
            }



            string prevEndZValue = "0";

            for (int i = 1; i < itCutList.Count; i++)
            {
                List <String> tmp = new List <string>();
                //append common initial gcode (line0 --> "LAYER:0"
                tmp.AddRange(appendLines(0, GetLayerRowOf(0)));

                //append lines tfor resuming temp as left by previous layer
                List <String> prefixGcode = generatePrefixGcode(itCutList[i - 1]);
                //on line above -1 is necessary becausa cutLevel has a initial and final
                //item added
                tmp.AddRange(prefixGcode);

                //append central gcode of current slice
                int startLayer = GetLayerRowOf(itCutList[i - 1].layer);
                int endLayer   = GetLayerRowOf(itCutList[i].layer);
                tmp.AddRange(appendLines(startLayer, endLayer));

                //add pause temperature, if necessary
                List <String> pauseLines = generatePauseTempGcode(nozzlePauseTemp, bedPauseTemp);
                tmp.AddRange(pauseLines);

                //add custom gcode at the end of this layer
                tmp.AddRange(getTextBoxLines());

                //append common final part
                tmp.AddRange(appendLines(end_gcode_row, lines.Length));

                //replace in prefix gcode the initial value for motor E
                if (rbABS.Checked)
                {
                    string startEvalue = findFirst_G1_E(startLayer);
                    int    toReplace   = findLast_G92_E0_backwards(GetLayerRowOf(0));
                    tmp[toReplace] = "G92 E" + startEvalue;
                }

                int      searchStart = findLast_G28_backwards(GetLayerRowOf(0));
                int      startZrow   = idxFindFirst_G1_Z(searchStart);
                String   row         = lines[startZrow];
                String[] tmp2        = row.Split(new char[] { ' ', '\t' });
                for (int k = 0; k < tmp2.Length; k++)
                {
                    if (tmp2[k].StartsWith("Z"))
                    {
                        String str      = tmp2[k].Replace("Z", "");
                        float  defvalue = 0;
                        float.TryParse(str, out defvalue);

                        float curvalue = 0;
                        float.TryParse(prevEndZValue, out curvalue);

                        float value = curvalue + defvalue;

                        tmp2[k] = "Z" + value.ToString("0.00");
                    }
                }

                tmp[startZrow] = String.Join(" ", tmp2);

                if (i < itCutList.Count - 1)
                {
                    prevEndZValue = findFirst_G1_Z(endLayer);
                }



                //String outputPath = @"Z:\slice" + i + ".gcode";
                String outputPath = Path.GetDirectoryName(filePath);
                String outputName = Path.GetFileNameWithoutExtension(filePath);
                outputName = outputName + "_slice_" + i + ".gcode";
                outputPath = Path.Combine(outputPath, outputName);


                File.WriteAllLines(outputPath, tmp.ToArray());
            }

            //add final cut, from last cut point to end of gcode
            String folder = Path.GetDirectoryName(filePath);

            System.Diagnostics.Process.Start(folder);
        }