public void Output(string path)
            {
                average = (int)Math.Ceiling(layerPowderAmounts.Average(a => a));
                sum     = layerPowderAmounts.Sum(b => b);
                FileStream fs = File.Open(path, FileMode.Create);

                using (EnglishStreamWriter2 writer = new EnglishStreamWriter2(fs))
                {
                    writer.WriteLine(String.Format("Sum-{0}", sum));
                    for (int i = 0; i < layerPowderAmounts.Count; i++)
                    {
                        writer.WriteLine(String.Format("Layer{0}-{1}", i, layerPowderAmounts[i]));
                    }
                    writer.Flush();
                }
            }
        public bool GenerateDefineFile()
        {
            //string headerFile = Application.CommonAppDataPath + "\\composition\\Header.txt";
            string headerFile = MainParameter.AppdataPath + MainParameter.AssemblyFileVersion + "\\composition\\Autodesk.txt";

            MainParameter.DefineFile = headerFile;
            FileStream           fs     = File.Open(headerFile, FileMode.Create);
            EnglishStreamWriter2 writer = new EnglishStreamWriter2(fs);

            try
            {
                writer.WriteLine("This file generate by XYZSDK for Autodesk.");
                writer.Flush();
                writer.Close();
                return(true);
            }
            catch (Exception ex)
            {
                SVGTo3WL.logFile.writer.WriteLine("3WL Data, Error encountered: GenerateDefineFile.");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data exception: {0}", ex.ToString());
                SVGTo3WL.logFile.writer.Flush();
                Console.WriteLine("3WL Data, Error encountered: GenerateDefineFile");
                Console.WriteLine("3WL Data exception: {0}", ex.ToString());
                gCode.Release();
                return(false);
            }
        }
        public bool GenerateHeaderFile()
        {
            //string headerFile = Application.CommonAppDataPath + "\\composition\\Header.txt";
            string               headerFile = MainParameter.AppdataPath + MainParameter.AssemblyFileVersion + "\\composition\\Header.txt";
            FileStream           fs         = File.Open(headerFile, FileMode.Create);
            EnglishStreamWriter2 writer     = new EnglishStreamWriter2(fs);

            try
            {
                writer.WriteLine("; total dxf file size (kb): " + Math.Round(MainParameter.TotalDXFFileSize, 2));
                writer.Write("; total Estimated Marking time (secs): " + Math.Round(MainParameter.totalEstimatedTime, 4));
                writer.Flush();
                writer.Close();
                return(true);
            }
            catch (Exception ex)
            {
                SVGTo3WL.logFile.writer.WriteLine("3WL Data, Error encountered: GenerateHeaderFile.");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data exception: {0}", ex.ToString());
                SVGTo3WL.logFile.writer.Flush();
                Console.WriteLine("3WL Data, Error encountered: GenerateHeaderFile");
                Console.WriteLine("3WL Data exception: {0}", ex.ToString());
                gCode.Release();
                return(false);
            }
        }
            public void CreateNew(int index)
            {
                dxfFilePath = dxfPath + string.Format("\\layer{0}.dxf", index);
                FileStream fs = File.Open(dxfFilePath, FileMode.Create);

                writer = new EnglishStreamWriter2(fs);
                writer.WriteLine("  0\nSECTION\n  2\nENTITIES");
            }
 public void AddPolygon(float[] points)
 {
     writer.WriteLine("  0\nLINE\n8\nL1");
     writer.WriteLine(" 10");
     writer.WriteLine((points[0] - widthOffset).ToString("0.0000"));
     writer.WriteLine(" 20");
     writer.WriteLine(points[1] - depthOffset);
     writer.WriteLine(" 30");
     writer.WriteLine("0.0000");
     for (int i = 2; i < points.Length - 1; i += 2)
     {
         float X = points[i] - widthOffset;
         float Y = points[i + 1] - depthOffset;
         writer.WriteLine(" 11");
         writer.WriteLine(X.ToString());
         writer.WriteLine(" 21");
         writer.WriteLine(Y.ToString());
         writer.WriteLine(" 31");
         writer.WriteLine("0.0000");
         writer.WriteLine("  0\nLINE\n8\nL1");
         writer.WriteLine(" 10");
         writer.WriteLine(X.ToString());
         writer.WriteLine(" 20");
         writer.WriteLine(Y.ToString());
         writer.WriteLine(" 30");
         writer.WriteLine("0.0000");
     }
     writer.WriteLine(" 11");
     writer.WriteLine(points[0] - widthOffset);
     writer.WriteLine(" 21");
     writer.WriteLine(points[1] - depthOffset);
     writer.WriteLine(" 31");
     writer.WriteLine("0.0000");
 }
            public void Header(float layerHeight, int layerAmount)
            {
                float printDensity = (float)PrinterSetting.PrintAreaWidth * (float)PrinterSetting.PrintAreaDepth * layerAmount * layerHeight;
                //float packingDensity = ((float)MainParameter.gCodeVolume / printDensity) * 100f;
                float packingDensity = (float)MainParameter.PackingDensity;

                //List<model.PrintModel> models = Main.main.objectPlacement.models;
                writer.WriteLine("3DPSNKG13WTW0000");
                writer.WriteLine("; machine: SLS 1.0");
                writer.WriteLine("; ----------Summary Details---------- ");
                writer.WriteLine("; layer height: " + layerHeight.ToString());
                writer.WriteLine("; filled: no");
                writer.WriteLine("; volume: " + MainParameter.gCodeVolume.ToString("#,0.0000"));
                writer.WriteLine("; model width: 1");
                writer.WriteLine("; model length: 1");
                writer.WriteLine("; model height: {0}", MainParameter.selLayerHeight * MainParameter.layercount);
                writer.WriteLine("; layer count: " + layerAmount.ToString());
                writer.WriteLine("; parts count: " + MainParameter.ModelCount.ToString());
                writer.WriteLine("; packing density %: " + packingDensity.ToString("0.00"));
                writer.WriteLine("; non-sintered powder: " + (printDensity - MainParameter.gCodeVolume).ToString("0.00") + "\n\n");
                //if (MainParameter.ModelCount > 1)
                //{
                //    writer.WriteLine("; ----------Parts Details---------- ");
                //    for (int i = 0; i < models.Count; i++)
                //    {
                //        model.PrintModel mod = models[i];
                //        //<Carson(Taipei)><07-02-2019><Modified - Fixed non-ascii encryption error>
                //        //writer.WriteLine("; part" + "[" + (i + 1) + "]" + ": " + mod);
                //        writer.WriteLine("; part" + "[" + (i + 1) + "]" + ": ");
                //        //<><><>
                //        writer.WriteLine("; volume: " + mod.ActiveModel.Volume().ToString("0.00"));
                //        writer.WriteLine("; part width: " + (mod.xMax - mod.xMin).ToString("0.00"));
                //        writer.WriteLine("; part length: " + (mod.yMax - mod.yMin).ToString("0.00"));
                //        writer.WriteLine("; part height: " + (mod.zMax - mod.zMin).ToString("0.00"));
                //        writer.WriteLine("; layer count: " + Math.Floor((mod.zMax - mod.zMin) / layerHeight).ToString("0") + "\n");
                //    }
                //    writer.WriteLine();
                //}
                writer.WriteLine("M601 ; Laser Off");;
            }
        public bool GenerateRecordFile()
        {
            try
            {
                //Main.main.LogMessage("Main", "Generating Record file ....." , "");
                //string recordFilePath = Application.CommonAppDataPath + "\\composition\\RecordFile.txt";
                string recordFilePath = MainParameter.AppdataPath + MainParameter.AssemblyFileVersion + "\\composition\\RecordFile.txt";
                //StringBuilder shortPath = new StringBuilder(255);
                //Main.GetShortPathName(recordFilePath, shortPath, shortPath.Capacity);
                //recordFilePath = shortPath.ToString();
                FileStream           fs     = File.Open(recordFilePath, FileMode.Create);
                EnglishStreamWriter2 writer = new EnglishStreamWriter2(fs);
                //Main.main.threedview.ui.ProfileSettings_UI.Dispatcher.Invoke(new Action(() =>{
                //writer.WriteLine("Infill Scan Speed: "+Main.main.threedview.ui.ProfileSettings_UI.txt_InfillScanningSpeed.Text);
                //writer.WriteLine("Contour Scan Speed: " + Main.main.threedview.ui.ProfileSettings_UI.txt_ContourScanningSpeed.Text);
                //writer.WriteLine("Beam Offset: " + Main.main.threedview.ui.ProfileSettings_UI.txt_InfillContourOffset.Text);
                //writer.WriteLine("Fill Round Pitch: " + Main.main.threedview.ui.ProfileSettings_UI.txt_InfillBorderOffset.Text);
                //writer.WriteLine("Border: 0.12");
                //writer.WriteLine("Step Angle: 90");
                //writer.WriteLine("Offset Angle: 180");
                //writer.WriteLine("Infill Pitch: " + Main.main.threedview.ui.ProfileSettings_UI.txt_InfillSinterPitch.Text);
                //writer.WriteLine("Start Angle: " + Main.main.threedview.ui.ProfileSettings_UI.txt_StartAngle.Text);
                //writer.WriteLine("Powder Density:" + Main.main.threedview.ui.ProfileSettings_UI.Powder_Density.Text);
                //writer.WriteLine("Sintered Density:" + Main.main.threedview.ui.ProfileSettings_UI.Sintered_Density.Text);
                //writer.WriteLine("Laser Sintering Twice: " + Main.main.threedview.ui.ProfileSettings_UI.SelectedProfileSettings.SinteringTwice.ToString());
                ////<timmy><9-15-2020><add base/cover in RecordFile.txt>
                //writer.WriteLine("Base Layers: " + Main.main.threedview.ui.ProfileSettings_UI.SelectedProfileSettings.baselayercyclecount.ToString());
                //writer.WriteLine("Cover Layers: " + Main.main.threedview.ui.ProfileSettings_UI.SelectedProfileSettings.coverlayer.ToString());
                ////<><><>
                //}));

                writer.WriteLine("Infill Scan Speed: 0");
                writer.WriteLine("Contour Scan Speed: 0");
                writer.WriteLine("Beam Offset: 0");
                writer.WriteLine("Fill Round Pitch: 0");
                writer.WriteLine("Border: 0");
                writer.WriteLine("Step Angle: 0");
                writer.WriteLine("Offset Angle: 0");
                writer.WriteLine("Infill Pitch: 0");
                writer.WriteLine("Start Angle: 0");
                writer.WriteLine("Powder Density:0");
                writer.WriteLine("Sintered Density:0");
                writer.WriteLine("Laser Sintering Twice: 0");
                //<timmy><9-15-2020><add base/cover in RecordFile.txt>
                writer.WriteLine("Base Layers: 0");
                writer.WriteLine("Cover Layers: 0");
                //<><><>



                writer.Flush();
                writer.Dispose();

                //Main.main.LogMessage("Main", "Success: Record File was Generated.", "");
                return(true);
            }
            catch (Exception ex)
            {
                //Main.main.LogMessage("Main", "Failed: Generating record file.", "");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data, Error encountered: GenerateRecordFile.");
                SVGTo3WL.logFile.writer.WriteLine("3WL Data exception: {0}", ex.ToString());
                SVGTo3WL.logFile.writer.Flush();
                Console.WriteLine("3WL Data, Error encountered: GenerateRecordFile");
                Console.WriteLine("3WL Data exception: {0}", ex.ToString());
                gCode.Release();
                return(false);
            }
        }