<commit_before>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "QmitkNavigationToolManagementWidget.h"

//mitk headers
#include "mitkTrackingTypes.h"
#include <mitkSurface.h>
#include <mitkNavigationToolReader.h>
#include <mitkNavigationToolWriter.h>
#include <mitkNavigationToolStorage.h>
#include <mitkNavigationToolStorageDeserializer.h>
#include <mitkNavigationToolStorageSerializer.h>
#include <QmitkIGTCommonHelper.h>

//qt headers
#include <qfiledialog.h>
#include <qinputdialog.h>
#include <qmessagebox.h>
#include <qsettings.h>

//poco headers
#include <Poco/Path.h>

const std::string QmitkNavigationToolManagementWidget::VIEW_ID = "org.mitk.views.navigationtoolmanagementwidget";

QmitkNavigationToolManagementWidget::QmitkNavigationToolManagementWidget(QWidget* parent, Qt::WindowFlags f)
  : QWidget(parent, f)
{
  m_Controls = NULL;
  CreateQtPartControl(this);
  CreateConnections();
}

QmitkNavigationToolManagementWidget::~QmitkNavigationToolManagementWidget()
{
}

void QmitkNavigationToolManagementWidget::CreateQtPartControl(QWidget *parent)
{
  if (!m_Controls)
  {
    // create GUI widgets
    m_Controls = new Ui::QmitkNavigationToolManagementWidgetControls;
    m_Controls->setupUi(parent);
  }

  //Disable StorageControls in the beginning, because there is no storage to edit
  DisableStorageControls();
}

void QmitkNavigationToolManagementWidget::OnLoadTool()
{
  if (m_NavigationToolStorage->isLocked())
  {
    MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first.");
    return;
  }
  mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New();
  std::string filename = QFileDialog::getOpenFileName(NULL,tr("Add Navigation Tool"), QmitkIGTCommonHelper::GetLastFileLoadPath(), "*.IGTTool").toLatin1().data();
  QmitkIGTCommonHelper::SetLastFileLoadPathByFileName(QString::fromStdString(filename));
  if (filename == "") return;
  mitk::NavigationTool::Pointer readTool = myReader->DoRead(filename);
  if (readTool.IsNull()) MessageBox("Error: " + myReader->GetErrorMessage());
  else
  {
    if (!m_NavigationToolStorage->AddTool(readTool))
    {
      MessageBox("Error: Can't add tool!");
      m_DataStorage->Remove(readTool->GetDataNode());
    }
    UpdateToolTable();
    m_NavigationToolStorage->UpdateMicroservice();
  }
}

void QmitkNavigationToolManagementWidget::OnSaveTool()
{
  //if no item is selected, show error message:
  if (m_Controls->m_ToolList->currentItem() == NULL) { MessageBox("Error: Please select tool first!"); return; }

    mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New();
    std::string filename = QFileDialog::getSaveFileName(NULL,tr("Save Navigation Tool"), QmitkIGTCommonHelper::GetLastFileSavePath(), "*.IGTTool").toLatin1().data();
    QmitkIGTCommonHelper::SetLastFileSavePathByFileName(QString::fromStdString(filename));
    filename.append(".IGTTool");
    if (filename == "") return;
    if (!myWriter->DoWrite(filename,m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row())))
      MessageBox("Error: "+ myWriter->GetErrorMessage());
}

void QmitkNavigationToolManagementWidget::CreateConnections()
{
  if (m_Controls)
  {
    //main widget page:
    connect((QObject*)(m_Controls->m_AddTool), SIGNAL(clicked()), this, SLOT(OnAddTool()));
    connect((QObject*)(m_Controls->m_DeleteTool), SIGNAL(clicked()), this, SLOT(OnDeleteTool()));
    connect((QObject*)(m_Controls->m_EditTool), SIGNAL(clicked()), this, SLOT(OnEditTool()));
    connect((QObject*)(m_Controls->m_MoveToolUp), SIGNAL(clicked()), this, SLOT(OnMoveToolUp()));<commit_msg>fixed a bug which caused doubled file extensions when saving IGT navigation tools<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include "QmitkNavigationToolManagementWidget.h"

//mitk headers
#include "mitkTrackingTypes.h"
#include <mitkSurface.h>
#include <mitkNavigationToolReader.h>
#include <mitkNavigationToolWriter.h>
#include <mitkNavigationToolStorage.h>
#include <mitkNavigationToolStorageDeserializer.h>
#include <mitkNavigationToolStorageSerializer.h>
#include <QmitkIGTCommonHelper.h>

//qt headers
#include <qfiledialog.h>
#include <qinputdialog.h>
#include <qmessagebox.h>
#include <qsettings.h>

//poco headers
#include <Poco/Path.h>

const std::string QmitkNavigationToolManagementWidget::VIEW_ID = "org.mitk.views.navigationtoolmanagementwidget";

QmitkNavigationToolManagementWidget::QmitkNavigationToolManagementWidget(QWidget* parent, Qt::WindowFlags f)
  : QWidget(parent, f)
{
  m_Controls = NULL;
  CreateQtPartControl(this);
  CreateConnections();
}

QmitkNavigationToolManagementWidget::~QmitkNavigationToolManagementWidget()
{
}

void QmitkNavigationToolManagementWidget::CreateQtPartControl(QWidget *parent)
{
  if (!m_Controls)
  {
    // create GUI widgets
    m_Controls = new Ui::QmitkNavigationToolManagementWidgetControls;
    m_Controls->setupUi(parent);
  }

  //Disable StorageControls in the beginning, because there is no storage to edit
  DisableStorageControls();
}

void QmitkNavigationToolManagementWidget::OnLoadTool()
{
  if (m_NavigationToolStorage->isLocked())
  {
    MessageBox("Storage is locked, cannot modify it. Maybe the tracking device which uses this storage is connected. If you want to modify the storage please disconnect the device first.");
    return;
  }
  mitk::NavigationToolReader::Pointer myReader = mitk::NavigationToolReader::New();
  std::string filename = QFileDialog::getOpenFileName(NULL,tr("Add Navigation Tool"), QmitkIGTCommonHelper::GetLastFileLoadPath(), "*.IGTTool").toLatin1().data();
  QmitkIGTCommonHelper::SetLastFileLoadPathByFileName(QString::fromStdString(filename));
  if (filename == "") return;
  mitk::NavigationTool::Pointer readTool = myReader->DoRead(filename);
  if (readTool.IsNull()) MessageBox("Error: " + myReader->GetErrorMessage());
  else
  {
    if (!m_NavigationToolStorage->AddTool(readTool))
    {
      MessageBox("Error: Can't add tool!");
      m_DataStorage->Remove(readTool->GetDataNode());
    }
    UpdateToolTable();
    m_NavigationToolStorage->UpdateMicroservice();
  }
}

void QmitkNavigationToolManagementWidget::OnSaveTool()
{
  //if no item is selected, show error message:
  if (m_Controls->m_ToolList->currentItem() == NULL) { MessageBox("Error: Please select tool first!"); return; }

    mitk::NavigationToolWriter::Pointer myWriter = mitk::NavigationToolWriter::New();
    std::string filename = QFileDialog::getSaveFileName(NULL,tr("Save Navigation Tool"), QmitkIGTCommonHelper::GetLastFileSavePath(), "*.IGTTool").toLatin1().data();
    QmitkIGTCommonHelper::SetLastFileSavePathByFileName(QString::fromStdString(filename));
    if (filename == "") return;
    std::string fileExt = Poco::Path(filename).getExtension();
    if (fileExt == "") { filename.append(".IGTTool"); }
    if (!myWriter->DoWrite(filename,m_NavigationToolStorage->GetTool(m_Controls->m_ToolList->currentIndex().row())))
      MessageBox("Error: "+ myWriter->GetErrorMessage());
}

void QmitkNavigationToolManagementWidget::CreateConnections()
{
  if (m_Controls)
  {
    //main widget page:
    connect((QObject*)(m_Controls->m_AddTool), SIGNAL(clicked()), this, SLOT(OnAddTool()));
    connect((QObject*)(m_Controls->m_DeleteTool), SIGNAL(clicked()), this, SLOT(OnDeleteTool()));
    connect((QObject*)(m_Controls->m_EditTool), SIGNAL(clicked()), this, SLOT(OnEditTool()));
    connect((QObject*)(m_Controls->m_MoveToolUp), SIGNAL(clicked()), this, SLOT(OnMoveToolUp()));
{'fraction_non_alphanumeric': 0.15551643192488263, 'fraction_numerical': 0.00046948356807511736, 'mean_word_length': 6.803113553113553, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3137356', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2449, 'n_words': 512}