Ejemplo n.º 1
0
 public void WriteTablesSection(StreamWriter writer)
 {
     DXFUtils.WriteDXFRecord(writer, 0, "SECTION");
     DXFUtils.WriteDXFRecord(writer, 2, "TABLES");
     WriteLayers(writer);
     //WriteStyles(writer);
     DXFUtils.WriteDXFRecord(writer, 0, "ENDSEC");
 }
Ejemplo n.º 2
0
        public void SaveToFile(StreamWriter writer)
        {
            // Construct the styles list from the text entities we are to write out
            // ProcessStyles;

            WriteHeaderSection(writer);
            WriteTablesSection(writer);
            WriteEntitiesSection(writer);

            DXFUtils.WriteDXFRecord(writer, 0, "EOF");
        }
Ejemplo n.º 3
0
        public override void SaveToFile(StreamWriter writer, DistanceUnitsType OutputUnits)
        {
            DXFUtils.WriteDXFRecord(writer, 0, "LINE");

            base.SaveToFile(writer, OutputUnits);

            DXFUtils.WriteXYZToDXF(writer, 0, X1, Y1, Z1, OutputUnits);
            DXFUtils.WriteXYZToDXF(writer, 1, X2, Y2, Z2, OutputUnits);

            DXFUtils.WriteDXFRecord(writer, DXFConsts.DxfThicknessId, Thickness.ToString());
        }
Ejemplo n.º 4
0
        public void WriteEntitiesSection(StreamWriter writer)
        {
            DXFUtils.WriteDXFRecord(writer, 0, "SECTION");
            DXFUtils.WriteDXFRecord(writer, 2, "ENTITIES");

            foreach (var entity in Entities)
            {
                entity.SaveToFile(writer, OutputUnits);
            }

            DXFUtils.WriteDXFRecord(writer, 0, "ENDSEC");
        }
Ejemplo n.º 5
0
        public void WriteHeaderSection(StreamWriter writer)
        {
            DXFUtils.WriteDXFRecord(writer, 0, "SECTION");
            DXFUtils.WriteDXFRecord(writer, 2, "HEADER");

            /*
             * DXFUtils.WriteDXFRecord(writer, 9, "$LIMMIN");
             * DXFUtils.WriteDXFRecord(writer, 10, DXFUtils.NoLocaleFloatToStrF(DXFUtils.DXFDistance(FLimMinX, FOutputUnits), 6));
             * DXFUtils.WriteDXFRecord(writer, 20, DXFUtils.NoLocaleFloatToStrF(DXFUtils.DXFDistance(FLimMinY, FOutputUnits), 6));
             *
             * DXFUtils.WriteDXFRecord(writer, 9, "$LIMMAX");
             * DXFUtils.WriteDXFRecord(writer, 10, DXFUtils.NoLocaleFloatToStrF(DXFUtils.DXFDistance(FLimMaxX, FOutputUnits), 6));
             * DXFUtils.WriteDXFRecord(writer, 20, DXFUtils.NoLocaleFloatToStrF(DXFUtils.DXFDistance(FLimMaxY, FOutputUnits), 6));
             */

            DXFUtils.WriteDXFRecord(writer, 0, "ENDSEC");
        }
Ejemplo n.º 6
0
        public override void SaveToFile(StreamWriter writer, DistanceUnitsType OutputUnits)
        {
            GetStartEndAnglesRadius(out double start_angle, out double end_angle, out double radius);

            double IncAngle   = ArcUtils.CalcIncludedAngle(X1, Y1, X2, Y2, CX, CY, Clockwise);
            bool   ItsACircle = (start_angle == end_angle) && SingleArcEdgePoint;

            if (ItsACircle)
            {
                DXFUtils.WriteDXFRecord(writer, 0, "CIRCLE");
            }
            else
            {
                DXFUtils.WriteDXFRecord(writer, 0, "ARC");
            }

            base.SaveToFile(writer, OutputUnits);

            DXFUtils.WriteXYZToDXF(writer, 0, CX, CY, CZ, OutputUnits);
            DXFUtils.WriteDXFRecord(writer, DXFConsts.ArcRadiusId, DXFUtils.NoLocaleFloatToStrF(DXFUtils.DXFDistance(radius, OutputUnits), 6));

            if (!ItsACircle)
            {
                start_angle = start_angle / (Math.PI / 180);
                end_angle   = end_angle / (Math.PI / 180);

                if (IncAngle < 0)
                {
                    MinMax.Swap(ref start_angle, ref end_angle);
                }
                if (start_angle < 0)
                {
                    start_angle = start_angle + 360;
                }
                if (end_angle < start_angle)
                {
                    end_angle = end_angle + 360;
                }

                // Write the two angles to the DXF file
                DXFUtils.WriteDXFAngle(writer, DXFConsts.ArcStartAngleId, start_angle);
                DXFUtils.WriteDXFAngle(writer, DXFConsts.ArcEndAngleId, end_angle);
            }

            DXFUtils.WriteDXFRecord(writer, DXFConsts.DxfThicknessId, Thickness.ToString());
        }
Ejemplo n.º 7
0
        public void WriteLayers(StreamWriter writer)
        {
            if (Layers.Count == 0)
            {
                return;
            }

            DXFUtils.WriteDXFRecord(writer, 0, "TABLE");
            DXFUtils.WriteDXFRecord(writer, 2, "LAYER");
            for (int I = 0; I < Layers.Count; I++)
            {
                DXFUtils.WriteDXFRecord(writer, 0, "LAYER");
                DXFUtils.WriteDXFRecord(writer, 2, DXFUtils.DXFiseLayerName(Layers[I]));
                DXFUtils.WriteDXFRecord(writer, 70, "0");
                DXFUtils.WriteDXFRecord(writer, 62, "7");
                DXFUtils.WriteDXFRecord(writer, 6, "CONTINUOUS");
            }
            DXFUtils.WriteDXFRecord(writer, 0, "ENDTAB");
        }
Ejemplo n.º 8
0
        protected void SaveAsPolyLine(StreamWriter writer, DistanceUnitsType OutputUnits)
        {
            if (Entities.Count == 0)
            {
                return;
            }

            // Get the height of the first vertex in the polyline. If the polyline is not
            // to be written out as a 3D polyline, this height will be the height of all the
            // vertices in the polyline.
            var PolyLineHeight = Entities[0].GetInitialHeight();

            DXFUtils.WriteDXFRecord(writer, 0, "POLYLINE");

            base.SaveToFile(writer, OutputUnits);

            DXFUtils.WriteDXFRecord(writer, DXFConsts.DxfThicknessId, Thickness.ToString());

            DXFUtils.WriteDXFRecord(writer, 6, "CONTINUOUS");

            var PolylineFlags = 0;

            if (Closed)
            {
                PolylineFlags |= 0x01;
            }

            // Determine if the polyline contains any arc entities (ie: intervals with 'bulges')
            var HasArcs = false;

            foreach (var entity in Entities)
            {
                if (entity is DXFArcEntity)
                {
                    HasArcs = true;
                    break;
                }
            }

            var Output3DVertices = Is3D();

            if (HasArcs && PolyLineHeight != Consts.NullDouble)
            // We have to write out a 30 record to specify the
            // height of all the entities in the polyline.
            {
                DXFUtils.WriteDXFRecord(writer, 30, DXFUtils.NoLocaleFloatToStrF(DXFUtils.DXFDistance(PolyLineHeight, OutputUnits), 6));
                Output3DVertices = false;
            }

            if (Output3DVertices)
            {
                PolylineFlags |= 0x08;
            }
            DXFUtils.WriteDXFRecord(writer, DXFConsts.PolyLineFlagsId, PolylineFlags.ToString());

            DXFUtils.WriteDXFRecord(writer, DXFConsts.EntitiesFollowId, "1");
            DXFUtils.WriteXYZToDXF(writer, 0, 0, 0, Consts.NullDouble, OutputUnits);

            for (int I = 0; I < Entities.Count; I++)
            {
                DXFUtils.WriteDXFRecord(writer, 0, "VERTEX");
                DXFUtils.WriteDXFRecord(writer, DXFConsts.LayerNameId, DXFUtils.DXFiseLayerName(Layer));

                if (Entities[I] is DXFLineEntity lineEntity)
                {
                    DXFUtils.WriteXYZToDXF(writer, 0, lineEntity.X1, lineEntity.Y1, HasArcs ? Consts.NullDouble : lineEntity.Z1, OutputUnits);
                }

                if (Entities[I] is DXFArcEntity arcEntity)
                {
                    DXFUtils.WriteXYZToDXF(writer, 0, arcEntity.X1, arcEntity.Y1, Consts.NullDouble, OutputUnits);

                    // Write out the bulge for the arc
                    var IncAngle = ArcUtils.CalcIncludedAngle(arcEntity.X1, arcEntity.Y1, arcEntity.X2, arcEntity.Y2, arcEntity.CX, arcEntity.CY, arcEntity.Clockwise);
                    var Bulge    = Math.Tan(IncAngle / 4);
                    DXFUtils.WriteDXFRecord(writer, DXFConsts.ArcBulgeId, DXFUtils.NoLocaleFloatToStrF(Bulge, 6));
                }

                if (Output3DVertices)
                {
                    DXFUtils.WriteDXFRecord(writer, DXFConsts.VertexFlagsId, "32");
                }
            }

            // Write out last vertex
            DXFUtils.WriteDXFRecord(writer, 0, "VERTEX");

            DXFUtils.WriteDXFRecord(writer, DXFConsts.LayerNameId, DXFUtils.DXFiseLayerName(Layer));
            if (Entities[Entities.Count - 1] is DXFArcEntity arcEntityEnd)
            {
                DXFUtils.WriteXYZToDXF(writer, 0, arcEntityEnd.X2, arcEntityEnd.Y2, Consts.NullDouble, OutputUnits);
            }
            else if (Entities[Entities.Count - 1] is DXFLineEntity lineEntity)
            {
                DXFUtils.WriteXYZToDXF(writer, 0, lineEntity.X2, lineEntity.Y2, HasArcs ? Consts.NullDouble : lineEntity.Z2, OutputUnits);
            }

            if (Output3DVertices)
            {
                DXFUtils.WriteDXFRecord(writer, DXFConsts.VertexFlagsId, "32");
            }

            DXFUtils.WriteDXFRecord(writer, 0, "SEQEND");
        }
Ejemplo n.º 9
0
        public override void SaveToFile(StreamWriter writer, DistanceUnitsType OutputUnits)
        {
//  text_format : text_format_rec;
//      XJust, YJust: Word;
//    DXFText: string;
            //   FontCodes: string;

            /*
             * string ReplaceDXFANSIChars(string S)
             * {
             * Result = S;
             *
             * AnsiReplaceText(Result, '%', '%%%');
             * AnsiReplaceText(Result, AnsiDegreeSymbol, '%%d');
             * AnsiReplaceText(Result, AnsiPlusMinusSymbol, '%%p');
             * AnsiReplaceText(Result, AnsiCircleAndStrokeSymbol, '%%c');
             * }
             */

            var DXFText = Text; //ReplaceChars(fText);

            if (DXFText.Length > 255)
            {
                /*
                 * WriteDXFRecord(F, 0, 'MTEXT');
                 * FontCodes= '';
                 * if fsBold in fStyles then FontCodes= FontCodes + '|b1';
                 * if fsItalic in fStyles then FontCodes= FontCodes + '|i1';
                 * if fsUnderline in fStyles then DXFText= '\L' + DXFText;
                 * if Length(FontCodes) <> 0 then
                 * DXFText = '\f' + fFontName + FontCodes + ';' + DXFText;
                 */
            }
            else
            {
                DXFUtils.WriteDXFRecord(writer, 0, "TEXT");
            }

            base.SaveToFile(writer, OutputUnits);

            DXFUtils.WriteXYZToDXF(writer, 0, X, Y, Z, OutputUnits);
            DXFUtils.WriteDXFRecord(writer, DXFConsts.TextSizeId, DXFUtils.NoLocaleFloatToStrF(DXFUtils.DXFDistance(Size, OutputUnits), 3));

            // Note: Underline text attributes must be supported by use of the %%u descriptor
            //       embedded in the text, rather than in a style (can't be supported by styles)

            //  if fsUnderline in fStyles then
            //DXFText= '%%u' + DXFText;

            DXFUtils.WriteDXFRecord(writer, 1, DXFText);

            /*
             * DXFUtils.WriteDXFRecord(writer, 1, copy(ReplaceDXFANSIChars(DXFText), 1, 255));
             * Delete(DXFText, 1, 255);
             * while Length(DXFText) <> 0 do
             *    begin
             * DXFUtils.WriteDXFRecord(writer, 3, copy(ReplaceDXFANSIChars(DXFText), 1, 255));
             * Delete(DXFText, 1, 255);
             * end;
             */

            /*
             * if Assigned(FTextStyle) then
             * DXFUtils.WriteDXFRecord(writer, DXFConsts.FontNameId, FTextStyle.Name);
             * else
             * DXFUtils.WriteDXFRecord(writer, DXFConsts.FontNameId, FontName);
             */

            DXFUtils.WriteDXFRecord(writer, DXFConsts.TextOrientationId, DXFUtils.NoLocaleFloatToStrF(((Math.PI / 2) - Orientation) * (180 / Math.PI), 3)); // fOrientation is in radians, but degress in file

            /*
             * unpack_text_format(fFormat, text_format);
             *
             * int XJust = 0;
             * int YJust = 0;
             *
             * Case Text_format.posn of
             * top_left, top_right, top_centre: YJust = 3;
             * centre_left, centre_right, centre_centre:
             * YJust = 2;
             * bottom_left, bottom_right, bottom_centre:
             * YJust = 0; // 0 for baseline, not bottom of descender (=1)!;
             * descender_left, descender_right, descender_centre:
             * YJust = 1;
             * end;
             *
             * Case Text_format.posn of
             * bottom_left, top_left, centre_left, descender_left: XJust = 0;
             * bottom_centre, top_centre, centre_centre, descender_centre:
             * XJust = 1;
             * bottom_right, top_right, centre_right, descender_right:
             * XJust = 2;
             * end;
             *
             * if (XJust != 0)
             * DXFUtils.WriteDXFRecord(writer, DXFConsts.TextJustificationX, XJust.ToString());
             * if (YJust != 0)
             * DXFUtils.WriteDXFRecord(writer, DXFConsts.TextJustificationY, YJust.ToString());
             *
             * if (XJust != 0 || YJust != 0) // write out secondary position, same as initial position
             * DXFUtils.WriteXYZToDXF(writer, 1, AlignX, AlignY, 0, OutputUnits);
             */
        }
Ejemplo n.º 10
0
 public virtual void SaveToFile(StreamWriter writer, DistanceUnitsType OutputUnits)
 {
     DXFUtils.WriteDXFRecord(writer, DXFConsts.LayerNameId, DXFUtils.DXFiseLayerName(Layer));
     DXFUtils.WriteDXFRecord(writer, DXFConsts.ColourId, Colour.ToString());
 }