// 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);
 }
        public bool Save(string filename)
        {
            bool retval = false;
            m_filename = filename;
            m_name = Path.GetFileNameWithoutExtension(filename);
            XmlHelper xh = new XmlHelper();
            // bool fileExist = xh.Start(m_filename, "MachineConfig");
            //bool fileExist = false;
            xh.StartNew(m_filename, "MachineConfig");
            XmlNode mc = xh.m_toplevel;
            xh.SetParameter(mc, "PlatformXSize", m_PlatXSize);
            xh.SetParameter(mc, "PlatformYSize", m_PlatYSize);
            xh.SetParameter(mc, "PlatformZSize", m_PlatZSize);
            xh.SetParameter(mc, "MaxXFeedRate", m_XMaxFeedrate);
            xh.SetParameter(mc, "MaxYFeedRate", m_YMaxFeedrate);
            xh.SetParameter(mc, "MaxZFeedRate", m_ZMaxFeedrate);
            xh.SetParameter(mc, "XRenderSize", XRenderSize);
            xh.SetParameter(mc, "YRenderSize", YRenderSize);
            xh.SetParameter(mc, "DisplayedControls", MachineControls);

            xh.SetParameter(mc, "MachineType", m_machinetype);
            xh.SetParameter(mc, "MultiMonType", m_multimontype);

            if (m_driverconfig.Save(xh, mc))
            {
                retval = true;
            }
            // save all the monitor configurations
            foreach (MonitorConfig monc in m_lstMonitorconfigs) 
            {
                monc.Save(xh, mc);
            }
            //m_monitorconfig.Save(xh, mc);
            xh.Save(FILE_VERSION);
            return retval;
        }
Exemple #3
0
 public bool Save(String filename)
 {
     m_filename = filename;
     XmlHelper xh = new XmlHelper();
     xh.StartNew(filename, "SliceBuildConfig");
     SaveInternal(ref xh);
     try
     {
         xh.Save(FILE_VERSION);
     }
     catch (Exception ex)
     {
         DebugLogger.Instance().LogRecord(ex.Message);
         return false;
     }
     return true;
 }
Exemple #4
0
 /// <summary>
 /// This function assumes that the file has already been saved
 /// after setting the variable, it will re-save the file
 /// </summary>
 /// <param name="varname"></param>
 /// <param name="value"></param>
 public void SetStringVar(string varname, string value)
 {
     //m_filename = filename;
     XmlHelper xh = new XmlHelper();
     xh.StartNew(m_filename, "SliceBuildConfig");
     SaveInternal(ref xh);
     //save the var
     XmlNode sbc = xh.m_toplevel;
     xh.SetParameter(sbc, varname, value);
     try
     {
         xh.Save(FILE_VERSION);
     }
     catch (Exception ex)
     {
         DebugLogger.Instance().LogRecord(ex.Message);
     }
 }
 /// <summary>
 /// this function will tkae the manifest that is in this object and write it to the zip file
 /// this is an atomic operation the zip file will not be held open
 /// </summary>
 /// <returns></returns>
 public bool UpdateManifest(string scenefilename)
 {
     try
     {
         using (ZipFile tmpzip = ZipFile.Read(scenefilename))
         {
             string xmlname = "manifest.xml";
             //remove the old manifest entry
             try
             {
                 tmpzip.RemoveEntry(xmlname);
             }
             catch (Exception)
             {
                 DebugLogger.Instance().LogInfo("Creating new manifest for scene file");
                 // might not be in the file
             }
             //create a new memory stream to store the manifest file
             MemoryStream manifeststream = new MemoryStream();
             //store the modified manifest stream
             ZipEntry manifestentry = new ZipEntry();
             //save the XML document to memorystream
             if (mManifest != null)
             {
                 //save the manifest file to a memory stream
                 mManifest.Save(1, ref manifeststream);
                 //rewind to the beginning
                 manifeststream.Seek(0, SeekOrigin.Begin);
                 //save the memorystream for the xml metadata manifest into the zip file
                 tmpzip.AddEntry(xmlname, manifeststream);
                 //save the file
                 tmpzip.Save();
             }
             else
             {
                 //no existing manifest, start a new one
                 mManifest = new XmlHelper();
                 mManifest.StartNew("", "manifest");
                 tmpzip.Save();
             }
         } // end of using statement ensures closure of file
         return true;
     }
     catch (Exception ex)
     {
        // m
         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 SaveModelsIntoScene(string scenefilename)
        {
            try
            {
                // get the scene name
                UVDLPApp.Instance().SceneFileName = scenefilename;
               // MemoryStream manifeststream = new MemoryStream(); ;
                //string xmlname = "manifest.xml";
                ZipFile mZip = null;
                bool newfile = false;
                //check to see if the file already exists
                if (File.Exists(scenefilename))
                {

                    RemoveResourcesFromFile(scenefilename, "Models", ".stl|.obj|.amf|.dxf");
                    LoadManifest(scenefilename); // reload the manifest
                    mZip = ZipFile.Read(scenefilename);
                }
                else
                {
                    mManifest = new XmlHelper();
                    mManifest.StartNew("", "manifest");
                    mZip = new ZipFile();
                    newfile = true;

                }

                XmlNode mc = null;
                //find or create
                mc = mManifest.FindSection(mManifest.m_toplevel, "Models");
                if(mc == null)
                    mc = mManifest.AddSection(mManifest.m_toplevel, "Models");

                using (mZip)
                {
                    //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

                        mZip.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 = mManifest.AddSection(mc, "model");
                        mManifest.SetParameter(objnode, "name", objnameNE);
                        mManifest.SetParameter(objnode, "tag", obj.tag);
                        if (obj.tag != Object3d.OBJ_NORMAL && obj.m_parent != null)
                        {
                            // note it's parent name in the entry
                            mManifest.SetParameter(objnode, "parent", Path.GetFileNameWithoutExtension(obj.m_parent.Name));
                        }
                    }
                    if (newfile)
                    {
                        mZip.Save(scenefilename);
                    }
                    else
                    {
                        mZip.Save();
                    }
                } // end using block. mZip is still in scope, but should be closed here...

                UpdateManifest(scenefilename);
                DebugLogger.Instance().LogInfo("Saved scene into " + scenefilename);
                return true;
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex);
            }
            return false;
        }
 /// <summary>
 /// This will open the zip file
 /// load the manifest file into this object
 /// and close the zip file
 /// </summary>
 /// <param name="scenefilename"></param>
 /// <returns></returns>
 public bool LoadManifest(string scenefilename)
 {
     try
     {
         using (ZipFile tmpZip = ZipFile.Read(scenefilename))
         {
             //open the manifest file
             string xmlname = "manifest.xml";
             ZipEntry manifestentry = tmpZip[xmlname];
             //get memory stream
             MemoryStream manistream = new MemoryStream();
             //extract the stream
             manifestentry.Extract(manistream);
             //read from stream
             manistream.Seek(0, SeekOrigin.Begin); // rewind the stream for reading
             //create a new XMLHelper to load the stream into
             mManifest = new XmlHelper();
             //load the stream
             mManifest.LoadFromStream(manistream, "manifest");
         } // the end of this using block should close the zip file
         return true;
     }
     catch (Exception ex)
     {
         mManifest = new XmlHelper();
         mManifest.StartNew("", "manifest");
         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 SaveOld(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;
        }
        /// <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
            {
                // get the scene name
                UVDLPApp.Instance().SceneFileName = scenefilename;
                MemoryStream manifeststream = new MemoryStream(); ;
                string xmlname = "manifest.xml";
                //check to see if the file already exists
                if (File.Exists(scenefilename))
                {

                    RemoveExistingModels(scenefilename); // opens file, removes models out of file and manifest, and closes
                    // open the existing file and open up the manifest,
                    if (!OpenSceneFile(scenefilename)) 
                    {
                        DebugLogger.Instance().LogError("Could not open existing scene file for update");
                        return false;
                    }
                }
                else 
                {                    
                    mManifest = new XmlHelper();
                    mManifest.StartNew("", "manifest");                    
                    mZip = new ZipFile();
                    
                }

                XmlNode mc = null;
                //find or create
                mc = mManifest.FindSection(mManifest.m_toplevel, "Models");
                if(mc == null)
                    mc = mManifest.AddSection(mManifest.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

                    mZip.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 = mManifest.AddSection(mc, "model");
                    mManifest.SetParameter(objnode, "name", objnameNE);
                    mManifest.SetParameter(objnode, "tag", obj.tag);
                    if (obj.tag != Object3d.OBJ_NORMAL && obj.m_parrent != null)
                    {
                        // note it's parent name in the entry
                        mManifest.SetParameter(objnode, "parent", Path.GetFileNameWithoutExtension(obj.m_parrent.Name));
                    }
                }
                //save the gcode

                //save the XML document to memorystream
                mManifest.Save(1, ref manifeststream);
                manifeststream.Seek(0, SeekOrigin.Begin);
                //remove the old one if present
                if (mZip[xmlname] != null) 
                {
                    mZip.RemoveEntry(xmlname);
                }
                //save the memorystream for the xml metadata manifest into the zip file
                mZip.AddEntry(xmlname, manifeststream);
                //save the zip file
                mZip.Save(scenefilename);
                mZip.Dispose();
                mZip = null; 
                return true;
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex);
            }
            return false;
        }