// This function is called to start the print job public void StartPrint(SliceFile sf, GCodeFile gcode, bool snippet = false) { //late init of callback handler if (callbackinited == false) { UVDLPApp.Instance().m_callbackhandler.RegisterCallback("DisplayDone", DisplayDone, null, "Indicates when the display device is done with the current slice"); callbackinited = true; } m_runningsnippet = snippet; if (m_printing) // already printing { return; } //make sure to reset these m_pause_request = false; //m_cancel_request = false; m_printing = true; m_buildstarttime = new DateTime(); m_buildstarttime = DateTime.Now; estimatedbuildtime = EstimateBuildTime(gcode); StartBuildTimer(); m_sf = sf; // set the slicefile for rendering m_gcode = gcode; // set the file m_state = STATE_START; // set the state machine as started m_runthread = new Thread(new ThreadStart(BuildThread)); m_running = true; m_runthread.Start(); }
/// <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) { obj.CenterOnPlatform(); 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); } else { RaiseAppEvent(eAppEvent.eModelNotLoaded, "Model " + filename + " Failed to load"); } return(objs != null); } catch (Exception ex) { DebugLogger.Instance().LogRecord(ex.Message); return(false); } }
private void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers, SliceFile sf) { try { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate() { SliceEv(ev, layer, totallayers, sf); })); } else { switch (ev) { case Slicer.eSliceEvent.eSliceStarted: SetMainMessage("Slicing Started"); break; case Slicer.eSliceEvent.eLayerSliced: break; case Slicer.eSliceEvent.eSliceCompleted: //ctl3DView1.SetNumLayers(totallayers); SetMainMessage("Slicing Completed"); String timeest = BuildManager.EstimateBuildTime(UVDLPApp.Instance().m_gcode); SetTimeMessage("Estimated Build Time: " + timeest); //show the slice in the slice view break; } } } catch (Exception ex) { DebugLogger.Instance().LogError(ex.Message); } }
/* * This is the main function to generate gcode files for the * already sliced model */ public static GCodeFile Generate(SliceFile sf, MachineConfig pi) { String gcode; StringBuilder sb = new StringBuilder(); PreProcessor pp = PreparePreprocessor(sf, pi); double zdist = 0.0; // double feedrate = pi.ZMaxFeedrate; // 10mm/min double liftfeed = sf.m_config.liftfeedrate; double retractfeed = sf.m_config.liftretractrate; double zdir = 1.0; // assume a bottom up machine int numbottom = sf.m_config.numfirstlayers; if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down) { zdir = -1.0;// top down machine, reverse the z direction } pp.SetVar("$ZDir", zdir); // append the build parameters as reference sb.Append(sf.m_config.ToString()); sb.Append(";Number of Slices = " + sf.NumSlices.ToString() + "\r\n"); sb.Append(pi.ToString());//add the machine build parameters string // append the header sb.Append(pp.Process(sf.m_config.HeaderCode)); zdist = sf.m_config.ZThick; String firstlayerdelay = ";<Delay> " + sf.m_config.firstlayertime_ms + " \r\n"; String layerdelay = ";<Delay> " + sf.m_config.layertime_ms + " \r\n"; String blankdelay = ";<Delay> " + sf.m_config.blanktime_ms + " \r\n"; String preSliceGCode = pp.Process(sf.m_config.PreSliceCode); String LiftGCode = pp.Process(sf.m_config.LiftCode); for (int c = 0; c < sf.NumSlices; c++) { sb.Append(preSliceGCode);//add in the pre-slice code // this is the marker the BuildManager uses to display the correct slice sb.Append(";<Slice> " + c + " \r\n"); // add a pause for the UV resin to be set using this image if (c < numbottom)// check for the bottom layers { sb.Append(firstlayerdelay); } else { sb.Append(layerdelay); } sb.Append(";<Slice> Blank \r\n"); // show the blank layer sb.Append(LiftGCode); // append the pre-lift codes } //append the footer sb.Append(pp.Process(sf.m_config.FooterCode)); gcode = sb.ToString(); GCodeFile gc = new GCodeFile(gcode); return(gc); }
private void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers, SliceFile sf) { try { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate() { SliceEv(ev, layer, totallayers, sf); })); } else { switch (ev) { case Slicer.eSliceEvent.eSliceStarted: Text = ""; break; case Slicer.eSliceEvent.eSliceCompleted: //show the gcode Text = UVDLPApp.Instance().m_gcode.RawGCode; break; } } } catch (Exception ex) { DebugLogger.Instance().LogError(ex.Message); } }
// This function is called to start the print job public void StartPrint(SliceFile sf, GCodeFile gcode) { if (m_printing) // already printing { return; } if (sf == null) { DebugLogger.Instance().LogRecord("No slice file, build cannot start"); RaiseStatusEvent(ePrintStat.ePrintCancelled); return; } if (gcode == null) { DebugLogger.Instance().LogRecord("No gcode file, build cannot start"); RaiseStatusEvent(ePrintStat.ePrintCancelled); return; } // we really need to map onto the events of the PrinterInterface to determine // important stuff like current z position, HBP temp, etc... m_printing = true; m_sf = sf; // set the slicefile for rendering m_gcode = gcode; // set the file m_state = STATE_START; // set the state machine as started m_runthread = new Thread(new ThreadStart(BuildThread)); m_running = true; m_runthread.Start(); }
// slicing of special objects. this is done in immediate mode only. no thread needed public SliceFile Slice(SliceBuildConfig sp, SliceFile.ModelType modeltype)//, Object3d obj) { int numslices = 0; string scenename = ""; switch (modeltype) { case SliceFile.ModelType.eScene: return(Slice(sp)); //break; case SliceFile.ModelType.eResinTest1: numslices = (int)(7.0 / sp.ZThick); scenename = "Test Model V1"; break; } m_sf = new SliceFile(sp); m_sf.m_modeltype = modeltype; m_sf.m_mode = SliceFile.SFMode.eImmediate; m_sf.NumSlices = numslices; SliceStarted(scenename, numslices); DebugLogger.Instance().LogRecord("Test model slicing started"); SliceCompleted(scenename, 0, numslices); return(m_sf); }
private void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers, SliceFile sf) { try { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate() { SliceEv(ev, layer, totallayers, sf); })); } else { switch (ev) { case Slicer.eSliceEvent.eSliceCompleted: SetNumLayers(totallayers); m_sf = sf; this.Update(); break; } } } catch (Exception ex) { DebugLogger.Instance().LogError(ex.Message); } }
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); }
/* * GCode Process for building 3d DVP UV objects * * <Build Start> * <Slicing Comments> comments containing the slicing and building parameters * <Header Code> start.gcode - commands from this * file are inserted, they contain whatever intiailization sequences are need to initialize the machine * at this point, the build tray is in position to start printing a layer * <Layer Start> * Display the correct image slice for the current layer * Delay for <Layertime> to expose the UV resin * <Layer End> * * * Example: * G1 Z0.05 F10 (move to the layer position .05 mm distance) * (<Layer 0 >) (show the slice image layer) * (<Delay 1000 >) (pause to expose the layer, first layer time is longer) * (<Layer Blank >) (show the blank image layer now) * (pre- lift gcode goes here) * G1 Z5 F10 (Move up (or down) for the lift sequence) * G1 X20 F20 (Move the wiper) * G1 X-20 F20 (Move the wiper back) * G1 Z5 F10 (Move down (or up) for the lift sequence) * (post - lift gcode goes here) * (<Delay blanktime >) (the previous commands will all be run, this command will cause the build manager to delay before moving to the next layer) * */ /* * This is the main function to generate gcode files for the * already sliced model */ public static GCodeFile Generate(SliceFile sf, MachineConfig pi) { String gcode; StringBuilder sb = new StringBuilder(); double zdist = 0.0; double feedrate = pi.m_ZMaxFeedrate; // 10mm/min double zdir = 1.0; // assume a bottom up machine if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down) { zdir = -1.0;// top down machine, reverse the z direction } // append the build parameters as reference sb.Append(sf.m_config.ToString()); // append the header sb.Append(sf.m_config.HeaderCode); String firstlayerdelay = "(<Delay> " + sf.m_config.firstlayertime_ms + " )\r\n"; String layerdelay = "(<Delay> " + sf.m_config.layertime_ms + " )\r\n"; String blankdelay = "(<Delay> " + sf.m_config.blanktime_ms + " )\r\n"; zdist = sf.m_config.ZThick; for (int c = 0; c < sf.m_slices.Count; c++) { //move the z axis to the right layer position sb.Append("G1 Z" + String.Format("{0:0.00000}", (zdist * zdir)) + " F" + feedrate + "\r\n"); // this is the marker the BuildManager uses to display the correct slice sb.Append("(<Slice> " + c + " )\r\n"); // add a pause for the UV resin to be set using this image if (c == 0)// check for the first layer { sb.Append(firstlayerdelay); } else { sb.Append(layerdelay); } sb.Append("(<Slice> Blank )\r\n"); // show the blank layer sb.Append(sf.m_config.PreLiftCode); // append the pre-lift codes //do the lift sb.Append("G1 Z" + String.Format("{0:0.00000}", (sf.m_config.liftdistance * zdir)) + " F" + feedrate + " (Lift) \r\n"); sb.Append(sf.m_config.PostLiftCode); // append the post-lift codes // move back from the lift sb.Append("G1 Z" + String.Format("{0:0.00000}", (sf.m_config.liftdistance * zdir * -1)) + " F" + feedrate + " (End Lift) \r\n"); // add a delay for the lift sequence and the pre/post lift codes to execute sb.Append(blankdelay); } //append the footer sb.Append(sf.m_config.FooterCode); gcode = sb.ToString(); GCodeFile gc = new GCodeFile(gcode); return(gc); }
// this function takes the object, the slicing parameters, // and the output directory. it generates the object slices // and saves them in the directory public SliceFile Slice(SliceBuildConfig sp, Object3d obj, String outdir) { m_obj = obj; m_cancel = false; // create new slice file m_sf = new SliceFile(sp); m_slicethread = new Thread(new ThreadStart(slicefunc)); m_slicethread.Start(); isslicing = true; return(m_sf); }
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; } }
// standard scene slicing // this function takes the object, the slicing parameters, // and the output directory. it generates the object slices // and saves them in the directory virtual public SliceFile Slice(SliceBuildConfig sp)//, Object3d obj) { // create new slice file m_sf = new SliceFile(sp); m_sf.m_modeltype = Slicing.SliceFile.ModelType.eScene; if (sp.export == false) { m_sf.m_mode = SliceFile.SFMode.eImmediate; } m_slicethread = new Thread(new ThreadStart(slicefunc)); m_slicethread.Start(); isslicing = true; return(m_sf); }
/* * GCode Process for building 3d DVP UV objects * * <Build Start> * <Slicing Comments> comments containing the slicing and building parameters * <Header Code> start.gcode - commands from this * file are inserted, they contain whatever intiailization sequences are need to initialize the machine * at this point, the build tray is in position to start printing a layer * <Layer Start> * Display the correct image slice for the current layer * Delay for <Layertime> to expose the UV resin * <Layer End> * * */ // here we prepare the gcode preprocessor and fill all nessesary variables protected static PreProcessor PreparePreprocessor(SliceFile sf, MachineConfig pi) { PreProcessor pp = new PreProcessor(); pp.SetVar("$LayerThickness", sf.m_config.ZThick); pp.SetVar("$ZLiftDist", sf.m_config.liftdistance); pp.SetVar("$ZLiftRate", sf.m_config.liftfeedrate); pp.SetVar("$ZRetractRate", sf.m_config.liftretractrate); pp.SetVar("$SlideTiltVal", sf.m_config.slidetiltval); pp.SetVar("$BlankTime", sf.m_config.blanktime_ms); pp.SetVar("$LayerTime", sf.m_config.layertime_ms); pp.SetVar("$FirstLayerTime", sf.m_config.firstlayertime_ms); return(pp); }
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); }
/* * GCode Process for building 3d DVP UV objects * * <Build Start> * <Slicing Comments> comments containing the slicing and building parameters * <Header Code> start.gcode - commands from this * file are inserted, they contain whatever intiailization sequences are need to initialize the machine * at this point, the build tray is in position to start printing a layer * <Layer Start> * Display the correct image slice for the current layer * Delay for <Layertime> to expose the UV resin * <Layer End> * * */ // here we prepare the gcode preprocessor and fill all nessesary variables protected static PreProcessor PreparePreprocessor(SliceFile sf, MachineConfig pi) { PreProcessor pp = new PreProcessor(); pp.SetVar("$LayerThickness", sf.m_config.ZThick); // the thickenss of the layer in mm pp.SetVar("$ZLiftDist", sf.m_config.liftdistance); // how far we're lifting pp.SetVar("$ZLiftRate", sf.m_config.liftfeedrate); // the rate at which we're lifting pp.SetVar("$ZRetractRate", sf.m_config.liftretractrate); // how fast we'r retracting pp.SetVar("$SlideTiltVal", sf.m_config.slidetiltval); // any used slide / tilt value on the x axis pp.SetVar("$BlankTime", sf.m_config.blanktime_ms); // how long to show the blank in ms pp.SetVar("$LayerTime", sf.m_config.layertime_ms); // total delay for a layer for gcode commands to complete - not including expusre time pp.SetVar("$FirstLayerTime", sf.m_config.firstlayertime_ms); // time to expose the first layers in ms pp.SetVar("$NumFirstLayers", sf.m_config.numfirstlayers); // number of first layers return(pp); }
// this function takes the object, the slicing parameters, // and the output directory. it generates the object slices // and saves them in the directory public SliceFile Slice(SliceBuildConfig sp)//, Object3d obj) { //m_obj = obj; m_cancel = false; // create new slice file m_sf = new SliceFile(sp); if (sp.export == false) { m_sf.m_mode = SliceFile.SFMode.eImmediate; } m_slicethread = new Thread(new ThreadStart(slicefunc)); m_slicethread.Start(); isslicing = true; return(m_sf); }
/// <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"); }
public bool LoadModel(String filename) { try { Object3d obj = new Object3d(); string ext = Path.GetExtension(filename); bool ret = false; ext = ext.ToLower(); if (ext.Equals(".dxf")) { ret = obj.LoadDXF(filename); } if (ext.Equals(".stl")) { ret = obj.LoadSTL(filename); } if (ext.Equals(".obj")) { ret = obj.LoadObjFile(filename); } if (ext.Equals(".3ds")) { ret = obj.Load3ds(filename); } if (ret == true) { m_engine3d.AddObject(obj); m_selectedobject = obj; m_slicefile = null; // the slice file is not longer current RaiseAppEvent(eAppEvent.eModelLoaded, "Model Loaded"); } else { RaiseAppEvent(eAppEvent.eModelNotLoaded, "Model " + filename + " Failed to load"); } return(ret); } catch (Exception ex) { DebugLogger.Instance().LogRecord(ex.Message); return(false); } }
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; } }
// This function is called to start the print job public void StartPrint(SliceFile sf, GCodeFile gcode) { if (m_printing) // already printing { return; } m_printing = true; m_buildstarttime = new DateTime(); m_buildstarttime = DateTime.Now; estimatedbuildtime = EstimateBuildTime(gcode); StartBuildTimer(); m_sf = sf; // set the slicefile for rendering m_gcode = gcode; // set the file m_state = STATE_START; // set the state machine as started m_runthread = new Thread(new ThreadStart(BuildThread)); m_running = true; m_runthread.Start(); }
/// <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) { obj.CenterOnPlatform(); m_engine3d.AddObject(obj); m_undoer.SaveAddition(obj); SelectedObject = obj; //test code to create a preview, this should definitely go somewhere else /*PreviewGenerator pg = new PreviewGenerator(); * Bitmap preview = pg.GeneratePreview(512, 512, obj); * if(preview !=null) * preview.Save(UVDLPApp.Instance().m_apppath + "\\testpreview.png");*/ } UVDLPApp.Instance().m_engine3d.UpdateLists(); m_slicefile = null; // the slice file is not longer current RaiseAppEvent(eAppEvent.eModelAdded, "Model Loaded " + filename); } else { RaiseAppEvent(eAppEvent.eModelNotLoaded, "Model " + filename + " Failed to load"); } return(objs != null); } catch (Exception ex) { DebugLogger.Instance().LogRecord(ex.Message); return(false); } }
// 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); } }
private void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers, SliceFile sf) { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate() { SliceEv(ev, layer, totallayers, sf); })); } else { switch (ev) { case Slicer.eSliceEvent.eSliceStarted: cmdSlice.Text = ((DesignMode) ? "Cancel" :UVDLPApp.Instance().resman.GetString("Cancel", UVDLPApp.Instance().cul)); prgSlice.Maximum = totallayers - 1; break; case Slicer.eSliceEvent.eLayerSliced: prgSlice.Maximum = totallayers - 1; prgSlice.Value = (layer > prgSlice.Maximum) ? prgSlice.Maximum : layer; lblMessage.Text = ((DesignMode) ? "SlicingLayer" :UVDLPApp.Instance().resman.GetString("SlicingLayer", UVDLPApp.Instance().cul)) + (layer + 1).ToString() + ((DesignMode) ? "Of" :UVDLPApp.Instance().resman.GetString("Of", UVDLPApp.Instance().cul)) + totallayers.ToString(); break; case Slicer.eSliceEvent.eSliceCompleted: lblMessage.Text = ((DesignMode) ? "SlicingCompleted" :UVDLPApp.Instance().resman.GetString("SlicingCompleted", UVDLPApp.Instance().cul)); cmdSlice.Text = ((DesignMode) ? "Slice_" :UVDLPApp.Instance().resman.GetString("Slice_", UVDLPApp.Instance().cul)); Close(); break; case Slicer.eSliceEvent.eSliceCancelled: cmdSlice.Text = ((DesignMode) ? "Slice_" :UVDLPApp.Instance().resman.GetString("Slice_", UVDLPApp.Instance().cul)); lblMessage.Text = ((DesignMode) ? "SlicingCancelled" :UVDLPApp.Instance().resman.GetString("SlicingCancelled", UVDLPApp.Instance().cul)); prgSlice.Value = 0; break; } } }
private void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers, SliceFile sf) { if (InvokeRequired) { BeginInvoke(new MethodInvoker(delegate() { SliceEv(ev, layer, totallayers, sf); })); } else { switch (ev) { case Slicer.eSliceEvent.eSliceStarted: cmdSlice.Text = "Cancel"; prgSlice.Maximum = totallayers - 1; break; case Slicer.eSliceEvent.eLayerSliced: prgSlice.Maximum = totallayers - 1; prgSlice.Value = layer; lblMessage.Text = "Slicing Layer " + (layer + 1).ToString() + " of " + totallayers.ToString(); break; case Slicer.eSliceEvent.eSliceCompleted: lblMessage.Text = "Slicing Completed"; cmdSlice.Text = "Slice!"; Close(); break; case Slicer.eSliceEvent.eSliceCancelled: cmdSlice.Text = "Slice!"; lblMessage.Text = "Slicing Cancelled"; prgSlice.Value = 0; break; } } }
public override string Export(Stream stream, string filename) { m_stream = stream; if ((m_name == null) || (m_name.Length == 0)) { m_name = Path.GetFileNameWithoutExtension(filename); } if ((m_description == null) || (m_description.Length == 0)) { m_description = m_name; } try { ReportStart(); SliceBuildConfig config = UVDLPApp.Instance().m_buildparms; config.UpdateFrom(UVDLPApp.Instance().m_printerinfo); // make sure we've got the correct display size and PixPerMM values // write header WriteString("1"); // version WriteString(m_name); // scene name WriteString(m_description); // scene description WriteDouble(1 / config.dpmmX); // pixel size in mm WriteDouble(config.ZThick); // slice thickness WriteInt32(0); // base standoff layers (?) WriteInt32(0); // Number of base offset layers where extents are filled (?) WriteString("Reserved3"); WriteString("Reserved2"); WriteString("Reserved1"); // write slices int numslices = UVDLPApp.Instance().m_slicer.GetNumberOfSlices(config); WriteInt32(numslices); float zlev = (float)(config.ZThick * 0.5); int npix = config.xres * config.yres; int[] lbm = new int[npix]; // current slice int p; //Bitmap bm = new Bitmap(config.xres, config.yres, System.Drawing.Imaging.PixelFormat.Format32bppArgb); // working bitmap //Color savecol = UVDLPApp.Instance().m_appconfig.m_foregroundcolor; if (UVDLPApp.Instance().m_slicer.SliceFile == null) { SliceFile sf = new SliceFile(config); sf.m_mode = SliceFile.SFMode.eImmediate; UVDLPApp.Instance().m_slicer.SliceFile = sf; // wasn't set } for (int c = 0; c < numslices; c++) { //bool layerneedssupport = false; if (CancelExport) { return("Info|Export operation canceled"); } ReportProgress(c * 100 / numslices); /*Slice sl = UVDLPApp.Instance().m_slicer.GetSliceImmediate(zlev); * zlev += (float)config.ZThick; * * if ((sl == null) || (sl.m_segments == null) || (sl.m_segments.Count == 0)) * continue; * sl.Optimize();// find loops * using (Graphics gfx = Graphics.FromImage(bm)) * gfx.Clear(Color.Transparent); * * //render current slice * UVDLPApp.Instance().m_appconfig.m_foregroundcolor = Color.White; * sl.RenderSlice(config, ref bm);*/ Bitmap bm = UVDLPApp.Instance().m_slicer.SliceImmediate(zlev); zlev += (float)config.ZThick; BitmapData data = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Marshal.Copy(data.Scan0, lbm, 0, lbm.Length); for (p = 0; p < npix; p++) { lbm[p] &= 0xFFFFFF; } bm.UnlockBits(data); CrushSlice(lbm, config.xres, config.yres); } // write supports (currently not handled) WriteInt32(0); // zero supports } catch (Exception ex) { DebugLogger.Instance().LogError(ex); return("Error|Export terminated unexpectedly"); } return("Export|Export completed successfully"); }
/* * This is the main function to generate gcode files for the * already sliced model */ public static GCodeFile Generate(SliceFile sf, MachineConfig pi) { String gcode; StringBuilder sb = new StringBuilder(); PreProcessor pp = PreparePreprocessor(sf, pi); double zdist = 0.0; // double feedrate = pi.ZMaxFeedrate; // 10mm/min double liftfeed = sf.m_config.liftfeedrate; double bottomliftfeed = sf.m_config.bottomliftfeedrate; double retractfeed = sf.m_config.liftretractrate; double zdir = 1.0; // assume a bottom up machine int numbottom = sf.m_config.numfirstlayers; if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down) { zdir = -1.0;// top down machine, reverse the z direction } pp.SetVar("$ZDir", zdir); // append the build parameters as reference sb.Append(sf.m_config.ToString()); sb.Append(";Number of Slices = " + sf.NumSlices.ToString() + "\r\n"); sb.Append(pi.ToString());//add the machine build parameters string // append the header sb.Append(pp.Process(sf.m_config.HeaderCode)); zdist = sf.m_config.ZThick; String firstlayerdelay = ";<Delay> " + sf.m_config.firstlayertime_ms + " \r\n"; String layerdelay = ";<Delay> " + sf.m_config.layertime_ms + " \r\n"; String blankdelay = ";<Delay> " + sf.m_config.blanktime_ms + " \r\n"; String preSliceGCode = pp.Process(sf.m_config.PreSliceCode); String LiftGCode = pp.Process(sf.m_config.LiftCode); int numslices = sf.NumSlices; if (sf.m_modeltype == SliceFile.ModelType.eResinTest1) { numslices -= 10; } // for a per-slice basis, we're going to re-evaluate the prelift and lift gcode // doing this will allow us to have per-slice determinations based on slice index. int c; for (c = 0; c < numslices; c++) { pp.SetVar("$CURSLICE", c); preSliceGCode = pp.Process(sf.m_config.PreSliceCode); //pp.SetVar("$CURSLICE", c); sb.Append(preSliceGCode);//add in the pre-slice code // this is the marker the BuildManager uses to display the correct slice sb.Append(";<Slice> " + c + " \r\n"); // add a pause for the UV resin to be set using this image if (c < numbottom)// check for the bottom layers { sb.Append(firstlayerdelay); } else { sb.Append(layerdelay); } sb.Append(";<Slice> Blank \r\n"); // show the blank layer LiftGCode = pp.Process(sf.m_config.LiftCode); // re-run the lift code sb.Append(LiftGCode); // append the pre-lift codes } // special ending on resin test model slicing if (sf.m_modeltype == SliceFile.ModelType.eResinTest1) { for (; c < sf.NumSlices; c++) { sb.Append(";<Slice> " + c + " \r\n"); // add a pause for the UV resin to be set using this image if (c == sf.NumSlices - 1) // set minimus exposure time on final layer { sb.Append(";<Delay> " + sf.m_config.minExposure + " \r\n"); } else { sb.Append(";<Delay> " + sf.m_config.exposureStep + " \r\n"); } } sb.Append(";<Slice> Blank \r\n"); // show the blank layer LiftGCode = pp.Process(sf.m_config.LiftCode); // re-run the lift code sb.Append(LiftGCode); // append the pre-lift codes } //append the footer sb.Append(pp.Process(sf.m_config.FooterCode)); gcode = sb.ToString(); GCodeFile gc = new GCodeFile(gcode); return(gc); }
/// <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(); if (SceneFileName.Length == 0) { SceneFileName = filename; // set it to be the first file loaded } List <Object3d> objs = ml.Load(filename); if (objs != null) { foreach (Object3d obj in objs) { obj.CenterOnPlatform(); 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); } }
/// <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); } }