Commit ff795fad authored by Robert Maynard's avatar Robert Maynard

Allow ImportJSON to update existing collections.

parent 0c094f32
Pipeline #7173 passed with stage
......@@ -940,7 +940,7 @@ int ImportJSON::ofOperatorResult(cJSON* node, OperatorResult& resOut, smtk::mode
if(mesh_records)
{
status &= ImportJSON::ofMeshesOfModel(mesh_records, mgr, true);
status &= ImportJSON::ofMeshesOfModel(mesh_records, mgr);
}
}
return status;
......@@ -1059,8 +1059,7 @@ int ImportJSON::ofLog(cJSON* logrecordarray, smtk::io::Logger& log)
*
*/
int ImportJSON::ofMeshesOfModel(cJSON* node,
smtk::model::ManagerPtr modelMgr,
bool updateExisting)
smtk::model::ManagerPtr modelMgr)
{
int status = 1;
......@@ -1094,22 +1093,6 @@ int ImportJSON::ofMeshesOfModel(cJSON* node,
continue;
}
//first verify the collection doesn't already exist
if (smtk::mesh::CollectionPtr existingC = meshMgr->collection(uid))
{
if(updateExisting)
{
// Import everything in a json string into the existing collection?, need to clear first?
// smtk::mesh::json::import(child, existingC);
// update properties, if any, to the existing collection
status &= ImportJSON::ofMeshProperties(child, existingC);
}
else
{
std::cerr << "Importing a mesh collection that already exists: " << child->string << "\n";
}
continue;
}
//assoicated model uuid of the collection
smtk::common::UUID associatedModelId;
if(cJSON* modelIdNode = cJSON_GetObjectItem(child, "associatedModel"))
......@@ -1145,10 +1128,20 @@ int ImportJSON::ofMeshesOfModel(cJSON* node,
if(importedCollection)
{
//Transfer ownership of the interface over to this new collection
//done so that we get the correct uuid for the collection
smtk::mesh::CollectionPtr collection =
meshMgr->makeCollection(uid, importedCollection->interface());
smtk:mesh::CollectionPtr collection;
smtk::mesh::CollectionPtr existingC = meshMgr->collection(uid);
if(existingC)
{
existingC->swapInterfaces(importedCollection);
collection = existingC;
}
else
{
//Transfer ownership of the interface over to this new collection
//done so that we get the correct uuid for the collection
collection = meshMgr->makeCollection(uid, importedCollection->interface());
}
//remove the old collection, as its interface is now owned by the new
//collection
......
......@@ -63,7 +63,7 @@ public:
static int ofLog(cJSON* logrecordarray, smtk::io::Logger& log);
//write all mesh collections that have associations to a model
static int ofMeshesOfModel(cJSON* node, smtk::model::ManagerPtr modelMgr, bool updateExisting=false);
static int ofMeshesOfModel(cJSON* node, smtk::model::ManagerPtr modelMgr);
//write all mesh properties for the collection
static int ofMeshProperties(cJSON* node, smtk::mesh::CollectionPtr collection);
// Mid-level helpers:
......
......@@ -61,8 +61,6 @@ public:
smtk::mesh::Handle mesh_root_handle() const
{ return this->Interface->getRoot(); }
private:
smtk::weak_ptr<smtk::mesh::Manager> WeakManager;
smtk::mesh::InterfacePtr Interface;
......@@ -120,12 +118,21 @@ Collection::~Collection()
delete this->m_internals;
}
}
//----------------------------------------------------------------------------
const smtk::mesh::InterfacePtr& Collection::interface() const
{
return this->m_internals->mesh_iface();
}
//----------------------------------------------------------------------------
void Collection::swapInterfaces(smtk::mesh::CollectionPtr& other)
{
smtk::mesh::Collection::InternalImpl* temp = other->m_internals;
other->m_internals = this->m_internals;
this->m_internals = temp;
}
//----------------------------------------------------------------------------
void Collection::removeManagerConnection()
{
......
......@@ -277,8 +277,14 @@ private:
Collection( const Collection& other ); //blank since we are used by shared_ptr
Collection& operator=( const Collection& other ); //blank since we are used by shared_ptr
//Sets the location that this collection was loaded from
void readLocation(const std::string& path);
//Swap the internal interfaces between this Collection and another Collection
//this is how we can easily update a collection that has already been
//loaded with a newer version from disk
void swapInterfaces(smtk::mesh::CollectionPtr& other);
friend class smtk::mesh::Manager;
friend class smtk::io::ImportMesh;
friend class smtk::io::ImportJSON;
......
......@@ -154,7 +154,7 @@ int SessionIOJSON::loadModelsRecord(ManagerPtr modelMgr,
smtkInfoMacro(modelMgr->log(), "Invalid model uuid, skipping!");
continue;
}
// model meta info
// model meta info
status &= smtk::io::ImportJSON::ofManager(modelentry, modelMgr);
}
......@@ -176,7 +176,7 @@ int SessionIOJSON::loadMeshesRecord(ManagerPtr modelMgr,
smtkInfoMacro(modelMgr->log(), "Expecting a \"mesh_collections\" entry!");
return 1;
}
return smtk::io::ImportJSON::ofMeshesOfModel(sessionRec, modelMgr, true);
return smtk::io::ImportJSON::ofMeshesOfModel(sessionRec, modelMgr);
}
/**\brief Encode information into \a sessionRec for the given \a modelMgr.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment