1 // Copyright (C) 2021-2024 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : MEDCALCGUI_Displayer.cxx
21 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
24 #include "PresentationController.hxx"
25 #include "MEDCALCGUI_Displayer.hxx"
26 #include <MEDCalcConstants.hxx>
27 #include <MEDFactoryClient.hxx>
30 #include <Basics_Utils.hxx>
31 #include <SALOME_KernelServices.hxx>
32 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
33 #include <SALOMEDSImpl_AttributeParameter.hxx>
36 #include <PVViewer_ViewModel.h>
39 MEDCALCGUI_Displayer::MEDCALCGUI_Displayer(PresentationController* presentationController):
41 _presentationController(presentationController)
44 MEDCALCGUI_Displayer::~MEDCALCGUI_Displayer()
46 _presentationController = nullptr;
49 void MEDCALCGUI_Displayer::Display(const QStringList& list, const bool /*val*/, SALOME_View* /*theView*/)
51 STDLOG("MEDCALCGUI_Displayer::Display");
52 changeVisibility(list, true);
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);
60 bool MEDCALCGUI_Displayer::canBeDisplayed(const QString& entry, const QString& viewer_type) const {
62 if (viewer_type != PVViewer_Viewer::Type())
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);
70 bool MEDCALCGUI_Displayer::IsDisplayed(const QString& entry, SALOME_View* /*view*/) const
72 return (visibilityState(entry) == MEDCALC::PRESENTATION_VISIBLE);
75 void MEDCALCGUI_Displayer::changeVisibility(const QStringList& list, const bool visible)
77 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
78 if (aStudy->_is_nil())
80 QStringList::const_iterator it = list.constBegin();
81 for (; it != list.constEnd(); ++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);
105 MEDCALC::PresentationVisibility
106 MEDCALCGUI_Displayer::visibilityState(const QString& entry) const
108 MEDCALC::PresentationVisibility result = MEDCALC::PRESENTATION_NOT_IN_VIEW;
109 SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
110 if (aStudy->_is_nil())
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);
129 STDLOG("MEDCALCGUI_Displayer::state result is " << entry.toUtf8().constData() << " = " << result);