]> SALOME platform Git repositories - modules/med.git/blob - src/MEDCalc/cmp/MEDPresentationManager_i.cxx
Salome HOME
update MEDCalc APIs
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationManager_i.cxx
1 // Copyright (C) 2011-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 "MEDPresentationManager_i.hxx"
21 #include "MEDFactoryClient.hxx"
22 #include "MEDPresentation.hxx"
23 #include "MEDPresentationScalarMap.hxx"
24 #include "MEDPresentationContour.hxx"
25 #include "MEDPresentationVectorField.hxx"
26 #include "MEDPresentationSlices.hxx"
27 #include "MEDPresentationDeflectionShape.hxx"
28 #include "MEDPresentationPointSprite.hxx"
29
30 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
31
32 MEDPresentationManager_i*
33 MEDPresentationManager_i::getInstance() {
34   if ( _instance == NULL )
35     _instance = new MEDPresentationManager_i();
36   return _instance;
37 }
38
39 MEDPresentationManager_i::MEDPresentationManager_i()
40 {
41 }
42
43 MEDPresentationManager_i::~MEDPresentationManager_i()
44 {
45   /*
46   std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
47   for ( ; itr != this->_presentations.end(); ++itr) {
48     delete *itr;
49     *itr = NULL;
50   }
51   this->_presentations.clear();
52   */
53 }
54
55 TypeID MEDPresentationManager_i::GenerateID()
56 {
57   static TypeID START_ID = -1;
58   START_ID++;
59   return START_ID;
60 }
61
62 #include <iostream>
63
64 void
65 MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue)
66 {
67   if (_presentations.find(presentationID) != _presentations.end())
68     {
69       MEDPresentation * pres(_presentations[presentationID]);
70       pres->setProperty(propName, propValue);
71     }
72   else
73     {
74       std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
75     }
76 }
77
78 char*
79 MEDPresentationManager_i::getPresentationProperty(TypeID presentationID, const char* propName)
80 {
81   if (_presentations.find(presentationID) != _presentations.end()) {
82     MEDPresentation* pres = _presentations[presentationID];
83     return (char*) pres->getProperty(propName).c_str();
84   }
85   else {
86     std::cerr << "getPresentationProperty(): presentation not found!!" << std::endl;
87     return (char*) "";
88   }
89 }
90
91 TypeID
92 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params)
93 {
94   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
95
96   TypeID fieldHandlerId = params.fieldHandlerId;
97   MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
98
99   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
100   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
101   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
102
103   std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
104   std::cout << "\tviewMode: " << viewMode << std::endl;
105   std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
106   std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
107
108   // Create a new presentation instance
109   TypeID newID = MEDPresentationManager_i::GenerateID();
110   MEDPresentationScalarMap * presentation = new MEDPresentationScalarMap(fieldHandler, true);  // on stack or on heap?? stack for now
111   _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
112
113   presentation->generatePipeline();
114
115   return newID;
116 }
117
118 TypeID
119 MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params)
120 {
121   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
122
123   TypeID fieldHandlerId = params.fieldHandlerId;
124   MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
125
126   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
127   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
128   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
129
130   std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
131   std::cout << "\tviewMode: " << viewMode << std::endl;
132   std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
133   std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
134
135   // Create a new presentation instance
136   TypeID newID = MEDPresentationManager_i::GenerateID();
137   MEDPresentationContour * presentation = new MEDPresentationContour(fieldHandler, true);  // on stack or on heap?? stack for now
138   _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
139
140   presentation->generatePipeline();
141
142   return newID;
143 }
144
145 TypeID
146 MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
147 {
148   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
149
150   TypeID fieldHandlerId = params.fieldHandlerId;
151   MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
152
153   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
154   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
155   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
156
157   std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
158   std::cout << "\tviewMode: " << viewMode << std::endl;
159   std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
160   std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
161
162   // Create a new presentation instance
163   TypeID newID = MEDPresentationManager_i::GenerateID();
164   MEDPresentationVectorField * presentation = new MEDPresentationVectorField(fieldHandler, true);  // on stack or on heap?? stack for now
165   _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
166
167   presentation->generatePipeline();
168
169   return newID;
170 }
171
172 TypeID
173 MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params)
174 {
175   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
176
177   TypeID fieldHandlerId = params.fieldHandlerId;
178   MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
179
180   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
181   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
182   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
183
184   std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
185   std::cout << "\tviewMode: " << viewMode << std::endl;
186   std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
187   std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
188
189   // Create a new presentation instance
190   TypeID newID = MEDPresentationManager_i::GenerateID();
191   MEDPresentationSlices * presentation = new MEDPresentationSlices(fieldHandler, true);  // on stack or on heap?? stack for now
192   _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
193
194   presentation->generatePipeline();
195
196   return newID;
197 }
198
199 TypeID
200 MEDPresentationManager_i::makeDeflectionShape(const MEDCALC::DeflectionShapeParameters& params)
201 {
202   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
203
204   TypeID fieldHandlerId = params.fieldHandlerId;
205   MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
206
207   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
208   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
209   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
210
211   std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
212   std::cout << "\tviewMode: " << viewMode << std::endl;
213   std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
214   std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
215
216   // Create a new presentation instance
217   TypeID newID = MEDPresentationManager_i::GenerateID();
218   MEDPresentationDeflectionShape * presentation = new MEDPresentationDeflectionShape(fieldHandler, true);  // on stack or on heap?? stack for now
219   _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
220
221   presentation->generatePipeline();
222
223   return newID;
224 }
225
226 TypeID
227 MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params)
228 {
229   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
230
231   TypeID fieldHandlerId = params.fieldHandlerId;
232   MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
233
234   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
235   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
236   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
237
238   std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
239   std::cout << "\tviewMode: " << viewMode << std::endl;
240   std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
241   std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
242
243   // Create a new presentation instance
244   TypeID newID = MEDPresentationManager_i::GenerateID();
245   MEDPresentationPointSprite * presentation = new MEDPresentationPointSprite(fieldHandler, true);  // on stack or on heap?? stack for now
246   _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, presentation) );
247
248   presentation->generatePipeline();
249
250   return newID;
251 }