API Documentation
Loading...
Searching...
No Matches
EntityConverter.h
Go to the documentation of this file.
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: EntityConverter
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
42#include "Design/Headers/Text.h"
44#include "Base/Headers/RWLock.h"
48namespace NDEVR
49{
50 /**--------------------------------------------------------------------------------------------------
51 \brief Converts from a given CAD index unit.
52 **/
53 static ConstPointer<Unit> ConvertFromCADUnit(uint04 cad_unit)
54 {
55 switch (cad_unit)
56 {
57 case 0: return ConstPointer<Unit>();//No units
58 case 1: return UnitDefinitions::Inches(); break;
59 case 2: return UnitDefinitions::Feet(); break;
60#if NDEVR_EXOTIC_UNITS
61 case 3: return UnitDefinitions::InternationalMiles(); break;
62 case 8: return UnitDefinitions::Microinches(); break;
63 case 9: return UnitDefinitions::Mils(); break;
64 case 11: return UnitDefinitions::Angstrom(); break;
65 case 12: return UnitDefinitions::Nanometers(); break;
66 case 13: return UnitDefinitions::Microns(); break;
67 case 14: return UnitDefinitions::Decimeters(); break;
68 case 15: return UnitDefinitions::Dekameters(); break;
69 case 16: return UnitDefinitions::Hectometers(); break;
70 case 17: return UnitDefinitions::Gigameters(); break;
71 case 18: return UnitDefinitions::AstronomicalUnits(); break;
72 case 19: return UnitDefinitions::LightYears(); break;
73 case 20: return UnitDefinitions::Parsecs(); break;
74#endif
75 case 4: return UnitDefinitions::Millimeters(); break;
76 case 5: return UnitDefinitions::Centimeters(); break;
77 case 6: return UnitDefinitions::Meters(); break;
78 case 7: return UnitDefinitions::Kilometers(); break;
79 case 10: return UnitDefinitions::Yards(); break;
80
81 default: lib_assert(false, "Unknown unit"); return ConstPointer<Unit>();
82 }
83 }
84 /*static uint04 ConvertToCADUnit(const ConstPointer<Unit>& cad_unit)
85 {
86 switch (cad_unit->name.hashLower())
87 {
88 default: return 0;
89 case String::hash("inches"): return 1;
90 case String::hash("feet"): return 2;
91 case String::hash("international miles"): return 3;
92 case String::hash("millimeters"): return 4;
93 case String::hash("centimeters"): return 5;
94 case String::hash("meters"): return 6;
95 case String::hash("kilometers"): return 7;
96 case String::hash("microinches"): return 8;
97 case String::hash("mils"): return 9;
98 case String::hash("yards"): return 10;
99 case String::hash("angstroms"): return 11;
100 case String::hash("nanometers"): return 12;
101 case String::hash("microns"): return 13;
102 case String::hash("decimeters"): return 14;
103 case String::hash("dekameters"): return 15;
104 case String::hash("hectometers"): return 16;
105 case String::hash("gigameters"): return 17;
106 case String::hash("astronomical_units"): return 18;
107 case String::hash("light_years"): return 19;
108 case String::hash("parsecs"): return 20;
109 }
110 }*/
111 /**--------------------------------------------------------------------------------------------------
112 \brief Options for CAD dimension objects.
113 **/
136 class CADMeshVertexAttributeSetter;
137 class CADMeshVertexColorSetter;
138 /**--------------------------------------------------------------------------------------------------
139 \brief Primary class responsible for converting CAD entities into native CAD entities. If specified
140 can merge UUID structures based on modified time.
141 **/
143 {
144 public:
145 EntityConverter(const File& relative_path, DesignObjectLookup* lookup, ProgressInfo* logger);
150 void endSection() final override;
151 const ConstPointer<Unit>& unit() const;
153 void addLayer(const LayerData& layer) final override;
155 String convertFromCADName(const String& file_name, const TranslatedString& object_type, uint04 object_count);
156 void addDictionary(const CADDictionaryObject& dictionary) override;
157 void addXRecord(const HandleData& record) override;
158 void addXRecordData(uint04 value, DXFValueManager* value_manager) override;
159 void addDXFMaterial(DXFMaterial& mat) override;
160 Model getLayer(const String& layer_name);
162 Material getMaterial(const uint04& material_handle);
163 virtual void addLinetype(const LineTypeData&) override;
164 virtual void addLinetypeDash(double) override;
165 Model getBlockModel(const String& block_name);
166 void copyBlock(Model& model, Model& block);
167 virtual void addGroup(const DXFGroup& group_info) override;
168 virtual void addBlock(const BlockData& block_info) override;
169 virtual void endBlock(const uint04&) override;
171 virtual void addTextStyle(const StyleData& text_style) override;
172 virtual void addPoint(const PointData& point) override;
173 void addLine(const LineData& line) override;
174 void addXLine(const LineData& line) override;
175 void addRay(const LineData& ray) override;
176 virtual void addTrace(const TraceData& data) override;
177 virtual void add3dFace(const TraceData& data) override;
178 void addArc(const ArcData& arc) override;
179#if NDEVR_TEXT_MODEL
180 void addAttribute(const Attrib& attribute) override;
181 void addAttributeDefintion(const Attrib& attribute) override;
182 Text createFromTextData(const TextData& data);
183 virtual void addText(const TextData& data) override;
184#endif
185 void addCircle(const CircleData& c) override;
186 virtual void addEllipse(const EllipseData& e) override;
187 virtual void addPolyline(const PolylineData& poly) override;
188 virtual void addMesh(CADMeshData& mesh_data) override;
189 virtual void addVertex(const Vector<4, fltp08>& vertex) override;
190 virtual void addIndex(const Vector<4, sint04>& vertex) override;
191 virtual void addInsert(const BlockInsert& data) override;
192 virtual void addSpline(const SplineData&) override;
193 #if NDEVR_VIEWPORT && NDEVR_MEASURE_MODELS
194 void addDimAlign(const DimAlignedData& dimension) override;
195 void addDimLinear(const LinearDimension& dimension) override;
196 #endif
197 void addDimRadial(const RadialDimension&) override;
198 void addDimDiametric(const DiametricDimension&) override;
201 void addDimOrdinate(const DimOrdinateData&) override;
202 virtual void addLeader(const LeaderData& data) override;
203 virtual void addComment(const String& comment) override;
204 #if NDEVR_TEXT_MODEL
205 void setupTextData(Text& text, const TextData& data);
206 #endif
207 virtual void endEntity() override;
208 void setAttributes(const DXFAttributes&) override;
209 void setExtrusion(fltp08 dx, fltp08 dy, fltp08 dz, fltp08 elevation) override;
214 Buffer<TextBlock> parseString(const String& text, fltp08 default_height);
215 void addBulge(Geometry& geo, fltp08 bulge, const Vertex<3, fltp08>& p1, const Vertex<3, fltp08>& p2);
218 void setVariableInt(const String& label, int value, int key_label) override;
223 const Buffer<UUID>& pointsRead() const;
225 const Buffer<UUID>& meshesRead() const;
226
228 public:
229 void setGroupImport(bool group_import);
230 void setTextFacingCamera(bool text_face_camera);
231 void setAutoNameObjects(bool auto_name_objects);
232 void setIgnoreKnownBlocks(bool ignore_known_blocks);
233 [[nodiscard]] Buffer<UUID> getAllReadEntities() const;
234 private:
235 void _addLayer(const LayerData& layer_data);
236 void setupLayer(Model& model);
237 #if NDEVR_TEXT_MODEL
238 DynamicPointer<TextConstructor> getTextContructor(const String& font_name, const Font& font);
239 DynamicPointer<TextConstructor> getTextContructor(const String& font);
240 #endif
241 private:
242 enum DXFMode
243 {
244 e_none
245 , e_points
246 , e_polyline
247 , e_leader
248 , e_line
249 , e_closed_polyline
250 , e_polyface
251 , e_3D_face
252 , e_3D_trace
253 , e_measurement
254 };
255 #if NDEVR_TEXT_MODEL
257 #endif
260 Dictionary<String, UUID> m_point_name_data;
261 String m_last_x_data_label;
262 Dictionary<uint04, UUID> m_mesh_object_dictionary_listeners;
263 Dictionary<uint04, std::pair<UUID, VertexProperty>> m_mesh_object_field_listeners;
264 Dictionary<uint04, std::pair<UUID, VertexProperty>> m_mesh_object_color_listeners;
265 String m_current_block_name;
266 ConstPointer<Unit> m_unit;
267 EntityData m_current_data;
268 Buffer<Vertex<3, fltp08>> m_quad_position_data;
269 Buffer<Vertex<3, fltp08>> m_tri_position_data;
270 Buffer<RGBColor> m_quad_color_data;
271 Buffer<RGBColor> m_tri_color_data;
273 Buffer<UUID> m_model_roots;
274 UUID m_core_root;
275 UUID m_current_paper_root;
276 UUID m_blocks_root;
277 UUID m_current_block;
278 UUID m_current_entity;
279 UUID m_last_insert;
280 Geometry m_current_geometry;
281 Geometry m_current_linework;
282 Geometry m_current_mesh;
283 Geometry m_current_points;
284 UUID m_current_material;
285 Buffer<UUID> m_linework_read;
286 Buffer<UUID> m_points_read;
287 Buffer<UUID> m_meshes_read;
288 Buffer<UUID> m_blocks_read;
289 Buffer<UUID> m_materials_read;
290 fltp08 m_next_bulge;
291
292 DynamicPointer<CADHandleManager> m_handle_manager;
293 Dictionary<String, StyleData> m_text_styles;
295 Dictionary<String, Buffer<Model>> m_blocks_to_insert;
296 Dictionary<UUID, String> m_child_blocks_to_insert;
297 DesignObjectLookup* m_model_lookup;
298 DXFMode m_current_mode;
299 bool m_read_paper_space = false;
300 bool m_color_by_vertex = false;
301 bool m_group_import = true;
302 bool m_text_face_camera = false;
303 bool m_auto_name_objects = true;
304 bool m_ignore_known_blocks = true;
305 bool m_ignore_known_materials = true;
306 bool m_ignore_current = false;//when true, ignores any information
308 std::function<void(uint04 value, DXFValueManager* manager)> m_xdata_callback;
309 uint04 m_circle_count = 0;
310 uint04 m_ellipse_count = 0;
311 uint04 m_insert_count = 0;
312 uint04 m_attribute_count = 0;
313 CADMeshVertexAttributeSetter* m_mesh_attribute_setter = nullptr;
314 CADMeshVertexColorSetter* m_mesh_color_setter = nullptr;
315 File m_relative_path;
316 DimensionOptions m_dim_options;
317 };
318}
319
#define lib_assert(expression, message)
Definition LibAssert.h:61
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A base-class for streaming out CAD entities from a file or CAD program memory.
Definition CADEntityStreamer.h:45
virtual void addDimAlign(const DimAlignedData &)
Definition CADEntityStreamer.h:85
virtual void addDimLinear(const LinearDimension &)
Definition CADEntityStreamer.h:86
virtual void addAttribute(const Attrib &)
Definition CADEntityStreamer.h:66
virtual void addText(const TextData &)
Definition CADEntityStreamer.h:84
virtual void addAttributeDefintion(const Attrib &)
Definition CADEntityStreamer.h:67
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition GraphicsPipeline.h:42
DXF Style attributes that can be applied to CAD Entity objects.
Definition DXFAttributes.h:42
DXF streams store data in a large numbered index structure. This class optimally stores this data so ...
Definition DXFValueManager.h:46
A core class where all Design Objects including models, materials, and geometries are stored....
Definition DesignObjectLookup.h:65
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
Primary class responsible for converting CAD entities into native CAD entities. If specified can merg...
Definition EntityConverter.h:143
void addDictionary(const CADDictionaryObject &dictionary) override
const Buffer< UUID > & lineworkRead() const
virtual void addIndex(const Vector< 4, sint04 > &vertex) override
EntityConverter(const File &relative_path, DesignObjectLookup *lookup, ProgressInfo *logger)
Geometry & currentTriMesh()
virtual void addLinetypeDash(double) override
void addDXFMaterial(DXFMaterial &mat) override
Buffer< UUID > getAllReadEntities() const
void addLayer(const LayerData &layer) final override
void setGroupImport(bool group_import)
virtual void endBlock(const uint04 &) override
Geometry & currentPolyMesh()
const ConstPointer< Unit > & unit() const
void setVariableInt(const String &label, int value, int key_label) override
Geometry currentLinework()
void setExtrusion(fltp08 dx, fltp08 dy, fltp08 dz, fltp08 elevation) override
void setupEntityMaterial(Model model)
void copyBlock(Model &model, Model &block)
virtual void addSpline(const SplineData &) override
void addXRecord(const HandleData &record) override
void setHandleManager(const DynamicPointer< CADHandleManager > &handle_manager)
virtual void addGroup(const DXFGroup &group_info) override
void addBulge(Geometry &geo, fltp08 bulge, const Vertex< 3, fltp08 > &p1, const Vertex< 3, fltp08 > &p2)
Buffer< TextBlock > parseString(const String &text, fltp08 default_height)
Buffer< Model > modelRoots() const
void addXRecordData(uint04 value, DXFValueManager *value_manager) override
virtual void addBlock(const BlockData &block_info) override
virtual void addTextStyle(const StyleData &text_style) override
void addXLine(const LineData &line) override
virtual void add3dFace(const TraceData &data) override
void setAutoNameObjects(bool auto_name_objects)
void addLine(const LineData &line) override
Extrusion & getExtrusion()
Model getLayer(const String &layer_name)
void setIgnoreKnownBlocks(bool ignore_known_blocks)
void addRay(const LineData &ray) override
void addDimRadial(const RadialDimension &) override
virtual void addPolyline(const PolylineData &poly) override
virtual void addLeader(const LeaderData &data) override
virtual void addLinetype(const LineTypeData &) override
void addDimDiametric(const DiametricDimension &) override
void addDimOrdinate(const DimOrdinateData &) override
Model getBlockModel(const String &block_name)
void addCircle(const CircleData &c) override
virtual void addPoint(const PointData &point) override
Material generateNewMaterial()
virtual void addVertex(const Vector< 4, fltp08 > &vertex) override
virtual void addTrace(const TraceData &data) override
void endSection() final override
const Buffer< UUID > & meshesRead() const
virtual void endEntity() override
void addDimAngular(const AngularDimensionData< 3 > &) override
virtual void addComment(const String &comment) override
void setTextFacingCamera(bool text_face_camera)
void addArc(const ArcData &arc) override
virtual void addEllipse(const EllipseData &e) override
const Buffer< UUID > & pointsRead() const
void setAttributes(const DXFAttributes &) override
static Matrix< fltp08 > GetOrientation(const Vector< 3, fltp08 > &extrusion)
void addDimAngular(const AngularDimensionData< 4 > &) override
virtual void addInsert(const BlockInsert &data) override
String convertFromCADName(const String &file_name, const TranslatedString &object_type, uint04 object_count)
virtual void addMesh(CADMeshData &mesh_data) override
logic for storing a extrusion data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:1055
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
A core class within the model heirarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:64
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:51
Definition Matrix.hpp:176
A core class that represents a node on model heirarchy. This node may contain a Geometry or one or mo...
Definition Model.h:58
A light-weight base class for Log that allows processes to update, without the need for additional in...
Definition ProgressInfo.hpp:48
The root Model that is responsible for storing the underlying data for all Scene Models.
Definition Model.h:492
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:60
static ConstPointer< Unit > Inches()
static ConstPointer< Unit > Centimeters()
static ConstPointer< Unit > Millimeters()
static ConstPointer< Unit > Kilometers()
static ConstPointer< Unit > Yards()
static ConstPointer< Unit > Degrees()
Angle Units.
static ConstPointer< Unit > Meters()
static ConstPointer< Unit > Feet()
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
logic for storing an angular dimension in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:657
logic for storing a arc data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:297
logic for storing a attribue data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:470
A block structure (Similar to a Model) used to share data with CAD.
Definition CADEntities.h:196
Information for how to place a CAD block within a scene (Similar to Model).
Definition CADEntities.h:528
A container for information pointing to a CAD dictionary in CAD memory.
Definition CADEntities.h:614
Stores mesh data in a way optimized for CAD.
Definition CADEntities.h:379
logic for storing a circle data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:487
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
A type of entity in CAD representing several entities grouped together.
Definition CADEntities.h:1031
A DXF friendly material class which contains UV properties similar to a Material object.
Definition CADEntities.h:1015
logic for storing an diametric dimension in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:643
A CAD measurement similar to AngleMeasurementModel.
Definition CADEntities.h:589
logic for storing an ordinate dimension in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:680
Options for CAD dimension objects.
Definition EntityConverter.h:115
char decimal_seperator
Definition EntityConverter.h:133
String arrow_block_name
Definition EntityConverter.h:134
ConstPointer< Unit > angle_unit
Definition EntityConverter.h:127
ConstPointer< Unit > distance_unit
Definition EntityConverter.h:129
fltp08 dimension_scale_factor
Definition EntityConverter.h:132
fltp08 arrow_size
Definition EntityConverter.h:131
uint04 angle_min_decimals
Definition EntityConverter.h:128
DimensionMode
Definition EntityConverter.h:117
@ e_decimal
Definition EntityConverter.h:119
@ e_fractional_stacked
Definition EntityConverter.h:122
@ e_fractional
Definition EntityConverter.h:124
@ e_architectural_stacked
Definition EntityConverter.h:121
@ e_ngineering
Definition EntityConverter.h:120
@ e_scientific
Definition EntityConverter.h:118
@ e_architectural
Definition EntityConverter.h:123
DimensionMode display_mode
Definition EntityConverter.h:130
Stores Ellipse information for interfacing with CAD.
Definition CADEntities.h:496
An entity in CAD which has a layer and other handle information.
Definition CADEntities.h:158
Information for how to display text data.
Definition Font.h:46
A handle used to reference an object in CAD.
Definition CADEntities.h:148
Layer information shared with CAD.
Definition CADEntities.h:175
logic for storing a leader in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:696
A CAD-friendly way to store line segment information.
Definition CADEntities.h:509
information for a type of line in CAD
Definition CADEntities.h:218
A CAD measurement similar to DistanceMeasurementModel.
Definition CADEntities.h:600
Point data stored in a friendly way for interfacing with CAD.
Definition CADEntities.h:539
logic for storing a polyline data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:317
logic for storing a radial dimension in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:630
logic for storing a spline data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:362
logic for storing a style data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:245
logic for storing a text data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:451
logic for storing a trace data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:349
A definition of how to describe and display data. Units can be of any type.
Definition Unit.h:36