11#ifndef __vtkSlicerApplicationLogicRequests_h
12#define __vtkSlicerApplicationLogicRequests_h
51 int displayData,
int deleteFile,
int uid = 0)
66 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: read data request node id = " << nd->
GetID());
68 vtkSmartPointer<vtkMRMLStorageNode> storageNode;
69#ifdef Slicer_BUILD_CLI_SUPPORT
79 for (
int n = 0; n < numStorageNodes; n++)
84 if (useURI && testStorageNode->
GetURI() !=
nullptr)
89 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: found a storage node with the right URI: " << testStorageNode->
GetURI());
90 storageNode = testStorageNode;
94 else if (testStorageNode->
GetFileName() !=
nullptr &&
98 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: found a storage node with the right filename: " << testStorageNode->
GetFileName());
99 storageNode = testStorageNode;
106 bool createdNewStorageNode =
false;
107 if (storageNode.GetPointer() ==
nullptr)
110 if (itksys::SystemTools::FileExists(
m_Filename.c_str()))
115 createdNewStorageNode = (storageNode !=
nullptr);
120 if (storageNode.GetPointer() !=
nullptr)
124 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: about to call read data, " \
125 "storage node's read state is " << storageNode->GetReadStateAsString());
129 storageNode->SetWriteStateIdle();
133 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: calling ReadData on the storage node " \
134 << storageNode->GetID() <<
", uri = " << storageNode->GetURI());
135 storageNode->ReadData(nd,
true);
136 if (createdNewStorageNode)
138 storageNode->SetURI(
nullptr);
144 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: calling ReadData on the storage node " \
145 << storageNode->GetID() <<
", filename = " << storageNode->GetFileName());
146 storageNode->ReadData(nd,
true);
147 if (createdNewStorageNode)
149 storageNode->SetFileName(
nullptr);
153 catch (itk::ExceptionObject& exc)
155 vtkErrorWithObjectMacro(appLogic,
"Exception while reading " <<
m_Filename <<
", " << exc);
159 vtkErrorWithObjectMacro(appLogic,
"Unknown exception while reading " <<
m_Filename);
163#ifdef Slicer_BUILD_CLI_SUPPORT
177 if (
m_Filename.find(
"slicer:") != std::string::npos)
183 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str()));
187 vtkGenericWarningMacro(
"Unable to delete temporary file " <<
m_Filename);
252 const std::vector<std::string>& sourceNodes,
253 const std::string& filename,
254 int displayData,
int deleteFile,
280 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str()));
283 std::stringstream information;
284 information <<
"Unable to delete temporary file "
286 vtkGenericWarningMacro( << information.str().c_str() );
293 vtkNew<vtkMRMLScene> miniscene;
298 std::vector<std::string>::const_iterator tit;
299 std::vector<std::string>::const_iterator sit;
308 vtkMRMLNode *source = miniscene->GetNodeByID(sit->c_str());
311 if (source && target)
317 if ( storableTarget )
320 target->
Copy(source);
325 target->
Copy(source);
373 std::map<std::string, std::string> parentNodeIDMapper;
376 std::vector<vtkMRMLModelHierarchyNode *> childNodesThatNeedParentsIDsRemapped;
378 n<miniscene->GetNumberOfNodesByClass(
"vtkMRMLModelHierarchyNode");
382 ::SafeDownCast(miniscene->GetNthNodeByClass(n,
383 "vtkMRMLModelHierarchyNode"));
388 std::vector<std::string>::const_iterator ssit
404 parentNodeIDMapper[std::string(mhnd->
GetID())] = std::string(tchild->
GetID());
409 std::string parentNodeID = std::string(tmhnd->
GetID());
413 std::map<std::string,std::string>::iterator pIt = parentNodeIDMapper.find(std::string(tcmhd->
GetParentNodeID()));
414 if (pIt != parentNodeIDMapper.end())
416 parentNodeID = pIt->second;
417 vtkDebugWithObjectMacro(appLogic,
"Remapped parent node id to " << parentNodeID.c_str());
421 childNodesThatNeedParentsIDsRemapped.push_back(tcmhd);
454 if (childNodesThatNeedParentsIDsRemapped.size() > 0)
457 for (
unsigned int i = 0; i < childNodesThatNeedParentsIDsRemapped.size(); i++)
459 std::map<std::string,std::string>::iterator pIt = parentNodeIDMapper.find(childNodesThatNeedParentsIDsRemapped[i]->GetParentNodeID());
460 if (pIt != parentNodeIDMapper.end())
462 vtkDebugWithObjectMacro(appLogic,
"Remapping child node " << childNodesThatNeedParentsIDsRemapped[i]->GetName() << \
463 " parent node id from " << childNodesThatNeedParentsIDsRemapped[i]->GetParentNodeID() <<
" to " << pIt->second.c_str());
464 childNodesThatNeedParentsIDsRemapped[i]->SetParentNodeID(pIt->second.c_str());
472 std::stringstream information;
473 information <<
"Node " << (*sit) <<
" not found in scene file "
475 vtkGenericWarningMacro( << information.str().c_str() );
479 std::stringstream information;
480 information <<
"Node " << (*tit) <<
" not found in current scene."
482 vtkGenericWarningMacro( << information.str().c_str() );
495 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str() ));
498 std::stringstream information;
499 information <<
"Unable to delete temporary file "
501 vtkGenericWarningMacro( << information.str().c_str() );
519 const std::string& parentTransformNode,
int uid = 0)
547 const std::string& siblingNode,
int uid = 0)
564 if (updatedNodeShItemID && siblingNodeShItemID)
566 vtkIdType parentItemID = shnd->
GetItemParent(siblingNodeShItemID);
582 const std::string& referencedNode,
const std::string& role,
int uid = 0)
596 if (referencingNode && referencedNode)
613 const std::string& vtkNotUsed(node),
614 const std::string& vtkNotUsed(filename),
629 const std::vector<std::string>& sourceNodes,
630 const std::string& filename,
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)