Salome HOME
0bc34f29ffba7e5030a9483ebf2cb1c4356c1b45
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationManager_i.txx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
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 #ifndef _MED_PRESENTATION_MANAGER_I_TXX_
21 #define _MED_PRESENTATION_MANAGER_I_TXX_
22
23 #include <Basics_Utils.hxx>
24
25 template<typename PresentationType, typename PresentationParameters>
26 MEDPresentation::TypeID
27 MEDPresentationManager_i::_makePresentation(const PresentationParameters params, const MEDCALC::ViewModeType viewMode)
28 {
29   int activeViewId = getActiveViewPythonId();
30
31   // Replace = Remove then add
32   std::vector<int> to_del;
33   if (viewMode == MEDCALC::VIEW_MODE_REPLACE)
34     {
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)
38         {
39           int viewId2 = (*it).second->getPyViewID();
40           if (viewId2 == activeViewId)
41             to_del.push_back((*it).first);
42         }
43   }
44
45   // Create a new presentation instance
46   PresentationType* presentation = NULL;
47   MEDPresentation::TypeID newID = MEDPresentationManager_i::GenerateID();
48   STDLOG("Generated presentation ID: " << newID);
49   try {
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);
55     else
56       presentation->setPyViewID(newID);  // ensures a new ID for the view
57   }
58   catch (const std::exception& e) {
59     std::cerr << e.what() << std::endl;
60     STDLOG("Error: " << e.what());
61     return -1;
62   }
63
64   STDLOG("Add new presentation " << newID);
65   _presentations.insert( std::pair<MEDPresentation::TypeID, MEDPresentation *>(newID, presentation) );
66   presentation->generatePipeline();
67
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);
72
73   // Make the view holding the newly created presentation the active one:
74   activateView(newID);
75   return newID;
76 }
77
78 template<typename PresentationType, typename PresentationParameters>
79 void
80 MEDPresentationManager_i::_updatePresentation(MEDPresentation::TypeID presentationID, const PresentationParameters params)
81 {
82   STDLOG("Update presentation " << presentationID);
83   MEDPresentation* presentation = _getPresentation(presentationID);
84   if (!presentation) {
85     std::cerr << "_updatePresentation(): presentation not found!!" << std::endl;
86     return;
87   }
88
89   presentation->updatePipeline<PresentationType>(params);
90 }
91
92 template<typename PresentationType, typename PresentationParameters>
93 void
94 MEDPresentationManager_i::_getParameters(MEDPresentation::TypeID presentationID, PresentationParameters & params) const
95 {
96   MEDPresentation* presentation = _getPresentation(presentationID);
97   if (!presentation) {
98     std::cerr << "_getParameters(): presentation not found!!" << std::endl;
99     return;
100   }
101
102   presentation->getParameters<PresentationType>(params);
103 }
104
105
106 #endif // _MED_PRESENTATION_MANAGER_I_TXX_