Skip to content

Commit

Permalink
BUG: Fix filename when loading markup node from file
Browse files Browse the repository at this point in the history
Entire filename part after the first . was removed, instead of just stripping the known file extension.
For example, F.ab.fcsv, and F.aa.fcsv were both shown as F in the data module after load.

Fixed by removing only the known file extension.
  • Loading branch information
lassoan committed Jun 11, 2020
1 parent eac7802 commit 6e346bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
26 changes: 17 additions & 9 deletions Modules/Loadable/Markups/Logic/vtkSlicerMarkupsLogic.cxx
Expand Up @@ -755,20 +755,28 @@ char * vtkSlicerMarkupsLogic::LoadMarkupsFromFcsv(const char* fileName, const ch
}

vtkDebugMacro("LoadMarkups, file name = " << fileName << ", nodeName = " << (nodeName ? nodeName : "null"));

vtkMRMLMarkupsNode* markupsNode = vtkMRMLMarkupsNode::SafeDownCast(this->GetMRMLScene()->AddNewNodeByClass("vtkMRMLMarkupsFiducialNode", nodeName));
if (!markupsNode)
{
vtkErrorMacro("LoadMarkups: failed to instantiate markups node by class vtkMRMLMarkupsFiducialNode");
return nullptr;
}

// make a storage node and fiducial node and set the file name
vtkMRMLStorageNode* storageNode = vtkMRMLStorageNode::SafeDownCast(this->GetMRMLScene()->AddNewNodeByClass("vtkMRMLMarkupsFiducialStorageNode"));
if (!storageNode)
{
vtkErrorMacro("LoadMarkups: failed to instantiate markups storage node by class vtkMRMLMarkupsFiducialNode");
this->GetMRMLScene()->RemoveNode(markupsNode);
return nullptr;
}

std::string newNodeName;
if (nodeName && strlen(nodeName)>0)
{
newNodeName = nodeName;
}
else
{
newNodeName = this->GetMRMLScene()->GetUniqueNameByString(storageNode->GetFileNameWithoutExtension(fileName).c_str());
}
vtkMRMLMarkupsNode* markupsNode = vtkMRMLMarkupsNode::SafeDownCast(this->GetMRMLScene()->AddNewNodeByClass("vtkMRMLMarkupsFiducialNode", newNodeName));
if (!markupsNode)
{
vtkErrorMacro("LoadMarkups: failed to instantiate markups node by class vtkMRMLMarkupsFiducialNode");
this->GetMRMLScene()->RemoveNode(storageNode);
return nullptr;
}

Expand Down
12 changes: 11 additions & 1 deletion Modules/Loadable/Markups/MRML/vtkMRMLMarkupsJsonStorageNode.cxx
Expand Up @@ -710,7 +710,17 @@ vtkMRMLMarkupsNode* vtkMRMLMarkupsJsonStorageNode::AddNewMarkupsNodeFromFile(con
return nullptr;
}
std::string markupsType = markup["type"].GetString();
vtkMRMLMarkupsNode* markupsNode = vtkMRMLMarkupsNode::SafeDownCast(scene->AddNewNodeByClass(className.c_str(), nodeName ? nodeName : ""));

std::string newNodeName;
if (nodeName && strlen(nodeName)>0)
{
newNodeName = nodeName;
}
else
{
newNodeName = scene->GetUniqueNameByString(this->GetFileNameWithoutExtension(filePath).c_str());
}
vtkMRMLMarkupsNode* markupsNode = vtkMRMLMarkupsNode::SafeDownCast(scene->AddNewNodeByClass(className.c_str(), newNodeName));
if (!markupsNode)
{
vtkErrorMacro("vtkMRMLMarkupsStorageNode::ReadDataInternal failed: cannot instantiate class '" << className);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Loadable/Markups/qSlicerMarkupsReader.cxx
Expand Up @@ -102,7 +102,7 @@ bool qSlicerMarkupsReader::load(const IOProperties& properties)
Q_ASSERT(properties.contains("fileName"));
QString fileName = properties["fileName"].toString();

QString name = QFileInfo(fileName).baseName();
QString name;
if (properties.contains("name"))
{
name = properties["name"].toString();
Expand Down

0 comments on commit 6e346bf

Please sign in to comment.