diff --git a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp index 5e626d7836..46aa8d3cb7 100644 --- a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.cpp @@ -1,79 +1,132 @@ /*=================================================================== 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 "QmitkUSAbstractCustomWidget.h" #include #include std::string QmitkUSAbstractCustomWidget::US_DEVICE_PROPKEY_CLASS() { static std::string s = "org.mitk.services.UltrasoundCustomWidget.deviceClass"; return s; } QmitkUSAbstractCustomWidget::QmitkUSAbstractCustomWidget(QWidget* parent) : QWidget(parent), m_PrototypeServiceFactory(0), m_IsClonedForQt(false) { + } QmitkUSAbstractCustomWidget::~QmitkUSAbstractCustomWidget() { + this->UnregisterService(); delete m_PrototypeServiceFactory; } void QmitkUSAbstractCustomWidget::SetDevice(mitk::USDevice::Pointer device) { m_Device = device; if ( device ) { this->OnDeviceSet(); } } mitk::USDevice::Pointer QmitkUSAbstractCustomWidget::GetDevice() const { return m_Device; } QmitkUSAbstractCustomWidget* QmitkUSAbstractCustomWidget::CloneForQt(QWidget* parent) const { QmitkUSAbstractCustomWidget* clonedWidget = this->Clone(parent); clonedWidget->Initialize(); // initialize the Qt stuff of the widget clonedWidget->m_IsClonedForQt = true; // set flag that this object was really cloned return clonedWidget; } +//////////// µS Registration & Properties ////////////// + +us::ServiceRegistration QmitkUSAbstractCustomWidget::RegisterService(us::ModuleContext *context) +{ + if (m_PrototypeServiceFactory) + return us::ServiceRegistration(); + + if (context == nullptr) + { + context = us::GetModuleContext(); + } + + // Define a PrototypeServiceFactory for the abstract super class of all custom control widgets of USUI + // This factory is used to register the individual widgets as micro services linked to specific US devices + struct PrototypeFactory : public us::PrototypeServiceFactory + { + QmitkUSAbstractCustomWidget *const m_Prototype; + + PrototypeFactory(QmitkUSAbstractCustomWidget *prototype) : m_Prototype(prototype) {} + us::InterfaceMap GetService(us::Module * /*module*/, + const us::ServiceRegistrationBase & /*registration*/) override + { + return us::MakeInterfaceMap(m_Prototype->Clone()); + } + + void UngetService(us::Module * /*module*/, + const us::ServiceRegistrationBase & /*registration*/, + const us::InterfaceMap &service) override + { + delete us::ExtractInterface(service); + } + }; + + m_PrototypeServiceFactory = new PrototypeFactory(this); // instantiate PrototypeFactory with QmitkUSAbstractCustomWidget as prototype + us::ServiceProperties props = this->GetServiceProperties(); // retrieve the service properties (the device class linked with each custom control widget) + m_Reg = context->RegisterService(m_PrototypeServiceFactory, props); // register service + return m_Reg; +} + +void QmitkUSAbstractCustomWidget::UnregisterService() +{ + try + { + m_Reg.Unregister(); + } + catch (const std::exception &e) + { + MITK_ERROR << e.what(); + } +} + us::ServiceProperties QmitkUSAbstractCustomWidget::GetServiceProperties() const { us::ServiceProperties result; result[QmitkUSAbstractCustomWidget::US_DEVICE_PROPKEY_CLASS()] = this->GetDeviceClass(); return result; } void QmitkUSAbstractCustomWidget::showEvent ( QShowEvent * event ) { // using object from micro service directly in Qt without cloning it first // can cause problems when Qt deletes this object -> throw an exception to // show that object should be cloned before if ( ! m_IsClonedForQt ) { MITK_ERROR << "Object wasn't cloned with CloneForQt() before using as QWidget."; mitkThrow() << "Object wasn't cloned with CloneForQt() before using as QWidget."; } QWidget::showEvent(event); } diff --git a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h index 7f8eb49674..b475e0795a 100644 --- a/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSAbstractCustomWidget.h @@ -1,157 +1,165 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QmitkUSAbstractCustomWidget_h #define QmitkUSAbstractCustomWidget_h #include #include #include "mitkUSDevice.h" // Microservices #include #include #include +#include #include namespace us { struct PrototypeServiceFactory; class ModuleContext; } /** * \brief Abstract superclass for all custom control widgets of mitk::USDevice classes. * * The custom control widgets are made available using a us::PrototypeServiceFactory. This means that each * concrete subclass should be registered in the microservice by calling * QmitkUSAbstractCustomWidget::RegisterService() on an object. The best place for doing this would be in * the corresponding module or plugin activator. * * Afterwards a copy of the registered object can be obtained from the microservice as shown in the example * below. Do not forget to call QmitkUSAbstractCustomWidget::CloneForQt() on the object received from the * microservice. This is necessary to allow deleting the object as it is necessary in Qt for removing it from * a layout. * * * Subclasses must implement three methods: * - QmitkUSAbstractCustomWidget::OnDeviceSet() -> should handle initialization when mitk:USDevice was set * - QmitkUSAbstractCustomWidget::GetDeviceClass() -> must return device class of corresponding mitk::USDevice * - QmitkUSAbstractCustomWidget::Clone() -> must create a copy of the current object * * * The code to use a custom control widget in a plugin can look like this: * * \code * ctkPluginContext* pluginContext = // get the plugig context * mitk::USDevice device = // get the ultrasound device * * // get service references for ultrasound device * std::string filter = "(org.mitk.services.UltrasoundCustomWidget.deviceClass=" + device->GetDeviceClass() + ")"; * QString interfaceName ( us_service_interface_iid() ); * QList serviceRefs = pluginContext->getServiceReferences(interfaceName, QString::fromStdString(filter)); * * if (serviceRefs.size() > 0) * { * // get widget from the service and make sure that it is cloned, so that * // it can be deleted if it should be removed from the GUI later * QmitkUSAbstractCustomWidget* widget = pluginContext->getService * (serviceRefs.at(0))->CloneForQt(parentWidget); * // now the widget can be used like any other QWidget * } * \endcode */ class MITKUSUI_EXPORT QmitkUSAbstractCustomWidget : public QWidget { Q_OBJECT public: QmitkUSAbstractCustomWidget(QWidget* parent = 0); virtual ~QmitkUSAbstractCustomWidget(); void SetDevice(mitk::USDevice::Pointer device); mitk::USDevice::Pointer GetDevice() const; /** * \brief Called every time a mitk::USDevice was set with QmitkUSAbstractCustomWidget::SetDevice(). * A sublcass can implement this function to handle initialiation actions * necessary when a device was set. */ virtual void OnDeviceSet() = 0; /** * \brief Subclass must implement this method to return device class of corresponding mitk::USDevice. * * \return same value as mitk::USDevice::GetDeviceClass() of the corresponding mitk::USDevice */ virtual std::string GetDeviceClass() const = 0; /** * \brief Subclass must implement this method to return a pointer to a copy of the object. */ virtual QmitkUSAbstractCustomWidget* Clone(QWidget* parent = 0) const = 0; /** * \brief Method for initializing the Qt stuff of the widget (setupUI, connect). * This method will be called in CloneForQt() and has to be implemented by concrete * subclasses. * \warning All Qt initialization stuff belongs into this method rather than in the constructor. */ virtual void Initialize() = 0; /** * \brief Return pointer to copy of the object. * Internally use of QmitkUSAbstractCustomWidget::Clone() with additionaly * setting an internal flag that the object was really cloned. */ QmitkUSAbstractCustomWidget* CloneForQt(QWidget* parent = 0) const; + /** + * \brief Register this widget as microservice using the us::PrototypeServiceFactory. The registered microservice is linked to the US device + */ + us::ServiceRegistration RegisterService(us::ModuleContext * context = us::GetModuleContext()); + void UnregisterService(); + /** * \brief Returns the properties of the micro service. * Properties consist of just the device class of the corresponding * mitk::USDevice. */ us::ServiceProperties GetServiceProperties() const; /** * \brief Overwritten Qt even method. * It is checked if the object was cloned with * QmitkUSAbstractCustomWidget::CloneForQt() before. An exception is thrown * if not. This is done, because using the object from micro service directly * in Qt without cloning it first can cause problems after Qt deleted the * object. * * \throws mitk::Exception */ void showEvent ( QShowEvent * event ) override; /** * \brief Property key for the class name of corresponding us device object. */ static std::string US_DEVICE_PROPKEY_CLASS(); private: - mitk::USDevice::Pointer m_Device; - us::PrototypeServiceFactory* m_PrototypeServiceFactory; + mitk::USDevice::Pointer m_Device; ///< USDevice related to the specific widgets + us::PrototypeServiceFactory* m_PrototypeServiceFactory; ///< PrototypeServiceFactory used to register the individual widgets as micro services linked to specific US devices + us::ServiceRegistration m_Reg; ///< ServiceRegistration object used to update the service properties or to unregister the service bool m_IsClonedForQt; }; // This is the microservice declaration. Do not meddle! MITK_DECLARE_SERVICE_INTERFACE(QmitkUSAbstractCustomWidget, "org.mitk.QmitkUSAbstractCustomWidget") #endif // QmitkUSAbstractCustomWidget_h diff --git a/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.cpp b/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.cpp index 4a8cd6ef85..835ef23fa6 100644 --- a/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.cpp @@ -1,421 +1,420 @@ /*=================================================================== 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 "QmitkUSControlsCustomDiPhASDeviceWidget.h" #include "ui_QmitkUSControlsCustomDiPhASDeviceWidget.h" #include #include +QmitkUSControlsCustomDiPhASDeviceWidget::QmitkUSControlsCustomDiPhASDeviceWidget() + : ui(new Ui::QmitkUSControlsCustomDiPhASDeviceWidget) +{ + this->RegisterService(); +} + QmitkUSControlsCustomDiPhASDeviceWidget::QmitkUSControlsCustomDiPhASDeviceWidget(QWidget *parent) : QmitkUSAbstractCustomWidget(parent), ui(new Ui::QmitkUSControlsCustomDiPhASDeviceWidget) { } QmitkUSControlsCustomDiPhASDeviceWidget::~QmitkUSControlsCustomDiPhASDeviceWidget() { - m_ControlInterface = dynamic_cast - (this->GetDevice()->GetControlInterfaceCustom().GetPointer()); - - if (m_ControlInterface.IsNotNull()) - { - m_ControlInterface->passGUIOut([](QString /*str*/)->void {} ); - } delete ui; } std::string QmitkUSControlsCustomDiPhASDeviceWidget::GetDeviceClass() const { return "org.mitk.modules.us.USDiPhASDevice"; } QmitkUSAbstractCustomWidget* QmitkUSControlsCustomDiPhASDeviceWidget::Clone(QWidget* parent) const { QmitkUSAbstractCustomWidget* clonedWidget = new QmitkUSControlsCustomDiPhASDeviceWidget(parent); clonedWidget->SetDevice(this->GetDevice()); return clonedWidget; } void QmitkUSControlsCustomDiPhASDeviceWidget::OnDeviceSet() { m_ControlInterface = dynamic_cast (this->GetDevice()->GetControlInterfaceCustom().GetPointer()); if ( m_ControlInterface.IsNotNull() ) { m_ControlInterface->passGUIOut([this](QString str)->void{ if (this && this->ui) { this->ui->CurrentState->setText(str); } }); } else { MITK_WARN("QmitkUSAbstractCustomWidget")("QmitkUSControlsCustomDiPhASDeviceWidget") << "Did not get a custom device control interface."; } //now pass the default values m_OldReconstructionLines = 0; m_ControlInterface->SetSilentUpdate(true); // don't update the scanmode everytime OnTransmitPhaseLengthChanged(); OnExcitationFrequencyChanged(); OnTransmitEventsChanged(); OnVoltageChanged(); OnScanDepthChanged(); // HERE OnAveragingCountChanged(); OnTGCMinChanged(); OnTGCMaxChanged(); OnDataTypeChanged(); OnPitchChanged(); OnReconstructedSamplesChanged(); OnReconstructedLinesChanged(); OnSpeedOfSoundChanged(); OnBandpassEnabledChanged(); OnLowCutChanged(); OnHighCutChanged(); OnUseBModeFilterChanged(); // HERE OnVerticalSpacingChanged(); OnScatteringCoefficientChanged(); OnCompensateScatteringChanged(); OnChangedSavingSettings(); OnCompensateEnergyChanged(); m_ControlInterface->SetSilentUpdate(false); // on the last update pass the scanmode and geometry! OnModeChanged(); // HERE } void QmitkUSControlsCustomDiPhASDeviceWidget::Initialize() { ui->setupUi(this); connect(ui->CompensateEnergy, SIGNAL(stateChanged(int)), this, SLOT(OnCompensateEnergyChanged())); connect(ui->UseBModeFilter, SIGNAL(stateChanged(int)), this, SLOT(OnUseBModeFilterChanged())); connect(ui->StartStopRecord, SIGNAL(clicked()), this, SLOT(OnRecordChanged())); connect(ui->ScatteringCoefficient, SIGNAL(valueChanged(int)), this, SLOT(OnScatteringCoefficientChanged())); connect(ui->CompensateScattering, SIGNAL(stateChanged(int)), this, SLOT(OnCompensateScatteringChanged())); connect(ui->VerticalSpacing, SIGNAL(valueChanged(double)), this, SLOT(OnVerticalSpacingChanged())); connect(ui->SaveBeamformed, SIGNAL(stateChanged(int)), this, SLOT(OnChangedSavingSettings())); connect(ui->SaveRaw, SIGNAL(stateChanged(int)), this, SLOT(OnChangedSavingSettings())); //transmit connect(ui->TransmitPhaseLength, SIGNAL(valueChanged(double)), this, SLOT(OnTransmitPhaseLengthChanged())); connect(ui->ExcitationFrequency, SIGNAL(valueChanged(double)), this, SLOT(OnExcitationFrequencyChanged())); connect(ui->TransmitEvents, SIGNAL(valueChanged(int)), this, SLOT(OnTransmitEventsChanged())); connect(ui->Voltage, SIGNAL(valueChanged(int)), this, SLOT(OnVoltageChanged())); connect(ui->Mode, SIGNAL(currentTextChanged(QString)), this, SLOT(OnModeChanged())); //Receive connect(ui->ScanDepth, SIGNAL(valueChanged(double)), this, SLOT(OnScanDepthChanged())); connect(ui->AveragingCount, SIGNAL(valueChanged(int)), this, SLOT(OnAveragingCountChanged())); connect(ui->TimeGainCompensationMinSlider, SIGNAL(valueChanged(int)), this, SLOT(OnTGCMinChanged())); connect(ui->TimeGainCompensationMaxSlider, SIGNAL(valueChanged(int)), this, SLOT(OnTGCMaxChanged())); connect(ui->DataType, SIGNAL(currentTextChanged(QString)), this, SLOT(OnDataTypeChanged())); //Beamforming connect(ui->PitchOfTransducer, SIGNAL(valueChanged(double)), this, SLOT(OnPitchChanged())); connect(ui->ReconstructedSamplesPerLine, SIGNAL(valueChanged(int)), this, SLOT(OnReconstructedSamplesChanged())); connect(ui->ReconstructedLines, SIGNAL(valueChanged(int)), this, SLOT(OnReconstructedLinesChanged())); connect(ui->SpeedOfSound, SIGNAL(valueChanged(int)), this, SLOT(OnSpeedOfSoundChanged())); //Bandpass connect(ui->BandpassEnabled, SIGNAL(currentTextChanged(QString)), this, SLOT(OnBandpassEnabledChanged())); connect(ui->LowCut, SIGNAL(valueChanged(double)), this, SLOT(OnLowCutChanged())); connect(ui->HighCut, SIGNAL(valueChanged(double)), this, SLOT(OnHighCutChanged())); } //slots void QmitkUSControlsCustomDiPhASDeviceWidget::OnCompensateEnergyChanged() { if (m_ControlInterface.IsNull()) { return; } bool CompensateEnergy = ui->CompensateEnergy->isChecked(); m_ControlInterface->SetCompensateEnergy(CompensateEnergy); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnUseBModeFilterChanged() { if (m_ControlInterface.IsNull()) { return; } bool UseBModeFilter = ui->UseBModeFilter->isChecked(); m_ControlInterface->SetUseBModeFilter(UseBModeFilter); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnRecordChanged() { if (m_ControlInterface.IsNull()) { return; } if (ui->StartStopRecord->text() == "Start Recording") { ui->StartStopRecord->setText("Stop Recording"); ui->UseBModeFilter->setEnabled(false); ui->ScatteringCoefficient->setEnabled(false); ui->CompensateScattering->setEnabled(false); ui->VerticalSpacing->setEnabled(false); ui->SaveBeamformed->setEnabled(false); ui->SaveRaw->setEnabled(false); ui->TransmitPhaseLength->setEnabled(false); ui->ExcitationFrequency->setEnabled(false); ui->TransmitEvents->setEnabled(false); ui->Voltage->setEnabled(false); ui->Mode->setEnabled(false); ui->ScanDepth->setEnabled(false); ui->AveragingCount->setEnabled(false); ui->TimeGainCompensationMinSlider->setEnabled(false); ui->TimeGainCompensationMaxSlider->setEnabled(false); ui->DataType->setEnabled(false); ui->PitchOfTransducer->setEnabled(false); ui->ReconstructedSamplesPerLine->setEnabled(false); ui->ReconstructedLines->setEnabled(false); ui->SpeedOfSound->setEnabled(false); ui->BandpassEnabled->setEnabled(false); ui->LowCut->setEnabled(false); ui->HighCut->setEnabled(false); ui->CompensateEnergy->setEnabled(false); m_ControlInterface->SetRecord(true); } else { ui->StartStopRecord->setText("Start Recording"); ui->UseBModeFilter->setEnabled(true); ui->CompensateScattering->setEnabled(true); if(ui->CompensateScattering->isChecked()) ui->ScatteringCoefficient->setEnabled(true); ui->VerticalSpacing->setEnabled(true); ui->SaveBeamformed->setEnabled(true); ui->SaveRaw->setEnabled(true); ui->TransmitPhaseLength->setEnabled(true); ui->ExcitationFrequency->setEnabled(true); ui->TransmitEvents->setEnabled(true); ui->Voltage->setEnabled(true); ui->Mode->setEnabled(true); ui->ScanDepth->setEnabled(true); ui->AveragingCount->setEnabled(true); ui->TimeGainCompensationMinSlider->setEnabled(true); ui->TimeGainCompensationMaxSlider->setEnabled(true); ui->DataType->setEnabled(true); ui->PitchOfTransducer->setEnabled(true); ui->ReconstructedSamplesPerLine->setEnabled(true); ui->ReconstructedLines->setEnabled(true); ui->SpeedOfSound->setEnabled(true); ui->BandpassEnabled->setEnabled(true); ui->LowCut->setEnabled(true); ui->HighCut->setEnabled(true); ui->CompensateEnergy->setEnabled(true); m_ControlInterface->SetRecord(false); } } void QmitkUSControlsCustomDiPhASDeviceWidget::OnVerticalSpacingChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetVerticalSpacing(ui->VerticalSpacing->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnScatteringCoefficientChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetScatteringCoefficient(ui->ScatteringCoefficient->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnCompensateScatteringChanged() { if (m_ControlInterface.IsNull()) { return; } if (ui->CompensateScattering->isChecked()) ui->ScatteringCoefficient->setEnabled(true); else ui->ScatteringCoefficient->setEnabled(false); m_ControlInterface->SetCompensateScattering(ui->CompensateScattering->isChecked()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnChangedSavingSettings() { if (m_ControlInterface.IsNull()) { return; } mitk::USDiPhASDeviceCustomControls::SavingSettings settings; settings.saveBeamformed = ui->SaveBeamformed->isChecked(); settings.saveRaw = ui->SaveRaw->isChecked(); m_ControlInterface->SetSavingSettings(settings); } //Transmit void QmitkUSControlsCustomDiPhASDeviceWidget::OnTransmitPhaseLengthChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetTransmitPhaseLength(ui->TransmitPhaseLength->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnExcitationFrequencyChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetExcitationFrequency(ui->ExcitationFrequency->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnTransmitEventsChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetTransmitEvents(ui->TransmitEvents->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnVoltageChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetVoltage(ui->Voltage->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnModeChanged() { if (m_ControlInterface.IsNull()) { return; } QString Mode = ui->Mode->currentText(); bool silent = m_ControlInterface->GetSilentUpdate(); m_ControlInterface->SetSilentUpdate(true); if (Mode == "Ultrasound only") { m_ControlInterface->SetMode(false); ui->TransmitEvents->setValue(1); } else if (Mode == "Interleaved") { m_ControlInterface->SetMode(true); ui->TransmitEvents->setValue(1); } if (!silent) { m_ControlInterface->SetSilentUpdate(false); } OnTransmitEventsChanged(); } //Receive void QmitkUSControlsCustomDiPhASDeviceWidget::OnScanDepthChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetScanDepth(ui->ScanDepth->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnAveragingCountChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetAveragingCount(ui->AveragingCount->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnTGCMinChanged() { if (m_ControlInterface.IsNull()) { return; } int tgcMin = ui->TimeGainCompensationMinSlider->value(); int tgcMax = ui->TimeGainCompensationMaxSlider->value(); if (tgcMin > tgcMax) { ui->TimeGainCompensationMinSlider->setValue(tgcMax); MITK_INFO << "User tried to set tgcMin>tgcMax."; } QString text("TGC min = " + QString::fromStdString(std::to_string(ui->TimeGainCompensationMinSlider->value()))); ui->TimeGainCompensationMinLabel->setText(text); m_ControlInterface->SetTGCMin(ui->TimeGainCompensationMinSlider->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnTGCMaxChanged() { if (m_ControlInterface.IsNull()) { return; } int tgcMin = ui->TimeGainCompensationMinSlider->value(); int tgcMax = ui->TimeGainCompensationMaxSlider->value(); if (tgcMin > tgcMax) { ui->TimeGainCompensationMaxSlider->setValue(tgcMin); MITK_INFO << "User tried to set tgcMin>tgcMax."; } QString text("TGC max = "+QString::fromStdString(std::to_string(ui->TimeGainCompensationMaxSlider->value()))); ui->TimeGainCompensationMaxLabel->setText(text); m_ControlInterface->SetTGCMax(ui->TimeGainCompensationMaxSlider->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnDataTypeChanged() { if (m_ControlInterface.IsNull()) { return; } QString DataType = ui->DataType->currentText(); if (DataType == "Image Data") { m_ControlInterface->SetDataType(mitk::USDiPhASDeviceCustomControls::DataType::Image_uChar); } else if (DataType == "Beamformed Data") { m_ControlInterface->SetDataType(mitk::USDiPhASDeviceCustomControls::DataType::Beamformed_Short); } } //Beamforming void QmitkUSControlsCustomDiPhASDeviceWidget::OnPitchChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetPitch(ui->PitchOfTransducer->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnReconstructedSamplesChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetReconstructedSamples(ui->ReconstructedSamplesPerLine->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnReconstructedLinesChanged() { if (m_ControlInterface.IsNull()) { return; } if (m_OldReconstructionLines == 0) m_OldReconstructionLines = ui->ReconstructedLines->value(); m_ControlInterface->SetReconstructedLines(ui->ReconstructedLines->value()); ui->PitchOfTransducer->setValue(ui->PitchOfTransducer->value()*((double)m_OldReconstructionLines / (double)ui->ReconstructedLines->value())); m_OldReconstructionLines = ui->ReconstructedLines->value(); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnSpeedOfSoundChanged() { if (m_ControlInterface.IsNull()) { return; } m_ControlInterface->SetSpeedOfSound(ui->SpeedOfSound->value()); } //Bandpass void QmitkUSControlsCustomDiPhASDeviceWidget::OnBandpassEnabledChanged() { if (m_ControlInterface.IsNull()) { return; } if (ui->BandpassEnabled->currentText() == "On") { m_ControlInterface->SetBandpassEnabled(true); } else { m_ControlInterface->SetBandpassEnabled(false); } } void QmitkUSControlsCustomDiPhASDeviceWidget::OnLowCutChanged() { if (m_ControlInterface.IsNull()) { return; } unsigned int Low = ui->LowCut->value(); unsigned int High = ui->HighCut->value(); if (Low > High) { ui->LowCut->setValue(High); MITK_INFO << "User tried to set LowCut>HighCut."; } m_ControlInterface->SetLowCut(ui->LowCut->value()); } void QmitkUSControlsCustomDiPhASDeviceWidget::OnHighCutChanged() { if (m_ControlInterface.IsNull()) { return; } unsigned int Low = ui->LowCut->value(); unsigned int High = ui->HighCut->value(); if (Low > High) { ui->HighCut->setValue(Low); MITK_INFO << "User tried to set LowCut>HighCut."; } m_ControlInterface->SetHighCut(ui->HighCut->value()); } diff --git a/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.h b/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.h index d80fe50018..a19dbcec15 100644 --- a/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.h @@ -1,116 +1,117 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QmitkUSControlsCustomDiPhASDeviceWidget_H #define QmitkUSControlsCustomDiPhASDeviceWidget_H #include "QmitkUSAbstractCustomWidget.h" #include "mitkUSDiPhASDeviceCustomControls.h" #include "mitkUSDevice.h" #include namespace Ui { class QmitkUSControlsCustomDiPhASDeviceWidget; } /** \brief Widget for custom controls of mitk::USDiPhASDevice. * This class handles the itk::USDiPhASDeviceCustomControls of video device * objects. */ class QmitkUSControlsCustomDiPhASDeviceWidget : public QmitkUSAbstractCustomWidget { Q_OBJECT private slots: virtual void OnCompensateEnergyChanged(); virtual void OnUseBModeFilterChanged(); virtual void OnVerticalSpacingChanged(); virtual void OnRecordChanged(); virtual void OnScatteringCoefficientChanged(); virtual void OnCompensateScatteringChanged(); virtual void OnChangedSavingSettings(); //Transmit virtual void OnTransmitPhaseLengthChanged(); virtual void OnExcitationFrequencyChanged(); virtual void OnTransmitEventsChanged(); virtual void OnVoltageChanged(); virtual void OnModeChanged(); //Receive virtual void OnScanDepthChanged(); virtual void OnAveragingCountChanged(); virtual void OnTGCMinChanged(); virtual void OnTGCMaxChanged(); virtual void OnDataTypeChanged(); //Beamforming virtual void OnPitchChanged(); virtual void OnReconstructedSamplesChanged(); virtual void OnReconstructedLinesChanged(); virtual void OnSpeedOfSoundChanged(); //Bandpass virtual void OnBandpassEnabledChanged(); virtual void OnLowCutChanged(); virtual void OnHighCutChanged(); public: /** * Constructs widget object. All gui control elements will be disabled until * QmitkUSAbstractCustomWidget::SetDevice() was called. */ - explicit QmitkUSControlsCustomDiPhASDeviceWidget(QWidget *parent = 0); + QmitkUSControlsCustomDiPhASDeviceWidget(); ~QmitkUSControlsCustomDiPhASDeviceWidget(); /** * Getter for the device class of mitk:USDiPhASDevice. */ virtual std::string GetDeviceClass() const override; /** * Creates new QmitkUSAbstractCustomWidget with the same mitk::USDiPhASDevice * and the same mitk::USDiPhASDeviceCustomControls which were set on the * original object. * * This method is just for being calles by the factory. Use * QmitkUSAbstractCustomWidget::CloneForQt() instead, if you want a clone of * an object. */ virtual QmitkUSAbstractCustomWidget* Clone(QWidget* parent = 0) const override; /** * Gets control interface from the device which was currently set. Control * elements are according to current crop area of the device. If custom * control interface is null, the control elements stay disabled. */ virtual void OnDeviceSet() override; virtual void Initialize() override; protected: void BlockSignalAndSetValue(QSpinBox* target, int value); private: + QmitkUSControlsCustomDiPhASDeviceWidget(QWidget *parent); Ui::QmitkUSControlsCustomDiPhASDeviceWidget* ui; mitk::USDiPhASDeviceCustomControls::Pointer m_ControlInterface; int m_OldReconstructionLines; }; #endif // QmitkUSControlsCustomDiPhASDeviceWidget_H \ No newline at end of file diff --git a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp index 3295f188a4..bda64d6031 100644 --- a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp @@ -1,158 +1,166 @@ /*=================================================================== 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 "QmitkUSControlsCustomVideoDeviceWidget.h" #include "ui_QmitkUSControlsCustomVideoDeviceWidget.h" #include #include + +QmitkUSControlsCustomVideoDeviceWidget::QmitkUSControlsCustomVideoDeviceWidget() + : ui(new Ui::QmitkUSControlsCustomVideoDeviceWidget) +{ + this->RegisterService(); +} + + QmitkUSControlsCustomVideoDeviceWidget::QmitkUSControlsCustomVideoDeviceWidget(QWidget *parent) : QmitkUSAbstractCustomWidget(parent), ui(new Ui::QmitkUSControlsCustomVideoDeviceWidget) { m_Cropping.left = 0; m_Cropping.top = 0; m_Cropping.right = 0; m_Cropping.bottom = 0; } QmitkUSControlsCustomVideoDeviceWidget::~QmitkUSControlsCustomVideoDeviceWidget() { delete ui; } std::string QmitkUSControlsCustomVideoDeviceWidget::GetDeviceClass() const { return mitk::USVideoDevice::GetDeviceClassStatic(); } QmitkUSAbstractCustomWidget* QmitkUSControlsCustomVideoDeviceWidget::Clone(QWidget* parent) const { QmitkUSAbstractCustomWidget* clonedWidget = new QmitkUSControlsCustomVideoDeviceWidget(parent); clonedWidget->SetDevice(this->GetDevice()); return clonedWidget; } void QmitkUSControlsCustomVideoDeviceWidget::OnDeviceSet() { m_ControlInterface = dynamic_cast (this->GetDevice()->GetControlInterfaceCustom().GetPointer()); if (m_ControlInterface.IsNotNull()) { mitk::USImageVideoSource::USImageCropping cropping = m_ControlInterface->GetCropArea(); ui->crop_left->setValue(cropping.left); ui->crop_right->setValue(cropping.right); ui->crop_bot->setValue(cropping.bottom); ui->crop_top->setValue(cropping.top); //get all probes and put their names into a combobox std::vector probes = m_ControlInterface->GetProbes(); for (std::vector::iterator it = probes.begin(); it != probes.end(); it++) { std::string probeName = (*it)->GetName(); ui->m_ProbeIdentifier->addItem(QString::fromUtf8(probeName.data(), probeName.size())); } connect(ui->m_UsDepth, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnDepthChanged())); connect(ui->m_ProbeIdentifier, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnProbeChanged())); } else { MITK_WARN("QmitkUSAbstractCustomWidget")("QmitkUSControlsCustomVideoDeviceWidget") << "Did not get a custom video device control interface."; } ui->crop_left->setEnabled(m_ControlInterface.IsNotNull()); ui->crop_right->setEnabled(m_ControlInterface.IsNotNull()); ui->crop_bot->setEnabled(m_ControlInterface.IsNotNull()); ui->crop_top->setEnabled(m_ControlInterface.IsNotNull()); } void QmitkUSControlsCustomVideoDeviceWidget::Initialize() { ui->setupUi(this); connect(ui->crop_left, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged())); connect(ui->crop_right, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged())); connect(ui->crop_top, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged())); connect(ui->crop_bot, SIGNAL(valueChanged(int)), this, SLOT(OnCropAreaChanged())); } void QmitkUSControlsCustomVideoDeviceWidget::OnCropAreaChanged() { if (m_ControlInterface.IsNull()) { return; } mitk::USImageVideoSource::USImageCropping cropping; cropping.left = ui->crop_left->value(); cropping.top = ui->crop_top->value(); cropping.right = ui->crop_right->value(); cropping.bottom = ui->crop_bot->value(); try { m_ControlInterface->SetCropArea(cropping); m_Cropping = cropping; } catch (mitk::Exception e) { m_ControlInterface->SetCropArea(m_Cropping); // reset to last valid crop //reset values BlockSignalAndSetValue(ui->crop_left, m_Cropping.left); BlockSignalAndSetValue(ui->crop_right, m_Cropping.right); BlockSignalAndSetValue(ui->crop_top, m_Cropping.top); BlockSignalAndSetValue(ui->crop_bot, m_Cropping.bottom); // inform user QMessageBox msgBox; msgBox.setInformativeText("The crop area you specified is invalid.\nPlease make sure that no more pixels are cropped than are available."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); MITK_WARN << "User tried to crop beyond limits of the image"; } } void QmitkUSControlsCustomVideoDeviceWidget::OnDepthChanged() { double depth = ui->m_UsDepth->currentText().toDouble(); m_ControlInterface->SetNewDepth(depth); } void QmitkUSControlsCustomVideoDeviceWidget::OnProbeChanged() { std::string probename = ui->m_ProbeIdentifier->currentText().toStdString(); m_ControlInterface->SetNewProbeIdentifier(probename); SetDepthsForProbe(probename); } void QmitkUSControlsCustomVideoDeviceWidget::BlockSignalAndSetValue(QSpinBox* target, int value) { bool oldState = target->blockSignals(true); target->setValue(value); target->blockSignals(oldState); } void QmitkUSControlsCustomVideoDeviceWidget::SetDepthsForProbe(std::string probename) { ui->m_UsDepth->clear(); std::vector depths = m_ControlInterface->GetDepthsForProbe(probename); for (std::vector::iterator it = depths.begin(); it != depths.end(); it++) { ui->m_UsDepth->addItem(QString::number(*it)); } } diff --git a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h index fb7761380c..8f20dc5c40 100644 --- a/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h @@ -1,103 +1,105 @@ /*=================================================================== 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. ===================================================================*/ #ifndef QmitkUSControlsCustomVideoDeviceWidget_H #define QmitkUSControlsCustomVideoDeviceWidget_H #include "QmitkUSAbstractCustomWidget.h" #include "mitkUSVideoDeviceCustomControls.h" #include "mitkUSVideoDevice.h" #include namespace Ui { class QmitkUSControlsCustomVideoDeviceWidget; } /** \brief Widget for custom controls of mitk::USVideoDevice. * This class handles the itk::USVideoDeviceCustomControls of video device * objects. */ class QmitkUSControlsCustomVideoDeviceWidget : public QmitkUSAbstractCustomWidget { Q_OBJECT private slots: /** * \brief Called when user changes one of the crop area control elements. */ void OnCropAreaChanged(); /** * \brief Called when user changes the scanning depth of the ultrasound */ void OnDepthChanged(); /** * \brief Called when user chagnes the identifier for the probe of the ultrasoud machine */ void OnProbeChanged(); /** * \brief Get all depths for the given probe and fill them into a combobox */ void SetDepthsForProbe(std::string probename); public: - /** - * Constructs widget object. All gui control elements will be disabled until - * QmitkUSAbstractCustomWidget::SetDevice() was called. - */ - explicit QmitkUSControlsCustomVideoDeviceWidget(QWidget *parent = 0); + + QmitkUSControlsCustomVideoDeviceWidget(); ~QmitkUSControlsCustomVideoDeviceWidget(); /** * Getter for the device class of mitk:USVideoDevice. */ virtual std::string GetDeviceClass() const override; /** * Creates new QmitkUSAbstractCustomWidget with the same mitk::USVideoDevice * and the same mitk::USVideoDeviceCustomControls which were set on the * original object. * * This method is just for being calles by the factory. Use * QmitkUSAbstractCustomWidget::CloneForQt() instead, if you want a clone of * an object. */ virtual QmitkUSAbstractCustomWidget* Clone(QWidget* parent = 0) const override; /** * Gets control interface from the device which was currently set. Control * elements are according to current crop area of the device. If custom * control interface is null, the control elements stay disabled. */ virtual void OnDeviceSet() override; virtual void Initialize() override; protected: void BlockSignalAndSetValue(QSpinBox* target, int value); mitk::USImageVideoSource::USImageCropping m_Cropping; private: + /** + * Constructs widget object. All gui control elements will be disabled until + * QmitkUSAbstractCustomWidget::SetDevice() was called. + */ + QmitkUSControlsCustomVideoDeviceWidget(QWidget *parent); Ui::QmitkUSControlsCustomVideoDeviceWidget* ui; mitk::USVideoDeviceCustomControls::Pointer m_ControlInterface; }; #endif // QmitkUSControlsCustomVideoDeviceWidget_H \ No newline at end of file diff --git a/Modules/USUI/files.cmake b/Modules/USUI/files.cmake index 037da83963..828924aadc 100644 --- a/Modules/USUI/files.cmake +++ b/Modules/USUI/files.cmake @@ -1,38 +1,37 @@ set(CPP_FILES mitkUSUIActivator.cpp - mitkUSUICustomWidgetFactory.cpp Qmitk/QmitkUSDeviceManagerWidget.cpp Qmitk/QmitkUSNewVideoDeviceWidget.cpp Qmitk/QmitkUSControlsBModeWidget.cpp Qmitk/QmitkUSControlsDopplerWidget.cpp Qmitk/QmitkUSControlsProbesWidget.cpp Qmitk/QmitkUSControlsCustomVideoDeviceWidget.cpp Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.cpp Qmitk/QmitkUSAbstractCustomWidget.cpp Qmitk/QmitkComboBoxStepThrough.cpp ) set(UI_FILES Qmitk/QmitkUSDeviceManagerWidgetControls.ui Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui Qmitk/QmitkUSControlsBModeWidget.ui Qmitk/QmitkUSControlsDopplerWidget.ui Qmitk/QmitkUSControlsProbesWidget.ui Qmitk/QmitkUSControlsCustomVideoDeviceWidget.ui Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.ui ) set(MOC_H_FILES Qmitk/QmitkUSDeviceManagerWidget.h Qmitk/QmitkUSNewVideoDeviceWidget.h Qmitk/QmitkUSControlsBModeWidget.h Qmitk/QmitkUSControlsDopplerWidget.h Qmitk/QmitkUSControlsProbesWidget.h Qmitk/QmitkUSControlsCustomVideoDeviceWidget.h Qmitk/QmitkUSControlsCustomDiPhASDeviceWidget.h Qmitk/QmitkUSAbstractCustomWidget.h Qmitk/QmitkComboBoxStepThrough.h ) set(QRC_FILES resources/USUI.qrc ) diff --git a/Modules/USUI/mitkUSUIActivator.cpp b/Modules/USUI/mitkUSUIActivator.cpp index 23317bf34d..06d9d4fd9b 100644 --- a/Modules/USUI/mitkUSUIActivator.cpp +++ b/Modules/USUI/mitkUSUIActivator.cpp @@ -1,79 +1,41 @@ /*=================================================================== 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 "mitkUSUIActivator.h" -#include "mitkUSUICustomWidgetFactory.h" #include "QmitkUSControlsCustomVideoDeviceWidget.h" #include "QmitkUSControlsCustomDiPhASDeviceWidget.h" mitk::USUIActivator::USUIActivator() - : m_CustomWidgetFactory(0), m_CustomVideoDeviceWidget(0), m_CustomDiPhASDeviceWidget(0) { } mitk::USUIActivator::~USUIActivator() { - for(auto i : m_CustomWidgetFactory) - delete i; - delete m_CustomVideoDeviceWidget; - - if ( m_ServiceRegistration ) { m_ServiceRegistration.Unregister(); } } void mitk::USUIActivator::Load(us::ModuleContext* context) { - // create a custom video device widget, which will be used as - // a prototype for the custom widget factory - - if (!m_CustomVideoDeviceWidget) - { - m_CustomVideoDeviceWidget = new QmitkUSControlsCustomVideoDeviceWidget(); - } - - // create a custom DiPhAS device widget, which will be used as - // a prototype for the custom widget factory - - if (!m_CustomDiPhASDeviceWidget) - { - m_CustomDiPhASDeviceWidget = new QmitkUSControlsCustomDiPhASDeviceWidget(); - } - - // create a factory for custom widgets, using the video device - // widget as a prototype - m_CustomWidgetFactory.push_back(new mitk::USUICustomWidgetFactory(m_CustomVideoDeviceWidget)); - - // create a factory for custom widgets, using the DiPhAS device - // widget as a prototype - m_CustomWidgetFactory.push_back(new mitk::USUICustomWidgetFactory(m_CustomDiPhASDeviceWidget)); - - // register the custom widget factories as a microservice - for (auto i : m_CustomWidgetFactory) - m_ServiceRegistration = i->RegisterService(context); + m_USCustomWidgets.push_back(new QmitkUSControlsCustomVideoDeviceWidget()); + m_USCustomWidgets.push_back(new QmitkUSControlsCustomDiPhASDeviceWidget()); } void mitk::USUIActivator::Unload(us::ModuleContext* /*context*/) { - m_ServiceRegistration.Unregister(); - m_ServiceRegistration = 0; - - for (auto i : m_CustomWidgetFactory) - delete i; - - m_CustomWidgetFactory.clear(); - - delete m_CustomVideoDeviceWidget; - m_CustomVideoDeviceWidget = 0; + for (auto &elem : m_USCustomWidgets) + { + delete elem; + } } diff --git a/Modules/USUI/mitkUSUIActivator.h b/Modules/USUI/mitkUSUIActivator.h index d99d46b974..acb2046638 100644 --- a/Modules/USUI/mitkUSUIActivator.h +++ b/Modules/USUI/mitkUSUIActivator.h @@ -1,67 +1,61 @@ /*=================================================================== 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. ===================================================================*/ #ifndef __mitkUSUIActivator_h #define __mitkUSUIActivator_h #include "QmitkUSAbstractCustomWidget.h" // Microservices #include #include -class QmitkUSControlsCustomVideoDeviceWidget; -class QmitkUSControlsCustomDiPhASDeviceWidget; - namespace mitk { class USUICustomWidgetFactory; /** * \brief Module activator for the USUI module. * Registers custom widget for mitk::USVideoDevice as microservice. */ class USUIActivator : public us::ModuleActivator { public: USUIActivator(); virtual ~USUIActivator(); /** * Custom video device widget is registered as a micro service on module * load. A plugin can get this widget then when using a * mitk::USVideoDevice. */ void Load(us::ModuleContext* context) override; /** * Custom video device widget is deregistered from micro service on module * unload. */ void Unload(us::ModuleContext* context) override; protected: - us::ServiceRegistration m_ServiceRegistration; - std::vector m_CustomWidgetFactory; - QmitkUSControlsCustomVideoDeviceWidget* m_CustomVideoDeviceWidget; - QmitkUSControlsCustomDiPhASDeviceWidget* m_CustomDiPhASDeviceWidget; + std::vector m_USCustomWidgets; ///< Contains the currently available US custom controls widgets which are loaded on Load() }; } // namespace mitk US_EXPORT_MODULE_ACTIVATOR(mitk::USUIActivator) #endif // __mitkUSUIActivator_h diff --git a/Modules/USUI/mitkUSUICustomWidgetFactory.cpp b/Modules/USUI/mitkUSUICustomWidgetFactory.cpp deleted file mode 100644 index 4067fac200..0000000000 --- a/Modules/USUI/mitkUSUICustomWidgetFactory.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*=================================================================== - -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 "mitkUSUICustomWidgetFactory.h" - -#include "QmitkUSAbstractCustomWidget.h" - -#include - -mitk::USUICustomWidgetFactory::USUICustomWidgetFactory(QmitkUSAbstractCustomWidget* prototype) - : m_Prototype(prototype) -{ -} - -us::ServiceRegistration mitk::USUICustomWidgetFactory::RegisterService(us::ModuleContext* context) -{ - return context->RegisterService(m_Prototype, m_Prototype->GetServiceProperties()); -} - -us::InterfaceMap mitk::USUICustomWidgetFactory::GetService(us::Module* /*module*/, const us::ServiceRegistrationBase& /*registration*/) -{ - // clone the prototype for returning a uniqe instance - return us::MakeInterfaceMap(m_Prototype->Clone()); -} - -void mitk::USUICustomWidgetFactory::UngetService(us::Module*, const us::ServiceRegistrationBase&, const us::InterfaceMap& service) -{ - // just delete the given service - delete us::ExtractInterface(service); -} diff --git a/Modules/USUI/mitkUSUICustomWidgetFactory.h b/Modules/USUI/mitkUSUICustomWidgetFactory.h deleted file mode 100644 index a2617e4593..0000000000 --- a/Modules/USUI/mitkUSUICustomWidgetFactory.h +++ /dev/null @@ -1,49 +0,0 @@ -/*=================================================================== - -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. - -===================================================================*/ - -#ifndef MITKUSUICUSTOMWIDGETFACTORY_H -#define MITKUSUICUSTOMWIDGETFACTORY_H - -#include - -class QmitkUSAbstractCustomWidget; - -namespace us { -class ModuleContext; -} - -namespace mitk { -/** - * \brief Prototype service factory for creating unique instances of QmitUSAbstractCustomWidget. - */ -class USUICustomWidgetFactory : public us::PrototypeServiceFactory { -public: - USUICustomWidgetFactory(QmitkUSAbstractCustomWidget* prototype); - - /** - * \brief Registers this factory in the given module context. - */ - us::ServiceRegistration RegisterService(us::ModuleContext* context); - - us::InterfaceMap GetService(us::Module* /*module*/, const us::ServiceRegistrationBase& /*registration*/) override; - void UngetService(us::Module*, const us::ServiceRegistrationBase&, const us::InterfaceMap& service) override; - -private: - QmitkUSAbstractCustomWidget* const m_Prototype; -}; -} // namespace mitk - -#endif // MITKUSUICUSTOMWIDGETFACTORY_H