/// <summary> /// Add a single image slice to the entry in the manifest and store in the zip /// </summary> /// <param name="bmp"></param> /// <param name="name"></param> /// <returns></returns> public bool AddSlice(string scenefilename, MemoryStream ms, string imname) { try { LoadManifest(scenefilename); using (ZipFile mZip = ZipFile.Read(scenefilename)) { // store the slice file into the zip if (mZip.Entries.Count(a => a.FileName == imname) != 0) { mZip.RemoveEntry(mZip.Entries.First(a => a.FileName == imname)); } mZip.AddEntry(imname, ms); mZip.Save(); } // file should be closed here //update the manifest // find the slices node in the top level XmlNode slicesnode = mManifest.FindSection(mManifest.m_toplevel, "Slices"); if (slicesnode == null) // no slice node { //create one slicesnode = mManifest.AddSection(mManifest.m_toplevel, "Slices"); } //add the slice file name into the manifest XmlNode curslice = mManifest.AddSection(slicesnode, "Slice"); mManifest.SetParameter(curslice, "name", imname); UpdateManifest(scenefilename); // save the new manifest file out } catch (Exception ex) { DebugLogger.Instance().LogError(ex); } return(false); }
// save to xml file -SHS public bool Save(String filename) { XmlHelper xh = new XmlHelper(); xh.StartNew(filename, "ProjectorCmdList"); foreach (ProjectorCommand pc in m_commands) { XmlNode nd = xh.AddSection(null, "Command"); xh.SetParameter(nd, "Name", pc.name); xh.SetParameter(nd, "IsHex", pc.hex); xh.SetParameter(nd, "Cmd", pc.command); } return(xh.Save(FILE_VERSION)); }
/// <summary> /// Add a single image slice to the entry in the manifest and store in the zip /// </summary> /// <param name="bmp"></param> /// <param name="name"></param> /// <returns></returns> public bool AddSlice(MemoryStream ms, string imname) { try { // store the slice file into the zip mZip.AddEntry(imname, ms); // find the slices node in the top level XmlNode slicesnode = mManifest.FindSection(mManifest.m_toplevel, "Slices"); if (slicesnode == null) // no slice node { //create one slicesnode = mManifest.AddSection(mManifest.m_toplevel, "Slices"); } //add the slice file name into the manifest XmlNode curslice = mManifest.AddSection(slicesnode, "Slice"); mManifest.SetParameter(curslice, "name", imname); } catch (Exception ex) { DebugLogger.Instance().LogError(ex); } return(false); }
/// <summary> /// Save the entire scene into a zip file with a manifest /// This file will later be re-used to store png slicee, gcode & svg /// </summary> /// <param name="scenename"></param> /// <returns></returns> public bool Save(string scenefilename) { try { UVDLPApp.Instance().SceneFileName = scenefilename; // open a zip file with the scenename // iterate through all objects in engine string xmlname = "manifest.xml"; XmlHelper manifest = new XmlHelper(); //start the doc with no filename, becasue we're saving to a memory stream manifest.StartNew("", "manifest"); //start a new stream to store the manifest file MemoryStream manifeststream = new MemoryStream(); //create a new zip file ZipFile zip = new ZipFile(); //get the top-level node in the manifest //XmlNode mc = manifest.m_toplevel; // Add in a section for GCode if present XmlNode gcn = manifest.AddSection(manifest.m_toplevel, "GCode"); if (UVDLPApp.Instance().m_gcode != null) { //create the name of the gcode file String GCodeFileName = Path.GetFileNameWithoutExtension(scenefilename) + ".gcode"; manifest.SetParameter(gcn, "filename", GCodeFileName); Stream gcs = new MemoryStream(); //save to memory stream UVDLPApp.Instance().m_gcode.Save(gcs); //rewind gcs.Seek(0, SeekOrigin.Begin); //create new zip entry zip.AddEntry(GCodeFileName, gcs); } XmlNode mc = manifest.AddSection(manifest.m_toplevel, "Models"); //we need to make sure that only unique names are put in the zipentry // cloned objects yield the same name List <string> m_uniquenames = new List <string>(); // we can adda 4-5 digit code to the end here to make sure names are unique int id = 0; string idstr; foreach (Object3d obj in UVDLPApp.Instance().m_engine3d.m_objects) { //create a unique id to post-fix item names id++; idstr = string.Format("{0:0000}", id); idstr = "_" + idstr; //create a new memory stream MemoryStream ms = new MemoryStream(); //save the object to the memory stream obj.SaveSTL_Binary(ref ms); //rewind the stream to the beginning ms.Seek(0, SeekOrigin.Begin); //get the file name with no extension string objname = Path.GetFileNameWithoutExtension(obj.Name); //spaces cause this to blow up too objname = objname.Replace(' ', '_'); // add a value to the end of the string to make sure it's a unique name objname = objname + idstr; string objnameNE = objname; objname += ".stl"; // stl file zip.AddEntry(objname, ms); //create an entry for this object, using the object name with no extension //save anything special about it //XmlNode objnode = manifest.AddSection(mc, objnameNE); XmlNode objnode = manifest.AddSection(mc, "model"); manifest.SetParameter(objnode, "name", objnameNE); manifest.SetParameter(objnode, "tag", obj.tag); if (obj.tag != Object3d.OBJ_NORMAL && obj.m_parrent != null) { // note it's parent name in the entry manifest.SetParameter(objnode, "parent", Path.GetFileNameWithoutExtension(obj.m_parrent.Name)); } } //save the gcode //save the XML document to memorystream manifest.Save(1, ref manifeststream); manifeststream.Seek(0, SeekOrigin.Begin); //manifeststream. //save the memorystream for the xml metadata manifest into the zip file zip.AddEntry(xmlname, manifeststream); //save the zip file zip.Save(scenefilename); return(true); } catch (Exception ex) { DebugLogger.Instance().LogError(ex); } return(false); }