/*
         This is the main function to generate gcode files for the
         * already sliced model
         */
        public static GCodeFile Generate(SliceFile sf, MachineConfig pi)
        {
            String gcode;
            StringBuilder sb = new StringBuilder();
            PreProcessor pp = PreparePreprocessor(sf, pi);
            double zdist = 0.0;
               // double feedrate = pi.ZMaxFeedrate; // 10mm/min
            double liftfeed = sf.m_config.liftfeedrate;
            double retractfeed = sf.m_config.liftretractrate;
            double zdir = 1.0; // assume a bottom up machine
            int numbottom = sf.m_config.numfirstlayers;

            if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down)
            {
                zdir = -1.0;// top down machine, reverse the z direction
            }
            pp.SetVar("$ZDir", zdir);

            // append the build parameters as reference
            sb.Append(sf.m_config.ToString());
            sb.Append(";Number of Slices        =  " + sf.NumSlices.ToString() + "\r\n");

            sb.Append(pi.ToString());//add the machine build parameters string

            // append the header
            sb.Append(pp.Process(sf.m_config.HeaderCode));

            zdist = sf.m_config.ZThick;

            String firstlayerdelay = ";<Delay> " + sf.m_config.firstlayertime_ms + " \r\n";
            String layerdelay = ";<Delay> " + sf.m_config.layertime_ms + " \r\n";
            String blankdelay = ";<Delay> " + sf.m_config.blanktime_ms + " \r\n";

            String preSliceGCode = pp.Process(sf.m_config.PreSliceCode);
            String LiftGCode = pp.Process(sf.m_config.LiftCode);

            for (int c = 0; c < sf.NumSlices; c++)
            {
                sb.Append(preSliceGCode);//add in the pre-slice code
                // this is the marker the BuildManager uses to display the correct slice
                sb.Append(";<Slice> " + c + " \r\n");
                // add a pause for the UV resin to be set using this image
                if (c < numbottom)// check for the bottom layers
                {
                    sb.Append(firstlayerdelay);
                }
                else
                {
                    sb.Append(layerdelay);
                }
                sb.Append(";<Slice> Blank \r\n"); // show the blank layer
                sb.Append(LiftGCode); // append the pre-lift codes
            }
            //append the footer
            sb.Append(pp.Process(sf.m_config.FooterCode));
            gcode = sb.ToString();
            GCodeFile gc = new GCodeFile(gcode);
            return gc;
        }
        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:
                m_slicefile = sf;
                //generate the GCode
                m_gcode = GCodeGenerator.Generate(m_slicefile, m_printerinfo);

                path     = SliceFile.GetSliceFilePath(m_slicefile.modelname);
                fileName = Path.GetFileNameWithoutExtension(m_slicefile.modelname) + ".gcode";
                //see if we're exporting this to a zip file
                if (sf.m_config.m_exportopt.Contains("ZIP"))
                {
                    // open the existing zip file
                    //store the gcode
                    Stream stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(m_gcode.RawGCode));
                    String zpath  = path + ".zip";
                    if (!Utility.StoreInZip(zpath, fileName, stream))
                    {
                        DebugLogger.Instance().LogError("Could not store GCode in Zip " + zpath);
                    }
                }
                else      // or just to the disk
                {
                    String sdn = path + UVDLPApp.m_pathsep + fileName;
                    SaveGCode(sdn);
                }

                //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;
            }
        }
 private UVDLPApp()
 {
     m_appconfig           = new AppConfig();
     m_printerinfo         = new MachineConfig();
     m_buildparms          = new SliceBuildConfig();
     m_deviceinterface     = new DeviceInterface();
     m_buildmgr            = new BuildManager();
     m_slicer              = new Slicer();
     m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
     m_flexslice           = new FlexSlice();
     m_gcode            = new GCodeFile(""); // create a blank gcode to start with
     m_supportconfig    = new SupportConfig();
     m_supportgenerator = new SupportGenerator();
     m_supportgenerator.SupportEvent += new SupportGeneratorEvent(SupEvent);
 }
 /// <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");
 }
 private UVDLPApp()
 {
     m_appconfig           = new AppConfig();
     m_printerinfo         = new MachineConfig();
     m_buildparms          = new SliceBuildConfig();
     m_deviceinterface     = new DeviceInterface();
     m_buildmgr            = new BuildManager();
     m_slicer              = new Slicer();
     m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
     //m_flexslice = new FlexSlice();
     m_gcode            = new GCodeFile(""); // create a blank gcode to start with
     m_supportconfig    = new SupportConfig();
     m_supportgenerator = new SupportGenerator();
     m_supportgenerator.SupportEvent += new SupportGeneratorEvent(SupEvent);
     m_proj_cmd_lst = new prjcmdlst();
     m_plugins      = new List <IPlugin>(); // list of user plug-ins
     m_undoer       = new Undoer();
 }
Example #6
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;
            }
        }
        // This function is called to start the print job
        public void StartPrint(SliceFile sf, GCodeFile gcode)
        {
            if (m_printing)  // already printing
            {
                return;
            }

            m_printing         = true;
            m_buildstarttime   = new DateTime();
            m_buildstarttime   = DateTime.Now;
            estimatedbuildtime = EstimateBuildTime(gcode);
            StartBuildTimer();

            m_sf        = sf;          // set the slicefile for rendering
            m_gcode     = gcode;       // set the file
            m_state     = STATE_START; // set the state machine as started
            m_runthread = new Thread(new ThreadStart(BuildThread));
            m_running   = true;
            m_runthread.Start();
        }
Example #8
0
        void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers)
        {
            String path = "";
            switch (ev)
            {
                case Slicer.eSliceEvent.eSliceStarted:
                    // if we're exporting images
                    if (m_buildparms.exportimages)
                    {
                        // get the model name
                        String modelname = m_selectedobject.m_fullname;
                        // strip off the file extension
                        path = Path.GetDirectoryName(modelname);
                        path += UVDLPApp.m_pathsep;
                        path += Path.GetFileNameWithoutExtension(modelname);// strip off the file extension
                        if (!Directory.Exists(path)) // check and see if a directory of that name exists,
                        {
                            Directory.CreateDirectory(path);// if not, create it
                        }
                    }
                    break;
                case Slicer.eSliceEvent.eLayerSliced:
                    //save the rendered image slice
                    //render the slice

                    if (m_buildparms.exportimages)
                    {
                        // get the model name
                        String modelname = m_selectedobject.m_fullname;
                        // strip off the file extension
                        path = Path.GetDirectoryName(modelname);
                        path += UVDLPApp.m_pathsep;
                        path += Path.GetFileNameWithoutExtension(modelname);// strip off the file extension
                        Bitmap bmp = null;
                        String imagename = path + m_pathsep + Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}",layer) + ".png";
                        bmp = UVDLPApp.Instance().m_slicefile.RenderSlice(layer);
                        bmp.Save(imagename);
                    }
                    break;
                case Slicer.eSliceEvent.eSliceCompleted:
                    m_gcode = GCodeGenerator.Generate(m_slicefile, m_printerinfo);

                    //get the path of the current object file
                    path = Path.GetDirectoryName(m_selectedobject.m_fullname);
                    string fn = Path.GetFileNameWithoutExtension(m_selectedobject.m_fullname);
                    /*
                    if (!UVDLPApp.Instance().m_gcode.Save(path + UVDLPApp.m_pathsep + fn + ".gcode"))
                    {
                        DebugLogger.Instance().LogRecord("Cannot save GCode File " + path + m_pathsep + fn + ".gcode");
                    }
                    */
                    SaveGCode(path + UVDLPApp.m_pathsep + fn + ".gcode");
                    break;
                case Slicer.eSliceEvent.eSliceCancelled:
                    DebugLogger.Instance().LogRecord("Slicing Cancelled");
                    break;

            }
        }
        /*
         * GCode Process for building 3d DVP UV objects
         *
         * <Build Start>
         * <Slicing Comments> comments containing the slicing and building parameters
         * <Header Code> start.gcode - commands from this
         * file are inserted, they contain whatever intiailization sequences are need to initialize the machine
         * at this point, the build tray is in position to start printing a layer
         * <Layer Start>
         * Display the correct image slice for the current layer
         * Delay for <Layertime> to expose the UV resin
         * <Layer End>
         *
         *
         */

        /*
         * This is the main function to generate gcode files for the
         * already sliced model
         */
        public static GCodeFile Generate(SliceFile sf, MachineConfig pi)
        {
            String        gcode;
            StringBuilder sb    = new StringBuilder();
            double        zdist = 0.0;
            // double feedrate = pi.ZMaxFeedrate; // 10mm/min
            double liftfeed    = sf.m_config.liftfeedrate;
            double retractfeed = sf.m_config.liftretractrate;
            double zdir        = 1.0; // assume a bottom up machine
            int    numbottom   = sf.m_config.numfirstlayers;

            if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down)
            {
                zdir = -1.0;// top down machine, reverse the z direction
            }

            // append the build parameters as reference
            sb.Append(sf.m_config.ToString());

            // append the header
            sb.Append(sf.m_config.HeaderCode);

            String firstlayerdelay = "(<Delay> " + sf.m_config.firstlayertime_ms + " )\r\n";
            String layerdelay      = "(<Delay> " + sf.m_config.layertime_ms + " )\r\n";
            String blankdelay      = "(<Delay> " + sf.m_config.blanktime_ms + " )\r\n";

            zdist = sf.m_config.ZThick;

            for (int c = 0; c < sf.m_slices.Count; c++)
            {
                sb.Append(sf.m_config.PreSliceCode);//add in the pre-slice code
                // this is the marker the BuildManager uses to display the correct slice
                sb.Append("(<Slice> " + c + " )\r\n");
                // add a pause for the UV resin to be set using this image
                if (c < numbottom)// check for the bottom layers
                {
                    sb.Append(firstlayerdelay);
                }
                else
                {
                    sb.Append(layerdelay);
                }
                sb.Append("(<Slice> Blank )\r\n");  // show the blank layer
                sb.Append(sf.m_config.PreLiftCode); // append the pre-lift codes
                String tmpZU = String.Format("{0:0.00000}", (sf.m_config.liftdistance * zdir)).Replace(',', '.');
                String tmpZD = String.Format("{0:0.00000}", ((sf.m_config.liftdistance - zdist) * zdir * -1)).Replace(',', '.');

                if (sf.m_config.slidetiltval == 0.0) // tilt/slide is not used here
                {
                    sb.Append("G1 Z" + tmpZU + " F" + liftfeed + " (Lift) \r\n");
                    sb.Append("G1 Z" + tmpZD + " F" + retractfeed + " (End Lift) \r\n");
                }
                else // tilt/slide has a value, so it is used
                {
                    // format the X slide/tilt value
                    String tmpX1 = String.Format("{0:0.00000}", (sf.m_config.slidetiltval)).Replace(',', '.');
                    String tmpX2 = String.Format("{0:0.00000}", (sf.m_config.slidetiltval * -1)).Replace(',', '.');
                    sb.Append("G1 X" + tmpX1 + " Z" + tmpZU + " F" + liftfeed + " (Lift) \r\n");
                    sb.Append("G1 X" + tmpX2 + " Z" + tmpZD + " F" + retractfeed + " (End Lift) \r\n");
                }
                // append the post-lift codes
                sb.Append(sf.m_config.PostLiftCode);
                // add a delay for the lift sequence and the pre/post lift codes to execute
                sb.Append(blankdelay);
            }
            //append the footer
            sb.Append(sf.m_config.FooterCode);
            gcode = sb.ToString();
            GCodeFile gc = new GCodeFile(gcode);

            return(gc);
        }
        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;

            }
        }
        /*
         GCode Process for building 3d DVP UV objects

         * <Build Start>
         * <Slicing Comments> comments containing the slicing and building parameters
         * <Header Code> start.gcode - commands from this
         * file are inserted, they contain whatever intiailization sequences are need to initialize the machine
         * at this point, the build tray is in position to start printing a layer
         * <Layer Start>
         * Display the correct image slice for the current layer
         * Delay for <Layertime> to expose the UV resin
         * <Layer End>

        */
        /*
         This is the main function to generate gcode files for the
         * already sliced model
         */
        public static GCodeFile Generate(SliceFile sf, MachineConfig pi)
        {
            String gcode;
            StringBuilder sb = new StringBuilder();
            double zdist = 0.0;
               // double feedrate = pi.ZMaxFeedrate; // 10mm/min
            double liftfeed = sf.m_config.liftfeedrate;
            double retractfeed = sf.m_config.liftretractrate;
            double zdir = 1.0; // assume a bottom up machine
            int numbottom = sf.m_config.numfirstlayers;

            if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down)
            {
                zdir = -1.0;// top down machine, reverse the z direction
            }

            // append the build parameters as reference
            sb.Append(sf.m_config.ToString());
            sb.Append(";(Number of Slices        =  " + sf.NumSlices.ToString() + ")\r\n");

            sb.Append(pi.ToString());//add the machine build parameters string

            // append the header
            sb.Append(sf.m_config.HeaderCode);

            zdist = sf.m_config.ZThick;

            String firstlayerdelay = ";(<Delay> " + sf.m_config.firstlayertime_ms + " )\r\n";
            String layerdelay = ";(<Delay> " + sf.m_config.layertime_ms + " )\r\n";
            String blankdelay = ";(<Delay> " + sf.m_config.blanktime_ms + " )\r\n";
            String tmpZU = String.Format("{0:0.00000}", (sf.m_config.liftdistance * zdir)).Replace(',', '.');
            String tmpZD = String.Format("{0:0.00000}", ((sf.m_config.liftdistance - zdist) * zdir * -1)).Replace(',', '.');
            String tmpX1 = String.Format("{0:0.00000}", (sf.m_config.slidetiltval)).Replace(',', '.');
            String tmpX2 = String.Format("{0:0.00000}", (sf.m_config.slidetiltval * -1)).Replace(',', '.');

            for (int c = 0; c < sf.NumSlices; c++)
            {
                sb.Append(sf.m_config.PreSliceCode);//add in the pre-slice code
                // this is the marker the BuildManager uses to display the correct slice
                sb.Append(";(<Slice> " + c + " )\r\n");
                // add a pause for the UV resin to be set using this image
                if (c < numbottom)// check for the bottom layers
                {
                    sb.Append(firstlayerdelay);
                }
                else
                {
                    sb.Append(layerdelay);
                }
                sb.Append(";(<Slice> Blank )\r\n"); // show the blank layer
                sb.Append(sf.m_config.PreLiftCode); // append the pre-lift codes
                // I put the following two lines out of the loop to reduce calculationTime
                //String tmpZU = String.Format("{0:0.00000}", (sf.m_config.liftdistance * zdir)).Replace(',', '.');
                //String tmpZD = String.Format("{0:0.00000}", ((sf.m_config.liftdistance - zdist) * zdir * -1)).Replace(',', '.');
                if (sf.m_config.usemainliftgcode == true) // if you want to use the GCode from the MainLiftGCode-Tab
                {
                    sb.Append(sf.m_config.MainLiftCode);
                }
                else if (sf.m_config.slidetiltval == 0.0) // tilt/slide is not used here
                {
                    sb.Append("G1 Z" + tmpZU + " F" + liftfeed + " ;(Lift) \r\n");
                    sb.Append("G1 Z" + tmpZD + " F" + retractfeed + " ;(End Lift) \r\n");
                }
                else // tilt/slide has a value, so it is used
                {
                    // I put the following two lines out of the loop to reduce calculationTime
                    // format the X slide/tilt value
                    //String tmpX1 = String.Format("{0:0.00000}", (sf.m_config.slidetiltval)).Replace(',', '.');
                    //String tmpX2 = String.Format("{0:0.00000}", (sf.m_config.slidetiltval * -1)).Replace(',', '.');
                    sb.Append("G1 X" + tmpX1 + " Z" + tmpZU + " F" + liftfeed + " ;(Lift) \r\n");
                    sb.Append("G1 X" + tmpX2 + " Z" + tmpZD + " F" + retractfeed + " ;(End Lift) \r\n");
                }
                // add a delay for the lift sequence and the pre/post lift codes to execute
                sb.Append(blankdelay);
                // append the post-lift codes
                sb.Append(sf.m_config.PostLiftCode);
            }
            //append the footer
            sb.Append(sf.m_config.FooterCode);
            gcode = sb.ToString();
            GCodeFile gc = new GCodeFile(gcode);
            return gc;
        }
        /// <summary>
        /// This function will return the estimated build time for UV DLP print Jobs
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static String EstimateBuildTime(GCodeFile file)
        {
            int bt = 0; // in milliseconds
            bool done = false;
            int gidx = 0;
            while (!done)
            {
                if (gidx >= file.Lines.Length)
                {
                    done = true;
                    break;
                }

                String line = file.Lines[gidx++];
                if (line.Length > 0)
                {
                    // if the line is a comment, parse it to see if we need to take action
                    if (line.Contains("<Delay> "))// get the delay
                    {
                        int delay = getvarfromline(line);
                        bt += delay;
                    }
                }
            }
            TimeSpan ts = new TimeSpan();
            ts = TimeSpan.FromMilliseconds(bt);
            return String.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);
        }
        /// <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;
            }
        }
 // This function is called to start the print job
 public void StartPrint(SliceFile sf, GCodeFile gcode)
 {
     if (m_printing)  // already printing
         return;
     if (sf == null)
     {
         DebugLogger.Instance().LogRecord("No slice file, build cannot start");
         RaiseStatusEvent(ePrintStat.ePrintCancelled);
         return;
     }
     if (gcode == null)
     {
         DebugLogger.Instance().LogRecord("No gcode file, build cannot start");
         RaiseStatusEvent(ePrintStat.ePrintCancelled);
         return;
     }
     // we really need to map onto the events of the PrinterInterface to determine
     // important stuff like current z position, HBP temp, etc...
     m_printing = true;
     m_sf = sf; // set the slicefile for rendering
     m_gcode = gcode; // set the file
     m_state = STATE_START; // set the state machine as started
     m_runthread = new Thread(new ThreadStart(BuildThread));
     m_running = true;
     m_runthread.Start();
 }
        private ZipFile m_zip; // for storing image slices

        #endregion Fields

        #region Constructors

        private UVDLPApp()
        {
            m_appconfig = new AppConfig();
            m_printerinfo = new MachineConfig();
            m_buildparms = new SliceBuildConfig();
            m_deviceinterface = new DeviceInterface();
            m_buildmgr = new BuildManager();
            m_slicer = new Slicer();
            m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            m_flexslice = new FlexSlice();
            m_gcode = new GCodeFile(""); // create a blank gcode to start with
            m_supportconfig = new SupportConfig();
            m_supportgenerator = new SupportGenerator();
            m_supportgenerator.SupportEvent+= new SupportGeneratorEvent(SupEvent);
        }
Example #16
0
        /// <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)
                    {
                        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);
            }
        }
        // This function is called to start the print job
        public void StartPrint(SliceFile sf, GCodeFile gcode, bool snippet = false)
        {
            m_runningsnippet = snippet;

            if (m_printing)  // already printing
                return;
            //make sure to reset these
            m_pause_request = false;
            //m_cancel_request = false;

            m_printing = true;
            m_buildstarttime = new DateTime();
            m_buildstarttime = DateTime.Now;
            estimatedbuildtime = EstimateBuildTime(gcode);
            StartBuildTimer();

            m_sf = sf; // set the slicefile for rendering
            m_gcode = gcode; // set the file
            m_state = STATE_START; // set the state machine as started
            m_runthread = new Thread(new ThreadStart(BuildThread));
            m_running = true;
            m_runthread.Start();
        }
        void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers)
        {
            String path = "";
            switch (ev)
            {
                case Slicer.eSliceEvent.eSliceStarted:
                    // if we're exporting images
                    if (m_buildparms.exportimages)
                    {
                        m_zip = new ZipFile();
                        // get the model name, could be scene....
                        String modelname = m_selectedobject.m_fullname;
                        // strip off the file extension
                        path = Path.GetDirectoryName(modelname);
                        path += UVDLPApp.m_pathsep;
                        path += Path.GetFileNameWithoutExtension(modelname);// strip off the file extension
                        if (!Directory.Exists(path)) // check and see if a directory of that name exists,
                        {
                            Directory.CreateDirectory(path);// if not, create it
                        }
                    }
                    break;
                case Slicer.eSliceEvent.eLayerSliced:
                    //save the rendered image slice
                    //render the slice

                    if (m_buildparms.exportimages)
                    {
                        // get the model name
                        String modelname = m_selectedobject.m_fullname;
                        // strip off the file extension
                        path = Path.GetDirectoryName(modelname);
                        path += UVDLPApp.m_pathsep;
                        path += Path.GetFileNameWithoutExtension(modelname);// strip off the file extension
                        Bitmap bmp = null;
                        String imname = Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}",layer) + ".png";
                        String imagename = path + m_pathsep + imname;
                        bmp = UVDLPApp.Instance().m_slicefile.RenderSlice(layer);
                       // bmp.Save(imagename);
                        // create a memory stream for this to save into
                        MemoryStream ms = new MemoryStream();
                        bmp.Save(ms, ImageFormat.Png);
                        ms.Seek(0, SeekOrigin.Begin); // seek back to beginning
                        m_zip.AddEntry(imname, ms);
                    }

                    break;
                case Slicer.eSliceEvent.eSliceCompleted:

                    // save the zip file full of images
                    if (m_buildparms.exportimages)
                    {
                        String modelname = m_selectedobject.m_fullname;
                        // strip off the file extension
                        path = Path.GetDirectoryName(modelname);
                        path += UVDLPApp.m_pathsep;
                        path += Path.GetFileNameWithoutExtension(modelname);// strip off the file extension
                        path += ".zip";
                        m_zip.Save(path);
                    }

                    m_gcode = GCodeGenerator.Generate(m_slicefile, m_printerinfo);

                    //get the path of the current object file
                    path = Path.GetDirectoryName(m_selectedobject.m_fullname);
                    string fn = Path.GetFileNameWithoutExtension(m_selectedobject.m_fullname);
                    /*
                    if (!UVDLPApp.Instance().m_gcode.Save(path + UVDLPApp.m_pathsep + fn + ".gcode"))
                    {
                        DebugLogger.Instance().LogRecord("Cannot save GCode File " + path + m_pathsep + fn + ".gcode");
                    }
                    */
                    SaveGCode(path + UVDLPApp.m_pathsep + fn + ".gcode");
                    break;
                case Slicer.eSliceEvent.eSliceCancelled:
                    DebugLogger.Instance().LogRecord("Slicing Cancelled");
                    break;

            }
        }
Example #19
0
 private UVDLPApp()
 {
     m_callbackhandler = new CallbackHandler();
     m_appconfig = new AppConfig();
     m_printerinfo = new MachineConfig();
     m_buildparms = new SliceBuildConfig();
     m_deviceinterface = new DeviceInterface();
     m_buildmgr = new BuildManager();
     m_slicer = new Slicer();
     m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
     //m_dispmgr = DisplayManager.Instance(); // initialize the singleton for early event app binding
     //m_flexslice = new FlexSlice();
     m_gcode = new GCodeFile(""); // create a blank gcode to start with
     m_supportconfig = new SupportConfig();
     m_supportgenerator = new SupportGenerator();
     m_supportgenerator.SupportEvent+= new SupportGeneratorEvent(SupEvent);
     CSG.Instance().CSGEvent += new CSG.CSGEventDel(CSGEvent);
     m_proj_cmd_lst = new prjcmdlst();
     m_plugins = new List<PluginEntry>(); // list of user plug-ins
     m_undoer = new Undoer();
     m_2d_graphics = new C2DGraphics();
     m_gui_config = new GuiConfig();
 }
 private UVDLPApp()
 {
     m_appconfig = new AppConfig();
     m_printerinfo = new MachineConfig();
     m_buildparms = new SliceBuildConfig();
     m_deviceinterface = new DeviceInterface();
     m_buildmgr = new BuildManager();
     m_slicer = new Slicer();
     m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
     //m_flexslice = new FlexSlice();
     m_gcode = new GCodeFile(""); // create a blank gcode to start with
     m_supportconfig = new SupportConfig();
     m_supportgenerator = new SupportGenerator();
     m_supportgenerator.SupportEvent+= new SupportGeneratorEvent(SupEvent);
     CSG.Instance().CSGEvent += new CSG.CSGEventDel(CSGEvent);
     m_proj_cmd_lst = new prjcmdlst();
     m_plugins = new List<PluginEntry>(); // list of user plug-ins
     m_undoer = new Undoer();
 }
        /*
         GCode Process for building 3d DVP UV objects

         * <Build Start>
         * <Slicing Comments> comments containing the slicing and building parameters
         * <Header Code> start.gcode - commands from this
         * file are inserted, they contain whatever intiailization sequences are need to initialize the machine
         * at this point, the build tray is in position to start printing a layer
         * <Layer Start>
         * Display the correct image slice for the current layer
         * Delay for <Layertime> to expose the UV resin
         * <Layer End>

         Example:
         * G1 Z0.05 F10 (move to the layer position .05 mm distance)
         * (<Layer 0 >) (show the slice image layer)
         * (<Delay 1000 >) (pause to expose the layer, first layer time is longer)
         * (<Layer Blank >) (show the blank image layer now)
         * (pre- lift gcode goes here)
         * G1 Z5 F10    (Move up (or down) for the lift sequence)
         * G1 X20 F20   (Move the wiper)
         * G1 X-20 F20  (Move the wiper back)
         * G1 Z5 F10    (Move down (or up) for the lift sequence)
         * (post - lift gcode goes here)
         * (<Delay blanktime >) (the previous commands will all be run, this command will cause the build manager to delay before moving to the next layer)

         */
        /*
         This is the main function to generate gcode files for the
         * already sliced model
         */
        public static GCodeFile Generate(SliceFile sf, MachineConfig pi)
        {
            String gcode;
            StringBuilder sb = new StringBuilder();
            double zdist = 0.0;
            double feedrate = pi.ZMaxFeedrate; // 10mm/min
            double zdir = 1.0; // assume a bottom up machine
            int numbottom = sf.m_config.numfirstlayers;

            if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down)
            {
                zdir = -1.0;// top down machine, reverse the z direction
            }

            // append the build parameters as reference
            sb.Append(sf.m_config.ToString());

            // append the header
            sb.Append(sf.m_config.HeaderCode);

            String firstlayerdelay = "(<Delay> " + sf.m_config.firstlayertime_ms + " )\r\n";
            String layerdelay = "(<Delay> " + sf.m_config.layertime_ms + " )\r\n";
            String blankdelay = "(<Delay> " + sf.m_config.blanktime_ms + " )\r\n";

            zdist = sf.m_config.ZThick;

            for (int c = 0; c < sf.m_slices.Count; c++ )
            {
                //move the z axis to the right layer position
              //  sb.Append("G1 Z" + String.Format("{0:0.00000}", (zdist * zdir)) + " F" + feedrate + "\r\n");
                // this is the marker the BuildManager uses to display the correct slice
                sb.Append( "(<Slice> " + c + " )\r\n");
                // add a pause for the UV resin to be set using this image
                if (c < numbottom)// check for the bottom layers
                {
                    sb.Append(firstlayerdelay);
                }
                else
                {
                    sb.Append(layerdelay);
                }
                sb.Append("(<Slice> Blank )\r\n"); // show the blank layer
                sb.Append(sf.m_config.PreLiftCode); // append the pre-lift codes
                //do the lift
                sb.Append("G1 Z" + String.Format("{0:0.00000}", (sf.m_config.liftdistance * zdir)) + " F" + feedrate + " (Lift) \r\n");
                sb.Append(sf.m_config.PostLiftCode); // append the post-lift codes
                // move back from the lift
                sb.Append("G1 Z" + String.Format("{0:0.00000}", (sf.m_config.liftdistance * zdir * -1)) + " F" + feedrate + " (End Lift) \r\n");
                // add a delay for the lift sequence and the pre/post lift codes to execute
                sb.Append(blankdelay);
                // this move is moved to the end, so the first layer doesn't try to move up
                sb.Append("G1 Z" + String.Format("{0:0.00000}", (zdist * zdir)) + " F" + feedrate + "\r\n");
            }
            //append the footer
            sb.Append(sf.m_config.FooterCode);
            gcode = sb.ToString();
            GCodeFile gc = new GCodeFile(gcode);
            return gc;
        }
        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:
                    m_slicefile = sf;
                    //generate the GCode
                    m_gcode = GCodeGenerator.Generate(m_slicefile, m_printerinfo);

                    path = SliceFile.GetSliceFilePath(m_slicefile.modelname);
                    fileName = Path.GetFileNameWithoutExtension(m_slicefile.modelname) + ".gcode";
                    //see if we're exporting this to a zip file
                    if (sf.m_config.m_exportopt.Contains("ZIP"))
                    {
                        // open the existing zip file
                        //store the gcode
                        Stream stream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes (m_gcode.RawGCode));
                        String zpath = path + ".zip";
                        if (!Utility.StoreInZip(zpath, fileName, stream))
                        {
                            DebugLogger.Instance().LogError("Could not store GCode in Zip " + zpath);
                        }
                    }
                    else  // or just to the disk
                    {
                        String sdn = path + UVDLPApp.m_pathsep + fileName;
                        SaveGCode(sdn);
                    }

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

            }
        }
        /*
         This is the main function to generate gcode files for the
         * already sliced model
         */
        public static GCodeFile Generate(SliceFile sf, MachineConfig pi)
        {
            String gcode;
            StringBuilder sb = new StringBuilder();
            PreProcessor pp = PreparePreprocessor(sf, pi);
            double zdist = 0.0;
               // double feedrate = pi.ZMaxFeedrate; // 10mm/min
            double liftfeed = sf.m_config.liftfeedrate;
            double bottomliftfeed = sf.m_config.bottomliftfeedrate;

            double retractfeed = sf.m_config.liftretractrate;
            double zdir = 1.0; // assume a bottom up machine
            int numbottom = sf.m_config.numfirstlayers;

            if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down)
            {
                zdir = -1.0;// top down machine, reverse the z direction
            }
            pp.SetVar("$ZDir", zdir);

            // append the build parameters as reference
            sb.Append(sf.m_config.ToString());
            sb.Append(";Number of Slices        =  " + sf.NumSlices.ToString() + "\r\n");

            sb.Append(pi.ToString());//add the machine build parameters string

            // append the header
            sb.Append(pp.Process(sf.m_config.HeaderCode));

            zdist = sf.m_config.ZThick;

            String firstlayerdelay = ";<Delay> " + sf.m_config.firstlayertime_ms + " \r\n";
            String layerdelay = ";<Delay> " + sf.m_config.layertime_ms + " \r\n";
            String blankdelay = ";<Delay> " + sf.m_config.blanktime_ms + " \r\n";

            String preSliceGCode = pp.Process(sf.m_config.PreSliceCode);
            String LiftGCode = pp.Process(sf.m_config.LiftCode);

            int numslices = sf.NumSlices;
            if (sf.m_modeltype == SliceFile.ModelType.eResinTest1)
                numslices -= 10;

            // for a per-slice basis, we're going to re-evaluate the prelift and lift gcode
            // doing this will allow us to have per-slice determinations based on slice index.
            int c;
            for (c = 0; c < numslices; c++)
            {
                pp.SetVar("$CURSLICE", c);
                preSliceGCode = pp.Process(sf.m_config.PreSliceCode);
                //pp.SetVar("$CURSLICE", c);
                sb.Append(preSliceGCode);//add in the pre-slice code
                // this is the marker the BuildManager uses to display the correct slice
                sb.Append(";<Slice> " + c + " \r\n");
                // add a pause for the UV resin to be set using this image
                if (c < numbottom)// check for the bottom layers
                {
                    sb.Append(firstlayerdelay);
                }
                else
                {
                    sb.Append(layerdelay);
                }
                sb.Append(";<Slice> Blank \r\n"); // show the blank layer
                LiftGCode = pp.Process(sf.m_config.LiftCode); // re-run the lift code
                sb.Append(LiftGCode); // append the pre-lift codes
            }

            // special ending on resin test model slicing
            if (sf.m_modeltype == SliceFile.ModelType.eResinTest1)
            {
                for (; c < sf.NumSlices; c++)
                {
                    sb.Append(";<Slice> " + c + " \r\n");
                    // add a pause for the UV resin to be set using this image
                    if (c == sf.NumSlices -1) // set minimus exposure time on final layer
                        sb.Append(";<Delay> " + sf.m_config.minExposure + " \r\n");
                    else
                        sb.Append(";<Delay> " + sf.m_config.exposureStep + " \r\n");
                }
                sb.Append(";<Slice> Blank \r\n"); // show the blank layer
                LiftGCode = pp.Process(sf.m_config.LiftCode); // re-run the lift code
                sb.Append(LiftGCode); // append the pre-lift codes
            }

            //append the footer
            sb.Append(pp.Process(sf.m_config.FooterCode));
            gcode = sb.ToString();
            GCodeFile gc = new GCodeFile(gcode);
            return gc;
        }
Example #24
0
 private UVDLPApp()
 {
     m_appconfig = new AppConfig();
     m_printerinfo = new MachineConfig();
     m_buildparms = new SliceBuildConfig();
     m_deviceinterface = new DeviceInterface();
     m_buildmgr = new BuildManager();
     m_slicer = new Slicer();
     m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
     m_flexslice = new FlexSlice();
     m_gcode = null;
 }
 /// <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");
 }
        // This function is called to start the print job
        public void StartPrint(SliceFile sf, GCodeFile gcode)
        {
            if (m_printing)  // already printing
                return;

            m_printing = true;
            m_buildstarttime = new DateTime();
            m_buildstarttime = DateTime.Now;
            estimatedbuildtime = EstimateBuildTime(gcode);
            StartBuildTimer();

            m_sf = sf; // set the slicefile for rendering
            m_gcode = gcode; // set the file
            m_state = STATE_START; // set the state machine as started
            m_runthread = new Thread(new ThreadStart(BuildThread));
            m_running = true;
            m_runthread.Start();
        }
        // This function is called to start the print job
        public void StartPrint(SliceFile sf, GCodeFile gcode, bool snippet = false)
        {
            //late init of callback handler
            if (callbackinited == false)
            {
                UVDLPApp.Instance().m_callbackhandler.RegisterCallback("DisplayDone", DisplayDone, null, "Indicates when the display device is done with the current slice");
                callbackinited = true;
            }
            m_runningsnippet = snippet;

            if (m_printing)  // already printing
                return;
            //make sure to reset these
            m_pause_request = false;
            //m_cancel_request = false;

            m_printing = true;
            m_buildstarttime = new DateTime();
            m_buildstarttime = DateTime.Now;
            estimatedbuildtime = EstimateBuildTime(gcode);
            StartBuildTimer();

            m_sf = sf; // set the slicefile for rendering
            m_gcode = gcode; // set the file
            m_state = STATE_START; // set the state machine as started
            m_runthread = new Thread(new ThreadStart(BuildThread));
            m_running = true;
            m_runthread.Start();
        }
        /*
         * This is the main function to generate gcode files for the
         * already sliced model
         */
        public static GCodeFile Generate(SliceFile sf, MachineConfig pi)
        {
            String        gcode;
            StringBuilder sb    = new StringBuilder();
            PreProcessor  pp    = PreparePreprocessor(sf, pi);
            double        zdist = 0.0;
            // double feedrate = pi.ZMaxFeedrate; // 10mm/min
            double liftfeed       = sf.m_config.liftfeedrate;
            double bottomliftfeed = sf.m_config.bottomliftfeedrate;

            double retractfeed = sf.m_config.liftretractrate;
            double zdir        = 1.0; // assume a bottom up machine
            int    numbottom   = sf.m_config.numfirstlayers;

            if (sf.m_config.direction == SliceBuildConfig.eBuildDirection.Top_Down)
            {
                zdir = -1.0;// top down machine, reverse the z direction
            }
            pp.SetVar("$ZDir", zdir);

            // append the build parameters as reference
            sb.Append(sf.m_config.ToString());
            sb.Append(";Number of Slices        =  " + sf.NumSlices.ToString() + "\r\n");

            sb.Append(pi.ToString());//add the machine build parameters string

            // append the header
            sb.Append(pp.Process(sf.m_config.HeaderCode));

            zdist = sf.m_config.ZThick;

            String firstlayerdelay = ";<Delay> " + sf.m_config.firstlayertime_ms + " \r\n";
            String layerdelay      = ";<Delay> " + sf.m_config.layertime_ms + " \r\n";
            String blankdelay      = ";<Delay> " + sf.m_config.blanktime_ms + " \r\n";

            String preSliceGCode = pp.Process(sf.m_config.PreSliceCode);
            String LiftGCode     = pp.Process(sf.m_config.LiftCode);

            int numslices = sf.NumSlices;

            if (sf.m_modeltype == SliceFile.ModelType.eResinTest1)
            {
                numslices -= 10;
            }

            // for a per-slice basis, we're going to re-evaluate the prelift and lift gcode
            // doing this will allow us to have per-slice determinations based on slice index.
            int c;

            for (c = 0; c < numslices; c++)
            {
                pp.SetVar("$CURSLICE", c);
                preSliceGCode = pp.Process(sf.m_config.PreSliceCode);
                //pp.SetVar("$CURSLICE", c);
                sb.Append(preSliceGCode);//add in the pre-slice code
                // this is the marker the BuildManager uses to display the correct slice
                sb.Append(";<Slice> " + c + " \r\n");
                // add a pause for the UV resin to be set using this image
                if (c < numbottom)// check for the bottom layers
                {
                    sb.Append(firstlayerdelay);
                }
                else
                {
                    sb.Append(layerdelay);
                }
                sb.Append(";<Slice> Blank \r\n");             // show the blank layer
                LiftGCode = pp.Process(sf.m_config.LiftCode); // re-run the lift code
                sb.Append(LiftGCode);                         // append the pre-lift codes
            }

            // special ending on resin test model slicing
            if (sf.m_modeltype == SliceFile.ModelType.eResinTest1)
            {
                for (; c < sf.NumSlices; c++)
                {
                    sb.Append(";<Slice> " + c + " \r\n");
                    // add a pause for the UV resin to be set using this image
                    if (c == sf.NumSlices - 1) // set minimus exposure time on final layer
                    {
                        sb.Append(";<Delay> " + sf.m_config.minExposure + " \r\n");
                    }
                    else
                    {
                        sb.Append(";<Delay> " + sf.m_config.exposureStep + " \r\n");
                    }
                }
                sb.Append(";<Slice> Blank \r\n");             // show the blank layer
                LiftGCode = pp.Process(sf.m_config.LiftCode); // re-run the lift code
                sb.Append(LiftGCode);                         // append the pre-lift codes
            }



            //append the footer
            sb.Append(pp.Process(sf.m_config.FooterCode));
            gcode = sb.ToString();
            GCodeFile gc = new GCodeFile(gcode);

            return(gc);
        }
Example #29
0
        void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers)
        {
            String path = "";

            switch (ev)
            {
            case Slicer.eSliceEvent.eSliceStarted:
                // if we're exporting images
                if (m_buildparms.exportimages)
                {
                    // get the model name
                    String modelname = m_obj.m_fullname;
                    // strip off the file extension
                    path  = Path.GetDirectoryName(modelname);
                    path += UVDLPApp.m_pathsep;
                    path += Path.GetFileNameWithoutExtension(modelname); // strip off the file extension
                    if (!Directory.Exists(path))                         // check and see if a directory of that name exists,
                    {
                        Directory.CreateDirectory(path);                 // if not, create it
                    }
                }
                break;

            case Slicer.eSliceEvent.eLayerSliced:
                //save the rendered image slice
                //render the slice

                if (m_buildparms.exportimages)
                {
                    // get the model name
                    String modelname = m_obj.m_fullname;
                    // strip off the file extension
                    path  = Path.GetDirectoryName(modelname);
                    path += UVDLPApp.m_pathsep;
                    path += Path.GetFileNameWithoutExtension(modelname);    // strip off the file extension
                    Bitmap bmp       = null;
                    String imagename = path + m_pathsep + Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}", layer) + ".png";
                    bmp = UVDLPApp.Instance().m_slicefile.RenderSlice(layer);
                    bmp.Save(imagename);
                }
                break;

            case Slicer.eSliceEvent.eSliceCompleted:
                m_gcode = GCodeGenerator.Generate(m_slicefile, m_printerinfo);

                /*
                 * //get the path of the current object file
                 * path = Path.GetDirectoryName(m_obj.m_fullname);
                 * string fn = Path.GetFileNameWithoutExtension(m_obj.m_fullname);
                 * if (!UVDLPApp.Instance().m_gcode.Save(path + UVDLPApp.m_pathsep + fn + ".gcode"))
                 * {
                 *  DebugLogger.Instance().LogRecord("Cannot save GCode File " + path + m_pathsep + fn + ".gcode");
                 * }
                 * */
                SaveGCode();
                break;

            case Slicer.eSliceEvent.eSliceCancelled:
                DebugLogger.Instance().LogRecord("Slicing Cancelled");
                break;
            }
        }
 private UVDLPApp()
 {
     m_supportmode = eSupportEditMode.eNone;
     SceneFileName = "";
     m_callbackhandler = new CallbackHandler();
     m_appconfig = new AppConfig();
     m_printerinfo = new MachineConfig();
     m_buildparms = new SliceBuildConfig();
     m_deviceinterface = new DeviceInterface();
     m_buildmgr = new BuildManager();
     m_slicer = new Slicer();
     m_slicer.m_slicemethod = Slicer.eSliceMethod.eNormalCount;// configure the slicer to user the new normal count - Thanks Shai!!!
     m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
     //m_dispmgr = DisplayManager.Instance(); // initialize the singleton for early event app binding
     //m_flexslice = new FlexSlice();
     m_gcode = new GCodeFile(""); // create a blank gcode to start with
     m_supportconfig = new SupportConfig();
     m_supportgenerator = new SupportGenerator();
     m_supportgenerator.SupportEvent+= new SupportGeneratorEvent(SupEvent);
     CSG.Instance().CSGEvent += new CSG.CSGEventDel(CSGEvent);
     m_proj_cmd_lst = new prjcmdlst();
     m_plugins = new List<PluginEntry>(); // list of user plug-ins
     m_pluginstates =  PluginStates.Instance(); // initialize the plugin state singleton
     m_undoer = new Undoer();
     m_2d_graphics = new C2DGraphics();
     m_gui_config = new GuiConfigManager();
     m_AuxBuildCmds = AuxBuildCmds.Instance(); // make sure the singleton doesn't go away...
     m_sequencemanager = SequenceManager.Instance();
     m_exporter = new frmExport();
     m_exporter.RegisterExporter(new B9JExporter());
 }
        void SliceEv(Slicer.eSliceEvent ev, int layer, int totallayers)
        {
            String path = "";

            switch (ev)
            {
            case Slicer.eSliceEvent.eSliceStarted:
                // if we're exporting images
                if (m_buildparms.exportimages)
                {
                    m_zip = new ZipFile();
                    // get the model name, could be scene....
                    String modelname = m_selectedobject.m_fullname;
                    // strip off the file extension
                    path  = Path.GetDirectoryName(modelname);
                    path += UVDLPApp.m_pathsep;
                    path += Path.GetFileNameWithoutExtension(modelname); // strip off the file extension
                    if (!Directory.Exists(path))                         // check and see if a directory of that name exists,
                    {
                        Directory.CreateDirectory(path);                 // if not, create it
                    }
                }
                break;

            case Slicer.eSliceEvent.eLayerSliced:
                //save the rendered image slice
                //render the slice

                if (m_buildparms.exportimages)
                {
                    // get the model name
                    String modelname = m_selectedobject.m_fullname;
                    // strip off the file extension
                    path  = Path.GetDirectoryName(modelname);
                    path += UVDLPApp.m_pathsep;
                    path += Path.GetFileNameWithoutExtension(modelname);    // strip off the file extension
                    Bitmap bmp       = null;
                    String imname    = Path.GetFileNameWithoutExtension(modelname) + String.Format("{0:0000}", layer) + ".png";
                    String imagename = path + m_pathsep + imname;
                    bmp = UVDLPApp.Instance().m_slicefile.RenderSlice(layer);
                    // bmp.Save(imagename);
                    // create a memory stream for this to save into
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, ImageFormat.Png);
                    ms.Seek(0, SeekOrigin.Begin);     // seek back to beginning
                    m_zip.AddEntry(imname, ms);
                }



                break;

            case Slicer.eSliceEvent.eSliceCompleted:

                // save the zip file full of images
                if (m_buildparms.exportimages)
                {
                    String modelname = m_selectedobject.m_fullname;
                    // strip off the file extension
                    path  = Path.GetDirectoryName(modelname);
                    path += UVDLPApp.m_pathsep;
                    path += Path.GetFileNameWithoutExtension(modelname);    // strip off the file extension
                    path += ".zip";
                    m_zip.Save(path);
                }

                m_gcode = GCodeGenerator.Generate(m_slicefile, m_printerinfo);

                //get the path of the current object file
                path = Path.GetDirectoryName(m_selectedobject.m_fullname);
                string fn = Path.GetFileNameWithoutExtension(m_selectedobject.m_fullname);

                /*
                 * if (!UVDLPApp.Instance().m_gcode.Save(path + UVDLPApp.m_pathsep + fn + ".gcode"))
                 * {
                 *  DebugLogger.Instance().LogRecord("Cannot save GCode File " + path + m_pathsep + fn + ".gcode");
                 * }
                 */
                SaveGCode(path + UVDLPApp.m_pathsep + fn + ".gcode");
                break;

            case Slicer.eSliceEvent.eSliceCancelled:
                DebugLogger.Instance().LogRecord("Slicing Cancelled");
                break;
            }
        }