Commit 4685d50c authored by Yumin Yuan's avatar Yumin Yuan
Browse files

Support for serializing mesh properpies with existing collection

parent 1777a3ae
......@@ -23,6 +23,7 @@
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/Definition.h"
#include "smtk/attribute/MeshItem.h"
#include "smtk/attribute/System.h"
#include "smtk/mesh/Manager.h"
......@@ -586,6 +587,7 @@ int ExportJSON::forOperatorResult(OperatorResult res, cJSON* entRec)
EntityRefs ents = res->modelEntitiesAs<EntityRefs>("created");
EntityRefs mdfs = res->modelEntitiesAs<EntityRefs>("modified");
EntityRefs meshents = res->modelEntitiesAs<EntityRefs>("mesh_created");
ents.insert(mdfs.begin(), mdfs.end());
ents.insert(meshents.begin(), meshents.end());
if (!ents.empty())
......@@ -596,12 +598,33 @@ int ExportJSON::forOperatorResult(OperatorResult res, cJSON* entRec)
cJSON* records = cJSON_CreateObject();
ExportJSON::forEntities(records, ents, smtk::model::ITERATE_MODELS, JSON_CLIENT_DATA);
cJSON_AddItemToObject(entRec, "records", records);
}
// Also export JSON meshes as a new node "mesh_records"
if(!meshents.empty())
smtk::attribute::MeshItemPtr modifiedMeshes = res->findMesh("mesh_modified");
// Also export JSON meshes as a new node "mesh_records"
if(!meshents.empty() || modifiedMeshes)
{
// get all collections associated with the input entities
smtk::common::UUIDs collectionIds;
smtk::mesh::ManagerPtr meshMgr = res->modelManager()->meshes();
smtk::model::EntityRefs::const_iterator iter;
for (iter = meshents.begin(); iter != meshents.end(); ++iter)
{
smtk::common::UUIDs cids = meshMgr->associatedCollectionIds(*iter);
collectionIds.insert(cids.begin(), cids.end());
}
if(modifiedMeshes)
{
smtk::attribute::MeshItem::const_mesh_it it;
for(it = modifiedMeshes->begin(); it != modifiedMeshes->end(); ++it)
{
collectionIds.insert(it->collection()->entity());
}
}
if(collectionIds.size() > 0)
{
cJSON* mesh_records = cJSON_CreateObject();
ExportJSON::forEntityMeshes(mesh_records, meshents, res->modelManager()->meshes());
ExportJSON::forMeshes(mesh_records, collectionIds, meshMgr);
cJSON_AddItemToObject(entRec, "mesh_records", mesh_records);
}
}
......@@ -724,11 +747,11 @@ int ExportJSON::forManagerMeshes(
* This creates and populate an JSON Object "mesh_collections"
* and add it to the parent json node (\a pnode) with
* data required to recreate the smtk::mesh Collections
* associated with the given EntityRefs.
* associated with the given \a collectionIds.
*/
int ExportJSON::forEntityMeshes(
int ExportJSON::forMeshes(
cJSON* pnode,
const smtk::model::EntityRefs& ents,
const smtk::common::UUIDs& collectionIds,
smtk::mesh::ManagerPtr meshMgr)
{
if (!pnode || pnode->type != cJSON_Object)
......@@ -736,15 +759,6 @@ int ExportJSON::forEntityMeshes(
return 0;
}
// get all collections associated with the input entities
smtk::common::UUIDs collectionIds;
smtk::model::EntityRefs::const_iterator iter;
for (iter = ents.begin(); iter != ents.end(); ++iter)
{
smtk::common::UUIDs cids = meshMgr->associatedCollectionIds(*iter);
collectionIds.insert(cids.begin(), cids.end());
}
if(collectionIds.empty())
{
return 0;
......
......@@ -104,9 +104,9 @@ public:
smtk::mesh::CollectionPtr collection);
// Serialize all the smtk::mesh associated with given EntityRefs.
static int forEntityMeshes(
static int forMeshes(
cJSON* pnode,
const smtk::model::EntityRefs& ents,
const smtk::common::UUIDs& collectionIds,
smtk::mesh::ManagerPtr meshMgr);
static int forLog(
......
......@@ -933,7 +933,7 @@ int ImportJSON::ofOperatorResult(cJSON* node, OperatorResult& resOut, smtk::mode
if(mesh_records)
{
status &= ImportJSON::ofMeshesOfModel(mesh_records, mgr);
status &= ImportJSON::ofMeshesOfModel(mesh_records, mgr, true);
}
}
return status;
......@@ -1050,7 +1050,8 @@ int ImportJSON::ofLog(cJSON* logrecordarray, smtk::io::Logger& log)
*
*/
int ImportJSON::ofMeshesOfModel(cJSON* node,
smtk::model::ManagerPtr modelMgr)
smtk::model::ManagerPtr modelMgr,
bool updateExisting)
{
int status = 1;
......@@ -1085,9 +1086,19 @@ int ImportJSON::ofMeshesOfModel(cJSON* node,
}
//first verify the collection doesn't already exist
if (meshMgr->collection(uid))
if (smtk::mesh::CollectionPtr existingC = meshMgr->collection(uid))
{
std::cerr << "Importing a mesh collection that already exists: " << child->string << "\n";
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
......@@ -1149,7 +1160,7 @@ int ImportJSON::ofMeshesOfModel(cJSON* node,
{
collection->associateModel(associatedModelId);
}
//write propertis to the new collection
//write properties to the new collection
status = ImportJSON::ofMeshProperties(child, collection);
}
else
......@@ -1180,6 +1191,7 @@ int ImportJSON::ofMeshProperties(cJSON* node,
smtk::mesh::HandleRange hrange = smtk::mesh::from_json(meshEntry);
smtk::mesh::MeshSet mesh = smtk::mesh::MeshSet(
collection, collection->interface()->getRoot(), hrange);
// float properties
cJSON* floatNode = cJSON_GetObjectItem(meshEntry, "f");
if (floatNode)
......@@ -1226,6 +1238,7 @@ int ImportJSON::ofMeshProperties(cJSON* node,
}
}
}
return 0;
}
......
......@@ -54,7 +54,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);
static int ofMeshesOfModel(cJSON* node, smtk::model::ManagerPtr modelMgr, bool updateExisting=false);
//write all mesh properties for the collection
static int ofMeshProperties(cJSON* node, smtk::mesh::CollectionPtr collection);
// Mid-level helpers:
......
......@@ -298,8 +298,6 @@ void XmlDocV2Parser::processMeshEntityItem(pugi::xml_node &node,
smtk::common::UUID cid;
smtk::model::ManagerPtr modelmgr = this->m_system.refModelManager();
xml_node valsNode, val;
std::string attName;
AttRefInfo info;
std::size_t i = 0;
valsNode = node.child("Values");
......@@ -327,12 +325,11 @@ void XmlDocV2Parser::processMeshEntityItem(pugi::xml_node &node,
smtk::mesh::HandleRange hrange = smtk::mesh::from_json(jshandle);
cJSON_Delete(jshandle);
smtk::mesh::CollectionPtr c = modelmgr->meshes()->collection(cid);
smtk::mesh::json::InterfacePtr interface =
smtk::dynamic_pointer_cast< smtk::mesh::json::Interface >(c->interface());
smtk::mesh::InterfacePtr interface =c->interface();
if(!interface)
{
smtkErrorMacro(this->m_logger, "Expecting a json interface for mesh item: " << item->name());
smtkErrorMacro(this->m_logger, "Expecting a valid interface for mesh item: " << item->name());
continue;
}
......
......@@ -71,7 +71,7 @@ std::string MeshPhrase::title()
{
smtk::mesh::CollectionPtr c = this->m_relatedMesh.collection();
bool hasValidNameProp = false;
if(c && c->hasIntegerProperty(this->m_relatedMesh, "name"))
if(c && c->hasStringProperty(this->m_relatedMesh, "name"))
{
smtk::model::StringList const& nprop(c->stringProperty(this->m_relatedMesh, "name"));
if (!nprop.empty() && !nprop[0].empty())
......
......@@ -40,8 +40,10 @@
</AttDef>
<!-- Result -->
<AttDef Type="result(set property)" BaseType="result">
<!-- The modified entities are stored in the base result's "modified" item. -->
<MeshEntity Name="mesh_modified" NumberOfRequiredValues="0" Extensible="true" AdvanceLevel="11"/>
<ItemDefinitions>
<!-- The modified entities are stored in the base result's "modified" item. -->
<MeshEntity Name="mesh_modified" NumberOfRequiredValues="0" Extensible="true" AdvanceLevel="11"/>
</ItemDefinitions>
</AttDef>
</Definitions>
</SMTK_AttributeSystem>
......@@ -144,7 +144,7 @@
<suppress-warning text="skipping function 'smtk::io::ExportJSON::forOperator', unmatched parameter type 'cJSON*'"/>
<suppress-warning text="skipping function 'smtk::io::ExportJSON::forEntities', unmatched parameter type 'T const&amp;'"/>
<suppress-warning text="skipping function 'smtk::io::ExportJSON::forEntities', unmatched parameter type 'cJSON*'"/>
<suppress-warning text="skipping function 'smtk::io::ExportJSON::forEntityMeshes', unmatched parameter type 'cJSON*'"/>
<suppress-warning text="skipping function 'smtk::io::ExportJSON::forMeshes', unmatched parameter type 'cJSON*'"/>
<suppress-warning text="skipping function 'smtk::io::ImportMesh::entireJSON', unmatched parameter type 'cJSON*'"/>
<suppress-warning text="skipping function 'smtk::io::ImportMesh::entireJSONToCollection', unmatched parameter type 'cJSON*'"/>
......
Supports Markdown
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