30 CFGENTRY (String, defaultName, ""); |
30 CFGENTRY (String, defaultName, ""); |
31 CFGENTRY (String, defaultUser, ""); |
31 CFGENTRY (String, defaultUser, ""); |
32 CFGENTRY (Int, defaultLicense, 0); |
32 CFGENTRY (Int, defaultLicense, 0); |
33 |
33 |
34 // List of all LDObjects |
34 // List of all LDObjects |
35 static QMap<long, LDObjectWeakPtr> g_allObjects; |
35 QMap<long, LDObjectWeakPtr> g_allObjects; |
36 static int32 g_idcursor = 1; // 0 shalt be null |
36 static int32 g_idcursor = 1; // 0 shalt be null |
37 static constexpr int32 g_maxID = (1 << 24); |
37 static constexpr int32 g_maxID = (1 << 24); |
38 |
38 |
39 #define LDOBJ_DEFAULT_CTOR(T,BASE) \ |
39 #define LDOBJ_DEFAULT_CTOR(T,BASE) \ |
40 T :: T (LDObjectPtr* selfptr) : \ |
40 T :: T (LDObjectPtr* selfptr) : \ |
45 // |
45 // |
46 LDObject::LDObject (LDObjectPtr* selfptr) : |
46 LDObject::LDObject (LDObjectPtr* selfptr) : |
47 m_isHidden (false), |
47 m_isHidden (false), |
48 m_isSelected (false), |
48 m_isSelected (false), |
49 m_isDestructed (false), |
49 m_isDestructed (false), |
50 m_document (null), |
|
51 qObjListEntry (null) |
50 qObjListEntry (null) |
52 { |
51 { |
53 *selfptr = LDObjectPtr (this, [](LDObject* obj){ obj->finalDelete(); }); |
52 *selfptr = LDObjectPtr (this, [](LDObject* obj){ obj->finalDelete(); }); |
54 memset (m_coords, 0, sizeof m_coords); |
53 memset (m_coords, 0, sizeof m_coords); |
55 m_self = selfptr->toWeakRef(); |
54 m_self = selfptr->toWeakRef(); |
240 { |
239 { |
241 long idx = lineNumber(); |
240 long idx = lineNumber(); |
242 assert (idx != -1); |
241 assert (idx != -1); |
243 |
242 |
244 // Replace the instance of the old object with the new object |
243 // Replace the instance of the old object with the new object |
245 document()->setObject (idx, other); |
244 document().toStrongRef()->setObject (idx, other); |
246 |
245 |
247 // Remove the old object |
246 // Remove the old object |
248 destroy(); |
247 destroy(); |
249 } |
248 } |
250 |
249 |
251 // ============================================================================= |
250 // ============================================================================= |
252 // |
251 // |
253 void LDObject::swap (LDObjectPtr other) |
252 void LDObject::swap (LDObjectPtr other) |
254 { |
253 { |
255 assert (document() == other->document()); |
254 assert (document() == other->document()); |
256 document()->swapObjects (self(), other); |
255 document().toStrongRef()->swapObjects (self(), other); |
257 } |
256 } |
258 |
257 |
259 // ============================================================================= |
258 // ============================================================================= |
260 // |
259 // |
261 LDLine::LDLine (LDObjectPtr* selfptr, Vertex v1, Vertex v2) : |
260 LDLine::LDLine (LDObjectPtr* selfptr, Vertex v1, Vertex v2) : |
300 // If this object was selected, unselect it now |
299 // If this object was selected, unselect it now |
301 if (isSelected()) |
300 if (isSelected()) |
302 deselect(); |
301 deselect(); |
303 |
302 |
304 // If this object was associated to a file, remove it off it now |
303 // If this object was associated to a file, remove it off it now |
305 if (document()) |
304 if (document() != null) |
306 document()->forgetObject (self()); |
305 document().toStrongRef()->forgetObject (self()); |
307 |
306 |
308 // Delete the GL lists |
307 // Delete the GL lists |
309 g_win->R()->forgetObject (self()); |
308 g_win->R()->forgetObject (self()); |
310 |
309 |
311 // Remove this object from the list of LDObjects |
310 // Remove this object from the list of LDObjects |
422 // ----------------------------------------------------------------------------- |
421 // ----------------------------------------------------------------------------- |
423 long LDObject::lineNumber() const |
422 long LDObject::lineNumber() const |
424 { |
423 { |
425 assert (document() != null); |
424 assert (document() != null); |
426 |
425 |
427 for (int i = 0; i < document()->getObjectCount(); ++i) |
426 for (int i = 0; i < document().toStrongRef()->getObjectCount(); ++i) |
428 if (document()->getObject (i) == this) |
427 if (document().toStrongRef()->getObject (i) == this) |
429 return i; |
428 return i; |
430 |
429 |
431 return -1; |
430 return -1; |
432 } |
431 } |
433 |
432 |
441 // If we move down, we need to iterate the array in reverse order. |
440 // If we move down, we need to iterate the array in reverse order. |
442 const long start = up ? 0 : (objs.size() - 1); |
441 const long start = up ? 0 : (objs.size() - 1); |
443 const long end = up ? objs.size() : -1; |
442 const long end = up ? objs.size() : -1; |
444 const long incr = up ? 1 : -1; |
443 const long incr = up ? 1 : -1; |
445 LDObjectList objsToCompile; |
444 LDObjectList objsToCompile; |
446 LDDocument* file = objs[0]->document(); |
445 LDDocumentPtr file = objs[0]->document(); |
447 |
446 |
448 for (long i = start; i != end; i += incr) |
447 for (long i = start; i != end; i += incr) |
449 { |
448 { |
450 LDObjectPtr obj = objs[i]; |
449 LDObjectPtr obj = objs[i]; |
451 |
450 |
537 LDObjectPtr LDObject::next() const |
536 LDObjectPtr LDObject::next() const |
538 { |
537 { |
539 long idx = lineNumber(); |
538 long idx = lineNumber(); |
540 assert (idx != -1); |
539 assert (idx != -1); |
541 |
540 |
542 if (idx == (long) document()->getObjectCount() - 1) |
541 if (idx == (long) document().toStrongRef()->getObjectCount() - 1) |
543 return LDObjectPtr(); |
542 return LDObjectPtr(); |
544 |
543 |
545 return document()->getObject (idx + 1); |
544 return document().toStrongRef()->getObject (idx + 1); |
546 } |
545 } |
547 |
546 |
548 // ============================================================================= |
547 // ============================================================================= |
549 // |
548 // |
550 LDObjectPtr LDObject::previous() const |
549 LDObjectPtr LDObject::previous() const |
652 |
651 |
653 // ============================================================================= |
652 // ============================================================================= |
654 // |
653 // |
655 void LDSubfile::invert() |
654 void LDSubfile::invert() |
656 { |
655 { |
|
656 if (document() == null) |
|
657 return; |
|
658 |
657 // Check whether subfile is flat |
659 // Check whether subfile is flat |
658 int axisSet = (1 << X) | (1 << Y) | (1 << Z); |
660 int axisSet = (1 << X) | (1 << Y) | (1 << Z); |
659 LDObjectList objs = inlineContents (true, false); |
661 LDObjectList objs = inlineContents (true, false); |
660 |
662 |
661 for (LDObjectPtr obj : objs) |
663 for (LDObjectPtr obj : objs) |
711 return; |
713 return; |
712 } |
714 } |
713 } |
715 } |
714 |
716 |
715 // Not inverted, thus prefix it with a new invertnext. |
717 // Not inverted, thus prefix it with a new invertnext. |
716 document()->insertObj (idx, spawn<LDBFC> (LDBFC::InvertNext)); |
718 document().toStrongRef()->insertObj (idx, spawn<LDBFC> (LDBFC::InvertNext)); |
717 } |
719 } |
718 |
720 |
719 // ============================================================================= |
721 // ============================================================================= |
720 // |
722 // |
721 void LDLine::invert() |
723 void LDLine::invert() |
823 // ============================================================================= |
825 // ============================================================================= |
824 // |
826 // |
825 void LDObject::setVertex (int i, const Vertex& vert) |
827 void LDObject::setVertex (int i, const Vertex& vert) |
826 { |
828 { |
827 if (document() != null) |
829 if (document() != null) |
828 document()->vertexChanged (*m_coords[i], vert); |
830 document().toStrongRef()->vertexChanged (*m_coords[i], vert); |
829 |
831 |
830 changeProperty (self(), &m_coords[i], LDSharedVertex::getSharedVertex (vert)); |
832 changeProperty (self(), &m_coords[i], LDSharedVertex::getSharedVertex (vert)); |
831 } |
833 } |
832 |
834 |
833 // ============================================================================= |
835 // ============================================================================= |
835 void LDMatrixObject::setPosition (const Vertex& a) |
837 void LDMatrixObject::setPosition (const Vertex& a) |
836 { |
838 { |
837 LDObjectPtr ref = linkPointer().toStrongRef(); |
839 LDObjectPtr ref = linkPointer().toStrongRef(); |
838 |
840 |
839 if (ref->document() != null) |
841 if (ref->document() != null) |
840 ref->document()->removeKnownVerticesOf (ref); |
842 ref->document().toStrongRef()->removeKnownVerticesOf (ref); |
841 |
843 |
842 changeProperty (ref, &m_position, LDSharedVertex::getSharedVertex (a)); |
844 changeProperty (ref, &m_position, LDSharedVertex::getSharedVertex (a)); |
843 |
845 |
844 if (ref->document() != null) |
846 if (ref->document() != null) |
845 ref->document()->addKnownVerticesOf (ref); |
847 ref->document().toStrongRef()->addKnownVerticesOf (ref); |
846 } |
848 } |
847 |
849 |
848 // ============================================================================= |
850 // ============================================================================= |
849 // |
851 // |
850 void LDMatrixObject::setTransform (const Matrix& val) |
852 void LDMatrixObject::setTransform (const Matrix& val) |
851 { |
853 { |
852 LDObjectPtr ref = linkPointer().toStrongRef(); |
854 LDObjectPtr ref = linkPointer().toStrongRef(); |
853 |
855 |
854 if (ref->document() != null) |
856 if (ref->document() != null) |
855 ref->document()->removeKnownVerticesOf (ref); |
857 ref->document().toStrongRef()->removeKnownVerticesOf (ref); |
856 |
858 |
857 changeProperty (ref, &m_transform, val); |
859 changeProperty (ref, &m_transform, val); |
858 |
860 |
859 if (ref->document() != null) |
861 if (ref->document() != null) |
860 ref->document()->addKnownVerticesOf (ref); |
862 ref->document().toStrongRef()->addKnownVerticesOf (ref); |
861 } |
863 } |
862 |
864 |
863 // ============================================================================= |
865 // ============================================================================= |
864 // |
866 // |
865 static QMap<Vertex, LDSharedVertex*> g_sharedVerts; |
867 static QMap<Vertex, LDSharedVertex*> g_sharedVerts; |
901 // ============================================================================= |
903 // ============================================================================= |
902 // |
904 // |
903 void LDObject::select() |
905 void LDObject::select() |
904 { |
906 { |
905 assert (document() != null); |
907 assert (document() != null); |
906 document()->addToSelection (self()); |
908 document().toStrongRef()->addToSelection (self()); |
907 |
909 |
908 // If this object is inverted with INVERTNEXT, pick the INVERTNEXT as well. |
910 // If this object is inverted with INVERTNEXT, pick the INVERTNEXT as well. |
909 LDBFCPtr invertnext; |
911 LDBFCPtr invertnext; |
910 |
912 |
911 if (previousIsInvertnext (invertnext)) |
913 if (previousIsInvertnext (invertnext)) |
915 // ============================================================================= |
917 // ============================================================================= |
916 // |
918 // |
917 void LDObject::deselect() |
919 void LDObject::deselect() |
918 { |
920 { |
919 assert (document() != null); |
921 assert (document() != null); |
920 document()->removeFromSelection (self()); |
922 document().toStrongRef()->removeFromSelection (self()); |
921 |
923 |
922 // If this object is inverted with INVERTNEXT, deselect the INVERTNEXT as well. |
924 // If this object is inverted with INVERTNEXT, deselect the INVERTNEXT as well. |
923 LDBFCPtr invertnext; |
925 LDBFCPtr invertnext; |
924 |
926 |
925 if (previousIsInvertnext (invertnext)) |
927 if (previousIsInvertnext (invertnext)) |
954 return copy; |
956 return copy; |
955 } |
957 } |
956 |
958 |
957 // ============================================================================= |
959 // ============================================================================= |
958 // |
960 // |
959 void LDSubfile::setFileInfo (const LDDocumentPointer& a) |
961 void LDSubfile::setFileInfo (const LDDocumentPtr& a) |
960 { |
962 { |
961 if (document() != null) |
963 if (document() != null) |
962 document()->removeKnownVerticesOf (self()); |
964 document().toStrongRef()->removeKnownVerticesOf (self()); |
963 |
965 |
964 m_fileInfo = a; |
966 m_fileInfo = a; |
965 |
967 |
966 // If it's an immediate subfile reference (i.e. this subfile belongs in an |
968 // If it's an immediate subfile reference (i.e. this subfile belongs in an |
967 // explicit file), we need to pre-compile the GL polygons for the document |
969 // explicit file), we need to pre-compile the GL polygons for the document |