public void SaveScene(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new MethodInvoker(delegate() { SaveScene(sender, e); }));
            }
            else
            {
                saveFileDialog1.Filter      = "Scene files (*.cws)|*.cws|STL File (*.stl)|*.stl";
                saveFileDialog1.FilterIndex = 0;
                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //check the filter index
                    switch (saveFileDialog1.FilterIndex) // index starts at 1 instead of 0
                    {
                    case 1:
                        SceneFile.Instance().Save(saveFileDialog1.FileName);
                        break;

                    case 2:
                        //stl file
                        UVDLPApp.Instance().CalcScene();     // calc the scene object
                        UVDLPApp.Instance().Scene.SaveSTL_Binary(saveFileDialog1.FileName);
                        UVDLPApp.Instance().Scene.m_fullname = saveFileDialog1.FileName;
                        break;
                    }
                }
            }
        }
Example #2
0
 private void SliceStarted(string scenename, int numslices)
 {
     if (m_sf.m_config.export == true)  // if we're exporting
     {
         //exporting to cws file
         //get the name oif the scene file
         if (UVDLPApp.Instance().SceneFileName.Length == 0)
         {
             MessageBox.Show("Please Save the Scene First Before Exporting Slices");
             CancelSlicing();
             return;
         }
         if (m_sf.m_config.exportpng == true)
         {
             // if we're exporting png slices to disk as well, then make sure we have a directory to export them into
             try
             {
                 string exportdirname = SliceFile.GetSliceFilePath(UVDLPApp.Instance().SceneFileName);
                 if (!Directory.Exists(exportdirname))  // if the directory does not exist
                 {
                     //create the directory to export images into
                     Directory.CreateDirectory(exportdirname);
                     //create the /preview directory here?
                 }
             }
             catch (Exception ex)
             {
                 DebugLogger.Instance().LogError(ex);
             }
         }
         if (UVDLPApp.Instance().SceneFileName.Length != 0) // check again to make sure we've really got a name
         {
             //remove all the previous images first
             //remove the png slices
             //SceneFile.Instance().RemoveResourcesFromFile(UVDLPApp.Instance().SceneFileName, "Slices", ".png");
             SceneFile.Instance().RemoveResourcesBySection(UVDLPApp.Instance().SceneFileName, "Slices");
             //remove the vector slices
             SceneFile.Instance().RemoveResourcesFromFile(UVDLPApp.Instance().SceneFileName, "VectorSlices", ".svg");
             //remove any slice profile in the scene file
             SceneFile.Instance().RemoveResourcesFromFile(UVDLPApp.Instance().SceneFileName, "SliceProfile", ".slicing");
             //create a memory stream to hold the slicing profile in memory
             MemoryStream ms = new MemoryStream();
             //serialize the slciing profile into the memory stream
             string sliceprofilename = Path.GetFileNameWithoutExtension(UVDLPApp.Instance().m_buildparms.m_filename) + ".slicing";
             UVDLPApp.Instance().m_buildparms.Save(ms, sliceprofilename);
             ms.Seek(0, SeekOrigin.Begin); // rewind
             //save the stream to the scene cws zip file
             SceneFile.Instance().AddSliceProfileToFile(UVDLPApp.Instance().SceneFileName, ms, sliceprofilename);
             // if we've saved this scene before, then we can save the images into it. Open it up for add
         }
         else
         {
             //no name? cancel slicing
             CancelSlicing();
         }
     }
     RaiseSliceEvent(eSliceEvent.eSliceStarted, 0, numslices);
 }
 private void testLoadSceneToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         if (SceneFile.Instance().Load(openFileDialog1.FileName))
         {
             UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eReDraw, "");
         }
     }
 }
 /// <summary>
 /// This is called after the scene file is loaded
 /// It will also load the gcode file and slicing profile / vector slices
 /// </summary>
 public void PostLoadScene()
 {
     m_gcode = SceneFile.Instance().LoadGCodeFromScene(SceneFileName);
     if (m_gcode == null)
     {
         m_gcode = new GCodeFile(""); // create empty file
     }
     RaiseAppEvent(eAppEvent.eGCodeLoaded, "GCode Loaded ");
     SceneFile.Instance().LoadSliceProfileFromScene(SceneFileName);
     m_slicefile        = new SliceFile(m_buildparms);
     m_slicefile.m_mode = SliceFile.SFMode.eLoaded;
     m_slicer.SliceFile = m_slicefile;
     //set the number of slices
     m_slicefile.NumSlices = m_slicer.GetNumberOfSlices(m_buildparms);
     RaiseAppEvent(eAppEvent.eSliceProfileChanged, "Slice Profile loaded");
     RaiseAppEvent(eAppEvent.eSlicedLoaded, "Slice Profile loaded");
 }
Example #5
0
        void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers, SliceFile sf)
        {
            //  String path = "";
            // String fileName = "";
            switch (ev)
            {
            case Slicer.eSliceEvent.eSliceStarted:

                break;

            case Slicer.eSliceEvent.eLayerSliced:

                break;

            case Slicer.eSliceEvent.eSliceCompleted:     // this all needs to be changed....
                m_slicefile = sf;
                //generate the GCode
                m_gcode = GCodeGenerator.Generate(m_slicefile, m_printerinfo);
                //we only need the file name of the gcode if we're saving it somewhere...
                //see if we're exporting this to a zip file
                //if (sf.m_config.m_exportopt.Contains("ZIP") && sf.m_config.export)
                if (sf.m_config.export)
                {
                    // open the existing scene file
                    //store the gcode
                    MemoryStream stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(m_gcode.RawGCode));
                    String       gcn    = Path.GetFileNameWithoutExtension(UVDLPApp.Instance().SceneFileName) + ".gcode";
                    //SceneFile.Instance().RemoveExistingGCode(UVDLPApp.Instance().SceneFileName);
                    SceneFile.Instance().RemoveResourcesFromFile(UVDLPApp.Instance().SceneFileName, "GCode", ".gcode");
                    SceneFile.Instance().AddGCodeToFile(UVDLPApp.Instance().SceneFileName, stream, gcn);
                }
                //save the slicer object for later too
                //save the slice file

                // UVDLPApp.Instance().m_slicefile.Save(path + UVDLPApp.m_pathsep + fn + ".sliced");
                break;

            case Slicer.eSliceEvent.eSliceCancelled:
                DebugLogger.Instance().LogRecord("Slicing Cancelled");
                break;
            }
        }
 public void LoadSTLModel_Click(object sender, object e)
 {
     openFileDialog1.FileName = "";
     //openFileDialog1.Filter = "3D Model Files (*.stl;*.obj;*.3ds;*.amf)|*.stl;*.obj;*.3ds;*.amf|Scene files (*.cws)|*.cws";
     openFileDialog1.Filter = "3D Model Files (*.stl;*.obj;*.3ds;*.amf)|*.stl;*.obj;*.3ds;*.amf|Scene files (*." + SceneFileExt + ")|*." + SceneFileExt;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         foreach (string filename in openFileDialog1.FileNames)
         {
             if (filename.Contains("." + SceneFileExt))
             {
                 //scene file
                 if (SceneFile.Instance().LoadSceneFile(filename))
                 {
                     //set up for newly loaded scene
                     //load gcode
                     UVDLPApp.Instance().PostLoadScene();
                     //raise events
                     //load slicing info?
                     UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eReDraw, "");
                 }
                 else
                 {
                     DebugLogger.Instance().LogError("Error loading scene file : " + filename);
                 }
             }
             else
             {
                 if (UVDLPApp.Instance().LoadModel(filename) == false)
                 {
                     DebugLogger.Instance().LogError("Error loading object file : " + filename);
                 }
                 else
                 {
                     //chkWireframe.Checked = false;
                     //ctl3DView1.UpdateObjectInfo();
                 }
             }
         }
     }
 }
        public void SaveScene(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new MethodInvoker(delegate() { SaveScene(sender, e); }));
            }
            else
            {
                //saveFileDialog1.Filter = "Scene files (*.cws)|*.cws|STL File (*.stl)|*.stl";
                saveFileDialog1.Filter      = "Scene files (*." + SceneFileExt + ")|*." + SceneFileExt + "|STL File (*.stl)|*.stl";
                saveFileDialog1.FilterIndex = 0;
                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //check the filter index
                    switch (saveFileDialog1.FilterIndex) // index starts at 1 instead of 0
                    {
                    case 1:
                        SceneFile.Instance().SaveModelsIntoScene(saveFileDialog1.FileName);
                        if (UVDLPApp.Instance().m_buildparms.exportpreview != PreviewGenerator.ePreview.None)
                        {
                            PreviewGenerator pg = new PreviewGenerator();
                            pg.ViewAngle = UVDLPApp.Instance().m_buildparms.exportpreview;
                            Bitmap preview = pg.GeneratePreview(512, 512);
                            SceneFile.Instance().AddPreviewImage(UVDLPApp.Instance().SceneFileName, preview, "Default", "ScenePreview.png");
                        }
                        UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eSceneSaved, "cws");
                        break;

                    case 2:
                        //stl file
                        UVDLPApp.Instance().CalcScene();     // calc the scene object
                        UVDLPApp.Instance().Scene.SaveSTL_Binary(saveFileDialog1.FileName);
                        UVDLPApp.Instance().Scene.m_fullname = saveFileDialog1.FileName;
                        UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eSceneSaved, "stl");
                        break;
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// This will be called when we're exporting
        /// </summary>
        /// <param name="scenename"></param>
        /// <param name="layer"></param>
        /// <param name="numslices"></param>
        /// <param name="bmp"></param>
        /// <param name="lstPoly"></param>
        private void LayerSliced(string scenename, int layer, int numslices, Bitmap bmp, List <PolyLine3d> lstintersections, bool outline = false)
        {
            string path = "";

            try
            {
                // if (m_buildparms.exportimages)
                {
                    // get the model name
                    String modelname   = scenename;
                    String outlinename = "";
                    // strip off the file extension
                    path = SliceFile.GetSliceFilePath(modelname);
                    if (outline)
                    {
                        outlinename = "_outline";
                    }
                    String imname    = Path.GetFileNameWithoutExtension(modelname) + outlinename + String.Format("{0:0000}", layer) + ".bmp";
                    String imagename = path + UVDLPApp.m_pathsep + imname;
                    // create a memory stream for this to save into
                    bmp.Tag = BuildManager.SLICE_NORMAL; // mark it as normal
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, ImageFormat.Bmp);
                    ms.Seek(0, SeekOrigin.Begin); // seek back to beginning
                    if (!m_cancel)                // if we're not in the process of cancelling
                    {
                        SceneFile.Instance().AddSlice(UVDLPApp.Instance().SceneFileName, ms, imname);
                    }

                    if (m_sf.m_config.exportpng)
                    {
                        //imagename
                        var img = (Image)bmp;
                        img.Save(imagename, ImageFormat.Bmp);
                        //bmp.Save(imagename);
                    }
                    if (lstintersections != null)
                    {
                        StreamWriter sw;
                        imname    = Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}", layer) + ".svg";
                        imagename = path + UVDLPApp.m_pathsep + imname;
                        if (m_sf.m_config.exportsvg < 3)
                        {
                            Path2D vectorPath = new Path2D(lstintersections);
                            sw = vectorPath.GenerateSVG(UVDLPApp.Instance().m_printerinfo.m_PlatXSize,
                                                        UVDLPApp.Instance().m_printerinfo.m_PlatYSize, m_sf.m_config.exportsvg == 2);
                        }
                        else
                        {
                            Slice sl = new Slice();
                            sl.m_segments = lstintersections;
                            sl.Optimize();
                            sw = GenerateSVG(sl.m_opsegs, m_sf.m_config.exportsvg == 4);
                        }
                        if (!m_cancel)
                        {
                            SceneFile.Instance().AddVectorSlice(UVDLPApp.Instance().SceneFileName, (MemoryStream)sw.BaseStream, imname);
                        }
                    }

                    RaiseSliceEvent(eSliceEvent.eLayerSliced, layer, numslices);
                }
            }
            catch (Exception ex)
            {
                string s = ex.StackTrace;
                DebugLogger.Instance().LogError(ex.Message);
            }
        }