Sun, 10 Jun 2018 21:48:58 +0300
refactored LDPolygon
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include "../algorithms/geometry.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include "../glShared.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | #include "../model.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | #include "../algorithms/invert.h" |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
5 | #include "circularprimitive.h" |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | #include "quadrilateral.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | #include "primitives.h" |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
9 | QString LDCircularPrimitive::buildFilename() const |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | int numerator = this->m_segments; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | int denominator = this->m_divisions; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | QString prefix; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | if (m_divisions != MediumResolution) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | prefix = QString::number(m_divisions) + '\\'; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | simplify(numerator, denominator); |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
19 | |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
20 | // Ensure that the denominator is at least 4, expand if necessary |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
21 | if (denominator < 4) |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
22 | { |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
23 | numerator = static_cast<int>(round(numerator * 4.0 / denominator)); |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
24 | denominator = 4; |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
25 | } |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
26 | |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
27 | return format("%1%2-%3%4.dat", prefix, numerator, denominator, stem()); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
30 | LDCircularPrimitive::LDCircularPrimitive( |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
31 | PrimitiveModel::Type type, |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | int segments, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | int divisions, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | const Matrix& transformationMatrix, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
35 | const Vertex& position |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | ) : |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | LDMatrixObject {transformationMatrix, position}, |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
38 | m_type {type}, |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | m_segments {segments}, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | m_divisions {divisions} {} |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
42 | LDObjectType LDCircularPrimitive::type() const |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
43 | { |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
44 | return SubclassType; |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
45 | } |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
46 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
47 | QString LDCircularPrimitive::asText() const |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | return LDSubfileReference(buildFilename(), transformationMatrix(), position()).asText(); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
52 | void LDCircularPrimitive::getVertices(DocumentManager* /* context */, QSet<Vertex>& vertices) const |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | int endSegment = (m_segments == m_divisions) ? m_segments : m_segments + 1; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | for (int i = 0; i < endSegment; i += 1) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | QPointF point2d = pointOnLDrawCircumference(i, m_divisions); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | for (double y_value : {0.0, 1.0}) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | Vertex vertex {point2d.x(), y_value, point2d.y()}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | vertex.transform(transformationMatrix(), position()); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
64 | vertices.insert(vertex); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
67 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
68 | |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
69 | bool LDCircularPrimitive::isRasterizable() const |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
70 | { |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
71 | return true; |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
72 | } |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
73 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
74 | void LDCircularPrimitive::rasterize( |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
75 | DocumentManager* context, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
76 | Winding /* parentWinding */, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
77 | Model& model, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
78 | bool /* deep */, |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
79 | bool /* render */ |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
80 | ) { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
81 | Model cylinderBody {context}; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
82 | buildPrimitiveBody(cylinderBody); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
83 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
84 | for (LDObject* object : cylinderBody.objects()) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
85 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
86 | for (int i = 0; i < object->numVertices(); i += 1) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
87 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
88 | Vertex vertex = object->vertex(i); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
89 | vertex.transform(transformationMatrix(), position()); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
90 | object->setVertex(i, vertex); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
91 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
92 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
93 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
94 | model.merge(cylinderBody); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
95 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
97 | QVector<LDPolygon> LDCircularPrimitive::rasterizePolygons(DocumentManager* context, Winding winding) |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
98 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
99 | Model cylinderBody {context}; |
1394
8d9d0532b3df
fixed cylinder rendering
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
100 | buildPrimitiveBody(cylinderBody); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
101 | QVector<LDPolygon> result; |
1394
8d9d0532b3df
fixed cylinder rendering
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
102 | bool cachedShouldInvert = shouldInvert(winding, context); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
103 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
104 | for (LDObject* object : cylinderBody.objects()) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
105 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
106 | for (int i = 0; i < object->numVertices(); i += 1) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
107 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
108 | Vertex vertex = object->vertex(i); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
109 | vertex.transform(transformationMatrix(), position()); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
110 | object->setVertex(i, vertex); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
111 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
112 | |
1400 | 113 | LDPolygon polygon = object->getPolygon(); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
114 | |
1400 | 115 | if (polygon.isValid()) |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
116 | { |
1394
8d9d0532b3df
fixed cylinder rendering
Teemu Piippo <teemu@hecknology.net>
parents:
1391
diff
changeset
|
117 | if (cachedShouldInvert) |
1400 | 118 | invertPolygon(polygon); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
119 | |
1400 | 120 | result.append(polygon); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
121 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
122 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
123 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
124 | return result; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
125 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
126 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
127 | void LDCircularPrimitive::buildPrimitiveBody(Model& model) const |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
128 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
129 | PrimitiveModel primitive; |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
130 | primitive.type = m_type; |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
131 | primitive.segments = m_segments; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
132 | primitive.divisions = m_divisions; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
133 | primitive.ringNumber = 0; |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
134 | primitive.generateBody(model); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
135 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
136 | |
1399
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
137 | QString LDCircularPrimitive::stem() const |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
138 | { |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
139 | switch (m_type) |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
140 | { |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
141 | case PrimitiveModel::Cylinder: |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
142 | return "cyli"; |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
143 | |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
144 | case PrimitiveModel::Circle: |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
145 | return "edge"; |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
146 | |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
147 | case PrimitiveModel::Disc: |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
148 | return "disc"; |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
149 | |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
150 | case PrimitiveModel::DiscNegative: |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
151 | return "ndis"; |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
152 | |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
153 | default: |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
154 | throw std::logic_error("Bad primitive type to LDCircularPrimitive"); |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
155 | } |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
156 | } |
f52ea4078f5d
added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents:
1398
diff
changeset
|
157 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
158 | QString LDCircularPrimitive::objectListText() const |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
159 | { |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
160 | QString result = format( |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
161 | "%1 %2 %3, (", |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
162 | PrimitiveModel::typeName(m_type), |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
163 | m_segments / m_divisions, |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
164 | position().toString(true) |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
165 | ); |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
166 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
167 | for (int i = 0; i < 9; ++i) |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
168 | result += format("%1%2", transformationMatrix().value(i), (i != 8) ? " " : ""); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
169 | |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
170 | result += ')'; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
171 | return result; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
172 | } |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
173 | |
1398
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
174 | int LDCircularPrimitive::triangleCount(DocumentManager*) const |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
175 | { |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
176 | switch (m_type) |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
177 | { |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
178 | case PrimitiveModel::Ring: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
179 | case PrimitiveModel::Cone: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
180 | throw std::logic_error("Bad primitive type to LDCircularPrimitive"); |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
181 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
182 | case PrimitiveModel::Cylinder: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
183 | return 2 * m_segments; |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
184 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
185 | case PrimitiveModel::Disc: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
186 | case PrimitiveModel::DiscNegative: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
187 | return m_segments; |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
188 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
189 | case PrimitiveModel::Circle: |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
190 | return 0; |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
191 | } |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
192 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
193 | return 0; |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
194 | } |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
195 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
196 | QString LDCircularPrimitive::typeName() const |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
197 | { |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
198 | return "circular-primitive"; |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
199 | } |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
200 | |
1c70d3447d20
changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents:
1394
diff
changeset
|
201 | void LDCircularPrimitive::serialize(class Serializer& serializer) |
1391
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
202 | { |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
203 | LDMatrixObject::serialize(serializer); |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
204 | serializer << m_segments << m_divisions; |
5fa4bf1fc781
added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
205 | } |