public override string[] GetGCodeCommands(Point3D startfrom) { string[] ret = new string[] { GCodeAdd }; return ret; }
private void InitLoad() { _last = new Point3D(); _minpt = new Point3D() { X = int.MaxValue, Y = int.MaxValue }; _maxpt = new Point3D() { X = int.MinValue, Y = int.MinValue }; _stream = new CommandStream(); _IsPenUp = true; _color = Color.Black; }
protected void AddCamBamPoint(Point3D pt) { _pline.Pts.Add(new CamBam.CamBam.PLinePoints() { X = pt.X, Y = pt.Y, Z = pt.Z }); }
public void RotateXAngle90Grad() { var r = new Rotate3D(Math.PI / 2.0, new double[] { 1.0, 0, 0 }); var pt_src = new Point3D(1.0, 2.0, 3.0); var pt_dest = r.Rotate(pt_src); Assert.AreEqual(1.0, Math.Round(pt_dest.X.Value, 5)); Assert.AreEqual(-3.0, Math.Round(pt_dest.Y.Value, 5)); Assert.AreEqual(2.0, Math.Round(pt_dest.Z.Value,5)); }
public void RotateZAngleMinus90Grad() { var r = new Rotate3D(-Math.PI / 2.0, new double[] { 0, 0, 1.0 }); var pt_src = new Point3D(1.0, 2.0, 3.0); var pt_dest = r.Rotate(pt_src); Assert.AreEqual(2.0, Math.Round(pt_dest.X.Value, 5)); Assert.AreEqual(-1.0, Math.Round(pt_dest.Y.Value, 5)); Assert.AreEqual(3.0, pt_dest.Z.Value); }
public void NoRotateAngle0() { var r = new Rotate3D(); var pt_src = new Point3D(1.0, 2.0, 3.0); var pt_dest = r.Rotate(pt_src); Assert.AreEqual(1.0, pt_dest.X.Value); Assert.AreEqual(2.0, pt_dest.Y.Value); Assert.AreEqual(3.0, pt_dest.Z.Value); }
public void RotateXYZAngle90Grad() { var r = new Rotate3D(Math.PI / 2.0, new double[] { 1.0, 1.0, 1.0 }); var pt_src = new Point3D(1.0, 2.0, 3.0); var pt_dest = r.Rotate(pt_src); Assert.AreEqual(Math.Round(-2.2200846792814621,10), Math.Round(pt_dest.X.Value, 10)); Assert.AreEqual(Math.Round(-1.8213672050459184, 10), Math.Round(pt_dest.Y.Value, 10)); Assert.AreEqual(Math.Round(2.3987174742355446, 10), Math.Round(pt_dest.Z.Value, 10)); }
public void DrawArc(Command cmd, object param, DrawType drawtype, Point3D ptFrom, Point3D ptTo, Point3D pIJ, bool clockwise) { if (drawtype == DrawType.NoDraw) return; PaintEventArgs e = (PaintEventArgs)param; var from = ToClientF(ptFrom); var to = ToClientF(ptTo); pIJ = Rotate.Rotate(pIJ); double I = pIJ.X.Value; double J = pIJ.Y.Value; double R = Math.Sqrt(I * I + J * J); double cx = (ptFrom.X??0.0) + I; double cy = (ptFrom.Y??0.0) + J; double startAng = ConvertRadToDeg(Math.Atan2(J, I)); double endAng = ConvertRadToDeg(Math.Atan2(cy - (ptTo.Y??0.0), cx - (ptTo.X??0.0))); double diffAng = (endAng - startAng); if (startAng > endAng) diffAng += 360; if (clockwise == false) { startAng = endAng; diffAng = 360 - diffAng; while (diffAng > 360) diffAng -= 360; while (diffAng < -360) diffAng += 360; } var pt3d = new Point3D(cx - R * SignX, cy - R * SignY, ptFrom.Z??0); PointF rcfrom = ToClientF(pt3d); //Point rcfrom = new Point(ToClientXInt(cx - R * SignX), ToClientYInt(cy - R * SignY)); float RR = (float) ToClientSizeX(R * 2); var rec = new RectangleF(rcfrom, new SizeF(RR, RR)); //e.Graphics.DrawRectangle(_helpLine, rec); if (rec.Width > 0 && rec.Height > 0) { try { e.Graphics.DrawArc(GetPen(drawtype, LineDrawType.Arc), rec.X, rec.Y, rec.Width, rec.Height, (float)startAng, (float)diffAng); } catch (OutOfMemoryException) { // ignore this Exception } } }
public void DrawEllipse(Command cmd, object param, DrawType drawtype, Point3D ptCenter, int xradius, int yradius) { if (drawtype == DrawType.NoDraw) return; PaintEventArgs e = (PaintEventArgs)param; var from = ToClientF(ptCenter); e.Graphics.DrawEllipse(GetPen(drawtype, LineDrawType.Ellipse), from.X - xradius / 2, from.Y - yradius / 2, xradius, yradius); }
public void DrawLine(Command cmd, object param, DrawType drawtype, Point3D ptFrom, Point3D ptTo) { if (drawtype == DrawType.NoDraw) return; PaintEventArgs e = (PaintEventArgs)param; var from = ToClientF(ptFrom); var to = ToClientF(ptTo); if (PreDrawLineOrArc(param, drawtype, from, to)) { e.Graphics.DrawLine(GetPen(drawtype, LineDrawType.Line), from, to); } }
public Point3D Rotate(Point3D pt) { double x = pt.X ?? 0; double y = pt.Y ?? 0; double z = pt.Z ?? 0; Rotate(ref x, ref y, ref z); return new Point3D(x, y, z); }
private Point3D GetSpaceCoordiante(bool isRelativPoint) { Point3D pt = new Point3D(); pt.X = _stream.GetInt() / 40.0; _stream.IsCommand(",") ; pt.Y = _stream.GetInt() / 40.0; AdjustOrig(ref pt); if (pt.X != 0 || pt.Y != 0) { if (_minpt.X > pt.X) _minpt.X = pt.X; if (_minpt.Y > pt.Y) _minpt.Y = pt.Y; if (_maxpt.X < pt.X) _maxpt.X = pt.X; if (_maxpt.Y < pt.Y) _maxpt.Y = pt.Y; } Adjust(ref pt, isRelativPoint); return pt; }
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; }
public virtual bool ReadFrom(CommandStream stream) { Point3D ep = new Point3D(); if (stream.NextChar == '.') { stream.Next(); SubCode = stream.GetInt().ToString(); } if (PositionValid) { while (true) { switch (stream.SkipSpacesToUpper()) { case 'X': ep.X = ReadVariable(stream, stream.NextCharToUpper, false); break; case 'Y': ep.Y = ReadVariable(stream, stream.NextCharToUpper, false); break; case 'Z': ep.Z = ReadVariable(stream, stream.NextCharToUpper, false); break; case 'F': ReadVariable(stream, stream.NextCharToUpper, true); break; case 'R': case 'I': case 'J': case 'K': ReadVariable(stream,stream.NextCharToUpper, false); break; default: { ReadFromToEnd(stream); return true; } } } } else { ReadFromToEnd(stream); } return true; }
public void UpdateCalculatedEndPosition() { if (PositionValid) { var sc = new Point3D(); double val; if (TryGetVariable('X', out val)) sc.X = (double) val; if (TryGetVariable('Y', out val)) sc.Y = (double) val; if (TryGetVariable('Z', out val)) sc.Z = (double) val; if (!sc.HasAllValues && PrevCommand != null) { sc.AssignMissing(PrevCommand.CalculatedEndPosition); } _calculatedEndPosition = sc;; } else { _calculatedEndPosition = (PrevCommand == null) ? new Point3D() : PrevCommand._calculatedEndPosition; } }
public virtual string[] GetGCodeCommands(Point3D startfrom) { string[] ret = new string[] { GCodeHelper(startfrom) }; return ret; }
protected string GCodeHelper(Point3D current) { var cmd = Code; if (!string.IsNullOrEmpty(SubCode)) cmd += "." + SubCode; foreach (Variable p in _variables ) { cmd += " " + p.ToGCode(); } if (!string.IsNullOrEmpty(GCodeAdd)) { if (!string.IsNullOrEmpty(cmd)) cmd += " "; cmd += GCodeAdd; } return cmd; }
private void Adjust(ref Point3D pt,bool isRelativPoint) { if (!isRelativPoint) { pt.X += (double) LoadOptions.OfsX; pt.Y += (double) LoadOptions.OfsY; } if (LoadOptions.ScaleX != 0) pt.X = Math.Round(pt.X.Value * (double)LoadOptions.ScaleX, 3); if (LoadOptions.ScaleY != 0) pt.Y = Math.Round(pt.Y.Value * (double)LoadOptions.ScaleY, 3); }
private void AdjustOrig(ref Point3D pt) { if (LoadOptions.SwapXY) { var tmp = pt.X.Value; pt.X = pt.Y; pt.Y = -tmp; } }
public void AssignMissing(Point3D from) { if (!X.HasValue && from.X.HasValue) X = from.X; if (!Y.HasValue && from.Y.HasValue) Y = from.Y; if (!Z.HasValue && from.Z.HasValue) Z = from.Z; }
public void RotateXYZAngle90GradAndBack() { var r1 = new Rotate3D(Math.PI / 2.0, new double[] { 1.0, 1.0, 1.0 }); var r2 = new Rotate3D(-Math.PI / 2.0, new double[] { 1.0, 1.0, 1.0 }); var pt_src = new Point3D(1.0, 2.0, 3.0); var pt_rot = r1.Rotate(pt_src); var pt_dest = r2.Rotate(pt_rot); Assert.AreEqual(1.0, Math.Round(pt_dest.X.Value, 10)); Assert.AreEqual(2.0, Math.Round(pt_dest.Y.Value, 10)); Assert.AreEqual(3.0, Math.Round(pt_dest.Z.Value, 10)); }
public void GotoPos(Point3D pt) { new Task(() => { Com.SendCommand(string.Format(@"g0 x{0} y{1}", (pt.X??0.0).ToString(CultureInfo.InvariantCulture), (pt.Y?? 0.0).ToString(CultureInfo.InvariantCulture))); } ).Start(); }
PointF ToClientF(Point3D pt) { pt = _rotate3D.Rotate(pt); double x = (((pt.X ?? 0) - OffsetX) * Zoom) * _ratioX; double y = (((SizeY - (((pt.Y ?? 0)) + OffsetY))) * Zoom) * _ratioY; //double z = ((double)((double)(pt.Z ?? 0) - (double)OffsetZ) * Zoom) * _ratioZ; return new PointF((float) x, (float) y); }
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); }
private void GCodeUserControl_MouseDown(object sender, MouseEventArgs e) { if (_draggingType == EDraggingType.NoDragging) { var mousePos = e.GetPosition(this); var pt = new System.Drawing.PointF((float)mousePos.X, (float)mousePos.Y); if (IsGotoPosKey()) { var gcoderotated = _bitmapDraw.FromClient(pt, 0.0); if (GotoPos != null && GotoPos.CanExecute(gcoderotated)) GotoPos.Execute(gcoderotated); } else { _mouseDownPos = mousePos; _mouseDownCNCPos = _bitmapDraw.FromClient(pt); _mouseDownCNCOffsetX = OffsetX; _mouseDownCNCOffsetY = OffsetY; _sw.Start(); Mouse.Capture(this); if (e.RightButton == MouseButtonState.Pressed) _draggingType = EDraggingType.RotateAngle; else _draggingType = EDraggingType.Position; } } }
double ToClientSizeX(double X) { var pt3d = new Point3D(X, 0, 0); pt3d = Rotate.Rotate(pt3d); double x = (pt3d.X??0) * Zoom; return _ratioX * x; }
public void Offset(Point3D p) { if (X.HasValue && p.X.HasValue) X += p.X; if (Y.HasValue && p.Y.HasValue) Y += p.Y; if (Z.HasValue && p.Z.HasValue) Z += p.Z; }
double ToClientSizeY(double Y) { var pt3d = new Point3D(0,Y, 0); pt3d = Rotate.Rotate(pt3d); double y = (pt3d.Y ?? 0) * Zoom; return _ratioY * y; }
public bool CanGotoPos(Point3D pt) { return !_loadingOrSending && Com.IsConnected; }
private bool Command(List<Shape> shapes, 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 = _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; } _last = pt; if (!analyse) { if (_IsPenUp) { PolyLine r = new PolyLine(); r.ForgroundColor = _color; r.LineSize = 1; r.HPGLStart = r.HPGLEnd = pt; shapes.Add(r); } else { PolyLine r = (shapes.Count > 0) ? (PolyLine)shapes.Last() : null; if (r == null) { r = new PolyLine(); r.ForgroundColor = _color; r.LineSize = 1; r.HPGLStart = r.HPGLEnd = pt; shapes.Add(r); } r.Points.Add(new PolyLine.LinePoint() { HPGLPos = pt }); } } _stream.IsCommand(","); } } else { // skip command _stream.SkipEndCommand(); } } return true; }