Skip to content

Commit

Permalink
ENH: Do not allow loading the same treatment machine twice
Browse files Browse the repository at this point in the history
Re #218
  • Loading branch information
cpinter committed Oct 5, 2023
1 parent 959e529 commit 6fac598
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

// Constants
const char* vtkSlicerRoomsEyeViewModuleLogic::ORIENTATION_MARKER_MODEL_NODE_NAME = "RoomsEyeViewOrientationMarker";
const char* vtkSlicerRoomsEyeViewModuleLogic::TREATMENT_MACHINE_FOLDER_ITEM_ATTRIBUTE_NAME = "TreatmentMachineFolder";
const char* vtkSlicerRoomsEyeViewModuleLogic::TREATMENT_MACHINE_DESCRIPTOR_FILE_PATH_ATTRIBUTE_NAME = "TreatmentMachineDescriptorFilePath";
//TODO: Add this dynamically to the IEC transform map
static const char* ADDITIONALCOLLIMATORMOUNTEDDEVICES_TO_COLLIMATOR_TRANSFORM_NODE_NAME = "AdditionalCollimatorDevicesToCollimatorTransform";
static rapidjson::Value JSON_EMPTY_VALUE;
Expand Down Expand Up @@ -499,7 +499,7 @@ void vtkSlicerRoomsEyeViewModuleLogic::LoadTreatmentMachine(vtkMRMLRoomsEyeViewN
// Create subject hierarchy folder so that the treatment machine can be shown/hidden easily
std::string subjectHierarchyFolderName = machineType + std::string("_Components");
vtkIdType rootFolderItem = shNode->CreateFolderItem(shNode->GetSceneItemID(), subjectHierarchyFolderName);
shNode->SetItemAttribute(rootFolderItem, TREATMENT_MACHINE_FOLDER_ITEM_ATTRIBUTE_NAME, "1");
shNode->SetItemAttribute(rootFolderItem, TREATMENT_MACHINE_DESCRIPTOR_FILE_PATH_ATTRIBUTE_NAME, descriptorFilePath);

// Load treatment machine models

Expand Down
2 changes: 1 addition & 1 deletion RoomsEyeView/Logic/vtkSlicerRoomsEyeViewModuleLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class VTK_SLICER_ROOMSEYEVIEW_LOGIC_EXPORT vtkSlicerRoomsEyeViewModuleLogic :
};

static const char* ORIENTATION_MARKER_MODEL_NODE_NAME;
static const char* TREATMENT_MACHINE_FOLDER_ITEM_ATTRIBUTE_NAME;
static const char* TREATMENT_MACHINE_DESCRIPTOR_FILE_PATH_ATTRIBUTE_NAME;

public:
static vtkSlicerRoomsEyeViewModuleLogic *New();
Expand Down
40 changes: 23 additions & 17 deletions RoomsEyeView/qSlicerRoomsEyeViewModuleWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,21 @@ void qSlicerRoomsEyeViewModuleWidget::onLoadTreatmentMachineButtonClicked()
return;
}

// Get treatment machine descriptor file path
QString treatmentMachineType(d->TreatmentMachineComboBox->currentData().toString());
QString descriptorFilePath;
if (!treatmentMachineType.compare("FromFile"))
{
// Ask user for descriptor JSON file if load from file option is selected
descriptorFilePath = QFileDialog::getOpenFileName( this, "Select treatment machine descriptor JSON file...",
QString(), "Json files (*.json);; All files (*)" );
}
else //TODO: Currently support two default types in addition to loading file. Need to rethink the module
{
QString relativeFilePath = QString("%1/%2.json").arg(treatmentMachineType).arg(treatmentMachineType);
descriptorFilePath = QDir(d->logic()->GetModuleShareDirectory().c_str()).filePath(relativeFilePath);
}

// Check if there is a machine already loaded and ask user what to do if so
vtkMRMLSubjectHierarchyNode* shNode = this->mrmlScene()->GetSubjectHierarchyNode();
std::vector<vtkIdType> allItemIDs;
Expand All @@ -463,8 +478,14 @@ void qSlicerRoomsEyeViewModuleWidget::onLoadTreatmentMachineButtonClicked()
std::vector<vtkIdType>::iterator itemIt;
for (itemIt=allItemIDs.begin(); itemIt!=allItemIDs.end(); ++itemIt)
{
std::string machineFolderAttValue = shNode->GetItemAttribute(*itemIt, vtkSlicerRoomsEyeViewModuleLogic::TREATMENT_MACHINE_FOLDER_ITEM_ATTRIBUTE_NAME);
if (!machineFolderAttValue.compare("1"))
std::string machineDescriptorFilePath = shNode->GetItemAttribute(*itemIt,
vtkSlicerRoomsEyeViewModuleLogic::TREATMENT_MACHINE_DESCRIPTOR_FILE_PATH_ATTRIBUTE_NAME);
if (!machineDescriptorFilePath.compare(descriptorFilePath.toUtf8().constData()))
{
QMessageBox::warning(this, tr("Machine already loaded"), tr("This treatment machine is already loaded."));
return;
}
if (!machineDescriptorFilePath.empty())
{
machineFolderItemIDs.push_back(*itemIt);
}
Expand Down Expand Up @@ -503,21 +524,6 @@ void qSlicerRoomsEyeViewModuleWidget::onLoadTreatmentMachineButtonClicked()
}
}

// Get treatment machine descriptor file path
QString treatmentMachineType(d->TreatmentMachineComboBox->currentData().toString());
QString descriptorFilePath;
if (!treatmentMachineType.compare("FromFile"))
{
// Ask user for descriptor JSON file if load from file option is selected
descriptorFilePath = QFileDialog::getOpenFileName( this, "Select treatment machine descriptor JSON file...",
QString(), "Json files (*.json);; All files (*)" );
}
else //TODO: Currently support two default types in addition to loading file. Need to rethink the module
{
QString relativeFilePath = QString("%1/%2.json").arg(treatmentMachineType).arg(treatmentMachineType);
descriptorFilePath = QDir(d->logic()->GetModuleShareDirectory().c_str()).filePath(relativeFilePath);
}

// Load and setup models
paramNode->SetTreatmentMachineDescriptorFilePath(descriptorFilePath.toUtf8().constData());

Expand Down

0 comments on commit 6fac598

Please sign in to comment.