Mon, 30 Jan 2017 00:59:06 +0200
The "all objects have valid models" invariant seems to be holding up now. At least basic drawing works again.
src/editmodes/circleMode.cpp | file | annotate | diff | comparison | revisions | |
src/ldObject.cpp | file | annotate | diff | comparison | revisions | |
src/ldObject.h | file | annotate | diff | comparison | revisions | |
src/model.cpp | file | annotate | diff | comparison | revisions | |
src/model.h | file | annotate | diff | comparison | revisions |
--- a/src/editmodes/circleMode.cpp Sun Jan 29 21:17:43 2017 +0200 +++ b/src/editmodes/circleMode.cpp Mon Jan 30 00:59:06 2017 +0200 @@ -125,10 +125,7 @@ { primitiveModel.ringNumber = component.num; primitiveFile = primitives()->getPrimitive(primitiveModel); - LDSubfileReference* ref = model.emplace<LDSubfileReference>(); - ref->setFileInfo(primitiveFile); - ref->setTransformationMatrix(getCircleDrawMatrix(component.scale)); - ref->setPosition(m_drawedVerts[0]); + model.emplace<LDSubfileReference>(primitiveFile, getCircleDrawMatrix(component.scale), m_drawedVerts.first()); } } else @@ -172,13 +169,7 @@ } if (circleOrDisc and primitiveFile) - { - LDSubfileReference* ref = model.emplace<LDSubfileReference>(); - ref->setFileInfo (primitiveFile); - ref->setTransformationMatrix (transform); - ref->setPosition (m_drawedVerts[0]); - ref->setColor (MainColor); - } + model.emplace<LDSubfileReference>(primitiveFile, transform, m_drawedVerts.first()); if (not model.isEmpty()) {
--- a/src/ldObject.cpp Sun Jan 29 21:17:43 2017 +0200 +++ b/src/ldObject.cpp Mon Jan 30 00:59:06 2017 +0200 @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - +#include <assert.h> #include "main.h" #include "ldObject.h" #include "ldDocument.h" @@ -44,14 +44,12 @@ // LDObject constructors // LDObject::LDObject (Model* model) : - m_isHidden (false), - m_isSelected (false), - _model (nullptr) + m_isHidden {false}, + m_isSelected {false}, + _model {model}, + m_coords {Origin} { - if (model) - model->addObject (this); - - memset (m_coords, 0, sizeof m_coords); + assert(_model != nullptr); // Let's hope that nobody goes to create 17 million objects anytime soon... static int32 nextId = 1; // 0 shalt be null @@ -191,34 +189,6 @@ // ============================================================================= // -// Replace this LDObject with another LDObject. Object is deleted in the process. -// -void LDObject::replace (LDObject* other) -{ - int idx = lineNumber(); - - if (idx != -1) - { - // Replace the instance of the old object with the new object - model()->setObjectAt(idx, other); - } -} - -void LDObject::replace (const LDObjectList& others) -{ - int idx = lineNumber(); - - if (idx != -1 and not others.isEmpty()) - { - for (int i = 1; i < countof(others); ++i) - model()->insertObject (idx + i, others[i]); - - model()->setObjectAt(idx, others[0]); - } -} - -// ============================================================================= -// // Swap this object with another. // void LDObject::swap (LDObject* other)
--- a/src/ldObject.h Sun Jan 29 21:17:43 2017 +0200 +++ b/src/ldObject.h Mon Jan 30 00:59:06 2017 +0200 @@ -117,10 +117,7 @@ LDObject* previous() const; bool previousIsInvertnext (LDBfc*& ptr); QColor randomColor() const; - void replace (LDObject* other); - void replace (const LDObjectList& others); void setColor (LDColor color); - void setDocument (Model* model); void setHidden (bool value); void setVertex (int i, const Vertex& vert); void swap (LDObject* other); @@ -138,6 +135,7 @@ friend class Model; LDObject (Model* model = nullptr); virtual ~LDObject(); + void setDocument(Model* model); private: bool m_isHidden;
--- a/src/model.cpp Sun Jan 29 21:17:43 2017 +0200 +++ b/src/model.cpp Mon Jan 30 00:59:06 2017 +0200 @@ -31,13 +31,11 @@ if (object->model() and object->model() != this) object->model()->withdraw(object); - if (not object->model()) - { - _objects.insert(position, object); - _needsTriangleRecount = true; - object->setDocument(this); - print("Object %1 added to position %2", object->id(), position); - } + // TODO: check that the object isn't in the vector once there's a cheap way to do so! + _objects.insert(position, object); + _needsTriangleRecount = true; + object->setDocument(this); + print("Object %1 added to position %2", object->id(), position); } bool Model::swapObjects(LDObject* one, LDObject* other) @@ -93,12 +91,6 @@ delete object; } -void Model::replace(LDObject* object, LDObject* newObject) -{ - if (object->model() == this) - setObjectAt(object->lineNumber(), newObject); -} - void Model::replace(LDObject *object, Model &model) { if (object->model() == this)
--- a/src/model.h Sun Jan 29 21:17:43 2017 +0200 +++ b/src/model.h Mon Jan 30 00:59:06 2017 +0200 @@ -18,7 +18,6 @@ void replace(LDObject *object, Model& model); void clear(); void merge(Model& other, int position = -1); - void replace(LDObject* object, LDObject* newObject); int size() const; const QVector<LDObject*>& objects() const; LDObject* getObject(int position) const;