From 3bc970c9e92e082fec68f78c31443250d397b0f7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 25 Jun 2014 16:11:06 -0700 Subject: [PATCH] added ModelTree::deleteModels(QSet) which correctly marks tree as changed --- libraries/models/src/ModelTree.cpp | 88 +++++++++--------------------- libraries/models/src/ModelTree.h | 1 + 2 files changed, 26 insertions(+), 63 deletions(-) diff --git a/libraries/models/src/ModelTree.cpp b/libraries/models/src/ModelTree.cpp index 3429e9e372..9286985665 100644 --- a/libraries/models/src/ModelTree.cpp +++ b/libraries/models/src/ModelTree.cpp @@ -37,49 +37,6 @@ bool ModelTree::handlesEditPacketType(PacketType packetType) const { } } -class FindAndDeleteModelsArgs { -public: - QList _idsToDelete; -}; - -// TODO: this operations needs to correctly set the markAsChanged for each of the octree elments -bool ModelTree::findAndDeleteOperation(OctreeElement* element, void* extraData) { - //qDebug() << "findAndDeleteOperation()"; - - FindAndDeleteModelsArgs* args = static_cast< FindAndDeleteModelsArgs*>(extraData); - - // if we've found and deleted all our target models, then we can stop looking - if (args->_idsToDelete.size() <= 0) { - return false; - } - - ModelTreeElement* modelTreeElement = static_cast(element); - - //qDebug() << "findAndDeleteOperation() args->_idsToDelete.size():" << args->_idsToDelete.size(); - - for (QList::iterator it = args->_idsToDelete.begin(); it != args->_idsToDelete.end(); it++) { - uint32_t modelID = *it; - //qDebug() << "findAndDeleteOperation() modelID:" << modelID; - - if (modelTreeElement->removeModelWithID(modelID)) { - // if the model was in this element, then remove it from our search list. - //qDebug() << "findAndDeleteOperation() it = args->_idsToDelete.erase(it)"; - it = args->_idsToDelete.erase(it); - } - - if (it == args->_idsToDelete.end()) { - //qDebug() << "findAndDeleteOperation() breaking"; - break; - } - } - - // if we've found and deleted all our target models, then we can stop looking - if (args->_idsToDelete.size() <= 0) { - return false; - } - return true; -} - class StoreModelOperator : public RecurseOctreeOperator { public: StoreModelOperator(ModelTree* tree, const ModelItem& searchModel); @@ -420,18 +377,6 @@ bool DeleteModelOperator::PostRecursion(OctreeElement* element) { } void ModelTree::deleteModel(const ModelItemID& modelID) { - -/* - if (modelID.isKnownID) { - FindAndDeleteModelsArgs args; - args._idsToDelete.push_back(modelID.id); - - // NOTE: We need to do this with recursion, because we need to mark the - // path to get to the models as dirty, so that sending to any viewers - // will work correctly - recurseTreeWithOperation(findAndDeleteOperation, &args); - } -*/ // NOTE: callers must lock the tree before using this method // First, look for the existing model in the tree.. @@ -447,6 +392,26 @@ void ModelTree::deleteModel(const ModelItemID& modelID) { } } +void ModelTree::deleteModels(QSet modelIDs) { + // NOTE: callers must lock the tree before using this method + + // TODO: fix this to use one pass + foreach(const ModelItemID& modelID, modelIDs) { + + // First, look for the existing model in the tree.. + DeleteModelOperator theOperator(this, modelID); + + recurseTreeWithOperator(&theOperator); + _isDirty = true; + + bool wantDebug = false; + if (wantDebug) { + ModelTreeElement* containingElement = getContainingElement(modelID); + qDebug() << "ModelTree::storeModel().... after store... containingElement=" << containingElement; + } + } +} + // scans the tree and handles mapping locally created models to know IDs. // in the event that this tree is also viewing the scene, then we need to also // search the tree to make sure we don't have a duplicate model from the viewing @@ -907,7 +872,7 @@ void ModelTree::processEraseMessage(const QByteArray& dataByteArray, const Share processedBytes += sizeof(numberOfIds); if (numberOfIds > 0) { - FindAndDeleteModelsArgs args; + QSet modelItemIDsToDelete; for (size_t i = 0; i < numberOfIds; i++) { if (processedBytes + sizeof(uint32_t) > packetLength) { @@ -918,14 +883,11 @@ void ModelTree::processEraseMessage(const QByteArray& dataByteArray, const Share memcpy(&modelID, dataAt, sizeof(modelID)); dataAt += sizeof(modelID); processedBytes += sizeof(modelID); - args._idsToDelete.push_back(modelID); + + ModelItemID modelItemID(modelID); + modelItemIDsToDelete << modelItemID; } - - // calling recurse to actually delete the models - // NOTE: We need to do this with recursion, because we need to mark the - // path to get to the models as dirty, so that sending to any viewers - // will work correctly - recurseTreeWithOperation(findAndDeleteOperation, &args); + deleteModels(modelItemIDsToDelete); } } diff --git a/libraries/models/src/ModelTree.h b/libraries/models/src/ModelTree.h index 9ad3b6594d..5306da9efc 100644 --- a/libraries/models/src/ModelTree.h +++ b/libraries/models/src/ModelTree.h @@ -55,6 +55,7 @@ public: void updateModel(const ModelItemID& modelID, const ModelItemProperties& properties); void addModel(const ModelItemID& modelID, const ModelItemProperties& properties); void deleteModel(const ModelItemID& modelID); + void deleteModels(QSet modelIDs); const ModelItem* findClosestModel(glm::vec3 position, float targetRadius); const ModelItem* findModelByID(uint32_t id, bool alreadyLocked = false) const; const ModelItem* findModelByModelItemID(const ModelItemID& modelID) const;