PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusSaveConfigCommand.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4 See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #include "PlusConfigure.h"
8 #include "vtkPlusDataCollector.h"
10 #include "vtkPlusCommandResponse.h"
12 #include "vtkIGSIOTransformRepository.h"
13 #include "vtkPlusVirtualCapture.h"
14 
16 
17 namespace
18 {
19  static const std::string SAVE_CONFIG_CMD = "SaveConfig";
20 }
21 
22 //----------------------------------------------------------------------------
24 {
25 }
26 
27 //----------------------------------------------------------------------------
29 {
30 
31 }
32 
33 //----------------------------------------------------------------------------
35 {
36  this->SetName(SAVE_CONFIG_CMD);
37 }
38 
39 //----------------------------------------------------------------------------
40 void vtkPlusSaveConfigCommand::GetCommandNames(std::list<std::string>& cmdNames)
41 {
42  cmdNames.clear();
43  cmdNames.push_back(SAVE_CONFIG_CMD);
44 }
45 
46 //----------------------------------------------------------------------------
47 std::string vtkPlusSaveConfigCommand::GetDescription(const std::string& commandName)
48 {
49  std::string desc;
50  if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, SAVE_CONFIG_CMD))
51  {
52  desc += SAVE_CONFIG_CMD;
53  desc += ": Tell the data collector to save the config file.";
54  }
55  return desc;
56 }
57 
58 //----------------------------------------------------------------------------
59 void vtkPlusSaveConfigCommand::PrintSelf(ostream& os, vtkIndent indent)
60 {
61  this->Superclass::PrintSelf(os, indent);
62  os << indent << "Filename: " << this->Filename;
63 }
64 
65 //----------------------------------------------------------------------------
67 {
69  {
70  return PLUS_FAIL;
71  }
72  this->SetFilename(aConfig->GetAttribute("Filename"));
73  return PLUS_SUCCESS;
74 }
75 
76 //----------------------------------------------------------------------------
78 {
80  {
81  return PLUS_FAIL;
82  }
83  // Start parameters
84  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(Filename, aConfig);
85  return PLUS_SUCCESS;
86 }
87 
88 //----------------------------------------------------------------------------
90 {
91  LOG_INFO("vtkPlusSaveConfigCommand::Execute");
92 
93  if (GetFilename().empty())
94  {
95  this->SetFilename(this->CommandProcessor->GetPlusServer()->GetConfigFilename());
96  }
97 
98  std::string baseMessageString = std::string("SaveConfig (") + (!this->Filename.empty() ? this->Filename : "undefined") + ")";
99 
100  if (this->GetDataCollector() == NULL)
101  {
102  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", baseMessageString + " Can't access data collector.");
103  return PLUS_FAIL;
104  }
105  if (this->GetDataCollector()->WriteConfiguration(vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationData()) != PLUS_SUCCESS
106  || this->GetTransformRepository()->WriteConfiguration(vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationData()) != PLUS_SUCCESS)
107  {
108  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", baseMessageString + " Unable to write configuration.");
109  return PLUS_FAIL;
110  }
111 
112  igsioCommon::XML::PrintXML(this->GetFilename(), vtkPlusConfig::GetInstance()->GetDeviceSetConfigurationData());
113  this->QueueCommandResponse(PLUS_SUCCESS, baseMessageString + " Completed successfully.");
114  return PLUS_SUCCESS;
115 }
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDescription(const std::string &commandName)
virtual void PrintSelf(ostream &os, vtkIndent indent)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual vtkIGSIOTransformRepository * GetTransformRepository()
virtual vtkPlusOpenIGTLinkServer * GetPlusServer()
#define PLUS_FAIL
Definition: PlusCommon.h:43
static vtkPlusConfig * GetInstance()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual void GetCommandNames(std::list< std::string > &cmdNames)
vtkPlusCommandProcessor * CommandProcessor
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual vtkPlusDataCollector * GetDataCollector()
This command forces the data collector to save the config file.
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
vtkStandardNewMacro(vtkPlusSaveConfigCommand)