src/ldObject.cc

changeset 861
83426c5fa732
parent 857
e62983881460
child 867
557cb07dbe57
equal deleted inserted replaced
860:a496e72af069 861:83426c5fa732
84 return; 84 return;
85 } 85 }
86 86
87 // In case someone does, we cannot really continue execution. We must abort, 87 // In case someone does, we cannot really continue execution. We must abort,
88 // give the user a chance to save their documents though. 88 // give the user a chance to save their documents though.
89 critical ("Created too many objects. Execution cannot continue. You have a " 89 CriticalError ("Created too many objects. Execution cannot continue. You have a "
90 "chance to save any changes to documents, then restart."); 90 "chance to save any changes to documents, then restart.");
91 (void) safeToCloseAll(); 91 (void) IsSafeToCloseAll();
92 Exit(); 92 Exit();
93 } 93 }
94 94
95 // ============================================================================= 95 // =============================================================================
96 // 96 //
218 // 0---3 0---3 3 218 // 0---3 0---3 3
219 // | | | / /| 219 // | | | / /|
220 // | | ==> | / / | 220 // | | ==> | / / |
221 // | | |/ / | 221 // | | |/ / |
222 // 1---2 1 1---2 222 // 1---2 1 1---2
223 LDTrianglePtr tri1 (spawn<LDTriangle> (vertex (0), vertex (1), vertex (3))); 223 LDTrianglePtr tri1 (LDSpawn<LDTriangle> (vertex (0), vertex (1), vertex (3)));
224 LDTrianglePtr tri2 (spawn<LDTriangle> (vertex (1), vertex (2), vertex (3))); 224 LDTrianglePtr tri2 (LDSpawn<LDTriangle> (vertex (1), vertex (2), vertex (3)));
225 225
226 // The triangles also inherit the quad's color 226 // The triangles also inherit the quad's color
227 tri1->setColor (color()); 227 tri1->setColor (color());
228 tri2->setColor (color()); 228 tri2->setColor (color());
229 229
335 delete this; 335 delete this;
336 } 336 }
337 337
338 // ============================================================================= 338 // =============================================================================
339 // 339 //
340 static void transformObject (LDObjectPtr obj, Matrix transform, Vertex pos, LDColor parentcolor) 340 static void TransformObject (LDObjectPtr obj, Matrix transform, Vertex pos, LDColor parentcolor)
341 { 341 {
342 switch (obj->type()) 342 switch (obj->type())
343 { 343 {
344 case OBJ_Line: 344 case OBJ_Line:
345 case OBJ_CondLine: 345 case OBJ_CondLine:
346 case OBJ_Triangle: 346 case OBJ_Triangle:
347 case OBJ_Quad: 347 case OBJ_Quad:
348
349 for (int i = 0; i < obj->numVertices(); ++i) 348 for (int i = 0; i < obj->numVertices(); ++i)
350 { 349 {
351 Vertex v = obj->vertex (i); 350 Vertex v = obj->vertex (i);
352 v.transform (transform, pos); 351 v.transform (transform, pos);
353 obj->setVertex (i, v); 352 obj->setVertex (i, v);
361 Matrix newMatrix = transform * ref->transform(); 360 Matrix newMatrix = transform * ref->transform();
362 Vertex newpos = ref->position(); 361 Vertex newpos = ref->position();
363 newpos.transform (transform, pos); 362 newpos.transform (transform, pos);
364 ref->setPosition (newpos); 363 ref->setPosition (newpos);
365 ref->setTransform (newMatrix); 364 ref->setTransform (newMatrix);
365 break;
366 } 366 }
367 break;
368 367
369 default: 368 default:
370 break; 369 break;
371 } 370 }
372 371
373 if (obj->color() == maincolor()) 372 if (obj->color() == MainColor())
374 obj->setColor (parentcolor); 373 obj->setColor (parentcolor);
375 } 374 }
376 375
377 // ============================================================================= 376 // =============================================================================
378 // ----------------------------------------------------------------------------- 377 // -----------------------------------------------------------------------------
383 // Transform the objects 382 // Transform the objects
384 for (LDObjectPtr obj : objs) 383 for (LDObjectPtr obj : objs)
385 { 384 {
386 // Set the parent now so we know what inlined the object. 385 // Set the parent now so we know what inlined the object.
387 obj->setParent (self()); 386 obj->setParent (self());
388 transformObject (obj, transform(), position(), color()); 387 TransformObject (obj, transform(), position(), color());
389 } 388 }
390 389
391 return objs; 390 return objs;
392 } 391 }
393 392
480 objsToCompile << file->getObject (target); 479 objsToCompile << file->getObject (target);
481 480
482 obj->swap (file->getObject (target)); 481 obj->swap (file->getObject (target));
483 } 482 }
484 483
485 removeDuplicates (objsToCompile); 484 RemoveDuplicates (objsToCompile);
486 485
487 // The objects need to be recompiled, otherwise their pick lists are left with 486 // The objects need to be recompiled, otherwise their pick lists are left with
488 // the wrong index colors which messes up selection. 487 // the wrong index colors which messes up selection.
489 for (LDObjectPtr obj : objsToCompile) 488 for (LDObjectPtr obj : objsToCompile)
490 g_win->R()->compileObject (obj); 489 g_win->R()->compileObject (obj);
520 continue; 519 continue;
521 520
522 if (not text.isEmpty()) 521 if (not text.isEmpty())
523 text += ", "; 522 text += ", ";
524 523
525 QString noun = format ("%1%2", typeName (objType), plural (count)); 524 QString noun = format ("%1%2", typeName (objType), Plural (count));
526 525
527 // Plural of "vertex" is "vertices", correct that 526 // Plural of "vertex" is "vertices", correct that
528 if (objType == OBJ_Vertex and count != 1) 527 if (objType == OBJ_Vertex and count != 1)
529 noun = "vertices"; 528 noun = "vertices";
530 529
616 // 615 //
617 LDObjectPtr LDObject::getDefault (const LDObjectType type) 616 LDObjectPtr LDObject::getDefault (const LDObjectType type)
618 { 617 {
619 switch (type) 618 switch (type)
620 { 619 {
621 case OBJ_Comment: return spawn<LDComment>(); 620 case OBJ_Comment: return LDSpawn<LDComment>();
622 case OBJ_BFC: return spawn<LDBFC>(); 621 case OBJ_BFC: return LDSpawn<LDBFC>();
623 case OBJ_Line: return spawn<LDLine>(); 622 case OBJ_Line: return LDSpawn<LDLine>();
624 case OBJ_CondLine: return spawn<LDCondLine>(); 623 case OBJ_CondLine: return LDSpawn<LDCondLine>();
625 case OBJ_Subfile: return spawn<LDSubfile>(); 624 case OBJ_Subfile: return LDSpawn<LDSubfile>();
626 case OBJ_Triangle: return spawn<LDTriangle>(); 625 case OBJ_Triangle: return LDSpawn<LDTriangle>();
627 case OBJ_Quad: return spawn<LDQuad>(); 626 case OBJ_Quad: return LDSpawn<LDQuad>();
628 case OBJ_Empty: return spawn<LDEmpty>(); 627 case OBJ_Empty: return LDSpawn<LDEmpty>();
629 case OBJ_Error: return spawn<LDError>(); 628 case OBJ_Error: return LDSpawn<LDError>();
630 case OBJ_Vertex: return spawn<LDVertex>(); 629 case OBJ_Vertex: return LDSpawn<LDVertex>();
631 case OBJ_Overlay: return spawn<LDOverlay>(); 630 case OBJ_Overlay: return LDSpawn<LDOverlay>();
632 case OBJ_NumTypes: assert (false); 631 case OBJ_NumTypes: assert (false);
633 } 632 }
634 return LDObjectPtr(); 633 return LDObjectPtr();
635 } 634 }
636 635
700 699
701 if (axisSet != 0) 700 if (axisSet != 0)
702 { 701 {
703 // Subfile has all vertices zero on one specific plane, so it is flat. 702 // Subfile has all vertices zero on one specific plane, so it is flat.
704 // Let's flip it. 703 // Let's flip it.
705 Matrix matrixModifier = g_identity; 704 Matrix matrixModifier = IdentityMatrix;
706 705
707 if (axisSet & (1 << X)) 706 if (axisSet & (1 << X))
708 matrixModifier[0] = -1; 707 matrixModifier[0] = -1;
709 708
710 if (axisSet & (1 << Y)) 709 if (axisSet & (1 << Y))
731 return; 730 return;
732 } 731 }
733 } 732 }
734 733
735 // Not inverted, thus prefix it with a new invertnext. 734 // Not inverted, thus prefix it with a new invertnext.
736 document().toStrongRef()->insertObj (idx, spawn<LDBFC> (BFCStatement::InvertNext)); 735 document().toStrongRef()->insertObj (idx, LDSpawn<LDBFC> (BFCStatement::InvertNext));
737 } 736 }
738 737
739 // ============================================================================= 738 // =============================================================================
740 // 739 //
741 void LDLine::invert() 740 void LDLine::invert()
761 760
762 // ============================================================================= 761 // =============================================================================
763 // 762 //
764 LDLinePtr LDCondLine::toEdgeLine() 763 LDLinePtr LDCondLine::toEdgeLine()
765 { 764 {
766 LDLinePtr replacement (spawn<LDLine>()); 765 LDLinePtr replacement (LDSpawn<LDLine>());
767 766
768 for (int i = 0; i < replacement->numVertices(); ++i) 767 for (int i = 0; i < replacement->numVertices(); ++i)
769 replacement->setVertex (i, vertex (i)); 768 replacement->setVertex (i, vertex (i));
770 769
771 replacement->setColor (color()); 770 replacement->setColor (color());
818 817
819 if (before != after) 818 if (before != after)
820 { 819 {
821 obj->document().toStrongRef()->addToHistory (new EditHistory (idx, before, after)); 820 obj->document().toStrongRef()->addToHistory (new EditHistory (idx, before, after));
822 g_win->R()->compileObject (obj); 821 g_win->R()->compileObject (obj);
823 getCurrentDocument()->redoVertices(); 822 CurrentDocument()->redoVertices();
824 } 823 }
825 } 824 }
826 else 825 else
827 *ptr = val; 826 *ptr = val;
828 } 827 }
899 898
900 // ============================================================================= 899 // =============================================================================
901 // 900 //
902 LDObjectPtr LDObject::createCopy() const 901 LDObjectPtr LDObject::createCopy() const
903 { 902 {
904 LDObjectPtr copy = parseLine (asText()); 903 LDObjectPtr copy = ParseLine (asText());
905 return copy; 904 return copy;
906 } 905 }
907 906
908 // ============================================================================= 907 // =============================================================================
909 // 908 //

mercurial