Salome HOME
fix conflict
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationManager_i.cxx
1 // Copyright (C) 2011-2015  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
24 MEDPresentationManager_i* MEDPresentationManager_i::_instance = NULL;
25
26 MEDPresentationManager_i*
27 MEDPresentationManager_i::getInstance() {
28   if ( _instance == NULL )
29     _instance = new MEDPresentationManager_i();
30   return _instance;
31 }
32
33 MEDPresentationManager_i::MEDPresentationManager_i()
34 {
35 }
36
37 MEDPresentationManager_i::~MEDPresentationManager_i()
38 {
39   /*
40   std::vector<MEDPresentation*>::iterator itr = this->_presentations.begin();
41   for ( ; itr != this->_presentations.end(); ++itr) {
42     delete *itr;
43     *itr = NULL;
44   }
45   this->_presentations.clear();
46   */
47 }
48
49 TypeID MEDPresentationManager_i::GenerateID()
50 {
51   static TypeID START_ID = -1;
52   START_ID++;
53   return START_ID;
54 }
55
56 #include <iostream>
57
58 void
59 MEDPresentationManager_i::setPresentationProperty(TypeID presentationID, const char * propName, const char * propValue)
60 {
61   if (_presentations.find(presentationID) != _presentations.end())
62     {
63       MEDPresentation * pres(_presentations[presentationID]);
64       pres->setProperty(propName, propValue);
65     }
66   else
67     {
68       std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
69     }
70 }
71
72 char*
73 MEDPresentationManager_i::getPresentationProperty(TypeID presentationID, const char* propName)
74 {
75   if (_presentations.find(presentationID) != _presentations.end()) {
76     MEDPresentation* pres = _presentations[presentationID];
77     return (char*) pres->getProperty(propName).c_str();
78   }
79   else {
80     std::cerr << "getPresentationProperty(): presentation not found!!" << std::endl;
81     return (char*) "";
82   }
83 }
84
85 TypeID
86 MEDPresentationManager_i::makeScalarMap(const MEDCALC::ScalarMapParameters& params)
87 {
88   MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
89
90   TypeID fieldHandlerId = params.fieldHandlerId;
91   MEDCALC::MEDPresentationViewMode viewMode = params.viewMode;
92
93   MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
94   MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
95   MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
96
97   std::cout << "\tfieldHandlerId: " << fieldHandlerId << std::endl;
98   std::cout << "\tviewMode: " << viewMode << std::endl;
99   std::cout << "\tfileName: " <<  dataSHandler->uri << std::endl;
100   std::cout << "\tfiedName: " << fieldHandler->fieldname << std::endl;
101
102   // Create a new presentation instance
103   TypeID newID = MEDPresentationManager_i::GenerateID();
104   MEDPresentationScalarMap * scalarMap = new MEDPresentationScalarMap(fieldHandler, true);  // on stack or on heap?? stack for now
105   _presentations.insert( std::pair<TypeID, MEDPresentation *>(newID, scalarMap) );
106
107   scalarMap->generatePipeline();
108
109   return newID;
110 }