From c74d6d8cb1b1d7352f68afdfd0b453588b8b06e0 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 15 Apr 2015 16:14:06 -0400 Subject: [PATCH 1/2] Allow exportation of session information for a subset of all models. So when a session is exported it can generate information that references all the models in the current session. But there are use cases where we want only session information for a subset of all models. --- smtk/io/ExportJSON.cxx | 23 +++++++++++++++++++++++ smtk/io/ExportJSON.h | 1 + smtk/model/SessionIOJSON.cxx | 11 +++++++++++ smtk/model/SessionIOJSON.h | 1 + 4 files changed, 36 insertions(+) diff --git a/smtk/io/ExportJSON.cxx b/smtk/io/ExportJSON.cxx index 9c9e44a10b..027b472805 100644 --- a/smtk/io/ExportJSON.cxx +++ b/smtk/io/ExportJSON.cxx @@ -429,6 +429,29 @@ int ExportJSON::forManagerSession(const smtk::common::UUID& uid, cJSON* node, Ma return status; } +int ExportJSON::forManagerSessionPartial(const smtk::common::UUID& uid, + const smtk::common::UUIDs& modelIds, + cJSON* node, + ManagerPtr modelMgr) +{ + int status = 1; + SessionPtr session = SessionRef(modelMgr, uid).session(); + if (!session) + return status; + + cJSON* sess = cJSON_CreateObject(); + cJSON_AddItemToObject(node, uid.toString().c_str(), sess); + cJSON_AddStringToObject(sess, "type", "session"); + cJSON_AddStringToObject(sess, "name", session->name().c_str()); + SessionIOJSONPtr delegate = + smtk::dynamic_pointer_cast( + session->createIODelegate("json")); + if (delegate) + status &= delegate->exportJSON(modelMgr, modelIds, sess); + status &= ExportJSON::forOperatorDefinitions(session->operatorSystem(), sess); + return status; +} + /* int ExportJSON::forModelOperators(const smtk::common::UUID& uid, cJSON* entRec, ManagerPtr modelMgr) { diff --git a/smtk/io/ExportJSON.h b/smtk/io/ExportJSON.h index 5d3bec17ee..5d20a4257e 100644 --- a/smtk/io/ExportJSON.h +++ b/smtk/io/ExportJSON.h @@ -78,6 +78,7 @@ class SMTKCORE_EXPORT ExportJSON static int forManagerStringProperties(const smtk::common::UUID& uid, cJSON*, smtk::model::ManagerPtr modelMgr); static int forManagerIntegerProperties(const smtk::common::UUID& uid, cJSON*, smtk::model::ManagerPtr modelMgr); static int forManagerSession(const smtk::common::UUID& uid, cJSON*, smtk::model::ManagerPtr modelMgr); + static int forManagerSessionPartial(const smtk::common::UUID& sessionId, const common::UUIDs &modelIds, cJSON*, smtk::model::ManagerPtr modelMgrId); //static int forModelOperators(const smtk::common::UUID& uid, cJSON*, smtk::model::ManagerPtr modelMgr); static int forOperatorDefinitions(smtk::attribute::System* opSys, cJSON*); static int forOperator(smtk::model::OperatorSpecification op, cJSON*); diff --git a/smtk/model/SessionIOJSON.cxx b/smtk/model/SessionIOJSON.cxx index d0bf236b94..bd20f34381 100644 --- a/smtk/model/SessionIOJSON.cxx +++ b/smtk/model/SessionIOJSON.cxx @@ -32,6 +32,17 @@ int SessionIOJSON::importJSON(ManagerPtr modelMgr, cJSON* sessionRec) * Subclasses should return 1 on success and 0 on failure. */ int SessionIOJSON::exportJSON(ManagerPtr modelMgr, cJSON* sessionRec) +{ + (void)modelMgr; + (void)sessionRec; + return 1; +} + +/**\brief Encode information into \a sessionRec for the given \a modelId of the \a modelMgr. + * + * Subclasses should return 1 on success and 0 on failure. + */ +int SessionIOJSON::exportJSON(ManagerPtr modelMgr, const smtk::common::UUIDs& modelIds, cJSON* sessionRec) { (void)modelMgr; (void)sessionRec; diff --git a/smtk/model/SessionIOJSON.h b/smtk/model/SessionIOJSON.h index 1e1ac65435..faf7dabad6 100644 --- a/smtk/model/SessionIOJSON.h +++ b/smtk/model/SessionIOJSON.h @@ -29,6 +29,7 @@ class SMTKCORE_EXPORT SessionIOJSON : public SessionIO virtual int importJSON(ManagerPtr modelMgr, cJSON* sessionRec); virtual int exportJSON(ManagerPtr modelMgr, cJSON* sessionRec); + virtual int exportJSON(ManagerPtr modelMgr, const common::UUIDs &modelIds, cJSON* sessionRec); }; } // namespace model From ea5137bc9bfc5a55c5bf023ddb45355f071802bc Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 13 Apr 2015 09:55:03 -0400 Subject: [PATCH 2/2] Export the session information for the models that we are meshing. --- smtk/extension/remus/MeshOperator.cxx | 50 ++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/smtk/extension/remus/MeshOperator.cxx b/smtk/extension/remus/MeshOperator.cxx index a45064538c..c754a3e066 100644 --- a/smtk/extension/remus/MeshOperator.cxx +++ b/smtk/extension/remus/MeshOperator.cxx @@ -74,12 +74,51 @@ OperatorResult MeshOperator::operateInternal() //of the mesher submission["meshing_attributes"] = meshingControls; - //lastly all we have to do is serialize the model - std::string modelSerialized = - smtk::io::ExportJSON::forEntities( - models, smtk::model::ITERATE_MODELS, smtk::io::JSON_DEFAULT); + if(models.size() > 0) + { + //lastly all we have to do is serialize the model, and the session information + //for that model. This way workers that can reconstruct specific sessions + //are possible. + cJSON* modelAndSession = cJSON_CreateObject(); + cJSON* topo = cJSON_CreateObject(); + cJSON* sess = cJSON_CreateObject(); + + cJSON_AddItemToObject(modelAndSession, "topo", topo); + cJSON_AddItemToObject(modelAndSession, "sessions", sess); + + //first thing we do is export the session for each model. We do this + //by asking each session to export the relevant models + typedef smtk::model::Models::const_iterator model_const_it; + smtk::common::UUIDs modelIds; + for(model_const_it i=models.begin(); i!=models.end(); ++i) + { + modelIds.insert(i->entity()); + } + + smtk::model::SessionRefs sessions = this->manager()->sessions(); + for (smtk::model::SessionRefs::iterator bit = sessions.begin(); bit != sessions.end(); ++bit) + { + smtk::io::ExportJSON::forManagerSessionPartial(bit->entity(), + modelIds, + sess, + this->manager()); + } - submission["model"] = remus::proto::make_JobContent(modelSerialized); + //next we export all the models and place them in the topo section + smtk::io::ExportJSON::forEntities(topo, + models, + smtk::model::ITERATE_MODELS, + smtk::io::JSON_DEFAULT); + + char* json = cJSON_Print(modelAndSession); + std::string modelSerialized(json); + free(json); + cJSON_Delete(modelAndSession); + + //if we don't have any model's don't specify this key. + //Omitting this key should make the worker fail. + submission["model"] = remus::proto::make_JobContent(modelSerialized); + } //now that we have the submission, construct a remus client to submit it const remus::client::ServerConnection conn = @@ -126,6 +165,7 @@ OperatorResult MeshOperator::operateInternal() smtkImplementsModelOperator( smtk::model::MeshOperator, remus_mesh, + "mesh", MeshOperator_xml, smtk::model::Session);