Salome HOME
Merge branch 'abn/configuration'
[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 void
42 MEDPresentationMeshView::representationType()
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   pushAndExecPyLine(oss1.str());
63 }
64
65 void
66 MEDPresentationMeshView::internalGeneratePipeline()
67 {
68   MEDPresentation::internalGeneratePipeline();
69
70   MEDPyLockWrapper lock;
71
72   createSource();
73   setOrCreateRenderView();
74
75   std::ostringstream oss;
76   oss << _objVar << " = " << _srcObjVar << ";";
77   pushAndExecPyLine(oss.str()); oss.str("");
78
79   showObject();
80   representationType();
81   resetCameraAndRender();
82 }
83
84 void
85 MEDPresentationMeshView::updatePipeline(const MEDCALC::MeshViewParameters& params)
86 {
87   if (params.fieldHandlerId != _params.fieldHandlerId)
88     throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
89
90   if (params.mode != _params.mode)
91     updateMeshMode(params.mode);
92 }
93
94 void
95 MEDPresentationMeshView::updateMeshMode(const MEDCALC::MeshModeType mode)
96 {
97   _params.mode = mode;
98
99   // GUI helper:
100   setIntProperty(MEDPresentationMeshView::PROP_MESH_MODE, mode);
101
102   // Update the pipeline:
103   {
104     MEDPyLockWrapper lock;
105     representationType();
106     pushAndExecPyLine("pvs.Render();");
107   }
108 }