diff --git a/Modules/Qmitk/QmitkServiceListWidget.h b/Modules/Qmitk/QmitkServiceListWidget.h index a9b9db5a13..831abfdcef 100644 --- a/Modules/Qmitk/QmitkServiceListWidget.h +++ b/Modules/Qmitk/QmitkServiceListWidget.h @@ -1,239 +1,239 @@ /*=================================================================== 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 _QmitkServiceListWidget_H_INCLUDED #define _QmitkServiceListWidget_H_INCLUDED #include "QmitkExports.h" #include "ui_QmitkServiceListWidgetControls.h" #include //QT headers #include #include //Microservices #include "usServiceReference.h" #include "usModuleContext.h" #include "usServiceEvent.h" #include "usServiceInterface.h" /** * @brief This widget provides abstraction for the handling of MicroServices . Place one in your Plugin and set it to look for a certain interface. * One can also specify a filter and / or a property to use for captioning of the services. It also offers functionality to signal * ServiceEvents and to return the actual classes, so only a minimum of interaction with the MicroserviceInterface is required. * To get started, just put it in your Plugin or Widget, call the Initialize Method and optionally connect it's signals. * As QT limits templating possibilities, events only throw ServiceReferences. You can manually dereference them using TranslateServiceReference() * * @ingroup QMITK */ class QMITK_EXPORT QmitkServiceListWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT private: mitk::ModuleContext* m_Context; /** \brief a filter to further narrow down the list of results*/ std::string m_Filter; /** \brief The name of the ServiceInterface that this class should list */ std::string m_Interface; /** \brief The name of the ServiceProperty that will be displayed in the list to represent the service */ std::string m_NamingProperty; public: static const std::string VIEW_ID; QmitkServiceListWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkServiceListWidget(); /** \brief This method is part of the widget an needs not to be called separately. */ virtual void CreateQtPartControl(QWidget *parent); /** \brief This method is part of the widget an needs not to be called separately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /** * \brief Will return true, if a service is currently selected and false otherwise. * * Call this before requesting service references to avoid invalid ServiceReferences. */ bool GetIsServiceSelected(); /** * \brief Returns the currently selected Service as a ServiceReference. * * If no Service is selected, the result will probably be a bad pointer. call GetIsServiceSelected() * beforehand to avoid this */ mitk::ServiceReference GetSelectedService(); /** * \brief Use this function to return the currently selected service as a class directly. * * Make sure you pass the appropriate type, or else this call will fail. * Usually, you will pass the class itself, not the SmartPointer, but the function returns a pointer. Example: * \verbatim mitk::USDevice::Pointer device = GetSelectedServiceAsClass(); \endverbatim */ template T* GetSelectedServiceAsClass() { mitk::ServiceReference ref = GetServiceForListItem( this->m_Controls->m_ServiceList->currentItem() ); - return dynamic_cast ( m_Context->GetService(ref) ); + return ( m_Context->GetService(ref) ); } /** * \brief Initializes the Widget with essential parameters. * * The string filter is an LDAP parsable String, compare mitk::ModuleContext for examples on filtering. * This. Pass class T to tell the widget which class it should filter for - only services of this class will be listed. * NamingProperty is a property that will be used to caption the Items in the list. If no filter is supplied, all * matching interfaces are shown. If no namingProperty is supplied, the interfaceName will be used to caption Items in the list. * For example, this Initialization will filter for all USDevices that are set to active. The USDevice's model will be used to display it in the list: * \verbatim * std::string filter = "(&(" + mitk::ServiceConstants::OBJECTCLASS() + "=" + "org.mitk.services.UltrasoundDevice)(IsActive=true))"; * m_Controls.m_ActiveVideoDevices->Initialize(mitk::USImageMetadata::PROP_DEV_MODEL ,filter); * \endverbatim */ template void Initialize(const std::string& namingProperty, std::string& filter) { std::string interfaceName ( us_service_interface_iid() ); m_Interface = interfaceName; InitPrivate(namingProperty, filter); } /** * \brief Translates a serviceReference to a class of the given type. * * Use this to translate the signal's parameters. To adhere to the MicroService contract, * only ServiceReferences stemming from the same widget should be used as parameters for this method. * \verbatim mitk::USDevice::Pointer device = TranslateReference(myDeviceReference); \endverbatim */ template T* TranslateReference(mitk::ServiceReference reference) { return dynamic_cast ( m_Context->GetService(reference) ); } /** *\brief This Function listens to ServiceRegistry changes and updates the list of services accordingly. * * The user of this widget does not need to call this method, it is instead used to recieve events from the module registry. */ void OnServiceEvent(const mitk::ServiceEvent event); signals: /** *\brief Emitted when a new Service matching the filter is being registered. * * Be careful if you use a filter: * If a device does not match the filter when registering, but modifies it's properties later to match the filter, * then the first signal you will see this device in will be ServiceModified. */ void ServiceRegistered(mitk::ServiceReference); /** *\brief Emitted directly before a Service matching the filter is being unregistered. */ void ServiceUnregistering(mitk::ServiceReference); /** *\brief Emitted when a Service matching the filter changes it's properties, or when a service that formerly not matched the filter * changed it's properties and now matches the filter. */ void ServiceModified(mitk::ServiceReference); /** *\brief Emitted when a Service matching the filter changes it's properties, * * and the new properties make it fall trough the filter. This effectively means that * the widget will not track the service anymore. Usually, the Service should still be useable though */ void ServiceModifiedEndMatch(mitk::ServiceReference); /** *\brief Emitted if the user selects a Service from the list. * * If no service is selected, an invalid serviceReference is returned. The user can easily check for this. * if (serviceReference) will evaluate to false, if the reference is invalid and true if valid. */ void ServiceSelectionChanged(mitk::ServiceReference); public slots: protected slots: /** \brief Called, when the selection in the list of Services changes. */ void OnServiceSelectionChanged(); protected: Ui::QmitkServiceListWidgetControls* m_Controls; ///< member holding the UI elements of this widget /** * \brief Internal structure used to link ServiceReferences to their QListWidgetItems */ struct ServiceListLink { mitk::ServiceReference service; QListWidgetItem* item; }; /** * \brief Finishes initialization after Initialize has been called. * * This function assumes that m_Interface is set correctly (Which Initialize does). */ void InitPrivate(const std::string& namingProperty, const std::string& filter); /** * \brief Contains a list of currently active services and their entires in the list. This is wiped with every ServiceRegistryEvent. */ std::vector m_ListContent; /** * \brief Constructs a ListItem from the given service, displays it, and locally stores the service. */ QListWidgetItem* AddServiceToList(mitk::ServiceReference serviceRef); /** * \brief Removes the given service from the list and cleans up. Returns true if successful, false if service was not found. */ bool RemoveServiceFromList(mitk::ServiceReference serviceRef); /** * \brief Returns the serviceReference corresponding to the given ListEntry or an invalid one if none was found (will evaluate to false in bool expressions). */ mitk::ServiceReference GetServiceForListItem(QListWidgetItem* item); /** * \brief Returns a list of ServiceReferences matching the filter criteria by querying the service registry. */ std::list GetAllRegisteredServices(); }; #endif // _QmitkServiceListWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp index 539a82c6d5..4ce86ef91f 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp @@ -1,181 +1,83 @@ /*=================================================================== 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. ===================================================================*/ //#define _USE_MATH_DEFINES #include -#include - -//QT headers -#include - -//mitk headers - - - -//itk headers - -//microservices -#include -#include -#include const std::string QmitkUSDeviceManagerWidget::VIEW_ID = "org.mitk.views.QmitkUSDeviceManagerWidget"; QmitkUSDeviceManagerWidget::QmitkUSDeviceManagerWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { m_Controls = NULL; CreateQtPartControl(this); - - // get ModuleContext - mitk::Module* mitkUS = mitk::ModuleRegistry::GetModule("MitkUS"); - m_MitkUSContext = mitkUS->GetModuleContext(); - - //ServiceTracker* tracker = new ServiceTracker(m_MitkUSContext, this); - - // Register this Widget as a listener for Registry changes. - // If devices are registered, unregistered or changed, notifications will go there - std::string filter = "(&("; - filter += mitk::ServiceConstants::OBJECTCLASS(); - filter += "="; - //filter += us_service_interface_iid(); - filter += "org.mitk.services.UltrasoundDevice)(IsActive=false))"; - m_MitkUSContext->AddServiceListener(this, &QmitkUSDeviceManagerWidget::OnServiceEvent, filter); } QmitkUSDeviceManagerWidget::~QmitkUSDeviceManagerWidget() { } //////////////////// INITIALIZATION ///////////////////// void QmitkUSDeviceManagerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkUSDeviceManagerWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); } } void QmitkUSDeviceManagerWidget::CreateConnections() { if ( m_Controls ) { connect( m_Controls->m_BtnActivate, SIGNAL(clicked()), this, SLOT(OnClickedActivateDevice()) ); connect( m_Controls->m_BtnDisconnect, SIGNAL(clicked()), this, SLOT(OnClickedDisconnectDevice()) ); connect( m_Controls->m_ConnectedDevices, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnDeviceSelectionChanged()) ); } -} - + // Initializations + std::string empty = ""; + m_Controls->m_ConnectedDevices->Initialize(mitk::USImageMetadata::PROP_DEV_MODEL, empty); +} ///////////// Methods & Slots Handling Direct Interaction ///////////////// void QmitkUSDeviceManagerWidget::OnClickedActivateDevice() { - mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); + mitk::USDevice::Pointer device = m_Controls->m_ConnectedDevices->GetSelectedServiceAsClass(); if (device.IsNull()) return; if (device->GetIsActive()) device->Deactivate(); else device->Activate(); } void QmitkUSDeviceManagerWidget::OnClickedDisconnectDevice(){ - mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); + mitk::USDevice::Pointer device = m_Controls->m_ConnectedDevices->GetSelectedServiceAsClass(); if (device.IsNull()) return; device->Disconnect(); } void QmitkUSDeviceManagerWidget::OnDeviceSelectionChanged(){ - mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); + mitk::USDevice::Pointer device = m_Controls->m_ConnectedDevices->GetSelectedServiceAsClass(); if (device.IsNull()) return; if (device->GetIsActive()) m_Controls->m_BtnActivate->setText("Deactivate"); else m_Controls->m_BtnActivate->setText("Activate"); } - -///////////////// Methods & Slots Handling Logic ////////////////////////// - -void QmitkUSDeviceManagerWidget::OnServiceEvent(const mitk::ServiceEvent event){ - // Empty ListWidget - this->m_ListContent.clear(); - m_Controls->m_ConnectedDevices->clear(); - - - - // get Active Devices - std::vector devices = this->GetAllRegisteredDevices(); - // Transfer them to the List - for(std::vector::iterator it = devices.begin(); it != devices.end(); ++it) - { - QListWidgetItem *newItem = ConstructItemFromDevice(it->GetPointer()); - //Add new item to QListWidget - m_Controls->m_ConnectedDevices->addItem(newItem); - // Construct Link and add to internal List for reference - QmitkUSDeviceManagerWidget::DeviceListLink link; - link.device = it->GetPointer(); - link.item = newItem; - m_ListContent.push_back(link); - } -} - - -/////////////////////// HOUSEHOLDING CODE ///////////////////////////////// - -QListWidgetItem* QmitkUSDeviceManagerWidget::ConstructItemFromDevice(mitk::USDevice::Pointer device){ - QListWidgetItem *result = new QListWidgetItem; - std::string text = device->GetDeviceManufacturer() + "|" + device->GetDeviceModel(); - - if (device->GetIsActive()) - { - result->foreground().setColor(Qt::blue); - text += "|(ON)"; - } else text += "|(OFF)"; - - result->setText(text.c_str()); - - return result; -} - - -mitk::USDevice::Pointer QmitkUSDeviceManagerWidget::GetDeviceForListItem(QListWidgetItem* item) -{ - for(std::vector::iterator it = m_ListContent.begin(); it != m_ListContent.end(); ++it) - { - if (item == it->item) return it->device; - } - return 0; -} - -std::vector QmitkUSDeviceManagerWidget::GetAllRegisteredDevices(){ - - //Get Service References - std::list serviceRefs = m_MitkUSContext->GetServiceReferences(); - - // Convert Service References to US Devices - std::vector* result = new std::vector; - std::list::const_iterator iterator; - for (iterator = serviceRefs.begin(); iterator != serviceRefs.end(); ++iterator) - { - mitk::USDevice::Pointer device = m_MitkUSContext->GetService(*iterator); - if (device) result->push_back(device); - } - - return *result; -} \ No newline at end of file diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h index 96cdf84c2b..9d92c59731 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h @@ -1,135 +1,83 @@ /*=================================================================== 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 _QmitkUSDeviceManagerWidget_H_INCLUDED #define _QmitkUSDeviceManagerWidget_H_INCLUDED #include "MitkUSUIExports.h" #include "ui_QmitkUSDeviceManagerWidgetControls.h" #include "mitkUSDevice.h" #include //QT headers #include #include -//mitk header -//Microservices -#include "usServiceReference.h" -#include "usModuleContext.h" -#include "usServiceEvent.h" /** * @brief This Widget is used to manage available Ultrasound Devices. * * @ingroup USUI */ class MitkUSUI_EXPORT QmitkUSDeviceManagerWidget :public QWidget //, public mitk::ServiceTrackerCustomizer<> // this extension is necessary if one wants to use ServiceTracking instead of filtering { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkUSDeviceManagerWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkUSDeviceManagerWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); - - /* - *\brief This Function listens to ServiceRegistry changes and updates the - * list of devices accordingly. - */ - void OnServiceEvent(const mitk::ServiceEvent event); - - - - signals: - - /* - \brief Sent, when the user clicks "Activate Device" - */ - void USDeviceActivated(); public slots: protected slots: /* \brief Called, when the button "Activate Device" was clicked */ void OnClickedActivateDevice(); /* \brief Called, when the button "Disconnect Device" was clicked */ void OnClickedDisconnectDevice(); /* \brief Called, when the selection in the devicelist changes */ void OnDeviceSelectionChanged(); protected: Ui::QmitkUSDeviceManagerWidgetControls* m_Controls; ///< member holding the UI elements of this widget - /* - * \brief Internal Structure used to link devices to their QListWidget Items - */ - struct DeviceListLink { - mitk::USDevice::Pointer device; - QListWidgetItem* item; - }; - - /* - * \brief Contains a list of currently active devices and their entires in the list. This is wiped with every ServiceRegistryEvent. - */ - std::vector m_ListContent; - - /* - * \brief Constructs a ListItem from the given device for display in the list of active devices. - */ - QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); - - /* - * \brief Returns the device corresponding to the given ListEntry or null if none was found (which really shouldnt happen). - */ - mitk::USDevice::Pointer GetDeviceForListItem(QListWidgetItem* item); - - //mitk::ServiceTracker ConstructServiceTracker(); - - /* - * \brief Returns a List of US Devices that are currently connected by querying the service registry. - */ - std::vector GetAllRegisteredDevices(); - private: - mitk::ModuleContext* m_MitkUSContext; - }; #endif // _QmitkUSDeviceManagerWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui index 12e83cb191..124c1c7d1a 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui @@ -1,57 +1,65 @@ QmitkUSDeviceManagerWidgetControls 0 0 405 231 0 0 QmitkUSDeviceManagerWidget 11 Connected Devices: Activate Device Disconnect Device - + + + + QmitkServiceListWidget + QWidget +
QmitkServiceListWidget.h
+ 1 +
+
diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp index 6d9028e125..093daccbfb 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp @@ -1,116 +1,116 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include //Mitk #include "mitkDataNode.h" // Qmitk #include "UltrasoundSupport.h" #include // Qt #include // Ultrasound #include "mitkUSDevice.h" const std::string UltrasoundSupport::VIEW_ID = "org.mitk.views.ultrasoundsupport"; void UltrasoundSupport::SetFocus() { m_Controls.m_AddDevice->setFocus(); } void UltrasoundSupport::CreateQtPartControl( QWidget *parent ) { m_Timer = new QTimer(this); // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); connect( m_Controls.m_AddDevice, SIGNAL(clicked()), this, SLOT(OnClickedAddNewDevice()) ); // Change Widget Visibilities connect( m_Controls.m_AddDevice, SIGNAL(clicked()), this->m_Controls.m_NewVideoDeviceWidget, SLOT(CreateNewDevice()) ); // Init NewDeviceWidget connect( m_Controls.m_NewVideoDeviceWidget, SIGNAL(Finished()), this, SLOT(OnNewDeviceWidgetDone()) ); // After NewDeviceWidget finished editing connect( m_Controls.m_BtnView, SIGNAL(clicked()), this, SLOT(OnClickedViewDevice()) ); connect( m_Timer, SIGNAL(timeout()), this, SLOT(DisplayImage())); //connect (m_Controls.m_ActiveVideoDevices, SIGNAL()) // Initializations m_Controls.m_NewVideoDeviceWidget->setVisible(false); std::string filter = "(&(" + mitk::ServiceConstants::OBJECTCLASS() + "=" + "org.mitk.services.UltrasoundDevice)(IsActive=true))"; m_Controls.m_ActiveVideoDevices->Initialize(mitk::USImageMetadata::PROP_DEV_MODEL ,filter); m_Node = mitk::DataNode::New(); m_Node->SetName("US Image Stream"); this->GetDataStorage()->Add(m_Node); } void UltrasoundSupport::OnClickedAddNewDevice() { m_Controls.m_NewVideoDeviceWidget->setVisible(true); m_Controls.m_DeviceManagerWidget->setVisible(false); m_Controls.m_AddDevice->setVisible(false); m_Controls.m_Headline->setText("Add New Device:"); } void UltrasoundSupport::DisplayImage() { m_Device->UpdateOutputData(0); mitk::USImage::Pointer image = m_Device->GetOutput(); m_Node->SetData(image); // m_Image->Update(); this->RequestRenderWindowUpdate(); } void UltrasoundSupport::OnClickedViewDevice() { // We use the activity state of the timer to determine whether we are currently viewing images if ( ! m_Timer->isActive() ) // Activate Imaging { m_Device = m_Controls.m_ActiveVideoDevices->GetSelectedServiceAsClass(); if (m_Device.IsNull()){ m_Timer->stop(); return; } m_Device->UpdateOutputData(0); m_Image = m_Device->GetOutput(0); m_Node->SetData(m_Device->GetOutput(0)); int interval = (1000 / m_Controls.m_FrameRate->value()); m_Timer->setInterval(interval); m_Timer->start(); m_Controls.m_BtnView->setText("Stop Viewing"); } else - { //deactivate Imaging + { //deactivate imaging m_Controls.m_BtnView->setText("Start Viewing"); m_Timer->stop(); m_Node->ReleaseData(); this->RequestRenderWindowUpdate(); } } void UltrasoundSupport::OnNewDeviceWidgetDone() { m_Controls.m_NewVideoDeviceWidget->setVisible(false); m_Controls.m_DeviceManagerWidget->setVisible(true); m_Controls.m_AddDevice->setVisible(true); m_Controls.m_Headline->setText("Connected Devices:"); } \ No newline at end of file