#include "QtxActionToolMgr.h"
#include "MEDFactoryClient.hxx"
#include "MEDPresentationManager_i.hxx"
+#include "XmedConsoleDriver.hxx"
+
+#include "MEDWidgetHelperScalarMap.hxx"
+#include "MEDPresentationScalarMap.hxx"
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <QMessageBox>
#include <sstream>
+#include "MEDFactoryClient.hxx"
+
static const int OPTIONS_VIEW_MODE_ID = 943;
static const int OPTIONS_VIEW_MODE_REPLACE_ID = 944;
static const int OPTIONS_VIEW_MODE_OVERLAP_ID = 945;
static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
+//! The only instance of the MEDPresentationManager
+MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
+
PresentationController::PresentationController(MEDModule* salomeModule) :
_salomeModule(salomeModule),
- _studyEditor(salomeModule->getStudyEditor())
+ _consoleDriver(0),
+ _studyEditor(salomeModule->getStudyEditor()),
+ _presHelperMap(),
+ _currentWidgetHelper(0)
{
STDLOG("Creating a PresentationController");
_dockWidget->setWidget(_widgetPresentationParameters);
parent->addDockWidget(Qt::LeftDockWidgetArea, _dockWidget);
//_dockWidget->show();
+
+ // Retrieve MEDFactory to get MEDPresentationManager (sometimes GUI needs to talk to the engine directly)
+ if ( ! _presManager ) {
+ _presManager = MEDFactoryClient::getFactory()->getPresentationManager();
+ }
+
+ // Connect to the click in the object browser
+ connect(salomeModule, SIGNAL( presentationSelected(int , const QString&, const QString&) ),
+ this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) );
}
PresentationController::~PresentationController()
{
- STDLOG("Deleting the PresentationController");
+ STDLOG("Deleting the resentationController");
+ // Clean allocated widget helpers:
+ for ( std::map<int, MEDWidgetHelper *>::iterator it = _presHelperMap.begin(); it != _presHelperMap.end(); ++it)
+ delete((*it).second);
+}
+
+/**
+ * [ABN] Created this probably because I don't know the right way to deal with non existent
+ * attributes in an object from the study ...
+ */
+int
+PresentationController::getIntParamFromStudyEditor(SALOMEDS::SObject_var obj, const char * name)
+{
+ int theInt = -1;
+ try {
+ theInt = _studyEditor->getParameterInt(obj,name);
+ }
+ catch(...) { }
+ return theInt;
}
std::string
tooltip = tr("TIP_PRESENTATION_SCALAR_MAP");
QString icon = tr(_getIconName("ICO_PRESENTATION_SCALAR_MAP").c_str());
int actionId;
- actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeScalarMap()),icon,tooltip);
+ actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeScalarMap()),icon,tooltip);
_salomeModule->createTool(actionId, presentationToolbarId);
_salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
label = tr("LAB_PRESENTATION_CONTOUR");
tooltip = tr("TIP_PRESENTATION_CONTOUR");
icon = tr(_getIconName("ICO_PRESENTATION_CONTOUR").c_str());
- actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeContour()),icon,tooltip);
+ actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeContour()),icon,tooltip);
_salomeModule->createTool(actionId, presentationToolbarId);
_salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
label = tr("LAB_PRESENTATION_VECTOR_FIELD");
tooltip = tr("TIP_PRESENTATION_VECTOR_FIELD");
icon = tr(_getIconName("ICO_PRESENTATION_VECTOR_FIELD").c_str());
- actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeVectorField()),icon,tooltip);
+ actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeVectorField()),icon,tooltip);
_salomeModule->createTool(actionId, presentationToolbarId);
_salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
label = tr("LAB_PRESENTATION_SLICES");
tooltip = tr("TIP_PRESENTATION_SLICES");
icon = tr(_getIconName("ICO_PRESENTATION_SLICES").c_str());
- actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeSlices()),icon,tooltip);
+ actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeSlices()),icon,tooltip);
_salomeModule->createTool(actionId, presentationToolbarId);
_salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
label = tr("LAB_PRESENTATION_DEFLECTION_SHAPE");
tooltip = tr("TIP_PRESENTATION_DEFLECTION_SHAPE");
icon = tr(_getIconName("ICO_PRESENTATION_DEFLECTION_SHAPE").c_str());
- actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizeDeflectionShape()),icon,tooltip);
+ actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizeDeflectionShape()),icon,tooltip);
_salomeModule->createTool(actionId, presentationToolbarId);
_salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
label = tr("LAB_PRESENTATION_POINT_SPRITE");
tooltip = tr("TIP_PRESENTATION_POINT_SPRITE");
icon = tr(_getIconName("ICO_PRESENTATION_POINT_SPRITE").c_str());
- actionId = _salomeModule->createStandardAction(label,this, SLOT(OnVisualizePointSprite()),icon,tooltip);
+ actionId = _salomeModule->createStandardAction(label,this, SLOT(onVisualizePointSprite()),icon,tooltip);
_salomeModule->createTool(actionId, presentationToolbarId);
_salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
+ // Separator
+ _salomeModule->createMenu(_salomeModule->separator(), presentationMenuId);
+
label = tr("LAB_DELETE_PRESENTATION");
tooltip = tr("TIP_DELETE_PRESENTATION");
icon = tr(_getIconName("ICO_DELETE_PRESENTATION").c_str());
- actionId = _salomeModule->createStandardAction(label,this, SLOT(OnDeletePresentation()),icon,tooltip);
+ actionId = _salomeModule->createStandardAction(label,this, SLOT(onDeletePresentation()),icon,tooltip);
// _salomeModule->createTool(actionId, presentationToolbarId);
// _salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
+ //
+ // Actions for popup menu only
+ //
+ // Low level PARAVIS dump
+ label = tr("LAB_PARAVIS_DUMP");
+ //icon = tr("ICO_DATASOURCE_EXPAND_FIELD");
+ actionId = _salomeModule->createStandardAction(label,this,SLOT(onParavisDump()),"");
+ _salomeModule->addActionInPopupMenu(actionId);
+
+
}
MEDCALC::MEDPresentationViewMode
-PresentationController::getSelectedViewMode()
+PresentationController::getSelectedViewMode() const
{
if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
return MEDCALC::VIEW_MODE_REPLACE;
}
MEDCALC::MEDPresentationColorMap
-PresentationController::getSelectedColorMap()
+PresentationController::getSelectedColorMap() const
{
return _widgetPresentationParameters->getColorMap();
}
+MEDCALC::MEDPresentationScalarBarRange
+PresentationController::getSelectedScalarBarRange() const
+{
+ return _widgetPresentationParameters->getScalarBarRange();
+}
+
void
PresentationController::visualize(PresentationEvent::EventType eventType)
{
// to make a view of an object from the tui console).
for (int i=0; i<listOfSObject->size(); i++) {
SALOMEDS::SObject_var soField = listOfSObject->at(i);
- int fieldId = -1;
- try {
- fieldId = _studyEditor->getParameterInt(soField,FIELD_ID); }
- catch(...) { }
+ int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
if (fieldId < 0) // is it a field serie ?
{
- int fieldSeriesId = -1;
- try {
- fieldSeriesId = _studyEditor->getParameterInt(soField,FIELD_SERIES_ID); }
- catch(...) { }
+ int fieldSeriesId = getIntParamFromStudyEditor(soField, FIELD_SERIES_ID);
// If fieldId and fieldSeriesId equals -1, then it means that it is not a field
// managed by the MED module, and we stop this function process.
if ( fieldSeriesId < 0)
PresentationEvent* event = new PresentationEvent();
event->eventtype = eventType;
- XmedDataObject* dataObject = new XmedDataObject();
- dataObject->setFieldHandler(*fieldHandler);
- event->objectdata = dataObject;
- emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
+ event->fieldHandler = fieldHandler;
+ emit presentationSignal(event); // --> processPresentationEvent()
}
}
void
-PresentationController::OnVisualizeScalarMap()
+PresentationController::onVisualizeScalarMap()
{
this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP);
}
void
-PresentationController::OnVisualizeContour()
+PresentationController::onVisualizeContour()
{
this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR);
}
void
-PresentationController::OnVisualizeVectorField()
+PresentationController::onVisualizeVectorField()
{
this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD);
}
void
-PresentationController::OnVisualizeSlices()
+PresentationController::onVisualizeSlices()
{
this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_SLICES);
}
void
-PresentationController::OnVisualizeDeflectionShape()
+PresentationController::onVisualizeDeflectionShape()
{
this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE);
}
void
-PresentationController::OnVisualizePointSprite()
+PresentationController::onVisualizePointSprite()
{
this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
}
void
-PresentationController::OnDeletePresentation()
+PresentationController::onDeletePresentation()
{
// We need a _studyEditor updated on the active study
_studyEditor->updateActiveStudy();
// For each object, emit a signal to the workspace to request pres deletion
for (int i=0; i<listOfSObject->size(); i++) {
SALOMEDS::SObject_var soPres = listOfSObject->at(i);
- int presId = _studyEditor->getParameterInt(soPres,PRESENTATION_ID);
+ int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
// If fieldId equals -1, then it means that it is not a field
// managed by the MED module, and we stop this function process.
if ( presId < 0 )
continue;
- STDLOG("Requesting deletion of presentation: ")
- std::ostringstream oss;
- oss << presId;
- STDLOG(" - Pres id: " + oss.str());
-
PresentationEvent* event = new PresentationEvent();
event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
- XmedDataObject* dataObject = new XmedDataObject();
- dataObject->setPresentationId(presId);
- event->objectdata = dataObject;
- emit presentationSignal(event); // --> WorkspaceController::processPresentationEvent
+ event->presentationId = presId;
+ emit presentationSignal(event); // --> processPresentationEvent()
+ }
+}
+
+QString
+PresentationController::getViewModePython() const
+{
+ MEDCALC::MEDPresentationViewMode viewMode = getSelectedViewMode();
+ switch(viewMode) {
+ case MEDCALC::VIEW_MODE_REPLACE: return "MEDCALC.VIEW_MODE_REPLACE";
+ case MEDCALC::VIEW_MODE_OVERLAP: return "MEDCALC.VIEW_MODE_OVERLAP";
+ case MEDCALC::VIEW_MODE_NEW_LAYOUT: return "MEDCALC.VIEW_MODE_NEW_LAYOUT";
+ case MEDCALC::VIEW_MODE_SPLIT_VIEW: return "MEDCALC.VIEW_MODE_SPLIT_VIEW";
+ }
+ return QString();
+}
+
+QString
+PresentationController::getColorMapPython() const
+{
+ MEDCALC::MEDPresentationColorMap colorMap = getSelectedColorMap();
+ switch(colorMap) {
+ case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: return "MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW";
+ case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "MEDCALC.COLOR_MAP_COOL_TO_WARM";
+ }
+ return QString();
+}
+
+QString
+PresentationController::getScalarBarRangePython() const
+{
+ MEDCALC::MEDPresentationScalarBarRange colorMap = getSelectedScalarBarRange();
+ switch(colorMap) {
+ case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS: return "MEDCALC.SCALAR_BAR_ALL_TIMESTEPS";
+ case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP: return "MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP";
+ }
+ return QString();
+}
+
+std::string
+PresentationController::getPresTypeFromWidgetHelper(int presId) const
+{
+ std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
+ if (it != _presHelperMap.end())
+ return (*it).second->getPythonTag();
+ return "UNKNOWN";
+}
+
+void
+PresentationController::processPresentationEvent(const PresentationEvent* event) {
+ // --> Send commands to SALOME Python console
+ if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SCALAR_MAP ) {
+ QString viewMode = getViewModePython();
+ //QString displayedComponent = ; // from PresentationController combobox
+ //QString scalarBarRange = ; // from PresentationController spinbox
+ QString colorMap = getColorMapPython();
+ MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
+ QStringList commands;
+ commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), %2, colorMap=%3)").arg(fieldHandler->id).arg(viewMode).arg(colorMap);
+ commands += QString("presentation_id");
+ _consoleDriver->exec(commands);
+ }
+// else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
+// QString viewMode = getViewModePython();
+// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
+// QStringList commands;
+// commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+// commands += QString("presentation_id");
+// _consoleDriver->exec(commands);
+// }
+// else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
+// QString viewMode = getViewModePython();
+// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
+// QStringList commands;
+// commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+// commands += QString("presentation_id");
+// _consoleDriver->exec(commands);
+// }
+// else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
+// QString viewMode = getViewModePython();
+// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
+// QStringList commands;
+// commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+// commands += QString("presentation_id");
+// _consoleDriver->exec(commands);
+// }
+// else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
+// QString viewMode = getViewModePython();
+// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
+// QStringList commands;
+// commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+// commands += QString("presentation_id");
+// _consoleDriver->exec(commands);
+// }
+// else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
+// QString viewMode = getViewModePython();
+// MEDCALC::FieldHandler* fieldHandler = event->_fieldHandler;
+// QStringList commands;
+// commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+// commands += QString("presentation_id");
+// _consoleDriver->exec(commands);
+// }
+
+ // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each
+ // dedicated widget helper class?
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COMPONENT ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ QStringList commands;
+ commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ commands += QString("params.displayedComponent = '%1'").arg(QString::fromStdString(event->aString));
+ commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ _consoleDriver->exec(commands);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_COLORMAP ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ QStringList commands;
+ commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ commands += QString("params.colorMap = %1").arg(getColorMapPython());
+ commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ _consoleDriver->exec(commands);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_CHANGE_TIME_RANGE ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ QStringList commands;
+ commands += QString("params = medcalc.Get%1Parameters(%2)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ commands += QString("params.scalarBarRange = %1").arg(getScalarBarRangePython());
+ commands += QString("medcalc.Update%1(%2, params)").arg(QString::fromStdString(typ)).arg(event->presentationId);
+ _consoleDriver->exec(commands);
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
+ QStringList commands;
+ commands += QString("medcalc.RemovePresentation(%1)").arg(event->presentationId);
+ _consoleDriver->exec(commands);
+ }
+ else {
+ STDLOG("The event "<<event->eventtype<<" is not implemented yet");
+ }
+}
+
+MEDWidgetHelper *
+PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager_ptr presManager,
+ int presId, const std::string& type, const std::string& name )
+{
+ std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
+ if (it != _presHelperMap.end())
+ return (*it).second;
+ MEDWidgetHelper * wh;
+ if (type == MEDPresentationScalarMap::TYPE_NAME)
+ wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
+ else
+ {
+// case PRES_CONTOUR:
+//// break;
+// case PRES_DEFLECTION:
+//// break;
+// case PRES_VECTOR_FIELD:
+// // break;
+// case PRES_POINT_SPRITE:
+// // break;
+// case PRES_POINT_SPRITE:
+// // break;
+// default:
+ STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!");
+
+ }
+ _presHelperMap[presId] = wh;
+ return wh;
+}
+
+void
+PresentationController::onPresentationSelected(int presId, const QString& presType, const QString& presName)
+{
+ if (presId == -1)
+ {
+ if (_widgetPresentationParameters->isShown())
+ {
+ _widgetPresentationParameters->toggleWidget(false);
+ if(_currentWidgetHelper)
+ _currentWidgetHelper->releaseWidget();
+ }
+ }
+ else
+ {
+ // Activate corresponding ParaView render view
+ _presManager->activateView(presId);
+ // Update widgets parameters
+ _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
+ _currentWidgetHelper->udpateWidget();
+ }
+}
+
+void
+PresentationController::onParavisDump()
+{
+ // We need a _studyEditor updated on the active study
+ _studyEditor->updateActiveStudy();
+
+ // Get the selected objects in the study (SObject)
+ SALOME_StudyEditor::SObjectList* listOfSObject = _studyEditor->getSelectedObjects();
+
+ // For the first object only, request the dump
+ for (int i=0; i<listOfSObject->size(); i++) {
+ SALOMEDS::SObject_var soPres = listOfSObject->at(i);
+ int presId = getIntParamFromStudyEditor(soPres,PRESENTATION_ID);
+ // If fieldId equals -1, then it means that it is not a field
+ // managed by the MED module, and we stop this function process.
+ if ( presId < 0 )
+ continue;
+
+ std::string dump(_presManager->getParavisDump(presId));
+ std::cerr << "#====== ParaVis dump =============== " << std::endl;
+ std::cerr << dump;
+ std::cerr << "#====== End of ParaVis dump ======== " << std::endl;
+
+ break; // stop at the first one
}
}
return;
}
- std::string name = MEDFactoryClient::getPresentationManager()->getPresentationProperty(presentationId, "name");
- std::string icon = std::string("ICO_") + name;
+ std::string name(MEDFactoryClient::getPresentationManager()->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
+ std::string type = name;
+ std::string icon = std::string("ICO_") + type;
icon = _getIconName(icon);
+ std::string ico = tr(icon.c_str()).toStdString();
+
+ // Append presentation ID to the displayed name in the OB:
+ std::ostringstream oss;
name = tr(name.c_str()).toStdString();
- std::string label = tr(icon.c_str()).toStdString();
+ oss << name << " (" << presentationId << ")";
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
_PTR(Study) studyDS = study->studyDS();
- _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId, name.c_str(), label.c_str(), presentationId);
+ _salomeModule->engine()->registerPresentation(_CAST(Study, studyDS)->GetStudy(), fieldId,
+ oss.str().c_str(), type.c_str(),ico.c_str(), presentationId);
MEDCALC::MEDPresentationViewMode viewMode = MEDFactoryClient::getPresentationManager()->getPresentationViewMode(presentationId);
void
PresentationController::showDockWidgets(bool isVisible)
{
- STDLOG("Switching PresentationController visibility to: " << isVisible);
_dockWidget->setVisible(isVisible);
}
+