Esempio n. 1
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);
 }
        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);

                path     = SliceFile.GetSliceFilePath(m_slicefile.modelname);
                fileName = Path.GetFileNameWithoutExtension(m_slicefile.modelname) + ".gcode";
                //see if we're exporting this to a zip file
                if (sf.m_config.m_exportopt.Contains("ZIP") && sf.m_config.export)
                {
                    // open the existing zip file
                    //store the gcode
                    Stream stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(m_gcode.RawGCode));
                    String zpath  = path + ".zip";
                    if (!Utility.StoreInZip(zpath, fileName, stream))
                    {
                        DebugLogger.Instance().LogError("Could not store GCode in Zip " + zpath);
                    }
                }
                else      // or just to the disk
                {
                    String sdn = path + UVDLPApp.m_pathsep + fileName;
                    SaveGCode(sdn);
                }

                //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;
            }
        }
        private void SliceStarted(string scenename, int numslices)
        {
            // if (m_buildparms.exportimages)
            {
                string path = "";
                // get the model name, could be scene....
                String modelname = scenename;
                String barename  = Path.GetFileNameWithoutExtension(modelname);
                // strip off the file extension
                path = SliceFile.GetSliceFilePath(modelname);

                // remove previousely created slices -SHS
                if (Directory.Exists(path))
                {
                    String    searchPattern = Path.GetFileNameWithoutExtension(modelname) + "*.png";
                    String [] fileNames     = Directory.GetFiles(path, searchPattern);
                    try
                    {
                        foreach (String fname in fileNames)
                        {
                            File.Delete(fname);
                        }
                        File.Delete(path + UVDLPApp.m_pathsep + barename + ".gcode");
                        Directory.Delete(path);
                    }
                    catch (Exception) { }
                }
                try
                {
                    File.Delete(path + ".zip");
                }
                catch (Exception ex)
                {
                    DebugLogger.Instance().LogError(ex.Message);
                }

                if (m_sf.m_config.m_exportopt.ToUpper().Contains("ZIP"))
                {
                    m_zip = new ZipFile();
                }
                else
                {
                    if (!Directory.Exists(path))         // check and see if a directory of that name exists,
                    {
                        Directory.CreateDirectory(path); // if not, create it
                    }
                }
            }
            RaiseSliceEvent(eSliceEvent.eSliceStarted, 0, numslices);
        }
 private void SliceCompleted(string scenename, int layer, int numslices)
 {
     if (m_sf.m_config.export == true) // if we're exporting image slices
     {
         if (m_sf.m_config.m_exportopt.ToUpper().Contains("ZIP"))
         {
             String modelname = scenename;
             // strip off the file extension
             String path = SliceFile.GetSliceFilePath(modelname);
             path += ".zip";
             m_zip.Save(path);
         }
     }
     RaiseSliceEvent(eSliceEvent.eSliceCompleted, layer, numslices);
 }
        // currently, this will save both into a zip file and into a subdirectory
        private void LayerSliced(string scenename, int layer, int numslices, Bitmap bmp)
        {
            string path;

            try
            {
                // if (m_buildparms.exportimages)
                {
                    // get the model name
                    String modelname = scenename;
                    // strip off the file extension
                    path = SliceFile.GetSliceFilePath(modelname);
                    // = null;
                    String imname    = Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}", layer) + ".png";
                    String imagename = path + UVDLPApp.m_pathsep + imname;
                    if (m_sf.m_config.m_exportopt.ToUpper().Contains("ZIP"))
                    {
                        // create a memory stream for this to save into
                        MemoryStream ms = new MemoryStream();
                        bmp.Save(ms, ImageFormat.Png);
                        ms.Seek(0, SeekOrigin.Begin); // seek back to beginning
                        m_zip.AddEntry(imname, ms);
                    }
                    else
                    {
                        bmp.Save(imagename);
                    }

                    RaiseSliceEvent(eSliceEvent.eLayerSliced, layer, numslices);
                }
            }
            catch (Exception ex)
            {
                string s = ex.StackTrace;
                DebugLogger.Instance().LogError(ex.Message);
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Loads a model, adds it to the 3d engine to be shown, and raises an app event
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool LoadModel(String filename)
        {
            try
            {
                ModelLoader     ml   = new ModelLoader();
                List <Object3d> objs = ml.Load(filename);
                if (objs != null)
                {
                    foreach (Object3d obj in objs)
                    {
                        m_engine3d.AddObject(obj);
                        m_undoer.SaveAddition(obj);
                        SelectedObject = obj;
                    }
                    UVDLPApp.Instance().m_engine3d.UpdateLists();
                    m_slicefile = null; // the slice file is not longer current
                    RaiseAppEvent(eAppEvent.eModelAdded, "Model Loaded " + filename);
                    //now try to load the gcode file
                    String gcodefile = Path.GetFileNameWithoutExtension(filename) + ".gcode";
                    String gcodepath = SliceFile.GetSliceFilePath(filename);

                    String gpath = gcodepath + UVDLPApp.m_pathsep + gcodefile;
                    if (File.Exists(gpath))
                    {
                        LoadGCode(gpath);
                    }
                    else // read the gcode from the zip file
                    {
                        String zpath = gcodepath + ".zip";
                        if (File.Exists(zpath)) // make sure the file exists before we try to read it
                        {
                            Stream s = Utility.ReadFromZip(zpath, gcodefile);
                            if (s != null)
                            {
                                s.Seek(0, 0); // go to the beginning of the stream
                                byte [] array = Utility.ReadFully(s);
                                string  gc    = System.Text.Encoding.ASCII.GetString(array);
                                m_gcode = new GCodeFile(gc);
                                RaiseAppEvent(eAppEvent.eGCodeLoaded, "GCode Loaded " + gcodefile);
                            }
                            else
                            {
                                DebugLogger.Instance().LogError("Could not load GCode from Zip " + zpath);
                            }
                        }
                    }
                    if (m_gcode != null)
                    {
                        int xres, yres, numslices;
                        xres                  = m_gcode.GetVar("Projector X Res");
                        yres                  = m_gcode.GetVar("Projector Y Res");
                        numslices             = m_gcode.GetVar("Number of Slices");
                        m_slicefile           = new SliceFile(xres, yres, numslices);
                        m_slicefile.modelname = SelectedObject.m_fullname;
                        m_slicefile.m_config  = null; //this can be null if we're loading it...
                        RaiseAppEvent(eAppEvent.eSlicedLoaded, "SliceFile Created");
                    }
                }
                else
                {
                    RaiseAppEvent(eAppEvent.eModelNotLoaded, "Model " + filename + " Failed to load");
                }

                return(objs != null);
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogRecord(ex.Message);
                return(false);
            }
        }