/// <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); //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> /// 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; } }
/// <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; } }