コード例 #1
0
        public bool Load(string scenefilename) 
        {
            try
            {
                UVDLPApp.Instance().SceneFileName = scenefilename;

                mZip = ZipFile.Read(scenefilename);
                string xmlname = "manifest.xml";
                OpenSceneFile(scenefilename);

                //examine manifest
                //find the node with models
                XmlNode topnode = mManifest.m_toplevel;

                XmlNode models = mManifest.FindSection(topnode, "Models");
                List<XmlNode> modelnodes = mManifest.FindAllChildElement(models, "model");
               // bool supportLoaded = false;
                foreach (XmlNode nd in modelnodes) 
                {
                    string name = mManifest.GetString(nd, "name", "noname");
                    string modstlname = name + ".stl";
                    int tag = mManifest.GetInt(nd, "tag", 0);
                    ZipEntry modelentry = mZip[modstlname]; // the model name will have the _XXXX on the end with the stl extension
                    MemoryStream modstr = new MemoryStream();
                    modelentry.Extract(modstr);
                    //rewind to beginning
                    modstr.Seek(0, SeekOrigin.Begin);
                    //fix the name
                    name = name.Substring(0, name.Length - 5);// get rid of the _XXXX at the end
                    string parentName = mManifest.GetString(nd, "parent", "noname");
                    Object3d obj, tmpObj;
                    switch (tag)
                    {
                        case Object3d.OBJ_SUPPORT:
                        case Object3d.OBJ_SUPPORT_BASE:
                            if (tag == Object3d.OBJ_SUPPORT)
                                obj = (Object3d)(new Support());
                            else
                                obj = (Object3d)(new SupportBase());
                            //load the model
                            obj.LoadSTL_Binary(modstr, name);
                            //add to the 3d engine
                            UVDLPApp.Instance().m_engine3d.AddObject(obj);
                            //set the tag
                            obj.tag = tag;
                            obj.SetColor(System.Drawing.Color.Yellow);
                            //find and set the parent
                            tmpObj = UVDLPApp.Instance().m_engine3d.Find(parentName);
                            if (tmpObj != null)
                            {
                                tmpObj.AddSupport(obj);
                            }
                            //supportLoaded = true;
                            break;

                        default:
                            //load as normal object
                            obj = new Object3d();
                            //load the model
                            obj.LoadSTL_Binary((MemoryStream)modstr, name);
                            //add to the 3d engine
                            UVDLPApp.Instance().m_engine3d.AddObject(obj);
                            //set the tag
                            obj.tag = tag;
                            break;
                    }
                }
                CloseSceneFile(true);
                UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eModelAdded, "Scene loaded");
                return true;
            }
            catch (Exception ex) 
            {
                DebugLogger.Instance().LogError(ex);
                return false;
            }
        }
コード例 #2
0
        public bool LoadSceneFile(string scenefilename)
        {
            try
            {
                UVDLPApp.Instance().SceneFileName = scenefilename;
                LoadManifest(scenefilename);
                using (ZipFile mZip = ZipFile.Read(scenefilename))
                {

                    //examine manifest
                    //find the node with models
                    XmlNode topnode = mManifest.m_toplevel;

                    //load gcode if present
                    XmlNode gcn = mManifest.FindSection(mManifest.m_toplevel, "GCode");
                    //get the name of the gcode file
                    string gcodename = mManifest.GetString(gcn, "name", "none");
                    if (!gcodename.Equals("none"))
                    {
                        //open the zip
                        ZipEntry gcodeentry = mZip[gcodename];
                        MemoryStream gcstr = new MemoryStream();
                        gcodeentry.Extract(gcstr);
                        //rewind to beginning
                        gcstr.Seek(0, SeekOrigin.Begin);
                        GCodeFile gcf = new GCodeFile(gcstr);
                        UVDLPApp.Instance().m_gcode = gcf;
                        UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eGCodeLoaded, "GCode Loaded ");
                    }
                    else
                    {
                        UVDLPApp.Instance().m_gcode = new GCodeFile(""); // empty
                    }

                    // load slice profile if present
                    XmlNode spn = mManifest.FindSection(mManifest.m_toplevel, "SliceProfile");
                    string sliceprofilename = mManifest.GetString(spn, "name", "none");
                    if (!sliceprofilename.Equals("none"))
                    {
                        ZipEntry gcodeentry = mZip[sliceprofilename];
                        MemoryStream gcstr = new MemoryStream();
                        gcodeentry.Extract(gcstr);
                        //rewind to beginning
                        gcstr.Seek(0, SeekOrigin.Begin);
                        //GCodeFile gcf = new GCodeFile(gcstr);
                        UVDLPApp.Instance().m_buildparms = new SliceBuildConfig();
                        UVDLPApp.Instance().m_buildparms.Load(gcstr, sliceprofilename);
                        //create a new slice file based off of the build and slicing parameters
                        UVDLPApp.Instance().m_slicefile = new SliceFile(UVDLPApp.Instance().m_buildparms);
                        UVDLPApp.Instance().m_slicefile.m_mode = SliceFile.SFMode.eLoaded;
                        UVDLPApp.Instance().m_slicer.SliceFile = UVDLPApp.Instance().m_slicefile;
                        UVDLPApp.Instance().m_slicefile.NumSlices = UVDLPApp.Instance().m_slicer.GetNumberOfSlices(UVDLPApp.Instance().m_buildparms);
                        //raise the event to indicate it's loaded
                        UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eSliceProfileChanged, "Slice Profile loaded");
                        UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eSlicedLoaded, "Slice Profile loaded");

                    }

                    // now load the models
                    XmlNode models = mManifest.FindSection(topnode, "Models");
                    List<XmlNode> modelnodes = mManifest.FindAllChildElement(models, "model");
                    // bool supportLoaded = false;
                    foreach (XmlNode nd in modelnodes)
                    {
                        string name = mManifest.GetString(nd, "name", "noname");
                        string modstlname = name + ".stl";
                        int tag = mManifest.GetInt(nd, "tag", 0);
                        ZipEntry modelentry = mZip[modstlname]; // the model name will have the _XXXX on the end with the stl extension
                        MemoryStream modstr = new MemoryStream();
                        modelentry.Extract(modstr);
                        //rewind to beginning
                        modstr.Seek(0, SeekOrigin.Begin);
                        //fix the name
                        name = name.Substring(0, name.Length - 5);// get rid of the _XXXX at the end
                        string parentName = mManifest.GetString(nd, "parent", "noname");
                        Object3d obj, tmpObj;
                        switch (tag)
                        {
                            case Object3d.OBJ_SUPPORT:
                            case Object3d.OBJ_SUPPORT_BASE:
                                if (tag == Object3d.OBJ_SUPPORT)
                                    obj = (Object3d)(new Support());
                                else
                                    obj = (Object3d)(new SupportBase());
                                //load the model
                                obj.LoadSTL_Binary(modstr, name);
                                //add to the 3d engine
                                UVDLPApp.Instance().m_engine3d.AddObject(obj);
                                //set the tag
                                obj.tag = tag;
                                obj.SetColor(System.Drawing.Color.Yellow);
                                //find and set the parent
                                tmpObj = UVDLPApp.Instance().m_engine3d.Find(parentName);
                                if (tmpObj != null)
                                {
                                    tmpObj.AddSupport(obj);
                                }
                                //supportLoaded = true;
                                break;

                            default:
                                //load as normal object
                                obj = new Object3d();
                                //load the model
                                obj.LoadSTL_Binary((MemoryStream)modstr, name);
                                //add to the 3d engine
                                UVDLPApp.Instance().m_engine3d.AddObject(obj);
                                //set the tag
                                obj.tag = tag;
                                break;
                        }
                    }
                }

                UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eModelAdded, "Scene loaded");
                return true;
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex);
                return false;
            }
        }
コード例 #3
0
        public bool Load(string scenename)
        {
            try
            {
                ZipFile zip = ZipFile.Read(scenename);
                string xmlname = "manifest.xml";
                ZipEntry manifestentry = zip[xmlname];
                //create new manifest xml doc
                XmlHelper manifest = new XmlHelper();
                //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
                manifest.LoadFromStream(manistream, "manifest");
                //examine manifest
                //find the node with models
                XmlNode topnode = manifest.m_toplevel;
                XmlNode models = manifest.FindSection(topnode, "Models");
                List<XmlNode> modelnodes = manifest.FindAllChildElement(models, "model");
                foreach (XmlNode nd in modelnodes)
                {
                    string name = manifest.GetString(nd, "name", "noname");
                    string modstlname = name + ".stl";
                    int tag = manifest.GetInt(nd, "tag", 0);
                    ZipEntry modelentry = zip[modstlname]; // the model name will have the _XXXX on the end with the stl extension
                    MemoryStream modstr = new MemoryStream();
                    modelentry.Extract(modstr);
                    //rewind to beginning
                    modstr.Seek(0, SeekOrigin.Begin);
                    //fix the name
                    name = name.Substring(0, name.Length - 5);// get rid of the _XXXX at the end
                    if (tag == Object3d.OBJ_SUPPORT)
                    {
                        Support s = new Support();
                        //load the model
                        s.LoadSTL_Binary(modstr, name);
                        //add to the 3d engine
                        UVDLPApp.Instance().m_engine3d.AddObject(s);
                        //set the tag
                        s.tag = tag;
                        string parent = manifest.GetString(nd, "parent", "noname");
                        s.SetColor(System.Drawing.Color.Yellow);
                        //find and set the parent
                        Object3d tmp = UVDLPApp.Instance().m_engine3d.Find(parent);
                        if (tmp != null)
                        {
                            tmp.AddSupport(s);
                        }
                    }
                    else
                    {
                        //load as normal object
                        Object3d obj = new Object3d();
                        //load the model
                        obj.LoadSTL_Binary((MemoryStream)modstr, name);
                        //add to the 3d engine
                        UVDLPApp.Instance().m_engine3d.AddObject(obj);
                        //set the tag
                        obj.tag = tag;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex);
                return false;
            }
        }