1 // Copyright (C) 2011-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Authors: A Bruneton (CEA), C Aguerre (EdF)
21 #include "MEDFactoryClient.hxx"
22 #include "MEDPresentation.hxx"
23 #include "MEDPresentationException.hxx"
24 #include "MEDCouplingRefCountObject.hxx"
27 MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name)
28 : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties()
30 MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
31 MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
32 MEDCALC::MeshHandler* meshHandler = dataManager->getMesh(fieldHandler->meshid);
33 MEDCALC::DatasourceHandler* dataSHandler = dataManager->getDatasourceHandlerFromID(meshHandler->sourceid);
35 _fileName = dataSHandler->uri;
36 _fieldName = fieldHandler->fieldname;
37 _fieldType = getFieldTypeString((MEDCoupling::TypeOfField) fieldHandler->type);
39 if (_fileName.substr(0, 7) != std::string("file://")) {
40 const char* msg = "Data source is not a file! Can not proceed.";
41 throw MEDPresentationException(msg);
43 _fileName = _fileName.substr(7, _fileName.size());
45 setProperty("name", name);
48 MEDPresentation::~MEDPresentation()
50 std::cout << "###TODO#### ~MEDPresentation: clear pipeline\n";
51 std::cout << "###TODO#### ~MEDPresentation: clear display\n";
55 MEDPresentation::generatePipeline()
57 // Might be more complicated in the future:
59 this->internalGeneratePipeline();
63 MEDPresentation::pushInternal(PyObject* obj, PyObject* disp)
65 _pipeline.push_back(obj);
66 _display.push_back(disp);
70 MEDPresentation::setProperty(const std::string& propName, const std::string& propValue)
72 // LIMITED!!! For now switch the first display element to Wireframe
75 PyObject_CallMethod(_display[0], (char*)"SetRepresentationType", (char*)"(s)", "Wireframe");
78 _properties[propName] = propValue;
82 MEDPresentation::getProperty(const std::string& propName) const
84 std::map<std::string, std::string>::const_iterator it = _properties.find(propName);
85 if (it != _properties.end()) {
89 std::cerr << "getProperty(): no property named " << propName << std::endl;
95 MEDPresentation::getPythonObjectFromMain(const char* python_var) const
97 // TODO: improve to avoid getting dict at each call
99 // All the calls below returns *borrowed* references
100 PyObject* main_module = PyImport_AddModule((char*)"__main__");
101 PyObject* global_dict = PyModule_GetDict(main_module);
102 return PyDict_GetItemString(global_dict, python_var);
106 MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const
110 case MEDCoupling::ON_CELLS:
112 case MEDCoupling::ON_NODES:
115 std::cerr << "MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?";
121 MEDPresentation::getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const
123 std::string cmd = std::string("pvs._DisableFirstRenderCameraReset();");
124 if (viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
125 cmd += std::string("__view1 = pvs.GetActiveViewOrCreate('RenderView');");
126 } else if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
127 cmd += std::string("__view1 = pvs.GetActiveViewOrCreate('RenderView');");
128 cmd += std::string("pvs.active_objects.source and pvs.Hide(view=__view1);");
129 cmd += std::string("pvs.Render();");
130 } else if (viewMode == MEDCALC::VIEW_MODE_NEW_LAYOUT) {
131 cmd += std::string("__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');");
132 cmd += std::string("__view1 = pvs.CreateView('RenderView');");
133 } else if (viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) {
134 cmd += std::string("__view1 = pvs.CreateView('RenderView');");
140 MEDPresentation::getResetCameraCommand() const
142 return std::string("__view1.ResetCamera();");
147 MEDPresentation::getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const
150 case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "Blue to Red Rainbow";
151 case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "Cool to Warm";