11#ifndef __vtkSlicerApplicationLogicRequests_h
12#define __vtkSlicerApplicationLogicRequests_h
45 ReadDataRequestFile(
const std::string& node,
const std::string& filename,
int displayData,
int deleteFile,
int uid = 0)
60 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: read data request node id = " << nd->
GetID());
62 vtkSmartPointer<vtkMRMLStorageNode> storageNode;
71 for (
int n = 0; n < numStorageNodes; n++)
76 if (useURI && testStorageNode->
GetURI() !=
nullptr)
81 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: found a storage node with the right URI: " << testStorageNode->
GetURI());
82 storageNode = testStorageNode;
86 else if (testStorageNode->
GetFileName() !=
nullptr &&
90 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: found a storage node with the right filename: " << testStorageNode->
GetFileName());
91 storageNode = testStorageNode;
98 bool createdNewStorageNode =
false;
99 if (storageNode.GetPointer() ==
nullptr)
102 if (itksys::SystemTools::FileExists(
m_Filename.c_str()))
107 createdNewStorageNode = (storageNode !=
nullptr);
112 if (storageNode.GetPointer() !=
nullptr)
116 vtkDebugWithObjectMacro(appLogic,
117 "ProcessReadNodeData: about to call read data, "
118 "storage node's read state is "
119 << storageNode->GetReadStateAsString());
123 storageNode->SetWriteStateIdle();
127 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: calling ReadData on the storage node " << storageNode->GetID() <<
", uri = " << storageNode->GetURI());
128 storageNode->ReadData(nd,
true);
129 if (createdNewStorageNode)
131 storageNode->SetURI(
nullptr);
137 vtkDebugWithObjectMacro(appLogic,
138 "ProcessReadNodeData: calling ReadData on the storage node " << storageNode->GetID() <<
", filename = " << storageNode->GetFileName());
139 storageNode->ReadData(nd,
true);
140 if (createdNewStorageNode)
142 storageNode->SetFileName(
nullptr);
146 catch (itk::ExceptionObject& exc)
148 vtkErrorWithObjectMacro(appLogic,
"Exception while reading " <<
m_Filename <<
", " << exc);
152 vtkErrorWithObjectMacro(appLogic,
"Unknown exception while reading " <<
m_Filename);
168 if (
m_Filename.find(
"slicer:") != std::string::npos)
174 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str()));
178 vtkGenericWarningMacro(
"Unable to delete temporary file " <<
m_Filename);
241 const std::vector<std::string>& sourceNodes,
242 const std::string& filename,
270 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str()));
273 std::stringstream information;
274 information <<
"Unable to delete temporary file " <<
m_Filename << std::endl;
275 vtkGenericWarningMacro(<< information.str().c_str());
282 vtkNew<vtkMRMLScene> miniscene;
287 std::vector<std::string>::const_iterator tit;
288 std::vector<std::string>::const_iterator sit;
297 vtkMRMLNode* source = miniscene->GetNodeByID(sit->c_str());
300 if (source && target)
309 target->
Copy(source);
314 target->
Copy(source);
360 std::map<std::string, std::string> parentNodeIDMapper;
363 std::vector<vtkMRMLModelHierarchyNode*> childNodesThatNeedParentsIDsRemapped;
364 for (
int n = 0; n < miniscene->GetNumberOfNodesByClass(
"vtkMRMLModelHierarchyNode"); n++)
385 parentNodeIDMapper[std::string(mhnd->
GetID())] = std::string(tchild->
GetID());
389 std::string parentNodeID = std::string(tmhnd->
GetID());
393 std::map<std::string, std::string>::iterator pIt = parentNodeIDMapper.find(std::string(tcmhd->
GetParentNodeID()));
394 if (pIt != parentNodeIDMapper.end())
396 parentNodeID = pIt->second;
397 vtkDebugWithObjectMacro(appLogic,
"Remapped parent node id to " << parentNodeID.c_str());
401 childNodesThatNeedParentsIDsRemapped.push_back(tcmhd);
434 if (childNodesThatNeedParentsIDsRemapped.size() > 0)
437 for (
unsigned int i = 0; i < childNodesThatNeedParentsIDsRemapped.size(); i++)
439 std::map<std::string, std::string>::iterator pIt = parentNodeIDMapper.find(childNodesThatNeedParentsIDsRemapped[i]->GetParentNodeID());
440 if (pIt != parentNodeIDMapper.end())
442 vtkDebugWithObjectMacro(appLogic,
443 "Remapping child node " << childNodesThatNeedParentsIDsRemapped[i]->GetName() <<
" parent node id from "
444 << childNodesThatNeedParentsIDsRemapped[i]->GetParentNodeID() <<
" to " << pIt->second.c_str());
445 childNodesThatNeedParentsIDsRemapped[i]->SetParentNodeID(pIt->second.c_str());
453 std::stringstream information;
454 information <<
"Node " << (*sit) <<
" not found in scene file " <<
m_Filename << std::endl;
455 vtkGenericWarningMacro(<< information.str().c_str());
459 std::stringstream information;
460 information <<
"Node " << (*tit) <<
" not found in current scene." << std::endl;
461 vtkGenericWarningMacro(<< information.str().c_str());
474 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str()));
477 std::stringstream information;
478 information <<
"Unable to delete temporary file " <<
m_Filename << std::endl;
479 vtkGenericWarningMacro(<< information.str().c_str());
539 if (updatedNodeShItemID && siblingNodeShItemID)
541 vtkIdType parentItemID = shnd->
GetItemParent(siblingNodeShItemID);
570 if (referencingNode && referencedNode)
586 WriteDataRequestFile(
const std::string& vtkNotUsed(node),
const std::string& vtkNotUsed(filename),
int uid = 0)
600 WriteDataRequestScene(
const std::vector<std::string>& targetNodes,
const std::vector<std::string>& sourceNodes,
const std::string& filename,
int uid = 0)
virtual ~DataRequest()=default
virtual void Execute(vtkSlicerApplicationLogic *)
std::string m_ReferencingNode
void Execute(vtkSlicerApplicationLogic *appLogic) override
std::string m_ReferencedNode
ReadDataRequestAddNodeReference(const std::string &referencingNode, const std::string &referencedNode, const std::string &role, int uid=0)
ReadDataRequestFile(const std::string &node, const std::string &filename, int displayData, int deleteFile, int uid=0)
void Execute(vtkSlicerApplicationLogic *appLogic) override
ReadDataRequestScene(const std::vector< std::string > &targetNodes, const std::vector< std::string > &sourceNodes, const std::string &filename, int displayData, int deleteFile, int uid=0)
std::vector< std::string > m_TargetNodes
std::vector< std::string > m_SourceNodes
void Execute(vtkSlicerApplicationLogic *appLogic) override
std::string m_SubjectHierarchySiblingNode
ReadDataRequestUpdateSubjectHierarchyLocation(const std::string &updatedNode, const std::string &siblingNode, int uid=0)
void Execute(vtkSlicerApplicationLogic *appLogic) override
std::string m_UpdatedNode
WriteDataRequestFile(const std::string &vtkNotUsed(node), const std::string &vtkNotUsed(filename), int uid=0)
WriteDataRequestScene(const std::vector< std::string > &targetNodes, const std::vector< std::string > &sourceNodes, const std::string &filename, int uid=0)
std::vector< std::string > m_TargetNodes
void Execute(vtkSlicerApplicationLogic *appLogic) override
std::vector< std::string > m_SourceNodes
virtual int IsRemoteReference(const char *uri)
vtkMRMLScene * GetMRMLScene() const
Return a reference to the current MRML scene.
void PropagateTableSelection()
Propagate selected table in the SelectionNode to table view nodes.
void PropagateVolumeSelection(int fit=1)
vtkMRMLSelectionNode * GetSelectionNode() const
Get default Selection node.
MRML node for representing the parameters allowing to run a command line interface module (CLI)....
static vtkMRMLCommandLineModuleNode * SafeDownCast(vtkObject *o)
bool ReadParameterFile(const std::string &filename)
Abstract class that contains graphical display properties for displayable nodes.
vtkMRMLDisplayNode * GetDisplayNode()
Get associated display MRML node.
void SetAndObserveDisplayNodeID(const char *DisplayNodeID)
static vtkMRMLDisplayableNode * SafeDownCast(vtkObject *o)
void SetAndObserveDisplayNodeID(const char *displayNodeID)
virtual void CreateDefaultDisplayNodes()
vtkMRMLDisplayNode * GetDisplayNode()
vtkMRMLHierarchyNode * GetTopParentNode()
Get the top parent node in the hierarchy.
virtual char * GetParentNodeID()
String ID of the parent hierarchy MRML node.
virtual void SetParentNodeID(const char *ref)
static vtkMRMLLabelMapVolumeNode * SafeDownCast(vtkObject *o)
MRML node to represent a hierarchy of models.
void SetModelNodeID(const char *id)
String ID of the model MRML node.
static vtkMRMLModelHierarchyNode * SafeDownCast(vtkObject *o)
vtkMRMLModelNode * GetModelNode()
Get associated model MRML node.
MRML node to represent a 3D surface model.
static vtkMRMLModelNode * SafeDownCast(vtkObject *o)
Abstract Superclass for all specific types of MRML nodes.
virtual char * GetID()
ID use by other nodes to reference this node in XML.
vtkMRMLNode * AddNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Convenience method that adds a referencedNodeID at the end of the list.
void Modified() override
Customized version of Modified() allowing to compress vtkCommand::ModifiedEvent.
virtual void Copy(vtkMRMLNode *node)
Copy node contents from another node of the same type. Does not copy node ID and Scene....
static vtkMRMLScalarVolumeNode * SafeDownCast(vtkObject *o)
A set of MRML Nodes that supports serialization and undo/redo.
void StartState(unsigned long state, int anticipatedMaxProgress=0)
Flag the scene as being in a state mode.
void EndState(unsigned long state)
Unflag the scene as being in a state mode.
int Commit(const char *url=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
virtual vtkCacheManager * GetCacheManager()
vtkMRMLNode * CopyNode(vtkMRMLNode *n)
Add a copy of a node to the scene.
vtkMRMLNode * GetNodeByID(const char *name)
Get node given a unique ID.
int Import(vtkMRMLMessageCollection *userMessages=nullptr)
Add the scene into the existing scene (no clear) from URL file or from.
void SetURL(const char *url)
Set URL (file name) of the scene.
void SetActiveTableID(const char *id)
void SetActiveVolumeID(const char *id)
void SetActiveLabelVolumeID(const char *id)
MRML node to represent a 3D surface model.
vtkMRMLStorageNode * GetNthStorageNode(int n)
Get associated display MRML node.
void SetAndObserveStorageNodeID(const char *storageNodeID)
String ID of the storage MRML node.
virtual bool AddDefaultStorageNode(const char *filename=nullptr)
const char * GetStorageNodeID()
vtkMRMLStorageNode * GetStorageNode()
static vtkMRMLStorableNode * SafeDownCast(vtkObject *o)
int GetNumberOfStorageNodes()
A superclass for other storage nodes.
virtual char * GetFileName()
MRML node to represent a complete subject hierarchy tree.
vtkIdType GetItemByDataNode(vtkMRMLNode *dataNode)
void SetItemLevel(vtkIdType itemID, std::string level)
Convenience function to set level attribute for a subject hierarchy item.
void SetItemParent(vtkIdType itemID, vtkIdType parentItemID, bool enableCircularCheck=true)
static vtkMRMLSubjectHierarchyNode * GetSubjectHierarchyNode(vtkMRMLScene *scene)
std::string GetItemLevel(vtkIdType itemID)
Convenience function to get level attribute for a subject hierarchy item.
vtkIdType GetItemParent(vtkIdType itemID)
static vtkMRMLTableNode * SafeDownCast(vtkObject *o)