Salome HOME
Copyright update 2020
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationMeshView.cxx
1 // Copyright (C) 2016-2020  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 #include "MEDFactoryClient.hxx"
22
23 #include <SALOME_KernelServices.hxx>
24 #undef LOG  // should be fixed in KERNEL - double definition
25 #include <Basics_Utils.hxx>
26
27 #include <sstream>
28
29 const std::string MEDPresentationMeshView::TYPE_NAME = "MEDPresentationMeshView";
30 const std::string MEDPresentationMeshView::PROP_MESH_MODE = "meshMode";
31
32 MEDPresentationMeshView::MEDPresentationMeshView(const MEDCALC::MeshViewParameters& params,
33                                                const MEDCALC::ViewModeType viewMode) :
34         // Cheating a bit here - a mesh view doesn't need a color map or a range:
35         MEDPresentation(params.meshHandlerId, TYPE_NAME, viewMode, MEDCALC::COLOR_MAP_DEFAULT,
36                         MEDCALC::SCALAR_BAR_RANGE_DEFAULT),
37         _params(params)
38 {
39   setIntProperty(MEDPresentationMeshView::PROP_MESH_MODE, params.mode);
40 }
41
42 void
43 MEDPresentationMeshView::initFieldMeshInfos()
44 {
45   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
46   MEDCALC::MeshHandler* meshHandler = dataManager->getMeshHandler(_handlerId);
47   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
48
49   extractFileName(std::string(dataSHandler->uri));
50
51   _meshName = meshHandler->name;
52 }
53
54 void
55 MEDPresentationMeshView::representationType()
56 {
57   std::ostringstream oss1;
58
59   switch (_params.mode)
60   {
61     case MEDCALC::MESH_MODE_WIREFRAME:
62       oss1 << _dispVar << ".SetRepresentationType('Wireframe');";
63       break;
64     case MEDCALC::MESH_MODE_SURFACE_EDGES:
65       oss1 << _dispVar << ".SetRepresentationType('Surface With Edges');";
66       break;
67     case MEDCALC::MESH_MODE_SURFACE:
68       oss1 << _dispVar << ".SetRepresentationType('Surface');";
69       break;
70     default:
71       const char * mes = "Unexpected getMeshViewCommand error!";
72       STDLOG(mes);
73       throw KERNEL::createSalomeException(mes);
74   }
75   pushAndExecPyLine(oss1.str());
76 }
77
78 void
79 MEDPresentationMeshView::internalGeneratePipeline()
80 {
81   MEDPresentation::internalGeneratePipeline();
82
83   MEDPyLockWrapper lock;
84
85   createSource();
86   setOrCreateRenderView();
87
88   std::ostringstream oss;
89   oss << _objVar << " = " << _srcObjVar << ";";
90   pushAndExecPyLine(oss.str()); oss.str("");
91
92   recreateViewSetup();
93 }
94
95 void
96 MEDPresentationMeshView::recreateViewSetup()
97 {
98   showObject();
99   representationType();
100   resetCameraAndRender();
101 }
102
103 void
104 MEDPresentationMeshView::updatePipeline(const MEDCALC::MeshViewParameters& params)
105 {
106   if (params.meshHandlerId != _params.meshHandlerId)
107     throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching meshHandlerId!");
108
109   if (params.mode != _params.mode)
110     updateMeshMode(params.mode);
111 }
112
113 void
114 MEDPresentationMeshView::updateMeshMode(const MEDCALC::MeshModeType mode)
115 {
116   _params.mode = mode;
117
118   // GUI helper:
119   setIntProperty(MEDPresentationMeshView::PROP_MESH_MODE, mode);
120
121   // Update the pipeline:
122   {
123     MEDPyLockWrapper lock;
124     representationType();
125     pushAndExecPyLine("pvs.Render();");
126   }
127 }