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 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: calling ReadData on the storage node " \
130 << storageNode->GetID() <<
", uri = " << storageNode->GetURI());
131 storageNode->ReadData(nd,
true);
132 if (createdNewStorageNode)
134 storageNode->SetURI(
nullptr);
140 vtkDebugWithObjectMacro(appLogic,
"ProcessReadNodeData: calling ReadData on the storage node " \
141 << storageNode->GetID() <<
", filename = " << storageNode->GetFileName());
142 storageNode->ReadData(nd,
true);
143 if (createdNewStorageNode)
145 storageNode->SetFileName(
nullptr);
149 catch (itk::ExceptionObject& exc)
151 vtkErrorWithObjectMacro(appLogic,
"Exception while reading " <<
m_Filename <<
", " << exc);
155 vtkErrorWithObjectMacro(appLogic,
"Unknown exception while reading " <<
m_Filename);
159 #ifdef Slicer_BUILD_CLI_SUPPORT 173 if (
m_Filename.find(
"slicer:") != std::string::npos)
179 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str()));
183 vtkGenericWarningMacro(
"Unable to delete temporary file " <<
m_Filename);
248 const std::vector<std::string>& sourceNodes,
249 const std::string& filename,
250 int displayData,
int deleteFile,
276 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str()));
279 std::stringstream information;
280 information <<
"Unable to delete temporary file " 282 vtkGenericWarningMacro( << information.str().c_str() );
289 vtkNew<vtkMRMLScene> miniscene;
294 std::vector<std::string>::const_iterator tit;
295 std::vector<std::string>::const_iterator sit;
304 vtkMRMLNode *source = miniscene->GetNodeByID(sit->c_str());
307 if (source && target)
313 if ( storableTarget )
316 target->
Copy(source);
321 target->
Copy(source);
369 std::map<std::string, std::string> parentNodeIDMapper;
372 std::vector<vtkMRMLModelHierarchyNode *> childNodesThatNeedParentsIDsRemapped;
374 n<miniscene->GetNumberOfNodesByClass(
"vtkMRMLModelHierarchyNode");
379 "vtkMRMLModelHierarchyNode"));
384 std::vector<std::string>::const_iterator ssit
400 parentNodeIDMapper[std::string(mhnd->
GetID())] = std::string(tchild->
GetID());
405 std::string parentNodeID = std::string(tmhnd->
GetID());
406 if (tcmhd->GetParentNodeID() !=
nullptr &&
407 strcmp(tcmhd->GetParentNodeID(),smhnd->
GetID()) != 0)
409 std::map<std::string,std::string>::iterator pIt = parentNodeIDMapper.find(std::string(tcmhd->GetParentNodeID()));
410 if (pIt != parentNodeIDMapper.end())
412 parentNodeID = pIt->second;
413 vtkDebugWithObjectMacro(appLogic,
"Remapped parent node id to " << parentNodeID.c_str());
417 childNodesThatNeedParentsIDsRemapped.push_back(tcmhd);
420 tcmhd->SetParentNodeID( parentNodeID.c_str() );
432 tcmhd->SetModelNodeID( mnd->
GetID() );
444 tcmhd->SetAndObserveDisplayNodeID( tdnd->
GetID() );
450 if (childNodesThatNeedParentsIDsRemapped.size() > 0)
453 for (
unsigned int i = 0; i < childNodesThatNeedParentsIDsRemapped.size(); i++)
455 std::map<std::string,std::string>::iterator pIt = parentNodeIDMapper.find(childNodesThatNeedParentsIDsRemapped[i]->GetParentNodeID());
456 if (pIt != parentNodeIDMapper.end())
458 vtkDebugWithObjectMacro(appLogic,
"Remapping child node " << childNodesThatNeedParentsIDsRemapped[i]->GetName() << \
459 " parent node id from " << childNodesThatNeedParentsIDsRemapped[i]->GetParentNodeID() <<
" to " << pIt->second.c_str());
460 childNodesThatNeedParentsIDsRemapped[i]->SetParentNodeID(pIt->second.c_str());
468 std::stringstream information;
469 information <<
"Node " << (*sit) <<
" not found in scene file " 471 vtkGenericWarningMacro( << information.str().c_str() );
475 std::stringstream information;
476 information <<
"Node " << (*tit) <<
" not found in current scene." 478 vtkGenericWarningMacro( << information.str().c_str() );
491 removed =
static_cast<bool>(itksys::SystemTools::RemoveFile(
m_Filename.c_str() ));
494 std::stringstream information;
495 information <<
"Unable to delete temporary file " 497 vtkGenericWarningMacro( << information.str().c_str() );
515 const std::string& parentTransformNode,
int uid = 0)
543 const std::string& siblingNode,
int uid = 0)
560 if (updatedNodeShItemID && siblingNodeShItemID)
562 vtkIdType parentItemID = shnd->
GetItemParent(siblingNodeShItemID);
578 const std::string& referencedNode,
const std::string& role,
int uid = 0)
592 if (referencingNode && referencedNode)
609 const std::string& vtkNotUsed(node),
610 const std::string& vtkNotUsed(filename),
625 const std::vector<std::string>& sourceNodes,
626 const std::string& filename,
656 #endif // __vtkSlicerApplicationLogicRequests_h void Execute(vtkSlicerApplicationLogic *appLogic) override
void Execute(vtkSlicerApplicationLogic *appLogic) override
void SetActiveVolumeID(const char *id)
void Execute(vtkSlicerApplicationLogic *appLogic) override
void EndState(unsigned long state)
Unflag the scene as being in a state mode.
ReadDataRequestUpdateSubjectHierarchyLocation(const std::string &updatedNode, const std::string &siblingNode, int uid=0)
void SetAndObserveDisplayNodeID(const char *displayNodeID)
vtkMRMLStorageNode * GetNthStorageNode(int n)
Get associated display MRML node
vtkMRMLHierarchyNode * GetTopParentNode()
Get the top parent node in the hierarchy
void Execute(vtkSlicerApplicationLogic *appLogic) override
virtual ~DataRequest()=default
MRML node to represent a 3D surface model.
void SetItemLevel(vtkIdType itemID, std::string level)
Convenience function to set level attribute for a subject hierarchy item.
WriteDataRequestScene(const std::vector< std::string > &targetNodes, const std::vector< std::string > &sourceNodes, const std::string &filename, int uid=0)
vtkMRMLSelectionNode * GetSelectionNode() const
Get default Selection node.
vtkMRMLScene * GetMRMLScene() const
Return a reference to the current MRML scene.
void Execute(vtkSlicerApplicationLogic *appLogic) override
vtkMRMLNode * CopyNode(vtkMRMLNode *n)
Add a copy of a node to the scene.
std::vector< std::string > m_SourceNodes
WriteDataRequestFile(const std::string &vtkNotUsed(node), const std::string &vtkNotUsed(filename), int uid=0)
void SetAndObserveDisplayNodeID(const char *DisplayNodeID)
MRML node to represent a complete subject hierarchy tree.
static vtkMRMLModelHierarchyNode * SafeDownCast(vtkObject *o)
void PropagateVolumeSelection(int fit=1)
std::string m_SubjectHierarchySiblingNode
static vtkMRMLCommandLineModuleNode * SafeDownCast(vtkObject *o)
ReadDataRequestAddNodeReference(const std::string &referencingNode, const std::string &referencedNode, const std::string &role, int uid=0)
void SetActiveLabelVolumeID(const char *id)
const char * GetStorageNodeID()
vtkMRMLDisplayNode * GetDisplayNode()
Get associated display MRML node
virtual bool AddDefaultStorageNode(const char *filename=nullptr)
virtual void Copy(vtkMRMLNode *node)
Copy node contents from another node of the same type. Does not copy node ID and Scene. Performs deep copy - an independent copy is created from all data, including bulk data.
MRML node to represent a 3D surface model.
void SetAndObserveStorageNodeID(const char *storageNodeID)
String ID of the storage MRML node
A set of MRML Nodes that supports serialization and undo/redo.
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.
std::vector< std::string > m_SourceNodes
virtual char * GetFileName()
int Commit(const char *url=nullptr, vtkMRMLMessageCollection *userMessages=nullptr)
std::string m_ReferencedNode
static vtkMRMLLabelMapVolumeNode * SafeDownCast(vtkObject *o)
static vtkMRMLSubjectHierarchyNode * GetSubjectHierarchyNode(vtkMRMLScene *scene)
virtual void CreateDefaultDisplayNodes()
void StartState(unsigned long state, int anticipatedMaxProgress=0)
Flag the scene as being in a state mode.
void PropagateTableSelection()
Propagate selected table in the SelectionNode to table view nodes.
virtual vtkCacheManager * GetCacheManager()
std::vector< std::string > m_TargetNodes
vtkMRMLNode * GetNodeByID(const char *name)
Get node given a unique ID.
vtkMRMLDisplayNode * GetDisplayNode()
static vtkMRMLStorableNode * SafeDownCast(vtkObject *o)
std::string GetItemLevel(vtkIdType itemID)
Convenience function to get level attribute for a subject hierarchy item.
A superclass for other storage nodes.
void SetModelNodeID(const char *id)
String ID of the model MRML node
MRML node to represent a hierarchyu of models.
static vtkMRMLTableNode * SafeDownCast(vtkObject *o)
vtkMRMLModelNode * GetModelNode()
Get associated model MRML node
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.
virtual int IsRemoteReference(const char *uri)
int GetNumberOfStorageNodes()
vtkIdType GetItemByDataNode(vtkMRMLNode *dataNode)
vtkMRMLStorageNode * GetStorageNode()
static vtkMRMLScalarVolumeNode * SafeDownCast(vtkObject *o)
void SetItemParent(vtkIdType itemID, vtkIdType parentItemID, bool enableCircularCheck=true)
bool ReadParameterFile(const std::string &filename)
std::string m_ReferencingNode
static vtkMRMLDisplayableNode * SafeDownCast(vtkObject *o)
virtual void SetURI(const char *)
Location of the remote copy of this file.
Abstract class that contains graphical display properties for displayable nodes.
void Modified() override
Customized version of Modified() allowing to compress vtkCommand::ModifiedEvent.
void SetActiveTableID(const char *id)
Abstract Superclass for all specific types of MRML nodes.
MRML node for representing the parameters allowing to run a command line interface module (CLI)...
ReadDataRequestScene(const std::vector< std::string > &targetNodes, const std::vector< std::string > &sourceNodes, const std::string &filename, int displayData, int deleteFile, int uid=0)
vtkIdType GetItemParent(vtkIdType itemID)
std::string m_UpdatedNode
std::vector< std::string > m_TargetNodes
static vtkMRMLModelNode * SafeDownCast(vtkObject *o)
ReadDataRequestFile(const std::string &node, const std::string &filename, int displayData, int deleteFile, int uid=0)
virtual void Execute(vtkSlicerApplicationLogic *)