#include "MEDPresentation.hxx"
#include "MEDPresentationException.hxx"
#include "MEDCouplingRefCountObject.hxx"
-#include <iostream>
+#include "Basics_Utils.hxx"
+#include "PyInterp_Utils.h"
-MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, std::string name)
- : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties()
+#include <sstream>
+
+MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name)
+ : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties(),
+ _renderViewPyId(GeneratePythonId())
{
MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
_fileName = dataSHandler->uri;
_fieldName = fieldHandler->fieldname;
- _fieldType = getFieldTypeString((ParaMEDMEM::TypeOfField) fieldHandler->type);
+ _fieldType = getFieldTypeString((MEDCoupling::TypeOfField) fieldHandler->type);
if (_fileName.substr(0, 7) != std::string("file://")) {
const char* msg = "Data source is not a file! Can not proceed.";
setProperty("name", name);
}
-void MEDPresentation::generatePipeline()
+MEDPresentation::~MEDPresentation()
+{
+ STDLOG("~MEDPresentation(): clear display");
+ {
+ PyLockWrapper lock;
+ std::ostringstream oss_o, oss_v, oss;
+ // Get top level object and display:
+ oss_o << "__obj" << _pipeline.front().first;
+ oss_v << "__view" << _renderViewPyId;
+ oss << "pvs.Hide(" << oss_o.str() << ", view=" << oss_v.str() << ");";
+ oss << "pvs.Render();";
+
+// std::cerr << oss.str() << std::endl;
+ PyRun_SimpleString(oss.str().c_str());
+ }
+}
+
+void
+MEDPresentation::generatePipeline()
{
// Might be more complicated in the future:
this->internalGeneratePipeline();
}
-void MEDPresentation::pushInternal(PyObject * obj, PyObject * disp)
+void
+MEDPresentation::pushPyObjects(PyObjectId obj, PyObjectId disp)
{
_pipeline.push_back(obj);
_display.push_back(disp);
}
-void MEDPresentation::setProperty(const std::string& propName, const std::string& propValue)
+void
+MEDPresentation::pushAndExecPyLine(const std::string & lin)
+{
+ // TODO: store internally for low level dump
+ PyLockWrapper lock;
+// std::cerr << lin << std::endl;
+ PyRun_SimpleString(lin.c_str());
+}
+
+void
+MEDPresentation::setProperty(const std::string& propName, const std::string& propValue)
{
// LIMITED!!! For now switch the first display element to Wireframe
/*
}
const std::string
-MEDPresentation::getProperty(const std::string& propName)
+MEDPresentation::getProperty(const std::string& propName) const
{
- if (_properties.find(propName) != _properties.end()) {
- return _properties[propName];
+ std::map<std::string, std::string>::const_iterator it = _properties.find(propName);
+ if (it != _properties.end()) {
+ return (*it).second;
}
else {
- std::cerr << "getProperty(): no property named " << propName << std::endl;
+ STDLOG("MEDPresentation::getProperty(): no property named " + propName);
return std::string();
}
}
-PyObject * MEDPresentation::getPythonObjectFromMain(const char * python_var)
+PyObject*
+MEDPresentation::getPythonObjectFromMain(const char* python_var) const
{
// TODO: improve to avoid getting dict at each call
return PyDict_GetItemString(global_dict, python_var);
}
-std::string MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType)
+std::string
+MEDPresentation::getFieldTypeString(MEDCoupling::TypeOfField fieldType) const
{
switch(fieldType)
{
case MEDCoupling::ON_NODES:
return "POINTS";
default:
- std::cerr << "MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?";
+ STDLOG("MEDPresentation::getFieldTypeString() -- Not implemented ! Gauss points?");
return "";
}
}
+
+std::string
+MEDPresentation::getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const
+{
+ std::ostringstream oss, oss2;
+ oss << "__view" << _renderViewPyId;
+ std::string view(oss.str());
+ oss2 << "pvs._DisableFirstRenderCameraReset();";
+ if (viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
+ oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');";
+ } else if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
+ oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');";
+ oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");";
+ oss2 << "pvs.Render();";
+ } else if (viewMode == MEDCALC::VIEW_MODE_NEW_LAYOUT) {
+ oss2 << "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');";
+ oss2 << view << " = pvs.CreateView('RenderView');";
+ } else if (viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) {
+ oss2 << view << " = pvs.CreateView('RenderView');";
+ }
+ return oss2.str();
+}
+
+std::string
+MEDPresentation::getResetCameraCommand() const
+{
+ std::ostringstream oss;
+ oss << "__view" << _renderViewPyId << ".ResetCamera();";
+ return oss.str();
+}
+
+std::string
+MEDPresentation::getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const
+{
+ switch (colorMap) {
+ case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "Blue to Red Rainbow";
+ case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "Cool to Warm";
+ }
+}
+
+int
+MEDPresentation::GeneratePythonId()
+{
+ static int INIT_ID = 0;
+ return INIT_ID++;
+}
+
+void
+MEDPresentation::activateView() const
+{
+ PyLockWrapper lock;
+ std::ostringstream oss;
+ oss << "pvs.SetActiveView(__view" << _renderViewPyId << ");";
+ std::cerr << oss.str() << std::endl;
+ PyRun_SimpleString(oss.str().c_str());
+}