private void pictureBoxVideo_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { measureAngleStop = (xyPoint)pictureBoxVideo.PointToClient(MousePosition); angle = (float)measureAngleStart.AngleTo(measureAngleStop); measureAngle = false; lblAngle.Text = String.Format("{0:0.00}°", angle); if (angle != 0) { cmsPictureBox.Visible = false; } else { cmsPictureBox.Visible = true; } } }
private void pictureBoxVideo_MouseDown(object sender, MouseEventArgs e) { //cmsPictureBox.Visible = true; if (e.Button == MouseButtons.Right) { measureAngleStart = (xyPoint)pictureBoxVideo.PointToClient(MousePosition); measureAngle = true; } if (e.Delta > 0) { nUDCameraZoom.Value += nUDCameraZoom.Increment; MessageBox.Show(e.Delta.ToString()); } if (e.Delta < 0) { nUDCameraZoom.Value -= nUDCameraZoom.Increment; } }
private xyPoint getPicBoxOffset(Point mouseLocation) { // backwards calculation to keep real coordinates on mouse-pos. on zoom-in -out double minx = VisuGCode.drawingSize.minX; double miny = VisuGCode.drawingSize.minY; double xRange = (VisuGCode.drawingSize.maxX - VisuGCode.drawingSize.minX); // calculate new size double yRange = (VisuGCode.drawingSize.maxY - VisuGCode.drawingSize.minY); if (Properties.Settings.Default.machineLimitsFix) { double offset = (double)Properties.Settings.Default.machineLimitsRangeX / 40; // view size minx = (double)Properties.Settings.Default.machineLimitsHomeX - grbl.posWCO.X - offset; miny = (double)Properties.Settings.Default.machineLimitsHomeY - grbl.posWCO.Y - offset; xRange = (double)Properties.Settings.Default.machineLimitsRangeX + 2 * offset; yRange = (double)Properties.Settings.Default.machineLimitsRangeY + 2 * offset; } double ratioVisu = xRange / yRange; double ratioPic = Convert.ToDouble(pictureBox1.Width) / pictureBox1.Height; double maxposY = yRange; if (ratioVisu > ratioPic) { maxposY = xRange * pictureBox1.Height / pictureBox1.Width; } double relposX = (picAbsPos.X - minx) / xRange; // double relposY = (yRange - picAbsPos.Y + miny) / yRange; double relposY = (maxposY - picAbsPos.Y + miny) / yRange; if (ratioVisu > ratioPic) { relposY = relposY * ratioPic / ratioVisu; } else { relposX = relposX * ratioVisu / ratioPic; } xyPoint picOffset = new xyPoint(); picOffset.X = mouseLocation.X - (relposX * zoomFactor * pictureBox1.Width); picOffset.Y = mouseLocation.Y - (relposY * zoomFactor * pictureBox1.Height); return(picOffset); }
private void ZoomScroll(Point location, int zoomIn) { if (showPicBoxBgImage || posIsMoving) // don't zoom if background image is shown { return; } if (zoomIn > 0) { if (zoomFactor < 1025) { pBoxTransform.Reset(); zoomTranslation = new xyPoint(location.X, location.Y) * zoomFactor + zoomTranslationOld;// + (moveTranslation * zoomFactor); pBoxTransform.Translate((float)-zoomTranslation.X, (float)-zoomTranslation.Y); zoomFactor *= scrollZoomFactor; pBoxTransform.Scale(zoomFactor, zoomFactor); } } else if (zoomIn < 0) { if (zoomFactor > 0.1) { pBoxTransform.Reset(); zoomFactor *= 1 / scrollZoomFactor; zoomTranslation = new xyPoint(location.X, location.Y) * -zoomFactor + zoomTranslationOld; pBoxTransform.Translate((float)-zoomTranslation.X, (float)-zoomTranslation.Y); pBoxTransform.Scale(zoomFactor, zoomFactor); } } zoomTranslationOld = zoomTranslation; if (zoomFactor == 1) { pBoxTransform.Reset(); zoomFactor = 1; zoomTranslation = new xyPoint(0, 0); zoomTranslationOld = new xyPoint(0, 0); } pictureBox1.Invalidate(); }
// find closest coordinate in GCode and mark private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { // MessageBox.Show(picAbsPosX + " " + picAbsPosY); pictureBox1.Focus(); moveTranslationOld = new xyPoint(e.X, e.Y); allowZoom = false; if (e.Button == MouseButtons.Left) { if ((fCTBCode.LinesCount > 2) && !posIsMoving) { int line = VisuGCode.setPosMarkerNearBy(picAbsPos); posMoveStart = picAbsPos; posMoveTmp = posMoveStart; posMoveEnd = posMoveStart; moveToMarkedPositionToolStripMenuItem.ToolTipText = "Work X: " + grbl.posMarker.X.ToString() + " Y: " + grbl.posMarker.Y.ToString(); fCTBCodeClickedLineNow = line; fCTBCodeMarkLine(); fCTBBookmark.DoVisible(); findFigureMarkSelection(Color.OrangeRed); posIsMoving = false; } } }
private void ZoomScroll(Point location, int zoomIn) { if (showPicBoxBgImage || posIsMoving) // don't zoom if background image is shown { return; } if (zoomIn > 0) { if (zoomFactor < 800) { zoomFactor *= scrollZoomFactor; xyPoint locationO = getPicBoxOffset(location); pBoxTransform.Reset(); pBoxTransform.Translate((float)locationO.X, (float)locationO.Y); pBoxTransform.Scale(zoomFactor, zoomFactor); } } else if (zoomIn < 0) { if (zoomFactor > 0.1) { zoomFactor *= 1 / scrollZoomFactor; xyPoint locationO = getPicBoxOffset(location); pBoxTransform.Reset(); pBoxTransform.Translate((float)locationO.X, (float)locationO.Y); pBoxTransform.Scale(zoomFactor, zoomFactor); } } if (Math.Round(zoomFactor, 2) == 1.00) { pBoxTransform.Reset(); zoomFactor = 1; } pictureBox1.Invalidate(); }
public void setDimensionArc(xyPoint oldPos, xyPoint newPos, double i, double j, bool isG2) { ArcProperties arcMove; arcMove = gcodeMath.getArcMoveProperties(oldPos, newPos, i, j, isG2); float x1 = (float)(arcMove.center.X - arcMove.radius); float x2 = (float)(arcMove.center.X + arcMove.radius); float y1 = (float)(arcMove.center.Y - arcMove.radius); float y2 = (float)(arcMove.center.Y + arcMove.radius); float r2 = 2 * (float)arcMove.radius; float aStart = (float)(arcMove.angleStart * 180 / Math.PI); float aDiff = (float)(arcMove.angleDiff * 180 / Math.PI); if (gcodeMath.isEqual(oldPos, newPos)) { setDimensionXY(x1, y1); setDimensionXY(x2, y2); } else { setDimensionCircle(arcMove.center.X, arcMove.center.Y, arcMove.radius, aStart, aDiff); // calculate new dimensions } }
public static ArcProperties getArcMoveProperties(xyPoint pOld, xyPoint pNew, xyPoint center, bool isG2) { return(getArcMoveProperties(pOld, pNew, pOld.X - center.X, pOld.Y - center.Y, isG2)); }
public static double distancePointToPoint(xyPoint a, xyPoint b) { return(Math.Sqrt(((a.X - b.X) * (a.X - b.X)) + ((a.Y - b.Y) * (a.Y - b.Y)))); }
public static bool isEqual(xyPoint a, xyPoint b) { return((Math.Abs(a.X - b.X) < precision) && (Math.Abs(a.Y - b.Y) < precision)); }
/// <summary> /// Process entities /// </summary> private static void processEntities(DXFEntity entity, double offsetX = 0, double offsetY = 0) { int index = 0; double x, y, x2 = 0, y2 = 0, bulge; if (dxfComments) { gcode.Comment(gcodeString[gcodeStringIndex], "Entity: " + entity.GetType().ToString()); gcode.Comment(gcodeString[gcodeStringIndex], "Color: " + entity.ColorNumber.ToString()); } if (entity.GetType() == typeof(DXFPointEntity)) { DXFPointEntity point = (DXFPointEntity)entity; x = (float)point.Location.X + (float)offsetX; y = (float)point.Location.Y + (float)offsetY; gcodeStartPath(x, y, "Start Point"); gcodeStopPath(); } #region DXFLWPolyline else if (entity.GetType() == typeof(DXFLWPolyLine)) { DXFLWPolyLine lp = (DXFLWPolyLine)entity; index = 0; bulge = 0; DXFLWPolyLine.Element coordinate; bool roundcorner = false; for (int i = 0; i < lp.VertexCount; i++) { coordinate = lp.Elements[i]; bulge = coordinate.Bulge; x = (double)coordinate.Vertex.X + (double)offsetX; y = (double)coordinate.Vertex.Y + (double)offsetY; if (i == 0) { gcodeStartPath(x, y, "Start LWPolyLine"); isReduceOk = true; } else { if (!roundcorner) { gcodeMoveTo(x, y, ""); } if (bulge != 0) { if (i < (lp.VertexCount - 1)) { AddRoundCorner(lp.Elements[i], lp.Elements[i + 1]); } else { AddRoundCorner(lp.Elements[i], lp.Elements[0]); } roundcorner = true; } else { roundcorner = false; } } x2 = x; y2 = y; } if (lp.Flags > 0) { gcodeMoveTo((float)lp.Elements[0].Vertex.X, (float)lp.Elements[0].Vertex.Y, "End LWPolyLine"); } gcodeStopPath(); } #endregion #region DXFPolyline else if (entity.GetType() == typeof(DXFPolyLine)) { DXFPolyLine lp = (DXFPolyLine)entity; index = 0; foreach (DXFVertex coordinate in lp.Children) { if (coordinate.GetType() == typeof(DXFVertex)) { if (coordinate.Location.X != null && coordinate.Location.Y != null) { x = (float)coordinate.Location.X + (float)offsetX; y = (float)coordinate.Location.Y + (float)offsetY; if (index == 0) { gcodeStartPath(x, y, "Start PolyLine"); } else { gcodeMoveTo(x, y, ""); } index++; } } } gcodeStopPath(); } #endregion #region DXFLine else if (entity.GetType() == typeof(DXFLine)) { DXFLine line = (DXFLine)entity; x = (float)line.Start.X + (float)offsetX; y = (float)line.Start.Y + (float)offsetY; x2 = (float)line.End.X + (float)offsetX; y2 = (float)line.End.Y + (float)offsetY; isReduceOk = false; gcodeStartPath(x, y, "Start Line"); gcodeMoveTo(x2, y2, ""); gcodeStopPath(); } #endregion #region DXFSpline else if (entity.GetType() == typeof(DXFSpline)) { DXFSpline spline = (DXFSpline)entity; index = 0; double cx0, cy0, cx1, cy1, cx2, cy2, cx3, cy3, cxMirror, cyMirror, lastX, lastY; lastX = (double)spline.ControlPoints[0].X + offsetX; lastY = (double)spline.ControlPoints[0].Y + offsetY; string cmt = "Start Spline " + spline.KnotValues.Count.ToString() + " " + spline.ControlPoints.Count.ToString() + " " + spline.FitPoints.Count.ToString(); gcodeStartPath(lastX, lastY, cmt); isReduceOk = true; for (int rep = 0; rep < spline.ControlPointCount; rep += 4) { cx0 = (double)spline.ControlPoints[rep].X + offsetX; cy0 = (double)spline.ControlPoints[rep].Y + offsetY; cx1 = (double)spline.ControlPoints[rep + 1].X + offsetX; cy1 = (double)spline.ControlPoints[rep + 1].Y + offsetY; cx2 = (double)spline.ControlPoints[rep + 2].X + offsetX; cy2 = (double)spline.ControlPoints[rep + 2].Y + offsetY; cx3 = (double)spline.ControlPoints[rep + 3].X + offsetX; cy3 = (double)spline.ControlPoints[rep + 3].Y + offsetY; points = new System.Windows.Point[4]; points[0] = new System.Windows.Point(cx0, cy0); //(qpx1, qpy1); points[1] = new System.Windows.Point(cx1, cy1); //(qpx1, qpy1); points[2] = new System.Windows.Point(cx2, cy2); //(qpx2, qpy2); points[3] = new System.Windows.Point(cx3, cy3); cxMirror = cx3 - (cx2 - cx3); cyMirror = cy3 - (cy2 - cy3); lastX = cx3; lastY = cy3; var b = GetBezierApproximation(points, dxfBezierAccuracy); for (int i = 1; i < b.Points.Count; i++) { gcodeMoveTo((float)b.Points[i].X, (float)b.Points[i].Y, ""); } } gcodeStopPath(); } #endregion #region DXFCircle else if (entity.GetType() == typeof(DXFCircle)) { DXFCircle circle = (DXFCircle)entity; x = (float)circle.Center.X + (float)offsetX; y = (float)circle.Center.Y + (float)offsetY; gcodeStartPath(x + circle.Radius, y, "Start Circle"); gcode.Arc(gcodeString[gcodeStringIndex], 2, (float)x + (float)circle.Radius, (float)y, -(float)circle.Radius, 0, ""); gcodeStopPath(); } #endregion else if (entity.GetType() == typeof(DXFEllipse)) { DXFEllipse circle = (DXFEllipse)entity; gcode.Comment(gcodeString[gcodeStringIndex], "Ellipse: " + circle.ColorNumber.ToString()); } #region DXFArc else if (entity.GetType() == typeof(DXFArc)) { DXFArc arc = (DXFArc)entity; double X = (double)arc.Center.X + offsetX; double Y = (double)arc.Center.Y + offsetY; double R = arc.Radius; double startAngle = arc.StartAngle; double endAngle = arc.EndAngle; if (startAngle > endAngle) { endAngle += 360; } double stepwidth = (double)Properties.Settings.Default.importGCSegment; float StepAngle = (float)(Math.Asin(stepwidth / R) * 180 / Math.PI);// Settings.Default.page11arcMaxLengLine); double currAngle = startAngle; index = 0; while (currAngle < endAngle) { double angle = currAngle * Math.PI / 180; double rx = (double)(X + R * Math.Cos(angle)); double ry = (double)(Y + R * Math.Sin(angle)); if (index == 0) { gcodeStartPath(rx, ry, "Start Arc"); isReduceOk = true; } else { gcodeMoveTo(rx, ry, ""); } currAngle += StepAngle; if (currAngle > endAngle) { double angle2 = endAngle * Math.PI / 180; double rx2 = (double)(X + R * Math.Cos(angle2)); double ry2 = (double)(Y + R * Math.Sin(angle2)); if (index == 0) { gcodeStartPath(rx2, ry2, "Start Arc"); } else { gcodeMoveTo(rx2, ry2, ""); } } index++; } gcodeStopPath(); } #endregion #region DXFMText else if (entity.GetType() == typeof(DXFMText)) { // https://www.autodesk.com/techpubs/autocad/acad2000/dxf/mtext_dxf_06.htm DXFMText txt = (DXFMText)entity; xyPoint origin = new xyPoint(0, 0); GCodeFromFont.reset(); foreach (var entry in txt.Entries) { if (entry.GroupCode == 1) { GCodeFromFont.gcText = entry.Value.ToString(); } else if (entry.GroupCode == 40) { GCodeFromFont.gcHeight = Convert.ToDouble(entry.Value); } // gcode.Comment(gcodeString[gcodeStringIndex], "Height "+entry.Value); } else if (entry.GroupCode == 41) { GCodeFromFont.gcWidth = Convert.ToDouble(entry.Value); } // gcode.Comment(gcodeString[gcodeStringIndex], "Width "+entry.Value); } else if (entry.GroupCode == 71) { GCodeFromFont.gcAttachPoint = Convert.ToInt16(entry.Value); } // gcode.Comment(gcodeString[gcodeStringIndex], "Origin " + entry.Value); } else if (entry.GroupCode == 10) { GCodeFromFont.gcOffX = Convert.ToDouble(entry.Value); } else if (entry.GroupCode == 20) { GCodeFromFont.gcOffY = Convert.ToDouble(entry.Value); } else if (entry.GroupCode == 50) { GCodeFromFont.gcAngle = Convert.ToDouble(entry.Value); } // gcode.Comment(gcodeString[gcodeStringIndex], "Angle " + entry.Value); } else if (entry.GroupCode == 44) { GCodeFromFont.gcSpacing = Convert.ToDouble(entry.Value); } else if (entry.GroupCode == 7) { GCodeFromFont.gcFontName = entry.Value.ToString(); } } GCodeFromFont.getCode(gcodeString[gcodeStringIndex]); } #endregion else { gcode.Comment(gcodeString[gcodeStringIndex], "Unknown: " + entity.GetType().ToString()); } }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { double minx = VisuGCode.drawingSize.minX; // extend dimensions double maxx = VisuGCode.drawingSize.maxX; double miny = VisuGCode.drawingSize.minY; double maxy = VisuGCode.drawingSize.maxY; double xRange = (maxx - minx); // calculate new size double yRange = (maxy - miny); if (Properties.Settings.Default.machineLimitsFix) { double offset = (double)Properties.Settings.Default.machineLimitsRangeX / 40; // view size minx = (double)Properties.Settings.Default.machineLimitsHomeX - grbl.posWCO.X - offset; miny = (double)Properties.Settings.Default.machineLimitsHomeY - grbl.posWCO.Y - offset; xRange = (double)Properties.Settings.Default.machineLimitsRangeX + 2 * offset; yRange = (double)Properties.Settings.Default.machineLimitsRangeY + 2 * offset; } double picScaling = Math.Min(pictureBox1.Width / (xRange), pictureBox1.Height / (yRange)); // calculate scaling px/unit if ((picScaling > 0.001) && (picScaling < 10000)) { double offsetX = 0; // pBoxTransform.OffsetX; double offsetY = 0; // pBoxTransform.OffsetY; try { offsetX = pBoxTransform.OffsetX; offsetY = pBoxTransform.OffsetY; } catch { } // pBoxTransform.Dispose too early double relposX = (Convert.ToDouble(pictureBox1.PointToClient(MousePosition).X) - offsetX) / Convert.ToDouble(pictureBox1.Width) / Convert.ToDouble(zoomFactor); double relposY = (Convert.ToDouble(pictureBox1.PointToClient(MousePosition).Y) - offsetY) / Convert.ToDouble(pictureBox1.Height) / Convert.ToDouble(zoomFactor); double ratioVisu = xRange / yRange; double ratioPic = Convert.ToDouble(pictureBox1.Width) / pictureBox1.Height; double maxposY = yRange; if (ratioVisu > ratioPic) { relposY = relposY * ratioVisu / ratioPic; maxposY = xRange * pictureBox1.Height / pictureBox1.Width; } else { relposX = relposX * ratioPic / ratioVisu; } picAbsPos.X = relposX * xRange + minx; // picAbsPos.Y = yRange - relposY * yRange + miny; picAbsPos.Y = maxposY - relposY * yRange + miny; if (posIsMoving) { posMoveEnd = picAbsPos; } /* Label position */ int offX = +5, offY = -10; if (pictureBox1.PointToClient(MousePosition).X > (pictureBox1.Width / 2)) { offX = -75; } if (pictureBox1.PointToClient(MousePosition).Y > (pictureBox1.Height / 2)) { offY = -30; } Point stringpos = new Point(pictureBox1.PointToClient(MousePosition).X + offX, pictureBox1.PointToClient(MousePosition).Y + offY); pBoxOrig = e.Graphics.Transform; try { e.Graphics.Transform = pBoxTransform; } catch { } e.Graphics.ScaleTransform((float)picScaling, (float)-picScaling); // apply scaling (flip Y) // e.Graphics.TranslateTransform((float)-minx, (float)(-yRange - miny)); // apply offset e.Graphics.TranslateTransform((float)-minx, (float)(-maxposY - miny)); // apply offset try { if (showPaths) // only show graphics path if something is loaded { if (!showPicBoxBgImage) { onPaint_drawToolPath(e.Graphics); // draw real path if background image is not shown } e.Graphics.DrawPath(penTool, VisuGCode.pathTool); e.Graphics.DrawPath(penMarker, VisuGCode.pathMarker); e.Graphics.Transform = pBoxOrig; if (Properties.Settings.Default.machineLimitsShow) { e.Graphics.FillRectangle(brushBackground, new Rectangle(stringpos.X, stringpos.Y - 2, 75, 34)); e.Graphics.FillRectangle(brushBackground, new Rectangle(18, 3, 140, 50)); if (VisuGCode.selectedFigureInfo.Length > 0) { e.Graphics.FillRectangle(brushBackground, new Rectangle(148, 3, 160, 50)); } } if (Properties.Settings.Default.gui2DInfoShow) { string unit = (Properties.Settings.Default.importUnitmm) ? "mm" : "Inch"; e.Graphics.DrawString(String.Format("Work-Pos:\r\nX:{0,7:0.000}\r\nY:{1,7:0.000}", picAbsPos.X, picAbsPos.Y), new Font("Lucida Console", 8), Brushes.Black, stringpos); if (simuEnabled) { e.Graphics.DrawString(String.Format("Zooming : {0,2:0.00}%\r\nRuler Unit: {1}\r\nMarker-Pos:\r\n X:{2,7:0.000}\r\n Y:{3,7:0.000}\r\n Z:{4,7:0.000}\r\n a:{5,7:0.000}°", 100 * zoomFactor, unit, grbl.posMarker.X, grbl.posMarker.Y, VisuGCode.Simulation.getZ(), 180 * grbl.posMarkerAngle / Math.PI), new Font("Lucida Console", 7), Brushes.Black, new Point(20, 5)); } else { e.Graphics.DrawString(String.Format("Zooming : {0,2:0.00}%\r\nRuler Unit: {1}\r\nMarker-Pos:\r\n X:{2,7:0.000}\r\n Y:{3,7:0.000}", 100 * zoomFactor, unit, grbl.posMarker.X, grbl.posMarker.Y), new Font("Lucida Console", 7), Brushes.Black, new Point(20, 5)); } if (VisuGCode.selectedFigureInfo.Length > 0) { e.Graphics.DrawString(VisuGCode.selectedFigureInfo, new Font("Lucida Console", 7), Brushes.Black, new Point(150, 5)); } } } } catch { } } }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { double minx = GCodeVisuAndTransform.drawingSize.minX; // extend dimensions double maxx = GCodeVisuAndTransform.drawingSize.maxX; double miny = GCodeVisuAndTransform.drawingSize.minY; double maxy = GCodeVisuAndTransform.drawingSize.maxY; double xRange = (maxx - minx); // calculate new size double yRange = (maxy - miny); if (Properties.Settings.Default.machineLimitsFix) { RectangleF tmp; float offset = (float)Properties.Settings.Default.machineLimitsRangeX / 40; // view size tmp = GCodeVisuAndTransform.pathMachineLimit.GetBounds(); minx = (float)Properties.Settings.Default.machineLimitsHomeX - (float)grbl.posWCO.X - offset; miny = (float)Properties.Settings.Default.machineLimitsHomeY - (float)grbl.posWCO.Y - offset; xRange = (float)Properties.Settings.Default.machineLimitsRangeX + 2 * offset; yRange = (float)Properties.Settings.Default.machineLimitsRangeY + 2 * offset; } double picScaling = Math.Min(pictureBox1.Width / (xRange), pictureBox1.Height / (yRange)); // calculate scaling px/unit string unit = (Properties.Settings.Default.importUnitmm) ? "mm" : "Inch"; if ((picScaling > 0.001) && (picScaling < 10000)) { // double relposX = zoomOffsetX + (Convert.ToDouble(pictureBox1.PointToClient(MousePosition).X - zoomTranslationOld.X ) / pictureBox1.Width) / zoomFactor; // double relposY = zoomOffsetY + (Convert.ToDouble(pictureBox1.PointToClient(MousePosition).Y - zoomTranslationOld.Y ) / pictureBox1.Height) / zoomFactor; double relposX = (Convert.ToDouble(pictureBox1.PointToClient(MousePosition).X - pBoxTransform.OffsetX) / pictureBox1.Width) / zoomFactor; double relposY = (Convert.ToDouble(pictureBox1.PointToClient(MousePosition).Y - pBoxTransform.OffsetY) / pictureBox1.Height) / zoomFactor; double ratioVisu = xRange / yRange; double ratioPic = Convert.ToDouble(pictureBox1.Width) / pictureBox1.Height; if (ratioVisu > ratioPic) { relposY = relposY * ratioVisu / ratioPic; } else { relposX = relposX * ratioPic / ratioVisu; } picAbsPos.X = relposX * xRange + minx; picAbsPos.Y = yRange - relposY * yRange + miny; posMoveEnd = picAbsPos; int offX = +5; if (pictureBox1.PointToClient(MousePosition).X > (pictureBox1.Width - 100)) { offX = -75; } Point stringpos = new Point(pictureBox1.PointToClient(MousePosition).X + offX, pictureBox1.PointToClient(MousePosition).Y - 10); pBoxOrig = e.Graphics.Transform; e.Graphics.Transform = pBoxTransform; e.Graphics.ScaleTransform((float)picScaling, (float)-picScaling); // apply scaling (flip Y) e.Graphics.TranslateTransform((float)-minx, (float)(-yRange - miny)); // apply offset if (showPaths) // only show graphics path if something is loaded { if (!showPicBoxBgImage) { onPaint_drawToolPath(e.Graphics); // draw real path if background image is not shown } e.Graphics.DrawPath(penMarker, GCodeVisuAndTransform.pathMarker); e.Graphics.DrawPath(penTool, GCodeVisuAndTransform.pathTool); e.Graphics.Transform = pBoxOrig; if (Properties.Settings.Default.machineLimitsShow) { e.Graphics.FillRectangle(brushBackground, new Rectangle(stringpos.X, stringpos.Y - 2, 75, 34)); e.Graphics.FillRectangle(brushBackground, new Rectangle(18, 3, 140, 50)); } if (Properties.Settings.Default.gui2DInfoShow) { e.Graphics.DrawString(String.Format("Work-Pos:\r\nX:{0,7:0.000}\r\nY:{1,7:0.000}", picAbsPos.X, picAbsPos.Y), new Font("Lucida Console", 8), Brushes.Black, stringpos); e.Graphics.DrawString(String.Format("Zooming : {0,2:0.00}%\r\nRuler Unit: {1}\r\nMarker-Pos:\r\n X:{2,7:0.000}\r\n Y:{3,7:0.000}", 100 * zoomFactor, unit, grbl.posMarker.X, grbl.posMarker.Y), new Font("Lucida Console", 7), Brushes.Black, new Point(20, 5)); if (visuGCode.selectedFigureInfo.Length > 0) { e.Graphics.DrawString(visuGCode.selectedFigureInfo, new Font("Lucida Console", 7), Brushes.Black, new Point(150, 5)); } } } } }
public static string transformGCodeRadiusCorrection(double radius) { Logger.Debug("Radius correction r: {0}", radius); #if (debuginfo) log.clear(); log.Add("### GCodeVisu radius correction ###"); #endif if (gcodeList == null) { return(""); } if (lastFigureNumber > 0) { pathBackground = (GraphicsPath)pathMarkSelection.Clone(); origWCOLandMark = (xyPoint)grbl.posWCO; } else { pathBackground = (GraphicsPath)pathPenDown.Clone(); origWCOLandMark = (xyPoint)grbl.posWCO; } xyPoint[] offset = new xyPoint[4]; int i, figureStart, figure2nd, prev, act, next; int counter = 0, isFirst = 0; bool figureProcessed = false; bool closeFigure = false; bool endFigure = false; figure2nd = figureStart = prev = act = next = 0; int offType = 0; for (i = 1; i < gcodeList.Count; i++) { if ((i == (gcodeList.Count - 1)) || ((lastFigureNumber > 0) && (gcodeList[i].figureNumber != lastFigureNumber))) // if wrong selection, nothing to do { if (figureProcessed) // correct last point { figureProcessed = false; goto ProcessesPath; } continue; } if (gcodeList[i].ismachineCoordG53) // machine coordinates, do not change { continue; } if (!xyMove(gcodeList[i])) // no xy moves, nothing to do - except G0 Z { continue; } while ((gcodeList[i].codeLine == gcodeList[i + 1].codeLine) && (i < gcodeList.Count)) // remove double lines (lff font) { gcodeList.RemoveAt(i + 1); } while (sameXYPos(gcodeList[i], gcodeList[i + 1]) && (i < (gcodeList.Count - 1))) // remove double coordinates { gcodeList.RemoveAt(i + 1); } #if (debuginfo) log.Add("----- " + i.ToString() + " -----"); #endif if (gcodeList[i].motionMode > 1) { double tmpR = Math.Sqrt((double)gcodeList[i].i * (double)gcodeList[i].i + (double)gcodeList[i].j * (double)gcodeList[i].j); bool remove = false; double abs_radius = Math.Abs(radius); if (gcodeList[i].motionMode == 2) { if ((radius < 0) && (tmpR < abs_radius)) { remove = true; } } if (gcodeList[i].motionMode == 3) { if ((radius > 0) && (tmpR < abs_radius)) { remove = true; } } if (remove) { gcodeList[i].i = null; gcodeList[i].j = null; gcodeList[i].motionMode = 1; #if (debuginfo) log.Add("Radius too small, do G1 " + gcodeList[act].codeLine + " ##############################"); #endif } } figureProcessed = true; // must stay before jump label next = i; endFigure = false; ProcessesPath: // gcodeList[i].info += " "+i.ToString()+" "+ figureProcessed.ToString()+" "+lastFigureNumber.ToString(); if (counter == 0) { figureStart = prev = act = next; } // preset indices if ((gcodeList[prev].motionMode == 0) && (gcodeList[act].motionMode >= 1)) // find start of figure { figureStart = prev; figure2nd = act; isFirst = 0; } //gcodeList[prev].info += " #start "; } if ((gcodeList[act].motionMode >= 1) && (gcodeList[next].motionMode == 0)) // find end of figure { endFigure = true; figureProcessed = false; } // gcodeList[act].info += " #end "; } closeFigure = false; if (act != prev) { xyArcPoint p1 = fillPointData(prev, prev); xyArcPoint p2 = fillPointData(prev, act); if ((gcodeList[act].actualPos.X == gcodeList[figureStart].actualPos.X) && (gcodeList[act].actualPos.Y == gcodeList[figureStart].actualPos.Y)) { next = figure2nd; closeFigure = true; } // gcodeList[act].info += " closefig "; } #if (debuginfo) log.Add(gcodeList[act].codeLine); #endif offType = createOffsetedPath((isFirst++ == 0), (endFigure && !closeFigure), figureStart, prev, act, next, radius, ref offset); #if (debuginfo) log.Add(string.Format(" typ {0} {1} {2} {3} {4} {5} ", offType, endFigure, figureStart, prev, act, next)); #endif if (closeFigure)// && !endFigure) { #if (debuginfo) log.Add(string.Format(" close Figure {0:0.00} {1:0.00} ", offset[2].X, offset[2].Y)); #endif gcodeList[figureStart].x = offset[2].X; gcodeList[figureStart].y = offset[2].Y; // close figure if (gcodeList[figure2nd].motionMode > 1) // act { bool isFullCircle = ((p1.X == p2.X) && (p1.Y == p2.Y)); if (!isFullCircle) { xyArcPoint p3 = fillPointData(prev, act); //fillPointData(act, next); gcodeList[figure2nd].i = p3.CX - offset[2].X; gcodeList[figure2nd].j = p3.CY - offset[2].Y; // offset radius #if (debuginfo) log.Add(string.Format(" correct Arc center of f2nd {0} origX {1:0.00} origY {2:0.00} ", figure2nd, p3.CX, p3.CY)); #endif } } } next = i; // restore next if (offType >= 1) // arc or line was inserted to connect points { act++; next++; counter++; i++; } // inc. counters } prev = act; act = next; counter++; if (endFigure) { prev = act; figureStart = act = i; } // preset indices if (closeFigure) { isFirst = 0; } } return(createGCodeProg()); }
/// <summary> /// mirror gcode /// </summary> public static string transformGCodeMirror(translate shiftToZero = translate.MirrorX) { Logger.Debug("Mirror {0}", shiftToZero); #if (debuginfo) log.Add(" GCodeVisu transform Mirror"); #endif if (gcodeList == null) { return(""); } xyPoint centerOfFigure = xyzSize.getCenter(); if (lastFigureNumber > 0) { centerOfFigure = getCenterOfMarkedFigure(); } oldLine.resetAll(grbl.posWork); // reset coordinates and parser modes clearDrawingnPath(); // reset path, dimensions foreach (gcodeByLine gcline in gcodeList) { if ((lastFigureNumber > 0) && (gcline.figureNumber != lastFigureNumber)) { continue; } if (!gcline.ismachineCoordG53) { // switch circle direction if ((shiftToZero == translate.MirrorX) || (shiftToZero == translate.MirrorY)) // mirror xy { if (gcline.motionMode == 2) { gcline.motionMode = 3; } else if (gcline.motionMode == 3) { gcline.motionMode = 2; } } if (shiftToZero == translate.MirrorX) // mirror x { if (gcline.x != null) { // if (gcline.isdistanceModeG90) // gcline.x = oldmaxx - gcline.x; // else gcline.x = -gcline.x + 2 * centerOfFigure.X; } gcline.i = -gcline.i; } if (shiftToZero == translate.MirrorY) // mirror y { if (gcline.y != null) { // if (gcline.isdistanceModeG90) // gcline.y = oldmaxy - gcline.y; // else gcline.y = -gcline.y + 2 * centerOfFigure.Y; } gcline.j = -gcline.j; } if (shiftToZero == translate.MirrorRotary) // mirror rotary { string rotary = Properties.Settings.Default.ctrl4thName; if ((rotary == "A") && (gcline.a != null)) { gcline.a = -gcline.a; } else if ((rotary == "B") && (gcline.b != null)) { gcline.b = -gcline.b; } else if ((rotary == "C") && (gcline.c != null)) { gcline.c = -gcline.c; } } calcAbsPosition(gcline, oldLine); oldLine = new gcodeByLine(gcline); // get copy of newLine } } return(createGCodeProg()); }
public double distance; // distance to specific point public coordByLine(int line, int figure, xyPoint p) { lineNumber = line; figureNumber = figure; actualPos = p; distance = -1; }
public coordByLine(int line, int figure, xyPoint p, double dist) { lineNumber = line; figureNumber = figure; actualPos = p; distance = dist; }
public static void MoveToSimple(xyPoint coordxy, string cmt, bool rapid = false) { MoveToSimple(new Point(coordxy.X, coordxy.Y), cmt, rapid); }
private void pictureBoxVideo_Paint(object sender, PaintEventArgs e) { double diff = cameraPosTop - cameraPosBot; if (diff == 0) { diff = 1; } double m = (cameraScalingTop - cameraScalingBot) / diff; double n = cameraScalingTop - m * cameraPosTop; float actualScaling = (float)Math.Abs(grbl.posMachine.Z * m + n); if (actualScaling < 1) { actualScaling = 5; } int gap = 5; int chlen = 200; e.Graphics.DrawLine(pen1, new System.Drawing.Point(xmid - chlen, ymid), new System.Drawing.Point(xmid - gap, ymid)); e.Graphics.DrawLine(pen1, new System.Drawing.Point(xmid + gap, ymid), new System.Drawing.Point(xmid + chlen, ymid)); e.Graphics.DrawLine(pen1, new System.Drawing.Point(xmid, ymid - chlen), new System.Drawing.Point(xmid, ymid - gap)); e.Graphics.DrawLine(pen1, new System.Drawing.Point(xmid, ymid + gap), new System.Drawing.Point(xmid, ymid + chlen)); realPosition.X = 2 * (Convert.ToDouble(pictureBoxVideo.PointToClient(MousePosition).X) / pictureBoxVideo.Size.Width - 0.5) * actualScaling / cameraZoom; realPosition.Y = -2 * (Convert.ToDouble(pictureBoxVideo.PointToClient(MousePosition).Y) / pictureBoxVideo.Size.Height - 0.5) * actualScaling * ratio / cameraZoom; int stringposY = -40; if (realPosition.Y > 0) { stringposY = 10; } System.Drawing.Point stringpos = new System.Drawing.Point(pictureBoxVideo.PointToClient(MousePosition).X - 60, pictureBoxVideo.PointToClient(MousePosition).Y + stringposY); if (teachingTop) { radius = (int)(cameraTeachRadiusTop * cameraZoom * xmid / actualScaling); e.Graphics.DrawEllipse(pen1, new Rectangle(xmid - radius, ymid - radius, 2 * radius, 2 * radius)); string txt = "Next click will teach scaling\r\n of camera view to " + cameraTeachRadiusTop.ToString(); showLabel(txt, stringpos, e.Graphics); } else if (teachingBot) { radius = (int)(cameraTeachRadiusBot * cameraZoom * xmid / actualScaling); e.Graphics.DrawEllipse(pen1, new Rectangle(xmid - radius, ymid - radius, 2 * radius, 2 * radius)); string txt = "Next click will teach scaling\r\n of camera view to " + cameraTeachRadiusBot.ToString(); showLabel(txt, stringpos, e.Graphics); } else if (measureAngle) { measureAngleStop = (xyPoint)pictureBoxVideo.PointToClient(MousePosition); e.Graphics.DrawLine(pen1, measureAngleStart.ToPoint(), measureAngleStop.ToPoint()); angle = (float)measureAngleStart.AngleTo(measureAngleStop); string txt = String.Format("Angle: {0:0.00}", angle); showLabel(txt, stringpos, e.Graphics); } else { xyPoint absolute = (xyPoint)grbl.posWork + realPosition; string txt = String.Format("Relative {0:0.00} ; {1:0.00}\r\nAbsolute {2:0.00} ; {3:0.00}", realPosition.X, realPosition.Y, absolute.X, absolute.Y); showLabel(txt, stringpos, e.Graphics); } /* if (teachTP1) * { * angle = (float)measureAngleStart.AngleTo(measureAngleStop); * e.Graphics.DrawString(String.Format("Angle: {0:0.00}", angle), new Font("Microsoft Sans Serif", 8), brushText, stringpos); * }*/ float scale = (float)(xmid / actualScaling * cameraZoom); e.Graphics.ScaleTransform(scale, -scale); float offX = (float)(xmid / scale - grbl.posWork.X); float offY = (float)(ymid / scale + grbl.posWork.Y); e.Graphics.TranslateTransform(offX, -offY); // apply offset // show drawing from MainForm (static members of class GCodeVisualization) if (showOverlay) { e.Graphics.DrawPath(penRuler, VisuGCode.pathRuler); e.Graphics.DrawPath(penMarker, VisuGCode.pathMarker); e.Graphics.DrawPath(penDown, VisuGCode.pathPenDown); e.Graphics.DrawPath(penUp, VisuGCode.pathPenUp); // e.Graphics.DrawEllipse(penTeach, new Rectangle((int)actualPosMarker.X-2, (int)actualPosMarker.Y - 2, (int)actualPosMarker.X + 2, (int)actualPosMarker.Y + 2)); } }
public void setPosMarker(xyPoint tmp)// double x, double y) { actualPosMarker = tmp; }
public void calcDistance(xyPoint tmp) { xyPoint delta = new xyPoint(tmp - (xyPoint)actualPos); distance = Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y); }
public xyPoint(xyPoint tmp) { X = tmp.X; Y = tmp.Y; }
public static double getAlpha(xyPoint pOld, xyPoint pNew) { return(getAlpha(pOld.X, pOld.Y, pNew.X, pNew.Y)); }
public xyzPoint(xyPoint xy, double z, double a = 0) { X = xy.X; Y = xy.Y; Z = z; A = a; B = 0; C = 0; }
public static int Next() { if (isIntermediate) { isIntermediate = calcIntermediatePos(); } if (!isIntermediate) { if (!getNextPos()) // finish simu if nextPos = false { grbl.posMarker = (xyPoint)codeNext.actualPos; grbl.posMarkerAngle = codeNext.alpha; createMarkerPath(false, (xyPoint)codeNext.actualPos); return(-1); } if (remainingStep <= 0) { remainingStep += stepWidth; } remainingStep -= distance; if (remainingStep == 0) // just next full pos { grbl.posMarker = (xyPoint)codeNext.actualPos; grbl.posMarkerAngle = codeNext.alpha; createMarkerPath(false, (xyPoint)codeNext.actualPos); posXY = grbl.posMarker; posA = grbl.posMarkerAngle; return(codeNext.lineNumber); } else if (remainingStep > 0) // move too short, get next gcode { while (remainingStep > 0) { if (!getNextPos()) // finish simu if nextPos = false // calc distance & remaining steps { grbl.posMarker = (xyPoint)codeNext.actualPos; grbl.posMarkerAngle = codeNext.alpha; createMarkerPath(false, (xyPoint)codeNext.actualPos); return(-codeNext.lineNumber); } remainingStep -= distance; } if (remainingStep == 0) // just next full pos { grbl.posMarker = (xyPoint)codeNext.actualPos; grbl.posMarkerAngle = codeNext.alpha; createMarkerPath(false, (xyPoint)codeNext.actualPos); posXY = grbl.posMarker; posA = grbl.posMarkerAngle; return(codeNext.lineNumber); } } // remainingStep < 0 calc intermediate steps posXY = (xyPoint)codeLast.actualPos; posAngle = codeLast.alpha; posZ = codeLast.actualPos.Z; posA = codeLast.alpha; diff.XY = ((xyPoint)codeLast.actualPos).DistanceTo((xyPoint)codeNext.actualPos); diff.Z = Math.Abs(codeNext.actualPos.Z - codeLast.actualPos.Z); diff.A = Math.Abs(codeNext.alpha - codeLast.alpha); isIntermediate = true; // Logger.Trace(" astart {0} aend {1}", 180*arcMove.angleStart/Math.PI, 180*arcMove.angleEnd/Math.PI); calcIntermediatePos(); remainingStep = stepWidth; } grbl.posMarker = posXY; grbl.posMarkerAngle = posA; // posAngle; createMarkerPath(false, posXY); return(codeNext.lineNumber); }
/// <summary> /// Process entities /// </summary> private static void processEntities(DXFEntity entity, double offsetX = 0, double offsetY = 0, bool updateColor = true) { int index = 0; double x, y;//, x2 = 0, y2 = 0, bulge; if (updateColor) { dxfColorID = entity.ColorNumber; Plotter.PathName = "Layer:" + entity.LayerName; } Plotter.PathDashArray = new double[0]; // default no dashes if ((entity.LineType == null) || (entity.LineType == "ByLayer")) { if (layerLType.ContainsKey(entity.LayerName)) // check if layer name is known { string dashType = layerLType[entity.LayerName]; // get name of pattern if (lineTypes.ContainsKey(dashType)) // check if pattern name is known { Plotter.PathDashArray = lineTypes[dashType]; // apply pattern } } } else { if (lineTypes.ContainsKey(entity.LineType)) // check if pattern name is known { Plotter.PathDashArray = lineTypes[entity.LineType]; // apply pattern } } if (dxfColorID > 255) { if (layerColor.ContainsKey(entity.LayerName)) { dxfColorID = layerColor[entity.LayerName]; } } if (dxfColorID < 0) { dxfColorID = 0; } if (dxfColorID > 255) { dxfColorID = 7; } if (Properties.Settings.Default.importDXFSwitchWhite && (dxfColorID == 7)) { dxfColorID = 0; } dxfColorHex = getColorFromID(dxfColorID); Plotter.PathColor = dxfColorHex; if (dxfUseColorIndex) { toolNr = dxfColorID + 1; // avoid ID=0 to start tool-table with index 1 } else { toolNr = toolTable.getToolNr(dxfColorHex, 0); //Logger.Trace("toolNr = {0}",toolNr); } Plotter.SetGroup(toolNr); // set index if grouping and tool if (dxfColorIDold != dxfColorID) { Plotter.PenUp(""); toolToUse = toolNr; if (Properties.Settings.Default.importGCToolTableUse && Properties.Settings.Default.importGCToolDefNrUse) { toolToUse = (int)Properties.Settings.Default.importGCToolDefNr; } Plotter.PathToolNr = toolToUse; if (!groupObjects) { if (dxfUseColorIndex) { Plotter.ToolChange(toolToUse, dxfColorID.ToString()); // add tool change commands (if enabled) and set XYFeed etc. } else { Plotter.ToolChange(toolToUse, dxfColorHex); } } } dxfColorIDold = dxfColorID; Logger.Trace(" Entity: {0}", entity.GetType().ToString()); if (entity.GetType() == typeof(DXFPointEntity)) { DXFPointEntity point = (DXFPointEntity)entity; x = (float)point.Location.X + (float)offsetX; y = (float)point.Location.Y + (float)offsetY; if (!nodesOnly) { dxfStartPath(x, y, "Start Point"); dxfStopPath(); } else { gcodeDotOnly(x, y, "Start Point"); } Logger.Trace(" Point: {0};{1} ", x, y); } #region DXFLWPolyline else if (entity.GetType() == typeof(DXFLWPolyLine)) { DXFLWPolyLine lp = (DXFLWPolyLine)entity; index = 0; double bulge = 0; DXFLWPolyLine.Element coordinate; bool roundcorner = false; x = 0; y = 0; for (int i = 0; i < lp.VertexCount; i++) { coordinate = lp.Elements[i]; bulge = coordinate.Bulge; // x2 = x; y2 = y; x = (double)coordinate.Vertex.X + (double)offsetX; y = (double)coordinate.Vertex.Y + (double)offsetY; // Logger.Trace(" Vertex: {0};{1} ", x, y); if (i == 0) { if (!nodesOnly) { dxfStartPath(x, y, "Start LWPolyLine - Nr pts " + lp.VertexCount.ToString()); Plotter.IsPathReduceOk = true; } else { gcodeDotOnly(x, y, "Start LWPolyLine"); } } if ((!roundcorner)) { dxfMoveTo(x, y, ""); } if (bulge != 0) { if (i < (lp.VertexCount - 1)) { AddRoundCorner(lp.Elements[i], lp.Elements[i + 1]); } else if (lp.Flags == DXFLWPolyLine.FlagsEnum.closed) { AddRoundCorner(lp.Elements[i], lp.Elements[0]); } roundcorner = true; } else { roundcorner = false; } } if ((lp.Flags > 0))// && (x2 != x) && (y2 != y)) // only move if prev pos is differnent { dxfMoveTo((float)(lp.Elements[0].Vertex.X + offsetX), (float)(lp.Elements[0].Vertex.Y + offsetY), "End LWPolyLine " + lp.Flags.ToString()); } dxfStopPath(); } #endregion #region DXFPolyline else if (entity.GetType() == typeof(DXFPolyLine)) { DXFPolyLine lp = (DXFPolyLine)entity; index = 0; foreach (DXFVertex coordinate in lp.Children) { if (coordinate.GetType() == typeof(DXFVertex)) { if (coordinate.Location.X != null && coordinate.Location.Y != null) { x = (float)coordinate.Location.X + (float)offsetX; y = (float)coordinate.Location.Y + (float)offsetY; // Logger.Trace(" Vertex: {0};{1} ", x, y); if (!nodesOnly) { if (index == 0) { dxfStartPath(x, y, "Start PolyLine"); } else { dxfMoveTo(x, y, ""); } } else { gcodeDotOnly(x, y, "PolyLine"); } index++; } } } dxfStopPath(); } #endregion #region DXFLine else if (entity.GetType() == typeof(DXFLine)) { DXFLine line = (DXFLine)entity; x = (double)line.Start.X + offsetX; y = (double)line.Start.Y + offsetY; double x2 = (double)line.End.X + offsetX; double y2 = (double)line.End.Y + offsetY; Plotter.IsPathReduceOk = false; if (!nodesOnly) { dxfStartPath(x, y, "Start Line"); dxfMoveTo(x2, y2, ""); } else { gcodeDotOnly(x, y, "Start Line"); gcodeDotOnly(x2, y2, "End Line"); } dxfStopPath(); Logger.Trace(" From: {0};{1} To: {2};{3}", x, y, x2, y2); } #endregion #region DXFSpline else if (entity.GetType() == typeof(DXFSpline)) { // from Inkscape DXF import - modified // https://gitlab.com/inkscape/extensions/blob/master/dxf_input.py#L106 DXFSpline spline = (DXFSpline)entity; index = 0; Point offset = new Point(offsetX, offsetY); double lastX = (double)spline.ControlPoints[0].X + offsetX; double lastY = (double)spline.ControlPoints[0].Y + offsetY; string cmt = "Start Spline " + spline.KnotValues.Count.ToString() + " " + spline.ControlPoints.Count.ToString() + " " + spline.FitPoints.Count.ToString(); Plotter.IsPathReduceOk = true; int knots = spline.KnotCount; int ctrls = spline.ControlPointCount; Logger.Trace(" Spline ControlPointCnt: {0} KnotsCount: {1}", ctrls, knots); if ((ctrls > 3) && (knots == ctrls + 4)) // # cubic { if (ctrls > 4) { for (int i = (knots - 5); i > 3; i--) { if ((spline.KnotValues[i] != spline.KnotValues[i - 1]) && (spline.KnotValues[i] != spline.KnotValues[i + 1])) { double a0 = (spline.KnotValues[i] - spline.KnotValues[i - 2]) / (spline.KnotValues[i + 1] - spline.KnotValues[i - 2]); double a1 = (spline.KnotValues[i] - spline.KnotValues[i - 1]) / (spline.KnotValues[i + 2] - spline.KnotValues[i - 1]); DXFPoint tmp = new DXFPoint(); tmp.X = (double)((1.0 - a1) * spline.ControlPoints[i - 2].X + a1 * spline.ControlPoints[i - 1].X); tmp.Y = (double)((1.0 - a1) * spline.ControlPoints[i - 2].Y + a1 * spline.ControlPoints[i - 1].Y); spline.ControlPoints.Insert(i - 1, tmp); spline.ControlPoints[i - 2].X = (1.0 - a0) * spline.ControlPoints[i - 3].X + a0 * spline.ControlPoints[i - 2].X; spline.ControlPoints[i - 2].Y = (1.0 - a0) * spline.ControlPoints[i - 3].Y + a0 * spline.ControlPoints[i - 2].Y; spline.KnotValues.Insert(i, spline.KnotValues[i]); } } knots = spline.KnotValues.Count; for (int i = (knots - 6); i > 3; i -= 2) { if ((spline.KnotValues[i] != spline.KnotValues[i - 2]) && (spline.KnotValues[i - 1] != spline.KnotValues[i + 1]) && (spline.KnotValues[i - 2] != spline.KnotValues[i])) { double a1 = (spline.KnotValues[i] - spline.KnotValues[i - 1]) / (spline.KnotValues[i + 2] - spline.KnotValues[i - 1]); DXFPoint tmp = new DXFPoint(); tmp.X = (double)((1.0 - a1) * spline.ControlPoints[i - 2].X + a1 * spline.ControlPoints[i - 1].X); tmp.Y = (double)((1.0 - a1) * spline.ControlPoints[i - 2].Y + a1 * spline.ControlPoints[i - 1].Y); spline.ControlPoints.Insert(i - 1, tmp); } } } ctrls = spline.ControlPoints.Count; dxfStartPath(lastX, lastY, cmt); for (int i = 0; i < Math.Floor((ctrls - 1) / 3d); i++) // for i in range(0, (ctrls - 1) // 3): { if (!nodesOnly) { importMath.calcCubicBezier(new Point(lastX, lastY), toPoint(spline.ControlPoints[3 * i + 1], offset), toPoint(spline.ControlPoints[3 * i + 2], offset), toPoint(spline.ControlPoints[3 * i + 3], offset), dxfMoveTo, "C"); } else { gcodeDotOnly(lastX, lastY, ""); gcodeDotOnly(toPoint(spline.ControlPoints[3 * i + 3], offset), ""); } lastX = (float)(spline.ControlPoints[3 * i + 3].X + offsetX); lastY = (float)(spline.ControlPoints[3 * i + 3].Y + offsetY); // path += ' C %f,%f %f,%f %f,%f' % (vals[groups['10']][3 * i + 1], vals[groups['20']][3 * i + 1], vals[groups['10']][3 * i + 2], vals[groups['20']][3 * i + 2], vals[groups['10']][3 * i + 3], vals[groups['20']][3 * i + 3]) } dxfStopPath(); } if ((ctrls == 3) && (knots == 6)) // # quadratic { // path = 'M %f,%f Q %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['10']][1], vals[groups['20']][1], vals[groups['10']][2], vals[groups['20']][2]) if (!nodesOnly) { dxfStartPath(lastX, lastY, cmt); importMath.calcQuadraticBezier(toPoint(spline.ControlPoints[0], offset), toPoint(spline.ControlPoints[1], offset), toPoint(spline.ControlPoints[2], offset), dxfMoveTo, "Q"); } else { gcodeDotOnly(lastX, lastY, ""); gcodeDotOnly(toPoint(spline.ControlPoints[2], offset), ""); } dxfStopPath(); } if ((ctrls == 5) && (knots == 8)) // # spliced quadratic { // path = 'M %f,%f Q %f,%f %f,%f Q %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['10']][1], vals[groups['20']][1], vals[groups['10']][2], vals[groups['20']][2], vals[groups['10']][3], vals[groups['20']][3], vals[groups['10']][4], vals[groups['20']][4]) if (!nodesOnly) { dxfStartPath(lastX, lastY, cmt); importMath.calcQuadraticBezier(toPoint(spline.ControlPoints[0], offset), toPoint(spline.ControlPoints[1], offset), toPoint(spline.ControlPoints[2], offset), dxfMoveTo, "SQ"); importMath.calcQuadraticBezier(toPoint(spline.ControlPoints[3], offset), toPoint(spline.ControlPoints[4], offset), toPoint(spline.ControlPoints[5], offset), dxfMoveTo, "SQ"); } else { gcodeDotOnly(lastX, lastY, ""); gcodeDotOnly(toPoint(spline.ControlPoints[2], offset), ""); gcodeDotOnly(toPoint(spline.ControlPoints[5], offset), ""); } dxfStopPath(); } } #endregion #region DXFCircle else if (entity.GetType() == typeof(DXFCircle)) { DXFCircle circle = (DXFCircle)entity; x = (float)circle.Center.X + (float)offsetX; y = (float)circle.Center.Y + (float)offsetY; dxfStartPath(x + circle.Radius, y, "Start Circle"); Plotter.Arc(2, (float)x + (float)circle.Radius, (float)y, -(float)circle.Radius, 0, ""); dxfStopPath(); Logger.Trace(" Center: {0};{1} R: {2}", x, y, circle.Radius); } #endregion #region DXFEllipse else if (entity.GetType() == typeof(DXFEllipse)) { // from Inkscape DXF import - modified // https://gitlab.com/inkscape/extensions/blob/master/dxf_input.py#L341 DXFEllipse ellipse = (DXFEllipse)entity; float xc = (float)ellipse.Center.X + (float)offsetX; float yc = (float)ellipse.Center.Y + (float)offsetY; float xm = (float)ellipse.MainAxis.X; float ym = (float)ellipse.MainAxis.Y; float w = (float)ellipse.AxisRatio; double a2 = -ellipse.StartParam; double a1 = -ellipse.EndParam; float rm = (float)Math.Sqrt(xm * xm + ym * ym); double a = Math.Atan2(-ym, xm); float diff = (float)((a2 - a1 + 2 * Math.PI) % (2 * Math.PI)); if ((Math.Abs(diff) > 0.0001) && (Math.Abs(diff - 2 * Math.PI) > 0.0001)) { int large = 0; if (diff > Math.PI) { large = 1; } float xt = rm * (float)Math.Cos(a1); float yt = w * rm * (float)Math.Sin(a1); float x1 = (float)(xt * Math.Cos(a) - yt * Math.Sin(a)); float y1 = (float)(xt * Math.Sin(a) + yt * Math.Cos(a)); xt = rm * (float)Math.Cos(a2); yt = w * rm * (float)Math.Sin(a2); float x2 = (float)(xt * Math.Cos(a) - yt * Math.Sin(a)); float y2 = (float)(xt * Math.Sin(a) + yt * Math.Cos(a)); dxfStartPath(xc + x1, yc - y1, "Start Ellipse 1"); importMath.calcArc(xc + x1, yc - y1, rm, w * rm, (float)(-180.0 * a / Math.PI), large, 0, (xc + x2), (yc - y2), dxfMoveTo); // path = 'M %f,%f A %f,%f %f %d 0 %f,%f' % (xc + x1, yc - y1, rm, w* rm, -180.0 * a / math.pi, large, xc + x2, yc - y2) } else { dxfStartPath(xc + xm, yc + ym, "Start Ellipse 2"); importMath.calcArc(xc + xm, yc + ym, rm, w * rm, (float)(-180.0 * a / Math.PI), 1, 0, xc - xm, yc - ym, dxfMoveTo); importMath.calcArc(xc - xm, yc - ym, rm, w * rm, (float)(-180.0 * a / Math.PI), 1, 0, xc + xm, yc + ym, dxfMoveTo); // path = 'M %f,%f A %f,%f %f 1 0 %f,%f %f,%f %f 1 0 %f,%f z' % (xc + xm, yc - ym, rm, w* rm, -180.0 * a / math.pi, xc - xm, yc + ym, rm, w* rm, -180.0 * a / math.pi, xc + xm, yc - ym) } dxfStopPath(); Logger.Trace(" Center: {0};{1} R1: {2} R2: {3} Start: {4} End: {5}", xc, yc, rm, w * rm, ellipse.StartParam, ellipse.EndParam); } #endregion #region DXFArc else if (entity.GetType() == typeof(DXFArc)) { DXFArc arc = (DXFArc)entity; double X = (double)arc.Center.X + offsetX; double Y = (double)arc.Center.Y + offsetY; double R = arc.Radius; double startAngle = arc.StartAngle; double endAngle = arc.EndAngle; if (startAngle > endAngle) { endAngle += 360; } double stepwidth = (double)Properties.Settings.Default.importGCSegment; // from setup-GCode modification-Avoid G2/3 commands... float StepAngle = (float)(Math.Asin(stepwidth / R) * 180 / Math.PI); double currAngle = startAngle; index = 0; if (!nodesOnly) { while (currAngle < endAngle) { double angle = currAngle * Math.PI / 180; double rx = (double)(X + R * Math.Cos(angle)); double ry = (double)(Y + R * Math.Sin(angle)); if (index == 0) { dxfStartPath(rx, ry, "Start Arc"); Plotter.IsPathReduceOk = true; } else { dxfMoveTo(rx, ry, ""); } currAngle += StepAngle; if (currAngle > endAngle) { double angle2 = endAngle * Math.PI / 180; double rx2 = (double)(X + R * Math.Cos(angle2)); double ry2 = (double)(Y + R * Math.Sin(angle2)); if (index == 0) { dxfStartPath(rx2, ry2, "Start Arc"); } else { dxfMoveTo(rx2, ry2, ""); } } index++; } dxfStopPath(); Logger.Trace(" Center: {0};{1} R: {2}", X, Y, R); } } #endregion #region DXFMText else if (entity.GetType() == typeof(DXFMText)) { // https://www.autodesk.com/techpubs/autocad/acad2000/dxf/mtext_dxf_06.htm DXFMText txt = (DXFMText)entity; xyPoint origin = new xyPoint(0, 0); GCodeFromFont.reset(); foreach (var entry in txt.Entries) { if (entry.GroupCode == 1) { GCodeFromFont.gcText = entry.Value.ToString(); } else if (entry.GroupCode == 40) { GCodeFromFont.gcHeight = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 41) { GCodeFromFont.gcWidth = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 71) { GCodeFromFont.gcAttachPoint = Convert.ToInt16(entry.Value); } else if (entry.GroupCode == 10) { GCodeFromFont.gcOffX = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat) + offsetX; } else if (entry.GroupCode == 20) { GCodeFromFont.gcOffY = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat) + offsetY; } else if (entry.GroupCode == 50) { GCodeFromFont.gcAngle = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 44) { GCodeFromFont.gcSpacing = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 7) { GCodeFromFont.gcFontName = entry.Value.ToString(); } } string tmp = string.Format("Id=\"{0}\" Color=\"#{1}\" ToolNr=\"{2}\"", dxfColorID, dxfColorHex, toolToUse); Plotter.InsertText(tmp); Plotter.IsPathFigureEnd = true; Logger.Trace(" Text: {0}", GCodeFromFont.gcText); } #endregion else { Plotter.Comment("Unknown: " + entity.GetType().ToString()); } }
{ // http://www.hinterseher.de/Diplomarbeit/GeometrischeFunktionen.html // get two lines and calc offsetted points public static int getPointOffsets(ref xyPoint[] offset, xyArcPoint P0, xyArcPoint P1, xyArcPoint P2, double distance, bool isEnd) { xyPoint[] S1off = new xyPoint[2]; xyPoint[] S2off = new xyPoint[2]; double a0 = 0, a1 = 0, a2 = 0, a3 = 0, adelta; double newRadius1 = distance; double newRadius2 = distance; if (P1.mode <= 1) // is a line { a1 = getAlphaLine(P0, P1); a0 = a1; calcOffsetLine(ref S1off, P0, P1, a1 + Math.PI / 2, distance); // offset by 90° } else { a0 = getAlphaCenterToPoint(P1, P0); // from center to start a1 = getAlphaCenterToPoint(P1, P1); // from center to end double usea0 = a0, usea1 = a1; a0 -= Math.PI / 2; a1 -= Math.PI / 2; // tangente if (P1.mode == 3) { usea0 += Math.PI; usea1 += Math.PI; // add 180° a0 += Math.PI; a1 += Math.PI; // tangente reverse } S1off[0] = calcOffsetPoint(P0, usea0, distance); // extend radius S1off[1] = calcOffsetPoint(P1, usea1, distance); // extend radius newRadius1 = Math.Sqrt((P1.CX - S1off[0].X) * (P1.CX - S1off[0].X) + (P1.CY - S1off[0].Y) * (P1.CY - S1off[0].Y)); } offset[0] = S1off[0]; offset[1] = S1off[1]; #if (debuginfo) log.Add(string.Format(" getPointOffsets P0-P1: P1mode: {0} S1offX {1:0.000} S1offX {2:0.000} S1offX {3:0.000} S1offX {4:0.000}", P1.mode, S1off[0].X, S1off[0].Y, S1off[1].X, S1off[1].Y)); #endif if (P2.mode <= 1) // is a line { a2 = getAlphaLine(P1, P2); a3 = a2; calcOffsetLine(ref S2off, P1, P2, a2 + Math.PI / 2, distance); // offset by 90° } else { a2 = getAlphaCenterToPoint(P2, P1); // from center to start a3 = getAlphaCenterToPoint(P2, P2); // from center to end double usea2 = a2, usea3 = a3; a2 -= Math.PI / 2; a3 -= Math.PI / 2; // tangente if (P2.mode == 3) { usea2 += Math.PI; usea3 += Math.PI; // add 180° a2 += Math.PI; a3 += Math.PI; // tangente reverse } S2off[0] = calcOffsetPoint(P1, usea2, distance); // extend radius S2off[1] = calcOffsetPoint(P2, usea3, distance); // extend radius newRadius2 = Math.Sqrt((P2.CX - S2off[0].X) * (P2.CX - S2off[0].X) + (P2.CY - S2off[0].Y) * (P2.CY - S2off[0].Y)); } offset[2] = S2off[0]; offset[3] = S2off[1]; #if (debuginfo) log.Add(string.Format(" getPointOffsets P1-P2: P2mode: {0} S1offX {1:0.000} S1offX {2:0.000} S1offX {3:0.000} S1offX {4:0.000}", P2.mode, S2off[0].X, S2off[0].Y, S2off[1].X, S2off[1].Y)); #endif if ((P1.mode == P2.mode) && (P1.X == P2.X) && (P1.Y == P2.Y)) { a2 = a0; a3 = a1; } // compare angle of both lines P0-P1 and P1-P2 adelta = a2 - a1; double dist = offset[1].DistanceTo(offset[2]); #if (debuginfo) log.Add(string.Format(" getPointOffsets Angles: a1 {0:0.000} a2 {1:0.000} delta {2:0.000}", (a1 * 180 / Math.PI), (a2 * 180 / Math.PI), (adelta * 180 / Math.PI))); #endif if (adelta >= (Math.PI)) { adelta -= 2 * Math.PI; } if (adelta <= -(Math.PI)) { adelta += 2 * Math.PI; } #if (debuginfo) log.Add(string.Format(" getPointOffsets adelta corrected {0:0.000}", (adelta * 180 / Math.PI))); log.Add(string.Format(" getPointOffsets offset [0]x{0:0.000} [0]y{1:0.000} [1]x{2:0.000} [1]y{3:0.000} [2]x{4:0.000} [2]y{5:0.000}", offset[0].X, offset[0].Y, offset[1].X, offset[1].Y, offset[2].X, offset[2].Y)); #endif if (isEnd || (Math.Abs(adelta) <= 0.2) || (dist < 0.2)) { return(0); // S1-angle == S2-angle, no correction needed } if (Math.Abs(Math.Abs(adelta) - Math.PI) <= 0.2) { return(1); // 180° } if ((adelta > 0) && (distance < 0)) { return(1); // connect lines with additional arc } if ((adelta < 0) && (distance > 0)) { return(1); // connect lines with additional arc } #if (debuginfo) log.Add(string.Format(" getPointOffsets Find intersection {0} {1}", P1.mode, P2.mode)); #endif bool result = false; // find common intersection if ((P1.mode <= 1) && (P2.mode <= 1)) // line to line { // https://www.java-forum.org/thema/algorithmus-fuer-pruefung-auf-ueberschneidende-linien.117102/ double d = (S1off[1].X - S1off[0].X) * (S2off[0].Y - S2off[1].Y) - (S2off[0].X - S2off[1].X) * (S1off[1].Y - S1off[0].Y); if (d == 0) { offset[2] = offset[1] = offset[3]; } else { double m = ((S2off[0].X - S1off[0].X) * (S2off[0].Y - S2off[1].Y) - (S2off[0].X - S2off[1].X) * (S2off[0].Y - S1off[0].Y)) / d; double n = ((S1off[1].X - S1off[0].X) * (S2off[0].X - S1off[0].X) - (S2off[0].Y - S1off[0].Y) * (S1off[1].Y - S1off[0].Y)) / d; offset[1].X = S1off[0].X + m * (S1off[1].X - S1off[0].X); offset[1].Y = S1off[0].Y + m * (S1off[1].Y - S1off[0].Y); offset[2] = offset[1]; } } else if ((P1.mode <= 1) && (P2.mode >= 2)) // 1st line then arc { result = calcIntersectionLineArc(ref offset, S1off, P2, newRadius2); } else if ((P1.mode >= 2) && (P2.mode <= 1)) // 1st arc then line { xyPoint tmp = S2off[0]; S2off[0] = S2off[1]; S2off[1] = tmp; // switch points, p[1] should be connection to arc result = calcIntersectionLineArc(ref offset, S2off, P1, newRadius1); } else { // 1st arc 2nd arc, transfer one arc to line to use available function calcIntersectionLineArc // http://www2.math.uni-wuppertal.de/~volkert/Das%20Apollonische%20Beruehrproblem,%202007.pdf double dy = P2.CY - P1.CY; double dx = P2.CX - P1.CX; if (dy == 0) // center points of arcs on same y -> chordale = vertical line { double a = (newRadius2 * newRadius2 - newRadius1 * newRadius1 - dx * dx) / (-2 * dx); double px = P1.CX + a; // vertical line S1off[0].X = S1off[1].X = px; S1off[0].Y = -P1.Y; S1off[1].Y = P1.Y; result = calcIntersectionLineArc(ref offset, S1off, P2, newRadius2); } else if (dx == 0) // center points of arcs on same x -> chordale = horizontal line { double a = (newRadius2 * newRadius2 - newRadius1 * newRadius1 - dy * dy) / (-2 * dy); double py = P1.CY + a; // horizontal line S1off[0].Y = S1off[1].Y = py; S1off[0].X = -P1.X; S1off[1].X = P1.X; result = calcIntersectionLineArc(ref offset, S1off, P2, newRadius2); } else { double c = Math.Sqrt(dx * dx + dy * dy); double a = (newRadius2 * newRadius2 - newRadius1 * newRadius1 - c * c) / (-2 * c); double m = dy / dx; double angle = getAlphaCenterToCenter(P1, P2); xyPoint aP = new xyPoint(); aP = calcOffsetPoint(new xyPoint(P1.CX, P1.CY), angle, a); angle += Math.PI / 2; S1off[0] = calcOffsetPoint(aP, angle, newRadius1); // create line from point S1off[1] = calcOffsetPoint(aP, angle, -newRadius1); // create line from point double d0 = S1off[0].DistanceTo((xyPoint)P1); double d1 = S1off[1].DistanceTo((xyPoint)P1); if (d1 > d0) // index 1 should be closer to final pos { S1off[1] = calcOffsetPoint(aP, angle, newRadius1); // create line from point S1off[0] = calcOffsetPoint(aP, angle, -newRadius1); // create line from point } result = calcIntersectionLineArc(ref offset, S1off, P2, newRadius2); } if ((double.IsNaN(offset[1].X)) || double.IsNaN(offset[1].Y)) { offset[1].X = 0; offset[1].Y = 0; offset[2] = offset[1]; } } if (result == true) // intersection successful { return(-1); } else { return(-2); } }
/// <summary> /// Process entities /// </summary> private static void processEntities(DXFEntity entity, double offsetX = 0, double offsetY = 0, bool updateColor = true) { int index = 0; double x, y, x2 = 0, y2 = 0, bulge; if (updateColor) { dxfColorID = entity.ColorNumber; Plotter.PathName = "Layer:" + entity.LayerName; } Plotter.PathDashArray = new double[0]; // default no dashes if (entity.LineType == "ByLayer") { if (layerLType.ContainsKey(entity.LayerName)) // check if layer name is known { string dashType = layerLType[entity.LayerName]; // get name of pattern if (lineTypes.ContainsKey(dashType)) // check if pattern name is known { Plotter.PathDashArray = lineTypes[dashType]; // apply pattern } } } else { if (lineTypes.ContainsKey(entity.LineType)) // check if pattern name is known { Plotter.PathDashArray = lineTypes[entity.LineType]; // apply pattern } } if (dxfColorID > 255) { if (layerColor.ContainsKey(entity.LayerName)) { dxfColorID = layerColor[entity.LayerName]; } } if (dxfColorID < 0) { dxfColorID = 0; } if (dxfColorID > 255) { dxfColorID = 7; } if (Properties.Settings.Default.importDXFSwitchWhite && (dxfColorID == 7)) { dxfColorID = 0; } dxfColorHex = getColorFromID(dxfColorID); Plotter.PathColor = dxfColorHex; if (dxfUseColorIndex) { toolNr = dxfColorID + 1; // avoid ID=0 to start tool-table with index 1 } else { toolNr = toolTable.getToolNr(dxfColorHex, 0); //Logger.Trace("toolNr = {0}",toolNr); } Plotter.SetGroup(toolNr); // set index if grouping and tool if (dxfColorIDold != dxfColorID) { Plotter.PenUp(""); toolToUse = toolNr; if (Properties.Settings.Default.importGCToolTableUse && Properties.Settings.Default.importGCToolDefNrUse) { toolToUse = (int)Properties.Settings.Default.importGCToolDefNr; } Plotter.PathToolNr = toolToUse; if (!groupObjects) { if (dxfUseColorIndex) { Plotter.ToolChange(toolToUse, dxfColorID.ToString()); // add tool change commands (if enabled) and set XYFeed etc. } else { Plotter.ToolChange(toolToUse, dxfColorHex); } } } dxfColorIDold = dxfColorID; if (entity.GetType() == typeof(DXFPointEntity)) { DXFPointEntity point = (DXFPointEntity)entity; x = (float)point.Location.X + (float)offsetX; y = (float)point.Location.Y + (float)offsetY; if (!nodesOnly) { dxfStartPath(x, y, "Start Point"); dxfStopPath(); } else { gcodeDotOnly(x, y, "Start Point"); } } #region DXFLWPolyline else if (entity.GetType() == typeof(DXFLWPolyLine)) { DXFLWPolyLine lp = (DXFLWPolyLine)entity; index = 0; bulge = 0; DXFLWPolyLine.Element coordinate; bool roundcorner = false; x = 0; y = 0; for (int i = 0; i < lp.VertexCount; i++) { coordinate = lp.Elements[i]; bulge = coordinate.Bulge; x2 = x; y2 = y; x = (double)coordinate.Vertex.X + (double)offsetX; y = (double)coordinate.Vertex.Y + (double)offsetY; if (i == 0) { if (!nodesOnly) { dxfStartPath(x, y, "Start LWPolyLine - Nr pts " + lp.VertexCount.ToString()); Plotter.IsPathReduceOk = true; } else { gcodeDotOnly(x, y, "Start LWPolyLine"); } } if ((!roundcorner)) { dxfMoveTo(x, y, ""); } if (bulge != 0) { if (i < (lp.VertexCount - 1)) { AddRoundCorner(lp.Elements[i], lp.Elements[i + 1]); } else if (lp.Flags == DXFLWPolyLine.FlagsEnum.closed) { AddRoundCorner(lp.Elements[i], lp.Elements[0]); } roundcorner = true; } else { roundcorner = false; } } if ((lp.Flags > 0))// && (x2 != x) && (y2 != y)) // only move if prev pos is differnent { dxfMoveTo((float)(lp.Elements[0].Vertex.X + offsetX), (float)(lp.Elements[0].Vertex.Y + offsetY), "End LWPolyLine " + lp.Flags.ToString()); } dxfStopPath(); } #endregion #region DXFPolyline else if (entity.GetType() == typeof(DXFPolyLine)) { DXFPolyLine lp = (DXFPolyLine)entity; index = 0; foreach (DXFVertex coordinate in lp.Children) { if (coordinate.GetType() == typeof(DXFVertex)) { if (coordinate.Location.X != null && coordinate.Location.Y != null) { x = (float)coordinate.Location.X + (float)offsetX; y = (float)coordinate.Location.Y + (float)offsetY; if (!nodesOnly) { if (index == 0) { dxfStartPath(x, y, "Start PolyLine"); } else { dxfMoveTo(x, y, ""); } } else { gcodeDotOnly(x, y, "PolyLine"); } index++; } } } dxfStopPath(); } #endregion #region DXFLine else if (entity.GetType() == typeof(DXFLine)) { DXFLine line = (DXFLine)entity; x = (float)line.Start.X + (float)offsetX; y = (float)line.Start.Y + (float)offsetY; x2 = (float)line.End.X + (float)offsetX; y2 = (float)line.End.Y + (float)offsetY; Plotter.IsPathReduceOk = false; if (!nodesOnly) { dxfStartPath(x, y, "Start Line"); dxfMoveTo(x2, y2, ""); } else { gcodeDotOnly(x, y, "Start Line"); gcodeDotOnly(x2, y2, "End Line"); } dxfStopPath(); } #endregion #region DXFSpline else if (entity.GetType() == typeof(DXFSpline)) { DXFSpline spline = (DXFSpline)entity; index = 0; double cx0, cy0, cx1, cy1, cx2, cy2, cx3, cy3, cxMirror, cyMirror, lastX, lastY; lastX = (double)spline.ControlPoints[0].X + offsetX; lastY = (double)spline.ControlPoints[0].Y + offsetY; string cmt = "Start Spline " + spline.KnotValues.Count.ToString() + " " + spline.ControlPoints.Count.ToString() + " " + spline.FitPoints.Count.ToString(); dxfStartPath(lastX, lastY, cmt); Plotter.IsPathReduceOk = true; for (int rep = 0; rep < spline.ControlPointCount; rep += 4) { cx0 = (double)spline.ControlPoints[rep].X + offsetX; cy0 = (double)spline.ControlPoints[rep].Y + offsetY; cx1 = (double)spline.ControlPoints[rep + 1].X + offsetX; cy1 = (double)spline.ControlPoints[rep + 1].Y + offsetY; cx2 = (double)spline.ControlPoints[rep + 2].X + offsetX; cy2 = (double)spline.ControlPoints[rep + 2].Y + offsetY; cx3 = (double)spline.ControlPoints[rep + 3].X + offsetX; cy3 = (double)spline.ControlPoints[rep + 3].Y + offsetY; points = new System.Windows.Point[4]; points[0] = new System.Windows.Point(cx0, cy0); //(qpx1, qpy1); points[1] = new System.Windows.Point(cx1, cy1); //(qpx1, qpy1); points[2] = new System.Windows.Point(cx2, cy2); //(qpx2, qpy2); points[3] = new System.Windows.Point(cx3, cy3); cxMirror = cx3 - (cx2 - cx3); cyMirror = cy3 - (cy2 - cy3); lastX = cx3; lastY = cy3; var b = GetBezierApproximation(points, dxfBezierAccuracy); if (!nodesOnly) { for (int i = 1; i < b.Points.Count; i++) { dxfMoveTo((float)b.Points[i].X, (float)b.Points[i].Y, ""); } } else { gcodeDotOnly(cx3, cy3, "Bezier"); } } dxfStopPath(); } #endregion #region DXFCircle else if (entity.GetType() == typeof(DXFCircle)) { DXFCircle circle = (DXFCircle)entity; x = (float)circle.Center.X + (float)offsetX; y = (float)circle.Center.Y + (float)offsetY; dxfStartPath(x + circle.Radius, y, "Start Circle"); Plotter.Arc(2, (float)x + (float)circle.Radius, (float)y, -(float)circle.Radius, 0, ""); dxfStopPath(); } #endregion else if (entity.GetType() == typeof(DXFEllipse)) { DXFEllipse circle = (DXFEllipse)entity; Plotter.Comment("Ellipse: " + circle.ColorNumber.ToString()); } #region DXFArc else if (entity.GetType() == typeof(DXFArc)) { DXFArc arc = (DXFArc)entity; double X = (double)arc.Center.X + offsetX; double Y = (double)arc.Center.Y + offsetY; double R = arc.Radius; double startAngle = arc.StartAngle; double endAngle = arc.EndAngle; if (startAngle > endAngle) { endAngle += 360; } double stepwidth = (double)Properties.Settings.Default.importGCSegment; float StepAngle = (float)(Math.Asin(stepwidth / R) * 180 / Math.PI);// Settings.Default.page11arcMaxLengLine); double currAngle = startAngle; index = 0; if (!nodesOnly) { while (currAngle < endAngle) { double angle = currAngle * Math.PI / 180; double rx = (double)(X + R * Math.Cos(angle)); double ry = (double)(Y + R * Math.Sin(angle)); if (index == 0) { dxfStartPath(rx, ry, "Start Arc"); Plotter.IsPathReduceOk = true; } else { dxfMoveTo(rx, ry, ""); } currAngle += StepAngle; if (currAngle > endAngle) { double angle2 = endAngle * Math.PI / 180; double rx2 = (double)(X + R * Math.Cos(angle2)); double ry2 = (double)(Y + R * Math.Sin(angle2)); if (index == 0) { dxfStartPath(rx2, ry2, "Start Arc"); } else { dxfMoveTo(rx2, ry2, ""); } } index++; } dxfStopPath(); } } #endregion #region DXFMText else if (entity.GetType() == typeof(DXFMText)) { // https://www.autodesk.com/techpubs/autocad/acad2000/dxf/mtext_dxf_06.htm DXFMText txt = (DXFMText)entity; xyPoint origin = new xyPoint(0, 0); GCodeFromFont.reset(); foreach (var entry in txt.Entries) { if (entry.GroupCode == 1) { GCodeFromFont.gcText = entry.Value.ToString(); } else if (entry.GroupCode == 40) { GCodeFromFont.gcHeight = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 41) { GCodeFromFont.gcWidth = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 71) { GCodeFromFont.gcAttachPoint = Convert.ToInt16(entry.Value); } else if (entry.GroupCode == 10) { GCodeFromFont.gcOffX = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat) + offsetX; } else if (entry.GroupCode == 20) { GCodeFromFont.gcOffY = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat) + offsetY; } else if (entry.GroupCode == 50) { GCodeFromFont.gcAngle = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 44) { GCodeFromFont.gcSpacing = double.Parse(entry.Value, CultureInfo.InvariantCulture.NumberFormat); } else if (entry.GroupCode == 7) { GCodeFromFont.gcFontName = entry.Value.ToString(); } } string tmp = string.Format("Id=\"{0}\" Color=\"#{1}\" ToolNr=\"{2}\"", dxfColorID, dxfColorHex, toolToUse); Plotter.InsertText(tmp); Plotter.IsPathFigureEnd = true; } #endregion else { Plotter.Comment("Unknown: " + entity.GetType().ToString()); } }
public xyArcPoint(xyPoint tmp) { X = tmp.X; Y = tmp.Y; CX = 0; CY = 0; mode = 0; }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (logDetailed) { Logger.Trace("pictureBox1_MouseDown e.x:{0} y:{1} absPos-x:{2:0.00} y:{3:0.00}", e.X, e.Y, picAbsPos.X, picAbsPos.Y); } pictureBox1.Focus(); moveTranslationOld = new xyPoint(e.X, e.Y); allowZoom = false; if (e.Button == MouseButtons.Left) { if ((fCTBCode.LinesCount > 2) && !posIsMoving) { int line = 0; posMoveStart = picAbsPos; posMoveTmp = posMoveStart; posMoveEnd = posMoveStart; int fold = foldLevel; if (!expandGCode) { fold = 0; } if (manualEdit) { newCodeEnd(); } if (Panel.ModifierKeys == Keys.Alt) { line = VisuGCode.setPosMarkerNearBy(picAbsPos, false); // find line with coord nearby, mark / unmark figure fCTBCodeClickedLineNow = line; findFigureMarkSelection(xmlMarkerType.Line, line, (fold > 0)); // collapse=true } else if (Panel.ModifierKeys == Keys.Control) { line = VisuGCode.setPosMarkerNearBy(picAbsPos, false); // find line with coord nearby, mark / unmark figure fCTBCodeClickedLineNow = line; findFigureMarkSelection(xmlMarkerType.Group, line, (fold > 0)); } else if (Panel.ModifierKeys == Keys.Shift) { line = VisuGCode.setPosMarkerNearBy(picAbsPos, false); // find line with coord nearby, mark / unmark figure fCTBCodeClickedLineNow = line; findFigureMarkSelection(xmlMarkerType.Tile, line, (fold > 0)); } else { line = VisuGCode.setPosMarkerNearBy(picAbsPos); // find line with coord nearby, mark / unmark figure fCTBCodeClickedLineNow = line; findFigureMarkSelection(xmlMarkerType.Figure, line, (fold > 0)); } cmsPicBoxMoveToMarkedPosition.ToolTipText = "Work X: " + grbl.posMarker.X.ToString() + " Y: " + grbl.posMarker.Y.ToString(); enableBlockCommands(VisuGCode.getHighlightStatus() > 0); if (VisuGCode.codeBlocksAvailable()) { statusStripSet(1, Localization.getString("statusStripeClickKeys2"), Color.LightGreen); } posIsMoving = false; } } }