diff --git a/Modules/Qmitk/QmitkServiceListWidget.cpp b/Modules/Qmitk/QmitkServiceListWidget.cpp index 6a6651f35f..d4ce5b735d 100644 --- a/Modules/Qmitk/QmitkServiceListWidget.cpp +++ b/Modules/Qmitk/QmitkServiceListWidget.cpp @@ -1,198 +1,196 @@ /*=================================================================== 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 // STL HEaders #include -//QT headers -#include - //microservices #include #include #include #include const std::string QmitkServiceListWidget::VIEW_ID = "org.mitk.views.QmitkServiceListWidget"; QmitkServiceListWidget::QmitkServiceListWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { m_Controls = NULL; CreateQtPartControl(this); } QmitkServiceListWidget::~QmitkServiceListWidget() { m_Context->RemoveServiceListener(this, &QmitkServiceListWidget::OnServiceEvent); } //////////////////// INITIALIZATION ///////////////////// void QmitkServiceListWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkServiceListWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); } m_Context = mitk::GetModuleContext(); } void QmitkServiceListWidget::CreateConnections() { if ( m_Controls ) { connect( m_Controls->m_ServiceList, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnServiceSelectionChanged()) ); } } void QmitkServiceListWidget::InitPrivate(const std::string& namingProperty, const std::string& filter) { if (filter.empty()) m_Filter = "(" + mitk::ServiceConstants::OBJECTCLASS() + "=" + m_Interface + ")"; else m_Filter = filter; m_NamingProperty = namingProperty; m_Context->RemoveServiceListener(this, &QmitkServiceListWidget::OnServiceEvent); m_Context->AddServiceListener(this, &QmitkServiceListWidget::OnServiceEvent, m_Filter); // Empty ListWidget this->m_ListContent.clear(); m_Controls->m_ServiceList->clear(); // get Services std::list services = this->GetAllRegisteredServices(); // Transfer them to the List for(std::list::iterator it = services.begin(); it != services.end(); ++it) AddServiceToList(*it); } ///////////// Methods & Slots Handling Direct Interaction ///////////////// bool QmitkServiceListWidget::GetIsServiceSelected(){ return (this->m_Controls->m_ServiceList->currentItem() != 0); } void QmitkServiceListWidget::OnServiceSelectionChanged(){ mitk::ServiceReference ref = this->GetServiceForListItem(this->m_Controls->m_ServiceList->currentItem()); if (! ref){ emit (ServiceSelectionChanged(mitk::ServiceReference())); return; } emit (ServiceSelectionChanged(ref)); } mitk::ServiceReference QmitkServiceListWidget::GetSelectedService(){ return this->GetServiceForListItem(this->m_Controls->m_ServiceList->currentItem()); } ///////////////// Methods & Slots Handling Logic ////////////////////////// void QmitkServiceListWidget::OnServiceEvent(const mitk::ServiceEvent event){ + //MITK_INFO << "ServiceEvent" << event.GetType(); switch (event.GetType()) { case mitk::ServiceEvent::MODIFIED: emit(ServiceModified(event.GetServiceReference())); RemoveServiceFromList(event.GetServiceReference()); AddServiceToList(event.GetServiceReference()); break; case mitk::ServiceEvent::REGISTERED: emit(ServiceRegistered(event.GetServiceReference())); AddServiceToList(event.GetServiceReference()); break; case mitk::ServiceEvent::UNREGISTERING: emit(ServiceUnregistering(event.GetServiceReference())); RemoveServiceFromList(event.GetServiceReference()); break; case mitk::ServiceEvent::MODIFIED_ENDMATCH: emit(ServiceModifiedEndMatch(event.GetServiceReference())); RemoveServiceFromList(event.GetServiceReference()); break; } } /////////////////////// HOUSEHOLDING CODE ///////////////////////////////// QListWidgetItem* QmitkServiceListWidget::AddServiceToList(mitk::ServiceReference serviceRef){ QListWidgetItem *newItem = new QListWidgetItem; std::string caption; //TODO allow more complex formatting if (m_NamingProperty.empty()) caption = m_Interface; else { mitk::Any prop = serviceRef.GetProperty(m_NamingProperty); if (prop.Empty()) { MITK_WARN << "QmitkServiceListWidget tried to resolve property '" + m_NamingProperty + "' but failed. Resorting to interface name for display."; caption = m_Interface; } else caption = prop.ToString(); } newItem->setText(caption.c_str()); // Add new item to QListWidget m_Controls->m_ServiceList->addItem(newItem); m_Controls->m_ServiceList->sortItems(); // Construct link and add to internal List for reference QmitkServiceListWidget::ServiceListLink link; link.service = serviceRef; link.item = newItem; m_ListContent.push_back(link); return newItem; } bool QmitkServiceListWidget::RemoveServiceFromList(mitk::ServiceReference serviceRef){ for(std::vector::iterator it = m_ListContent.begin(); it != m_ListContent.end(); ++it){ if ( serviceRef == it->service ) { int row = m_Controls->m_ServiceList->row(it->item); QListWidgetItem* oldItem = m_Controls->m_ServiceList->takeItem(row); delete oldItem; this->m_ListContent.erase(it); return true; } } return false; } mitk::ServiceReference QmitkServiceListWidget::GetServiceForListItem(QListWidgetItem* item) { for(std::vector::iterator it = m_ListContent.begin(); it != m_ListContent.end(); ++it) if (item == it->item) return it->service; // Return invalid ServiceReference (will evaluate to false in bool expressions) return mitk::ServiceReference(); } std::list QmitkServiceListWidget::GetAllRegisteredServices(){ //Get Service References return m_Context->GetServiceReferences(m_Interface, m_Filter); } \ No newline at end of file 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/US/USModel/mitkUSDevice.cpp b/Modules/US/USModel/mitkUSDevice.cpp index 3bb0aace67..bef6ed4736 100644 --- a/Modules/US/USModel/mitkUSDevice.cpp +++ b/Modules/US/USModel/mitkUSDevice.cpp @@ -1,282 +1,294 @@ /*=================================================================== 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 "mitkUSDevice.h" #include "mitkUSImageMetadata.h" //Microservices #include #include #include #include "mitkModuleContext.h" +const std::string mitk::USDevice::US_INTERFACE_NAME = "org.mitk.services.UltrasoundDevice"; +const std::string mitk::USDevice::US_PROPKEY_LABEL = US_INTERFACE_NAME + ".label"; +const std::string mitk::USDevice::US_PROPKEY_ISACTIVE = US_INTERFACE_NAME + ".isActive"; +const std::string mitk::USDevice::US_PROPKEY_CLASS = US_INTERFACE_NAME + ".class"; + mitk::USDevice::USDevice(std::string manufacturer, std::string model) : mitk::ImageSource() { // Initialize Members m_Metadata = mitk::USImageMetadata::New(); m_Metadata->SetDeviceManufacturer(manufacturer); m_Metadata->SetDeviceModel(model); - //m_Metadata->SetDeviceClass(GetDeviceClass()); m_IsActive = false; //set number of outputs this->SetNumberOfOutputs(1); //create a new output mitk::USImage::Pointer newOutput = mitk::USImage::New(); this->SetNthOutput(0,newOutput); } mitk::USDevice::USDevice(mitk::USImageMetadata::Pointer metadata) : mitk::ImageSource() { m_Metadata = metadata; - //m_Metadata->SetDeviceClass(GetDeviceClass()); m_IsActive = false; //set number of outputs this->SetNumberOfOutputs(1); //create a new output mitk::USImage::Pointer newOutput = mitk::USImage::New(); this->SetNthOutput(0,newOutput); } - mitk::USDevice::~USDevice() { } - -// Constructing Service Properties for the device mitk::ServiceProperties mitk::USDevice::ConstructServiceProperties() { ServiceProperties props; std::string yes = "true"; std::string no = "false"; if(this->GetIsActive()) - props["IsActive"] = yes; + props[mitk::USDevice::US_PROPKEY_ISACTIVE] = yes; else - props["IsActive"] = no; + props[mitk::USDevice::US_PROPKEY_ISACTIVE] = no; + + std::string isActive; + if (GetIsActive()) isActive = " (Active)"; + else isActive = " (Inactive)"; + // e.g.: Zonare MyLab5 (Active) + props[ mitk::USDevice::US_PROPKEY_LABEL] = m_Metadata->GetDeviceManufacturer() + " " + m_Metadata->GetDeviceModel() + isActive; if( m_Calibration.IsNotNull() ) props[ mitk::USImageMetadata::PROP_DEV_ISCALIBRATED ] = yes; else props[ mitk::USImageMetadata::PROP_DEV_ISCALIBRATED ] = no; - props[ "DeviceClass" ] = GetDeviceClass(); + props[ mitk::USDevice::US_PROPKEY_CLASS ] = GetDeviceClass(); props[ mitk::USImageMetadata::PROP_DEV_MANUFACTURER ] = m_Metadata->GetDeviceManufacturer(); props[ mitk::USImageMetadata::PROP_DEV_MODEL ] = m_Metadata->GetDeviceModel(); props[ mitk::USImageMetadata::PROP_DEV_COMMENT ] = m_Metadata->GetDeviceComment(); props[ mitk::USImageMetadata::PROP_PROBE_NAME ] = m_Metadata->GetProbeName(); props[ mitk::USImageMetadata::PROP_PROBE_FREQUENCY ] = m_Metadata->GetProbeFrequency(); props[ mitk::USImageMetadata::PROP_ZOOM ] = m_Metadata->GetZoom(); + return props; } - bool mitk::USDevice::Connect() { - //TODO Throw Exception is already activated before connection - + if (GetIsConnected()) + { + MITK_WARN << "Tried to connect an ultrasound device that was already connected. Ignoring call..."; + return false; + } // Prepare connection, fail if this fails. if (! this->OnConnection()) return false; // Get Context and Module mitk::ModuleContext* context = GetModuleContext(); ServiceProperties props = ConstructServiceProperties(); m_ServiceRegistration = context->RegisterService(this, props); - return true; -} + // This makes sure that the SmartPointer to this device does not invalidate while the device is connected + this->Register(); + return true; +} bool mitk::USDevice::Disconnect() { + if ( ! GetIsConnected()) + { + MITK_WARN << "Tried to disconnect an ultrasound device that was not connected. Ignoring call..."; + return false; + } // Prepare connection, fail if this fails. if (! this->OnDisconnection()) return false; // Unregister m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; + + // Undo the manual registration done in Connect(). Pointer will invalidte, if no one holds a reference to this object anymore. + this->UnRegister(); return true; } -//Changed bool mitk::USDevice::Activate() { if (! this->GetIsConnected()) return false; m_IsActive = OnActivation(); ServiceProperties props = ConstructServiceProperties(); this->m_ServiceRegistration.SetProperties(props); return m_IsActive; } void mitk::USDevice::Deactivate() { m_IsActive= false; ServiceProperties props = ConstructServiceProperties(); this->m_ServiceRegistration.SetProperties(props); OnDeactivation(); } void mitk::USDevice::AddProbe(mitk::USProbe::Pointer probe) { for(int i = 0; i < m_ConnectedProbes.size(); i++) { if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) return; } this->m_ConnectedProbes.push_back(probe); } void mitk::USDevice::ActivateProbe(mitk::USProbe::Pointer probe){ - // currently, we may just add the probe. This behaviour must be changed, should more complicated SDK applications emerge + // currently, we may just add the probe. This behaviour should be changed, should more complicated SDK applications emerge AddProbe(probe); int index = -1; for(int i = 0; i < m_ConnectedProbes.size(); i++) { if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) index = i; } // index now contains the position of the original instance of this probe m_ActiveProbe = m_ConnectedProbes[index]; } void mitk::USDevice::DeactivateProbe(){ m_ActiveProbe = 0; } -void mitk::USDevice::GenerateData() -{ - -} - - mitk::USImage* mitk::USDevice::GetOutput() { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(0)); } mitk::USImage* mitk::USDevice::GetOutput(unsigned int idx) { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(idx)); } void mitk::USDevice::GraftOutput(itk::DataObject *graft) { this->GraftNthOutput(0, graft); } void mitk::USDevice::GraftNthOutput(unsigned int idx, itk::DataObject *graft) { if ( idx >= this->GetNumberOfOutputs() ) { itkExceptionMacro(<<"Requested to graft output " << idx << " but this filter only has " << this->GetNumberOfOutputs() << " Outputs."); } if ( !graft ) { itkExceptionMacro(<<"Requested to graft output with a NULL pointer object" ); } itk::DataObject* output = this->GetOutput(idx); if ( !output ) { itkExceptionMacro(<<"Requested to graft output that is a NULL pointer" ); } // Call Graft on USImage to copy member data output->Graft( graft ); } itk::ProcessObject::DataObjectPointer mitk::USDevice::MakeOutput( unsigned int /*idx */) { mitk::USImage::Pointer p = mitk::USImage::New(); return static_cast(p.GetPointer()); } bool mitk::USDevice::ApplyCalibration(mitk::USImage::Pointer image){ if ( m_Calibration.IsNull() ) return false; image->GetGeometry()->SetIndexToWorldTransform(m_Calibration); return true; } //########### GETTER & SETTER ##################// void mitk::USDevice::setCalibration (mitk::AffineTransform3D::Pointer calibration){ if (calibration.IsNull()) { MITK_ERROR << "Null pointer passed to SetCalibration of mitk::USDevice. Ignoring call."; return; } m_Calibration = calibration; m_Metadata->SetDeviceIsCalibrated(true); if (m_ServiceRegistration != 0) { ServiceProperties props = ConstructServiceProperties(); this->m_ServiceRegistration.SetProperties(props); } } bool mitk::USDevice::GetIsActive() { return m_IsActive; } bool mitk::USDevice::GetIsConnected() { - // a device is connected if it is registered with the service + // a device is connected if it is registered with the Microservice Registry return (m_ServiceRegistration != 0); } std::string mitk::USDevice::GetDeviceManufacturer(){ return this->m_Metadata->GetDeviceManufacturer(); } std::string mitk::USDevice::GetDeviceModel(){ return this->m_Metadata->GetDeviceModel(); } std::string mitk::USDevice::GetDeviceComment(){ return this->m_Metadata->GetDeviceComment(); } std::vector mitk::USDevice::GetConnectedProbes() { return m_ConnectedProbes; } diff --git a/Modules/US/USModel/mitkUSDevice.h b/Modules/US/USModel/mitkUSDevice.h index 90020b90f3..f2cfff5045 100644 --- a/Modules/US/USModel/mitkUSDevice.h +++ b/Modules/US/USModel/mitkUSDevice.h @@ -1,297 +1,298 @@ /*=================================================================== 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 MITKUSDevice_H_HEADER_INCLUDED_ #define MITKUSDevice_H_HEADER_INCLUDED_ // STL #include // MitkUS #include "mitkUSProbe.h" #include "mitkUSImageMetadata.h" #include "mitkUSImage.h" #include // MITK #include #include // ITK #include // Microservices #include #include #include - namespace mitk { /**Documentation * \brief A device holds information about it's model, make and the connected probes. It is the * common super class for all devices and acts as an image source for mitkUSImages. It is the base class * for all US Devices, and every new device should extend it. * * US Devices support output of calibrated images, i.e. images that include a specific geometry. * To achieve this, call SetCalibration, and make sure that the subclass also calls apply * transformation at some point (The USDevice does not automatically apply the transformation to the image) + * + * Note that SmartPointers to USDevices will not invalidate while the device is still connected. * \ingroup US */ class MitkUS_EXPORT USDevice : public mitk::ImageSource { public: mitkClassMacro(USDevice, mitk::ImageSource); - /** - * \brief Enforces minimal Metadata to be set. - */ - // mitkNewMacro3Param(Self, std::string, std::string, bool); - - - /** - * \brief Constructs a device with the given Metadata. Make sure the Metadata contains meaningful content! - * + /** + *\brief These constants are used in conjunction with Microservices */ - // mitkNewMacro2Param(Self, mitk::USImageMetadata::Pointer, bool); - + static const std::string US_INTERFACE_NAME; // Common Interface name of all US Devices. Used to refer to this device via Microservices + static const std::string US_PROPKEY_LABEL; // Human readable text represntation of this device + static const std::string US_PROPKEY_ISACTIVE; // Whether this Device is active or not. + static const std::string US_PROPKEY_CLASS; // Class Name of this Object /** * \brief Connects this device. A connected device is ready to deliver images (i.e. be Activated). A Connected Device can be active. A disconnected Device cannot be active. * Internally calls onConnect and then registers the device with the service. A device usually should * override the OnConnection() method, but never the Connect() method, since this will possibly exclude the device * from normal service management. The exact flow of events is: * 0. Check if the device is already connected. If yes, return true anyway, but don't do anything. * 1. Call OnConnection() Here, a device should establish it's connection with the hardware Afterwards, it should be ready to start transmitting images at any time. * 2. If OnConnection() returns true ("successful"), then the device is registered with the service. * 3. if not, it the method itself returns false or may throw an expection, depeneding on the device implementation. * */ bool Connect(); /** * \brief Works analogously to mitk::USDevice::Connect(). Don't override this Method, but onDisconnection instead. */ bool Disconnect(); /** * \brief Activates this device. After the activation process, the device will start to produce images. This Method will fail, if the device is not connected. */ bool Activate(); /** * \brief Deactivates this device. After the deactivation process, the device will no longer produce images, but still be connected. */ void Deactivate(); /** * \brief Add a probe to the device without connecting to it. * This should usually be done before connecting to the probe. */ virtual void AddProbe(mitk::USProbe::Pointer probe); /** * \brief Connect to a probe and activate it. The probe should be added first. * Usually, a VideoDevice will simply add a probe it wants to connect to, * but an SDK Device might require adding a probe first. */ virtual void ActivateProbe(mitk::USProbe::Pointer probe); /** * \brief Deactivates the currently active probe. */ virtual void DeactivateProbe(); /** * \brief Removes a probe from the ist of currently added probes. */ //virtual void removeProbe(mitk::USProbe::Pointer probe); /** * \brief Returns a vector containing all connected probes. */ std::vector GetConnectedProbes(); /** *\brief return the output (output with id 0) of the filter */ USImage* GetOutput(void); /** *\brief return the output with id idx of the filter */ USImage* GetOutput(unsigned int idx); /** *\brief Graft the specified DataObject onto this ProcessObject's output. * * See itk::ImageSource::GraftNthOutput for details */ virtual void GraftNthOutput(unsigned int idx, itk::DataObject *graft); /** * \brief Graft the specified DataObject onto this ProcessObject's output. * * See itk::ImageSource::Graft Output for details */ virtual void GraftOutput(itk::DataObject *graft); /** * \brief Make a DataObject of the correct type to used as the specified output. * * This method is automatically called when DataObject::DisconnectPipeline() * is called. DataObject::DisconnectPipeline, disconnects a data object * from being an output of its current source. When the data object * is disconnected, the ProcessObject needs to construct a replacement * output data object so that the ProcessObject is in a valid state. * Subclasses of USImageVideoSource that have outputs of different * data types must overwrite this method so that proper output objects * are created. */ virtual DataObjectPointer MakeOutput(unsigned int idx); //########### GETTER & SETTER ##################// /** * \brief Returns the Class of the Device. This Method must be reimplemented by every Inheriting Class. */ virtual std::string GetDeviceClass() = 0; /** * \brief True, if the device is currently generating image data, false otherwise. */ bool GetIsActive(); /** * \brief True, if the device is currently ready to start transmitting image data or is already * transmitting image data. A disconnected device cannot be activated. */ bool GetIsConnected(); /** * \brief Sets a transformation as Calibration data. It also marks the device as Calibrated. This data is not automatically applied to the image. Subclasses must call ApplyTransformation * to achieve this. */ void setCalibration (mitk::AffineTransform3D::Pointer calibration); /** * \brief Returns the current Calibration */ itkGetMacro(Calibration, mitk::AffineTransform3D::Pointer); /** * \brief Returns the currently active probe or null, if none is active */ itkGetMacro(ActiveProbe, mitk::USProbe::Pointer); - + std::string GetDeviceManufacturer(); std::string GetDeviceModel(); std::string GetDeviceComment(); protected: mitk::USProbe::Pointer m_ActiveProbe; std::vector m_ConnectedProbes; bool m_IsActive; /* * \brief This Method constructs the service properties which can later be used to * register the object with the Microservices * Return service properties */ mitk::ServiceProperties ConstructServiceProperties(); /** * \brief Is called during the connection process. Override this method in your subclass to handle the actual connection. * Return true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. */ virtual bool OnConnection() = 0; /** * \brief Is called during the disconnection process. Override this method in your subclass to handle the actual disconnection. * Return true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. */ virtual bool OnDisconnection() = 0; /** * \brief Is called during the activation process. After this method is finished, the device should be generating images */ virtual bool OnActivation() = 0; /** * \brief Is called during the deactivation process. After a call to this method the device should still be connected, but not producing images anymore. */ virtual void OnDeactivation() = 0; /** * \brief This metadata set is privately used to imprint USImages with Metadata later. * At instantiation time, it only contains Information about the Device, * At scan time, it integrates this data with the probe information and imprints it on * the produced images. This field is intentionally hidden from outside interference. */ mitk::USImageMetadata::Pointer m_Metadata; /** * \brief Enforces minimal Metadata to be set. */ USDevice(std::string manufacturer, std::string model); /** * \brief Constructs a device with the given Metadata. Make sure the Metadata contains meaningful content! */ USDevice(mitk::USImageMetadata::Pointer metadata); virtual ~USDevice(); /** * \brief Grabs the next frame from the Video input. This method is called internally, whenever Update() is invoked by an Output. */ - void GenerateData(); + void GenerateData() = 0; /** * \brief The Calibration Transformation of this US-Device. This will automatically be written into the image once */ mitk::AffineTransform3D::Pointer m_Calibration; /** * \brief Convenience method that can be used by subclasses to apply the Calibration Data to the image. A subclass has to call * this method or set the transformation itself for the output to be calibrated! Returns true if a Calibration was set and false otherwise * (Usually happens when no transformation was set yet). */ bool ApplyCalibration(mitk::USImage::Pointer image); private: + /** + * \brief The device's ServiceRegistration object that allows to modify it's Microservice registraton details. + */ mitk::ServiceRegistration m_ServiceRegistration; + + }; } // namespace mitk // This is the microservice declaration. Do not meddle! US_DECLARE_SERVICE_INTERFACE(mitk::USDevice, "org.mitk.services.UltrasoundDevice") #endif \ No newline at end of file diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.cpp deleted file mode 100644 index 75acd872b2..0000000000 --- a/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.cpp +++ /dev/null @@ -1,167 +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. - -===================================================================*/ - -//#define _USE_MATH_DEFINES -#include -#include - -//QT headers -#include - -//mitk headers - - -//itk headers - -//microservices -#include -#include -#include - - -const std::string QmitkUSDeviceListWidget::VIEW_ID = "org.mitk.views.QmitkUSDeviceListWidget"; - -QmitkUSDeviceListWidget::QmitkUSDeviceListWidget(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(); - -} - -QmitkUSDeviceListWidget::~QmitkUSDeviceListWidget() -{ - -} - -//////////////////// INITIALIZATION ///////////////////// - -void QmitkUSDeviceListWidget::CreateQtPartControl(QWidget *parent) -{ - if (!m_Controls) - { - // create GUI widgets - m_Controls = new Ui::QmitkUSDeviceListWidgetControls; - m_Controls->setupUi(parent); - this->CreateConnections(); - } -} - -void QmitkUSDeviceListWidget::CreateConnections() -{ - if ( m_Controls ) - { - connect( m_Controls->m_DeviceList, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnDeviceSelectionChanged()) ); - } -} - -void QmitkUSDeviceListWidget::Initialize(std::string filter) -{ - m_Filter = filter; - m_MitkUSContext->AddServiceListener(this, &QmitkUSDeviceListWidget::OnServiceEvent, m_Filter); -} - - -///////////////////////// Getter & Setter ///////////////////////////////// - -mitk::USDevice::Pointer QmitkUSDeviceListWidget::GetSelectedDevice() -{ - return this->GetDeviceForListItem(this->m_Controls->m_DeviceList->currentItem()); -} - -///////////// Methods & Slots Handling Direct Interaction ///////////////// - - -void QmitkUSDeviceListWidget::OnDeviceSelectionChanged(){ - mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_DeviceList->currentItem()); - if (device.IsNull()) return; - emit (DeviceSelected(device)); -} - - -///////////////// Methods & Slots Handling Logic ////////////////////////// - -void QmitkUSDeviceListWidget::OnServiceEvent(const mitk::ServiceEvent event){ - // Empty ListWidget - this->m_ListContent.clear(); - m_Controls->m_DeviceList->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_DeviceList->addItem(newItem); - // Construct link and add to internal List for reference - QmitkUSDeviceListWidget::DeviceListLink link; - link.device = it->GetPointer(); - link.item = newItem; - m_ListContent.push_back(link); - } -} - - -/////////////////////// HOUSEHOLDING CODE ///////////////////////////////// - -QListWidgetItem* QmitkUSDeviceListWidget::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 QmitkUSDeviceListWidget::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 QmitkUSDeviceListWidget::GetAllRegisteredDevices(){ - - //Get Service References - std::list serviceRefs = m_MitkUSContext->GetServiceReferences(m_Filter); - - // 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/QmitkUSDeviceListWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.h deleted file mode 100644 index 4cdbd671c4..0000000000 --- a/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.h +++ /dev/null @@ -1,158 +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 _QmitkUSDeviceListWidget_H_INCLUDED -#define _QmitkUSDeviceListWidget_H_INCLUDED - -#include "MitkUSUIExports.h" -#include "ui_QmitkUSDeviceListWidgetControls.h" -#include "mitkUSDevice.h" -#include - -//QT headers -#include -#include - -//mitk header - -//Microservices -#include "usServiceReference.h" -#include "usModuleContext.h" -#include "usServiceEvent.h" -#include "usServiceTrackerCustomizer.h" - -/** -* @brief TODO -* -* @ingroup USUI -*/ -class MitkUSUI_EXPORT QmitkUSDeviceListWidget :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; - - QmitkUSDeviceListWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); - virtual ~QmitkUSDeviceListWidget(); - - /* @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 Initializes the connection to the registry. The string filter is an LDAP parsable String, compare mitk::ModuleContext for examples on filtering. - */ - void Initialize(std::string filter); - - /* - * \brief Returns the currently selected device, or null if none is selected. - */ - mitk::USDevice::Pointer GetSelectedDevice(); - - /* - *\brief This Function listens to ServiceRegistry changes and updates the - * list of devices accordingly. - */ - void OnServiceEvent(const mitk::ServiceEvent event); - - - - signals: - - /* - *\brief Emitted when a new device mathing the filter connects - */ - void DeviceConnected(mitk::USDevice::Pointer); - /* - *\brief Emitted directly before device matching the filter disconnects - */ - void DeviceDisconnected(mitk::USDevice::Pointer); - /* - *\brief Emitted when a new device mathing the filter changes it's state. This does of now only compromise changes to activity. - */ - void DeviceChanged(mitk::USDevice::Pointer); - - /* - *\brief Emitted the user selects a device from the list - */ - void DeviceSelected(mitk::USDevice::Pointer); - - - - public slots: - - protected slots: - - /* - \brief Called, when the selection in the devicelist changes - */ - void OnDeviceSelectionChanged(); - - - protected: - - Ui::QmitkUSDeviceListWidgetControls* 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; - std::string m_Filter; - - - - - -}; - -#endif // _QmitkUSDeviceListWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceListWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSDeviceListWidgetControls.ui deleted file mode 100644 index 4d36c2bb5e..0000000000 --- a/Modules/USUI/Qmitk/QmitkUSDeviceListWidgetControls.ui +++ /dev/null @@ -1,31 +0,0 @@ - - - QmitkUSDeviceListWidgetControls - - - - 0 - 0 - 323 - 231 - - - - - 0 - 0 - - - - QmitkUSDeviceListWidget - - - - - - - - - - - diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp index 539a82c6d5..71b2a96d73 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp @@ -1,181 +1,101 @@ /*=================================================================== 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(); } + + // Initializations + std::string empty = ""; + m_Controls->m_ConnectedDevices->Initialize(mitk::USDevice::US_PROPKEY_LABEL, empty); } 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()) ); + 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( ServiceSelectionChanged(mitk::ServiceReference) ), this, SLOT(OnDeviceSelectionChanged(mitk::ServiceReference)) ); } } - - ///////////// 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(); + + // Manually reevaluate Button logic + OnDeviceSelectionChanged(m_Controls->m_ConnectedDevices->GetSelectedService()); } 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()); - 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) +void QmitkUSDeviceManagerWidget::OnDeviceSelectionChanged(mitk::ServiceReference reference){ + if (! reference) { - 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); + m_Controls->m_BtnActivate->setEnabled(false); + m_Controls->m_BtnDisconnect->setEnabled(false); + return; } -} - - -/////////////////////// HOUSEHOLDING CODE ///////////////////////////////// - -QListWidgetItem* QmitkUSDeviceManagerWidget::ConstructItemFromDevice(mitk::USDevice::Pointer device){ - QListWidgetItem *result = new QListWidgetItem; - std::string text = device->GetDeviceManufacturer() + "|" + device->GetDeviceModel(); - - if (device->GetIsActive()) + std::string isActive = reference.GetProperty( mitk::USDevice::US_PROPKEY_ISACTIVE ).ToString(); + if (isActive.compare("true") == 0) { - 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; + m_Controls->m_BtnActivate->setEnabled(true); + m_Controls->m_BtnDisconnect->setEnabled(false); + m_Controls->m_BtnActivate->setText("Deactivate"); } - 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) + else { - mitk::USDevice::Pointer device = m_MitkUSContext->GetService(*iterator); - if (device) result->push_back(device); + m_Controls->m_BtnActivate->setEnabled(true); + m_Controls->m_BtnDisconnect->setEnabled(true); + m_Controls->m_BtnActivate->setText("Activate"); } +} - return *result; -} \ No newline at end of file diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h index 96cdf84c2b..425ee54ca1 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h @@ -1,135 +1,85 @@ /*=================================================================== 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. * +* It allows activation, deactivation and disconnection of connected 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 +class MitkUSUI_EXPORT QmitkUSDeviceManagerWidget :public QWidget { //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 + \brief Called, when the button "Activate Device" was clicked. */ void OnClickedActivateDevice(); /* - \brief Called, when the button "Disconnect Device" was clicked + \brief Called, when the button "Disconnect Device" was clicked. */ void OnClickedDisconnectDevice(); /* - \brief Called, when the selection in the devicelist changes + \brief Called, when the selection in the devicelist changes. */ - void OnDeviceSelectionChanged(); + void OnDeviceSelectionChanged(mitk::ServiceReference reference); 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..309ec77405 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui @@ -1,57 +1,53 @@ QmitkUSDeviceManagerWidgetControls 0 0 405 231 0 0 QmitkUSDeviceManagerWidget - - - - - 11 - - - - Connected Devices: - - - - + Activate Device - + Disconnect Device - - + + + + + QmitkServiceListWidget + QWidget +
QmitkServiceListWidget.h
+ 1 +
+
diff --git a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h index 22bf408b68..da109202cf 100644 --- a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h @@ -1,122 +1,122 @@ /*=================================================================== 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 _QmitkUSNewVideoDeviceWidget_H_INCLUDED #define _QmitkUSNewVideoDeviceWidget_H_INCLUDED #include "MitkUSUIExports.h" #include "ui_QmitkUSNewVideoDeviceWidgetControls.h" #include "mitkUSVideoDevice.h" #include "mitkUSImageMetadata.h" //QT headers #include #include //mitk header /** -* @brief TODO +* @brief This Widget enables the USer to create and connect Video Devices. * * @ingroup USUI */ class MitkUSUI_EXPORT QmitkUSNewVideoDeviceWidget :public QWidget { //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; QmitkUSNewVideoDeviceWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkUSNewVideoDeviceWidget(); /* @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(); signals: void Finished(); public slots: /* \brief Activates the widget and displays the given device's Data to edit. */ void EditDevice(mitk::USDevice::Pointer device); /* \brief Activates the widget with fields empty. */ void CreateNewDevice(); protected slots: /* \brief Called, when the the user clicks the "Done" button (Labeled either "Add Device" or "Edit Device", depending on the situation. */ void OnClickedDone(); /* \brief Called, when the button "Cancel" was clicked */ void OnClickedCancel(); /* \brief Called, when the Use selects one of the Radiobuttons */ void OnDeviceTypeSelection(); protected: Ui::QmitkUSNewVideoDeviceWidgetControls* m_Controls; ///< member holding the UI elements of this widget /* \brief Constructs a ListItem from the given device for display in the list of active devices */ QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); /* \brief Initializes the Widget's ListItems with the given Metadata Object. */ void InitFields(mitk::USImageMetadata::Pointer); /* \brief Displays whether this widget is active or not. It gets activated by either sending a Signal to * the "CreateNewDevice" Slot or to the "EditDevice" Slot. If the user finishes editing the device, a * "EditingComplete" Signal is sent, and the widget is set to inactive again. Clicking Cancel also * deactivates it. */ bool m_Active; /** * \brief This is the device to edit. It is either the device transmitted in the "EditDevice" signal, or a new one * if the "CreateNewDevice slot was called. */ mitk::USVideoDevice::Pointer m_TargetDevice; }; #endif // _QmitkUSNewVideoDeviceWidget_H_INCLUDED diff --git a/Modules/USUI/files.cmake b/Modules/USUI/files.cmake index fb6be5c93c..0747fcff17 100644 --- a/Modules/USUI/files.cmake +++ b/Modules/USUI/files.cmake @@ -1,22 +1,19 @@ set(CPP_FILES Qmitk/QmitkUSDeviceManagerWidget.cpp Qmitk/QmitkUSNewVideoDeviceWidget.cpp - Qmitk/QmitkUSDeviceListWidget.cpp ) set(UI_FILES - Qmitk/QmitkUSDeviceListWidgetControls.ui Qmitk/QmitkUSDeviceManagerWidgetControls.ui Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui ) set(MOC_H_FILES Qmitk/QmitkUSDeviceManagerWidget.h - Qmitk/QmitkUSDeviceListWidget.h Qmitk/QmitkUSNewVideoDeviceWidget.h ) # uncomment the following line if you want to use Qt resources set(QRC_FILES # resources/QmitkToFUtilWidget.qrc ) 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..a710e48114 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); + std::string filter = "(" + mitk::USDevice::US_PROPKEY_ISACTIVE + "=true)"; + m_Controls.m_ActiveVideoDevices->Initialize(mitk::USDevice::US_PROPKEY_LABEL ,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