17#include <usServiceReference.h>
18#include <usModuleContext.h>
19#include <usGetModuleContext.h>
20#include <usModuleContext.h>
32 us::ModuleContext* context = us::GetModuleContext();
34 this->LoadStoredDevices();
37 std::string filterExcludeCombinedModalities =
"(&(" + us::ServiceConstants::OBJECTCLASS() +
"="
40 context->AddServiceListener(
this, &mitk::USNavigationCombinedModalityPersistence::OnServiceEvent,
41 filterExcludeCombinedModalities);
44 context->AddServiceListener(
this, &mitk::USNavigationCombinedModalityPersistence::OnServiceEvent,
45 "(" + us::ServiceConstants::OBJECTCLASS() +
"=" + us_service_interface_iid<mitk::NavigationDataSource>() +
")");
53void mitk::USNavigationCombinedModalityPersistence::OnServiceEvent(
const us::ServiceEvent event)
55 if ( event.GetType() == event.REGISTERED )
61void mitk::USNavigationCombinedModalityPersistence::StoreCurrentDevices()
63 QList<QVariant> devices;
65 us::ModuleContext* context = us::GetModuleContext();
69 std::vector<us::ServiceReference<USDevice> > services = context->GetServiceReferences<USDevice>(filterOnlyCombinedModalities);
71 for ( std::vector<us::ServiceReference<USDevice> >::iterator it = services.begin();
72 it != services.end(); ++it )
74 QStringList deviceStrings;
76 if ( currentDevice.IsNotNull() )
79 deviceStrings.push_back(QString::fromStdString(currentDevice->GetUltrasoundDevice()->GetManufacturer()));
80 deviceStrings.push_back(QString::fromStdString(currentDevice->GetUltrasoundDevice()->GetName()));
83 mitk::NavigationDataSource::Pointer navigationDataSource = currentDevice->GetNavigationDataSource();
84 if ( currentDevice.IsNull() ) {
continue; }
85 deviceStrings.push_back(QString::fromStdString(navigationDataSource->GetName()));
88 mitk::USDevice::Pointer ultrasoundDevice = currentDevice->GetUltrasoundDevice();
89 if ( ultrasoundDevice.IsNull() ) {
continue; }
90 deviceStrings.push_back(QString::fromStdString(ultrasoundDevice->GetManufacturer()));
91 deviceStrings.push_back(QString::fromStdString(ultrasoundDevice->GetName()));
92 deviceStrings.push_back(QString::fromStdString(ultrasoundDevice->GetComment()));
95 deviceStrings.push_back(QString::fromStdString(currentDevice->SerializeCalibration()));
98 devices.push_back(deviceStrings);
103 settings.setValue(
"combined-modalities", devices);
106void mitk::USNavigationCombinedModalityPersistence::LoadStoredDevices()
110 QList<QVariant> devices = settings.value(
"combined-modalities").value< QList<QVariant> >();
112 for ( QList<QVariant>::iterator it = devices.begin();
113 it != devices.end(); ++it )
117 QStringList stringList = it->toStringList();
120 if (stringList.size() >= 7 && this->GetCombinedModality(stringList.at(0).toStdString(), stringList.at(1).toStdString()).IsNull())
123 mitk::NavigationDataSource::Pointer navigationDataSource = this->GetNavigationDataSource(stringList.at(2).toStdString());
124 mitk::USDevice::Pointer usDevice = this->GetUSDevice(stringList.at(3).toStdString(), stringList.at(4).toStdString(), stringList.at(5).toStdString());
128 if ( navigationDataSource.IsNotNull() && usDevice.IsNotNull() )
130 mitk::USCombinedModality::Pointer combinedModality = mitk::USCombinedModality::New(usDevice, navigationDataSource,
false);
131 combinedModality->DeserializeCalibration(stringList.at(6).toStdString());
132 combinedModality->GetUltrasoundDevice()->Initialize();
138mitk::USCombinedModality::Pointer mitk::USNavigationCombinedModalityPersistence::GetCombinedModality(std::string manufacturer, std::string model)
140 us::ModuleContext* context = us::GetModuleContext();
142 std::string filterOnlyCombinedModalities =
"(&(" + us::ServiceConstants::OBJECTCLASS() +
"="
145 std::vector<us::ServiceReference<USDevice> > services = context->GetServiceReferences<USDevice>(filterOnlyCombinedModalities);
147 for ( std::vector<us::ServiceReference<USDevice> >::iterator it = services.begin();
148 it != services.end(); ++it )
150 mitk::USCombinedModality::Pointer currentDevice =
dynamic_cast<mitk::USCombinedModality*
>(context->GetService(*it));
151 if ( currentDevice.IsNotNull() )
153 if ( currentDevice->GetUltrasoundDevice()->GetManufacturer() == manufacturer && currentDevice->GetUltrasoundDevice()->GetName() == model )
155 return currentDevice;
163mitk::USDevice::Pointer mitk::USNavigationCombinedModalityPersistence::GetUSDevice(std::string manufacturer, std::string model, std::string comment)
165 us::ModuleContext* context = us::GetModuleContext();
167 std::string filterExcludeCombinedModalities =
"(&(" + us::ServiceConstants::OBJECTCLASS() +
"="
170 std::vector<us::ServiceReference<USDevice> > services = context->GetServiceReferences<USDevice>(filterExcludeCombinedModalities);
172 for ( std::vector<us::ServiceReference<USDevice> >::iterator it = services.begin();
173 it != services.end(); ++it )
175 mitk::USDevice::Pointer currentDevice =
dynamic_cast<mitk::USDevice*
>(context->GetService(*it));
176 if ( currentDevice.IsNotNull() )
178 if ( currentDevice->GetManufacturer() == manufacturer && currentDevice->GetName() == model
179 && currentDevice->GetComment() == comment )
181 return currentDevice;
189mitk::NavigationDataSource::Pointer mitk::USNavigationCombinedModalityPersistence::GetNavigationDataSource(std::string name)
191 us::ModuleContext* context = us::GetModuleContext();
193 std::vector<us::ServiceReference<mitk::NavigationDataSource> > services = context->GetServiceReferences<
mitk::NavigationDataSource>();
195 for ( std::vector<us::ServiceReference<mitk::NavigationDataSource> >::iterator it = services.begin();
196 it != services.end(); ++it )
199 if ( currentDevice.IsNotNull() )
201 if ( currentDevice->GetName() == name )
203 return currentDevice;
static const std::string DeviceClassIdentifier
Combination of USDevice and NavigationDataSource. This class can be used as an ImageSource subclass....
A device holds information about it's model, make and the connected probes. It is the common super cl...
static mitk::USDevice::PropertyKeys GetPropertyKeys()
USNavigationCombinedModalityPersistence()
Restores combined modality from QSettings and registers on service events. Combined modalities are re...
~USNavigationCombinedModalityPersistence() override
The destructor stores combined modalities by calling mitk::USNavigationCombinedModalityPersistence::S...
const std::string US_PROPKEY_CLASS