Skip to content

Commit

Permalink
ENH: Improve vtkMRMLLayoutNode API
Browse files Browse the repository at this point in the history
The layout node did not have an API to remove a layout or easily copy all layouts.
  • Loading branch information
lassoan authored and jcfr committed Mar 5, 2024
1 parent 6b81ca2 commit 124abf6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
40 changes: 38 additions & 2 deletions Libs/MRML/Core/vtkMRMLLayoutNode.cxx
Expand Up @@ -224,18 +224,42 @@ bool vtkMRMLLayoutNode::SetLayoutDescription(int layout, const char* layoutDescr
vtkDebugMacro( << "Layout " << layout << " has NOT been registered");
return false;
}
if (this->Layouts[layout] == layoutDescription)
std::string layoutDescriptionStr;
if (layoutDescription)
{
layoutDescriptionStr = std::string(layoutDescription);
}
if (this->Layouts[layout] == layoutDescriptionStr)
{
// No change
return true;
}
this->Layouts[layout] = std::string(layoutDescription);
if (layoutDescriptionStr.empty())
{
this->Layouts.erase(layout);
}
else
{
this->Layouts[layout] = layoutDescriptionStr;
}
int wasModifying = this->StartModify();
this->UpdateCurrentLayoutDescription();
this->Modified();
this->EndModify(wasModifying);
return true;
}

//----------------------------------------------------------------------------
std::vector<int> vtkMRMLLayoutNode::GetLayoutIndices()
{
std::vector<int> indices;
for (const auto& keyValuePair : this->Layouts)
{
indices.push_back(keyValuePair.first);
}
return indices;
}

//----------------------------------------------------------------------------
bool vtkMRMLLayoutNode::IsLayoutDescription(int layout)
{
Expand Down Expand Up @@ -357,6 +381,18 @@ void vtkMRMLLayoutNode::Copy(vtkMRMLNode *anode)
this->EndModify(disabledModify);
}

//----------------------------------------------------------------------------
void vtkMRMLLayoutNode::CopyLayoutDescriptions(vtkMRMLLayoutNode* source)
{
if (!source)
{
vtkErrorMacro("CopyLayoutDescriptions: Invalid source node");
return;
}
this->Layouts = source->Layouts;
this->Modified();
}

//----------------------------------------------------------------------------
void vtkMRMLLayoutNode::PrintSelf(ostream& os, vtkIndent indent)
{
Expand Down
8 changes: 8 additions & 0 deletions Libs/MRML/Core/vtkMRMLLayoutNode.h
Expand Up @@ -139,15 +139,23 @@ class VTK_MRML_EXPORT vtkMRMLLayoutNode : public vtkMRMLAbstractLayoutNode
/// Modifies a layout description for integer identifier
/// "layout". Returns false without making any modifications if the
/// integer identifier "layout" has NOT already been added.
/// If layoutDescription is empty then the layout is removed.
bool SetLayoutDescription(int layout, const char* layoutDescription);

/// Get list of all specified layout indices
std::vector<int> GetLayoutIndices();

/// Query whether a layout exists with a specified integer identifier
bool IsLayoutDescription(int layout);

/// Get the layout description associated with a specified integer
/// identifier. The empty string is returned if the layout does not exist.
std::string GetLayoutDescription(int layout);

/// Copy all layout descriptions from the specified layout node.
/// All the previous layout descriptions are replaced.
void CopyLayoutDescriptions(vtkMRMLLayoutNode* source);

// Get the layout description currently displayed. Used
// internally. This is XML description corresponding to the ivar
// ViewArrangement which is the integer identifier for the
Expand Down

0 comments on commit 124abf6

Please sign in to comment.