// Low level ParaVis dump
string getParavisDump(in long presId);
- MEDPresentationViewMode getPresentationViewMode(in long presId);
+// MEDPresentationViewMode getPresentationViewMode(in long presId);
};
};
* This returns a copy of the fieldHandler associated to the specified id.
*/
MEDCALC::FieldHandler * MEDDataManager_i::getFieldHandler(CORBA::Long fieldHandlerId) {
- LOG("getFieldHandler: START")
+// LOG("getFieldHandler: START")
FieldHandlerMapIterator fieldIt = _fieldHandlerMap.find(fieldHandlerId);
if ( fieldIt != _fieldHandlerMap.end() ) {
MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name,
const MEDCALC::MEDPresentationViewMode viewMode,
- const MEDCALC::MEDPresentationColorMap colorMap)
+ const MEDCALC::MEDPresentationColorMap colorMap,
+ const MEDCALC::MEDPresentationScalarBarRange sbRange)
: _fieldHandlerId(fieldHandlerId), _propertiesStr(),
//_pipeline(0), _display(0)
_selectedComponentIndex(-1),
_viewMode(viewMode),
_colorMap(colorMap),
- _renderViewPyId(GeneratePythonId()),
- _objId(_renderViewPyId), _dispId(_renderViewPyId), _lutId(_renderViewPyId),
+ _sbRange(sbRange),
+ _renderViewPyId(-1), // will be set by getRenderViewCommand()
+ _objId(GeneratePythonId()),
+ _dispId(_objId), _lutId(_objId),
_globalDict(0)
{
MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
_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.";
+ const char* msg = "MEDPresentation(): Data source is not a file! Can not proceed.";
+ STDLOG(msg);
throw MEDPresentationException(msg);
}
_fileName = _fileName.substr(7, _fileName.size());
void
MEDPresentation::pushAndExecPyLine(const std::string & lin)
+{
+ execPyLine(lin);
+ _pythonCmds.push_back(lin);
+}
+
+void
+MEDPresentation::execPyLine(const std::string & lin)
{
PyLockWrapper lock;
-// std::cerr << lin << std::endl;
+// STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
if(PyRun_SimpleString(lin.c_str()))
{
std::ostringstream oss;
- oss << "MEDPresentation::pushAndExecPyLine(): following Python command failed!\n";
+ oss << "MEDPresentation::execPyLine(): following Python command failed!\n";
oss << ">> " << lin;
STDLOG(oss.str());
throw KERNEL::createSalomeException(oss.str().c_str());
}
- _pythonCmds.push_back(lin);
+
}
void
return (*it).second;
}
else {
+ STDLOG("MEDPresentation::getStringProperty(): no property named " + propName);
throw MEDPresentationException("MEDPresentation::getStringProperty(): no property named " + propName);
}
}
return (*it).second;
}
else {
+ STDLOG("MEDPresentation::getIntProperty(): no property named " + propName);
throw MEDPresentationException("MEDPresentation::getIntProperty(): no property named " + propName);
}
}
}
}
+ void
+ MEDPresentation::internalGeneratePipeline()
+ {
+ PyLockWrapper lock;
+ pushAndExecPyLine( "import pvsimple as pvs;");
+ }
+
PyObject*
MEDPresentation::getPythonObjectFromMain(const char* python_var) const
MEDPresentation::getRenderViewCommand() const
{
std::ostringstream oss, oss2;
+
oss << "__view" << _renderViewPyId;
std::string view(oss.str());
oss2 << "pvs._DisableFirstRenderCameraReset();" << std::endl;
if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
+ // this might potentially re-assign to an existing view variable, but this is OK, we
+ // normally reassign exaclty the same RenderView object.
oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl;
} else if (_viewMode == MEDCALC::VIEW_MODE_REPLACE) {
+ // same as above
oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl;
oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");" << std::endl;
oss2 << "pvs.Render();" << std::endl;
oss << lut << ".ApplyPreset('Cool to Warm',True);";
break;
default:
+ STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!");
throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!");
}
return oss.str();
oss << disp << ".RescaleTransferFunctionToDataRange(False);";
break;
default:
+ STDLOG("MEDPresentation::getRescaleCommand(): invalid range!");
throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!");
}
return oss.str();
}
else {
std::string msg("Unsupported spatial discretisation: " + _fieldType);
+ STDLOG(msg);
throw KERNEL::createSalomeException(msg.c_str());
}
std::ostringstream oss;
oss << "__nbCompo = " << obj << "." << typ << ".GetArray('" << _fieldName << "').GetNumberOfComponents();";
- PyRun_SimpleString(oss.str().c_str());
+ execPyLine(oss.str());
PyObject* p_obj = getPythonObjectFromMain("__nbCompo");
long nbCompo;
if (p_obj && PyInt_Check(p_obj))
nbCompo = PyInt_AS_LONG(p_obj);
else
- throw KERNEL::createSalomeException("Unexpected Python error");
+ {
+ STDLOG("Unexpected Python error");
+ throw KERNEL::createSalomeException("Unexpected Python error");
+ }
setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, nbCompo);
for (long i = 0; i<nbCompo; i++)
{
std::ostringstream oss2;
oss2 << "__compo = " << obj << "." << typ << ".GetArray('" << _fieldName << "').GetComponentName(" << i << ");";
- PyRun_SimpleString(oss2.str().c_str());
+ execPyLine(oss2.str());
PyObject* p_obj = getPythonObjectFromMain("__compo");
std::string compo;
if (p_obj && PyString_Check(p_obj))
compo = std::string(PyString_AsString(p_obj)); // pointing to internal Python memory, so make a copy!!
else
- throw KERNEL::createSalomeException("Unexpected Python error");
+ {
+ STDLOG("Unexpected Python error");
+ throw KERNEL::createSalomeException("Unexpected Python error");
+ }
std::ostringstream oss_p;
oss_p << MEDPresentation::PROP_COMPONENT << i;
setStringProperty(oss_p.str(), compo);
std::string paravisDump() const;
+ long getPyViewID() const { return _renderViewPyId; }
+ void setPyViewID(long id) { _renderViewPyId = id; }
+
protected:
typedef std::pair<int, PyObject *> PyObjectId;
static int GeneratePythonId();
MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name,
const MEDCALC::MEDPresentationViewMode viewMode,
- const MEDCALC::MEDPresentationColorMap colorMap);
+ const MEDCALC::MEDPresentationColorMap colorMap,
+ const MEDCALC::MEDPresentationScalarBarRange sbRange);
std::string getRenderViewCommand() const;
std::string getResetCameraCommand() const;
std::string getColorMapCommand() const;
std::string getRescaleCommand() const;
- virtual void internalGeneratePipeline() = 0;
+ virtual void internalGeneratePipeline();
PyObject* getPythonObjectFromMain(const char* var) const;
// void pushPyObjects(PyObjectId obj, PyObjectId disp);
+ void execPyLine(const std::string & lin);
void pushAndExecPyLine(const std::string & lin);
MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
- long getPyViewID() const { return _renderViewPyId; }
void fillAvailableFieldComponents();
- // TODO: follow the pattern of the others methods: template!
- virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0;
+// virtual MEDCALC::MEDPresentationViewMode getViewMode() = 0;
template<typename PresentationType, typename PresentationParameters>
void updateComponent(const std::string& newCompo);
return _instance;
}
-MEDPresentationManager_i::MEDPresentationManager_i()
+MEDPresentationManager_i::MEDPresentationManager_i() :
+ _presentations(),
+ _activeViewPythonId(-1)
{
}
delete presentation;
_presentations.erase(presentationID);
- std::stringstream sstm;
- sstm << "Presentation " << presentationID << " has been removed.\n";
- STDLOG(sstm.str());
-
+ STDLOG("Presentation " << presentationID << " has been removed.");
return true;
}
MEDPresentation* presentation = (*citr).second;
presentation->activateView();
+ _activeViewPythonId = presentation->getPyViewID();
return true;
}
-MEDCALC::MEDPresentationViewMode
-MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
+CORBA::Long
+MEDPresentationManager_i::getActiveViewPythonId()
{
- MEDPresentation* pres = _getPresentation(presentationID);
- if (pres) {
- return pres->getViewMode();
- } else {
- std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
- return MEDCALC::VIEW_MODE_DEFAULT;
- }
+ //TODO: should be more elaborate to re-identify the active ParaView view when another
+ //mechanism than MED module has activated another view.
+ // Idea: 1/ call Python to current active view
+ // 2/ compare with all id(__viewX) from currently existing presentations
+ return _activeViewPythonId;
}
+
+//MEDCALC::MEDPresentationViewMode
+//MEDPresentationManager_i::getPresentationViewMode(MEDPresentation::TypeID presentationID)
+//{
+// MEDPresentation* pres = _getPresentation(presentationID);
+// if (pres) {
+// return pres->getViewMode();
+// } else {
+// std::cerr << "setPresentationProperty(): presentation not found!!" << std::endl;
+// return MEDCALC::VIEW_MODE_DEFAULT;
+// }
+//}
+
char*
MEDPresentationManager_i::getParavisDump(MEDPresentation::TypeID presentationID)
{
MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID);
MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID);
- MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID);
+ MEDCALC_EXPORT CORBA::Long getActiveViewPythonId();
+// MEDCALC_EXPORT MEDCALC::MEDPresentationViewMode getPresentationViewMode(MEDPresentation::TypeID);
MEDCALC_EXPORT char* getParavisDump(MEDPresentation::TypeID presentationID);
private:
// Owns a list of MEDPresentation objects
std::map<MEDPresentation::TypeID, MEDPresentation*> _presentations;
+ long _activeViewPythonId;
};
#include "MEDPresentationManager_i.txx"
#ifndef _MED_PRESENTATION_MANAGER_I_TXX_
#define _MED_PRESENTATION_MANAGER_I_TXX_
+#include <Basics_Utils.hxx>
+
template<typename PresentationType, typename PresentationParameters>
MEDPresentation::TypeID
MEDPresentationManager_i::_makePresentation(const PresentationParameters params, const MEDCALC::MEDPresentationViewMode viewMode)
{
+ int activeViewId = getActiveViewPythonId();
+
// Replace = Remove then add
- if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
- MEDPresentation::TypeID currentPresentationId = _getActivePresentationId();
- if (currentPresentationId > -1)
- removePresentation(currentPresentationId);
+ if (viewMode == MEDCALC::VIEW_MODE_REPLACE)
+ {
+ // Remove all presentations from this view:
+ std::map<MEDPresentation::TypeID, MEDPresentation*>::const_iterator it;
+ std::vector<int> to_del;
+ for (it = _presentations.begin(); it != _presentations.end(); ++it)
+ {
+ int viewId2 = (*it).second->getPyViewID();
+ if (viewId2 == activeViewId)
+ to_del.push_back((*it).first);
+ }
+ for (std::vector<int>::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2)
+ removePresentation(*it2);
}
// Create a new presentation instance
PresentationType* presentation = NULL;
+ MEDPresentation::TypeID newID = MEDPresentationManager_i::GenerateID();
+ STDLOG("Generated presentation ID: " << newID);
try {
presentation = new PresentationType(params, viewMode); // on stack or on heap?? heap for now
+ // In replace or overlap mode we force the display in the active view:
+ if(activeViewId != -1 && (viewMode == MEDCALC::VIEW_MODE_REPLACE || viewMode == MEDCALC::VIEW_MODE_OVERLAP))
+ presentation->setPyViewID(activeViewId);
+ else
+ presentation->setPyViewID(newID); // ensures a new ID for the view
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
+ STDLOG("Error: " << e.what());
return -1;
}
- MEDPresentation::TypeID newID = MEDPresentationManager_i::GenerateID();
_presentations.insert( std::pair<MEDPresentation::TypeID, MEDPresentation *>(newID, presentation) );
presentation->generatePipeline();
+ // Make the view holding the newly created presentation the active one:
+ activateView(newID);
return newID;
}
MEDPresentationScalarMap::MEDPresentationScalarMap(const MEDCALC::ScalarMapParameters& params,
const MEDCALC::MEDPresentationViewMode viewMode) :
- MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap), _params(params)
+ MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
{
}
void
MEDPresentationScalarMap::internalGeneratePipeline()
{
+ MEDPresentation::internalGeneratePipeline();
+
PyLockWrapper lock;
std::ostringstream oss_o, oss_d,oss_l, oss, oss_v;
oss_o << "__obj" << _objId; std::string obj(oss_o.str());
oss_d << "__disp" << _dispId; std::string disp(oss_d.str());
oss_l << "__lut" << _lutId; std::string lut(oss_l.str());
-
- pushAndExecPyLine( "import pvsimple as pvs;");
- pushAndExecPyLine( getRenderViewCommand() ); // define __viewXXX
-
oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str());
+ pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
+
oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
pushAndExecPyLine(oss.str()); oss.str("");
virtual ~MEDPresentationScalarMap() {}
void updatePipeline(const MEDCALC::ScalarMapParameters& params);
- MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
void getParameters(MEDCALC::ScalarMapParameters & params) const { params = _params; } ;
void setParameters(const MEDCALC::ScalarMapParameters & params) { _params = params; } ;
+// MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
+
protected:
virtual void internalGeneratePipeline();
return;
}
- std::string name(MEDFactoryClient::getPresentationManager()->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
+ std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
std::string type = name;
std::string icon = std::string("ICO_") + type;
icon = _getIconName(icon);
oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
- MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
-
- // Remove sibling presentations if view mode is set to REPLACE
- if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
- MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
- CORBA::ULong size = presList->length();
-
- std::stringstream sstm;
- sstm << "Removing sibling presentation(s): ";
- for (int i = 0; i < size; ++i)
- sstm << (*presList)[i] << " ";
- STDLOG(sstm.str());
-
- for (int i = 0; i < size; ++i) {
- PresentationEvent* event = new PresentationEvent();
- event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
- XmedDataObject* dataObject = new XmedDataObject();
- dataObject->setPresentationId((*presList)[i]);
- event->objectdata = dataObject;
- emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
- }
-
- delete presList;
- }
+// MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
+//
+// // Remove sibling presentations if view mode is set to REPLACE
+// if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
+// MED_ORB::PresentationsList* presList = _salomeModule->engine()->getSiblingPresentations(_CAST(Study, studyDS)->GetStudy(), presentationId);
+// CORBA::ULong size = presList->length();
+//
+// std::stringstream sstm;
+// sstm << "Removing sibling presentation(s): ";
+// for (int i = 0; i < size; ++i)
+// sstm << (*presList)[i] << " ";
+// STDLOG(sstm.str());
+//
+// for (int i = 0; i < size; ++i) {
+// PresentationEvent* event = new PresentationEvent();
+// event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
+// XmedDataObject* dataObject = new XmedDataObject();
+// dataObject->setPresentationId((*presList)[i]);
+// event->objectdata = dataObject;
+// emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
+// }
+//
+// delete presList;
+// }
// update Object browser
_salomeModule->getApp()->updateObjectBrowser(true);
PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event)
{
if ( event->type == MEDCALC::EVENT_ADD_PRESENTATION ) {
- this->updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
+ updateTreeViewWithNewPresentation(event->dataId, event->presentationId);
+ // Deal with replace mode: presentations with invalid IDs have to be removed:
+ std::map<int, MEDWidgetHelper *>::iterator it;
+ std::vector<int> to_del;
+ for (it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
+ {
+ try {
+ // TODO: not the best way to test for presentation existence at the engine level?
+ _presManager->getPresentationStringProperty((*it).first, MEDPresentation::PROP_NAME.c_str());
+ }
+ catch(...){
+ to_del.push_back((*it).first);
+ delete((*it).second);
+ (*it).second = 0;
+ }
+ }
+ std::vector<int>::const_iterator it2;
+ for (it2 = to_del.begin(); it2 != to_del.end(); ++it2)
+ {
+ updateTreeViewForPresentationRemoval(*it2);
+ _presHelperMap.erase(*it2);
+ }
}
else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
- this->updateTreeViewForPresentationRemoval(event->presentationId);
+ updateTreeViewForPresentationRemoval(event->presentationId);
}
}