API Documentation
Loading...
Searching...
No Matches
CADTextWriteModifier.h
Go to the documentation of this file.
1#pragma once
3#if NDEVR_TEXT_MODEL
6namespace NDEVR
7{
8 class Model;
9 struct CADGeometryWriter;
10 class DXFTableWriteIterator;
11 class DXFBlockWriter;
12 class CADTextWriteModifier : public CADWriteModifier
13 {
14 public:
15 static void WriteText(DXFWriter& writer, const Matrix<fltp08>& tr, const Text& text, uint04 handle, uint04 parent_handle)
16 {
17
18 TextData text_data;
19 text_data.handle = handle;
20 text_data.parent_handle = parent_handle;
21 text_data.text = text.plainText();
22 text_data.text.replace("\n", "\\P");
23 if (text_data.text.size() == 0)
24 return;
25 FillOutData(text, text_data);
26 text_data.color_info = GenerateDXFColorInfo(text, false, false);
27 writer.cleanupCADName(text_data.layer);
28
29 Model text_object = text.textObject();
30 Bounds<3, fltp08> bounds = text_object.getBounds();
31 if (isNaN(bounds))
32 bounds = text_object.getSelectionBounds();
33 Matrix<fltp08> text_sub_matrix = tr * text_object.getTransform();
34 text_data.align_a = text_sub_matrix * bounds[MIN];
35 text_data.align_b = text_sub_matrix * bounds.center();
36
37 text_data.alignment = cast<uint01>(TextAlignment::e_center);
38 Vector<3, fltp08> scale = text_sub_matrix.decomposeScale();
39 text_data.height = scale[Y] * bounds.span()[Y];
40 text_data.reference_width = scale[X] * bounds.span()[X];
41
42 text_data.line_spacing_factor = text.lineSpaceFactor();
43
44 Ray<3, fltp08> up(0.0, 0.0, 1.0);
45 text_data.extrusion = (text_sub_matrix * up).normalized<fltp08>();
46 auto rotation = (EntityConverter::GetOrientation(text_data.extrusion) * text_sub_matrix).decomposeRotation<fltp08>();
47 text_data.rotatation = rotation[YAW];
48 //text_data.extrusion = orientation.first;
49 writer.addText(text_data);
50 }
51 bool canHandleBlock(const Model& model) final override
52 {
53 return model.isOfType(Text::TypeName());
54 }
55 ModelIterator::ParseResult handleBlock(const Model& model, DXFTableWriteIterator& options) final override
56 {
57 BlockData data = options.convertToBlock(model);
58
59 data.handle = options.handle_manager->getHandleIndex(data.name);
60 options.handle_manager->setHandleToUUID(model.uuid(), data.handle);
61 options.writer.handleManager()->setTransfromCoords(data.handle
62 , options.params.options.units.coordinate_space_unit.get()->matrix() * model.getCompleteTransform());
63 //options.block_data.insert({ model.uuid(), data });
64 return ModelIterator::ParseResult::e_do_not_parse_children;
65 }
66 ModelIterator::ParseResult handleBlock(const Model&, DXFBlockWriter&) final override
67 {
68 return ModelIterator::ParseResult::e_do_not_parse_children;
69 }
70
71 bool canHandleInsert(const Model& model) final override
72 {
73 return model.isOfType(Text::TypeName());
74 }
75 void handleInsert(const Matrix<fltp08>& parent_transform, const Model& model, uint04 parent_handle, DXFBlockWriter& options) final override
76 {
77 Text text(model);
78 WriteText(options.writer, parent_transform, text, options.writer.handleManager()->getHandleIndex(model.uuid()), parent_handle);
79 }
80 void handleInsert(const Matrix<fltp08>&, const Model&, uint04, CADGeometryWriter&) final override
81 {
82
83 }
84 };
85}
86 #endif
Definition ACIColor.h:37
@ MIN
Definition BaseValues.hpp:226
@ YAW
Definition Angle.h:53
CADColorInfo GenerateDXFColorInfo(const Model &model, bool is_flat, bool is_vertex)
Definition CADGeometryWriter.h:22
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
@ Y
Definition BaseValues.hpp:202
@ X
Definition BaseValues.hpp:200
void FillOutData(const Model &model, EntityData &data)
Definition CADGeometryWriter.h:117