Salome HOME
dc99dcdc522b111732d6eebc6b84db36f3ca031e
[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  * Update the ParaVis pipeline so that the given component appears on screen.
52  * Blank means "Euclidean norm"
53  * The property PROP_SELECTED_COMPONENT holding the corresponding index selected is also updated (help for the GUI).
54  */
55 template<typename PresentationType, typename PresentationParameters>
56 void
57 MEDPresentation::updateComponent(const std::string& newCompo)
58 {
59   PresentationType * p = static_cast<PresentationType*>(this);
60
61   PresentationParameters params;
62   p->getParameters(params);
63   params.displayedComponent = newCompo.c_str();
64   p->setParameters(params);
65
66   int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
67   int idx = -1;
68   for (int i=0; i < nbCompo; i++)
69     {
70       std::ostringstream oss_p;
71       oss_p << MEDPresentation::PROP_COMPONENT << i;
72       std::string compo = getStringProperty(oss_p.str());
73       if (compo == newCompo)
74         {
75           idx = i;
76           break;
77         }
78     }
79   if (idx == -1 && newCompo != "")
80     {
81       std::string msg("updateComponent(): internal error - field component not found!");
82       throw KERNEL::createSalomeException(msg.c_str());
83     }
84   setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, idx+1); // +1 because idx=0 means Euclidean norm
85   p->_selectedComponentIndex = idx;
86
87   // Update ParaView pipeline:
88   {
89     MEDPyLockWrapper lock;
90
91     std::ostringstream oss;
92     std::string cmd = getComponentSelectionCommand();
93     pushAndExecPyLine(cmd);
94     pushAndExecPyLine("pvs.Render();");
95   }
96
97 }
98
99 template<typename PresentationType, typename PresentationParameters>
100 void
101 MEDPresentation::updateColorMap(MEDCALC::ColorMapType colorMap)
102 {
103   PresentationType * p = static_cast<PresentationType*>(this);
104
105   PresentationParameters params;
106   p->getParameters(params);
107   params.colorMap = colorMap;
108   p->setParameters(params);
109
110   p->_colorMap = colorMap;
111
112   // GUI helper:
113   setIntProperty(MEDPresentation::PROP_COLOR_MAP, colorMap);
114
115   // Update the pipeline:
116   {
117     MEDPyLockWrapper lock;
118     std::string cmd = getColorMapCommand();
119     pushAndExecPyLine(cmd);
120     pushAndExecPyLine("pvs.Render();");
121   }
122 }
123
124 template<typename PresentationType, typename PresentationParameters>
125 void
126 MEDPresentation::updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange)
127 {
128   PresentationType * p = static_cast<PresentationType*>(this);
129
130   PresentationParameters params;
131   p->getParameters(params);
132   params.scalarBarRange = sbRange;
133   p->setParameters(params);
134
135   p->_sbRange = sbRange;
136
137   // GUI helper:
138   setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, sbRange);
139
140   // Update the pipeline:
141   {
142     MEDPyLockWrapper lock;
143     std::string cmd = getRescaleCommand();
144     pushAndExecPyLine(cmd);
145     pushAndExecPyLine("pvs.Render();");
146   }
147 }
148
149
150 #endif // _MED_PRESENTATION_TXX_