示例#1
0
        protected void WriteGCode(System.Drawing.Bitmap b)
        {
            Bitmap = b;
            SizeX = b.Width;
            SizeY = b.Height;
            PixelSizeX = 25.4 / b.HorizontalResolution;
            PixelSizeY = 25.4 / b.VerticalResolution;

            ShiftX = (double)LoadOptions.LaserSize / 2.0;
            ShiftY = (double)LoadOptions.LaserSize / 2.0;

			if (!string.IsNullOrEmpty(LoadOptions.ImageWriteToFileName))
				b.Save(LoadOptions.ImageWriteToFileName, System.Drawing.Imaging.ImageFormat.Bmp);

            AddComment("Image.Width", b.Width);
            AddComment("Image.Height", b.Width);
            AddComment("Image.HorizontalResolution(DPI)", b.HorizontalResolution);
            AddComment("Image.VerticalResolution(DPI)", b.VerticalResolution);
            AddComment("ImageInvert", LoadOptions.ImageInvert.ToString());

            if (LoadOptions.MoveSpeed.HasValue)
            {
                var setspeed = new G01Command();
                setspeed.AddVariable('F', LoadOptions.MoveSpeed.Value);
                Commands.Add(setspeed);
            }

            WriteGCode();
        }
示例#2
0
        public override Command[] ConvertCommand(CommandState state, ConvertOptions options)
        {
            if (!options.SubstG82)
            {
                return(base.ConvertCommand(state, options));
            }

            // from
            // G82 X-8.8900 Y3.8100  Z-0.2794 F400 R0.5000  P0.000000
            // next command with R and P G82 X-11.4300 Y3.8100
            // to
            // G00 X-8.8900 Y3.8100
            // G01 Z-0.2794 F400
            // (G04 P0)
            // G00 Z0.5000

            Variable r = GetVariable('R');

            if (r == null)
            {
                r = state.G82R;
            }
            else
            {
                state.G82R = r.ShallowCopy();
            }

            Variable p = GetVariable('P');

            if (p == null)
            {
                p = state.G82P;
            }
            else
            {
                state.G82P = p.ShallowCopy();
            }

            Variable z = GetVariable('Z');

            if (z == null)
            {
                z = state.G82Z;
            }
            else
            {
                state.G82Z = z.ShallowCopy();
            }

            var list = new List <Command>();

            var move1 = new G00Command();

            CopyVariable('X', move1);
            CopyVariable('Y', move1);
            list.Add(move1);

            var move2 = new G01Command();

            move2.AddVariable('Z', z);
            CopyVariable('F', move2);
            list.Add(move2);

            if (p != null && Math.Abs(p.Value ?? 0.0) > double.Epsilon)
            {
                var move3 = new G04Command();
                move3.AddVariable('P', p);
                list.Add(move3);
            }

            var move4 = new G00Command();

            move4.AddVariable('Z', r);
            list.Add(move4);

            return(list.ToArray());
        }
示例#3
0
        private void CreateCircle(double x, double y, double radius)
        {
            if (radius < 0.000001) return;     // true black do nothing
            if (radius * 2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            Command c = new G00Command();
            c.AddVariable('X', ToGCode(x + radius - StartLaserDist));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);
            LaserOn();
            c = new G01Command();
            c.AddVariable('X', ToGCode(x + radius));
            Commands.Add(c);

            c = new G03Command();
            c.AddVariable('I', ToGCode(-radius));
            Commands.Add(c);
        }
示例#4
0
        private void CreateHeart(double x, double y, double hsizeX2, double hsizeY2, bool mirror)
        {
            if (hsizeX2 < 0.000001) return;     // true black do nothing
            if (hsizeX2 * 2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            hsizeX2 *= 0.9;
            hsizeY2 = hsizeX2;
            double mr = mirror ? -1.0 : 1.0;

            Command c = new G00Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + (hsizeY2 - StartLaserDist) * mr));
            Commands.Add(c);
            LaserOn();

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + hsizeY2*mr));
            Commands.Add(c);

            if (mirror)
                c = new G03Command();
            else
                 c= new G02Command();
            c.AddVariable('X', ToGCode(x+ hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            c.AddVariable('I', ToGCode( hsizeX2 / 2.0));
            c.AddVariable('J', ToGCode(-hsizeY2 / 2.0 * mr));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y-hsizeY2 * mr));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x - hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);

            if (mirror)
                c = new G03Command();
            else
                c = new G02Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + hsizeY2 * mr));
            c.AddVariable('I', ToGCode(hsizeX2 / 2.0));
            c.AddVariable('J', ToGCode(hsizeY2 / 2.0 * mr));
            Commands.Add(c);
        }
示例#5
0
        private void CreateDiamond(double x, double y, double hsizeX2, double hsizeY2)
        {
            if (hsizeX2 < 0.000001) return;     // true black do nothing
            if (hsizeX2 * 2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            Command c = new G00Command();
            c.AddVariable('X', ToGCode(x - hsizeX2 + StartLaserDist));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);
            LaserOn();

            c = new G01Command();
            c.AddVariable('X', ToGCode(x - hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y - hsizeY2));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x + hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x));
            c.AddVariable('Y', ToGCode(y + hsizeY2));
            Commands.Add(c);

            c = new G01Command();
            c.AddVariable('X', ToGCode(x - hsizeX2));
            c.AddVariable('Y', ToGCode(y));
            Commands.Add(c);
        }
示例#6
0
        private void CreateHexagon(double x, double y, double radius)
        {
            if (radius < 0.000001) return;     // true black do nothing
            if (radius*2 < LaserSize)
            {
                CreateToSmallShape(x, y);
                return;
            }

            double rotateangel = Math.PI / 6.0;

            double startx = x + radius * Math.Cos(rotateangel);
            double starty = y + radius * Math.Sin(rotateangel);

            Command c = new G00Command();
            c.AddVariable('X', ToGCode(startx - StartLaserDist));
            c.AddVariable('Y', ToGCode(starty - StartLaserDist / 2));
            Commands.Add(c);
            LaserOn();

            //for (double rad = Math.PI / 3.0; rad < Math.PI * 2.0 + 0.1; rad += Math.PI / 3.0)
            for (double rad = 0; rad < Math.PI * 2.0 + 0.1; rad += Math.PI / 3.0)
            {
                double radrotated = rad + Math.PI / 6.0;
                c = new G01Command();
                c.AddVariable('X', ToGCode(x + radius * Math.Cos(radrotated)));
                c.AddVariable('Y', ToGCode(y + radius * Math.Sin(radrotated)));

                Commands.Add(c);
            }
        }
示例#7
0
 private void CreateToSmallShape(double x, double y)
 {
     Command cc = new G00Command();
     cc.AddVariable('X', ToGCode(x));
     cc.AddVariable('Y', ToGCode(y));
     Commands.Add(cc);
     LaserOn();
     cc = new G01Command();
     cc.AddVariable('X', ToGCode(x));
     cc.AddVariable('Y', ToGCode(y));
     Commands.Add(cc);
 }
示例#8
0
文件: LoadHPGL.cs 项目: aiten/CNCLib
        public override void Load()
        {
            PreLoad();

            if (LoadOptions.AutoScale)
			{
				AutoScale();
			}

			AddComment("PenMoveType" , LoadOptions.PenMoveType.ToString() );

            switch (LoadOptions.PenMoveType)
            {
                case LoadOptions.PenType.CommandString:
					AddCommentForLaser();
                    break;
                case LoadOptions.PenType.ZMove:
                    AddComment("PenDownSpeed" , LoadOptions.EngraveDownSpeed );
                    AddComment("PenUpPos" ,     LoadOptions.EngravePosUp );
                    AddComment("PenDownPos" ,   LoadOptions.EngravePosDown );
                    break;
            }

            AddComment("Speed" , LoadOptions.MoveSpeed.ToString() );

            using (StreamReader sr = new StreamReader(LoadOptions.FileName))
            {
				if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove)
				{
                    AddCommands("M3");

					if (LoadOptions.EngravePosInParameter)
					{
						Commands.AddCommand(new SetParameterCommand() { GCodeAdd = "#1 = " + LoadOptions.EngravePosUp.ToString(CultureInfo.InvariantCulture) } );
						Commands.AddCommand(new SetParameterCommand() { GCodeAdd = "#2 = " + LoadOptions.EngravePosDown.ToString(CultureInfo.InvariantCulture) });
					}
				}

                if (LoadOptions.MoveSpeed.HasValue)
                {
                    var setspeed = new G01Command();
                    setspeed.AddVariable('F', LoadOptions.MoveSpeed.Value);
                    Commands.Add(setspeed);
                }

				string line;
                while ((line = sr.ReadLine()) != null)
                {
                    _stream.Line = line;
                    if (!Command(false))
                    {
                        Commands.Clear();
                        break;
                    }
                }

				if (!_lastIsPenUp)
				{
                    LoadPenUp();
				}

				if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove)
				{
                    AddCommands("M5");
				}
            }
			PostLoad();
        }
示例#9
0
文件: LoadHPGL.cs 项目: aiten/CNCLib
        private void LoadPenDown(Point3D pt)
		{
			if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove)
			{
				var r = new G01Command();
				if (LoadOptions.EngravePosInParameter)
				{
					r.AddVariableParam('Z', "2");
				}
				else
				{
					r.AddVariable('Z', LoadOptions.EngravePosDown);
				}
				if (LoadOptions.EngraveDownSpeed.HasValue)
				{
					r.AddVariable('F', LoadOptions.EngraveDownSpeed.Value);
					_needSpeed = LoadOptions.MoveSpeed.HasValue;
				}
				Commands.AddCommand(r);
			}
			else // if (LoadOptions.PenMoveType == LoadInfo.PenType.Command)
			{
				LaserOn();
			}

			AddCamBamPLine();
			AddCamBamPoint(pt);
		}
示例#10
0
文件: LoadHPGL.cs 项目: aiten/CNCLib
		private bool Command(bool analyse)
        {
            string[] cmds = new string[] { "PU", "PD", "PA", "PR", "SP" };
            while (!_stream.IsEOF())
            {
                int cmdidx = _stream.IsCommand(cmds);

                if (cmdidx==4)
                {
                    if (_stream.IsInt())
                    {
                        int coloridx = _stream.GetInt();
						if (coloridx >= 1 && coloridx <= 8)
							_color = (coloridx - 1); //  _pencolor[coloridx - 1];
                    }
                }
                else if (cmdidx >= 0)
                {
                    switch (cmdidx)
                    {
                        case 0: _IsPenUp = true; break;
                        case 1: _IsPenUp = false; break;
                    }

                    while (_stream.IsInt())
                    {
                        Point3D pt = GetSpaceCoordiante(cmdidx == 3);
                        if (cmdidx == 3)  // move rel
                        {
                            pt.X += _last.X;
                            pt.Y += _last.Y;
                        }

						if (!analyse && _IsPenUp != _lastIsPenUp)
						{
							if (_IsPenUp)
                            {
                                LoadPenUp();
                            }
                            else
                            {
                                LoadPenDown(_last);
                            }
							_lastIsPenUp = _IsPenUp;
						}

						_last = pt;

						if (!analyse)
						{
							Command r;
							if (_IsPenUp)
							{
								r = new G00Command();
							}
							else
							{
								r = new G01Command();
								AddCamBamPoint(pt);
							}
							r.AddVariable('X', pt.X.Value);
							r.AddVariable('Y', pt.Y.Value);
                            if (_needSpeed)
                            {
                                _needSpeed = false;
                                r.AddVariable('F', LoadOptions.MoveSpeed.Value);
                            }
                            Commands.AddCommand(r);
						}

                        _stream.IsCommand(",");
                    }
                }
                else
                {
                    // skip command
                    _stream.SkipEndCommand();
                }
            }

            return true;
        }
示例#11
0
文件: LoadImage.cs 项目: aiten/CNCLib
        private void AddCommandX(int x, int y, ref int lasty, bool laserOn)
        {
            // start laser a bit later but switch it off earlier
            double shift = 0;
            shift = laserOn ? _shiftLaserOff : _shiftLaserOn;

            if (y != lasty)
            {
                var cy = new G00Command();
                double x1 = (x * PixelSizeX) + ShiftX + shift - (double)LoadOptions.LaserAccDist;

				cy.AddVariable('X', ToGCode(x1));
                cy.AddVariable('Y', ToGCode((SizeY - y - 1) * PixelSizeY + ShiftY));
                lasty = y;
                Commands.Add(cy);
            }

			Command cx;
			// if we have no laser on/off we switch with g01 and g00
			bool use_g1 = HaveLaserOnOffCommand() || laserOn == true;
			if (use_g1)
				cx = new G01Command();
			else
				cx = new G00Command();

            cx.AddVariable('X', ToGCode((x * PixelSizeX) + ShiftX + shift));

			if (!use_g1)
				cx.AddVariableNoValue('F');

			Commands.Add(cx);
        }