]> SALOME platform Git repositories - modules/med.git/blob - src/MEDCalc/gui/MEDCALCGUI_Displayer.cxx
Salome HOME
bos #28928: Merge branch 'rnv/28928'
[modules/med.git] / src / MEDCalc / gui / MEDCALCGUI_Displayer.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : MEDCALCGUI_Displayer.cxx
24 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
25
26 // Local includes
27 #include "PresentationController.hxx"
28 #include "MEDCALCGUI_Displayer.hxx"
29 #include <MEDCalcConstants.hxx>
30 #include <MEDFactoryClient.hxx>
31
32 // KERNEL includes
33 #include <Basics_Utils.hxx>
34 #include <SALOME_KernelServices.hxx>
35 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
36 #include <SALOMEDSImpl_AttributeParameter.hxx>
37
38 // GUI includes
39 #include <PVViewer_ViewModel.h>
40
41
42 MEDCALCGUI_Displayer::MEDCALCGUI_Displayer(PresentationController* presentationController): 
43   LightApp_Displayer(),
44   _presentationController(presentationController)
45 {
46 }
47 MEDCALCGUI_Displayer::~MEDCALCGUI_Displayer()  
48 {
49   _presentationController = nullptr;
50 }
51
52 void MEDCALCGUI_Displayer::Display(const QStringList& list, const bool /*val*/, SALOME_View* /*theView*/) 
53 {
54   STDLOG("MEDCALCGUI_Displayer::Display");
55   changeVisibility(list, true);
56 }
57
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);
61 }
62
63 bool MEDCALCGUI_Displayer::canBeDisplayed(const QString& entry, const QString& viewer_type) const {
64   bool result = false;
65   if (viewer_type != PVViewer_Viewer::Type())
66     return result;
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);
70   return result;
71 }
72
73 bool MEDCALCGUI_Displayer::IsDisplayed(const QString& entry, SALOME_View* /*view*/) const 
74 {
75   return (visibilityState(entry) == MEDCALC::PRESENTATION_VISIBLE);
76 }
77
78 void MEDCALCGUI_Displayer::changeVisibility(const QStringList& list, const bool visible)
79 {
80   SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
81   if (aStudy->_is_nil())
82     return;
83   QStringList::const_iterator it = list.constBegin();
84   for (; it != list.constEnd(); ++it)
85   {
86     QString entry = *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);
102         }
103       }
104     }
105   }
106 }
107     
108 MEDCALC::PresentationVisibility
109 MEDCALCGUI_Displayer::visibilityState(const QString& entry) const
110 {
111   MEDCALC::PresentationVisibility result = MEDCALC::PRESENTATION_NOT_IN_VIEW;
112   SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
113   if (aStudy->_is_nil())
114     return result;
115
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);
128         }
129       }
130     }
131   }
132   STDLOG("MEDCALCGUI_Displayer::state result is " << entry.toUtf8().constData() << " = " << result);
133   return result;
134 }