src/editmodes/circleMode.cpp

changeset 1151
0eddb5bcf25b
parent 1149
502c866b8512
child 1179
1a9ffd5e0399
equal deleted inserted replaced
1150:262345e53050 1151:0eddb5bcf25b
24 #include "../primitives.h" 24 #include "../primitives.h"
25 #include "../canvas.h" 25 #include "../canvas.h"
26 #include "../mainwindow.h" 26 #include "../mainwindow.h"
27 #include "../mathfunctions.h" 27 #include "../mathfunctions.h"
28 #include "../miscallenous.h" 28 #include "../miscallenous.h"
29 #include "../documentmanager.h"
29 #include "../grid.h" 30 #include "../grid.h"
30 #include "../linetypes/modelobject.h" 31 #include "../linetypes/modelobject.h"
31 #include "../linetypes/quadrilateral.h" 32 #include "../linetypes/quadrilateral.h"
32 33
33 CircleMode::CircleMode(Canvas* canvas) : 34 CircleMode::CircleMode(Canvas* canvas) :
81 if (dist0 == dist1) 82 if (dist0 == dist1)
82 { 83 {
83 // If the radii are the same, there's no ring space to fill. Use a circle. 84 // If the radii are the same, there's no ring space to fill. Use a circle.
84 primitiveModel.type = PrimitiveModel::Circle; 85 primitiveModel.type = PrimitiveModel::Circle;
85 primitiveFile = primitives()->getPrimitive(primitiveModel); 86 primitiveFile = primitives()->getPrimitive(primitiveModel);
86 transform = renderer()->currentCamera().transformationMatrix(dist0); 87 transform = Matrix::fromRotationMatrix(renderer()->currentCamera().transformationMatrix(dist0));
87 circleOrDisc = true; 88 circleOrDisc = true;
88 } 89 }
89 else if (dist0 == 0 or dist1 == 0) 90 else if (dist0 == 0 or dist1 == 0)
90 { 91 {
91 // If either radii is 0, use a disc. 92 // If either radii is 0, use a disc.
92 primitiveModel.type = PrimitiveModel::Disc; 93 primitiveModel.type = PrimitiveModel::Disc;
93 primitiveFile = primitives()->getPrimitive(primitiveModel); 94 primitiveFile = primitives()->getPrimitive(primitiveModel);
94 transform = renderer()->currentCamera().transformationMatrix((dist0 != 0) ? dist0 : dist1); 95 transform = Matrix::fromRotationMatrix(renderer()->currentCamera().transformationMatrix((dist0 != 0) ? dist0 : dist1));
95 circleOrDisc = true; 96 circleOrDisc = true;
96 } 97 }
97 else if (g_RingFinder.findRings(dist0, dist1)) 98 else if (g_RingFinder.findRings(dist0, dist1))
98 { 99 {
99 // The ring finder found a solution, use that. Add the component rings to the file. 100 // The ring finder found a solution, use that. Add the component rings to the file.
101 102
102 for (const RingFinder::Component& component : g_RingFinder.bestSolution()->getComponents()) 103 for (const RingFinder::Component& component : g_RingFinder.bestSolution()->getComponents())
103 { 104 {
104 primitiveModel.ringNumber = component.num; 105 primitiveModel.ringNumber = component.num;
105 primitiveFile = primitives()->getPrimitive(primitiveModel); 106 primitiveFile = primitives()->getPrimitive(primitiveModel);
106 model.emplace<LDSubfileReference>(primitiveFile, renderer()->currentCamera().transformationMatrix(component.scale), 107 Matrix matrix = Matrix::fromRotationMatrix(renderer()->currentCamera().transformationMatrix(component.scale));
107 m_drawedVerts.first()); 108 model.emplace<LDSubfileReference>(primitiveFile, matrix, m_drawedVerts.first());
108 } 109 }
109 } 110 }
110 else 111 else
111 { 112 {
112 // Ring finder failed, last resort: draw the ring with quads 113 // Ring finder failed, last resort: draw the ring with quads
147 } 148 }
148 } 149 }
149 150
150 if (circleOrDisc and primitiveFile) 151 if (circleOrDisc and primitiveFile)
151 model.emplace<LDSubfileReference>(primitiveFile, transform, m_drawedVerts.first()); 152 model.emplace<LDSubfileReference>(primitiveFile, transform, m_drawedVerts.first());
152
153 if (not model.isEmpty())
154 {
155 Axis relZ = renderer()->getRelativeZ();;
156 int l = (relZ == X ? 1 : 0);
157 int m = (relZ == Y ? 1 : 0);
158 int n = (relZ == Z ? 1 : 0);
159 math()->rotateObjects(l, m, n, -m_angleOffset, model.objects());
160 }
161 153
162 finishDraw (model); 154 finishDraw (model);
163 } 155 }
164 156
165 /* 157 /*

mercurial