src/linetypes/circularprimitive.cpp

Sun, 17 Jun 2018 16:13:24 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 17 Jun 2018 16:13:24 +0300
changeset 1406
37fffb682d2f
parent 1403
7a2d84112983
child 1407
22bc5862cb56
permissions
-rw-r--r--

Circular primitive editor complete

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};
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 buildPrimitiveBody(cylinderBody);
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};
1394
8d9d0532b3df fixed cylinder rendering
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
97 buildPrimitiveBody(cylinderBody);
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
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
124 void LDCircularPrimitive::buildPrimitiveBody(Model& model) 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;
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
131 primitive.generateBody(model);
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
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
150 default:
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
151 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
152 }
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
153 }
f52ea4078f5d added the disc and disc negative to the circular primitive type
Teemu Piippo <teemu@hecknology.net>
parents: 1398
diff changeset
154
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
155 QString LDCircularPrimitive::objectListText() const
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
156 {
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
157 QString prefix;
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
158
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
159 if (m_divisions == HighResolution)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
160 prefix = "Hi-Res";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
161 else if (m_divisions == LowResolution)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
162 prefix = "Lo-Res";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
163 else if (m_divisions != MediumResolution)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
164 prefix = format("%1-resolution", m_divisions);
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
165
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
166 QString result = format(
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
167 "%1 %2 %3 %4, (",
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
168 prefix,
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
169 PrimitiveModel::typeName(m_type),
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
170 m_segments / m_divisions,
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
171 position().toString(true)
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
172 ).simplified();
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
173
1403
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
174 for (int i = 0; i < 3; ++i)
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
175 for (int j = 0; j < 3; ++j)
7a2d84112983 replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1402
diff changeset
176 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
177
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
178 result += ')';
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
179 return result;
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
180 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
181
1406
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
182 PrimitiveModel::Type LDCircularPrimitive::primitiveType() const
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
183 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
184 return m_type;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
185 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
186
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
187 void LDCircularPrimitive::setPrimitiveType(PrimitiveModel::Type newType)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
188 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
189 changeProperty(&m_type, newType);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
190 }
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 int LDCircularPrimitive::segments() const
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
193 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
194 return m_segments;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
195 }
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 void LDCircularPrimitive::setSegments(int newSegments)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
198 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
199 changeProperty(&m_segments, newSegments);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
200 }
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 int LDCircularPrimitive::divisions() const
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
203 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
204 return m_divisions;
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
205 }
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 void LDCircularPrimitive::setDivisions(int newDivisions)
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
208 {
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
209 changeProperty(&m_divisions, newDivisions);
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
210 }
37fffb682d2f Circular primitive editor complete
Teemu Piippo <teemu@hecknology.net>
parents: 1403
diff changeset
211
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
212 int LDCircularPrimitive::triangleCount(DocumentManager*) const
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
213 {
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
214 switch (m_type)
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
215 {
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
216 case PrimitiveModel::Ring:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
217 case PrimitiveModel::Cone:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
218 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
219
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
220 case PrimitiveModel::Cylinder:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
221 return 2 * m_segments;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
222
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
223 case PrimitiveModel::Disc:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
224 case PrimitiveModel::DiscNegative:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
225 return m_segments;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
226
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
227 case PrimitiveModel::Circle:
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
228 return 0;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
229 }
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 return 0;
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
232 }
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
233
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
234 QString LDCircularPrimitive::iconName() const
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
235 {
1402
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
236 switch (m_type)
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
237 {
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
238 case PrimitiveModel::Ring:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
239 case PrimitiveModel::Cone:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
240 break;
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
241
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
242 case PrimitiveModel::Cylinder:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
243 return "cylinder";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
244
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
245 case PrimitiveModel::Disc:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
246 return "disc";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
247
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
248 case PrimitiveModel::DiscNegative:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
249 return "disc-negative";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
250
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
251 case PrimitiveModel::Circle:
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
252 return "circle";
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
253 }
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
254
8bbf2af8c3f5 some rework in description
Teemu Piippo <teemu@hecknology.net>
parents: 1401
diff changeset
255 return "";
1398
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
256 }
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
257
1c70d3447d20 changed LDCylinder to LDCircularPrimitive and moved circles to it
Teemu Piippo <teemu@hecknology.net>
parents: 1394
diff changeset
258 void LDCircularPrimitive::serialize(class Serializer& serializer)
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
259 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
260 LDMatrixObject::serialize(serializer);
1401
59b578c77111 fixed bugs regarding circular primitives
Teemu Piippo <teemu@hecknology.net>
parents: 1400
diff changeset
261 serializer << m_segments << m_divisions << m_type;
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
262 }

mercurial