Salome HOME
Updated copyright comment
[modules/med.git] / src / MEDCalc / gui / MEDCALCGUI_Displayer.cxx
1 // Copyright (C) 2021-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : MEDCALCGUI_Displayer.cxx
21 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
22
23 // Local includes
24 #include "PresentationController.hxx"
25 #include "MEDCALCGUI_Displayer.hxx"
26 #include <MEDCalcConstants.hxx>
27 #include <MEDFactoryClient.hxx>
28
29 // KERNEL includes
30 #include <Basics_Utils.hxx>
31 #include <SALOME_KernelServices.hxx>
32 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
33 #include <SALOMEDSImpl_AttributeParameter.hxx>
34
35 // GUI includes
36 #include <PVViewer_ViewModel.h>
37
38
39 MEDCALCGUI_Displayer::MEDCALCGUI_Displayer(PresentationController* presentationController): 
40   LightApp_Displayer(),
41   _presentationController(presentationController)
42 {
43 }
44 MEDCALCGUI_Displayer::~MEDCALCGUI_Displayer()  
45 {
46   _presentationController = nullptr;
47 }
48
49 void MEDCALCGUI_Displayer::Display(const QStringList& list, const bool /*val*/, SALOME_View* /*theView*/) 
50 {
51   STDLOG("MEDCALCGUI_Displayer::Display");
52   changeVisibility(list, true);
53 }
54
55 void MEDCALCGUI_Displayer::Erase(const QStringList& list, const bool forced, const bool updateViewer, SALOME_View* theView) {
56   STDLOG( "MEDCALCGUI_Displayer::Erase" );
57   changeVisibility(list, false);
58 }
59
60 bool MEDCALCGUI_Displayer::canBeDisplayed(const QString& entry, const QString& viewer_type) const {
61   bool result = false;
62   if (viewer_type != PVViewer_Viewer::Type())
63     return result;
64   MEDCALC::PresentationVisibility aState = visibilityState(entry);
65   result = (aState != MEDCALC::PRESENTATION_NOT_IN_VIEW);
66   STDLOG("MEDCALCGUI_Displayer::canBeDisplayed result is " << entry.toUtf8().constData() << " = " << result);
67   return result;
68 }
69
70 bool MEDCALCGUI_Displayer::IsDisplayed(const QString& entry, SALOME_View* /*view*/) const 
71 {
72   return (visibilityState(entry) == MEDCALC::PRESENTATION_VISIBLE);
73 }
74
75 void MEDCALCGUI_Displayer::changeVisibility(const QStringList& list, const bool visible)
76 {
77   SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
78   if (aStudy->_is_nil())
79     return;
80   QStringList::const_iterator it = list.constBegin();
81   for (; it != list.constEnd(); ++it)
82   {
83     QString entry = *it;
84     SALOMEDS::SObject_var sobject = aStudy->FindObjectID(entry.toUtf8().constData());
85     SALOMEDS::GenericAttribute_var anAttr;
86     SALOMEDS::AttributeParameter_var aParam;
87     if (sobject->FindAttribute(anAttr, "AttributeParameter")) {
88       aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
89       if (!aParam->_is_nil() && aParam->IsSet(PRESENTATION_ID, PT_INTEGER)) {
90         int presId = aParam->GetInt(PRESENTATION_ID);
91         if (aParam->IsSet(PRESENTATION_TYPE, PT_STRING)) {
92           std::string type = aParam->GetString(PRESENTATION_TYPE);
93           PresentationEvent* event = new PresentationEvent();
94           event->eventtype = visible ?
95             PresentationEvent::EVENT_DISPLAY_PRESENTATION : PresentationEvent::EVENT_ERASE_PRESENTATION;
96           event->presentationId = presId;
97           event->presentationType = PresentationController::presentationName2Type(type);
98           _presentationController->emitPresentationSignal(event);
99         }
100       }
101     }
102   }
103 }
104     
105 MEDCALC::PresentationVisibility
106 MEDCALCGUI_Displayer::visibilityState(const QString& entry) const
107 {
108   MEDCALC::PresentationVisibility result = MEDCALC::PRESENTATION_NOT_IN_VIEW;
109   SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
110   if (aStudy->_is_nil())
111     return result;
112
113   SALOMEDS::SObject_var sobject = aStudy->FindObjectID(entry.toUtf8().constData());
114   if (!sobject->_is_nil()) {
115     SALOMEDS::GenericAttribute_var anAttr;
116     SALOMEDS::AttributeParameter_var aParam;
117     if (sobject->FindAttribute(anAttr, "AttributeParameter")) {
118       aParam = SALOMEDS::AttributeParameter::_narrow(anAttr);
119       if (!aParam->_is_nil() && aParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)) {
120         if (aParam->IsSet(PRESENTATION_ID, PT_INTEGER)) {
121           long prsId = aParam->GetInt(PRESENTATION_ID);
122           MEDCALC::MEDPresentationManager_var presentationManager =
123             MEDFactoryClient::getFactory()->getPresentationManager();
124           result = presentationManager->stateInActiveView(prsId);
125         }
126       }
127     }
128   }
129   STDLOG("MEDCALCGUI_Displayer::state result is " << entry.toUtf8().constData() << " = " << result);
130   return result;
131 }