Commit c2ab0272 authored by Bob Obara's avatar Bob Obara

Merge branch 'master' into 'release-v1'

Updating Release Branch to have Preserve ID fix



See merge request !38
parents d5e9189e ee4af2e6
Pipeline #6315 failed with stage
......@@ -166,7 +166,7 @@ set(Boost_NO_SYSTEM_PATHS ${SMTK_NO_SYSTEM_BOOST})
# * Shared Ptr
# * String algorithms
# * UUID Generation
find_package(Boost 1.50.0
find_package(Boost 1.60.0
COMPONENTS filesystem system REQUIRED)
#setup windows exception handling so we can compile properly with boost enabled
......
......@@ -22,7 +22,7 @@ In order to build SMTK you must have
+ A modern C++ compiler (gcc, clang, or VS) that supports C++11 features,
+ [CMake](http://cmake.org) 2.8.11 or newer (3.2 is advised), and
+ [Boost](http://boost.org) 1.50.0 or newer.
+ [Boost](http://boost.org) 1.60.0 or newer.
We recommend using [Ninja](http://martine.github.io/ninja/) for fast builds.
......
......@@ -128,6 +128,10 @@ public:
virtual void Execute(
vtkObject* caller, unsigned long eventId, void* callData)
{
if (!session)
{ // The session has been deleted while models still existed.
return;
}
(void)eventId;
(void)callData;
smtk::common::UUID uid = session->findOrSetEntityUUID(vtkInformation::SafeDownCast(caller));
......
if(SMTK_DATA_DIR)
ADD_EXECUTABLE(SessionTest SessionTest.cxx)
TARGET_LINK_LIBRARIES(SessionTest smtkCore smtkDiscreteSession)
ADD_TEST(discreteSessionTest
SessionTest
${SMTK_DATA_DIR}/cmb/test2D.cmb ${SMTK_DATA_DIR}/cmb/smooth_surface.cmb)
add_executable(SessionTest SessionTest.cxx)
target_link_libraries(SessionTest smtkCore smtkDiscreteSession)
add_test(
NAME discreteSessionTest
COMMAND SessionTest ${SMTK_DATA_DIR}/cmb/test2D.cmb ${SMTK_DATA_DIR}/cmb/smooth_surface.cmb
)
endif()
......@@ -79,18 +79,18 @@ class TestDiscreteCreateAndSaveEdges(smtk.testing.TestCase):
self.assertIsNotNone(btm, 'Missing create edges operator.')
SetVectorValue(btm.findAsModelEntity('model'), [mod,])
res = btm.operate()
res = btm.operate()
sys.stdout.flush()
self.assertEqual(res.findInt('outcome').value(0), smtk.model.OPERATION_SUCCEEDED,
'create edges failed.')
writeop = GetActiveSession().op('write')
self.assertIsNotNone(writeop, 'Missing discrete write operator.')
SetVectorValue(writeop.findAsModelEntity('model'), [mod,])
SetVectorValue(writeop.specification().associations(), [mod,])
tmpfile = ['testCreateAndSaveEdges.cmb',]
outfilename = os.path.join(*([smtk.testing.TEMP_DIR,] + tmpfile))
writeop.findAsFile('filename').setValue(0, outfilename)
res = writeop.operate()
res = writeop.operate()
sys.stdout.flush()
self.assertEqual(res.findInt('outcome').value(0), smtk.model.OPERATION_SUCCEEDED,
'write SimpleBox model with edges failed.')
......
......@@ -53,6 +53,8 @@ smtk::model::OperatorResult ReadOperator::operateInternal()
this->specification()->findFile("filename");
smtk::attribute::StringItem::Ptr filetypeItem =
this->specification()->findString("filetype");
this->m_preservedUUIDs =
this->specification()->findModelEntity("preservedUUIDs");
std::string filename = filenameItem->value();
std::string filetype = filetypeItem->value();
......@@ -80,6 +82,33 @@ smtk::model::OperatorResult ReadOperator::operateInternal()
return this->readExodus();
}
static void AddPreservedUUID(
vtkDataObject* data, int& curId, attribute::ModelEntityItem::Ptr uuids)
{
if (!data || curId < 0 || curId >= uuids->numberOfValues())
return;
vtkInformation* info = data->GetInformation();
info->Set(Session::SMTK_UUID_KEY(), uuids->value(curId).entity().toString().c_str());
++curId;
}
static void AddPreservedUUIDsRecursive(
vtkDataObject* data, int& curId, attribute::ModelEntityItem::Ptr uuids)
{
AddPreservedUUID(data, curId, uuids);
vtkMultiBlockDataSet* mbds = vtkMultiBlockDataSet::SafeDownCast(data);
if (mbds)
{
int nb = mbds->GetNumberOfBlocks();
for (int i = 0; i < nb; ++i)
{
AddPreservedUUIDsRecursive(mbds->GetBlock(i), curId, uuids);
}
}
}
static void MarkMeshInfo(
vtkDataObject* data, int dim, const char* name, EntityType etype, int pedigree)
{
......@@ -91,14 +120,18 @@ static void MarkMeshInfo(
info->Set(Session::SMTK_GROUP_TYPE(), etype);
info->Set(vtkCompositeDataSet::NAME(), name);
// ++ 1 ++
// If a UUID has been saved to field data, we should copy it to the info object here.
vtkStringArray* uuidArr =
vtkStringArray::SafeDownCast(
data->GetFieldData()->GetAbstractArray("UUID"));
if (uuidArr && uuidArr->GetNumberOfTuples() > 0)
info->Set(Session::SMTK_UUID_KEY(), uuidArr->GetValue(0).c_str());
// -- 1 --
const char* existingUUID = info->Get(Session::SMTK_UUID_KEY());
if (!existingUUID || !existingUUID[0])
{
// ++ 1 ++
// If a UUID has been saved to field data, we should copy it to the info object here.
vtkStringArray* uuidArr =
vtkStringArray::SafeDownCast(
data->GetFieldData()->GetAbstractArray("UUID"));
if (uuidArr && uuidArr->GetNumberOfTuples() > 0)
info->Set(Session::SMTK_UUID_KEY(), uuidArr->GetValue(0).c_str());
// -- 1 --
}
info->Set(Session::SMTK_PEDIGREE(), pedigree);
}
......@@ -178,6 +211,10 @@ smtk::model::OperatorResult ReadOperator::readExodus()
rdr->GetOutputDataObject(0)));
int dim = rdr->GetDimensionality();
// If we have preserved UUIDs, assign them now before anything else does:
int curId = 0;
AddPreservedUUIDsRecursive(modelOut, curId, this->m_preservedUUIDs);
// Now iterate over the dataset and mark each block (leaf or not)
// with information needed by the session to determine how it should
// be presented.
......@@ -266,6 +303,10 @@ smtk::model::OperatorResult ReadOperator::readSLAC()
modelOut->SetBlock(0, surfBlocks.GetPointer());
modelOut->SetBlock(1, voluBlocks.GetPointer());
// If we have preserved UUIDs, assign them now before anything else does:
int curId = 0;
AddPreservedUUIDsRecursive(modelOut, curId, this->m_preservedUUIDs);
MarkMeshInfo(modelOut.GetPointer(), 3, path(filename).stem().string<std::string>().c_str(), EXO_MODEL, -1);
MarkSLACMeshWithChildren(surfBlocks.GetPointer(), 2, "surfaces", EXO_SIDE_SETS, EXO_SIDE_SET);
MarkSLACMeshWithChildren(voluBlocks.GetPointer(), 3, "volumes", EXO_BLOCKS, EXO_BLOCK);
......@@ -412,6 +453,10 @@ smtk::model::OperatorResult ReadOperator::readLabelMap()
modelOut->SetNumberOfBlocks(1);
modelOut->SetBlock(0, img.GetPointer());
// If we have preserved UUIDs, assign them now before anything else does:
int curId = 0;
AddPreservedUUIDsRecursive(modelOut, curId, this->m_preservedUUIDs);
MarkMeshInfo(modelOut.GetPointer(), imgDim, path(filename).stem().string<std::string>().c_str(), EXO_MODEL, -1);
MarkMeshInfo(img.GetPointer(), imgDim, labelname.c_str(), EXO_LABEL_MAP, -1);
for (int i = 0; i < numLabels; ++i)
......
......@@ -29,6 +29,8 @@ protected:
virtual smtk::model::OperatorResult readExodus();
virtual smtk::model::OperatorResult readSLAC();
virtual smtk::model::OperatorResult readLabelMap();
attribute::ModelEntityItemPtr m_preservedUUIDs;
};
} // namespace exodus
......
......@@ -22,6 +22,7 @@
The name of a scalar cell-data array indicating which segment each cell belongs to.
</BriefDescription>
</String>
<ModelEntity Name="preservedUUIDs" NumberOfRequiredValues="0" Extensible="1"/>
</ItemDefinitions>
</AttDef>
<!-- Result -->
......
......@@ -434,6 +434,7 @@ SessionInfoBits Session::transcribeInternal(
case EXO_MODEL:
mutableEntityRef.setStringProperty("_simple type", "file");
mutableEntityRef.setIntegerProperty("file order", handle.pedigree());
break;
default:
break;
......@@ -652,8 +653,13 @@ bool Session::ensureChildParentMapEntry(vtkDataObject* child, vtkDataObject* par
// ++ 12 ++
SessionIOPtr Session::createIODelegate(const std::string& format)
{
// Currently the DefaultSession is handling this.
return this->Superclass::createIODelegate(format);
SessionIOPtr result;
if (format == "json")
{
//result = this->Superclass::createIODelegate(format);
result = SessionIOJSON::create();
}
return result;
}
// -- 12 --
......
......@@ -7,46 +7,147 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/model/SessionIOJSON.h"
#include "smtk/bridge/exodus/SessionExodusIOJSON.h"
#include "smtk/model/Group.h"
#include "smtk/model/Manager.h"
#include "smtk/model/Model.h"
#include "smtk/model/Operator.h"
#include "smtk/attribute/Attribute.h"
#include "smtk/attribute/IntItem.h"
#include "smtk/attribute/FileItem.h"
#include "smtk/attribute/ModelEntityItem.h"
#include "smtk/io/ImportJSON.h"
#include "smtk/io/ExportJSON.h"
#include "boost/filesystem.hpp"
#include "boost/system/error_code.hpp"
#include "cJSON.h"
using namespace boost::filesystem;
namespace smtk {
namespace model {
namespace bridge {
namespace exodus {
/// Construct an I/O delegate.
SessionIOJSON::SessionIOJSON()
{
}
/**\brief Load a model file while preserving UUIDs contained in the JSON file in traversal-order.
*/
int SessionIOJSON::loadExodusFileWithUUIDs(
const model::SessionRef& sref,
const std::string& url,
const common::UUIDArray& preservedUUIDs
)
{
if (!sref.isValid() || url.empty())
{
smtkWarningMacro(
sref.manager()->log(),
"Invalid session (" << sref.name() << ") or URL (" << url << ")");
return 0;
}
// See if we can turn a relative path into an absolute one (but only if it exists)
path absURL(url);
if (!this->referencePath().empty() && !absURL.is_absolute())
{
path tryme(this->referencePath());
tryme += absURL;
if (exists(tryme))
{
absURL = tryme;
}
}
smtk::model::OperatorPtr readOp = sref.op("read");
if (!readOp)
{
smtkInfoMacro(sref.manager()->log(), "Failed to create a read operator to read the model for native kernel!");
return 0;
}
readOp->specification()->findFile("filename")->setValue(absURL.string());
attribute::ModelEntityItem::Ptr pu = readOp->specification()->findModelEntity("preservedUUIDs");
pu->setNumberOfValues(static_cast<int>(preservedUUIDs.size()));
pu->setIsEnabled(preservedUUIDs.empty() ? false : true);
int i = 0;
for (common::UUIDArray::const_iterator uit = preservedUUIDs.begin(); uit != preservedUUIDs.end(); ++uit, ++i)
{
pu->setValue(i, model::EntityRef(sref.manager(), *uit));
}
smtk::model::OperatorResult opresult = readOp->operate();
if (opresult->findInt("outcome")->value() !=
smtk::model::OPERATION_SUCCEEDED)
{
smtkWarningMacro(sref.manager()->log(), "Failed to read the model for native kernel!");
return 0;
}
return 1;
}
/**\brief Decode information from \a sessionRec for the given \a modelMgr.
*
* Subclasses should return 1 on success and 0 on failure.
*/
int SessionIOJSON::importJSON(ManagerPtr modelMgr,
const SessionPtr& session,
cJSON* sessionRec,
bool loadNativeModels)
int SessionIOJSON::importJSON(
model::ManagerPtr modelMgr,
const model::SessionPtr& session,
cJSON* sessionRec,
bool loadNativeModels)
{
(void)modelMgr;
(void)session;
(void)sessionRec;
(void)loadNativeModels;
cJSON* preservedUUIDs = cJSON_GetObjectItem(sessionRec, "preservedUUIDs");
cJSON* modelFiles = cJSON_GetObjectItem(sessionRec, "modelFiles");
common::UUIDArray uids;
if (preservedUUIDs)
{
smtk::io::ImportJSON::getUUIDArrayFromJSON(preservedUUIDs->child, uids);
}
if (loadNativeModels)
{
for (cJSON* entry = modelFiles->child; entry; entry = entry->next)
{
smtkDebugMacro(modelMgr->log(), "Loading file \"" << entry->valuestring << "\"");
this->loadExodusFileWithUUIDs(model::SessionRef(modelMgr, session), entry->valuestring, uids);
}
}
return 1;
}
/**\brief Encode information into \a sessionRec for the given \a modelMgr.
*
* Subclasses should return 1 on success and 0 on failure.
* In this case, we want to preserve UUIDs even when the original file (with
* UUIDs embedded) is not written to disk so that loading the session
* starting with the JSON file results in the same UUIDs as we have currently.
* This assumes model entities are loaded in the same order each time the
* native file is read.
*
* Returns 1 on success and 0 on failure.
*/
// ++ 1 ++
int SessionIOJSON::exportJSON(ManagerPtr modelMgr,
const SessionPtr& session,
cJSON* sessionRec,
bool writeNativeModels)
int SessionIOJSON::exportJSON(
model::ManagerPtr modelMgr,
const model::SessionPtr& session,
cJSON* sessionRec,
bool writeNativeModels)
{
(void)modelMgr;
(void)session;
(void)sessionRec;
(void)writeNativeModels;
return 1;
model::SessionRef sref(modelMgr, session);
model::Models sessModels = sref.models<model::Models>();
common::UUIDs modelIds;
model::EntityRef::EntityRefsToUUIDs(modelIds, sessModels);
return this->exportJSON(modelMgr, session, modelIds, sessionRec, writeNativeModels);
}
// -- 1 --
......@@ -56,18 +157,86 @@ int SessionIOJSON::exportJSON(ManagerPtr modelMgr,
* This variant should export only information for the given models.
*/
// ++ 3 ++
int SessionIOJSON::exportJSON(ManagerPtr modelMgr, const SessionPtr& session,
const common::UUIDs &modelIds, cJSON* sessionRec,
int SessionIOJSON::exportJSON(model::ManagerPtr modelMgr, const model::SessionPtr& session,
const common::UUIDs& modelIds, cJSON* sessionRec,
bool writeNativeModels)
{
(void)modelMgr;
(void)session;
(void)modelIds;
(void)sessionRec;
// We ignore writeNativeModels because we cannot write native models yet
// (the write operator only handles label maps, not Exodus or SLAC).
(void)writeNativeModels;
std::vector<smtk::common::UUID> uuidArray;
model::SessionRef sref(modelMgr, session);
std::vector<long> toplevelOffsets;
std::vector<long> modelNumbers;
std::set<std::string> modelFiles;
path refPath(this->referencePath());
long modelNumber = 0;
model::Models sessModels = sref.models<model::Models>();
for (model::Models::iterator mit = sessModels.begin(); mit != sessModels.end(); ++mit, ++modelNumber)
{
// Only add a model
if (modelIds.find(mit->entity()) != modelIds.end())
{
modelNumbers.push_back(modelNumber);
toplevelOffsets.push_back(static_cast<long>(uuidArray.size()));
uuidArray.push_back(mit->entity());
this->addChildrenUUIDs(*mit, uuidArray);
if (mit->hasStringProperty("url"))
{
path url(mit->stringProperty("url")[0]);
if (!refPath.string().empty())
{
boost::system::error_code err;
path tryme = relative(url, refPath, err);
if (err == boost::system::errc::success)
{
url = tryme.string();
}
}
modelFiles.insert(url.string());
}
}
}
cJSON_AddItemToObject(sessionRec, "preservedUUIDs",
smtk::io::ExportJSON::createUUIDArray(uuidArray));
cJSON_AddItemToObject(sessionRec, "toplevelOffsets",
smtk::io::ExportJSON::createIntegerArray(toplevelOffsets));
cJSON_AddItemToObject(sessionRec, "modelNumbers",
smtk::io::ExportJSON::createIntegerArray(modelNumbers));
std::vector<std::string> urlArray(modelFiles.begin(), modelFiles.end());
cJSON_AddItemToObject(sessionRec, "modelFiles",
smtk::io::ExportJSON::createStringArray(urlArray));
return 1;
}
// -- 3 --
} // namespace model
/**\brief Add UUIDs of children to \a uuids array.
*
* The children are assumed to be listed in a stable order across file loads.
*/
void SessionIOJSON::addChildrenUUIDs(const model::EntityRef& parent, common::UUIDArray& uuids)
{
model::EntityRefArray children;
if (parent.isModel())
{
children = parent.as<model::Model>().submodelsAs<model::EntityRefArray>();
this->addChildrenUUIDsIn(children, uuids);
children = parent.as<model::Model>().groupsAs<model::EntityRefArray>();
this->addChildrenUUIDsIn(children, uuids);
// NB: Exodus session doesn't provide cells, but if it did, traverse them here.
}
else if (parent.isGroup())
{
children = parent.as<model::Group>().members<model::EntityRefArray>();
this->addChildrenUUIDsIn(children, uuids);
}
}
} // namespace exodus
} // namespace bridge
} // namespace smtk
......@@ -10,12 +10,13 @@
#ifndef __smtk_model_SessionExodusIOJSON_h
#define __smtk_model_SessionExodusIOJSON_h
#include "smtk/model/SessionIO.h"
#include "smtk/model/SessionIOJSON.h"
struct cJSON;
namespace smtk {
namespace model {
namespace bridge {
namespace exodus {
/**\brief A base class for delegating session I/O to/from JSON.
*
......@@ -23,24 +24,45 @@ namespace smtk {
* importJSON and exportJSON methods.
*/
// ++ 1 ++
class SMTKCORE_EXPORT SessionIOJSON : public SessionIO
class SMTKCORE_EXPORT SessionIOJSON : public smtk::model::SessionIOJSON
{
public:
smtkTypeMacro(SessionIOJSON);
smtkCreateMacro(SessionIOJSON);
SessionIOJSON();
virtual ~SessionIOJSON() { }
virtual int importJSON(ManagerPtr modelMgr, const SessionPtr& session,
virtual int importJSON(model::ManagerPtr modelMgr, const model::SessionPtr& session,
cJSON* sessionRec, bool loadNativeModels = false);
virtual int exportJSON(ManagerPtr modelMgr, const SessionPtr& sessPtr,
virtual int exportJSON(model::ManagerPtr modelMgr, const model::SessionPtr& sessPtr,
cJSON* sessionRec, bool writeNativeModels = false);
virtual int exportJSON(ManagerPtr modelMgr, const SessionPtr& session,
virtual int exportJSON(model::ManagerPtr modelMgr, const model::SessionPtr& session,
const common::UUIDs &modelIds, cJSON* sessionRec,
bool writeNativeModels = false);
protected:
void addChildrenUUIDs(const model::EntityRef& parent, common::UUIDArray& uuids);
template<typename T>
void addChildrenUUIDsIn(const T& container, common::UUIDArray& uuids)
{
typename T::const_iterator it;
for (it = container.begin(); it != container.end(); ++it)
{
uuids.push_back(it->entity());
this->addChildrenUUIDs(*it, uuids);
}
}
int loadExodusFileWithUUIDs(
const model::SessionRef& sref,
const std::string& url,
const common::UUIDArray& preservedUUIDs);
};
// -- 1 --
} // namespace model
} // namespace exodus
} // namespace bridge
} // namespace smtk
#endif // __smtk_model_SessionExodusIOJSON_h
......@@ -24,7 +24,13 @@
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::SMTK_DIMENSION', unmatched return type 'vtkInformationIntegerKey*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::numberOfModels', unmatched return type 'size_t'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::ensureChildParentMapEntry', unmatched parameter type 'vtkDataObject*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::parentAs', unmatched return type 'T*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::modelOfHandleAs', unmatched return type 'T*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::modelOfHandle', unmatched return type 'vtkDataObject*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::SMTK_CHILDREN', unmatched return type 'vtkInformationObjectBaseVectorKey*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::SMTK_LABEL_VALUE', unmatched return type 'vtkInformationDoubleKey*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::SMTK_OUTER_LABEL', unmatched return type 'vtkInformationIntegerKey*'"/>
<suppress-warning text="skipping function 'smtk::bridge::exodus::Session::parent', unmatched return type 'vtkDataObject*'"/>
<!-- Ignore Exodus-specific enums -->
......
......@@ -385,8 +385,9 @@ void qtBaseView::showAdvanceLevel(int level)
this->buildUI();
}
void qtBaseView::createWidget()
void qtBaseView::enableShowBy(int enable)
{
this->Internals->ShowCategoryCombo->setEnabled(enable ? true : false);
}
//----------------------------------------------------------------------------
......
......@@ -101,7 +101,7 @@ namespace smtk
{ m_advOverlayVisible = val;}
virtual void showAdvanceLevel(int i);
virtual void updateViewUI(int /* currentTab */){}
virtual void enableShowBy(int /* enable */){}
virtual void enableShowBy(int /* enable */);
virtual void onShowCategory(){}
......@@ -119,7 +119,7 @@ namespace smtk
// Description:
// Creates the main QT Widget that is associated with a View. Typically this
// is the only method a derived View needs to override.
virtual void createWidget();
virtual void createWidget(){}
// Description:
// Adds properties associated with respects to a top level view
......
......@@ -76,6 +76,11 @@ qtGroupView::~qtGroupView()
void qtGroupView::updateCurrentTab(int ithTab)
{
this->Internals->m_currentTabSelected = ithTab;
qtBaseView* currView = this->getChildView(ithTab);
if(currView)
{
currView->updateUI();
}
}
//----------------------------------------------------------------------------
......
......@@ -486,10 +486,12 @@ int ExportJSON::forManagerIntegerProperties(const smtk::common::UUID& uid, cJSON
return ExportJSON::forIntegerData(dict, entIt->second);
}
int ExportJSON::forManagerSession(const smtk::common::UUID& uid,
cJSON* node,
ManagerPtr modelMgr,
bool writeNativeModels)
int ExportJSON::forManagerSession(
const smtk::common::UUID& uid,
cJSON* node,
ManagerPtr modelMgr,
bool writeNativeModels,
const std::string& refPath)
{
int status = 1;
SessionPtr session = SessionRef(modelMgr, uid).session();
......@@ -504,16 +506,26 @@ int ExportJSON::forManagerSession(const smtk::common::UUID& uid,
smtk::dynamic_pointer_cast<SessionIOJSON>(
session->createIODelegate("json"));
if (delegate)
{
delegate->setReferencePath(refPath);
status &= delegate->exportJSON(modelMgr, session, sess, writeNativeModels);
}
smtk::model::Models modelsOfSession = SessionRef(modelMgr, session).models<smtk::model::Models>();
ExportJSON::addModelsRecord(modelMgr, modelsOfSession, sess);
ExportJSON::addMeshesRecord(modelMgr, modelsOfSession, sess);
status &= ExportJSON::forOperatorDefinitions(session->operatorSystem(), sess);
return status;
}
int ExportJSON::forManagerSessionPartial(const smtk::common::UUID& sessionid,
const smtk::common::UUIDs& modelIds,
cJSON* node,
ManagerPtr modelMgr,
bool writeNativeModels)
int ExportJSON::forManagerSessionPartial(
const smtk::common::UUID& sessionid,
const smtk::common::UUIDs& modelIds,
cJSON* node,
ManagerPtr modelMgr,
bool writeNativeModels,
const std::string& refPath)
{
int status = 1;
SessionPtr session = SessionRef(modelMgr, sessionid).session();
......@@ -529,7 +541,12 @@ int ExportJSON::forManagerSessionPartial(const smtk::common::UUID& sessionid,
smtk::dynamic_pointer_cast<SessionIOJSON>(
session->createIODelegate("json"));
if (delegate)
{
delegate->setReferencePath(refPath);
status &= delegate->exportJSON(modelMgr, session, modelIds, sess, writeNativeModels);
}
ExportJSON::addModelsRecord(modelMgr, modelIds, sess);
ExportJSON::addMeshesRecord(modelMgr, modelIds, sess);
status &= ExportJSON::forOperatorDefinitions(session->operatorSystem(), sess);
return status;
}
......@@ -1072,6 +1089,81 @@ int ExportJSON::forSingleCollection(cJSON* mdesc,
return 1;
}
/**\brief Add records for \a modelIds to its parent \a sessionRec.
*
* This will add a "models" record to \a sessionRec, and all models
* will be added as children of "models"
*/
int ExportJSON::addModelsRecord(
const smtk::model::ManagerPtr modelMgr,
const smtk::common::UUIDs& modelIds,
cJSON* sessionRec)
{
smtk::model::Models models;
smtk::model::EntityRef::EntityRefsFromUUIDs(models, modelMgr, modelIds);
return ExportJSON::addModelsRecord(modelMgr, models, sessionRec);
}
int ExportJSON::addModelsRecord(
const smtk::model::ManagerPtr modelMgr,
const smtk::model::Models& inModels,
cJSON* sessionRec)
{
cJSON* jmodels = cJSON_CreateObject();
cJSON_AddItemToObject(sessionRec, "models", jmodels);
// add record for each model
smtk::model::Models::const_iterator modit;
for (modit = inModels.begin(); modit != inModels.end(); ++modit)
{
//smtk::model::Model model(modelMgr, *modit);
cJSON* jmodel = cJSON_CreateObject();
// Write out all entities of the model, only the meta data
smtk::model::Models currentmodels;
currentmodels.push_back(*modit);
ExportJSON::forEntities(
jmodel, currentmodels,
smtk::model::ITERATE_MODELS,
static_cast<smtk::io::JSONFlags>(
smtk::io::JSON_ENTITIES | smtk::io::JSON_PROPERTIES));
cJSON_AddItemToObject(jmodels, modit->entity().toString().c_str(), jmodel);
}
return 1;
}