Beispiel #1
0
        // 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;
        {
            getSettings();
            gcode.setup();
            GCodeFromFont.reset();

            GCodeFromFont.gcText         = tBText.Text;
            GCodeFromFont.gcFont         = GCodeFromFont.getFontIndex(cBFont.SelectedIndex);
            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;

            //           MessageBox.Show(cBFont.Items[cBFont.SelectedIndex].ToString());
            gcodeString.Clear();
            GCodeFromFont.getCode(gcodeString);

            if (gcodeUseSpindle)
            {
                gcode.SpindleOff(gcodeString, "End");
            }
            gcodeString.Replace(',', '.');
            string header = gcode.GetHeader("Text import");
            string footer = gcode.GetFooter();

            textgcode = header + gcodeString.ToString() + footer;
        }
Beispiel #2
0
        public void createText()
        {
            Logger.Trace(" createText()	");
            saveSettings();
            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;

            Graphic.CleanUp();
            Graphic.Init(Graphic.SourceTypes.Text, "", null, null);
            Graphic.graphicInformation.OptionNodesOnly  = false;
            Graphic.graphicInformation.OptionSortCode   = false;
            Graphic.graphicInformation.OptionZFromWidth = false;

            if (Properties.Settings.Default.createTextLineBreakEnable)
            {
                GCodeFromFont.getCode((double)nUDLineBreak.Value);      // do automatic page break
            }
            else
            {
                GCodeFromFont.getCode();
            }
            Graphic.CreateGCode();      // result is saved as stringbuilder in Graphic.GCode;
        }
Beispiel #3
0
        }                                                                                    // add tool change commands (if enabled) and set XYFeed etc.

        /// <summary>
        /// Insert text with settings via GCodeFromFont.xxx
        /// </summary>
        public static void InsertText(string tmp)
        {
            int oldPathCount = PathCount;

            PathCount = GCodeFromFont.getCode(PathCount, tmp);
            if (PathCount == oldPathCount)
            {
                AddToHeader(string.Format("Text insertion failed '{0}' with font '{1}'", GCodeFromFont.gcText, GCodeFromFont.gcFontName));
            }
        }
Beispiel #4
0
        public void createText()
        {
            Logger.Trace(" createText()	");
            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;

            Graphic.Init(Graphic.SourceTypes.Text, "");
            Graphic.graphicInformation.OptionNodesOnly  = false;
            Graphic.graphicInformation.OptionSortCode   = false;
            Graphic.graphicInformation.OptionZFromWidth = false;

            GCodeFromFont.getCode();
            textgcode = Graphic.CreateGCode();
        }
Beispiel #5
0
        /// <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());
            }
        }