Exemplo n.º 1
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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
		private void LoadPenUp()
        {
			if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove)
            {
                var r = new G00Command();
                if (LoadOptions.EngravePosInParameter)
                {
                    r.AddVariableParam('Z', "1");
                }
                else
                {
                    r.AddVariable('Z', LoadOptions.EngravePosUp);
                }
                Commands.AddCommand(r);
            }
            else // if (LoadOptions.PenMoveType == LoadInfo.PenType.Command)
            {
                LaserOff();
            }

			FinishCamBamPLine();
		}
Exemplo n.º 8
0
		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;
        }
Exemplo n.º 9
0
        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);
        }