src/linetypes/circularprimitive.cpp

Sun, 17 Jun 2018 17:07:29 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 17 Jun 2018 17:07:29 +0300
changeset 1407
22bc5862cb56
parent 1406
37fffb682d2f
child 1408
0d6162662040
permissions
-rw-r--r--

added support for open/closed cylinders in LDCircularPrimitive

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
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
30 LDCircularPrimitive::LDCircularPrimitive(PrimitiveModel::Type type,
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 int segments,
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 int divisions,
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
33 const QMatrix4x4& matrix) :
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
34 LDMatrixObject {matrix},
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
35 m_type {type},
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 m_segments {segments},
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 m_divisions {divisions} {}
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
39 LDObjectType LDCircularPrimitive::type() const
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
40 {
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
41 return SubclassType;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
42 }
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 QString LDCircularPrimitive::asText() const
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 {
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
46 return LDSubfileReference(buildFilename(), transformationMatrix()).asText();
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
49 void LDCircularPrimitive::getVertices(DocumentManager* /* context */, QSet<Vertex>& vertices) const
1391
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 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
52
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 for (int i = 0; i < endSegment; i += 1)
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 QPointF point2d = pointOnLDrawCircumference(i, m_divisions);
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 for (double y_value : {0.0, 1.0})
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 Vertex vertex {point2d.x(), y_value, point2d.y()};
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
60 vertex.transform(transformationMatrix());
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 vertices.insert(vertex);
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65
1399
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
66 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
67 {
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
68 return true;
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
69 }
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
70
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
71 void LDCircularPrimitive::rasterize(
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 DocumentManager* context,
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 Winding /* parentWinding */,
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 Model& model,
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 bool /* deep */,
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 bool /* render */
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 ) {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78 Model cylinderBody {context};
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
79 buildPrimitiveBody(cylinderBody, false);
1391
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 for (LDObject* object : cylinderBody.objects())
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83 for (int i = 0; i < object->numVertices(); i += 1)
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
84 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 Vertex vertex = object->vertex(i);
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
86 vertex.transform(transformationMatrix());
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
87 object->setVertex(i, vertex);
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
88 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
89 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91 model.merge(cylinderBody);
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
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
94 QVector<LDPolygon> LDCircularPrimitive::rasterizePolygons(DocumentManager* context, Winding winding)
1391
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 Model cylinderBody {context};
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
97 buildPrimitiveBody(cylinderBody, true);
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 QVector<LDPolygon> result;
1394
8d9d0532b3df fixed cylinder rendering
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
99 bool cachedShouldInvert = shouldInvert(winding, context);
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 for (LDObject* object : cylinderBody.objects())
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 for (int i = 0; i < object->numVertices(); i += 1)
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 Vertex vertex = object->vertex(i);
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
106 vertex.transform(transformationMatrix());
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107 object->setVertex(i, vertex);
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
108 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1399
diff changeset
110 LDPolygon polygon = object->getPolygon();
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
111
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1399
diff changeset
112 if (polygon.isValid())
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113 {
1394
8d9d0532b3df fixed cylinder rendering
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
114 if (cachedShouldInvert)
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1399
diff changeset
115 invertPolygon(polygon);
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
116
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1399
diff changeset
117 result.append(polygon);
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
118 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
119 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121 return result;
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
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
124 void LDCircularPrimitive::buildPrimitiveBody(Model& model, bool deep) const
1391
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 PrimitiveModel primitive;
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
127 primitive.type = m_type;
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 primitive.segments = m_segments;
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 primitive.divisions = m_divisions;
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130 primitive.ringNumber = 0;
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
131 primitive.generateBody(model, deep);
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
133
1399
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
134 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
135 {
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
136 switch (m_type)
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
137 {
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
138 case PrimitiveModel::Cylinder:
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
139 return "cyli";
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::Circle:
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
142 return "edge";
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::Disc:
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
145 return "disc";
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::DiscNegative:
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
148 return "ndis";
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
149
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
150 case PrimitiveModel::CylinderClosed:
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
151 return "cylc";
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
152
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
153 case PrimitiveModel::CylinderOpen:
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
154 return "cylo";
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
155
1399
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
156 default:
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
157 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
158 }
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
159 }
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
160
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
161 QString LDCircularPrimitive::objectListText() const
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
162 {
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
163 QString prefix;
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
164
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
165 if (m_divisions == HighResolution)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
166 prefix = "Hi-Res";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
167 else if (m_divisions == LowResolution)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
168 prefix = "Lo-Res";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
169 else if (m_divisions != MediumResolution)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
170 prefix = format("%1-resolution", m_divisions);
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
171
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
172 QString result = format(
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
173 "%1 %2 %3 %4, (",
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
174 prefix,
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
175 PrimitiveModel::typeName(m_type),
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
176 m_segments / m_divisions,
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
177 position().toString(true)
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
178 ).simplified();
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
179
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
180 for (int i = 0; i < 3; ++i)
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
181 for (int j = 0; j < 3; ++j)
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
182 result += format("%1%2", transformationMatrix()(i, j), (i != 2 or j != 2) ? " " : "");
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
183
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
184 result += ')';
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
185 return result;
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
188 PrimitiveModel::Type LDCircularPrimitive::primitiveType() const
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
189 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
190 return m_type;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
191 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
192
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
193 void LDCircularPrimitive::setPrimitiveType(PrimitiveModel::Type newType)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
194 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
195 changeProperty(&m_type, newType);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
196 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
197
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
198 int LDCircularPrimitive::segments() const
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
199 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
200 return m_segments;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
201 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
202
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
203 void LDCircularPrimitive::setSegments(int newSegments)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
204 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
205 changeProperty(&m_segments, newSegments);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
206 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
207
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
208 int LDCircularPrimitive::divisions() const
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
209 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
210 return m_divisions;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
211 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
212
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
213 void LDCircularPrimitive::setDivisions(int newDivisions)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
214 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
215 changeProperty(&m_divisions, newDivisions);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
216 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
217
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
218 int LDCircularPrimitive::triangleCount(DocumentManager*) const
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
219 {
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
220 switch (m_type)
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
221 {
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
222 case PrimitiveModel::Ring:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
223 case PrimitiveModel::Cone:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
224 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
225
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
226 case PrimitiveModel::Cylinder:
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
227 case PrimitiveModel::CylinderClosed:
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
228 case PrimitiveModel::CylinderOpen:
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
229 return 2 * m_segments;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
230
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
231 case PrimitiveModel::Disc:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
232 case PrimitiveModel::DiscNegative:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
233 return m_segments;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
234
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
235 case PrimitiveModel::Circle:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
236 return 0;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
237 }
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
238
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
239 return 0;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
240 }
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
241
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
242 QString LDCircularPrimitive::iconName() const
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
243 {
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
244 switch (m_type)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
245 {
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
246 case PrimitiveModel::Ring:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
247 case PrimitiveModel::Cone:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
248 break;
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
249
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
250 case PrimitiveModel::Cylinder:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
251 return "cylinder";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
252
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
253 case PrimitiveModel::Disc:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
254 return "disc";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
255
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
256 case PrimitiveModel::DiscNegative:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
257 return "disc-negative";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
258
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
259 case PrimitiveModel::Circle:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
260 return "circle";
1407
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
261
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
262 case PrimitiveModel::CylinderClosed:
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
263 return "cylinder-closed";
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
264
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
265 case PrimitiveModel::CylinderOpen:
22bc5862cb56 added support for open/closed cylinders in LDCircularPrimitive
Teemu Piippo <teemu@hecknology.net>
parents: 1406
diff changeset
266 return "cylinder-open";
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
267 }
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
268
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
269 return "";
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
270 }
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
271
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
272 void LDCircularPrimitive::serialize(class Serializer& serializer)
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
273 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
274 LDMatrixObject::serialize(serializer);
1401
59b578c77111 fixed bugs regarding circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1400
diff changeset
275 serializer << m_segments << m_divisions << m_type;
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
276 }

mercurial