61 |
61 |
62 QList<LDTriangle*> triangles = it->splitToTriangles(); |
62 QList<LDTriangle*> triangles = it->splitToTriangles(); |
63 |
63 |
64 // Replace the quad with the first triangle and add the second triangle |
64 // Replace the quad with the first triangle and add the second triangle |
65 // after the first one. |
65 // after the first one. |
66 CurrentDocument()->setObject (index, triangles[0]); |
66 currentDocument()->setObject (index, triangles[0]); |
67 CurrentDocument()->insertObj (index + 1, triangles[1]); |
67 currentDocument()->insertObj (index + 1, triangles[1]); |
68 num++; |
68 num++; |
69 } |
69 } |
70 |
70 |
71 print ("%1 quadrilaterals split", num); |
71 print ("%1 quadrilaterals split", num); |
72 } |
72 } |
73 |
73 |
74 void AlgorithmToolset::editRaw() |
74 void AlgorithmToolset::editRaw() |
75 { |
75 { |
76 if (Selection().size() != 1) |
76 if (selectedObjects().size() != 1) |
77 return; |
77 return; |
78 |
78 |
79 LDObject* obj = Selection()[0]; |
79 LDObject* obj = selectedObjects()[0]; |
80 QDialog* dlg = new QDialog; |
80 QDialog* dlg = new QDialog; |
81 Ui::EditRawUI ui; |
81 Ui::EditRawUI ui; |
82 |
82 |
83 ui.setupUi (dlg); |
83 ui.setupUi (dlg); |
84 ui.code->setText (obj->asText()); |
84 ui.code->setText (obj->asText()); |
99 obj->replace (newobj); |
99 obj->replace (newobj); |
100 } |
100 } |
101 |
101 |
102 void AlgorithmToolset::makeBorders() |
102 void AlgorithmToolset::makeBorders() |
103 { |
103 { |
104 LDObjectList objs = Selection(); |
104 LDObjectList objs = selectedObjects(); |
105 int num = 0; |
105 int num = 0; |
106 |
106 |
107 for (LDObject* obj : objs) |
107 for (LDObject* obj : objs) |
108 { |
108 { |
109 const LDObjectType type = obj->type(); |
109 const LDObjectType type = obj->type(); |
210 |
210 |
211 if (ui.x->isChecked()) sel << X; |
211 if (ui.x->isChecked()) sel << X; |
212 if (ui.y->isChecked()) sel << Y; |
212 if (ui.y->isChecked()) sel << Y; |
213 if (ui.z->isChecked()) sel << Z; |
213 if (ui.z->isChecked()) sel << Z; |
214 |
214 |
215 for (LDObject* obj : Selection()) |
215 for (LDObject* obj : selectedObjects()) |
216 { |
216 { |
217 for (int i = 0; i < obj->numVertices(); ++i) |
217 for (int i = 0; i < obj->numVertices(); ++i) |
218 { |
218 { |
219 Vertex v = obj->vertex (i); |
219 Vertex v = obj->vertex (i); |
220 |
220 |
253 |
253 |
254 if (ui.x->isChecked()) sel << X; |
254 if (ui.x->isChecked()) sel << X; |
255 if (ui.y->isChecked()) sel << Y; |
255 if (ui.y->isChecked()) sel << Y; |
256 if (ui.z->isChecked()) sel << Z; |
256 if (ui.z->isChecked()) sel << Z; |
257 |
257 |
258 for (LDObject* obj : Selection()) |
258 for (LDObject* obj : selectedObjects()) |
259 { |
259 { |
260 for (int i = 0; i < obj->numVertices(); ++i) |
260 for (int i = 0; i < obj->numVertices(); ++i) |
261 { |
261 { |
262 Vertex v = obj->vertex (i); |
262 Vertex v = obj->vertex (i); |
263 |
263 |
274 |
274 |
275 void AlgorithmToolset::demote() |
275 void AlgorithmToolset::demote() |
276 { |
276 { |
277 int num = 0; |
277 int num = 0; |
278 |
278 |
279 for (LDObjectIterator<LDCondLine> it (Selection()); it.isValid(); ++it) |
279 for (LDObjectIterator<LDCondLine> it (selectedObjects()); it.isValid(); ++it) |
280 { |
280 { |
281 it->toEdgeLine(); |
281 it->toEdgeLine(); |
282 ++num; |
282 ++num; |
283 } |
283 } |
284 |
284 |
285 print (tr ("Converted %1 conditional lines"), num); |
285 print (tr ("Converted %1 conditional lines"), num); |
286 } |
286 } |
287 |
287 |
288 bool AlgorithmToolset::isColorUsed (LDColor color) const |
288 bool AlgorithmToolset::isColorUsed (LDColor color) |
289 { |
289 { |
290 for (LDObject* obj : CurrentDocument()->objects()) |
290 for (LDObject* obj : currentDocument()->objects()) |
291 { |
291 { |
292 if (obj->isColored() and obj->color() == color) |
292 if (obj->isColored() and obj->color() == color) |
293 return true; |
293 return true; |
294 } |
294 } |
295 |
295 |
344 ui->m_date->date().toString ("yyyy-MM-dd"), |
344 ui->m_date->date().toString ("yyyy-MM-dd"), |
345 ui->m_username->text(), |
345 ui->m_username->text(), |
346 ui->m_comment->text())); |
346 ui->m_comment->text())); |
347 |
347 |
348 // Find a spot to place the new comment |
348 // Find a spot to place the new comment |
349 for (obj = CurrentDocument()->getObject (0); |
349 for (obj = currentDocument()->getObject (0); |
350 obj and obj->next() and not obj->next()->isScemantic(); |
350 obj and obj->next() and not obj->next()->isScemantic(); |
351 obj = obj->next()) |
351 obj = obj->next()) |
352 { |
352 { |
353 LDComment* comment = dynamic_cast<LDComment*> (obj); |
353 LDComment* comment = dynamic_cast<LDComment*> (obj); |
354 |
354 |
360 |
360 |
361 prevIsHistory = ishistory; |
361 prevIsHistory = ishistory; |
362 } |
362 } |
363 |
363 |
364 int idx = obj ? obj->lineNumber() : 0; |
364 int idx = obj ? obj->lineNumber() : 0; |
365 CurrentDocument()->insertObj (idx++, comment); |
365 currentDocument()->insertObj (idx++, comment); |
366 |
366 |
367 // If we're adding a history line right before a scemantic object, pad it |
367 // If we're adding a history line right before a scemantic object, pad it |
368 // an empty line |
368 // an empty line |
369 if (obj and obj->next() and obj->next()->isScemantic()) |
369 if (obj and obj->next() and obj->next()->isScemantic()) |
370 CurrentDocument()->insertObj (idx, new LDEmpty); |
370 currentDocument()->insertObj (idx, new LDEmpty); |
371 |
371 |
372 m_window->buildObjList(); |
372 m_window->buildObjList(); |
373 delete ui; |
373 delete ui; |
374 } |
374 } |
375 |
375 |
382 if (not ok) |
382 if (not ok) |
383 return; |
383 return; |
384 |
384 |
385 m_config->setSplitLinesSegments (segments); |
385 m_config->setSplitLinesSegments (segments); |
386 |
386 |
387 for (LDObject* obj : Selection()) |
387 for (LDObject* obj : selectedObjects()) |
388 { |
388 { |
389 if (not isOneOf (obj->type(), OBJ_Line, OBJ_CondLine)) |
389 if (not isOneOf (obj->type(), OBJ_Line, OBJ_CondLine)) |
390 continue; |
390 continue; |
391 |
391 |
392 QVector<LDObject*> newsegs; |
392 QVector<LDObject*> newsegs; |
417 } |
417 } |
418 |
418 |
419 int ln = obj->lineNumber(); |
419 int ln = obj->lineNumber(); |
420 |
420 |
421 for (LDObject* seg : newsegs) |
421 for (LDObject* seg : newsegs) |
422 CurrentDocument()->insertObj (ln++, seg); |
422 currentDocument()->insertObj (ln++, seg); |
423 |
423 |
424 obj->destroy(); |
424 obj->destroy(); |
425 } |
425 } |
426 |
426 |
427 m_window->buildObjList(); |
427 m_window->buildObjList(); |
428 m_window->refresh(); |
428 m_window->refresh(); |
429 } |
429 } |
430 |
430 |
431 void AlgorithmToolset::subfileSelection() |
431 void AlgorithmToolset::subfileSelection() |
432 { |
432 { |
433 if (Selection().size() == 0) |
433 if (selectedObjects().size() == 0) |
434 return; |
434 return; |
435 |
435 |
436 QString parentpath (CurrentDocument()->fullPath()); |
436 QString parentpath (currentDocument()->fullPath()); |
437 |
437 |
438 // BFC type of the new subfile - it shall inherit the BFC type of the parent document |
438 // BFC type of the new subfile - it shall inherit the BFC type of the parent document |
439 BFCStatement bfctype (BFCStatement::NoCertify); |
439 BFCStatement bfctype (BFCStatement::NoCertify); |
440 |
440 |
441 // Dirname of the new subfile |
441 // Dirname of the new subfile |
443 |
443 |
444 // Title of the new subfile |
444 // Title of the new subfile |
445 QString subtitle; |
445 QString subtitle; |
446 |
446 |
447 // Comment containing the title of the parent document |
447 // Comment containing the title of the parent document |
448 LDComment* titleobj = dynamic_cast<LDComment*> (CurrentDocument()->getObject (0)); |
448 LDComment* titleobj = dynamic_cast<LDComment*> (currentDocument()->getObject (0)); |
449 |
449 |
450 // License text for the subfile |
450 // License text for the subfile |
451 QString license (PreferredLicenseText()); |
451 QString license (PreferredLicenseText()); |
452 |
452 |
453 // LDraw code body of the new subfile (i.e. code of the selection) |
453 // LDraw code body of the new subfile (i.e. code of the selection) |
455 |
455 |
456 // Full path of the subfile to be |
456 // Full path of the subfile to be |
457 QString fullsubname; |
457 QString fullsubname; |
458 |
458 |
459 // Where to insert the subfile reference? |
459 // Where to insert the subfile reference? |
460 int refidx (Selection()[0]->lineNumber()); |
460 int refidx (selectedObjects()[0]->lineNumber()); |
461 |
461 |
462 // Determine title of subfile |
462 // Determine title of subfile |
463 if (titleobj != null) |
463 if (titleobj != null) |
464 subtitle = "~" + titleobj->text(); |
464 subtitle = "~" + titleobj->text(); |
465 else |
465 else |
469 while (subtitle.startsWith ("~~")) |
469 while (subtitle.startsWith ("~~")) |
470 subtitle.remove (0, 1); |
470 subtitle.remove (0, 1); |
471 |
471 |
472 // If this the parent document isn't already in s/, we need to stuff it into |
472 // If this the parent document isn't already in s/, we need to stuff it into |
473 // a subdirectory named s/. Ensure it exists! |
473 // a subdirectory named s/. Ensure it exists! |
474 QString topdirname = Basename (Dirname (CurrentDocument()->fullPath())); |
474 QString topdirname = Basename (Dirname (currentDocument()->fullPath())); |
475 |
475 |
476 if (topdirname != "s") |
476 if (topdirname != "s") |
477 { |
477 { |
478 QString desiredPath = subdirname + "/s"; |
478 QString desiredPath = subdirname + "/s"; |
479 QString title = tr ("Create subfile directory?"); |
479 QString title = tr ("Create subfile directory?"); |
519 } while (FindDocument ("s\\" + Basename (fullsubname)) != null or QFile (fullsubname).exists()); |
519 } while (FindDocument ("s\\" + Basename (fullsubname)) != null or QFile (fullsubname).exists()); |
520 } |
520 } |
521 |
521 |
522 // Determine the BFC winding type used in the main document - it is to |
522 // Determine the BFC winding type used in the main document - it is to |
523 // be carried over to the subfile. |
523 // be carried over to the subfile. |
524 for (LDObjectIterator<LDBFC> it (CurrentDocument()); it.isValid(); ++it) |
524 for (LDObjectIterator<LDBFC> it (currentDocument()); it.isValid(); ++it) |
525 { |
525 { |
526 if (isOneOf (it->statement(), BFCStatement::CertifyCCW, BFCStatement::CertifyCW, BFCStatement::NoCertify)) |
526 if (isOneOf (it->statement(), BFCStatement::CertifyCCW, BFCStatement::CertifyCW, BFCStatement::NoCertify)) |
527 { |
527 { |
528 bfctype = it->statement(); |
528 bfctype = it->statement(); |
529 break; |
529 break; |
530 } |
530 } |
531 } |
531 } |
532 |
532 |
533 // Get the body of the document in LDraw code |
533 // Get the body of the document in LDraw code |
534 for (LDObject* obj : Selection()) |
534 for (LDObject* obj : selectedObjects()) |
535 code << obj->asText(); |
535 code << obj->asText(); |
536 |
536 |
537 // Create the new subfile document |
537 // Create the new subfile document |
538 LDDocument* doc = LDDocument::createNew(); |
538 LDDocument* doc = m_window->newDocument(); |
539 doc->setImplicit (false); |
539 doc->setImplicit (false); |
540 doc->setFullPath (fullsubname); |
540 doc->setFullPath (fullsubname); |
541 doc->setName (LDDocument::shortenName (fullsubname)); |
541 doc->setName (LDDocument::shortenName (fullsubname)); |
542 |
542 |
543 LDObjectList objs; |
543 LDObjectList objs; |
565 // Try save it |
565 // Try save it |
566 if (m_window->save (doc, true)) |
566 if (m_window->save (doc, true)) |
567 { |
567 { |
568 // Save was successful. Delete the original selection now from the |
568 // Save was successful. Delete the original selection now from the |
569 // main document. |
569 // main document. |
570 for (LDObject* obj : Selection()) |
570 for (LDObject* obj : selectedObjects()) |
571 obj->destroy(); |
571 obj->destroy(); |
572 |
572 |
573 // Add a reference to the new subfile to where the selection was |
573 // Add a reference to the new subfile to where the selection was |
574 LDSubfile* ref = LDSpawn<LDSubfile>(); |
574 LDSubfile* ref = LDSpawn<LDSubfile>(); |
575 ref->setColor (MainColor); |
575 ref->setColor (MainColor); |
576 ref->setFileInfo (doc); |
576 ref->setFileInfo (doc); |
577 ref->setPosition (Origin); |
577 ref->setPosition (Origin); |
578 ref->setTransform (IdentityMatrix); |
578 ref->setTransform (IdentityMatrix); |
579 CurrentDocument()->insertObj (refidx, ref); |
579 currentDocument()->insertObj (refidx, ref); |
580 |
580 |
581 // Refresh stuff |
581 // Refresh stuff |
582 m_window->updateDocumentList(); |
582 m_window->updateDocumentList(); |
583 m_window->doFullRefresh(); |
583 m_window->doFullRefresh(); |
584 } |
584 } |