API Documentation
Loading...
Searching...
No Matches
CADGeometryWriter.h
Go to the documentation of this file.
1#pragma once
13
20namespace NDEVR
21{
22 CADColorInfo GenerateDXFColorInfo(const Model& model, bool is_flat, bool is_vertex)
23 {
24 CADColorInfo data;
25
27 if (!mat.isValid())
28 {
30 return data;
31 }
32 auto mode = mat.getUVMode(UVType::e_KD);
33 if (model.isLayer())
35 switch (mode)
36 {
41 break;
43 if (is_flat || model.hasMaterial(PrimitiveProperty::Solid) || model.isLayer())
44 {
46 if (isNaN(data.color))
48 else
49 data.mode = e_use;
50 }
51 else
52 {
53 data.mode = e_by_block;
54 }
55 break;
57 if (is_flat)
58 {
60 if (isNaN(data.color))
62 else
63 data.mode = e_use;
64 }
65 else
66 {
68 } break;
70 data.color = mat.getUVColor(UVType::e_KD);
71 if(!isNaN(data.color))
72 data.mode = e_use;
73 else
75 break;
79 if (is_vertex)
80 data.mode = e_use;
81 else
83 break;
84 default:
85 lib_assert(false, "Unknown property");
86 }
87 return data;
88
89 }
90 String layerName(const Model& model)
91 {
92 String layer_name;
93 if (model.hasLayer())
94 {
95 Model layer = model.getLayer();
96 layer_name = layer.getProperty<TranslatedString>(Model::e_name).translation();
97 }
98 if (layer_name.size() == 0)
99 {
100 layer_name = "0";
101 /*Material mat = model.getRootMaterial(PrimitiveProperty::Solid);
102 layer_name = mat.getProperty<TranslatedString>(DesignObject::e_name).translation();
103 if (layer_name.size() == 0)
104 layer_name = String(ACIColor(mat.getUVColor(UVType::e_KD)).getIndex());*/
105 }
106 return layer_name;
107 }
108 void FillOutLayerData(const Model& layer, LayerData& data)
109 {
110 //data.handle = String(model.uuid());
111 //data.is_off = !layer.isVisible();
112 data.visible = layer.isVisible();
113 String layer_name = layer.getProperty<TranslatedString>(DesignObject::e_name).translation();
114 data.name = layer_name.size() > 0 ? layer_name : String("0");
115 data.color_info = GenerateDXFColorInfo(layer, true, false);
116 }
117 void FillOutData(const Model& model, EntityData& data)
118 {
119 //data.handle = String(geo.uuid());
120 //data.is_off = !model.isVisible();
121 data.visible = model.isVisible();
122 data.layer = layerName(model);
123 }
124
126 {
139
141 bool has_solid_color = true;
142
151 {
153 if (params.log && shapes_written % 1000 == 0)
154 {
156 throw CancelException(_t("Writing DXF Canceled"));
157 }
158 }
187 {
188 FillOutData(model, data);
190 if(writer.handleManager()->hasHandleIndex(material.uuid()))
191 data.material_handle = writer.handleManager()->getHandleIndex(material.uuid());
194 else
195 data.layer = layer_name;
197 }
199 {
200 PointData data;
201
202 fillOutData(data);
203 //data.thickness = geo.getGeometryProperty<fltp08>(Geometry::e_thickness);
205 data.handle = writer.handleManager()->getHandleIndex(model.uuid());
208 for (uint04 i = 0; i < position_iterator.size(); i++)
209 {
210 Vertex<3, fltp08> point = position_iterator[i];
211 bool filtered = (position_iterator.flag(i)[cast<uint01>(VertexFlags::e_is_filtered)]);
212 if (!isNaN(point) && !filtered)
213 {
214 data.location = transform * point;
215 if (!has_solid_color)
216 data.color_info.color = color_iterator[i];
217 //else stays same as geo color
218 writer.addFastPoint(data);
220 }
222 }
224 }
226 {
227 LineData data;
228 fillOutData(data);
229 FillOutData(model, data);
231 data.handle = writer.handleManager()->getHandleIndex(model.uuid());
234 size--;
235
238
239 for (uint04 i = 0; i < size; i++)
240 {
242 if (isNaN(verts))
243 continue;
244 LineSegment<3, fltp08> seg(position_iterator[verts[A]], position_iterator[verts[B]]);
245 if (!isNaN(seg))
246 {
247 data.line = transform * seg;
248 if (!has_solid_color)
249 {
250
251 data.color_info.color = RGBColor::Average(color_iterator[verts[0]], color_iterator[verts[B]]);
252 }
253 writer.addLine(data);
255 }
257 }
258 }
260 {
261 PolylineData data;
264 fillOutData(data);
266 data.handle = writer.handleManager()->getHandleIndex(model.uuid());
268 for (uint04 i = 0; i < polylines.size(); i++)
269 {
270 writer.addPolyline(data, transform * polylines[i]);
273 }
274 }
276 {
277 LineData data;
278 fillOutData(data);
280 data.handle = writer.handleManager()->getHandleIndex(model.uuid());
283 for (uint04 i = 0; i < tris.size(); i++)
284 {
285 Triangle<3, fltp08> tri = tris[i];
286 if (!isNaN(tri) && abs(tri.area<fltp08>()) > 0.0)
287 {
289 if (!has_solid_color)
290 {
291 Vector<3, uint04> index = tris.vertexIndex(i);
292 color[A] = color_iterator[index[A]];
293 color[B] = color_iterator[index[B]];
294 color[C] = color_iterator[index[C]];
295 }
296 data.line = transform * tri.edge(A, B);
297 if (!has_solid_color)
298 data.color_info.color = RGBColor::Average(color[A], color[B]);
299 writer.addLine(data);
301
302 data.line = transform * tri.edge(B, C);
303 if (!has_solid_color)
304 data.color_info.color = RGBColor::Average(color[B], color[C]);
305 writer.addLine(data);
306
307 data.line = transform * tri.edge(C, A);
308 if (!has_solid_color)
309 data.color_info.color = RGBColor::Average(color[C], color[A]);
310 writer.addLine(data);
311 }
313 }
314 }
316 {
317 TraceData data;
318 fillOutData(data);
320 data.handle = writer.handleManager()->getHandleIndex(model.uuid());
323 for (uint04 i = 0; i < tris.size(); i++)
324 {
325 Triangle<3, fltp08> tri = tris[i];
326 if (!isNaN(tri) && abs(tri.area<fltp08>()) > 0.0)
327 {
328 if (!has_solid_color)
329 {
330 Vector<3, uint04> index = tris.vertexIndex(i);
332 color_iterator[index[A]]
333 , color_iterator[index[B]]
334 , color_iterator[index[C]]);
335 }
336 data.points[A] = transform * tri[A];
337 data.points[B] = transform * tri[B];
338 data.points[C] = transform * tri[C];
339 writer.addFast3dFace(false, data);
341 }
343 }
345 }
347 {
348 for (uint04 i = 0; i < 3; i++)
349 {
350 if (isNaN(vert[i]))
351 vert[i] = 0.0;
352 }
353 return vert;
354 }
356 {
357 CADMeshData data;
358 fillOutData(data);
359 data.handle = writer.handleManager()->getHandleIndex(model.uuid());
362 {
366 for (uint04 i = 0; i < data.normals.size(); i++)
368 break;
369 default:
370 break;
371 }
373 {
379 for (uint04 i = 0; i < data.textures.size(); i++)
380 CleanupDXFVertex(data.textures[i]);
381 break;
382 default:
383 break;
384 }
385 if (!has_solid_color)
386 {
388 data.colors.setSize(data.vertices.size());
389 for (uint04 i = 0; i < data.vertices.size(); i++)
390 data.colors[i] = color_iterator[i];
391 }
393 data.material_handle = writer.handleManager()->getHandleIndex(material.uuid());
395 for (uint04 i = 0; i < polylines.size(); i++)
396 {
397 bool invalid = false;
398 for (uint04 n = 0; n < polylines[i].size(); n++)
399 {
400 if (isNaN(polylines[i][n]))
401 {
402 invalid = true;
403 break;
404 }
405 if (isNaN(data.vertices[polylines[i][n]]))
406 {
407 invalid = true;
408 break;
409 }
410 }
411 if (invalid)
412 continue;
413 data.face_points.add(polylines[i].size());
414 for (uint04 n = 0; n < polylines[i].size(); n++)
415 {
416 data.face_points.add(polylines[i][n]);
417 }
419 }
420 for (uint04 i = 0; i < data.vertices.size(); i++)
421 data.vertices[i] = transform * CleanupDXFVertex(data.vertices[i]);
422 writer.addMesh(data);
423 }
425 {
426 switch (geometry.getGeometryType())
427 {
428 default:
429 lib_assert(false, "unknown geometry type");
430 break;
433 break;
435 {
436 if (has_solid_color)
437 {
439 {
440 default:
441 lib_assert(false, "unknown line type");
442 break;
444 writeAsLines();
445 break;
448 break;
449 }
450 }
451 else
452 {
453 writeAsLines();
454 }
455
456 } break;
460 {
461 switch (default_mesh_output)
462 {
465 break;
468 break;
469 default:
471 writeAsMesh();
472 break;
475 break;
476 }
477 } break;
478 }
479 }
480 };
481}
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
#define _t(english_string)
Definition Translator.h:87
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
void add(t_type &&object)
Definition Buffer.hpp:199
constexpr t_index_type size() const
Definition Buffer.hpp:1461
void setSize(t_index_type new_size)
Definition Buffer.hpp:1413
Definition Exception.h:66
Definition DXFWriter.h:53
void addPolyline(const PolylineData &data)
Definition DXFWriter.cpp:1360
void endFast3DFaces()
Definition DXFWriter.cpp:1610
void startFastPoints()
Definition DXFWriter.cpp:1199
void cleanupCADName(String &name)
Definition DXFWriter.cpp:1503
void addLine(const LineData &line)
Definition DXFWriter.cpp:1222
void addFastPoint(const PointData &face)
Definition DXFWriter.cpp:1203
void addMesh(const CADMeshData &data)
Definition DXFWriter.cpp:1278
const DynamicPointer< CADHandleManager > & handleManager() const
Definition DXFWriter.h:56
void addFast3dFace(bool is_solid, const TraceData &face)
Definition DXFWriter.cpp:1586
uint04 generateTempHandleIndex()
Definition DXFWriter.cpp:1774
void startFast3DFaces(bool is_solid)
Definition DXFWriter.cpp:1578
void endFastPoints()
Definition DXFWriter.cpp:1217
bool isValid() const
Definition DesignObject.h:362
UUID uuid() const
Definition DesignObject.cpp:533
t_type getProperty(DesignProperty property) const
Definition DesignObject.h:263
Matrix< fltp08 > getTransform() const
Definition DesignObject.cpp:593
@ e_name
Definition DesignObject.h:100
bool flatten_model
Definition FactoryOptions.h:152
Definition Geometry.h:64
@ e_cartesian_3F
Definition Geometry.h:74
@ e_cartesian_3D
Definition Geometry.h:76
@ e_cartesian_2F
Definition Geometry.h:73
@ e_cartesian_2D
Definition Geometry.h:75
GeometryType getGeometryType() const
Definition Geometry.cpp:1054
Buffer< t_type > vertices(VertexProperty property) const
Definition Geometry.h:962
uint04 primitiveCount(PrimitiveProperty property) const
Definition Geometry.h:669
t_type getGeometryProperty(GeometryProperty property) const
Definition Geometry.h:174
@ e_thickness
Definition Geometry.h:101
Buffer< Polyline< t_dims, t_type > > polylines(PrimitiveProperty primitive_property, VertexProperty vertex_property) const
Definition Geometry.h:1170
Buffer< Buffer< uint04 > > polyIndices(PrimitiveProperty primitive_property) const
Definition Geometry.cpp:1746
PrimitiveMode mode(PrimitiveProperty property) const
Definition Geometry.h:309
t_type primitive(PrimitiveProperty property, typename std::enable_if< ObjectInfo< t_type >::Dimensions<=1, uint04 >::type index) const
Definition Geometry.h:529
A line segment represented by two vertices, a start and end.
Definition Line.hpp:55
Definition Material.h:45
@ e_background_contrast
Definition Material.h:75
@ e_solid_color
Definition Material.h:70
@ e_color_by_model
Definition Material.h:73
@ e_scaled_channel
Definition Material.h:72
@ e_color_by_layer
Definition Material.h:78
@ e_color_channel
Definition Material.h:71
@ e_background_contrast_plus_solid
Definition Material.h:76
@ e_image
Definition Material.h:77
@ e_background
Definition Material.h:74
UVMode getUVMode(UVType uv_index) const
Definition Material.cpp:727
RGBColor getUVColor(UVType uv_index) const
Definition Material.cpp:889
Definition Matrix.hpp:173
Definition Model.h:54
Matrix< fltp08 > getCompleteTransform() const
Definition Model.cpp:117
Material getMaterial(PrimitiveProperty property) const
Definition Model.cpp:465
bool hasLayer() const
Definition Model.cpp:2328
bool isVisible() const
Definition Model.cpp:1149
Model getLayer() const
Definition Model.cpp:2342
RGBColor customModelColor(ModelColorMode mode) const
Definition Model.cpp:2066
bool isLayer() const
Definition Model.cpp:2252
bool hasMaterial() const
Definition Model.cpp:436
Material getRootMaterial(PrimitiveProperty property) const
Definition Model.cpp:545
virtual bool setProgress(fltp04 percent)=0
static NDEVR_BASE_API RGBColor Average(const RGBColor &a, const RGBColor &b, fltp04 percent=0.5f)
Definition RGBColor.cpp:159
Definition Vertex.hpp:341
Definition String.h:40
Definition TranslatedString.h:9
Definition Triangle.hpp:143
constexpr t_area_type area() const
Definition Triangle.hpp:385
constexpr LineSegment< t_dims, t_type, t_vertex > edge(uint01 triangle_node_a, uint01 triangle_node_b) const
Definition Triangle.hpp:276
Definition Geometry.h:1571
uint04 size() const
Definition Geometry.h:1615
Vector< 3, uint04 > vertexIndex(uint04 index) const
Definition Geometry.h:1605
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
Definition VertexColorIterator.h:10
A vertex.
Definition Vertex.hpp:54
Definition Geometry.h:1452
uint04 size() const
Definition Geometry.h:1492
BitFlag flag(uint04 index) const
Definition Geometry.h:1479
Definition ACIColor.h:37
@ e_background_contrast
Definition CADEntities.h:46
@ e_by_layer
Definition CADEntities.h:45
@ e_by_block
Definition CADEntities.h:44
@ e_use
Definition CADEntities.h:43
DXFEntityCodes
Definition EntityCodes.h:56
String layerName(const Model &model)
Definition CADGeometryWriter.h:90
CADColorInfo GenerateDXFColorInfo(const Model &model, bool is_flat, bool is_vertex)
Definition CADGeometryWriter.h:22
void FillOutLayerData(const Model &layer, LayerData &data)
Definition CADGeometryWriter.h:108
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
@ B
Definition BaseValues.hpp:203
@ A
Definition BaseValues.hpp:201
@ C
Definition BaseValues.hpp:205
void FillOutData(const Model &model, EntityData &data)
Definition CADGeometryWriter.h:117
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition CADEntities.h:68
ColorMode mode
Definition CADEntities.h:69
RGBColor color
Definition CADEntities.h:70
Definition CADGeometryWriter.h:126
void writeAsTriangleLines()
Definition CADGeometryWriter.h:275
Matrix< fltp08 > transform
Definition CADGeometryWriter.h:131
void writeAsPointData()
Definition CADGeometryWriter.h:198
FactoryParameters & params
Definition CADGeometryWriter.h:127
Matrix< fltp08 > model_transform
Definition CADGeometryWriter.h:140
uint04 shapes_written
Definition CADGeometryWriter.h:137
void setup(const Model &m, const Geometry &geo)
Definition CADGeometryWriter.h:159
Vertex< 3, fltp08 > & CleanupDXFVertex(Vertex< 3, fltp08 > &vert)
Definition CADGeometryWriter.h:346
bool has_solid_color
Definition CADGeometryWriter.h:141
void onShapeWritten()
Definition CADGeometryWriter.h:150
void writeAsPolyline()
Definition CADGeometryWriter.h:259
DXFEntityCodes default_mesh_output
Definition CADGeometryWriter.h:130
void fillOutData(EntityData &data)
Definition CADGeometryWriter.h:186
DXFWriter & writer
Definition CADGeometryWriter.h:128
void writeGeometry()
Definition CADGeometryWriter.h:424
uint04 parent_handle
Definition CADGeometryWriter.h:138
Geometry geometry
Definition CADGeometryWriter.h:133
void writeAsMesh()
Definition CADGeometryWriter.h:355
String layer_name
Definition CADGeometryWriter.h:135
void writeAs3DFace()
Definition CADGeometryWriter.h:315
Material material
Definition CADGeometryWriter.h:134
void writeAsLines()
Definition CADGeometryWriter.h:225
uint04 num_of_shapes
Definition CADGeometryWriter.h:136
CADGeometryWriter(DXFWriter &writer, FactoryParameters &params)
Definition CADGeometryWriter.h:143
Model model
Definition CADGeometryWriter.h:132
CADColorInfo model_color_info
Definition CADGeometryWriter.h:129
Definition CADEntities.h:366
Buffer< Vertex< 3, fltp08 > > normals
Definition CADEntities.h:384
Buffer< Vertex< 3, fltp08 > > textures
Definition CADEntities.h:385
Buffer< RGBColor > colors
Definition CADEntities.h:386
Buffer< Vertex< 3, fltp08 > > vertices
Definition CADEntities.h:383
Buffer< uint04 > face_points
Definition CADEntities.h:387
Definition BaseValues.hpp:272
Definition CADEntities.h:139
uint04 material_handle
Definition CADEntities.h:145
bool visible
Definition CADEntities.h:148
CADColorInfo color_info
Definition CADEntities.h:142
String layer
Definition CADEntities.h:140
Definition IOFactory.h:56
ProgressInfo * log
Definition IOFactory.h:95
FactoryOptions options
Definition IOFactory.h:90
uint04 parent_handle
Definition CADEntities.h:135
uint04 handle
Definition CADEntities.h:134
Definition CADEntities.h:154
String name
Definition CADEntities.h:167
Definition CADEntities.h:491
LineSegment< 3, fltp08 > line
Definition CADEntities.h:492
fltp08 thickness
Definition CADEntities.h:493
Definition CADEntities.h:509
Vector< 3, fltp08 > location
Definition CADEntities.h:510
logic for storing a polyline data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:293
Vector< 32, bool > flags
Definition CADEntities.h:329
@ e_is_3D_polyline
Definition CADEntities.h:299
fltp08 thickness
Definition CADEntities.h:312
logic for storing a trace data in a CAD-friendly way for exporting and importing.
Definition CADEntities.h:337
Vertex< 3, fltp08 > points[4]
Definition CADEntities.h:342