Example #1
0
        private static void AddPolyBez(ArrayList obj)
        {
            MetaForm.Data.Clear();
            MetaForm.Data.count = obj.Count;
            Color color = Color.FromArgb(MetaForm.r, MetaForm.g, MetaForm.b);

            MetaForm.Data.color  = DXFExport.ColorToDXF(color);
            MetaForm.Data.points = new ArrayList();
            MetaForm.Data.points.Add(new ArrayList());
            for (int i = 0; i < obj.Count; i++)
            {
                DXFPoint dXFPoint = new DXFPoint();
                PointF   item     = (PointF)obj[i];
                dXFPoint.X = item.X;
                item       = (PointF)obj[i];
                dXFPoint.Y = -item.Y + (float)MetaForm.imgHeight;
                dXFPoint.Z = 0f;
                if (MetaForm.transform)
                {
                    DXFPoint x = dXFPoint;
                    x.X = x.X + MetaForm.transPoint.X;
                    DXFPoint y = dXFPoint;
                    y.Y = y.Y + MetaForm.transPoint.Y;
                }
                ((ArrayList)MetaForm.Data.points[0]).Add(dXFPoint);
            }
            MetaForm.vDXF.AddPolyBezier(MetaForm.Data, 0);
        }
Example #2
0
        private static void DrawRectangle(byte[] arr, byte cn, bool hatch)
        {
            float x       = MetaForm.Format_Size2(arr[cn], arr[cn + 1]);
            float y       = MetaForm.Format_Size2(arr[cn + 2], arr[cn + 3]);
            float single  = MetaForm.Format_Size2(arr[cn + 4], arr[cn + 5]);
            float single1 = MetaForm.Format_Size2(arr[cn + 6], arr[cn + 7]);

            if (MetaForm.transform)
            {
                x = x + MetaForm.transPoint.X;
                y = y + MetaForm.transPoint.Y;
            }
            MetaForm.Data.Clear();
            MetaForm.Data.color = DXFExport.ColorToDXF(Color.FromArgb(MetaForm.r, MetaForm.g, MetaForm.b));
            MetaForm.SetLineStyle((int)MetaForm.line_style);
            MetaForm.Data.thickness = MetaForm.obj_width;
            MetaForm.Data.point.X   = x;
            MetaForm.Data.point.Y   = -y + (float)MetaForm.imgHeight;
            MetaForm.Data.point1.X  = single + x;
            MetaForm.Data.point1.Y  = -single1 - y + (float)MetaForm.imgHeight;
            if (!hatch)
            {
                MetaForm.vDXF.AddRectangle(MetaForm.Data);
                return;
            }
            MetaForm.Data.count = 1;
            MetaForm.Data.points.Add(new ArrayList());
            DXFPoint dXFPoint = new DXFPoint()
            {
                X = MetaForm.Data.point.X,
                Y = MetaForm.Data.point.Y,
                Z = 0f
            };

            ((ArrayList)MetaForm.Data.points[0]).Add(dXFPoint);
            dXFPoint = new DXFPoint()
            {
                X = MetaForm.Data.point1.X,
                Y = MetaForm.Data.point.Y,
                Z = 0f
            };
            ((ArrayList)MetaForm.Data.points[0]).Add(dXFPoint);
            dXFPoint = new DXFPoint()
            {
                X = MetaForm.Data.point1.X,
                Y = MetaForm.Data.point1.Y,
                Z = 0f
            };
            ((ArrayList)MetaForm.Data.points[0]).Add(dXFPoint);
            dXFPoint = new DXFPoint()
            {
                X = MetaForm.Data.point.X,
                Y = MetaForm.Data.point1.Y,
                Z = 0f
            };
            ((ArrayList)MetaForm.Data.points[0]).Add(dXFPoint);
            MetaForm.SetHatchStyle(MetaForm.hatch_style);
            MetaForm.Data.selfType = 0;
            MetaForm.vDXF.AddHatch(MetaForm.Data);
        }
Example #3
0
        private void method_0(IPointCollection ipointCollection_0, DXFExport dxfexport_0)
        {
            DXFData  dXFDatum = new DXFData();
            DXFPoint dXFPoint = new DXFPoint();

            dXFDatum.points.Add(new ArrayList());
            dXFDatum.count = ipointCollection_0.PointCount;
            for (int i = 0; i < ipointCollection_0.PointCount; i++)
            {
                IPoint point = ipointCollection_0.Point[i];
                ((ArrayList)dXFDatum.points[0]).Add(new DXFPoint((float)point.X, (float)point.Y, 0f));
            }
            dxfexport_0.AddPolyLine(dXFDatum, 0);
        }
Example #4
0
        private static void DrawCircle(byte[] arr, byte cn, bool hatch)
        {
            float x       = MetaForm.Format_Size2(arr[cn], arr[cn + 1]);
            float y       = MetaForm.Format_Size2(arr[cn + 2], arr[cn + 3]);
            float single  = MetaForm.Format_Size2(arr[cn + 4], arr[cn + 5]);
            float single1 = MetaForm.Format_Size2(arr[cn + 6], arr[cn + 7]);

            if (MetaForm.transform)
            {
                x = x + MetaForm.transPoint.X;
                y = y + MetaForm.transPoint.Y;
            }
            MetaForm.Data.Clear();
            MetaForm.Data.color     = DXFExport.ColorToDXF(Color.FromArgb(MetaForm.r, MetaForm.g, MetaForm.b));
            MetaForm.Data.thickness = MetaForm.obj_width;
            MetaForm.Data.point.X   = x;
            MetaForm.Data.point.Y   = -y + (float)MetaForm.imgHeight;
            MetaForm.Data.point1.X  = single + x;
            MetaForm.Data.point1.Y  = -single1 - y + (float)MetaForm.imgHeight;
            MetaForm.Data.radius    = (MetaForm.Data.point1.X - MetaForm.Data.point.X) / 2f;
            DXFPoint data = MetaForm.Data.point;

            data.Y = data.Y - MetaForm.Data.radius;
            DXFPoint dXFPoint = MetaForm.Data.point1;

            dXFPoint.Y = dXFPoint.Y - MetaForm.Data.radius;
            DXFPoint data1 = MetaForm.Data.point;

            data1.X = data1.X + MetaForm.Data.radius;
            DXFPoint x1 = MetaForm.Data.point1;

            x1.X = x1.X + MetaForm.Data.radius;
            MetaForm.SetLineStyle((int)MetaForm.line_style);
            if (!hatch)
            {
                MetaForm.vDXF.AddCircle(MetaForm.Data);
                return;
            }
            MetaForm.Data.startAngle = 0f;
            MetaForm.Data.endAngle   = 360f;
            MetaForm.SetHatchStyle(MetaForm.hatch_style);
            MetaForm.Data.selfType = 1;
            MetaForm.vDXF.AddHatch(MetaForm.Data);
        }
Example #5
0
        private static void DrawArc(byte[] arr)
        {
            float single  = MetaForm.FormatSize((int)arr[2], (int)arr[3]);
            float single1 = MetaForm.FormatSize((int)arr[6], (int)arr[7]);
            float x       = MetaForm.Format_Size2(arr[8], arr[9]);
            float y       = MetaForm.Format_Size2(arr[10], arr[11]);
            float single2 = MetaForm.Format_Size2(arr[12], arr[13]);
            float single3 = MetaForm.Format_Size2(arr[14], arr[15]);

            if (MetaForm.transform)
            {
                x = x + MetaForm.transPoint.X;
                y = y + MetaForm.transPoint.Y;
            }
            MetaForm.Data.Clear();
            MetaForm.SetLineStyle((int)MetaForm.line_style);
            MetaForm.Data.thickness = MetaForm.obj_width;
            MetaForm.Data.color     = DXFExport.ColorToDXF(Color.FromArgb(MetaForm.r, MetaForm.g, MetaForm.b));
            MetaForm.Data.point.X   = x;
            MetaForm.Data.point.Y   = -y + (float)MetaForm.imgHeight;
            MetaForm.Data.point1.X  = single2 + x;
            MetaForm.Data.point1.Y  = -single3 - y + (float)MetaForm.imgHeight;
            MetaForm.Data.radius    = (MetaForm.Data.point1.X - MetaForm.Data.point.X) / 2f;
            DXFPoint data = MetaForm.Data.point;

            data.Y = data.Y - MetaForm.Data.radius;
            DXFPoint dXFPoint = MetaForm.Data.point1;

            dXFPoint.Y = dXFPoint.Y - MetaForm.Data.radius;
            DXFPoint data1 = MetaForm.Data.point;

            data1.X = data1.X + MetaForm.Data.radius;
            DXFPoint x1 = MetaForm.Data.point1;

            x1.X = x1.X + MetaForm.Data.radius;
            MetaForm.Data.startAngle = -single1 - single;
            MetaForm.Data.endAngle   = -single;
            MetaForm.Data.selfType   = 0;
            MetaForm.vDXF.AddArc(MetaForm.Data);
        }
        private void saveFootprint(List <AbmachPoint> ptlist, int runNumber)
        {
            var entityList = new List <DwgEntity>();

            foreach (AbmachPoint v in ptlist)
            {
                DXFPoint pt = new DXFPoint(v.Position);
                if (v.JetHit)
                {
                    pt.DxfColor = DxfColor.Cyan;
                    entityList.Add(pt);
                }
                else
                {
                    pt.DxfColor = DxfColor.Grey;
                    entityList.Add(pt);
                }
            }
            string fileName = "footprintRun." + runNumber.ToString() + ".dxf";

            DxfFileBuilder.Save(entityList, fileName);
        }
Example #7
0
        void save3DSurface(string dxfFilename, string txtFileName)
        {
            try
            {
                ISurface <AbmachPoint> surfOut = model3D.GetSurface();

                List <AbmachPoint> ptlist     = surfOut.GetAllPoints();
                List <DwgEntity>   entityList = new List <DwgEntity>();
                var pointList = new List <string>();
                foreach (AbmachPoint v in ptlist)
                {
                    pointList.Add(v.Position.X.ToString("f4") + " " + v.Position.Y.ToString("f4") + " " + v.Position.Z.ToString("f4"));
                    DXFPoint pt = new DXFPoint(v.Position);
                    if (v.JetHit)
                    {
                        if (v.Normal.Length != 0.0)
                        {
                            double  scaleF = meshSize / v.Normal.Length;
                            DXFLine line   = new DXFLine(v.Position.X, v.Position.Y, v.Position.Z, scaleF * v.Normal.X + v.Position.X, scaleF * v.Normal.Y + v.Position.Y, scaleF * v.Normal.Z + v.Position.Z);
                            entityList.Add(line);
                        }
                        pt.DxfColor = DxfColor.Green;
                        entityList.Add(pt);
                    }
                    else
                    {
                        pt.DxfColor = DxfColor.Red;
                        entityList.Add(pt);
                    }
                }
                FileIO.Save(pointList, txtFileName);
                DxfFileBuilder.Save(entityList, dxfFilename);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #8
0
        private static void DrawLine(PointF p1, PointF p2)
        {
            MetaForm.Data.Clear();
            Color color = Color.FromArgb(MetaForm.r, MetaForm.g, MetaForm.b);

            MetaForm.Data.color    = DXFExport.ColorToDXF(color);
            MetaForm.Data.point1.X = p1.X;
            MetaForm.Data.point1.Y = -p1.Y + (float)MetaForm.imgHeight;
            MetaForm.Data.point.X  = p2.X;
            MetaForm.Data.point.Y  = -p2.Y + (float)MetaForm.imgHeight;
            if (MetaForm.transform)
            {
                DXFPoint data = MetaForm.Data.point1;
                data.X = data.X + MetaForm.transPoint.X;
                DXFPoint y = MetaForm.Data.point1;
                y.Y = y.Y + MetaForm.transPoint.Y;
                DXFPoint x = MetaForm.Data.point;
                x.X = x.X + MetaForm.transPoint.X;
                DXFPoint dXFPoint = MetaForm.Data.point;
                dXFPoint.Y = dXFPoint.Y + MetaForm.transPoint.Y;
            }
            MetaForm.vDXF.AddLine(MetaForm.Data);
        }
Example #9
0
 private static Point toPoint(DXFPoint tmp, Point Off)
 {
     return(new Point((double)tmp.X + Off.X, (double)tmp.Y + Off.Y));
 }
Example #10
0
        /// <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());
            }
        }
Example #11
0
        private static void DrawEllipse(byte[] arr, byte cn, bool hatch)
        {
            float x       = MetaForm.Format_Size2(arr[cn], arr[cn + 1]);
            float y       = MetaForm.Format_Size2(arr[cn + 2], arr[cn + 3]);
            float single  = MetaForm.Format_Size2(arr[cn + 4], arr[cn + 5]);
            float single1 = MetaForm.Format_Size2(arr[cn + 6], arr[cn + 7]);

            if (MetaForm.transform)
            {
                x = x + MetaForm.transPoint.X;
                y = y + MetaForm.transPoint.Y;
            }
            MetaForm.Data.Clear();
            MetaForm.SetLineStyle((int)MetaForm.line_style);
            MetaForm.Data.color     = DXFExport.ColorToDXF(Color.FromArgb(MetaForm.r, MetaForm.g, MetaForm.b));
            MetaForm.Data.thickness = MetaForm.obj_width;
            MetaForm.Data.point.X   = x;
            MetaForm.Data.point.Y   = -y + (float)MetaForm.imgHeight;
            MetaForm.Data.point1.X  = single + x;
            MetaForm.Data.point1.Y  = -single1 - y + (float)MetaForm.imgHeight;
            MetaForm.Data.radius    = (MetaForm.Data.point1.X - MetaForm.Data.point.X) / 2f;
            DXFPoint data = MetaForm.Data.point;

            data.Y = data.Y - MetaForm.Data.radius;
            DXFPoint dXFPoint = MetaForm.Data.point1;

            dXFPoint.Y = dXFPoint.Y - MetaForm.Data.radius;
            DXFPoint data1 = MetaForm.Data.point;

            data1.X = data1.X + MetaForm.Data.radius;
            DXFPoint x1 = MetaForm.Data.point1;

            x1.X = x1.X + MetaForm.Data.radius;
            if (single <= single1)
            {
                DXFPoint y1 = MetaForm.Data.point;
                y1.Y = y1.Y - (single1 - single) / 2f;
                DXFPoint dXFPoint1 = MetaForm.Data.point1;
                dXFPoint1.Y = dXFPoint1.Y - (single1 - single) / 2f;
            }
            else
            {
                DXFPoint data2 = MetaForm.Data.point;
                data2.Y = data2.Y + (single - single1) / 2f;
                DXFPoint y2 = MetaForm.Data.point1;
                y2.Y = y2.Y + (single - single1) / 2f;
            }
            MetaForm.Data.point1.X = (MetaForm.Data.point1.X - MetaForm.Data.point.X) / 2f;
            MetaForm.Data.point1.Y = (MetaForm.Data.point1.Y - MetaForm.Data.point.Y) / 2f;
            if (MetaForm.Data.radius < MetaForm.Data.point1.Y)
            {
                MetaForm.Data.radius = MetaForm.Data.point1.Y;
            }
            DXFPoint x2 = MetaForm.Data.point1;

            x2.X = x2.X / MetaForm.Data.radius;
            DXFPoint dXFPoint2 = MetaForm.Data.point1;

            dXFPoint2.Y = dXFPoint2.Y / MetaForm.Data.radius;
            if (MetaForm.Data.point1.X <= MetaForm.Data.point1.Y)
            {
                MetaForm.Data.point1.Y = MetaForm.Data.radius;
                MetaForm.Data.radius   = MetaForm.Data.point1.X;
                MetaForm.Data.point1.X = 0f;
            }
            else
            {
                MetaForm.Data.point1.X = MetaForm.Data.radius;
                MetaForm.Data.radius   = MetaForm.Data.point1.Y;
                MetaForm.Data.point1.Y = 0f;
            }
            if (!hatch)
            {
                MetaForm.vDXF.AddEllipse(MetaForm.Data);
                return;
            }
            MetaForm.Data.startAngle = 0f;
            MetaForm.Data.endAngle   = 6.283185f;
            MetaForm.SetHatchStyle(MetaForm.hatch_style);
            MetaForm.Data.selfType = 2;
            MetaForm.vDXF.AddHatch(MetaForm.Data);
        }
Example #12
0
        private static void DrawEllArc(byte[] arr)
        {
            float single  = MetaForm.FormatSize((int)arr[2], (int)arr[3]);
            float single1 = MetaForm.FormatSize((int)arr[6], (int)arr[7]);
            float x       = MetaForm.Format_Size2(arr[8], arr[9]);
            float y       = MetaForm.Format_Size2(arr[10], arr[11]);
            float single2 = MetaForm.Format_Size2(arr[12], arr[13]);
            float single3 = MetaForm.Format_Size2(arr[14], arr[15]);

            if (MetaForm.transform)
            {
                x = x + MetaForm.transPoint.X;
                y = y + MetaForm.transPoint.Y;
            }
            MetaForm.Data.Clear();
            MetaForm.SetLineStyle((int)MetaForm.line_style);
            MetaForm.Data.color     = DXFExport.ColorToDXF(Color.FromArgb(MetaForm.r, MetaForm.g, MetaForm.b));
            MetaForm.Data.thickness = MetaForm.obj_width;
            MetaForm.Data.point.X   = x;
            MetaForm.Data.point.Y   = -y + (float)MetaForm.imgHeight;
            MetaForm.Data.point1.X  = single2 + x;
            MetaForm.Data.point1.Y  = -single3 - y + (float)MetaForm.imgHeight;
            MetaForm.Data.radius    = (MetaForm.Data.point1.X - MetaForm.Data.point.X) / 2f;
            DXFPoint data = MetaForm.Data.point;

            data.Y = data.Y - MetaForm.Data.radius;
            DXFPoint dXFPoint = MetaForm.Data.point1;

            dXFPoint.Y = dXFPoint.Y - MetaForm.Data.radius;
            DXFPoint data1 = MetaForm.Data.point;

            data1.X = data1.X + MetaForm.Data.radius;
            DXFPoint x1 = MetaForm.Data.point1;

            x1.X = x1.X + MetaForm.Data.radius;
            if (single2 <= single3)
            {
                DXFPoint y1 = MetaForm.Data.point;
                y1.Y = y1.Y - (single3 - single2) / 2f;
                DXFPoint dXFPoint1 = MetaForm.Data.point1;
                dXFPoint1.Y = dXFPoint1.Y - (single3 - single2) / 2f;
            }
            else
            {
                DXFPoint data2 = MetaForm.Data.point;
                data2.Y = data2.Y + (single2 - single3) / 2f;
                DXFPoint y2 = MetaForm.Data.point1;
                y2.Y = y2.Y + (single2 - single3) / 2f;
            }
            MetaForm.Data.point1.X = (MetaForm.Data.point1.X - MetaForm.Data.point.X) / 2f;
            MetaForm.Data.point1.Y = (MetaForm.Data.point1.Y - MetaForm.Data.point.Y) / 2f;
            if (MetaForm.Data.radius < MetaForm.Data.point1.Y)
            {
                MetaForm.Data.radius = MetaForm.Data.point1.Y;
            }
            DXFPoint x2 = MetaForm.Data.point1;

            x2.X = x2.X / MetaForm.Data.radius;
            DXFPoint dXFPoint2 = MetaForm.Data.point1;

            dXFPoint2.Y = dXFPoint2.Y / MetaForm.Data.radius;
            if (MetaForm.Data.point1.X <= MetaForm.Data.point1.Y)
            {
                MetaForm.Data.point1.Y = MetaForm.Data.radius;
                MetaForm.Data.radius   = MetaForm.Data.point1.X;
                MetaForm.Data.point1.X = 0f;
            }
            else
            {
                MetaForm.Data.point1.X = MetaForm.Data.radius;
                MetaForm.Data.radius   = MetaForm.Data.point1.Y;
                MetaForm.Data.point1.Y = 0f;
            }
            MetaForm.Data.selfType   = 1;
            MetaForm.Data.startAngle = single * MetaForm.rad;
            MetaForm.Data.endAngle   = (single1 + single) * MetaForm.rad;
            MetaForm.vDXF.AddArc(MetaForm.Data);
        }