Ejemplo n.º 1
0
 public ColorSegment(int col, int len, bool rev, L2LConf c)
 {
     mColor   = col;
     mLen     = len / (c.vectorfilling ? c.fres : c.res);
     mReverse = rev;
     mConf    = c;
 }
Ejemplo n.º 2
0
        public void LoadImageL2L(Bitmap bmp, string filename, L2LConf c)
        {
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            long start = Tools.HiResTimer.TotalMilliseconds;

            list.Clear();
            mRange.ResetRange();

            bool   autoHome = autoHomeEnabled();
            double zOffset  = getZOffset();

            if (autoHome)
            {
                list.Add(new GrblCommand("G28"));
            }
            //absolute
            list.Add(new GrblCommand("G90"));
            //move fast to offset
            if (autoHome)
            {
                list.Add(new GrblCommand(String.Format("G0 X{0} Y{1} Z{2}", formatnumber(c.oX), formatnumber(c.oY), formatnumber(zOffset))));
            }
            else
            {
                list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY))));
            }

            if (c.pwm)
            {
                list.Add(new GrblCommand(String.Format("{0} S0", c.lOn)));                 //laser on and power to zero
            }
            else
            {
                list.Add(new GrblCommand(String.Format("{0} S255", c.lOff)));                 //laser off and power to maxpower
            }
            //relative
            list.Add(new GrblCommand("G91"));

            //set speed to markspeed
            list.Add(new GrblCommand(String.Format("G1 F{0}", c.markSpeed)));

            ImageLine2Line(bmp, c);

            //laser off
            list.Add(new GrblCommand(c.lOff));
            //absolute
            list.Add(new GrblCommand("G90"));
            //move fast to origin
            list.Add(new GrblCommand("G0 X0 Y0"));

            Analyze();
            long elapsed = Tools.HiResTimer.TotalMilliseconds - start;

            if (OnFileLoaded != null)
            {
                OnFileLoaded(elapsed, filename);
            }
        }
Ejemplo n.º 3
0
            public override string ToGCodeNumber(ref int cumX, ref int cumY, L2LConf c)
            {
                if (mPixLen < 0)
                {
                    throw new Exception();
                }

                cumX += mPixLen;
                return(string.Format("X{0}", formatnumber(cumX, c.oX, c)));
            }
Ejemplo n.º 4
0
        // For Marlin, as we sen M106 command, we need to know last color send
        //private int lastColorSend = 0;
        private void ImageLine2Line(Bitmap bmp, L2LConf c)
        {
            bool fast = true;
            List <ColorSegment> segments = GetSegments(bmp, c);
            List <GrblCommand>  temp     = new List <GrblCommand>();

            int cumX = 0;
            int cumY = 0;

            foreach (ColorSegment seg in segments)
            {
                bool changeGMode = (fast != seg.Fast(c));     //se veloce != dafareveloce

                if (seg.IsSeparator && !fast)                 //fast = previous segment contains S0 color
                {
                    if (c.pwm)
                    {
                        temp.Add(new GrblCommand("S0"));
                    }
                    else
                    {
                        temp.Add(new GrblCommand(c.lOff));                         //laser off
                    }
                }

                fast = seg.Fast(c);

                // For marlin firmware, we must defined laser power before moving (unsing M106 or M107)
                // So we have to speficy gcode (G0 or G1) each time....
                //if (c.firmwareType == Firmware.Marlin)
                //{
                //	// Add M106 only if color has changed
                //	if (lastColorSend != seg.mColor)
                //		temp.Add(new GrblCommand(String.Format("M106 P1 S{0}", fast ? 0 : seg.mColor)));
                //	lastColorSend = seg.mColor;
                //	temp.Add(new GrblCommand(String.Format("{0} {1}", fast ? "G0" : "G1", seg.ToGCodeNumber(ref cumX, ref cumY, c))));
                //}
                //else
                //{

                if (changeGMode)
                {
                    temp.Add(new GrblCommand(String.Format("{0} {1}", fast ? "G0" : "G1", seg.ToGCodeNumber(ref cumX, ref cumY, c))));
                }
                else
                {
                    temp.Add(new GrblCommand(seg.ToGCodeNumber(ref cumX, ref cumY, c)));
                }

                //}
            }

            temp = OptimizeLine2Line(temp, c);
            list.AddRange(temp);
        }
Ejemplo n.º 5
0
            public override string ToGCodeNumber(ref int cumX, ref int cumY, L2LConf c)
            {
                cumY += mPixLen;

                if (c.pwm)
                {
                    return(string.Format("Y{0} S{1}", formatnumber(cumY, c.oY, c), mColor));
                }
                else
                {
                    return(string.Format("Y{0} {1}", formatnumber(cumY, c.oY, c), Fast(c) ? c.lOff : c.lOn));
                }
            }
Ejemplo n.º 6
0
            public override string ToGCodeNumber(ref int cumX, ref int cumY, L2LConf c)
            {
                cumX += mPixLen;

                if (c.pwm)
                {
                    return(string.Format("X{0} {1}", formatnumber(cumX, c.oX, c), FormatLaserPower(mColor, c)));
                }
                else
                {
                    return(string.Format("X{0} {1}", formatnumber(cumX, c.oX, c), Fast(c) ? c.lOff : c.lOn));
                }
            }
Ejemplo n.º 7
0
 // Format laser power value
 // grbl                    with pwm : color can be between 0 and configured SMax - S128
 // smoothiware             with pwm : Value between 0.00 and 1.00    - S0.50
 // Marlin : Laser power can not be defined as switch (Add in comment hard coded changes)
 public string FormatLaserPower(int color, L2LConf c)
 {
     if (c.firmwareType == Firmware.Smoothie)
     {
         return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "S{0:0.00}", color / 255.0));                //maybe scaling to UI maxpower VS config maxpower instead of fixed / 255.0 ?
     }
     //else if (c.firmwareType == Firmware.Marlin)
     //	return "";
     else
     {
         return(string.Format(System.Globalization.CultureInfo.InvariantCulture, "S{0}", color));
     }
 }
Ejemplo n.º 8
0
        public void LoadImageL2L(Bitmap bmp, string filename, L2LConf c)
        {
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            long start = Tools.HiResTimer.TotalMilliseconds;

            mTotalTravelOff   = 0;
            mTotalTravelOn    = 0;
            mEstimatedTimeOff = TimeSpan.Zero;
            mEstimatedTimeOn  = TimeSpan.Zero;
            list.Clear();
            mRange.ResetRange();

            //absolute
            list.Add(new GrblCommand("G90"));
            //use travel speed
            list.Add(new GrblCommand(String.Format("F{0}", c.travelSpeed)));
            //move fast to offset
            list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY))));
            if (c.pwm)
            {
                list.Add(new GrblCommand(String.Format("{0} S0", c.lOn)));                 //laser on and power to zero
            }
            else
            {
                list.Add(new GrblCommand(String.Format("{0} S255", c.lOff)));                 //laser off and power to maxpower
            }
            //set speed to markspeed
            list.Add(new GrblCommand(String.Format("G1 F{0}", c.markSpeed)));
            //relative
            list.Add(new GrblCommand("G91"));

            ImageLine2Line(bmp, c);

            //laser off
            list.Add(new GrblCommand(c.lOff));
            //absolute
            list.Add(new GrblCommand("G90"));
            //move fast to origin
            list.Add(new GrblCommand("G0 X0 Y0"));

            Analyze();
            long elapsed = Tools.HiResTimer.TotalMilliseconds - start;

            if (OnFileLoaded != null)
            {
                OnFileLoaded(elapsed, filename);
            }
        }
Ejemplo n.º 9
0
        public void LoadImageL2L(Bitmap bmp, string filename, L2LConf c, bool append)
        {
            RiseOnFileLoading(filename);

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            DateTime start = DateTime.Now;

            if (!append)
            {
                list.Clear();
            }

            mRange.ResetRange();

            //absolute
            //list.Add(new GrblCommand("G90")); //(Moved to custom Header)

            //move fast to offset
            list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY))));
            if (c.pwm)
            {
                list.Add(new GrblCommand(String.Format("{0} S0", c.lOn)));                 //laser on and power to zero
            }
            else
            {
                list.Add(new GrblCommand(String.Format("{0} S255", c.lOff)));                 //laser off and power to maxpower
            }
            //set speed to markspeed
            // For marlin, need to specify G1 each time :
            //list.Add(new GrblCommand(String.Format("G1 F{0}", c.markSpeed)));
            list.Add(new GrblCommand(String.Format("F{0}", c.markSpeed)));

            ImageLine2Line(bmp, c);

            //laser off
            if (c.lOff != null)
            {
                list.Add(new GrblCommand(c.lOff));
            }

            //move fast to origin
            //list.Add(new GrblCommand("G0 X0 Y0")); //moved to custom footer

            Analyze();
            long elapsed = (long)(DateTime.Now - start).TotalMilliseconds;

            RiseOnFileLoaded(filename, elapsed);
        }
Ejemplo n.º 10
0
        public void LoadImageL2L(Bitmap bmp, string filename, L2LConf c, bool append)
        {
            RiseOnFileLoading(filename);

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            long start = Tools.HiResTimer.TotalMilliseconds;

            if (!append)
            {
                list.Clear();
            }

            mRange.ResetRange();

            //absolute
            list.Add(new GrblCommand("G90"));
            //move fast to offset
            list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY))));
            if (c.pwm)
            {
                list.Add(new GrblCommand(String.Format("{0} S0", c.lOn)));                 //laser on and power to zero
            }
            else
            {
                list.Add(new GrblCommand(String.Format("{0} S255", c.lOff)));                 //laser off and power to maxpower
            }
            //set speed to markspeed
            list.Add(new GrblCommand(String.Format("F{0}", c.markSpeed)));

            ImageLine2Line(bmp, c);

            //laser off
            list.Add(new GrblCommand(c.lOff));

            //move fast to origin
            list.Add(new GrblCommand("G0 X0 Y0"));

            Analyze();
            long elapsed = Tools.HiResTimer.TotalMilliseconds - start;

            RiseOnFileLoaded(filename, elapsed);
        }
Ejemplo n.º 11
0
        private void ImageLine2Line(Bitmap bmp, L2LConf c)
        {
            bool fast = false;
            List <ColorSegment> segments = GetSegments(bmp, c);
            List <GrblCommand>  temp     = new List <GrblCommand>();

            foreach (ColorSegment seg in segments)
            {
                //bool changeGMode = true; //(fast != seg.Fast); //se veloce != dafareveloce

                if (seg.IsSeparator && !fast)                 //fast = previous segment contains S0 color
                {
                    //if (c.pwm)
                    //	temp.Add(new GrblCommand("S0"));
                    //else
                    temp.Add(new GrblCommand(c.lOff));                             //laser off
                }

                fast = seg.Fast;

                string[] lines = seg.ToString().Split(new[] { System.Environment.NewLine }, StringSplitOptions.None);

                if (lines.Length > 1)
                {
                    temp.Add(new GrblCommand(String.Format("{0}" + System.Environment.NewLine + "{1} {2}", lines[0], fast ? "G0" : "G1", lines[1])));
                }
                else
                {
                    temp.Add(new GrblCommand(String.Format("{0} {1}", fast ? "G0" : "G1", lines[0])));
                }

                /*if (changeGMode)
                 *                      temp.Add(new GrblCommand(String.Format("{0} {1} {2}", lines[0], fast ? "G0" : "G1", lines[1])));
                 *              else
                 *                      temp.Add(new GrblCommand(seg.ToString()));*/

                //if (seg.IsSeparator)
                //	list.Add(new GrblCommand(lOn));
            }

            temp = OptimizeLine2Line(temp, c);
            list.AddRange(temp);
        }
Ejemplo n.º 12
0
        private void ImageLine2Line(Bitmap bmp, L2LConf c)
        {
            bool fast = false;
            List <ColorSegment> segments = GetSegments(bmp, c);
            List <GrblCommand>  temp     = new List <GrblCommand>();

            int cumX = 0;
            int cumY = 0;

            foreach (ColorSegment seg in segments)
            {
                bool changeGMode = (fast != seg.Fast(c));     //se veloce != dafareveloce

                if (seg.IsSeparator && !fast)                 //fast = previous segment contains S0 color
                {
                    if (c.pwm)
                    {
                        temp.Add(new GrblCommand("S0"));
                    }
                    else
                    {
                        temp.Add(new GrblCommand(c.lOff));                         //laser off
                    }
                }

                fast = seg.Fast(c);


                if (changeGMode)
                {
                    temp.Add(new GrblCommand(String.Format("{0} {1}", fast ? "G0" : "G1", seg.ToGCodeNumber(ref cumX, ref cumY, c))));
                }
                else
                {
                    temp.Add(new GrblCommand(seg.ToGCodeNumber(ref cumX, ref cumY, c)));
                }
            }

            temp = OptimizeLine2Line(temp, c);
            list.AddRange(temp);
        }
Ejemplo n.º 13
0
        private void ImageLine2Line(Bitmap bmp, L2LConf c)
        {
            bool fast = false;
            List <ColorSegment> segments = GetSegments(bmp, c);
            List <GrblCommand>  temp     = new List <GrblCommand>();

            foreach (ColorSegment seg in segments)
            {
                bool changespeed = (fast != seg.Fast);        //se veloce != dafareveloce

                if (seg.IsSeparator && !fast)                 //fast = previous segment contains S0 color
                {
                    if (c.pwm)
                    {
                        temp.Add(new GrblCommand("S0"));
                    }
                    else
                    {
                        temp.Add(new GrblCommand(c.lOff));                         //laser off
                    }
                }

                fast = seg.Fast;

                if (changespeed)
                {
                    temp.Add(new GrblCommand(String.Format("{0} F{1} {2}", fast ? "G0" : "G1", fast ? c.travelSpeed : c.markSpeed, seg.ToString())));
                }
                else
                {
                    temp.Add(new GrblCommand(seg.ToString()));
                }

                //if (seg.IsSeparator)
                //	list.Add(new GrblCommand(lOn));
            }

            temp = OptimizeLine2Line(temp, c);
            list.AddRange(temp);
        }
Ejemplo n.º 14
0
        private List <GrblCommand> OptimizeLine2Line(List <GrblCommand> temp, L2LConf c)
        {
            List <GrblCommand> rv = new List <GrblCommand>();

            decimal cumX     = 0;
            decimal cumY     = 0;
            bool    cumulate = false;

            foreach (GrblCommand cmd in temp)
            {
                try
                {
                    cmd.BuildHelper();
                    rv.Add(cmd);

                    /*
                     * bool oldcumulate = cumulate;
                     *
                     *                  if (c.pwm)
                     *                  {
                     *                          if (cmd.S != null) //is S command
                     *                          {
                     *                                  if (cmd.S.Number == 0) //is S command with zero power
                     *                                          cumulate = true;   //begin cumulate
                     *                                  else
                     *                                          cumulate = false;  //end cumulate
                     *                          }
                     *                  }
                     *                  else
                     *                  {
                     *                          if (cmd.IsLaserOFF)
                     *                                  cumulate = true;   //begin cumulate
                     *                          else if (cmd.IsLaserON)
                     *                                  cumulate = false;  //end cumulate
                     *                  }
                     *
                     *
                     *                  if (oldcumulate && !cumulate) //cumulate down front -> flush
                     *                  {
                     *                          if (c.pwm)
                     *                                  rv.Add(new GrblCommand(string.Format("G0 X{0} Y{1} S0", formatnumber((double)cumX), formatnumber((double)cumY))));
                     *                          else
                     *                                  rv.Add(new GrblCommand(string.Format("G0 X{0} Y{1} {2}", formatnumber((double)cumX), formatnumber((double)cumY), c.lOff)));
                     *
                     *                          cumX = cumY = 0;
                     *                  }
                     *
                     *                  if (cumulate) //cumulate
                     *                  {
                     *                          if (cmd.IsMovement)
                     *                          {
                     *                                  if (cmd.X != null)
                     *                                          cumX += cmd.X.Number;
                     *                                  if (cmd.Y != null)
                     *                                          cumY += cmd.Y.Number;
                     *                          }
                     *                          else
                     *                          {
                     *                                  rv.Add(cmd);
                     *                          }
                     *                  }
                     *                  else //emit line normally
                     *                  {
                     *                          rv.Add(cmd);
                     *                  }*/
                }
                catch (Exception ex) { throw ex; }
                finally { cmd.DeleteHelper(); }
            }

            return(rv);
        }
Ejemplo n.º 15
0
        private void ExtractSegment(Bitmap image, int x, int y, bool reverse, ref int len, ref int prevCol, List <ColorSegment> rv, L2LConf c)
        {
            len++;
            int col = GetColor(image, x, y, c.minPower, c.maxPower, c.pwm);

            if (prevCol == -1)
            {
                prevCol = col;
            }

            if (prevCol != col)
            {
                if (c.dir == RasterConverter.ImageProcessor.Direction.Horizontal)
                {
                    rv.Add(new XSegment(prevCol, len, reverse, c));
                }
                else if (c.dir == RasterConverter.ImageProcessor.Direction.Vertical)
                {
                    rv.Add(new YSegment(prevCol, len, reverse, c));
                }
                else if (c.dir == RasterConverter.ImageProcessor.Direction.Diagonal)
                {
                    rv.Add(new DSegment(prevCol, len, reverse, c));
                }

                len = 0;
            }

            prevCol = col;
        }
Ejemplo n.º 16
0
        private List <ColorSegment> GetSegments(Bitmap bmp, L2LConf c)
        {
            List <ColorSegment> rv = new List <ColorSegment>();

            if (c.dir == RasterConverter.ImageProcessor.Direction.Horizontal || c.dir == RasterConverter.ImageProcessor.Direction.Vertical)
            {
                bool h = (c.dir == RasterConverter.ImageProcessor.Direction.Horizontal);                 //horizontal/vertical

                for (int i = 0; i < (h ? bmp.Height : bmp.Width); i++)
                {
                    bool d       = IsEven(i);               //direct/reverse
                    int  prevCol = -1;
                    int  len     = -1;

                    for (int j = d ? 0 : (h ? bmp.Width - 1 : bmp.Height - 1); d ? (j < (h ? bmp.Width : bmp.Height)) : (j >= 0); j = (d ? j + 1 : j - 1))
                    {
                        ExtractSegment(bmp, h ? j : i, h ? i : j, !d, ref len, ref prevCol, rv, c);                         //extract different segments
                    }
                    if (h)
                    {
                        rv.Add(new XSegment(prevCol, len + 1, !d, c));                         //close last segment
                    }
                    else
                    {
                        rv.Add(new YSegment(prevCol, len + 1, !d, c));                         //close last segment
                    }
                    if (i < (h ? bmp.Height - 1 : bmp.Width - 1))
                    {
                        if (h)
                        {
                            rv.Add(new VSeparator(c));                             //new line
                        }
                        else
                        {
                            rv.Add(new HSeparator(c));                             //new line
                        }
                    }
                }
            }
            else if (c.dir == RasterConverter.ImageProcessor.Direction.Diagonal)
            {
                //based on: http://stackoverflow.com/questions/1779199/traverse-matrix-in-diagonal-strips
                //based on: http://stackoverflow.com/questions/2112832/traverse-rectangular-matrix-in-diagonal-strips

                /*
                 *
                 +------------+
                 |  -         |
                 |  -  -      |
                 +-------+    |
                 |  -  - |  - |
                 +-------+----+
                 |
                 */


                //the algorithm runs along the matrix for diagonal lines (slice index)
                //z1 and z2 contains the number of missing elements in the lower right and upper left
                //the length of the segment can be determined as "slice - z1 - z2"
                //my modified version of algorithm reverses travel direction each slice

                rv.Add(new VSeparator(c));                 //new line

                int w = bmp.Width;
                int h = bmp.Height;
                for (int slice = 0; slice < w + h - 1; ++slice)
                {
                    bool d = IsEven(slice);                     //direct/reverse

                    int prevCol = -1;
                    int len     = -1;

                    int z1 = slice < h ? 0 : slice - h + 1;
                    int z2 = slice < w ? 0 : slice - w + 1;

                    for (int j = (d ? z1 : slice - z2); d?j <= slice - z2 : j >= z1; j = (d ? j + 1 : j - 1))
                    {
                        ExtractSegment(bmp, j, slice - j, !d, ref len, ref prevCol, rv, c); //extract different segments
                    }
                    rv.Add(new DSegment(prevCol, len + 1, !d, c));                          //close last segment

                    //System.Diagnostics.Debug.WriteLine(String.Format("sl:{0} z1:{1} z2:{2}", slice, z1, z2));

                    if (slice < Math.Min(w, h) - 1)                   //first part of the image
                    {
                        if (d)
                        {
                            rv.Add(new HSeparator(c));                             //new line
                        }
                        else
                        {
                            rv.Add(new VSeparator(c));                             //new line
                        }
                    }
                    else if (slice >= Math.Max(w, h) - 1)                   //third part of image
                    {
                        if (d)
                        {
                            rv.Add(new VSeparator(c));                             //new line
                        }
                        else
                        {
                            rv.Add(new HSeparator(c));                             //new line
                        }
                    }
                    else                     //central part of the image
                    {
                        if (w > h)
                        {
                            rv.Add(new HSeparator(c));                             //new line
                        }
                        else
                        {
                            rv.Add(new VSeparator(c));                             //new line
                        }
                    }
                }
            }

            return(rv);
        }
Ejemplo n.º 17
0
        private List <GrblCommand> OptimizeLine2Line(List <GrblCommand> temp, L2LConf c)
        {
            List <GrblCommand> rv = new List <GrblCommand>();

            decimal cumX     = 0;
            decimal cumY     = 0;
            bool    cumulate = false;

            foreach (GrblCommand cmd in temp)
            {
                try
                {
                    cmd.BuildHelper();

                    bool oldcumulate = cumulate;

                    if (c.pwm)
                    {
                        if (cmd.S != null)                         //is S command
                        {
                            if (cmd.S.Number == 0)                 //is S command with zero power
                            {
                                cumulate = true;                   //begin cumulate
                            }
                            else
                            {
                                cumulate = false;                                  //end cumulate
                            }
                        }
                    }
                    else
                    {
                        if (cmd.IsLaserOFF)
                        {
                            cumulate = true;                               //begin cumulate
                        }
                        else if (cmd.IsLaserON)
                        {
                            cumulate = false;                              //end cumulate
                        }
                    }


                    if (oldcumulate && !cumulate)                     //cumulate down front -> flush
                    {
                        if (c.pwm)
                        {
                            rv.Add(new GrblCommand(string.Format("G0 X{0} Y{1} F{2} S0", formatnumber((double)cumX), formatnumber((double)cumY), c.travelSpeed)));
                        }
                        else
                        {
                            rv.Add(new GrblCommand(string.Format("G0 X{0} Y{1} F{2} {3}", formatnumber((double)cumX), formatnumber((double)cumY), c.travelSpeed, c.lOff)));
                        }

                        cumX = cumY = 0;
                    }

                    if (cumulate)                     //cumulate
                    {
                        if (cmd.IsMovement)
                        {
                            if (cmd.X != null)
                            {
                                cumX += cmd.X.Number;
                            }
                            if (cmd.Y != null)
                            {
                                cumY += cmd.Y.Number;
                            }
                        }
                        else
                        {
                            rv.Add(cmd);
                        }
                    }
                    else                     //emit line normally
                    {
                        rv.Add(cmd);
                    }
                }
                catch (Exception ex) { throw ex; }
                finally { cmd.DeleteHelper(); }
            }

            return(rv);
        }
Ejemplo n.º 18
0
        internal void LoadImageCenterline(Bitmap bmp, string filename, bool useCornerThreshold, int cornerThreshold, bool useLineThreshold, int lineThreshold, L2LConf conf, bool append)
        {
            RiseOnFileLoading(filename);

            long start = Tools.HiResTimer.TotalMilliseconds;

            if (!append)
            {
                list.Clear();
            }

            mRange.ResetRange();

            string content = Autotrace.BitmapToSvgString(bmp, useCornerThreshold, cornerThreshold, useLineThreshold, lineThreshold);

            SvgConverter.GCodeFromSVG converter = new SvgConverter.GCodeFromSVG();
            converter.GCodeXYFeed   = (float)(int)Settings.GetObject("GrayScaleConversion.VectorizeOptions.BorderSpeed", 1000);
            converter.SvgScaleApply = true;
            converter.SvgMaxSize    = (float)Math.Max(bmp.Width / 10.0, bmp.Height / 10.0);
            converter.UserOffset.X  = Convert.ToSingle(Settings.GetObject("GrayScaleConversion.Gcode.Offset.X", 0F));
            converter.UserOffset.Y  = Convert.ToSingle(Settings.GetObject("GrayScaleConversion.Gcode.Offset.Y", 0F));

            string gcode = converter.convertFromText(content);

            string[] lines = gcode.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            foreach (string l in lines)
            {
                string line = l;
                if ((line = line.Trim()).Length > 0)
                {
                    GrblCommand cmd = new GrblCommand(line);
                    if (!cmd.IsEmpty)
                    {
                        list.Add(cmd);
                    }
                }
            }

            Analyze();
            long elapsed = Tools.HiResTimer.TotalMilliseconds - start;

            RiseOnFileLoaded(filename, elapsed);
        }
Ejemplo n.º 19
0
 public HSeparator(L2LConf c) : base(0, 1, false, c)
 {
 }
Ejemplo n.º 20
0
        public void LoadImagePotrace(Bitmap bmp, string filename, bool UseSpotRemoval, int SpotRemoval, bool UseSmoothing, decimal Smoothing, bool UseOptimize, decimal Optimize, L2LConf c)
        {
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            long start = Tools.HiResTimer.TotalMilliseconds;

            mTotalTravelOff   = 0;
            mTotalTravelOn    = 0;
            mEstimatedTimeOff = TimeSpan.Zero;
            mEstimatedTimeOn  = TimeSpan.Zero;
            list.Clear();
            mRange.ResetRange();

            Potrace.turdsize        = (int)(UseSpotRemoval ? SpotRemoval : 2);
            Potrace.alphamax        = UseSmoothing ? (double)Smoothing : 0.0;
            Potrace.opttolerance    = UseOptimize ? (double)Optimize : 0.2;
            Potrace.curveoptimizing = UseOptimize;             //optimize the path p, replacing sequences of Bezier segments by a single segment when possible.

            List <List <CsPotrace.Curve> > plist = Potrace.PotraceTrace(bmp);

            if (c.dir != RasterConverter.ImageProcessor.Direction.None)
            {
                using (Bitmap ptb = new Bitmap(bmp.Width, bmp.Height))
                {
                    using (Graphics g = Graphics.FromImage(ptb))
                    {
                        //Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, (Math.Max(c.res/c.fres, 1) + 1) / 2.0f);
                        Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, Math.Max(1, c.res / c.fres));
                        using (Bitmap resampled = RasterConverter.ImageTransform.ResizeImage(ptb, new Size((int)(bmp.Width * c.fres / c.res), (int)(bmp.Height * c.fres / c.res)), true, InterpolationMode.HighQualityBicubic))
                        {
                            //absolute
                            list.Add(new GrblCommand("G90"));
                            //use travel speed
                            list.Add(new GrblCommand(String.Format("F{0}", c.travelSpeed)));
                            //move fast to offset
                            list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY))));
                            if (c.pwm)
                            {
                                list.Add(new GrblCommand(String.Format("{0} S0", c.lOn)));                                 //laser on and power to zero
                            }
                            else
                            {
                                list.Add(new GrblCommand(String.Format("{0} S255", c.lOff)));                                 //laser off and power to max power
                            }
                            //set speed to markspeed
                            list.Add(new GrblCommand(String.Format("G1 F{0}", c.markSpeed)));
                            //relative
                            list.Add(new GrblCommand("G91"));


                            c.vectorfilling = true;
                            ImageLine2Line(resampled, c);

                            //laser off
                            list.Add(new GrblCommand(c.lOff));
                        }
                    }
                }
            }

            //absolute
            list.Add(new GrblCommand("G90"));
            //use travel speed
            list.Add(new GrblCommand(String.Format("F{0}", c.travelSpeed)));
            //move fast to offset
            list.Add(new GrblCommand(String.Format("G0 X{0} Y{1}", formatnumber(c.oX), formatnumber(c.oY))));
            //laser off and power to maxPower
            list.Add(new GrblCommand(String.Format("{0} S{1}", c.lOff, c.maxPower)));
            //set speed to borderspeed
            list.Add(new GrblCommand(String.Format("G1 F{0}", c.borderSpeed)));

            //trace borders
            List <string> gc = Potrace.Export2GCode(plist, c.oX, c.oY, c.res, c.lOn, c.lOff, bmp.Size);

            foreach (string code in gc)
            {
                list.Add(new GrblCommand(code));
            }


            //laser off
            list.Add(new GrblCommand(String.Format("{0}", c.lOff)));

            //move fast to origin
            list.Add(new GrblCommand("G0 X0 Y0"));

            Analyze();
            long elapsed = Tools.HiResTimer.TotalMilliseconds - start;

            if (OnFileLoaded != null)
            {
                OnFileLoaded(elapsed, filename);
            }
        }
Ejemplo n.º 21
0
 public DSegment(int col, int len, bool rev, L2LConf c) : base(col, len, rev, c)
 {
 }
Ejemplo n.º 22
0
        public void LoadImagePotrace(Bitmap bmp, string filename, bool UseSpotRemoval, int SpotRemoval, bool UseSmoothing, decimal Smoothing, bool UseOptimize, decimal Optimize, bool useOptimizeFast, L2LConf c, bool append)
        {
            RiseOnFileLoading(filename);

            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            DateTime start = DateTime.Now;

            if (!append)
            {
                list.Clear();
            }

            Potrace potrace = new Potrace();

            //list.Add(new GrblCommand("G90")); //absolute (Moved to custom Header)

            mRange.ResetRange();

            potrace.turdsize        = (int)(UseSpotRemoval ? SpotRemoval : 2);
            potrace.alphamax        = UseSmoothing ? (double)Smoothing : 0.0;
            potrace.opttolerance    = UseOptimize ? (double)Optimize : 0.2;
            potrace.curveoptimizing = UseOptimize;             //optimize the path p, replacing sequences of Bezier segments by a single segment when possible.

            List <List <Curve> > plist = potrace.PotraceTrace(bmp);

            if (c.dir != RasterConverter.Direction.None)
            {
                using (Bitmap ptb = new Bitmap(bmp.Width, bmp.Height))
                {
                    using (Graphics g = Graphics.FromImage(ptb))
                    {
                        //Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, (Math.Max(c.res/c.fres, 1) + 1) / 2.0f);
                        Potrace.Export2GDIPlus(plist, g, Brushes.Black, null, Math.Max(1, c.res / c.fres));
                        using (Bitmap resampled = RasterConverter.ImageTransform.ResizeImage(ptb, new Size((int)(bmp.Width * c.fres / c.res), (int)(bmp.Height * c.fres / c.res)), true, InterpolationMode.HighQualityBicubic))
                        {
                            if (c.pwm)
                            {
                                list.Add(new GrblCommand(String.Format("{0} S0", c.lOn)));                                 //laser on and power to zero
                            }
                            else
                            {
                                list.Add(new GrblCommand(String.Format("{0} S255", c.lOff)));                                 //laser off and power to max power
                            }
                            //set speed to markspeed
                            // For marlin, need to specify G1 each time :
                            // list.Add(new GrblCommand(String.Format("G1 F{0}", c.markSpeed)));
                            list.Add(new GrblCommand(String.Format("F{0}", c.markSpeed)));

                            c.vectorfilling = true;
                            ImageLine2Line(resampled, c);

                            //laser off
                            list.Add(new GrblCommand(c.lOff));
                        }
                    }
                }
            }

            //Optimize fast movement
            if (useOptimizeFast)
            {
                plist = OptimizePaths(plist);
            }

            //laser off and power to maxPower
            list.Add(new GrblCommand(String.Format("{0} S{1}", c.lOff, c.maxPower)));
            //set speed to borderspeed
            // For marlin, need to specify G1 each time :
            //list.Add(new GrblCommand(String.Format("G1 F{0}", c.borderSpeed)));
            list.Add(new GrblCommand(String.Format("F{0}", c.borderSpeed)));

            //trace borders
            List <string> gc = Potrace.Export2GCode(plist, c.oX, c.oY, c.res, c.lOn, c.lOff, bmp.Size);

            foreach (string code in gc)
            {
                list.Add(new GrblCommand(code));
            }

            //laser off (superflua??)
            //list.Add(new GrblCommand(String.Format("{0}", c.lOff)));

            Analyze();
            long elapsed = (long)(DateTime.Now - start).TotalMilliseconds;

            RiseOnFileLoaded(filename, elapsed);
        }
Ejemplo n.º 23
0
 public bool Fast(L2LConf c)
 {
     return(c.pwm ? mColor == 0 : mColor <= 125);
 }
Ejemplo n.º 24
0
            public string formatnumber(int number, int offset, L2LConf c)
            {
                double dval = Math.Round(number / (c.vectorfilling ? c.fres : c.res) + offset, 3);

                return(dval.ToString(System.Globalization.CultureInfo.InvariantCulture));
            }
Ejemplo n.º 25
0
 public abstract string ToGCodeNumber(ref int cumX, ref int cumY, L2LConf c);