private static void loadDXF(Stream content)
        {
            doc = new DXFDocument();
            doc.Load(content);


            //    GetVectorDXF();
        }
Exemple #2
0
        /// <summary>
        /// Load and parse DXF code
        /// </summary>
        /// <param name="filename">String keeping file-name</param>
        /// <returns></returns>
        private static void GetVectorDXF(string filename)
        {
            DXFDocument doc = new DXFDocument();

            doc.Load(filename);
            gcodePenUp("DXF Start");
            lastGCX = -1; lastGCY = -1; lastSetGCX = -1; lastSetGCY = -1;
            foreach (DXFEntity dxfEntity in doc.Entities)
            {
                dxfBezierAccuracy = (int)Properties.Settings.Default.importSVGBezier;
                gcodeReduce       = Properties.Settings.Default.importSVGReduce;
                gcodeReduceVal    = (double)Properties.Settings.Default.importSVGReduceLimit;

                gcodeZIncEnable = Properties.Settings.Default.importGCZIncEnable;
                gcodeZIncrement = (double)Properties.Settings.Default.importGCZIncrement;

                dxfPauseElement = Properties.Settings.Default.importSVGPauseElement;
                dxfPausePenDown = Properties.Settings.Default.importSVGPausePenDown;
                dxfComments     = Properties.Settings.Default.importSVGAddComments;

                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)
                        {
                            if (dxfComments)
                            {
                                gcode.Comment(gcodeString[gcodeStringIndex], "Color: " + block.ColorNumber.ToString());
                                gcode.Comment(gcodeString[gcodeStringIndex], "Block: " + block.BlockName.ToString() + " at " + ins_x.ToString() + " " + ins_y.ToString());
                            }
                            foreach (DXFEntity blockEntity in block.Children)
                            {
                                processEntities(blockEntity, ins_x, ins_y);
                            }
                            if (dxfComments)
                            {
                                gcode.Comment(gcodeString[gcodeStringIndex], "Block: " + block.BlockName.ToString() + " end");
                            }
                        }
                    }
                }
                else
                {
                    processEntities(dxfEntity);
                }
            }
            if (askPenUp)   // retrieve missing pen up
            {
                gcode.PenUp(gcodeString[gcodeStringIndex]); askPenUp = false;
            }
        }
 private static bool loadDXF(Stream content)
 {
     doc = new DXFDocument();
     try { doc.Load(content); }
     catch (Exception er)
     { Logger.Error(er, "loading the file failed ");
       MessageBox.Show("The file could not be opened - perhaps already open in other application?\r\n" + er.ToString());
       return(false); }
     return(true);
 }
Exemple #4
0
 private static void loadDXF(string filename)
 {
     doc = new DXFDocument();
     doc.Load(filename);
     //  GetVectorDXF();
     Logger.Log.AddMsg2(Logger.LogType.Normal, doc.Blocks.Count.ToString(), "blockds");
     Logger.Log.AddMsg2(Logger.LogType.Normal, doc.Entities.Count.ToString(), "Entities");
     Logger.Log.AddMsg2(Logger.LogType.Normal, doc.Classes.Count.ToString(), "Classes");
     Logger.Log.AddMsg2(Logger.LogType.Normal, doc.Header.ToString(), "Header");
     Logger.Log.AddMsg2(Logger.LogType.Normal, doc.Tables.ToString(), "Tables");
 }
Exemple #5
0
        public GcodeDocument FromDXF(DXFDocument document)
        {
            List <object> items = new List <object>();


            // Need to get to the initial start point
            // The class structure needs to store the full co-ordinates
            // but only output the gcode with the differences

            foreach (DXFEntity entity in document.Entities)
            {
                if (entity.GetType() == typeof(DXFLine))
                {
                    DXFLine dxfLine = (DXFLine)entity;
                    Point   from    = new Point(dxfLine.Start.X.Value, dxfLine.Start.Y.Value, dxfLine.Start.Z.Value);
                    Point   to      = new Point(dxfLine.End.X.Value, dxfLine.End.Y.Value, dxfLine.End.Z.Value);
                    Line    line    = new Line(from, to);
                    items.Add(line);
                }
            }

            GcodeDocument gcodeDocument = new GcodeDocument();

            //foreach (DXFEntity entity in document.Entities)
            //{
            //    if (entity.GetType() == typeof(DXFLine))
            //    {
            //        DXFLine dxfLine = (DXFLine)entity;
            //        GraphicPrimitives.Point from = new GraphicPrimitives.Point(dxfLine.Start.X.Value, dxfLine.Start.Y.Value, dxfLine.Start.Z.Value);
            //        GraphicPrimitives.Point to = new GraphicPrimitives.Point(dxfLine.End.X.Value, dxfLine.End.Y.Value, dxfLine.End.Z.Value);
            //        GraphicPrimitives.Line line = new GraphicPrimitives.Line(from, to);
            //        GcodeLibrary.LinearMove linearMove = new LinearMove(line);
            //        gcodeDocument.Add(linearMove);
            //    }
            //}

            return(gcodeDocument);
        }
Exemple #6
0
 private static void loadDXF(string filename)
 {
     doc = new DXFDocument();
     doc.Load(filename);
     GetVectorDXF();
 }
        private List <GroupPoint> GetVectorDXF(string FileNAME)
        {
            textBoxInfo.Text = "";

            DXFDocument doc = new DXFDocument();

            doc.Load(FileNAME);

            List <GroupPoint> ListLines;
            List <cncPoint>   ListPoint;

            ListLines = new List <GroupPoint>();

            int count_DXFLWPolyLine = 0;
            int count_DXFPolyLine   = 0;
            int count_DXFLine       = 0;
            int count_DXFCircle     = 0;
            int count_DXFSpline     = 0;
            int count_DXFArc        = 0;



            double minX   = 99999;
            double maxX   = -99999;
            double deltaX = 0;

            double minY   = 99999;
            double maxY   = -99999;
            double deltaY = 0;

            foreach (DXFEntity VARIABLE in doc.Entities)
            {
                bool typeDetected = false;

                if (VARIABLE.GetType() == typeof(DXFLWPolyLine))
                {
                    typeDetected = true;
                    count_DXFLWPolyLine++;
                    DXFLWPolyLine lp = (DXFLWPolyLine)VARIABLE;

                    ListPoint = new List <cncPoint>();

                    foreach (DXFLWPolyLine.Element pl_e in lp.Elements)
                    {
                        ListPoint.Add(new cncPoint((double)pl_e.Vertex.X, (double)pl_e.Vertex.Y));
                    }
                    ListLines.Add(new GroupPoint(ListPoint));
                    ListPoint = new List <cncPoint>();
                }

                if (VARIABLE.GetType() == typeof(DXFPolyLine))
                {
                    typeDetected = true;
                    count_DXFPolyLine++;
                    DXFPolyLine lp = (DXFPolyLine)VARIABLE;

                    ListPoint = new List <cncPoint>();

                    foreach (DXFVertex pl_e in lp.Children)
                    {
                        if (pl_e.GetType() == typeof(DXFVertex))
                        {
                            if (pl_e.Location.X != null && pl_e.Location.Y != null)
                            {
                                ListPoint.Add(new cncPoint((double)pl_e.Location.X, (double)pl_e.Location.Y));
                            }
                        }
                    }
                    ListLines.Add(new GroupPoint(ListPoint));
                    ListPoint = new List <cncPoint>();
                }



                if (VARIABLE.GetType() == typeof(DXFLine))
                {
                    typeDetected = true;
                    count_DXFLine++;
                    DXFLine line = (DXFLine)VARIABLE;

                    ListPoint = new List <cncPoint>();
                    ListPoint.Add(new cncPoint((double)line.Start.X, (double)line.Start.Y));
                    ListPoint.Add(new cncPoint((double)line.End.X, (double)line.End.Y));
                    ListLines.Add(new GroupPoint(ListPoint));
                    ListPoint = new List <cncPoint>();
                }


                if (VARIABLE.GetType() == typeof(DXFSpline))
                {
                    typeDetected = true;
                    count_DXFSpline++;
                    DXFSpline spline = (DXFSpline)VARIABLE;

                    ListPoint = new List <cncPoint>();

                    foreach (DXFPoint ppoint in spline.ControlPoints)
                    {
                        ListPoint.Add(new cncPoint((double)ppoint.X, (double)ppoint.Y));
                    }

                    ListLines.Add(new GroupPoint(ListPoint));
                    ListPoint = new List <cncPoint>();
                }


                if (VARIABLE.GetType() == typeof(DXFCircle))
                {
                    typeDetected = true;
                    count_DXFCircle++;
                    DXFCircle circle = (DXFCircle)VARIABLE;

                    double X = (double)circle.Center.X;
                    double Y = (double)circle.Center.Y;
                    float  R = (float)circle.Radius;



                    //тут определим необходимый угол
                    //и вычислим количество сегментов

                    double angle = GetAngleArcSegment((decimal)R, Settings.Default.page11arcMaxLengLine);

                    if (angle < 1)
                    {
                        angle = 1;
                    }


                    int segmentsCount = 360 / (int)angle;

                    ListPoint = new List <cncPoint>();

                    for (int i = 0; i < segmentsCount; i++)
                    {
                        float rx = R * (float)Math.Cos(2 * (float)Math.PI / segmentsCount * i);
                        float ry = R * (float)Math.Sin(2 * (float)Math.PI / segmentsCount * i);

                        ListPoint.Add(new cncPoint(X + (double)rx, Y + (double)ry));
                    }

                    ListPoint.Add(new cncPoint(ListPoint[0].X, ListPoint[0].Y));

                    ListLines.Add(new GroupPoint(ListPoint));
                    ListPoint = new List <cncPoint>();


                    //
                    //ListPoint.Add(new Location((decimal)line.Start.X, (decimal)line.Start.Y));
                    //ListPoint.Add(new Location((decimal)line.End.X, (decimal)line.End.Y));
                    //
                }


                if (VARIABLE.GetType() == typeof(DXFArc))
                {
                    typeDetected = true;
                    count_DXFArc++;
                    DXFArc arc = (DXFArc)VARIABLE;

                    double X          = (double)arc.Center.X;
                    double Y          = (double)arc.Center.Y;
                    double R          = arc.Radius;
                    double startAngle = arc.StartAngle;
                    double endAngle   = arc.EndAngle;

                    if (startAngle > endAngle)
                    {
                        endAngle += 360;
                    }

                    //тут определим необходимый угол
                    //и вычислим количество сегментов

                    float StepAngle = (float)GetAngleArcSegment((decimal)R, Settings.Default.page11arcMaxLengLine);

                    ListPoint = new List <cncPoint>();

                    double currAngle = startAngle;

                    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));

                        ListPoint.Add(new cncPoint(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));

                            ListPoint.Add(new cncPoint(rx2, ry2));
                        }
                    }


                    // int segmentsCount = 360 / (int)angle;


                    //for (float i = startAngle; i < endAngle; i+= (float)angle)
                    //{


                    //

                    //}


                    ListLines.Add(new GroupPoint(ListPoint));
                    ListPoint = new List <cncPoint>();
                }



                if (!typeDetected)
                {
                    textBoxInfo.Text += "Не распознан тип данных: " + VARIABLE.GetType().ToString() +
                                        Environment.NewLine;
                }
            }

            //ListLines = new List<Segment>();

            textBoxInfo.Text += @"Обработано DXFLWPolyLine: " + count_DXFLWPolyLine.ToString() + Environment.NewLine;
            textBoxInfo.Text += @"Обработано DXFPolyLine: " + count_DXFPolyLine.ToString() + Environment.NewLine;
            textBoxInfo.Text += @"Обработано DXFLine: " + count_DXFLine.ToString() + Environment.NewLine;
            textBoxInfo.Text += @"Обработано DXFCircle: " + count_DXFCircle.ToString() + Environment.NewLine;

            textBoxInfo.Text += @"Обработано DXFSpline: " + count_DXFSpline.ToString() + Environment.NewLine;
            textBoxInfo.Text += @"Обработано DXFArc: " + count_DXFArc.ToString() + Environment.NewLine;


            foreach (GroupPoint vSegment in ListLines)
            {
                foreach (cncPoint vLocation in vSegment.Points)
                {
                    if (vLocation.X < minX)
                    {
                        minX = vLocation.X;
                    }

                    if (vLocation.Y < minY)
                    {
                        minY = vLocation.Y;
                    }

                    if (vLocation.X > maxX)
                    {
                        maxX = vLocation.X;
                    }

                    if (vLocation.Y > maxY)
                    {
                        maxY = vLocation.Y;
                    }
                }
            }

            deltaX = maxX - minX;
            deltaY = maxY - minY;

            textBoxInfo.Text += @"Размер по X: " + deltaX.ToString() + Environment.NewLine;
            textBoxInfo.Text += @"Размер по Y: " + deltaY.ToString() + Environment.NewLine;



            return(ListLines);
        }
Exemple #8
0
        public void Run(String[] args)
        {
            // Read in specific configuration

            _logger.LogDebug("In Run()");

            int       pos       = 0;
            Parameter HPGL2Path = new Parameter("");
            Parameter HPGL2Name = new Parameter("dxf.xml");

            // Required for the plot

            Parameter filename = new Parameter("");
            Parameter filePath = new Parameter("");
            Parameter outName  = new Parameter("");

            HPGL2Path.Value  = System.Reflection.Assembly.GetExecutingAssembly().Location;
            pos              = HPGL2Path.Value.ToString().LastIndexOf('\\');
            HPGL2Path.Value  = HPGL2Path.Value.ToString().Substring(0, pos);
            HPGL2Path.Source = Parameter.SourceType.App;

            filePath.Value  = Environment.CurrentDirectory;
            filePath.Source = Parameter.SourceType.App;

            try
            {
                RegistryKey key = Registry.LocalMachine;
                key = key.OpenSubKey("software\\green\\dxf\\");
                if (key != null)
                {
                    if (key.GetValue("path", "").ToString().Length > 0)
                    {
                        HPGL2Path.Value  = (string)key.GetValue("path", HPGL2Path);
                        HPGL2Path.Source = Parameter.SourceType.Registry;
                        _logger.LogDebug("Use registry value Path=" + HPGL2Path);
                    }

                    if (key.GetValue("name", "").ToString().Length > 0)
                    {
                        HPGL2Name.Value  = (string)key.GetValue("name", HPGL2Name);
                        HPGL2Name.Source = Parameter.SourceType.Registry;
                        _logger.LogDebug("Use registry value Name=" + HPGL2Name);
                    }
                }
            }
            catch (NullReferenceException)
            {
                _logger.LogError("Registry error use default values; Name=" + HPGL2Name.Value + " Path=" + HPGL2Path.Value);
            }
            catch (Exception e)
            {
                _logger.LogDebug(e.ToString());
            }

            // Check if the config file has been paased in and overwrite the registry

            int items = args.Length;

            for (int item = 0; item < items; item++)
            {
                {
                    switch (args[item])
                    {
                    case "/N":
                    case "--name":
                    {
                        HPGL2Name.Value  = args[item + 1];
                        HPGL2Name.Value  = HPGL2Name.Value.ToString().TrimStart('"');
                        HPGL2Name.Value  = HPGL2Name.Value.ToString().TrimEnd('"');
                        HPGL2Name.Source = Parameter.SourceType.Command;
                        _logger.LogDebug("Use command value Name=" + HPGL2Name);
                        break;
                    }

                    case "/P":
                    case "--path":
                    {
                        HPGL2Path.Value  = args[item + 1];
                        HPGL2Path.Value  = HPGL2Path.Value.ToString().TrimStart('"');
                        HPGL2Path.Value  = HPGL2Path.Value.ToString().TrimEnd('"');
                        HPGL2Path.Source = Parameter.SourceType.Command;
                        _logger.LogDebug("Use command value Path=" + HPGL2Path);
                        break;
                    }
                    }
                }
            }
            _logger.LogInformation("Use HPGL2Name=" + HPGL2Name.Value + " HPGL2Path=" + HPGL2Path.Value);

            // Read in configuration

            _dxf = new DXFDocument();

            //Serialise serialise = new Serialise(HPGL2Name.Value, HPGL2Path.Value, _logger);
            //_dxf = serialise.FromXML();
            //if (_dxf != null)
            //{

            //}

            // Read in the plot specific parameters

            string filenamePath = "";
            string extension    = "";

            items = args.Length;
            if (items == 1)
            {
                int index = 0;
                filenamePath = args[index].Trim('"');
                pos          = filenamePath.LastIndexOf('.');
                if (pos > 0)
                {
                    extension    = filenamePath.Substring(pos + 1, filenamePath.Length - pos - 1);
                    filenamePath = filenamePath.Substring(0, pos);
                }

                pos = filenamePath.LastIndexOf('\\');
                if (pos > 0)
                {
                    filePath.Value  = filenamePath.Substring(0, pos);
                    filePath.Source = Parameter.SourceType.Command;
                    filename.Value  = filenamePath.Substring(pos + 1, filenamePath.Length - pos - 1);
                    filename.Source = Parameter.SourceType.Command;
                }
                else
                {
                    filename.Value  = filenamePath;
                    filename.Source = Parameter.SourceType.Command;
                }
                _logger.LogInformation("Use filename=" + filename.Value);
                _logger.LogInformation("Use filePath=" + filePath.Value);
            }
            else
            {
                for (int item = 0; item < items; item++)
                {
                    {
                        switch (args[item])
                        {
                        case "/f":
                        case "--filename":
                        {
                            filename.Value  = args[item + 1];
                            filename.Value  = filename.Value.ToString().TrimStart('"');
                            filename.Value  = filename.Value.ToString().TrimEnd('"');
                            filename.Source = Parameter.SourceType.Command;
                            pos             = filename.Value.ToString().LastIndexOf('.');
                            if (pos > 0)
                            {
                                extension      = filename.Value.ToString().Substring(pos + 1, filename.Value.ToString().Length - pos - 1);
                                filename.Value = filename.Value.ToString().Substring(0, pos);
                            }
                            _logger.LogDebug("Use command value Filename=" + filename);
                            break;
                        }

                        case "/O":
                        case "--output":
                        {
                            outName.Value  = args[item + 1];
                            outName.Value  = outName.Value.ToString().TrimStart('"');
                            outName.Value  = outName.Value.ToString().TrimEnd('"');
                            outName.Source = Parameter.SourceType.Command;
                            _logger.LogDebug("Use command value Output=" + outName);
                            break;
                        }

                        case "/p":
                        case "--filepath":
                        {
                            filePath.Value  = args[item + 1];
                            filePath.Value  = filePath.Value.ToString().TrimStart('"');
                            filePath.Value  = filePath.Value.ToString().TrimEnd('"');
                            filePath.Source = Parameter.SourceType.Command;
                            _logger.LogDebug("Use command value Filename=" + filePath);
                            break;
                        }
                        }
                    }
                }
                _logger.LogInformation("Use Filename=" + filename.Value);
                _logger.LogInformation("Use Filepath=" + filePath.Value);
            }

            if (outName.Value.ToString().Length == 0)
            {
                outName.Value = filename.Value;
            }

            // Read the plot data and create the CNC file

            _dxf.Load(filePath.Value.ToString(), filename.Value.ToString());

            _logger.LogDebug("Out Run()");
        }
Exemple #9
0
        public void TestMethod4()
        {
            DXFDocument doc = new DXFDocument();

            doc.Load(new MemoryStream(Properties.Resources.Hase));
        }
Exemple #10
0
        //[TestMethod]
        public void TestMethod3()
        {
            DXFDocument doc = new DXFDocument();

            doc.Load(new MemoryStream(Properties.Resources.Untitled_2));
        }
Exemple #11
0
        //
        // Sie können beim Schreiben der Tests folgende zusätzliche Attribute verwenden:
        //
        // Verwenden Sie ClassInitialize, um vor Ausführung des ersten Tests in der Klasse Code auszuführen.
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Verwenden Sie ClassCleanup, um nach Ausführung aller Tests in einer Klasse Code auszuführen.
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        //[TestMethod]
        public void TestMethod1()
        {
            DXFDocument doc = new DXFDocument();

            doc.Load(new MemoryStream(Properties.Resources.LaptopStand));
        }