NDEVR
API Documentation
DXFWriter.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: CAD
28File: DXFWriter
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include "EntityCodes.h"
35#include "CADEntityStreamer.h"
36#include <NDEVR/String.h>
37#include <NDEVR/DynamicPointer.h>
38#include <NDEVR/LineSegment.h>
39#include <NDEVR/Polyline.h>
40#include <fstream>
41namespace NDEVR
42{
43 class DXFValueManager;
44 class File;
45 class CADHandleManager;
46 class DXFWriter;
51 class XDataWriter : public HandleData
52 {
53 public:
54 std::function<void(DXFWriter& dxf)> write_function;
55 };
56
59 class NDEVR_CAD_API DXFWriter
60 {
61 public:
62 explicit DXFWriter();
63 const DynamicPointer<CADHandleManager>& handleManager() const { return m_handle_manager; };
64 void setHandleManager(const DynamicPointer<CADHandleManager>& manager);
65 void setFileTarget(File file);
66 void setVersion(DXFVersion version);
67 void writeAPPIDTable();
68 void writeDimStyleTable();
69 void writeViewTable();
70 void writeStyleTable();
71 void writeUCSTable();
72 void writeClasses();
73 void writeLTypeTable();
74 void writeOptions(const Buffer<CADVariable>& data);
75 void startBlocks(const Buffer<BlockData>& data);
76 void startBlock(const BlockData& data);
77 void endBlock(const BlockData& data);
78 void addDictionary(const StringView& dictionary_name, const CADDictionaryObject& dictionary);
79 void startEntities();
80 void writeObjects();
81 void writeDictionaries();
82 void writeViewStyleObject();
83 void writeReactors(uint04 dictionary_handle);
84 void writeVariableValue(const CADVariable& variable);
85 void finish();
86 static bool getFileLine(String& s, std::ifstream& in, bool stripSpace = true);
87 void writeAttributesFast(const EntityData& data);
88 bool addColorInfo(const CADColorInfo& data, bool is_off = false);
89 void writeLabel(uint02 value_index);
90 void writeInteger(uint02 value_index);
91 void writeIntegerL(uint04 value_index);
92 void writeIntegerL(sint04 value_index);
93 void writeIntegerS(uint01 value_index);
94 void writeInteger(sint02 value_index);
95 void writeDouble(fltp08 value_index);
96 void writeValue(uint02 value_index, const String& value);
97 void writeHandle(uint02 value_index, const uint04& value);
98 void writeValue(uint02 value_index, const char* const value);
99 void writeValue(uint02 value_index, uint04 value);
100 void writeValueL(uint02 value_index, sint04 value);
101 void writeValueL(uint02 value_index, uint04 value);
102 void writeValueS(uint02 value_index, uint01 value);
103 void writeValue(uint02 value_index, sint04 value);
104 void writeValue(uint02 value_index, fltp08 value);
105 void writeValue(uint02 value_index, fltp04 value);
106 void writeDictionary(const CADDictionaryObject& data);
107 void writeValue(uint02 value_index, const Vector<3, fltp08>& value);
108 void writeViewports(Buffer<ViewportData> cameras);
109 void writeVPortTableEntree(const ViewportData& data);
110 void startLayers(uint04 max_layer_count);
111 void addLayer(const LayerData& data);
112 void addPoint(const PointData& point);
113 void addAttribute(const Attrib& attrib);
114 void startFastPoints();
115 void addFastPoint(const PointData& face);
116 void endFastPoints();
117
118 void addLine(const LineData& line);
119 void addXLine(const LineSegment<3, fltp08>& line);
120 void addRay(const LineSegment<3, fltp08>& line);
121 void addMesh(const CADMeshData& data);
122
123 void addPolyline(const PolylineData& data);
124 void addPolyline(const PolylineData& data, const Polyline<3, fltp08>& poly);
125 void addPolyline(const Polyline<3, fltp08>& poly);
126 void addVertex(const Vector<3, fltp08>& point);
127
128 void addSpline();
129
130 void addArc();
131 void addCircle();
132 void addEllipse();
133 void addInsert(const BlockInsert& insert);
134
135 void cleanupCADName(String& name);
136
137 void addTrace(bool is_solid, const TraceData& face);
138 void add3dFace(bool is_solid, const Triangle<3, fltp08>& tri);
139 void add3dFace(bool is_solid, const TraceData& face);
140 //Use this when writing many 3D faces
141 void startFast3DFaces(bool is_solid);
142 void addFast3dFace(bool is_solid, const TraceData& face);
143 void endFast3DFaces();
144 Buffer<BlockData> defaultBlocks();
145
146 void addText(const TextData& data);
147 void addMText(const TextData& data);
148 uint04 generateTempHandleIndex();
149 uint04 getHandleIndex(const StringView& handle_name);
150 void addAttribute();
151
152 void addDimLinear();
153 void addDimAligned(const DimAlignedData& alignment);
154 void addDimRadial();
155 void addDimDiametric();
156 void addDimAngular();
157 void addDimAngular3P();
158 void addDimOrdinate();
159
160 /*void addLeader();
161
162 void addHatch();
163 void addHatchLoop();
164 void addHatchEdge();
165 bool handleHatchData();
166
167 void addImage();*/
168 void addImageDef();
169 void addMaterialObject(const DXFMaterial& material);
170 void setBinary(bool is_binary) { m_is_binary = is_binary; }
171 bool handleMTextData();
172 bool handleLWPolylineData();
173 bool handleLinetypeData();
174 void endEntity();
175 void setDecimalPlaces(uint04 decimals) { m_decimal_places = decimals; }
176 void endSequence();
177 XDataWriter createVertexXData(uint02 start_offset, const Buffer<Vertex<3, fltp08>>& vertices);
178 XDataWriter createVertexXData(uint02 start_offset, const Buffer<RGBColor>& vertices);
179 bool writePointers() const { return m_write_pointers; }
180 private:
181 void writeDimensionData(const DimensionData& data);
182 void writeCache();
183 enum VertexMode
184 {
185 e_polyline
186 , e_3D_mesh
187 };
188 DynamicPointer<CADHandleManager> m_handle_manager;
189 uint04 m_current_line;
190 String m_polyline_layer;
191 Buffer<Vector<4, fltp08>> m_vertices;
192 //bool m_x_recordValues;
193 VertexMode m_vertex_mode;
194 String m_group_code_tmp;
195 uint04 m_group_code;
196 String m_group_value;
197 // Value of the current setting
198 String m_setting_value;
199 // Key of the current setting (e.g. "$ACADVER")
200 String m_setting_key;
201 // app specific dictionary handle:
202 //uint08 m_dictionary_handle;
203 // handle of standard text style, referenced by dimstyle:
204 //uint08 m_style_handle;
205 std::ofstream m_out;
206 File m_target_out;
207 String m_fast_data;
208 String m_cache;
209 uint04 m_cache_size;
210
211 bool m_write_pointers = true;
212 bool m_write_parent_pointers = true;
213 bool m_write_classes = true;
214 bool m_write_general_view_style = true;
215 bool m_write_viewports = true;
216 bool m_write_dim_style = true;
217 bool m_has_block_data = false;
218 bool m_is_binary = false;
219 //uint04 m_decimal_places = Constant<uint04>::Invalid;
220 uint04 m_decimal_places = 4;
221 DXFVersion m_version = DXFVersion::e_AC1021;
222 Buffer<CADDictionaryObject> m_dictionary_objects;
223 Dictionary<String, CADDictionaryObject> m_named_dictionary_objects;
224 Buffer<XDataWriter> m_xdata_objects;
225 };
226}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Handles converting NDEVR API UUID objects into CAD HANDLE IDs.
DXF streams store data in a large numbered index structure.
Handles writing data to a CAD entity stream.
Definition DXFWriter.h:60
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
Class: LineSegment.
Definition Line.hpp:52
A sequence of connected line segments defined by ordered vertices along a path.
Definition PolyLine.hpp:55
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
A three-vertex polygon representing a triangle in N-dimensional space.
Definition Triangle.hpp:142
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
Stores extended data (XData) that can be written out as part of a DXF entity, using a custom write fu...
Definition DXFWriter.h:52
std::function< void(DXFWriter &dxf)> write_function
The function that writes the XData content.
Definition DXFWriter.h:54
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
int16_t sint02
-Defines an alias representing a 2 byte, signed integer.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
DXFVersion
Versions of the DXF we support writing out.
Definition EntityCodes.h:40
@ file
The source file path associated with this object.
@ name
The display name of the object.
Logic for storing attribute data in a CAD-friendly way for exporting and importing.
A block structure (Similar to a Model) used to share data with CAD.
Information for how to place a CAD block within a scene (Similar to Model).
Stores color information for interfacing with CAD.
Definition CADEntities.h:77
A container for information pointing to a CAD dictionary in CAD memory.
Stores mesh data in a way optimized for CAD.
A variable shared between NDEVR and CAD.
Definition CADEntities.h:94
A DXF friendly material class which contains UV properties similar to a Material object.
A CAD measurement similar to AngleMeasurementModel.
Dimensional measurements stored in a CAD-friendly way.
An entity in CAD which has a layer and other handle information.
A handle used to reference an object in CAD.
Layer information shared with CAD.
A CAD-friendly way to store line segment information.
Point data stored in a friendly way for interfacing with CAD.
logic for storing a polyline data in a CAD-friendly way for exporting and importing.
logic for storing a text data in a CAD-friendly way for exporting and importing.
logic for storing a trace data in a CAD-friendly way for exporting and importing.
logic for storing a viewport in a CAD-friendly way for exporting and importing.