35 #include "../dialogs/colorselector.h" |
35 #include "../dialogs/colorselector.h" |
36 #include "../dialogs/subfilereferenceeditor.h" |
36 #include "../dialogs/subfilereferenceeditor.h" |
37 #include "../grid.h" |
37 #include "../grid.h" |
38 #include "../parser.h" |
38 #include "../parser.h" |
39 #include "../widgets/vertexobjecteditor.h" |
39 #include "../widgets/vertexobjecteditor.h" |
|
40 #include "../algorithms/invert.h" |
40 #include "basictoolset.h" |
41 #include "basictoolset.h" |
41 #include "guiutilities.h" |
42 #include "guiutilities.h" |
42 |
43 |
43 BasicToolset::BasicToolset (MainWindow *parent) : |
44 BasicToolset::BasicToolset (MainWindow *parent) : |
44 Toolset (parent) {} |
45 Toolset (parent) {} |
226 } |
227 } |
227 } |
228 } |
228 |
229 |
229 void BasicToolset::invert() |
230 void BasicToolset::invert() |
230 { |
231 { |
231 for (LDObject* obj : selectedObjects()) |
232 for (LDObject* object : selectedObjects()) |
232 { |
233 ::invert(object, m_documents); |
233 if (obj->numPolygonVertices() > 0) |
|
234 { |
|
235 QVector<Vertex> vertices; |
|
236 |
|
237 for (int i = 0; i < obj->numPolygonVertices(); i += 1) |
|
238 vertices.append(obj->vertex(i)); |
|
239 |
|
240 for (int i = 0; i < vertices.size(); i += 1) |
|
241 obj->setVertex(i, vertices[vertices.size() - 1 - i]); |
|
242 } |
|
243 else if (obj->type() == LDObjectType::SubfileReference) |
|
244 { |
|
245 // Check whether subfile is flat |
|
246 int axisSet = (1 << X) | (1 << Y) | (1 << Z); |
|
247 Model model {currentDocument()->documentManager()}; |
|
248 LDSubfileReference* reference = static_cast<LDSubfileReference*>(obj); |
|
249 reference->fileInfo(m_documents)->inlineContents(model, true, false); |
|
250 |
|
251 for (LDObject* subobj : model.objects()) |
|
252 { |
|
253 for (int i = 0; i < subobj->numVertices(); ++i) |
|
254 { |
|
255 Vertex const& vrt = subobj->vertex (i); |
|
256 |
|
257 if (axisSet & (1 << X) and vrt.x() != 0.0) |
|
258 axisSet &= ~(1 << X); |
|
259 |
|
260 if (axisSet & (1 << Y) and vrt.y() != 0.0) |
|
261 axisSet &= ~(1 << Y); |
|
262 |
|
263 if (axisSet & (1 << Z) and vrt.z() != 0.0) |
|
264 axisSet &= ~(1 << Z); |
|
265 } |
|
266 |
|
267 if (axisSet == 0) |
|
268 break; |
|
269 } |
|
270 |
|
271 if (axisSet != 0) |
|
272 { |
|
273 // Subfile has all vertices zero on one specific plane, so it is flat. |
|
274 // Let's flip it. |
|
275 Matrix matrixModifier = Matrix::identity; |
|
276 |
|
277 if (axisSet & (1 << X)) |
|
278 matrixModifier(0, 0) = -1; |
|
279 |
|
280 if (axisSet & (1 << Y)) |
|
281 matrixModifier(1, 1) = -1; |
|
282 |
|
283 if (axisSet & (1 << Z)) |
|
284 matrixModifier(2, 2) = -1; |
|
285 |
|
286 reference->setTransformationMatrix(reference->transformationMatrix() * matrixModifier); |
|
287 } |
|
288 else |
|
289 { |
|
290 // Subfile is not flat. Resort to invertnext. |
|
291 reference->setInverted(not reference->isInverted()); |
|
292 } |
|
293 } |
|
294 } |
|
295 } |
234 } |
296 |
235 |
297 template<typename T> |
236 template<typename T> |
298 static void createObject(MainWindow* window) |
237 static void createObject(MainWindow* window) |
299 { |
238 { |