+ preparation for the Python dump.
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/..
${PROJECT_BINARY_DIR}/idl
+ ${GUI_INCLUDE_DIRS} # For PyLockWrapper
)
SET(COMMON_SOURCES
${OMNIORB_LIBRARIES}
${PYTHON_LIBRARIES}
${MEDCoupling_medcoupling} ${MEDCoupling_medloader} ${MEDCoupling_medcouplingremapper}
+ ${GUI_PyInterp}
)
# This undefines the macros MIN and MAX which are specified in the windows headers
#include "MEDPresentation.hxx"
#include "MEDPresentationException.hxx"
#include "MEDCouplingRefCountObject.hxx"
-#include <iostream>
+#include "Basics_Utils.hxx"
+#include "PyInterp_Utils.h"
+
+#include <sstream>
MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name)
- : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties()
+ : _fieldHandlerId(fieldHandlerId), _pipeline(0), _display(0), _properties(),
+ _renderViewPyId(GeneratePythonId())
{
MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
MEDCALC::FieldHandler* fieldHandler = dataManager->getFieldHandler(fieldHandlerId);
MEDPresentation::~MEDPresentation()
{
- std::cout << "###TODO#### ~MEDPresentation: clear pipeline\n";
- std::cout << "###TODO#### ~MEDPresentation: clear display\n";
+ 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
}
void
-MEDPresentation::pushInternal(PyObject* obj, PyObject* disp)
+MEDPresentation::pushPyObjects(PyObjectId obj, PyObjectId disp)
{
_pipeline.push_back(obj);
_display.push_back(disp);
}
+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)
{
return (*it).second;
}
else {
- std::cerr << "getProperty(): no property named " << propName << std::endl;
+ STDLOG("MEDPresentation::getProperty(): no property named " + propName);
return std::string();
}
}
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::string cmd = std::string("pvs._DisableFirstRenderCameraReset();");
+ std::ostringstream oss, oss2;
+ oss << "__view" << _renderViewPyId;
+ std::string view(oss.str());
+ oss2 << "pvs._DisableFirstRenderCameraReset();";
if (viewMode == MEDCALC::VIEW_MODE_OVERLAP) {
- cmd += std::string("__view1 = pvs.GetActiveViewOrCreate('RenderView');");
+ oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');";
} else if (viewMode == MEDCALC::VIEW_MODE_REPLACE) {
- cmd += std::string("__view1 = pvs.GetActiveViewOrCreate('RenderView');");
- cmd += std::string("pvs.active_objects.source and pvs.Hide(view=__view1);");
- cmd += std::string("pvs.Render();");
+ 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) {
- cmd += std::string("__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');");
- cmd += std::string("__view1 = pvs.CreateView('RenderView');");
+ oss2 << "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');";
+ oss2 << view << " = pvs.CreateView('RenderView');";
} else if (viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) {
- cmd += std::string("__view1 = pvs.CreateView('RenderView');");
+ oss2 << view << " = pvs.CreateView('RenderView');";
}
- return cmd;
+ return oss2.str();
}
std::string
MEDPresentation::getResetCameraCommand() const
{
- return std::string("__view1.ResetCamera();");
+ std::ostringstream oss;
+ oss << "__view" << _renderViewPyId << ".ResetCamera();";
+ return oss.str();
}
-
std::string
MEDPresentation::getColorMapCommand(MEDCALC::MEDPresentationColorMap colorMap) const
{
case MEDCALC::COLOR_MAP_COOL_TO_WARM: return "Cool to Warm";
}
}
+
+int
+MEDPresentation::GeneratePythonId()
+{
+ static int INIT_ID = 0;
+ return INIT_ID++;
+}
const std::string getProperty(const std::string& propName) const;
protected:
+ typedef std::pair<int, PyObject *> PyObjectId;
MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const std::string& name);
std::string getRenderViewCommand(MEDCALC::MEDPresentationViewMode viewMode) const;
virtual void internalGeneratePipeline() = 0;
PyObject* getPythonObjectFromMain(const char* var) const;
- void pushInternal(PyObject* obj, PyObject* disp = NULL);
+ void pushPyObjects(PyObjectId obj, PyObjectId disp);
+ void pushAndExecPyLine(const std::string & lin);
MEDPresentation::TypeID getID() const { return _fieldHandlerId; }
+ static int GeneratePythonId();
+
private:
std::string getFieldTypeString(MEDCoupling::TypeOfField fieldType) const;
void updatePipeline(PresentationParameters params);
protected:
-
std::string _fileName;
std::string _fieldName;
std::string _fieldType;
-private:
+ ///! Identifier (in the Python dump) of the render view
+ int _renderViewPyId;
+private:
MEDPresentation::TypeID _fieldHandlerId;
///! Pipeline elements
- std::vector<PyObject*> _pipeline;
+ std::vector<PyObjectId> _pipeline;
///! Corresponding display object, if any:
- std::vector<PyObject*> _display;
+ std::vector<PyObjectId> _display;
///! Presentation properties <key,value>
std::map<std::string, std::string> _properties;
void
MEDPresentationContour::internalGeneratePipeline()
{
- PyGILState_STATE _gil_state = PyGILState_Ensure();
-
- std::string cmd = std::string("import pvsimple as pvs;");
- cmd += getRenderViewCommand(_params.viewMode); // define __view1
-
- cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
- cmd += std::string("__isovolume1 = pvs.IsoVolume(Input=__obj1);");
- cmd += std::string("__disp1 = pvs.Show(__isovolume1, __view1);");
- cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
- cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
- cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
- cmd += std::string("pvs.Render();");
-
- cmd += getResetCameraCommand();
-
- //std::cerr << "Python command:" << std::endl;
- //std::cerr << cmd << std::endl;
- PyRun_SimpleString(cmd.c_str());
- // Retrieve Python object for internal storage:
- PyObject* obj = getPythonObjectFromMain("__isovolume1");
- PyObject* disp = getPythonObjectFromMain("__disp1");
- pushInternal(obj, disp);
-
- PyGILState_Release(_gil_state);
+// PyGILState_STATE _gil_state = PyGILState_Ensure();
+//
+// std::string cmd = std::string("import pvsimple as pvs;");
+// cmd += getRenderViewCommand(_params.viewMode); // define __view1
+//
+// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+// cmd += std::string("__isovolume1 = pvs.IsoVolume(Input=__obj1);");
+// cmd += std::string("__disp1 = pvs.Show(__isovolume1, __view1);");
+// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
+// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+// cmd += std::string("pvs.Render();");
+//
+// cmd += getResetCameraCommand();
+//
+// //std::cerr << "Python command:" << std::endl;
+// //std::cerr << cmd << std::endl;
+// PyRun_SimpleString(cmd.c_str());
+// // Retrieve Python object for internal storage:
+// PyObject* obj = getPythonObjectFromMain("__isovolume1");
+// PyObject* disp = getPythonObjectFromMain("__disp1");
+// pushInternal(obj, disp);
+//
+// PyGILState_Release(_gil_state);
}
void
void
MEDPresentationDeflectionShape::internalGeneratePipeline()
{
- PyGILState_STATE _gil_state = PyGILState_Ensure();
-
- std::string cmd = std::string("import pvsimple as pvs;");
- cmd += getRenderViewCommand(_params.viewMode); // define __view1
-
- cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
- cmd += std::string("__warpByVector1 = pvs.WarpByVector(Input=__obj1);");
- cmd += std::string("__disp1 = pvs.Show(__warpByVector1, __view1);");
- cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
- cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
- cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
- cmd += std::string("pvs.Render();");
-
- cmd += getResetCameraCommand();
-
- //std::cerr << "Python command:" << std::endl;
- //std::cerr << cmd << std::endl;
- PyRun_SimpleString(cmd.c_str());
- // Retrieve Python object for internal storage:
- PyObject* obj = getPythonObjectFromMain("__warpByVector1");
- PyObject* disp = getPythonObjectFromMain("__disp1");
- pushInternal(obj, disp);
-
- PyGILState_Release(_gil_state);
+// PyGILState_STATE _gil_state = PyGILState_Ensure();
+//
+// std::string cmd = std::string("import pvsimple as pvs;");
+// cmd += getRenderViewCommand(_params.viewMode); // define __view1
+//
+// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+// cmd += std::string("__warpByVector1 = pvs.WarpByVector(Input=__obj1);");
+// cmd += std::string("__disp1 = pvs.Show(__warpByVector1, __view1);");
+// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
+// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+// cmd += std::string("pvs.Render();");
+//
+// cmd += getResetCameraCommand();
+//
+// //std::cerr << "Python command:" << std::endl;
+// //std::cerr << cmd << std::endl;
+// PyRun_SimpleString(cmd.c_str());
+// // Retrieve Python object for internal storage:
+// PyObject* obj = getPythonObjectFromMain("__warpByVector1");
+// PyObject* disp = getPythonObjectFromMain("__disp1");
+// pushInternal(obj, disp);
+//
+// PyGILState_Release(_gil_state);
}
void
void
MEDPresentationPointSprite::internalGeneratePipeline()
{
- PyGILState_STATE _gil_state = PyGILState_Ensure();
-
- std::string cmd = std::string("import pvsimple as pvs;");
- cmd += getRenderViewCommand(_params.viewMode); // define __view1
-
- cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
- cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);");
- cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
- cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
- cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
- cmd += std::string("__disp1.SetRepresentationType('Point Sprite');");
- cmd += std::string("pvs.Render();");
-
- cmd += getResetCameraCommand();
-
- //std::cerr << "Python command:" << std::endl;
- //std::cerr << cmd << std::endl;
- PyRun_SimpleString(cmd.c_str());
- // Retrieve Python object for internal storage:
- PyObject* obj = getPythonObjectFromMain("__obj1");
- PyObject* disp = getPythonObjectFromMain("__disp1");
- pushInternal(obj, disp);
-
- PyGILState_Release(_gil_state);
+// PyGILState_STATE _gil_state = PyGILState_Ensure();
+//
+// std::string cmd = std::string("import pvsimple as pvs;");
+// cmd += getRenderViewCommand(_params.viewMode); // define __view1
+//
+// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+// cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);");
+// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
+// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+// cmd += std::string("__disp1.SetRepresentationType('Point Sprite');");
+// cmd += std::string("pvs.Render();");
+//
+// cmd += getResetCameraCommand();
+//
+// //std::cerr << "Python command:" << std::endl;
+// //std::cerr << cmd << std::endl;
+// PyRun_SimpleString(cmd.c_str());
+// // Retrieve Python object for internal storage:
+// PyObject* obj = getPythonObjectFromMain("__obj1");
+// PyObject* disp = getPythonObjectFromMain("__disp1");
+// pushInternal(obj, disp);
+//
+// PyGILState_Release(_gil_state);
}
void
//
#include "MEDPresentationScalarMap.hxx"
+#include "PyInterp_Utils.h"
+
+#include <sstream>
void
MEDPresentationScalarMap::internalGeneratePipeline()
{
- PyGILState_STATE _gil_state = PyGILState_Ensure();
+ PyLockWrapper lock;
- std::string cmd = std::string("import pvsimple as pvs;");
- cmd += getRenderViewCommand(_params.viewMode); // define __view1
+ int disp_id(GeneratePythonId());
+ int obj_id(disp_id);
+ std::ostringstream oss_o, oss_d, oss, oss_v;
+ oss_o << "__obj" << obj_id; std::string obj(oss_o.str());
+ oss_d << "__disp" << disp_id; std::string disp(oss_d.str());
- cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
- cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);");
- cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
- cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
- cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
- cmd += std::string("__lut = pvs.GetColorTransferFunction('")+_fieldName+std::string("');");
- cmd += std::string("__lut.ApplyPreset('")+getColorMapCommand(_params.colorMap)+std::string("',True);");
- cmd += std::string("pvs.Render();");
+ pushAndExecPyLine( "import pvsimple as pvs;");
+ pushAndExecPyLine( getRenderViewCommand(_params.viewMode) ); // define __viewXXX
- cmd += getResetCameraCommand();
+ oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str());
- //std::cerr << "Python command:" << std::endl;
- //std::cerr << cmd << std::endl;
- PyRun_SimpleString(cmd.c_str());
- // Retrieve Python object for internal storage:
- PyObject* obj = getPythonObjectFromMain("__obj1");
- PyObject* disp = getPythonObjectFromMain("__disp1");
- pushInternal(obj, disp);
+ oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << disp << " = pvs.Show(" << obj << ", " << view << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << disp << ".SetScalarBarVisibility(" << view << ", True);";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << disp << ".RescaleTransferFunctionToDataRangeOverTime();";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "__lut = pvs.GetColorTransferFunction('" << _fieldName << "');";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "__lut.ApplyPreset('" << getColorMapCommand(_params.colorMap) << "',True);";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ pushAndExecPyLine(getResetCameraCommand());
+ pushAndExecPyLine("pvs.Render();");
- PyGILState_Release(_gil_state);
+ // Retrieve Python object for internal storage:
+ PyObject* p_obj = getPythonObjectFromMain(obj.c_str());
+ PyObject* p_disp = getPythonObjectFromMain(disp.c_str());
+ pushPyObjects(std::make_pair(obj_id, p_obj), std::make_pair(disp_id, p_disp));
}
void
void
MEDPresentationSlices::internalGeneratePipeline()
{
- PyGILState_STATE _gil_state = PyGILState_Ensure();
-
- std::string cmd = std::string("import pvsimple as pvs;");
- cmd += getRenderViewCommand(_params.viewMode); // define __view1
-
- cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
- cmd += std::string("__slice1 = pvs.Slice(Input=__obj1);");
- cmd += std::string("__disp1 = pvs.Show(__slice1, __view1);");
- cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
- cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
- cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
- cmd += std::string("pvs.Render();");
-
- cmd += getResetCameraCommand();
-
- //std::cerr << "Python command:" << std::endl;
- //std::cerr << cmd << std::endl;
- PyRun_SimpleString(cmd.c_str());
- // Retrieve Python object for internal storage:
- PyObject* obj = getPythonObjectFromMain("__slice1");
- PyObject* disp = getPythonObjectFromMain("__disp1");
- pushInternal(obj, disp);
-
- PyGILState_Release(_gil_state);
+// PyGILState_STATE _gil_state = PyGILState_Ensure();
+//
+// std::string cmd = std::string("import pvsimple as pvs;");
+// cmd += getRenderViewCommand(_params.viewMode); // define __view1
+//
+// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+// cmd += std::string("__slice1 = pvs.Slice(Input=__obj1);");
+// cmd += std::string("__disp1 = pvs.Show(__slice1, __view1);");
+// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
+// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+// cmd += std::string("pvs.Render();");
+//
+// cmd += getResetCameraCommand();
+//
+// //std::cerr << "Python command:" << std::endl;
+// //std::cerr << cmd << std::endl;
+// PyRun_SimpleString(cmd.c_str());
+// // Retrieve Python object for internal storage:
+// PyObject* obj = getPythonObjectFromMain("__slice1");
+// PyObject* disp = getPythonObjectFromMain("__disp1");
+// pushInternal(obj, disp);
+//
+// PyGILState_Release(_gil_state);
}
void
void
MEDPresentationVectorField::internalGeneratePipeline()
{
- PyGILState_STATE _gil_state = PyGILState_Ensure();
-
- std::string cmd = std::string("import pvsimple as pvs;");
- cmd += getRenderViewCommand(_params.viewMode); // define __view1
-
- cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
- cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);");
- cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
- cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
- cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
- cmd += std::string("__disp1.SetRepresentationType('3D Glyphs');");
- cmd += std::string("pvs.Render();");
-
- cmd += getResetCameraCommand();
-
- //std::cerr << "Python command:" << std::endl;
- //std::cerr << cmd << std::endl;
- PyRun_SimpleString(cmd.c_str());
- // Retrieve Python object for internal storage:
- PyObject* obj = getPythonObjectFromMain("__obj1");
- PyObject* disp = getPythonObjectFromMain("__disp1");
- pushInternal(obj, disp);
-
- PyGILState_Release(_gil_state);
+// PyGILState_STATE _gil_state = PyGILState_Ensure();
+//
+// std::string cmd = std::string("import pvsimple as pvs;");
+// cmd += getRenderViewCommand(_params.viewMode); // define __view1
+//
+// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');");
+// cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);");
+// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));");
+// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);");
+// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();");
+// cmd += std::string("__disp1.SetRepresentationType('3D Glyphs');");
+// cmd += std::string("pvs.Render();");
+//
+// cmd += getResetCameraCommand();
+//
+// //std::cerr << "Python command:" << std::endl;
+// //std::cerr << cmd << std::endl;
+// PyRun_SimpleString(cmd.c_str());
+// // Retrieve Python object for internal storage:
+// PyObject* obj = getPythonObjectFromMain("__obj1");
+// PyObject* disp = getPythonObjectFromMain("__disp1");
+// pushInternal(obj, disp);
+//
+// PyGILState_Release(_gil_state);
}
void
if (app && app->desktop()) {
connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(doubleClicked(const QModelIndex&)),
this, SLOT(onDblClick(const QModelIndex&)));
+ connect((QObject*) (getApp()->objectBrowser()->treeView()), SIGNAL(clicked(const QModelIndex&)),
+ this, SLOT(onClick(const QModelIndex&)));
}
// The following initializes the GUI widget and associated actions
MEDModule::addActionInPopupMenu(int actionId,const QString& menus,const QString& rule)
{
// _GBO_ for a fine customization of the rule (for example with a
- // test on the type of the selected object), see the LIGTH module:
+ // test on the type of the selected object), see the LIGHT module:
// implement "LightApp_Selection* createSelection() const;"
int parentId = -1;
QtxPopupMgr* mgr = this->popupMgr();
return _presentationController->getSelectedColorMap();
}
-void
-MEDModule::onDblClick(const QModelIndex& index)
+bool
+MEDModule::itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const
{
DataObjectList dol = getApp()->objectBrowser()->getSelected();
if (dol.isEmpty())
- return;
+ return false;
SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
if (!item)
- return;
+ return false;
SalomeApp_DataModel *model = dynamic_cast<SalomeApp_DataModel*>(dataModel());
if (!model)
- return;
+ return false;
if (item->componentDataType().toStdString() != "MED")
- return;
+ return false;
_PTR(SObject) obj = item->object();
_PTR(GenericAttribute) anAttribute;
if (! obj->FindAttribute(anAttribute, "AttributeName"))
- return;
+ return false;
_PTR(AttributeName) attrName(anAttribute);
- std::string name = attrName->Value();
+ name = attrName->Value();
if (! obj->FindAttribute(anAttribute, "AttributeParameter"))
- return;
+ return false;
_PTR(AttributeParameter) attrParam(anAttribute);
if (! attrParam->IsSet(IS_PRESENTATION, PT_BOOLEAN)
|| ! attrParam->GetBool(IS_PRESENTATION)) { // Not a presentation
- return;
+ return false;
}
if (!attrParam->IsSet(FIELD_ID, PT_INTEGER))
+ return false;
+ fieldId = attrParam->GetInt(FIELD_ID);
+ if (!attrParam->IsSet(PRESENTATION_ID, PT_INTEGER))
+ return false;
+ presId = attrParam->GetInt(PRESENTATION_ID);
+ return true;
+}
+
+void
+MEDModule::onClick(const QModelIndex & index)
+{
+ int fieldId, presId;
+ std::string name;
+ if (!itemClickGeneric(index, name, fieldId, presId))
+ return;
+
+ STDLOG("Presentation selection (should activate view): NOT IMPLEMENTED YET");
+ STDLOG(" Presention infos:");
+ std::ostringstream oss;
+ oss << fieldId << " / " << presId;
+ STDLOG(" - Field id / pres id: " + oss.str());
+ STDLOG(" - Presentation name: " + name);
+
+ // TODO: activate corresponding view
+
+}
+
+void
+MEDModule::onDblClick(const QModelIndex& index)
+{
+ int fieldId, presId;
+ std::string name;
+ if (!itemClickGeneric(index, name, fieldId, presId))
return;
- int fieldId = attrParam->GetInt(FIELD_ID);
STDLOG("Presentation edition: NOT IMPLEMENTED YET");
STDLOG(" Presention infos:");
- STDLOG(" - Component: " + item->componentDataType().toStdString());
- STDLOG(" - Item entry: " + item->entry().toStdString());
- STDLOG(" - Item name: " + item->name().toStdString());
+// STDLOG(" - Component: " + item->componentDataType().toStdString());
+// STDLOG(" - Item entry: " + item->entry().toStdString());
+// STDLOG(" - Item name: " + item->name().toStdString());
std::ostringstream oss;
oss << fieldId;
STDLOG(" - Field id: " + oss.str());
virtual bool activateModule(SUIT_Study* theStudy);
virtual bool deactivateModule(SUIT_Study* theStudy);
virtual void onDblClick(const QModelIndex& index);
+ virtual void onClick(const QModelIndex& index);
void createModuleWidgets();
void createModuleActions();
void initToolbars();
+ bool itemClickGeneric(const QModelIndex & index, std::string & name, int & fieldId, int & presId) const;
+
static void init();
private:
<source>ICO_MEDPresentationPointSprite_CLASSIC</source>
<translation>visu_points16.png</translation>
</message>
+ <message>
+ <source>ICO_DELETE_PRESENTATION</source>
+ <translation>close.png</translation>
+ </message>
</context>
</TS>
<source>TIP_PRESENTATION_POINT_SPRITE</source>
<translation>Point sprite</translation>
</message>
+ <message>
+ <source>LAB_DELETE_PRESENTATION</source>
+ <translation>Delete presentation</translation>
+ </message>
+ <message>
+ <source>TIP_DELETE_PRESENTATION</source>
+ <translation>Delete selected presentation</translation>
+ </message>
<message>
<source>MENU_PRESENTATIONS</source>
<translation>Presentations</translation>
static const int OPTIONS_VIEW_MODE_NEW_LAYOUT_ID = 946;
static const int OPTIONS_VIEW_MODE_SPLIT_VIEW_ID = 947;
-PresentationController::PresentationController(MEDModule* salomeModule)
+PresentationController::PresentationController(MEDModule* salomeModule) :
+ _salomeModule(salomeModule),
+ _studyEditor(salomeModule->getStudyEditor())
{
STDLOG("Creating a PresentationController");
- _salomeModule = salomeModule;
- _studyEditor = _salomeModule->getStudyEditor();
_widgetPresentationParameters = new WidgetPresentationParameters();
_salomeModule->createTool(actionId, presentationToolbarId);
_salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, 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);
+// _salomeModule->createTool(actionId, presentationToolbarId);
+// _salomeModule->action(actionId)->setIconVisibleInMenu(true);
+ _salomeModule->createMenu(actionId, presentationMenuId);
+
}
MEDCALC::MEDPresentationViewMode
this->visualize(PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE);
}
+void
+PresentationController::OnDeletePresentation()
+{
+ // 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 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);
+ // 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
+ }
+}
+
void
PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
{
EVENT_VIEW_OBJECT_POINT_SPRITE,
EVENT_VIEW_OBJECT_SCALAR_MAP,
EVENT_VIEW_OBJECT_SLICES,
- EVENT_VIEW_OBJECT_VECTOR_FIELD
+ EVENT_VIEW_OBJECT_VECTOR_FIELD,
+ EVENT_DELETE_PRESENTATION
};
int eventtype;
XmedDataObject* objectdata;
void OnVisualizeSlices();
void OnVisualizeDeflectionShape();
void OnVisualizePointSprite();
+
+ void OnDeletePresentation();
+
void processWorkspaceEvent(const MEDCALC::MedEvent*);
private:
private:
MEDModule* _salomeModule;
SALOME_AppStudyEditor* _studyEditor; // borrowed to MEDModule
+
QDockWidget *_dockWidget;
WidgetPresentationParameters* _widgetPresentationParameters;
};
commands += QString("presentation_id");
_consoleDriver->exec(commands);
}
+ else if ( event->eventtype == PresentationEvent::EVENT_DELETE_PRESENTATION ) {
+ QStringList commands;
+ commands += QString("medcalc.RemovePresentation(%1)").arg(dataObject->getPresentationId());
+ _consoleDriver->exec(commands);
+ }
else {
STDLOG("The event "<<event->eventtype<<" is not implemented yet");
}
// =================================================================
//
-XmedDataObject::XmedDataObject() : DataObject() {
+XmedDataObject::XmedDataObject() : DataObject(), _presId(-1) {
}
/*! This function specified the localization of the object in the
return &_fieldHandler;
}
+void XmedDataObject::setPresentationId(int presId) {
+ _presId = presId;
+}
+
+int XmedDataObject::getPresentationId() const { return _presId; }
+
+
/*!
* This function implements the convention for displaying a fieldname
* characterized by its spatial discretisation type.
void setFieldHandler(MEDCALC::FieldHandler fieldHandler);
MEDCALC::FieldHandler * getFieldHandler();
+ void setPresentationId(int presId);
+ int getPresentationId() const;
+
private:
MEDCALC::FieldHandler _fieldHandler;
+ int _presId;
string _getTypedFieldLabel();
};