15 #include <ctkPluginContext.h>
16 #include <vtkRenderWindow.h>
17 #include <vtkRenderWindowInteractor.h>
67 void ViewImplService::init()
82 connect(
settings(), SIGNAL(valueChangedFor(QString)),
this, SLOT(settingsChangedSlot(QString)));
84 const unsigned VIEW_GROUP_COUNT = 5;
86 for (
unsigned i = 0; i < VIEW_GROUP_COUNT; ++i)
89 mViewGroups.push_back(group);
93 mCameraStyleInteractor.reset(
new CameraStyleInteractor);
95 mActiveLayout = QStringList() <<
"" <<
"";
98 mInteractiveCropper.reset(
new InteractiveCropper(
mServices->patient()->getActiveData()));
99 connect(
this, SIGNAL(
activeViewChanged()),
this, SLOT(updateCameraStyleActions()));
101 this->loadGlobalSettings();
104 this->initializeGlobal2DZoom();
105 this->initializeActiveView();
114 std::vector<ViewGroupPtr> ViewImplService::getViewGroups()
135 void ViewImplService::initializeGlobal2DZoom()
139 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
140 mViewGroups[i]->getData()->initializeGlobal2DZoom(mGlobal2DZoomVal);
143 void ViewImplService::initializeActiveView()
146 connect(mActiveView.get(), SIGNAL(changed()),
this, SIGNAL(
activeViewChanged()));
148 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
149 mViewGroups[i]->initializeActiveView(mActiveView);
155 mCameraControl->refreshView(this->
get3DView(group));
173 bool optimizedViews =
settings()->
value(
"optimizedViews").toBool();
206 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
208 mViewGroups[i]->removeViews();
211 this->setActiveView(
"");
212 mSlicePlanesProxy->clearViewports();
215 mActiveLayout[0] =
"";
219 void ViewImplService::updateViews()
221 for(
unsigned i=0; i<mViewGroups.size(); ++i)
224 for (
unsigned j=0; j<group->getWrappers().size(); ++j)
225 group->getWrappers()[j]->updateView();
229 void ViewImplService::settingsChangedSlot(QString key)
231 if (key ==
"smartRender")
235 if (key ==
"renderingInterval")
239 if (key ==
"renderSpeedLogging")
247 return mInteractiveCropper;
252 CX_ASSERT(mActiveLayout.size() > widgetIndex);
253 return mActiveLayout[widgetIndex];
256 QString ViewImplService::getActiveView()
const
258 return mActiveView->get().value<QString>();
261 void ViewImplService::setActiveView(QString uid)
263 mActiveView->set(uid);
269 QString activeView = mActiveView->value<QString>();
271 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
273 ViewWrapperPtr viewWrapper = mViewGroups[i]->getViewWrapperFromViewUid(activeView);
281 void ViewImplService::addXml(QDomNode& parentNode)
286 base.addTextToElement(
"global2DZoom",
qstring_cast(mGlobal2DZoomVal->get().toDouble()));
288 QDomElement slicePlanes3DNode = base.addElement(
"slicePlanes3D");
289 slicePlanes3DNode.setAttribute(
"use", mSlicePlanesProxy->getVisible());
290 slicePlanes3DNode.setAttribute(
"opaque", mSlicePlanesProxy->getDrawPlanes());
292 XMLNodeAdder viewGroupsNode(base.addElement(
"viewGroups"));
293 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
295 QDomElement viewGroupNode = viewGroupsNode.addElement(
"viewGroup");
296 viewGroupNode.setAttribute(
"index", i);
297 mViewGroups[i]->addXml(viewGroupNode);
301 void ViewImplService::parseXml(QDomNode viewmanagerNode)
303 XMLNodeParser base(viewmanagerNode);
305 QString clippedImage = base.parseTextFromElement(
"clippedImage");
307 base.parseDoubleFromElementWithDefault(
"global2DZoom", mGlobal2DZoomVal->get().toDouble());
309 QDomElement slicePlanes3DNode = base.parseElement(
"slicePlanes3D");
310 mSlicePlanesProxy->setVisible(slicePlanes3DNode.attribute(
"use").toInt());
311 mSlicePlanesProxy->setDrawPlanes(slicePlanes3DNode.attribute(
"opaque").toInt());
313 QDomElement viewgroups = base.parseElement(
"viewGroups");
314 QDomNode viewgroup = viewgroups.firstChild();
315 while (!viewgroup.isNull())
317 if (viewgroup.toElement().tagName() !=
"viewGroup")
319 viewgroup = viewgroup.nextSibling();
322 int index = viewgroup.toElement().attribute(
"index").toInt();
324 if (index < 0 || index >=
int(mViewGroups.size()))
326 viewgroup = viewgroup.nextSibling();
330 mViewGroups[index]->parseXml(viewgroup);
332 viewgroup = viewgroup.nextSibling();
336 void ViewImplService::clear()
338 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
340 mViewGroups[i]->clearPatientData();
349 std::vector<ViewPtr> views = mViewGroups[group]->getViews();
350 for (
unsigned i = 0; i < views.size(); ++i)
356 if (index == count++)
365 void ViewImplService::deactivateCurrentLayout()
373 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
375 mViewGroups[i]->removeViews();
378 this->setActiveView(
"");
379 mSlicePlanesProxy->clearViewports();
384 if (( groupIdx>=0 )&&( groupIdx < mViewGroups.size() ))
385 return mViewGroups[groupIdx]->getData();
389 unsigned ViewImplService::viewGroupCount()
const
401 if(!mLayoutRepository->exists(layout))
404 CX_ASSERT(mActiveLayout.size() > widgetIndex);
406 if (mActiveLayout[widgetIndex] == layout)
409 mActiveLayout[widgetIndex] = layout;
413 if (!mViewGroups[0]->getViews().empty())
414 this->setActiveView(mViewGroups[0]->getViews()[0]->getUid());
418 QString layoutName = mLayoutRepository->get(layout).getName();
419 report(QString(
"Layout %1 changed to %2").arg(widgetIndex).arg(layoutName));
424 this->deactivateCurrentLayout();
428 LayoutData next = mLayoutRepository->get(mActiveLayout[i]);
433 this->setSlicePlanesProxyInViewsUpTo2DViewgroup();
435 mCameraControl->refreshView(this->
get3DView());
438 void ViewImplService::setSlicePlanesProxyInViewsUpTo2DViewgroup()
443 for (
unsigned i = 0; i < mViewGroups.size(); ++i)
445 bool foundSlice =
false;
446 std::vector<ViewWrapperPtr> wrappers = mViewGroups[i]->getWrappers();
447 for (
unsigned j = 0; j < wrappers.size(); ++j)
449 wrappers[j]->setSlicePlanesProxy(mSlicePlanesProxy);
450 foundSlice = foundSlice || wrappers[j]->getView()->getType() ==
View::VIEW_2D;
456 void ViewImplService::activateViews(ViewCollectionWidget *widget, LayoutData next)
461 widget->setOffScreenRenderingAndClear(next.getOffScreenRendering());
464 this->activateView(widget, *iter);
467 void ViewImplService::setRenderingInterval(
int interval)
472 void ViewImplService::activateView(ViewCollectionWidget* widget, LayoutViewData viewData)
474 if (!viewData.isValid())
477 ViewPtr view = widget->addView(viewData.mType, viewData.mRegion);
482 interactor->EnableRenderOff();
484 double rate =
settings()->
value(
"stillUpdateRate").value<
double>();
485 interactor->SetStillUpdateRate(rate);
488 interactor->SetDesiredUpdateRate(rate);
492 CX_LOG_WARNING() <<
"ViewImplService::activateView: got not shared OpenGL context";
501 wrapper->initializePlane(viewData.mPlane);
509 if (viewData.mGroup == 0)
510 mInteractiveCropper->setView(view);
528 return mLayoutRepository;
531 void ViewImplService::onLayoutRepositoryChanged(QString uid)
533 this->saveGlobalSettings();
535 bool activeChange = mActiveLayout[0] == uid;
538 mActiveLayout[0] =
"";
543 void ViewImplService::loadGlobalSettings()
545 XmlOptionFile file =
profile()->getXmlSettings().descend(
"viewmanager");
546 mLayoutRepository->load(file);
549 void ViewImplService::saveGlobalSettings()
551 XmlOptionFile file =
profile()->getXmlSettings().descend(
"viewmanager");
552 mLayoutRepository->save(file);
558 return mCameraStyleInteractor->getInteractorStyleActionGroup();
561 void ViewImplService::updateCameraStyleActions()
564 int index = this->findGroupContaining3DViewGivenGuess(active);
573 mCameraStyleInteractor->connectCameraStyle(group->getData());
574 mCameraControl->setView(this->
get3DView(index, 0));
580 int ViewImplService::findGroupContaining3DViewGivenGuess(
int preferredGroup)
582 if (preferredGroup>=0)
583 if (mViewGroups[preferredGroup]->contains3DView())
584 return preferredGroup;
586 for (
unsigned i=0; i<mViewGroups.size(); ++i)
587 if (mViewGroups[i]->contains3DView())
594 if (
settings()->value(
"Automation/autoShowNewData").toBool() && data)
596 this->autoShowInViewGroups(data);
597 this->autoResetCameraToSuperiorView();
598 this->autoCenterToImageCenter();
604 void ViewImplService::autoShowInViewGroups(
DataPtr data)
607 foreach (
unsigned i, showInViewGroups)
608 this->getViewGroups()[i]->getData()->addDataSorted(data->getUid());
613 QList<unsigned> showInViewGroups;
614 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup0").toBool())
615 showInViewGroups << 0;
616 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup1").toBool())
617 showInViewGroups << 1;
618 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup2").toBool())
619 showInViewGroups << 2;
620 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup3").toBool())
621 showInViewGroups << 3;
622 if(
settings()->value(
"Automation/autoShowNewDataInViewGroup4").toBool())
623 showInViewGroups << 4;
624 return showInViewGroups;
627 void ViewImplService::autoResetCameraToSuperiorView()
629 if(
settings()->value(
"Automation/autoResetCameraToSuperiorViewWhenAutoShowingNewData").toBool())
631 for (
unsigned i=0; i<mViewGroups.size(); ++i)
632 if (mViewGroups[i]->contains3DView())
634 mCameraControl->setView(this->
get3DView(i));
635 mCameraControl->setSuperiorView();
640 void ViewImplService::autoCenterToImageCenter()
642 if(
settings()->value(
"Automation/autoCenterToImageCenterViewWhenAutoShowingNewData").toBool())
646 foreach (
unsigned i, showInViewGroups)
647 this->centerToImageCenterInViewGroup(i);
651 void ViewImplService::centerToImageCenterInViewGroup(
unsigned groupNr)
664 if (!mViewGroups[groupIdx]->getViews().empty())
665 this->setActiveView(mViewGroups[groupIdx]->getViews()[0]->getUid());
668 for(
int i = 0; i < actions.size(); ++i)
670 if (actions[i]->data().toString() ==
enum2string(style))
671 actions[i]->trigger();
681 viewGroup3D->zoomCamera3D(zoomFactor);
686 mLayoutRepository->addDefault(layoutData);
701 this->
getGroup(0)->setRegistrationMode(mode);
716 return this->mClippers;
724 void ViewImplService::onSessionChanged()
727 void ViewImplService::onSessionCleared()
733 void ViewImplService::onSessionLoad(QDomElement& node)
735 XMLNodeParser root(node);
736 QDomElement viewManagerNode = root.descend(
"managers/viewManager").node().toElement();
737 if (!viewManagerNode.isNull())
738 this->parseXml(viewManagerNode);
740 mClippers->parseXml(node);
742 void ViewImplService::onSessionSave(QDomElement& node)
744 XMLNodeAdder root(node);
745 QDomElement managerNode = root.descend(
"managers").node().toElement();
746 this->addXml(managerNode);
747 mClippers->addXml(node);