1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : MEDCALCGUI_Displayer.cxx
24 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
27 #include "PresentationController.hxx"
28 #include "MEDCALCGUI_Displayer.hxx"
29 #include <MEDCalcConstants.hxx>
30 #include <MEDFactoryClient.hxx>
33 #include <Basics_Utils.hxx>
34 #include <SALOME_KernelServices.hxx>
35 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
36 #include <SALOMEDSImpl_AttributeParameter.hxx>
39 #include <PVViewer_ViewModel.h>
42 MEDCALCGUI_Displayer::MEDCALCGUI_Displayer(PresentationController* presentationController):
44 _presentationController(presentationController)
47 MEDCALCGUI_Displayer::~MEDCALCGUI_Displayer()
49 _presentationController = nullptr;
52 void MEDCALCGUI_Displayer::Display(const QStringList& list, const bool /*val*/, SALOME_View* /*theView*/)
54 STDLOG("MEDCALCGUI_Displayer::Display");
55 changeVisibility(list, true);
58 void MEDCALCGUI_Displayer::Erase(const QStringList& list, const bool forced, const bool updateViewer, SALOME_View* theView) {
59 STDLOG( "MEDCALCGUI_Displayer::Erase" );
60 changeVisibility(list, false);
63 bool MEDCALCGUI_Displayer::canBeDisplayed(const QString& entry, const QString& viewer_type) const {
65 if (viewer_type != PVViewer_Viewer::Type())
67 MEDCALC::PresentationVisibility aState = visibilityState(entry);
68 result = (aState != MEDCALC::PRESENTATION_NOT_IN_VIEW);
69 STDLOG("MEDCALCGUI_Displayer::canBeDisplayed result is " << entry.toUtf8().constData() << " = " << result);
73 bool MEDCALCGUI_Displayer::IsDisplayed(const QString& entry, SALOME_View* /*view*/) const
75 return (visibilityState(entry) == MEDCALC::PRESENTATION_VISIBLE);
78 void MEDCALCGUI_Displayer::changeVisibility(const QStringList& list, const bool visible)
80 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
81 if (aStudy->_is_nil())
83 QStringList::const_iterator it = list.constBegin();
84 for (; it != list.constEnd(); ++it)
87 SALOMEDS::SObject_var sobject = aStudy->FindObjectID(entry.toUtf8().constData());
88 SALOMEDS::GenericAttribute_var anAttr;
89 SALOMEDS::AttributeParameter_var aParam;
90 if (sobject->FindAttribute(anAttr, "AttributeParameter")) {
91 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
92 if (!aParam->_is_nil() && aParam->IsSet(PRESENTATION_ID, PT_INTEGER)) {
93 int presId = aParam->GetInt(PRESENTATION_ID);
94 if (aParam->IsSet(PRESENTATION_TYPE, PT_STRING)) {
95 std::string type = aParam->GetString(PRESENTATION_TYPE);
96 PresentationEvent* event = new PresentationEvent();
97 event->eventtype = visible ?
98 PresentationEvent::EVENT_DISPLAY_PRESENTATION : PresentationEvent::EVENT_ERASE_PRESENTATION;
99 event->presentationId = presId;
100 event->presentationType = PresentationController::presentationName2Type(type);
101 _presentationController->emitPresentationSignal(event);
108 MEDCALC::PresentationVisibility
109 MEDCALCGUI_Displayer::visibilityState(const QString& entry) const
111 MEDCALC::PresentationVisibility result = MEDCALC::PRESENTATION_NOT_IN_VIEW;
112 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
113 if (aStudy->_is_nil())
116 SALOMEDS::SObject_var sobject = aStudy->FindObjectID(entry.toUtf8().constData());
117 if (!sobject->_is_nil()) {
118 SALOMEDS::GenericAttribute_var anAttr;
119 SALOMEDS::AttributeParameter_var aParam;
120 if (sobject->FindAttribute(anAttr, "AttributeParameter")) {
121 aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
122 if (!aParam->_is_nil() && aParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)) {
123 if (aParam->IsSet(PRESENTATION_ID, PT_INTEGER)) {
124 long prsId = aParam->GetInt(PRESENTATION_ID);
125 MEDCALC::MEDPresentationManager_var presentationManager =
126 MEDFactoryClient::getFactory()->getPresentationManager();
127 result = presentationManager->stateInActiveView(prsId);
132 STDLOG("MEDCALCGUI_Displayer::state result is " << entry.toUtf8().constData() << " = " << result);