Salome HOME
83678f19bffd2a1b69b4aa2a7def0710ac2103d8
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationMeshView.cxx
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 #include "MEDPresentationMeshView.hxx"
21
22 #include <SALOME_KernelServices.hxx>
23 #undef LOG  // should be fixed in KERNEL - double definition
24 #include <Basics_Utils.hxx>
25
26 #include <sstream>
27
28 const std::string MEDPresentationMeshView::TYPE_NAME = "MEDPresentationMeshView";
29 const std::string MEDPresentationMeshView::PROP_MESH_MODE = "meshMode";
30
31 MEDPresentationMeshView::MEDPresentationMeshView(const MEDCALC::MeshViewParameters& params,
32                                                const MEDCALC::ViewModeType viewMode) :
33         // Cheating a bit here - a mesh view doesn't need a color map or a range:
34         MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, MEDCALC::COLOR_MAP_DEFAULT,
35                         MEDCALC::SCALAR_BAR_RANGE_DEFAULT),
36         _params(params)
37 {
38   setIntProperty(MEDPresentationMeshView::PROP_MESH_MODE, params.mode);
39 }
40
41 std::string
42 MEDPresentationMeshView::getMeshViewCommand() const
43 {
44   std::ostringstream oss1;
45
46   switch (_params.mode)
47   {
48     case MEDCALC::MESH_MODE_WIREFRAME:
49       oss1 << _dispVar << ".SetRepresentationType('Wireframe');";
50       break;
51     case MEDCALC::MESH_MODE_SURFACE_EDGES:
52       oss1 << _dispVar << ".SetRepresentationType('Surface With Edges');";
53       break;
54     case MEDCALC::MESH_MODE_SURFACE:
55       oss1 << _dispVar << ".SetRepresentationType('Surface');";
56       break;
57     default:
58       const char * mes = "Unexpected getMeshViewCommand error!";
59       STDLOG(mes);
60       throw KERNEL::createSalomeException(mes);
61   }
62
63   return oss1.str();
64 }
65
66 void
67 MEDPresentationMeshView::internalGeneratePipeline()
68 {
69   MEDPresentation::internalGeneratePipeline();
70
71   MEDPyLockWrapper lock;
72
73   std::ostringstream oss;
74   std::string view(getRenderViewVar());
75
76   oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
77   pushAndExecPyLine(oss.str()); oss.str("");
78   pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
79   oss << _objVar << " = " << _srcObjVar << ";";
80   pushAndExecPyLine(oss.str()); oss.str("");
81   oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
82   pushAndExecPyLine(oss.str()); oss.str("");
83   pushAndExecPyLine(getMeshViewCommand());
84   pushAndExecPyLine(getResetCameraCommand());
85   pushAndExecPyLine("pvs.Render();");
86 }
87
88 void
89 MEDPresentationMeshView::updatePipeline(const MEDCALC::MeshViewParameters& params)
90 {
91   if (params.fieldHandlerId != _params.fieldHandlerId)
92     throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
93
94   if (params.mode != _params.mode)
95     updateMeshMode(params.mode);
96 }
97
98 void
99 MEDPresentationMeshView::updateMeshMode(const MEDCALC::MeshModeType mode)
100 {
101   _params.mode = mode;
102
103   // GUI helper:
104   setIntProperty(MEDPresentationMeshView::PROP_MESH_MODE, mode);
105
106   // Update the pipeline:
107   {
108     MEDPyLockWrapper lock;
109     std::string cmd = getMeshViewCommand();
110     pushAndExecPyLine(cmd);
111     pushAndExecPyLine("pvs.Render();");
112   }
113 }