//-------------------------------------------------------------------------------------------------- void _WriteClasses(DxfWriter writer) { writer.Write(0, "SECTION"); writer.Write(2, "CLASSES"); writer.Write(0, "ENDSEC"); }
public MemoryStream WriteToStream() { var writer = new DxfWriter(Version, Flags.HasFlag(DxfFlags.ExportBinaryFile)); Write(writer); return(writer.Finish()); }
//-------------------------------------------------------------------------------------------------- void _WriteEntities(DxfWriter writer) { writer.Write(0, "SECTION"); writer.Write(2, "ENTITIES"); Entities.ForEach(entity => entity.Write(writer)); writer.Write(0, "ENDSEC"); }
//-------------------------------------------------------------------------------------------------- internal override void Write(DxfWriter writer) { writer.Write(0, "LINE"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, LayerName); writer.WriteSubclass("AcDbLine"); writer.Write(10, StartPoint.X); writer.Write(20, StartPoint.Y); writer.Write(30, 0.0); writer.Write(11, EndPoint.X); writer.Write(21, EndPoint.Y); writer.Write(31, 0.0); }
//-------------------------------------------------------------------------------------------------- void _WriteHeader(DxfWriter writer) { writer.Write(0, "SECTION"); writer.Write(2, "HEADER"); writer.Write(9, "$ACADVER"); writer.Write(1, Version.ToString()); // AutoCad R13 (SPLINE,Layer.Lineweight) writer.Write(9, "$HANDSEED"); writer.Write(5, "FFFFFF"); writer.Write(9, "$ANGDIR"); writer.Write(70, 1); // Clockwise Angles writer.Write(9, "$MEASUREMENT"); writer.Write(70, 1); // Metric writer.Write(0, "ENDSEC"); }
//-------------------------------------------------------------------------------------------------- public void Write(DxfWriter writer) { if (Version >= DxfVersion.AC1012) { _WriteHeader(writer); _WriteClasses(writer); _WriteTables(writer); _WriteBlocks(writer); } _WriteEntities(writer); if (Version >= DxfVersion.AC1012) { _WriteObjects(writer); } }
//-------------------------------------------------------------------------------------------------- void _WriteBlocks(DxfWriter writer) { writer.Write(0, "SECTION"); writer.Write(2, "BLOCKS"); writer.Write(0, "BLOCK"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, "0"); writer.WriteSubclass("AcDbBlockBegin"); writer.Write(2, "*Model_Space"); writer.Write(70, 0); writer.Write(10, 0.0); writer.Write(20, 0.0); writer.Write(30, 0.0); writer.Write(3, "*Model_Space"); writer.Write(1, ""); writer.Write(0, "ENDBLK"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, "0"); writer.WriteSubclass("AcDbBlockEnd"); writer.Write(0, "BLOCK"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, "0"); writer.WriteSubclass("AcDbBlockBegin"); writer.Write(2, "*Paper_Space"); writer.Write(70, 0); writer.Write(10, 0.0); writer.Write(20, 0.0); writer.Write(30, 0.0); writer.Write(3, "*Paper_Space"); writer.Write(1, ""); writer.Write(0, "ENDBLK"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, "0"); writer.WriteSubclass("AcDbBlockEnd"); writer.Write(0, "ENDSEC"); }
//-------------------------------------------------------------------------------------------------- internal override void Write(DxfWriter writer) { if (writer.Version < DxfVersion.AC1012) { return; } writer.Write(0, "SPLINE"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, LayerName); writer.WriteSubclass("AcDbSpline"); writer.Write(210, 0.0); // Plane normal vector writer.Write(220, 0.0); writer.Write(230, 1.0); writer.Write(70, (int)Flags.Added(SplineFlags.IsPlanar)); writer.Write(71, Degree); writer.Write(72, Knots.Length); writer.Write(73, ControlPoints.Length); writer.Write(74, 0); // Number of fit points foreach (var knot in Knots) { writer.Write(40, knot); } foreach (var point in ControlPoints) { writer.Write(10, point.X); writer.Write(20, point.Y); writer.Write(30, 0.0); } bool saveWeights = Weights?.Any(w => w.IsEqual(1.0, 0.0001)) ?? false; if (saveWeights) { foreach (var weight in Weights) { writer.Write(41, weight); } } }
//-------------------------------------------------------------------------------------------------- internal override void Write(DxfWriter writer) { // LWPOLYLINE supported by AC1012 or later if (writer.Version >= DxfVersion.AC1012) { writer.Write(0, "LWPOLYLINE"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, LayerName); writer.WriteSubclass("AcDbPolyline"); writer.Write(90, Points.Length); writer.Write(70, IsClosed ? 1 : 0); foreach (var point in Points) { writer.Write(10, point.X); writer.Write(20, point.Y); writer.Write(30, 0.0); } } else { // Version only for AC1009 writer.Write(0, "POLYLINE"); writer.WriteHandle(); writer.Write(8, LayerName); writer.Write(66, 1); writer.Write(10, 0.0); writer.Write(20, 0.0); writer.Write(30, 0.0); writer.Write(70, IsClosed ? 1 : 0); foreach (var point in Points) { writer.Write(0, "VERTEX"); writer.WriteHandle(); writer.Write(8, LayerName); writer.Write(10, point.X); writer.Write(20, point.Y); writer.Write(30, 0.0); } writer.Write(0, "SEQEND"); } }
//-------------------------------------------------------------------------------------------------- void _WriteObjects(DxfWriter writer) { writer.Write(0, "SECTION"); writer.Write(2, "OBJECTS"); writer.Write(0, "DICTIONARY"); int lastHandle = writer.WriteHandle(); writer.WriteSubclass("AcDbDictionary"); writer.Write(281, 1); writer.Write(3, "ACAD_GROUP"); writer.Write(350, (lastHandle + 1).ToString("X")); writer.Write(0, "DICTIONARY"); writer.WriteHandle(); writer.WriteSubclass("AcDbDictionary"); writer.Write(281, 1); writer.Write(0, "ENDSEC"); }
//-------------------------------------------------------------------------------------------------- internal override void Write(DxfWriter writer) { writer.Write(0, IsArc ? "ARC" : "CIRCLE"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, LayerName); writer.WriteSubclass("AcDbCircle"); writer.Write(10, CenterPoint.X); writer.Write(20, CenterPoint.Y); writer.Write(30, 0.0); writer.Write(40, Radius); if (IsArc) { writer.WriteSubclass("AcDbArc"); writer.Write(50, StartAngle); writer.Write(51, EndAngle); } }
//-------------------------------------------------------------------------------------------------- internal override void Write(DxfWriter writer) { writer.Write(0, "POLYLINE"); writer.WriteHandle(); writer.Write(8, LayerName); writer.Write(66, 1); writer.Write(10, 0.0); writer.Write(20, 0.0); writer.Write(30, 0.0); writer.Write(70, IsClosed ? 1 : 0); foreach (var point in Points) { writer.Write(0, "VERTEX"); writer.WriteHandle(); writer.Write(8, LayerName); writer.Write(10, point.X); writer.Write(20, point.Y); writer.Write(30, 0.0); } writer.Write(0, "SEQEND"); }
//-------------------------------------------------------------------------------------------------- internal override void Write(DxfWriter writer) { if (writer.Version < DxfVersion.AC1012) { return; } writer.Write(0, "ELLIPSE"); writer.WriteHandle(); writer.WriteSubclass("AcDbEntity"); writer.Write(8, LayerName); writer.WriteSubclass("AcDbEllipse"); writer.Write(10, CenterPoint.X); writer.Write(20, CenterPoint.Y); writer.Write(30, 0.0); writer.Write(11, MajorAxisPointOffset.X); writer.Write(21, MajorAxisPointOffset.Y); writer.Write(31, 0.0); writer.Write(40, Ratio); writer.Write(41, StartParameter); writer.Write(42, EndParameter); }
//-------------------------------------------------------------------------------------------------- void _WriteTables(DxfWriter writer) { writer.Write(0, "SECTION"); writer.Write(2, "TABLES"); // VPORT writer.Write(0, "TABLE"); { writer.Write(2, "VPORT"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, 0); } writer.Write(0, "ENDTAB"); // LTYPE writer.Write(0, "TABLE"); { writer.Write(2, "LTYPE"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, Linetypes.Count); { Linetypes.ForEach(linetype => linetype.Write(writer)); } } writer.Write(0, "ENDTAB"); // LAYER writer.Write(0, "TABLE"); { writer.Write(2, "LAYER"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, Layers.Count); Layers.ForEach(layer => layer.Write(writer)); } writer.Write(0, "ENDTAB"); // STYLE writer.Write(0, "TABLE"); { writer.Write(2, "STYLE"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, 1); { writer.Write(0, "STYLE"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTableRecord"); writer.WriteSubclass("AcDbTextStyleTableRecord"); writer.Write(2, "STANDARD"); writer.Write(70, 0); writer.Write(40, 0.0); writer.Write(41, 1.0); writer.Write(50, 0.0); writer.Write(71, 0); writer.Write(42, 2.5); writer.Write(3, "txt"); writer.Write(4, ""); } } writer.Write(0, "ENDTAB"); // VIEW writer.Write(0, "TABLE"); { writer.Write(2, "VIEW"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, 0); } writer.Write(0, "ENDTAB"); // UCS writer.Write(0, "TABLE"); { writer.Write(2, "UCS"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, 0); } writer.Write(0, "ENDTAB"); // APPID writer.Write(0, "TABLE"); { writer.Write(2, "APPID"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, 1); { writer.Write(0, "APPID"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTableRecord"); writer.WriteSubclass("AcDbRegAppTableRecord"); writer.Write(2, "ACAD"); writer.Write(70, 0); } } writer.Write(0, "ENDTAB"); // DIMSTYLE writer.Write(0, "TABLE"); { writer.Write(2, "DIMSTYLE"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, 1); if (Version >= DxfVersion.AC1015) { writer.WriteSubclass("AcDbDimStyleTable"); } { writer.Write(0, "DIMSTYLE"); writer.WriteHandle(105); writer.WriteSubclass("AcDbSymbolTableRecord"); writer.WriteSubclass("AcDbDimStyleTableRecord"); writer.Write(2, "STANDARD"); writer.Write(70, 0); } } writer.Write(0, "ENDTAB"); // BLOCK_RECORD writer.Write(0, "TABLE"); { writer.Write(2, "BLOCK_RECORD"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTable"); writer.Write(70, 2); { writer.Write(0, "BLOCK_RECORD"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTableRecord"); writer.WriteSubclass("AcDbBlockTableRecord"); writer.Write(2, "*MODEL_SPACE"); writer.Write(0, "BLOCK_RECORD"); writer.WriteHandle(); writer.WriteSubclass("AcDbSymbolTableRecord"); writer.WriteSubclass("AcDbBlockTableRecord"); writer.Write(2, "*PAPER_SPACE"); } } writer.Write(0, "ENDTAB"); writer.Write(0, "ENDSEC"); }
internal abstract void Write(DxfWriter writer);