diff --git a/Modules/US/USModel/mitkUSDevice.cpp b/Modules/US/USModel/mitkUSDevice.cpp index 75ede32636..b674017d99 100644 --- a/Modules/US/USModel/mitkUSDevice.cpp +++ b/Modules/US/USModel/mitkUSDevice.cpp @@ -1,260 +1,271 @@ /*=================================================================== 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" mitk::USDevice::USDevice(std::string manufacturer, std::string model, bool isVideoOnly) : mitk::ImageSource() { // Initialize Members m_Metadata = mitk::USImageMetadata::New(); m_Metadata->SetDeviceManufacturer(manufacturer); m_Metadata->SetDeviceModel(model); m_Metadata->SetDeviceIsVideoOnly(isVideoOnly); 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, bool isVideoOnly) : mitk::ImageSource() { m_Metadata = metadata; 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() { } bool mitk::USDevice::Connect() { //TODO Throw Exception is already activated before connection // Prepare connection, fail if this fails. if (! this->OnConnection()) return false; // Get Context and Module mitk::ModuleContext* context = GetModuleContext(); // Define ServiceProps ServiceProperties props; props["DeviceClass"] = this->GetDeviceClass(); props["IsActive"] = false; props["Class"] = this->GetClassName(); m_ServiceRegistration = context->RegisterService(this, props); return true; } bool mitk::USDevice::OnConnection() { return true; // TODO: Make Abstract } bool mitk::USDevice::Disconnect() { // Prepare connection, fail if this fails. if (! this->OnDisconnection()) return false; // Unregister m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; return true; } bool mitk::USDevice::OnDisconnection() { return true; // TODO Make Abstract } bool mitk::USDevice::Activate() { if (! this->GetIsConnected()) return false; m_IsActive = OnActivation(); + ServiceProperties props; + props["DeviceClass"] = this->GetDeviceClass(); + props["IsActive"] = true; + props["Class"] = this->GetClassName(); + this->m_ServiceRegistration.SetProperties(props); return m_IsActive; } void mitk::USDevice::Deactivate() { m_IsActive= false; + + ServiceProperties props; + props["DeviceClass"] = this->GetDeviceClass(); + props["IsActive"] = false; + props["Class"] = this->GetClassName(); + this->m_ServiceRegistration.SetProperties(props); OnDeactivation(); } bool mitk::USDevice::OnActivation() { return true; // TODO Make Abstract } void mitk::USDevice::OnDeactivation() { // TODO Make Abstract } std::string mitk::USDevice::GetDeviceClass() { return "org.mitk.Ultrasound.GenericDevice"; } 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 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()); } //########### GETTER & SETTER ##################// bool mitk::USDevice::GetIsActive() { return m_IsActive; } bool mitk::USDevice::GetIsConnected() { // a device is connected if it is registered with the service 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(); } bool mitk::USDevice::GetIsVideoOnly(){ return this->m_Metadata->GetDeviceIsVideoOnly(); } std::vector mitk::USDevice::GetConnectedProbes() { return m_ConnectedProbes; } diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp index 35aa1b31f0..64fbc1df1a 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp @@ -1,173 +1,174 @@ /*=================================================================== 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)"; 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()) ); } } ///////////// Methods & Slots Handling Direct Interaction ///////////////// void QmitkUSDeviceManagerWidget::OnClickedActivateDevice(){ MITK_INFO << "Activated Device"; mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); device->Activate(); } void QmitkUSDeviceManagerWidget::OnClickedDisconnectDevice(){ MITK_INFO << "Disconnected Device"; mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); device->Disconnect(); } ///////////////// 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; } //mitk::ServiceTracker QmitkUSDeviceManagerWidget::ConstructServiceTracker(){ //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/QmitkUSNewVideoDeviceWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui index 37174e6df2..08f540f348 100644 --- a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui @@ -1,169 +1,173 @@ QmitkUSNewVideoDeviceWidgetControls 0 0 405 404 0 0 QmitkUSNewVideoDeviceWidget Metadata 50 false true Device Information: Manufacturer Model Comment true Probe Information: Probe Zoom GroupBox - + + + C://Builds//MITK-superbuild//CMakeExternals//Source//MITK-Data//CommonTestData//bunny_320x240.avi + + -1 10 -1 From Device: true From File: Add Device Cancel