Salome HOME
[MEDCalc] Contour presentation
[modules/med.git] / src / MEDCalc / cmp / MEDPresentation.txx
1 // Copyright (C) 2016  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_TXX_
21 #define _MED_PRESENTATION_TXX_
22
23 #include "MEDPyLockWrapper.hxx"
24 #include <sstream>
25 #include <SALOME_KernelServices.hxx>
26
27 template<typename PresentationType, typename PresentationParameters>
28 void
29 MEDPresentation::updatePipeline(const PresentationParameters& params)
30 {
31   static_cast<PresentationType*>(this)->updatePipeline(params);
32 }
33
34 template<typename PresentationType, typename PresentationParameters>
35 void
36 MEDPresentation::getParameters(PresentationParameters& params) const
37 {
38   const PresentationType * p = static_cast<const PresentationType*>(this);
39   p->getParameters(params);
40 }
41
42 template<typename PresentationType, typename PresentationParameters>
43 void
44 MEDPresentation::setParameters(const PresentationParameters& params)
45 {
46   PresentationType * p = static_cast<PresentationType*>(this);
47   p->setParameters(params);
48 }
49
50
51 /**
52  * Update the ParaVis pipeline so that the given component appears on screen.
53  * Blank means "Euclidean norm"
54  * The property PROP_SELECTED_COMPONENT holding the corresponding index selected is also updated (help for the GUI).
55  */
56 template<typename PresentationType, typename PresentationParameters>
57 void
58 MEDPresentation::updateComponent(const std::string& newCompo)
59 {
60   PresentationType * p = static_cast<PresentationType*>(this);
61
62   PresentationParameters params;
63   p->getParameters(params);
64   params.displayedComponent = newCompo.c_str();
65   p->setParameters(params);
66
67
68
69   int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
70   int idx = -1;
71   for (int i=0; i < nbCompo; i++)
72     {
73       std::ostringstream oss_p;
74       oss_p << MEDPresentation::PROP_COMPONENT << i;
75       std::string compo = getStringProperty(oss_p.str());
76       if (compo == newCompo)
77         {
78           idx = i;
79           break;
80         }
81     }
82   if (idx == -1 && newCompo != "")
83     {
84       std::string msg("updateComponent(): internal error - field component not found!");
85       throw KERNEL::createSalomeException(msg.c_str());
86     }
87   setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, idx+1); // +1 because idx=0 means Euclidean norm
88   p->_selectedComponentIndex = idx;
89
90   // Update ParaView pipeline:
91   {
92     MEDPyLockWrapper lock;
93
94     std::ostringstream oss;
95     std::string cmd = getComponentSelectionCommand();
96     pushAndExecPyLine(cmd);
97     pushAndExecPyLine("pvs.Render();");
98   }
99
100 }
101
102 template<typename PresentationType, typename PresentationParameters>
103 void
104 MEDPresentation::updateColorMap(MEDCALC::MEDPresentationColorMap colorMap)
105 {
106   PresentationType * p = static_cast<PresentationType*>(this);
107
108   PresentationParameters params;
109   p->getParameters(params);
110   params.colorMap = colorMap;
111   p->setParameters(params);
112
113   p->_colorMap = colorMap;
114
115   // GUI helper:
116   setIntProperty(MEDPresentation::PROP_COLOR_MAP, colorMap);
117
118   // Update the pipeline:
119   {
120     MEDPyLockWrapper lock;
121     std::string cmd = getColorMapCommand();
122     pushAndExecPyLine(cmd);
123     pushAndExecPyLine("pvs.Render();");
124   }
125 }
126
127 template<typename PresentationType, typename PresentationParameters>
128 void
129 MEDPresentation::updateScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbRange)
130 {
131   PresentationType * p = static_cast<PresentationType*>(this);
132
133   PresentationParameters params;
134   p->getParameters(params);
135   params.scalarBarRange = sbRange;
136   p->setParameters(params);
137
138   p->_sbRange = sbRange;
139
140   // GUI helper:
141   setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, sbRange);
142
143   // Update the pipeline:
144   {
145     MEDPyLockWrapper lock;
146     std::string cmd = getRescaleCommand();
147     pushAndExecPyLine(cmd);
148     pushAndExecPyLine("pvs.Render();");
149   }
150 }
151
152
153 #endif // _MED_PRESENTATION_TXX_