private static void HPGL_SP(string nr) // select Pen Nr { if (nr.Length > 0) { int pen = int.Parse(nr); Plotter.PathColor = pen.ToString(); Plotter.SetGroup(pen); if (!groupObjects) { Plotter.ToolChange(pen, "Pen " + pen.ToString()); // add tool change commands (if enabled) and set XYFeed etc. } } else { Plotter.StopPath(""); } }
// draw a piece of the letter path: M x,y or L x,y private static void drawToken(StringBuilder gcodeString, string svgPath, double offX, double offY, float scale, int tnr, string comment) { var cmd = svgPath.Take(1).Single(); string remainingargs = svgPath.Substring(1); string argSeparators = @"[\s,]|(?=-)"; var splitArgs = Regex .Split(remainingargs, argSeparators) .Where(t => !string.IsNullOrEmpty(t)); double[] floatArgs = splitArgs.Select(arg => double.Parse(arg, NumberFormatInfo.InvariantInfo) * scale).ToArray(); if (tnr == 1) { if (pathCount > 0) { gcode.Comment(gcodeString, Plotter.SetFigureEnd(pathCount)); } gcode.Comment(gcodeString, string.Format("{0} {1} char='{2}'>", xmlMarker.figureStart, (++pathCount), comment)); } if (cmd == 'M') { if (gcConnectLetter && isSameWord && (tnr == 1)) { for (int i = 0; i < floatArgs.Length; i += 2) { gcodeMove(gcodeString, 1, (float)(offX + floatArgs[i]), (float)(offY - floatArgs[i + 1])); } } else { gcodePenUp(gcodeString); for (int i = 0; i < floatArgs.Length; i += 2) { gcodeMove(gcodeString, 0, (float)(offX + floatArgs[i]), (float)(offY - floatArgs[i + 1])); } gcodePenDown(gcodeString); } } if (cmd == 'L') { for (int i = 0; i < floatArgs.Length; i += 2) { gcodeMove(gcodeString, 1, (float)(offX + floatArgs[i]), (float)(offY - floatArgs[i + 1])); } } }
/// <summary> /// Convert DXF and create GCode /// </summary> private static string convertDXF(string txt) { Logger.Debug("convertDXF {0}", txt); dxfBezierAccuracy = (int)Properties.Settings.Default.importBezierLineSegmentsCnt; gcodeReduce = Properties.Settings.Default.importRemoveShortMovesEnable; gcodeReduceVal = (double)Properties.Settings.Default.importRemoveShortMovesLimit; dxfComments = Properties.Settings.Default.importSVGAddComments; dxfUseColorIndex = Properties.Settings.Default.importDXFToolIndex; // use DXF color index instead real color groupObjects = Properties.Settings.Default.importGroupObjects; // DXF-Import group objects nodesOnly = Properties.Settings.Default.importSVGNodesOnly; dxfColorID = 259; dxfColorIDold = dxfColorID; toolToUse = toolNr = 1; Plotter.StartCode(); // initalize variables GetVectorDXF(); // convert graphics Plotter.SortCode(); // sort objects return(Plotter.FinalGCode("DXF import", txt)); }
// get text, break it into chars, get path, etc... This event needs to be assigned in MainForm to poll text private void btnApply_Click(object sender, EventArgs e) // in MainForm: _text_form.btnApply.Click += getGCodeFromText; { GCodeFromFont.reset(); GCodeFromFont.gcText = tBText.Text; GCodeFromFont.gcFontName = cBFont.Items[cBFont.SelectedIndex].ToString(); GCodeFromFont.gcHeight = (double)nUDFontSize.Value; GCodeFromFont.gcFontDistance = (double)nUDFontDistance.Value; GCodeFromFont.gcLineDistance = (double)(nUDFontLine.Value / nUDFontSize.Value); GCodeFromFont.gcSpacing = (double)(nUDFontLine.Value / nUDFontSize.Value) / 1.5; GCodeFromFont.gcPauseChar = cBPauseChar.Checked; GCodeFromFont.gcPauseWord = cBPauseWord.Checked; GCodeFromFont.gcPauseLine = cBPauseLine.Checked; GCodeFromFont.gcConnectLetter = cBConnectLetter.Checked; bool groupObjects = Properties.Settings.Default.importGroupObjects; Plotter.StartCode(); // initalize variables Plotter.InsertText(""); Plotter.IsPathFigureEnd = true; Plotter.SortCode(); // sort objects textgcode = Plotter.FinalGCode("Text import", ""); Properties.Settings.Default.importGroupObjects = groupObjects; }
private static void dxfStopPath(string cmt = "") { Plotter.StopPath(cmt); }
/// <summary> /// Insert G0, Pen down gcode command /// </summary> private static void dxfStartPath(double x, double y, string cmt = "") { Plotter.StartPath(translateXY((float)x, (float)y), cmt); }
/// <summary> /// Calculate round corner of DXFLWPolyLine if Bulge is given /// </summary> /// <param name="var1">First vertex coord</param> /// <param name="var2">Second vertex</param> /// <returns></returns> private static void AddRoundCorner(DXFLWPolyLine.Element var1, DXFLWPolyLine.Element var2) { double bulge = var1.Bulge; double p1x = (double)var1.Vertex.X; double p1y = (double)var1.Vertex.Y; double p2x = (double)var2.Vertex.X; double p2y = (double)var2.Vertex.Y; //Definition of bulge, from Autodesk DXF fileformat specs double angle = Math.Abs(Math.Atan(bulge) * 4); bool girou = false; //For my method, this angle should always be less than 180. if (angle > Math.PI) { angle = Math.PI * 2 - angle; girou = true; } //Distance between the two vertexes, the angle between Center-P1 and P1-P2 and the arc radius double distance = Math.Sqrt(Math.Pow(p1x - p2x, 2) + Math.Pow(p1y - p2y, 2)); double alpha = (Math.PI - angle) / 2; double ratio = distance * Math.Sin(alpha) / Math.Sin(angle); if (angle == Math.PI) { ratio = distance / 2; } double xc, yc, direction; //Used to invert the signal of the calculations below if (bulge < 0) { direction = 1; } else { direction = -1; } //calculate the arc center double part = Math.Sqrt(Math.Pow(2 * ratio / distance, 2) - 1); if (!girou) { xc = ((p1x + p2x) / 2) - direction * ((p1y - p2y) / 2) * part; yc = ((p1y + p2y) / 2) + direction * ((p1x - p2x) / 2) * part; } else { xc = ((p1x + p2x) / 2) + direction * ((p1y - p2y) / 2) * part; yc = ((p1y + p2y) / 2) - direction * ((p1x - p2x) / 2) * part; } string cmt = ""; if (dxfComments) { cmt = "Bulge " + bulge.ToString(); } if (bulge > 0) { Plotter.Arc(3, (float)p2x, (float)p2y, (float)(xc - p1x), (float)(yc - p1y), cmt); } else { Plotter.Arc(2, (float)p2x, (float)p2y, (float)(xc - p1x), (float)(yc - p1y), cmt); } }
/// <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()); } }
private static void gcodeMove(int gnr, float x, float y, string cmd = "") { Plotter.MoveToSimple(new xyPoint(x, y), cmd, (gnr == 0)); }
private void btnApply_Click(object sender, EventArgs e) { saveSettings(); gcode.setup(false); // load defaults from setup-tab gcode.gcodeXYFeed = (float)nUDToolFeedXY.Value; // override devault values gcode.gcodeZFeed = (float)nUDToolFeedZ.Value; // override devault values gcode.gcodeSpindleSpeed = (float)nUDToolSpindleSpeed.Value; // override devault values gcode.gcodeZDown = (float)nUDImportGCZDown.Value; Logger.Debug("Create GCode {0}", gcode.getSettings()); gcodeString.Clear(); gcode.Tool(gcodeString, tprop.toolnr, tprop.name); // if (!Properties.Settings.Default.importGCSpindleToggle) gcode.SpindleOn(gcodeString, "Start"); float x, y, rShape, d, dTool, overlap, rTool, zStep; float zStart = 0; x = (float)nUDShapeX.Value; y = (float)nUDShapeY.Value; rShape = (float)nUDShapeR.Value; d = 2 * rShape; dTool = (float)nUDToolDiameter.Value; // tool diameter; overlap = dTool * (float)nUDToolOverlap.Value / 100; // tool overlap if (rBToolpath1.Checked) { dTool = 0; } // engrave if (rBToolpath3.Checked) { dTool = -dTool; } // outside rTool = dTool / 2; // tool radius int counter = 0, safety = 100; int zStepCount = 0; float dx = 0, dy = 0, rDelta = 0; int passCount = 0; int figureCount = 1; gcode.jobStart(gcodeString, "StartJob"); // gcode.PenUp(gcodeString); bool inOneStep = (nUDToolZStep.Value >= -nUDImportGCZDown.Value); gcode.Comment(gcodeString, xmlMarker.figureStart + " " + figureCount.ToString() + " >"); if (rBShape1.Checked) // rectangle { getOffset(x, y); offsetX -= rTool; offsetY -= rTool; x += dTool; y += dTool; // width +/- tool diameter (outline / inline) zStep = zStart; while (zStep > (float)nUDImportGCZDown.Value) // nUDImportGCZDown.Value e.g. -2 { zStep -= (float)nUDToolZStep.Value; // nUDToolZStep.Value e.g. 0.5 if (zStep < (float)nUDImportGCZDown.Value) { zStep = (float)nUDImportGCZDown.Value; } if ((overlap > x / 2) || (overlap > y / 2)) { overlap = (float)(Math.Min(x, y) / 2.1); } //if ((zStepCount++ == 0) || !cBNoZUp.Checked) // move up the 1st time if (!(zStepCount++ == 0) && !cBNoZUp.Checked) // move up the 1st time { gcode.PenUp(gcodeString); if (!inOneStep) { gcode.Comment(gcodeString, xmlMarker.passEnd + " " + passCount.ToString() + ">"); } } passCount++; if (!inOneStep) { gcode.Comment(gcodeString, string.Format("{0} {1} step='{2:0.000}' final='{3:0.000}'>", xmlMarker.passStart, passCount, zStep, nUDImportGCZDown.Value)); } if (cBToolpathPocket.Checked) { gcode.MoveToRapid(gcodeString, offsetX + overlap, offsetY + overlap, ""); } else { gcode.MoveToRapid(gcodeString, offsetX, offsetY, ""); } gcode.gcodeZDown = zStep; // adapt Z-deepth gcode.PenDown(gcodeString); if (cBToolpathPocket.Checked) // 1st pocket { if ((x > Math.Abs(dTool)) && (y > Math.Abs(dTool))) // wide enough for pocket { dx = overlap; dy = overlap; while (((dx < x / 2) && (dy < y / 2)) && (counter++ < safety)) { makeRect(offsetX + dx, offsetY + dy, offsetX + x - dx, offsetY + y - dy, 0, false); // rectangle clockwise dx += overlap; dy += overlap; if ((dx < x / 2) && (dy < y / 2)) { gcode.MoveTo(gcodeString, offsetX + dx, offsetY + dy, "Pocket"); } } if (cBNoZUp.Checked) { gcode.MoveTo(gcodeString, offsetX, offsetY, "Pocket finish"); } else { gcode.PenUp(gcodeString, "Pocket finish"); gcode.MoveToRapid(gcodeString, offsetX, offsetY, "Pocket finish"); gcode.PenDown(gcodeString); } } } makeRect(offsetX, offsetY, offsetX + x, offsetY + y, 0, true); // final rectangle clockwise } gcode.PenUp(gcodeString); if (!inOneStep) { gcode.Comment(gcodeString, xmlMarker.passEnd + " " + passCount.ToString() + ">"); } } else if (rBShape2.Checked) // rectangle with round edge { getOffset(x, y); offsetX -= rTool; offsetY -= rTool; x += dTool; y += dTool; if ((overlap > x / 2) || (overlap > y / 2)) { overlap = (float)(Math.Min(x, y) / 2.1); } // gcode.Move(gcodeString, 0, offsetX, offsetY + r, false, ""); zStep = zStart; while (zStep > (float)nUDImportGCZDown.Value) { zStep -= (float)nUDToolZStep.Value; if (zStep < (float)nUDImportGCZDown.Value) { zStep = (float)nUDImportGCZDown.Value; } // if ((zStepCount++ == 0) || !cBNoZUp.Checked) // move up the 1st time if (!(zStepCount++ == 0) && !cBNoZUp.Checked) // move up the 1st time { gcode.PenUp(gcodeString); if (!inOneStep) { gcode.Comment(gcodeString, xmlMarker.passEnd + " " + passCount.ToString() + ">"); } } passCount++; if (!inOneStep) { gcode.Comment(gcodeString, string.Format("{0} {1} step='{2:0.000}' final='{3:0.000}'>", xmlMarker.passStart, passCount, zStep, nUDImportGCZDown.Value)); } if (cBToolpathPocket.Checked) { gcode.MoveToRapid(gcodeString, offsetX + overlap, offsetY + rShape, ""); } else { gcode.MoveToRapid(gcodeString, offsetX, offsetY + rShape, ""); } gcode.gcodeZDown = zStep; // adapt Z-deepth gcode.PenDown(gcodeString); if (cBToolpathPocket.Checked) { dx = overlap; dy = overlap; rDelta = rShape - overlap; while (((dx < x / 2) && (dy < y / 2)) && (counter++ < safety)) { makeRect(offsetX + dx, offsetY + dy, offsetX + x - dx, offsetY + y - dy, rDelta, false); // rectangle clockwise dx += overlap; dy += overlap; rDelta -= overlap; if (dx > x / 2) { dx = x / 2; } if (dy > x / 2) { dy = y / 2; } if (rDelta < 0) { rDelta = 0; } if ((dx < x / 2) && (dy < y / 2)) { gcode.MoveTo(gcodeString, offsetX + dx, offsetY + dy + rDelta, ""); } } if (cBNoZUp.Checked) { gcode.MoveTo(gcodeString, offsetX, offsetY + rShape, ""); } else { gcode.PenUp(gcodeString); gcode.MoveToRapid(gcodeString, offsetX, offsetY + rShape, ""); gcode.PenDown(gcodeString); } } makeRect(offsetX, offsetY, offsetX + x, offsetY + y, rShape, true); // rectangle clockwise } gcode.PenUp(gcodeString); if (!inOneStep) { gcode.Comment(gcodeString, xmlMarker.passEnd + " " + passCount.ToString() + ">"); } } else if (rBShape3.Checked) // circle { getOffset(d, d); offsetX -= rTool; offsetY -= rTool; rShape += rTool; // take care of tool diameter if set if (overlap > rShape) { overlap = (float)(rShape / 2.1); } zStep = zStart; while (zStep > (float)nUDImportGCZDown.Value) { //if ((zStepCount++ == 0) || !cBNoZUp.Checked) // move up the 1st time if (!(zStepCount++ == 0) && !cBNoZUp.Checked) // move up the 1st time { gcode.PenUp(gcodeString); if (!inOneStep) { gcode.Comment(gcodeString, xmlMarker.passEnd + " " + passCount.ToString() + ">"); } } passCount++; if (!inOneStep) { gcode.Comment(gcodeString, string.Format("{0} {1} step='{2:0.000}' final='{3:0.000}'>", xmlMarker.passStart, passCount, zStep, nUDImportGCZDown.Value)); } if (cBToolpathPocket.Checked) { gcode.MoveToRapid(gcodeString, offsetX + rShape - overlap, offsetY + rShape, ""); } else { gcode.MoveToRapid(gcodeString, offsetX, offsetY + rShape, ""); } zStep -= (float)nUDToolZStep.Value; if (zStep < (float)nUDImportGCZDown.Value) { zStep = (float)nUDImportGCZDown.Value; } gcode.gcodeZDown = zStep; // adapt Z-deepth gcode.PenDown(gcodeString); rDelta = overlap; counter = 0; if ((cBToolpathPocket.Checked) && (rShape > 2 * rTool)) { while ((rDelta < rShape) && (counter++ < safety)) { gcode.Arc(gcodeString, 2, offsetX + rShape - rDelta, offsetY + rShape, rDelta, 0, ""); rDelta += overlap; if (rDelta < rShape) { gcode.MoveTo(gcodeString, offsetX + rShape - rDelta, offsetY + rShape, ""); } } gcode.MoveTo(gcodeString, offsetX, offsetY + rShape, ""); } gcode.Arc(gcodeString, 2, offsetX, offsetY + rShape, rShape, 0, ""); } gcode.PenUp(gcodeString); if (!inOneStep) { gcode.Comment(gcodeString, xmlMarker.passEnd + " " + passCount.ToString() + ">"); } } gcode.Comment(gcodeString, Plotter.SetFigureEnd(figureCount)); gcode.jobEnd(gcodeString, "EndJob"); // Spindle / laser off // if (Properties.Settings.Default.importGCZEnable) // gcode.SpindleOff(gcodeString, "Finish - Spindle off"); string header = gcode.GetHeader("Simple Shape"); string footer = gcode.GetFooter(); gcodeString.Replace(',', '.'); shapegcode = header + gcodeString.ToString() + footer; }
private static void gcodePause(string cmt) { Plotter.InsertPause(cmt); }
private static void gcodeComment(string cmt) { Plotter.Comment(cmt); }
private static void gcodePenUp(string cmt) { Plotter.PenUp(cmt); }
private static void gcodePenDown(string cmt) { Plotter.PenDown(cmt); }
public static int getCode(StringBuilder gcodeString, int startCount, string cmt) { pathCount = startCount; Logger.Trace("Create GCode, text length {0}, font {1}", gcText.Length, gcFontName); double scale = gcHeight / 21; string tmp1 = gcText.Replace('\r', '|'); gcodeString.AppendFormat("( Text: {0} )\r\n", tmp1.Replace('\n', ' ')); string[] fileContent = new string[] { "" }; string fileName = ""; if (gcFontName.IndexOf(@"fonts\") >= 0) { fileName = gcFontName; } else { fileName = datapath.fonts + "\\" + gcFontName + ".lff"; } if (gcFontName != "") { if (File.Exists(fileName)) { fileContent = File.ReadAllLines(fileName); scale = gcHeight / 9; useLFF = true; offsetY = 0; gcLineDistance = 1.667 * gcSpacing; foreach (string line in fileContent) { if (line.IndexOf("LetterSpacing") >= 0) { string[] tmp = line.Split(':'); gcLetterSpacing = double.Parse(tmp[1].Trim(), CultureInfo.InvariantCulture.NumberFormat);//Convert.ToDouble(tmp[1].Trim()); } if (line.IndexOf("WordSpacing") >= 0) { string[] tmp = line.Split(':'); gcWordSpacing = double.Parse(tmp[1].Trim(), CultureInfo.InvariantCulture.NumberFormat);//Convert.ToDouble(tmp[1].Trim()); } } } else { gcodeString.AppendFormat("( Font '{0}' not found )\r\n", gcFontName); if (!hersheyFonts.ContainsKey(gcFontName)) { Logger.Error("Font '{0}' or file '{1}' not found", gcFontName, fileName); return(startCount); } } } bool centerLine = false; bool rightLine = false; if ((gcAttachPoint == 2) || (gcAttachPoint == 5) || (gcAttachPoint == 8)) { gcOffX -= gcWidth / 2; centerLine = true; } if ((gcAttachPoint == 3) || (gcAttachPoint == 6) || (gcAttachPoint == 9)) { gcOffX -= gcWidth; rightLine = true; } if ((gcAttachPoint == 4) || (gcAttachPoint == 5) || (gcAttachPoint == 6)) { gcOffY -= gcHeight / 2; } if ((gcAttachPoint == 1) || (gcAttachPoint == 2) || (gcAttachPoint == 3)) { gcOffY -= gcHeight; } string[] lines; if (gcText.IndexOf("\\P") >= 0) { gcText = gcText.Replace("\\P", "\n"); } lines = gcText.Split('\n'); int maxCharCount = 0; foreach (string tmp in lines) { maxCharCount = Math.Max(maxCharCount, tmp.Length); } double charWidth = gcWidth / maxCharCount; offsetX = 0; offsetY = 9 * scale + ((double)lines.Length - 1) * gcHeight * gcLineDistance;// (double)nUDFontLine.Value; if (useLFF) { offsetY = ((double)lines.Length - 1) * gcHeight * gcLineDistance;// (double)nUDFontLine.Value; } isSameWord = false; for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++) { if (lineIndex > 0) { offsetY -= gcHeight * gcLineDistance; if (gcPauseLine) { gcode.Pause(gcodeString, "Pause before line"); } } string actualLine = lines[lineIndex]; for (int txtIndex = 0; txtIndex < actualLine.Length; txtIndex++) { char actualChar = actualLine[txtIndex]; int chrIndex = (int)actualChar - 32; int chrIndexLFF = (int)actualChar; if (txtIndex == 0) //actualChar == '\n') // next line { offsetX = 0; if (centerLine) { offsetX = (gcWidth - (charWidth * actualLine.Length)) / 2; // center line } else if (rightLine) { offsetX = (gcWidth - (charWidth * actualLine.Length)); } isSameWord = false; } if (useLFF) // LFF Font (LibreCAD font file format) { if (chrIndexLFF > 32) { gcode.Comment(gcodeString, string.Format("{0} {1} Char=\"{2}\" {3}>", xmlMarker.figureStart, (++pathCount), actualChar, cmt)); } drawLetterLFF(gcodeString, ref fileContent, chrIndexLFF, scale);//, string.Format("Char: {0}", gcText[txtIndex])); // regular char gcodePenUp(gcodeString); if (chrIndexLFF > 32) { gcode.Comment(gcodeString, Plotter.SetFigureEnd(pathCount)); } } else { if ((chrIndex < 0) || (chrIndex > 95)) // no valid char { offsetX += 2 * gcSpacing; // apply space isSameWord = false; if (gcPauseWord) { gcode.Pause(gcodeString, "Pause before word"); } } else { //gcodeString.AppendFormat("( Char: {0})\r\n", gcText[txtIndex]); if (gcPauseChar) { gcode.Pause(gcodeString, "Pause before char"); } if (gcPauseChar && (actualChar == ' ')) { gcode.Pause(gcodeString, "Pause before word"); } drawLetter(gcodeString, hersheyFonts[gcFontName][chrIndex], scale, actualChar.ToString() + cmt); // regular char } } } } if (!useLFF) { gcode.PenUp(gcodeString); gcode.Comment(gcodeString, Plotter.SetFigureEnd(pathCount)); } // startCount = pathCount; return(pathCount); }
private static void GetVectorHPGL(string htmlCode) { string[] commands = htmlCode.Split(';'); char[] charsToTrim = { ' ', '\r', '\n' }; string line, cmd, parameter; foreach (string cmdline in commands) { line = cmdline.Trim(charsToTrim); if (line.Length >= 2) { cmd = line.Substring(0, 2).ToUpper(); parameter = line.Substring(2); // Logger.Trace("=> {0} ", line); if (cmd == "IN") { HPGL_IN(); if (parameter.Length >= 2) { cmd = parameter.Substring(0, 2).ToUpper(); parameter = cmd.Substring(2); } else { continue; } } if (cmd == "SP") { HPGL_SP(parameter); } else if (cmd == "PU") { HPGL_PU(parameter); } else if (cmd == "PD") { HPGL_PD(parameter); } else if (cmd == "PA") { HPGL_PA(parameter); } else if (cmd == "PR") { HPGL_PR(parameter); } else if (cmd == "FS") { HPGL_FS(cmd, parameter); } else if (cmd == "VS") { HPGL_VS(cmd, parameter); } else if (cmd == "WU") { HPGL_WU(cmd, parameter); } else if (cmd == "PW") { HPGL_PW(cmd, parameter); } else { if (!messageList.Contains(cmd)) { Logger.Warn(" UNKOWN command {0} ", cmd); Plotter.AddToHeader(string.Format("Unknown command: {0}", cmd)); messageList.Add(cmd); } } } } }
private static void GetVectorDXF() { Plotter.PenUp("DXF Start"); layerColor.Clear(); layerLType.Clear(); lineTypes.Clear(); List <DXFLayerRecord> tst = doc.Tables.Layers; foreach (DXFLayerRecord rec in tst) { Plotter.AddToHeader(string.Format("Layer: {0} , color: {1} , line type: {2}", rec.LayerName, rec.Color, rec.LineType)); layerColor.Add(rec.LayerName, rec.Color); layerLType.Add(rec.LayerName, rec.LineType); } List <DXFLineTypeRecord> ltypes = doc.Tables.LineTypes; foreach (DXFLineTypeRecord lt in ltypes) { // Plotter.AddToHeader(string.Format("Description: {0} , Name: {1} , length: {2}", lt.Description, lt.LineTypeName, lt.PatternLength)); string pattern = ""; if ((lt.PatternLength > 0) && (lt.ElementCount > 0)) { double[] tmp = new double[lt.ElementCount]; for (int i = 0; i < lt.ElementCount; i++) { if (lt.Elements[i].Length == 0) { tmp[i] = 0.5; } else { tmp[i] = Math.Abs(lt.Elements[i].Length); } pattern += string.Format(" {0} ", lt.Elements[i].Length); } lineTypes.Add(lt.LineTypeName, tmp); // Plotter.AddToHeader(string.Format("Name: {0} , length: {1}", lt.LineTypeName, pattern)); } } foreach (DXFEntity dxfEntity in doc.Entities) { if (dxfEntity.GetType() == typeof(DXFInsert)) { DXFInsert ins = (DXFInsert)dxfEntity; double ins_x = (double)ins.InsertionPoint.X; double ins_y = (double)ins.InsertionPoint.Y; foreach (DXFBlock block in doc.Blocks) { if (block.BlockName.ToString() == ins.BlockName) { Logger.Trace("Block: {0}", block.BlockName); dxfColorID = block.ColorNumber; Plotter.PathName = "Block:" + block.BlockName; Plotter.AddToHeader("Block: " + block.BlockName); foreach (DXFEntity blockEntity in block.Children) { processEntities(blockEntity, ins_x, ins_y, false); } } } } else { processEntities(dxfEntity); } } Plotter.PenUp(""); }
private static void HPGL_PU(string coord) // Pen up { Plotter.PenUp(); penDown = false; startPathPos = moveTo(coord); // get last Pen up position }
/// <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()); } }