/// <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 void AddSceneFileShouldAddSceneFile()
        {
            SceneFile sf = new SceneFile {
                SceneID = 1, FileID = 1
            };

            using (var ctx = new AviDBContext(options))
            {
                IAviRepo repo = new AviRepoDB(ctx);
                repo.AddSceneFile(sf);
            }
            using (var assertCtx = new AviDBContext(options))
            {
                var result = assertCtx.SceneFiles.FirstOrDefault(_sf => _sf.ID == sf.ID);
                Assert.NotNull(result);
                Assert.Equal(1, result.SceneID);
                Assert.Equal(1, result.FileID);
            }
        }
示例#3
0
        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;
            }
        }
 public void LoadSTLModel_Click(object sender, object e)
 {
     openFileDialog1.FileName = "";
     //openFileDialog1.Filter = "3D Model Files (*.stl;*.obj;*.3ds;*.amf)|*.stl;*.obj;*.3ds;*.amf|Scene files (*.cws)|*.cws";
     openFileDialog1.Filter = "3D Model Files (*.stl;*.obj;*.3ds;*.amf)|*.stl;*.obj;*.3ds;*.amf|Scene files (*." + SceneFileExt + ")|*." + SceneFileExt;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         foreach (string filename in openFileDialog1.FileNames)
         {
             if (filename.Contains("." + SceneFileExt))
             {
                 //scene file
                 if (SceneFile.Instance().LoadSceneFile(filename))
                 {
                     //set up for newly loaded scene
                     //load gcode
                     UVDLPApp.Instance().PostLoadScene();
                     //raise events
                     //load slicing info?
                     UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eReDraw, "");
                 }
                 else
                 {
                     DebugLogger.Instance().LogError("Error loading scene file : " + filename);
                 }
             }
             else
             {
                 if (UVDLPApp.Instance().LoadModel(filename) == false)
                 {
                     DebugLogger.Instance().LogError("Error loading object file : " + filename);
                 }
                 else
                 {
                     //chkWireframe.Checked = false;
                     //ctl3DView1.UpdateObjectInfo();
                 }
             }
         }
     }
 }
        public void SaveScene(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new MethodInvoker(delegate() { SaveScene(sender, e); }));
            }
            else
            {
                //saveFileDialog1.Filter = "Scene files (*.cws)|*.cws|STL File (*.stl)|*.stl";
                saveFileDialog1.Filter      = "Scene files (*." + SceneFileExt + ")|*." + SceneFileExt + "|STL File (*.stl)|*.stl";
                saveFileDialog1.FilterIndex = 0;
                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    //check the filter index
                    switch (saveFileDialog1.FilterIndex) // index starts at 1 instead of 0
                    {
                    case 1:
                        SceneFile.Instance().SaveModelsIntoScene(saveFileDialog1.FileName);
                        if (UVDLPApp.Instance().m_buildparms.exportpreview != PreviewGenerator.ePreview.None)
                        {
                            PreviewGenerator pg = new PreviewGenerator();
                            pg.ViewAngle = UVDLPApp.Instance().m_buildparms.exportpreview;
                            Bitmap preview = pg.GeneratePreview(512, 512);
                            SceneFile.Instance().AddPreviewImage(UVDLPApp.Instance().SceneFileName, preview, "Default", "ScenePreview.png");
                        }
                        UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eSceneSaved, "cws");
                        break;

                    case 2:
                        //stl file
                        UVDLPApp.Instance().CalcScene();     // calc the scene object
                        UVDLPApp.Instance().Scene.SaveSTL_Binary(saveFileDialog1.FileName);
                        UVDLPApp.Instance().Scene.m_fullname = saveFileDialog1.FileName;
                        UVDLPApp.Instance().RaiseAppEvent(eAppEvent.eSceneSaved, "stl");
                        break;
                    }
                }
            }
        }
示例#6
0
 public SceneFile AddSceneFile(SceneFile newSF)
 {
     _context.SceneFiles.Add(newSF);
     _context.SaveChanges();
     return(newSF);
 }
示例#7
0
 public SceneFile AddSceneFile(SceneFile newSF)
 {
     return(_repo.AddSceneFile(newSF));
 }
示例#8
0
        /// <summary>
        /// Loads the Scene from the XML file located at the parameter passed into
        /// the constructor (sceneFileLocation). An array of Controllers and LightPoints
        /// are generated for each valid controller.
        /// </summary>
        /// <param name="sceneFileLocation">The location of the Scene file to be loaded</param>
        public void LoadScene(string sceneFileLocation)
        {
            try
            {
                SceneFile = XDocument.Load(sceneFileLocation);                       // loads XML document from file location
                XNamespace ns      = SceneFile.Root.GetDefaultNamespace();           // get the namespace being used in the XML document
                var        routers = SceneFile.Descendants(ns + CONTROLLER_ELEMENT); // get all routers
                Routers = new Router[routers.Count()];                               // initialise array of controllers

                int routerCounter = 0;

                // find min and madoubleoordinates
                MinX = routers.Descendants(ns + LIGHT_ELEMENT).Min(e => (double)e.Attribute("x"));
                MaxX = routers.Descendants(ns + LIGHT_ELEMENT).Max(e => (double)e.Attribute("x"));
                MinY = routers.Descendants(ns + LIGHT_ELEMENT).Min(e => (double)e.Attribute("y"));
                MaxY = routers.Descendants(ns + LIGHT_ELEMENT).Max(e => (double)e.Attribute("y"));

                VideoBufferWidth  = (int)MaxX * VIDEO_BUFFER_RESOLUTION + 1; //TODO: Fix the 2x videobuffer resolution
                VideoBufferHeight = (int)MaxY * VIDEO_BUFFER_RESOLUTION + 1;

                Console.WriteLine("VBW: {0}, VBH: {1}, maxX: {2}, maxY: {3}", VideoBufferWidth, VideoBufferHeight, MaxX, MaxY);

                Console.WriteLine("Namespace: {0}", ns);
                Console.WriteLine("Loading {0} Controllers", routers.Count());
                Console.WriteLine("Total number of LightPoints: {0}", routers.Descendants(ns + LIGHT_ELEMENT).Count());
                Console.WriteLine("MinX: {0}, MaxX: {1}, MinY: {2}, MaxY: {3}", MinX, MaxX, MinY, MaxY);
                Console.WriteLine("VidideoBufferWidth: {0}, VideoBufferHeight: {1}", VideoBufferWidth, VideoBufferHeight);

                // loop through all routers and load their lights
                foreach (var router in routers)
                {
                    int          controllerId;
                    var          lights      = router.Descendants(ns + LIGHT_ELEMENT);
                    LightPoint[] lightPoints = new LightPoint[lights.Count()];

                    Console.WriteLine("Router {0} has a total of {1} LightPoints", routerCounter + 1, lights.Count());

                    string name     = router.Attribute("name")?.Value;
                    string hostname = router.Attribute("hostname")?.Value;
                    int    port     = Int32.Parse(router.Attribute("port")?.Value);
                    Routers[routerCounter] = new Router(name, hostname, port, UdpClient);

                    // loop through all lightpoints on specific controller and create an instance
                    foreach (var light in lights)
                    {
                        controllerId = SeparateIDBytes(Int32.Parse(light.Attribute("id")?.Value))[1];

                        byte   lightId = SeparateIDBytes(Int32.Parse(light.Attribute("id")?.Value))[0];
                        double x       = Double.Parse(light.Attribute("x")?.Value);
                        double y       = Double.Parse(light.Attribute("y")?.Value);
                        double z       = Double.Parse(light.Attribute("z")?.Value);

                        // find controller in router
                        //TODO: This could be tidied up if the controllers are always in order? Ask Joe
                        Controller controller = Routers[routerCounter].getControllerByID(controllerId); // try to load the controller by its ID

                        // check if controller exists yet
                        if (controller == null)
                        {
                            controller = Routers[routerCounter].addController(controllerId); // if not, create a new one with the provided ID
                        }
                        // add new LightPopint to controller
                        LightPoint lightPoint = controller.addLightPoint(lightId, x, y, z);
                        lightPoint.CaluclateProjectedCoordinates(MinX, MaxX, MinY, MaxY, this.VideoBufferWidth, this.VideoBufferHeight); // calculate the projected coordinates given the min and max of each
                    }

                    // get max controller count for render loop
                    if (Routers[routerCounter].Controllers.Count > MaxControllerCount)
                    {
                        MaxControllerCount = Routers[routerCounter].Controllers.Count;
                    }

                    routerCounter++;
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("Scene file not found at {0}", sceneFileLocation);
            }
            catch (XmlException e)
            {
                Console.WriteLine("Error reading XML in Scene file at {0}", sceneFileLocation);
            }
            catch (Exception e)
            {
                //TODO: Throw a SceneFileError Exception to end program when an invalid scene was passed
                Console.WriteLine("Error loading Scene file at {0}", sceneFileLocation);
            }
        }
示例#9
0
        /// <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);
            }
        }
示例#10
0
        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");

                    if (MessageBox.Show("The Scene must be saved before exporting slices", "Please Save Scene", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        UVDLPApp.Instance().m_mainform.SaveScene(null, null);
                    }

                    //MessageBox.Show(en.Slicer_SliceStarted_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 (!string.IsNullOrWhiteSpace(UVDLPApp.Instance().SceneFileName)) // check again to make sure we've really got a name
                if (UVDLPApp.Instance().SceneFileName != null && 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);
        }
 private SceneFile CreateSceneFile(BinaryReader Reader)
 {
     SceneFile file = new SceneFile();
     file.SceneFileName = NTString(Encoding.ASCII.GetString(Reader.ReadBytes(260)));
     file.Location = new Point(Reader.ReadInt32(), Reader.ReadInt32());
     using (BinaryReader reader = new BinaryReader(new FileStream(ServerBase.Constants.DataHolderPath + file.SceneFileName, FileMode.Open)))
     {
         ScenePart[] partArray = new ScenePart[reader.ReadInt32()];
         for (int i = 0; i < partArray.Length; i++)
         {
             reader.BaseStream.Seek(0x14cL, SeekOrigin.Current);
             partArray[i].Size = new Size(reader.ReadInt32(), reader.ReadInt32());
             reader.BaseStream.Seek(4L, SeekOrigin.Current);
             partArray[i].StartPosition = new Point(reader.ReadInt32(), reader.ReadInt32());
             reader.BaseStream.Seek(4L, SeekOrigin.Current);
             partArray[i].NoAccess = new bool[partArray[i].Size.Width, partArray[i].Size.Height];
             for (int j = 0; j < partArray[i].Size.Height; j++)
             {
                 for (int k = 0; k < partArray[i].Size.Width; k++)
                 {
                     partArray[i].NoAccess[k, j] = reader.ReadInt32() == 0;
                     reader.BaseStream.Seek(8L, SeekOrigin.Current);
                 }
             }
         }
         file.Parts = partArray;
     }
     return file;
 }