Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export the session information for the model when meshing. #140

Merged
merged 2 commits into from
Apr 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions smtk/extension/remus/MeshOperator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -126,6 +165,7 @@ OperatorResult MeshOperator::operateInternal()
smtkImplementsModelOperator(
smtk::model::MeshOperator,
remus_mesh,

"mesh",
MeshOperator_xml,
smtk::model::Session);
23 changes: 23 additions & 0 deletions smtk/io/ExportJSON.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionIOJSON>(
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)
{
Expand Down
1 change: 1 addition & 0 deletions smtk/io/ExportJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
11 changes: 11 additions & 0 deletions smtk/model/SessionIOJSON.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions smtk/model/SessionIOJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down