Commit 2625cee4 authored by David Thompson's avatar David Thompson Committed by Kitware Robot

Merge topic 'save-as-changes'

9b08f99c Always named embedded files after the SMTK file.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !713
parents 6d151a90 9b08f99c
......@@ -24,6 +24,7 @@
#include "vtkDiscreteModelWrapper.h"
#include "vtkModel.h"
#include "vtkModelItem.h"
#include <vtksys/SystemTools.hxx>
#include "ReadOperator_xml.h"
......@@ -69,6 +70,7 @@ OperatorResult ReadOperator::operateInternal()
return this->createResult(OPERATION_FAILED);
this->m_op->SetFileName(fname.c_str());
std::string modelName = vtksys::SystemTools::GetFilenameWithoutExtension(fname.c_str());
// Create a new model to hold the result.
vtkNew<vtkDiscreteModelWrapper> mod;
......@@ -85,6 +87,7 @@ OperatorResult ReadOperator::operateInternal()
smtk::common::UUID modelId =
this->discreteSession()->trackModel(mod.GetPointer(), fname, this->manager());
smtk::model::EntityRef modelEntity(this->manager(), modelId);
modelEntity.setName(modelName);
OperatorResult result = this->createResult(OPERATION_SUCCEEDED);
smtk::attribute::ModelEntityItemPtr models = result->findModelEntity("created");
......
......@@ -108,48 +108,39 @@ bool SaveJSON::prepareToSave(const smtk::model::Models& modelsToSave,
Helpers::isDirectoryASubdirectory(embedDir.string(), url.parent_path().string(), relPath);
if (embedData)
{
/*
std::cout
<< "Is URL <" << url.parent_path().string() << "> inside EmbedDir <" << embedDir << ">? "
<< (alreadyEmbedded ? "Y" : "N")
<< " --- " << relPath << "\n";
*/
if (ok && !alreadyEmbedded)
{
std::string embeddedURL;
if (obj.m_saveModels.find(modelURL) == obj.m_saveModels.end())
{ // We haven't seen this model URL before.
embeddedURL = smtk::io::Helpers::uniqueFilename(url.filename().string(),
preExistingFilenames, smtkStem, defaultFileExtension, obj.m_embedDir);
obj.m_saveModels[modelURL] = embeddedURL;
smtk::model::SessionRef sref = model.owningSession();
if (!sref.op("write") && !sref.op("export") && !sref.op("save"))
std::string embeddedURL;
if (obj.m_saveModels.find(modelURL) == obj.m_saveModels.end())
{ // We haven't seen this model URL before.
embeddedURL = smtk::io::Helpers::uniqueFilename(smtkStem + defaultFileExtension,
preExistingFilenames, smtkStem, defaultFileExtension, obj.m_embedDir);
obj.m_saveModels[modelURL] = embeddedURL;
smtk::model::SessionRef sref = model.owningSession();
if (!sref.op("write") && !sref.op("export") && !sref.op("save"))
{
// We don't have an operator to save the model, so
// assume it hasn't changed and copy the file to its
// embedded location (if it exists in its original location).
::boost::filesystem::path prevURL(modelURL);
if (prevURL.is_relative() && model.hasStringProperty("smtk_url"))
{
// We don't have an operator to save the model, so
// assume it hasn't changed and copy the file to its
// embedded location (if it exists in its original location).
::boost::filesystem::path prevURL(modelURL);
if (prevURL.is_relative() && model.hasStringProperty("smtk_url"))
{
prevURL = prevEmbedDir / modelURL;
}
if (::boost::filesystem::exists(prevURL))
{
obj.m_copyFiles[prevURL.string()] = (embedDir / embeddedURL).string();
}
prevURL = prevEmbedDir / modelURL;
}
if (::boost::filesystem::exists(prevURL))
{
obj.m_copyFiles[prevURL.string()] = (embedDir / embeddedURL).string();
}
}
else
{ // Another model was stored in the same file URL as this model; look up the new URL.
embeddedURL = obj.m_saveModels[modelURL];
}
if (!embeddedURL.empty())
{
obj.m_modelChanges[model]["url"] = smtk::model::StringList(1, embeddedURL);
//::boost::filesystem::path url = ::boost::filesystem::canonical(modelURL, embedDir);
obj.m_saveErrors << "<li>Save " << url.filename().string() << " to "
<< (embedDir / embeddedURL).string() << "</li>";
}
}
else
{ // Another model was stored in the same file URL as this model; look up the new URL.
embeddedURL = obj.m_saveModels[modelURL];
}
if (!embeddedURL.empty())
{
obj.m_modelChanges[model]["url"] = smtk::model::StringList(1, embeddedURL);
//::boost::filesystem::path url = ::boost::filesystem::canonical(modelURL, embedDir);
obj.m_saveErrors << "<li>Save " << url.filename().string() << " to "
<< (embedDir / embeddedURL).string() << "</li>";
}
}
else
......
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