NDEVR
API Documentation
EntityConverter.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: EntityConverter
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "../Headers/CADEntityStreamer.h"
34#include "../Headers/CADHandleManager.h"
35#include "../Headers/DXFValueManager.h"
36#include "../Headers/EntityCodes.h"
37#include <NDEVR/DesignObjectLookup.h>
38#include <NDEVR/Geometry.h>
39#include <NDEVR/Model.h>
40#include <NDEVR/ArcShape.h>
41#include <NDEVR/ShapeConstructors.h>
42#include <NDEVR/Text.h>
43#include <NDEVR/MatrixFunctions.h>
44#include <NDEVR/FactoryOptions.h>
45#include <NDEVR/RWLock.h>
46#include <NDEVR/ACIColor.h>
47#include <NDEVR/Translator.h>
48#include <NDEVR/UnitDefinitions.h>
49namespace NDEVR
50{
55 {
56 switch (cad_unit)
57 {
58 case 0: return ConstPointer<Unit>();//No units
59 case 1: return UnitDefinitions::Inches(); break;
60 case 2: return UnitDefinitions::Feet(); break;
61#if NDEVR_EXOTIC_UNITS
62 case 3: return UnitDefinitions::InternationalMiles(); break;
63 case 8: return UnitDefinitions::Microinches(); break;
64 case 9: return UnitDefinitions::Mils(); break;
65 case 11: return UnitDefinitions::Angstrom(); break;
66 case 12: return UnitDefinitions::Nanometers(); break;
67 case 13: return UnitDefinitions::Microns(); break;
68 case 14: return UnitDefinitions::Decimeters(); break;
69 case 15: return UnitDefinitions::Dekameters(); break;
70 case 16: return UnitDefinitions::Hectometers(); break;
71 case 17: return UnitDefinitions::Gigameters(); break;
72 case 18: return UnitDefinitions::AstronomicalUnits(); break;
73 case 19: return UnitDefinitions::LightYears(); break;
74 case 20: return UnitDefinitions::Parsecs(); break;
75#endif
76 case 4: return UnitDefinitions::Millimeters(); break;
77 case 5: return UnitDefinitions::Centimeters(); break;
78 case 6: return UnitDefinitions::Meters(); break;
79 case 7: return UnitDefinitions::Kilometers(); break;
80 case 10: return UnitDefinitions::Yards(); break;
81
82 default: lib_assert(false, "Unknown unit"); return ConstPointer<Unit>();
83 }
84 }
85 /*static uint04 ConvertToCADUnit(const ConstPointer<Unit>& cad_unit)
86 {
87 switch (cad_unit->name.hashLower())
88 {
89 default: return 0;
90 case String::hash("inches"): return 1;
91 case String::hash("feet"): return 2;
92 case String::hash("international miles"): return 3;
93 case String::hash("millimeters"): return 4;
94 case String::hash("centimeters"): return 5;
95 case String::hash("meters"): return 6;
96 case String::hash("kilometers"): return 7;
97 case String::hash("microinches"): return 8;
98 case String::hash("mils"): return 9;
99 case String::hash("yards"): return 10;
100 case String::hash("angstroms"): return 11;
101 case String::hash("nanometers"): return 12;
102 case String::hash("microns"): return 13;
103 case String::hash("decimeters"): return 14;
104 case String::hash("dekameters"): return 15;
105 case String::hash("hectometers"): return 16;
106 case String::hash("gigameters"): return 17;
107 case String::hash("astronomical_units"): return 18;
108 case String::hash("light_years"): return 19;
109 case String::hash("parsecs"): return 20;
110 }
111 }*/
138 class CADMeshVertexAttributeSetter;
139 class CADMeshVertexColorSetter;
144 class EntityConverter : public CADEntityStreamer
145 {
146 public:
147 EntityConverter(const File& relative_path, DesignObjectLookup* lookup, ProgressInfo& logger);
148 virtual ~EntityConverter();
149 void setHandleManager(const DynamicPointer<CADHandleManager>& handle_manager);
150 void setupEntityMaterial(Model model);
151 void endFaceSection();
152 void endSection() final override;
153 const ConstPointer<Unit>& unit() const;
154 Material getMaterial();
155 void addLayer(const LayerData& layer) final override;
156 Scene paperRoot();
157 Scene viewportRoot();
158 String convertFromCADName(const String& file_name, const TranslatedString& object_type, uint04 object_count);
159 void addDictionary(const CADDictionaryObject& dictionary) override;
160 void addXRecord(const HandleData& record) override;
161 void addXRecordData(uint04 value, DXFValueManager* value_manager) override;
162 void addDXFMaterial(DXFMaterial& mat) override;
163 Model getLayer(const String& layer_name);
164 Material generateNewMaterial();
165 Material getMaterial(const uint04& material_handle);
166 virtual void addLinetype(const LineTypeData&) override;
167 virtual void addLinetypeDash(double) override;
168 Model getBlockModel(const String& block_name);
169 void copyBlock(Model& model, Model& block);
170 virtual void addGroup(const DXFGroup& group_info) override;
171 virtual void addBlock(const BlockData& block_info) override;
172 virtual void addViewport(const ViewportData& block_info) override;
173 virtual void endBlock(const uint04&) override;
174 void setupColorForGeoVertices();
175 virtual void addTextStyle(const StyleData& text_style) override;
176 virtual void addPoint(const PointData& point) override;
177 void addLine(const LineData& line) override;
178 void addXLine(const LineData& line) override;
179 void addRay(const LineData& ray) override;
180 virtual void addTrace(const TraceData& data) override;
181 virtual void add3dFace(const TraceData& data) override;
182 void addArc(const ArcData& arc) override;
183#if NDEVR_TEXT_MODEL
184 void addAttribute(const Attrib& attribute) override;
185 void addAttributeDefinition(const Attrib& attribute) override;
186 Text createFromTextData(const TextData& data, bool is_m_text);
187 virtual void addText(const TextData& data) override;
188#endif
189 void addCircle(const CircleData& c) override;
190 virtual void addEllipse(const EllipseData& e) override;
191 virtual void addPolyline(const PolylineData& poly) override;
192 virtual void addMesh(CADMeshData& mesh_data) override;
193 virtual void addVertex(const Vector<4, fltp08>& vertex) override;
194 virtual void addIndex(const Vector<4, sint04>& vertex) override;
195 virtual void addInsert(const BlockInsert& data) override;
196 virtual void addSpline(const SplineData&) override;
197 #if NDEVR_VIEWPORT && NDEVR_MEASURE_MODELS
198 void addDimAlign(const DimAlignedData& dimension) override;
199 void addDimLinear(const LinearDimension& dimension) override;
200 #endif
201 void addDimRadial(const RadialDimension&) override;
202 void addDimDiametric(const DiametricDimension&) override;
203 void addDimAngular(const AngularDimensionData<3>&) override;
204 void addDimAngular(const AngularDimensionData<4>&) override;
205 void addDimOrdinate(const DimOrdinateData&) override;
206 virtual void addLeader(const LeaderData& data) override;
207 virtual void addComment(const StringView& comment) override;
208 #if NDEVR_TEXT_MODEL
209 void setupTextData(Text& text, const TextData& data, const Font& default_font, bool is_m_text);
210 #endif
211 virtual void endEntity() override;
212 void setAttributes(const DXFAttributes&) override;
213 void setExtrusion(fltp08 dx, fltp08 dy, fltp08 dz, fltp08 elevation) override;
214 Extrusion& getExtrusion();
215 Buffer<Model> modelRoots() const;
216 Scene currentRoot();
217 Model currentBlock();
218 Buffer<TextBlock> parseString(const String& text, fltp08 default_height, const Font& start_font, bool is_m_text);
219 void addBulge(Geometry& geo, fltp08 bulge, const Vertex<3, fltp08>& p1, const Vertex<3, fltp08>& p2);
220 Geometry createGeometry(Model model = Model());
221 Model currentEntity();
222 void setVariableInt(const StringView& label, int value, int key_label) override;
223 Model& currentLinework();
224 Geometry& currentLineworkGeo();
225 Geometry& currentTriMesh();
226 Geometry& currentPolyMesh();
227 Model& currentPoint();
228 Geometry& currentCloudGeo();
229 const Buffer<UUID>& pointsRead() const;
230 const Buffer<UUID>& lineworkRead() const;
231 const Buffer<UUID>& meshesRead() const;
232
233 static Matrix<fltp08> GetOrientation(const Vector<3, fltp08>& extrusion);
234 public:
235 void setGroupImport(bool group_import);
236 void setTextFacingCamera(bool text_face_camera);
237 void setAutoNameObjects(bool auto_name_objects);
238 void setPointMode(NDEVRFilePointMode mode);
239 void setLineMode(DXFLineMode mode);
240 void setIgnoreKnownBlocks(bool ignore_known_blocks);
241 void setIgnoreKnownMaterials(bool ignore_known_materials);
242 [[nodiscard]] Buffer<UUID> getAllReadEntities() const;
243 private:
244 void _addLayer(const LayerData& layer_data);
245 void setupLayer(Model& model);
246 #if NDEVR_TEXT_MODEL
247 void getFont(const StringView& font_name, Font& font);
248 #endif
249 private:
250 enum DXFMode
251 {
252 e_none
253 , e_points
254 , e_polyline
255 , e_leader
256 , e_line
257 , e_closed_polyline
258 , e_polyface
259 , e_3D_face
260 , e_3D_trace
261 , e_measurement
262 };
263 #if NDEVR_TEXT_MODEL
264 Dictionary<String, Font> m_loaded_fonts;
265 #endif
267 Dictionary<String, UUID> m_point_name_data;
269 Dictionary<String, StyleData> m_text_styles;
271 Dictionary<String, Buffer<Model>> m_blocks_to_insert;
272 Dictionary<UUID, String> m_child_blocks_to_insert;
274 Vector<7, Geometry> m_measure_markers;
275 Dictionary<uint04, UUID> m_mesh_object_dictionary_listeners;
276 Dictionary<uint04, std::pair<UUID, VertexProperty>> m_mesh_object_field_listeners;
277 Dictionary<uint04, std::pair<UUID, VertexProperty>> m_mesh_object_color_listeners;
278 String m_current_block_name;
279 String m_last_x_data_label;
280 File m_relative_path;
281 ConstPointer<Unit> m_unit;
282 EntityData m_current_data;
283 Buffer<Vertex<3, fltp08>> m_quad_position_data;
284 Buffer<Vertex<3, fltp08>> m_tri_position_data;
285 Buffer<RGBColor> m_quad_color_data;
286 Buffer<RGBColor> m_tri_color_data;
287 Buffer<UUID> m_model_roots;
288 Buffer<UUID> m_linework_read;
289 Buffer<UUID> m_points_read;
290 Buffer<UUID> m_meshes_read;
291 Buffer<UUID> m_blocks_read;
292 Buffer<UUID> m_materials_read;
293 UUID m_core_root = Constant<UUID>::Invalid;
294 UUID m_current_paper_root = Constant<UUID>::Invalid;
295 UUID m_current_viewport_root = Constant<UUID>::Invalid;
296 UUID m_blocks_root = Constant<UUID>::Invalid;
297 UUID m_current_block = Constant<UUID>::Invalid;
298 UUID m_current_entity = Constant<UUID>::Invalid;
299 UUID m_current_material = Constant<UUID>::Invalid;
300 UUID m_last_insert = Constant<UUID>::Invalid;
301 Geometry m_current_geometry;
302 Model m_current_linework;
303 Geometry m_current_linework_geo;
304 Geometry m_current_mesh;
305 Geometry m_current_points;
306 Model m_current_point;
307 NDEVRFilePointMode m_point_mode = NDEVRFilePointMode::e_point;
308 DXFLineMode m_line_mode = DXFLineMode::e_line;
309 DynamicPointer<CADHandleManager> m_handle_manager;
310 DesignObjectLookup* m_model_lookup = nullptr;
311 CADMeshVertexAttributeSetter* m_mesh_attribute_setter = nullptr;
312 CADMeshVertexColorSetter* m_mesh_color_setter = nullptr;
313
314 Vertex<3, fltp08> m_position_offset = Constant<Vertex<3, fltp08>>::Invalid;
315 std::function<void(uint04 value, DXFValueManager* manager)> m_xdata_callback;
316 fltp08 m_next_bulge = Constant<fltp08>::Invalid;
317 uint04 m_circle_count = 0U;
318 uint04 m_ellipse_count = 0U;
319 uint04 m_insert_count = 0U;
320 uint04 m_attribute_count = 0U;
321 DimensionOptions m_dim_options;
322 DXFMode m_current_mode = DXFMode::e_none;
323 bool m_color_by_vertex = false;
324 bool m_group_import = true;
325 bool m_text_face_camera = false;
326 bool m_auto_name_objects = true;
327 bool m_ignore_known_blocks = true;
328 bool m_ignore_known_materials = false;
329 bool m_ignore_current = false;//when true, ignores any information
330 };
331}
332
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
DXF Style attributes that can be applied to CAD Entity objects.
DXF streams store data in a large numbered index structure.
A core class where all Design Objects including models, materials, and geometries are stored.
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 storing a extrusion data in a CAD-friendly way for exporting and importing.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
Information for how to display text data.
Definition Font.h:46
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
Container responsible for storing and setting the appearance of a Model or Geometry within the NDEVR ...
Definition Material.h:153
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
Used with InfoPipe to signal that the system will be using progress.
The root Model that is responsible for storing the underlying data for all Scene Models.
Definition Scene.h:52
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
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
static const ConstPointer< Unit > & Feet()
Gets the unit definition for feet.
static const ConstPointer< Unit > & Meters()
Gets the unit definition for meters.
static const ConstPointer< Unit > & Kilometers()
Gets the unit definition for kilometers.
static const ConstPointer< Unit > & Millimeters()
Gets the unit definition for millimeters.
static const ConstPointer< Unit > & Degrees()
Angle Units.
static const ConstPointer< Unit > & Centimeters()
Gets the unit definition for centimeters.
static const ConstPointer< Unit > & Yards()
Gets the unit definition for yards.
static const ConstPointer< Unit > & Inches()
Gets the unit definition for inches.
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
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
static ConstPointer< Unit > ConvertFromCADUnit(uint04 cad_unit)
Converts from a given CAD index unit.
double fltp08
Defines an alias representing an 8 byte floating-point number.
logic for storing an angular dimension in a CAD-friendly way for exporting and importing.
logic for storing a arc data in a CAD-friendly way for exporting and importing.
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).
A container for information pointing to a CAD dictionary in CAD memory.
Stores mesh data in a way optimized for CAD.
logic for storing a circle data in a CAD-friendly way for exporting and importing.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
A type of entity in CAD representing several entities grouped together.
A DXF friendly material class which contains UV properties similar to a Material object.
logic for storing an diametric dimension in a CAD-friendly way for exporting and importing.
A CAD measurement similar to AngleMeasurementModel.
logic for storing an ordinate dimension in a CAD-friendly way for exporting and importing.
Options for CAD dimension objects.
fltp08 dimension_scale_factor
Overall scale factor for dimensions.
ConstPointer< Unit > angle_unit
The unit used for angular dimensions.
ConstPointer< Unit > distance_unit
The unit used for distance dimensions.
String arrow_block_name
Name of the block used for dimension arrows.
uint04 angle_min_decimals
Minimum decimal places for angle display.
DimensionMode
Display modes for CAD dimension text.
@ e_fractional_stacked
Stacked fractional format.
@ e_ngineering
Engineering notation.
@ e_architectural_stacked
Stacked architectural format.
@ e_decimal
Decimal notation.
@ e_architectural
Architectural format.
@ e_fractional
Fractional format.
@ e_scientific
Scientific notation.
DimensionMode display_mode
The dimension text display mode.
char decimal_seperator
The decimal separator character.
fltp08 arrow_size
Arrow size for dimension lines.
Stores Ellipse information for interfacing with CAD.
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.
logic for storing a leader in a CAD-friendly way for exporting and importing.
A CAD-friendly way to store line segment information.
information for a type of line in CAD
A CAD measurement similar to DistanceMeasurementModel.
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 radial dimension in a CAD-friendly way for exporting and importing.
logic for storing a spline data in a CAD-friendly way for exporting and importing.
logic for storing a style 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.