Beispiel #1
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;
            }
        }
Beispiel #2
0
        private static void GetVectorDXF()
        {
            gcodePenUp("DXF Start");
            lastGCX = -1; lastGCY = -1; lastSetGCX = -1; lastSetGCY = -1;
//            MessageBox.Show("unit "+ doc.Header.MeasurementUnits.Value.ToString());

            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)
                        {
                            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 (isPenDown)
            {
                gcode.PenUp(gcodeString[gcodeStringIndex]);
            }
            //     if (dxfToolUse)
            gcode.Comment(gcodeString[gcodeStringIndex], xmlMarker.figureEnd + entityCount + ">");
        }
Beispiel #3
0
        public List <DXFGeometry> ConvertToDrawable()
        {
            List <DXFGeometry> geometry = new List <DXFGeometry>();

            if (this.FEntities == null)
            {
                return(geometry);
            }

            int n = this.FEntities.ecEntities.Count;

            for (int i = 0; i < n; i++)
            {
                DXFEntity e = this.FEntities.ecEntities[i];
                Type      t = e.GetType();

                DXFGeometry        eG  = new DXFGeometry();
                List <DXFGeometry> eGs = new List <DXFGeometry>();
                // type deistinction
                if (t == typeof(DXFInsert))
                {
                    DXFInsert ei = e as DXFInsert;
                    eGs = ei.ConvertToDrawables();
                    if (eGs.Count > 0)
                    {
                        geometry.AddRange(eGs);
                    }
                }
                else
                {
                    eG = e.ConvertToDrawable();
                    if (!eG.IsEmpty())
                    {
                        geometry.Add(eG);
                    }
                }
            }
            return(geometry);
        }
Beispiel #4
0
        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("");
        }
Beispiel #5
0
        public DXFEntity CreateEntity()
        {
            DXFEntity E;

            switch (this.FValue)
            {
            case "ENDSEC":
            case "ENDTAB":
            case "ENDBLK":
            case "SEQEND":
                return(null);

            case "SECTION":
                E = new DXFSection();
                break;

            case "TABLE":
                E = new DXFTable();
                break;

            case "BLOCK":
                E = new DXFBlock();
                break;

            case "ATTDEF":
            case "ATTRIB":
                E = new DXFAttribute();
                break;

            case "INSERT":
                E = new DXFInsert();
                break;

            case "LAYER":
                E = new DXFLayer();
                break;

            case "LINE":
                E = new DXFLine();
                break;

            case "CIRCLE":
            case "ARC":
                E = new DXFCircle();
                break;

            case "ELLIPSE":
                E = new DXFEllipse();
                break;

            case "LWPOLYLINE":
                E = new DXFLWPolyLine();
                break;

            case "TEXT":
                E = new DXFText();
                break;

            case "MTEXT":
                E = new DXFMText();
                break;

            case "POLYLINE":
                E = new DXFPolyLine();
                break;

            case "VERTEX":
                E = new DXFPositionable();
                break;

            default:
                E = new DXFDummy(this.FValue);
                break;
            }
            E.Converter = this;
            return(E);
        }