src/ldtypes.cpp

changeset 516
d3373bc7ca3b
parent 506
525f6c48db83
child 521
b85554206155
equal deleted inserted replaced
515:a0ad72800b96 516:d3373bc7ca3b
40 m_selected (false), 40 m_selected (false),
41 m_parent (null), 41 m_parent (null),
42 m_file (null), 42 m_file (null),
43 qObjListEntry (null), 43 qObjListEntry (null),
44 m_glinit (false) 44 m_glinit (false)
45 { // Determine ID 45 {
46 memset (m_coords, 0, sizeof m_coords);
47
48 // Determine ID
46 int32 id = 1; // 0 is invalid 49 int32 id = 1; // 0 is invalid
47 50
48 for (LDObject * obj : g_LDObjects) 51 for (LDObject* obj : g_LDObjects)
49 if (obj->id() >= id) 52 if (obj->id() >= id)
50 id = obj->id() + 1; 53 id = obj->id() + 1;
51 54
52 setID (id); 55 setID (id);
53 g_LDObjects << this; 56 g_LDObjects << this;
659 // ============================================================================= 662 // =============================================================================
660 // Hook the set accessors of certain properties to this changeProperty function. 663 // Hook the set accessors of certain properties to this changeProperty function.
661 // It takes care of history management so we can capture low-level changes, this 664 // It takes care of history management so we can capture low-level changes, this
662 // makes history stuff work out of the box. 665 // makes history stuff work out of the box.
663 // ----------------------------------------------------------------------------- 666 // -----------------------------------------------------------------------------
664 template<class T> void changeProperty (LDObject* obj, T* ptr, const T& val) 667 template<class T> static void changeProperty (LDObject* obj, T* ptr, const T& val)
665 { long idx; 668 { long idx;
666 669
667 if (obj->file() && (idx = obj->getIndex()) != -1) 670 if (obj->file() && (idx = obj->getIndex()) != -1)
668 { str before = obj->raw(); 671 { str before = obj->raw();
669 *ptr = val; 672 *ptr = val;
686 } 689 }
687 690
688 // ============================================================================= 691 // =============================================================================
689 // ----------------------------------------------------------------------------- 692 // -----------------------------------------------------------------------------
690 const vertex& LDObject::getVertex (int i) const 693 const vertex& LDObject::getVertex (int i) const
691 { return m_coords[i]; 694 { return m_coords[i]->data();
692 } 695 }
693 696
694 void LDObject::setVertex (int i, const vertex& vert) 697 void LDObject::setVertex (int i, const vertex& vert)
695 { changeProperty (this, &m_coords[i], vert); 698 { changeProperty (this, &m_coords[i], LDSharedVertex::getSharedVertex (vert));
696 } 699 }
697 700
698 // ============================================================================= 701 // =============================================================================
699 // ----------------------------------------------------------------------------- 702 // -----------------------------------------------------------------------------
700 READ_ACCESSOR (vertex, LDMatrixObject::position) 703 void LDMatrixObject::setPosition (const vertex& a)
701 { return m_position; 704 { changeProperty (linkPointer(), &m_position, LDSharedVertex::getSharedVertex (a));
702 }
703
704 SET_ACCESSOR (vertex, LDMatrixObject::setPosition)
705 { changeProperty (linkPointer(), &m_position, val);
706 } 705 }
707 706
708 // ============================================================================= 707 // =============================================================================
709 // ----------------------------------------------------------------------------- 708 // -----------------------------------------------------------------------------
710 READ_ACCESSOR (matrix, LDMatrixObject::transform) 709 READ_ACCESSOR (matrix, LDMatrixObject::transform)
712 } 711 }
713 712
714 SET_ACCESSOR (matrix, LDMatrixObject::setTransform) 713 SET_ACCESSOR (matrix, LDMatrixObject::setTransform)
715 { changeProperty (linkPointer(), &m_transform, val); 714 { changeProperty (linkPointer(), &m_transform, val);
716 } 715 }
716
717 // =============================================================================
718 // -----------------------------------------------------------------------------
719 static QMap<vertex, LDSharedVertex*> g_sharedVerts;
720
721 LDSharedVertex* LDSharedVertex::getSharedVertex (const vertex& a)
722 { auto it = g_sharedVerts.find (a);
723
724 if (it == g_sharedVerts.end())
725 { LDSharedVertex* v = new LDSharedVertex (a);
726 g_sharedVerts[a] = v;
727 return v;
728 }
729
730 return *it;
731 }
732
733 // =============================================================================
734 // -----------------------------------------------------------------------------
735 void LDSharedVertex::addRef(LDObject* a)
736 { m_refs << a;
737 }
738
739 // =============================================================================
740 // -----------------------------------------------------------------------------
741 void LDSharedVertex::delRef (LDObject* a)
742 { m_refs.removeOne (a);
743
744 if (m_refs.empty())
745 { g_sharedVerts.remove (m_data);
746 delete this;
747 }
748 }

mercurial