1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D
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 #ifndef _MED_PRESENTATION_MANAGER_I_TXX_
21 #define _MED_PRESENTATION_MANAGER_I_TXX_
23 #include <Basics_Utils.hxx>
25 template<typename PresentationType, typename PresentationParameters>
26 MEDPresentation::TypeID
27 MEDPresentationManager_i::_makePresentation(const PresentationParameters params, const MEDCALC::ViewModeType viewMode)
29 int activeViewId = getActiveViewPythonId();
31 // Replace = Remove then add
32 std::vector<int> to_del;
33 if (viewMode == MEDCALC::VIEW_MODE_REPLACE)
35 // Prepare all presentations to be removed from this view:
36 std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
37 for (it = _presentations.begin(); it != _presentations.end(); ++it)
39 int viewId2 = (*it).second->getPyViewID();
40 if (viewId2 == activeViewId)
41 to_del.push_back((*it).first);
45 // Create a new presentation instance
46 PresentationType* presentation = NULL;
47 MEDPresentation::TypeID newID = MEDPresentationManager_i::GenerateID();
48 STDLOG("Generated presentation ID: " << newID);
50 presentation = new PresentationType(params, viewMode); // on stack or on heap?? heap for now
51 presentation->initFieldMeshInfos();
52 // In replace or overlap mode we force the display in the active view:
53 if(activeViewId != -1 && (viewMode == MEDCALC::VIEW_MODE_REPLACE || viewMode == MEDCALC::VIEW_MODE_OVERLAP))
54 presentation->setPyViewID(activeViewId);
56 presentation->setPyViewID(newID); // ensures a new ID for the view
58 catch (const std::exception& e) {
59 std::cerr << e.what() << std::endl;
60 STDLOG("Error: " << e.what());
64 STDLOG("Add new presentation " << newID);
65 _presentations.insert( std::pair<MEDPresentation::TypeID, MEDPresentation *>(newID, presentation) );
66 presentation->generatePipeline();
68 // If generatePipeline didn't throw, we can actually remove presentations to be deleted:
69 STDLOG("About to remove all presentations from view " << activeViewId);
70 for (std::vector<int>::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2)
71 removePresentation(*it2);
73 // Make the view holding the newly created presentation the active one:
78 template<typename PresentationType, typename PresentationParameters>
80 MEDPresentationManager_i::_updatePresentation(MEDPresentation::TypeID presentationID, const PresentationParameters params)
82 STDLOG("Update presentation " << presentationID);
83 MEDPresentation* presentation = _getPresentation(presentationID);
85 std::cerr << "_updatePresentation(): presentation not found!!" << std::endl;
89 presentation->updatePipeline<PresentationType>(params);
92 template<typename PresentationType, typename PresentationParameters>
94 MEDPresentationManager_i::_getParameters(MEDPresentation::TypeID presentationID, PresentationParameters & params) const
96 MEDPresentation* presentation = _getPresentation(presentationID);
98 std::cerr << "_getParameters(): presentation not found!!" << std::endl;
102 presentation->getParameters<PresentationType>(params);
106 #endif // _MED_PRESENTATION_MANAGER_I_TXX_