コード例 #1
0
        void sliceItem_Done(object sender, EventArgs e)
        {
            PrintItemWrapper sliceItem = (PrintItemWrapper)sender;

            sliceItem.Done -= new EventHandler(sliceItem_Done);
            savedGCodeFileNames.Add(sliceItem.GCodePathAndFileName);

            itemCountBeingWorkedOn++;
            if (itemCountBeingWorkedOn < allFilesToExport.Count)
            {
                if (StartingNextPart != null)
                {
                    StartingNextPart(this, new StringEventArgs(ItemNameBeingWorkedOn));
                }
            }
            else
            {
                UpdatePartStatus(this, new StringEventArgs("Calculating Total cm3..."));

                if (savedGCodeFileNames.Count > 0)
                {
                    double total = 0;
                    foreach (string gcodeFileName in savedGCodeFileNames)
                    {
                        string[] lines = File.ReadAllLines(gcodeFileName);
                        string filamentAmountLine = lines[lines.Length - 1];
                        int startPos = filamentAmountLine.IndexOf("(");
                        int endPos = filamentAmountLine.IndexOf("cm3)");
                        string value = filamentAmountLine.Substring(startPos + 1, endPos - (startPos + 1));
                        double amountForThisFile;
                        if (double.TryParse(value, out amountForThisFile))
                        {
                            total += amountForThisFile;
                        }
                        else
                        {
                            GCodeFile gcodeFile = new GCodeFile(gcodeFileName);
                            total += gcodeFile.GetFilamentCubicMm(ActiveSliceSettings.Instance.FillamentDiameter) / 1000;
                        }
                    }

                    // now copy all the gcode to the path given
                    for (int i = 0; i < savedGCodeFileNames.Count; i++)
                    {
                        string savedGcodeFileName = savedGCodeFileNames[i];
                        string originalFileName = Path.GetFileName(allFilesToExport[i].Name);
                        string outputFileName = Path.ChangeExtension(originalFileName, ".gcode");
                        throw new NotImplementedException();
                        //string outputPathAndName = Path.Combine(exportPath, outputFileName);

                        if (ActivePrinterProfile.Instance.DoPrintLeveling)
                        {
                            GCodeFile unleveledGCode = new GCodeFile(savedGcodeFileName);
                            PrintLeveling.Instance.ApplyLeveling(unleveledGCode);
                            //unleveledGCode.Save(outputPathAndName);
                        }
                        else
                        {
                            //File.Copy(savedGcodeFileName, outputPathAndName, true);
                        }
                    }

                    if (DoneSaving != null)
                    {
                        DoneSaving(this, new StringEventArgs(string.Format("{0:0.0}", total)));
                    }
                }
            }
        }
コード例 #2
0
        void sliceItem_Done(object sender, EventArgs e)
        {
            PrintItemWrapper sliceItem = (PrintItemWrapper)sender;

            sliceItem.SlicingDone.UnregisterEvent(sliceItem_Done, ref unregisterEvents);
            sliceItem.SlicingOutputMessage.UnregisterEvent(printItemWrapper_SlicingOutputMessage, ref unregisterEvents);
            if (File.Exists(sliceItem.FileLocation))
            {
                savedGCodeFileNames.Add(sliceItem.GetGCodePathAndFileName());
            }

            itemCountBeingWorkedOn++;
            if (itemCountBeingWorkedOn < allFilesToExport.Count)
            {
                if (StartingNextPart != null)
                {
                    StartingNextPart(this, new StringEventArgs(ItemNameBeingWorkedOn));
                }
            }
            else
            {
                UpdatePartStatus(this, new StringEventArgs("Calculating Total cm3..."));

                if (savedGCodeFileNames.Count > 0)
                {
                    double total = 0;
                    foreach (string gcodeFileName in savedGCodeFileNames)
                    {
                        string[] lines = File.ReadAllLines(gcodeFileName);
                        if (lines.Length > 0)
                        {
                            string filamentAmountLine = lines[lines.Length - 1];
                            bool foundAmountInGCode = false;
                            int startPos = filamentAmountLine.IndexOf("(");
                            if (startPos > 0)
                            {
                                int endPos = filamentAmountLine.IndexOf("cm3)", startPos);
                                if (endPos > 0)
                                {
                                    string value = filamentAmountLine.Substring(startPos + 1, endPos - (startPos + 1));
                                    double amountForThisFile;
                                    if (double.TryParse(value, out amountForThisFile))
                                    {
                                        foundAmountInGCode = true;
                                        total += amountForThisFile;
                                    }
                                }
                            }
                            if (!foundAmountInGCode)
                            {
                                GCodeFile gcodeFile = new GCodeFile(gcodeFileName);
                                total += gcodeFile.GetFilamentCubicMm(ActiveSliceSettings.Instance.FilamentDiameter) / 1000;
                            }
                        }
                    }

                    // now copy all the gcode to the path given
                    for (int i = 0; i < savedGCodeFileNames.Count; i++)
                    {
                        string savedGcodeFileName = savedGCodeFileNames[i];
                        string originalFileName = Path.GetFileName(allFilesToExport[i].Name);
                        string outputFileName = Path.ChangeExtension(originalFileName, ".gcode");
                        string outputPathAndName = Path.Combine(exportPath, outputFileName);

                        if (ActivePrinterProfile.Instance.DoPrintLeveling)
                        {
                            GCodeFile unleveledGCode = new GCodeFile(savedGcodeFileName);
                            PrintLevelingPlane.Instance.ApplyLeveling(unleveledGCode);
                            unleveledGCode.Save(outputPathAndName);
                        }
                        else
                        {
                            File.Copy(savedGcodeFileName, outputPathAndName, true);
                        }
                    }

                    if (DoneSaving != null)
                    {
                        DoneSaving(this, new StringEventArgs(string.Format("{0:0.0}", total)));
                    }
                }
            }
        }