src/toolsets/basictoolset.cpp

changeset 1261
5d2c9d36da9d
parent 1258
f5921a474d57
child 1262
f6b253c17643
equal deleted inserted replaced
1260:0347e9bc883e 1261:5d2c9d36da9d
218 } 218 }
219 219
220 void BasicToolset::invert() 220 void BasicToolset::invert()
221 { 221 {
222 for (LDObject* obj : selectedObjects()) 222 for (LDObject* obj : selectedObjects())
223 obj->invert(); 223 {
224 if (obj->numPolygonVertices() > 0)
225 {
226 QVector<Vertex> vertices;
227
228 for (int i = 0; i < obj->numPolygonVertices(); i += 1)
229 vertices.append(obj->vertex(i));
230
231 for (int i = 0; i < vertices.size(); i += 1)
232 obj->setVertex(i, vertices[vertices.size() - 1 - i]);
233 }
234 else if (obj->type() == LDObjectType::SubfileReference)
235 {
236 // Check whether subfile is flat
237 int axisSet = (1 << X) | (1 << Y) | (1 << Z);
238 Model model {currentDocument()->documentManager()};
239 LDSubfileReference* reference = static_cast<LDSubfileReference*>(obj);
240 reference->fileInfo()->inlineContents(model, true, false);
241
242 for (LDObject* subobj : model.objects())
243 {
244 for (int i = 0; i < subobj->numVertices(); ++i)
245 {
246 Vertex const& vrt = subobj->vertex (i);
247
248 if (axisSet & (1 << X) and vrt.x() != 0.0)
249 axisSet &= ~(1 << X);
250
251 if (axisSet & (1 << Y) and vrt.y() != 0.0)
252 axisSet &= ~(1 << Y);
253
254 if (axisSet & (1 << Z) and vrt.z() != 0.0)
255 axisSet &= ~(1 << Z);
256 }
257
258 if (axisSet == 0)
259 break;
260 }
261
262 if (axisSet != 0)
263 {
264 // Subfile has all vertices zero on one specific plane, so it is flat.
265 // Let's flip it.
266 Matrix matrixModifier = Matrix::identity;
267
268 if (axisSet & (1 << X))
269 matrixModifier(0, 0) = -1;
270
271 if (axisSet & (1 << Y))
272 matrixModifier(1, 1) = -1;
273
274 if (axisSet & (1 << Z))
275 matrixModifier(2, 2) = -1;
276
277 reference->setTransformationMatrix(reference->transformationMatrix() * matrixModifier);
278 }
279 else
280 {
281 // Subfile is not flat. Resort to invertnext.
282 reference->setInverted(not reference->isInverted());
283 }
284 }
285 }
224 } 286 }
225 287
226 void BasicToolset::newSubfile() 288 void BasicToolset::newSubfile()
227 { 289 {
228 // TODO: 290 // TODO:

mercurial