EVENT_REMOVE_PRESENTATION,
EVENT_PLAY_TEST,
EVENT_QUIT_SALOME,
+ EVENT_ERROR,
EVENT_UNKNOWN
};
long dataId;
string filename;
long presentationId;
+ string msg;
};
interface MEDEventListener: SALOME::GenericObj {
const MEDPresentationViewMode VIEW_MODE_DEFAULT = VIEW_MODE_REPLACE;
const MEDPresentationColorMap COLOR_MAP_DEFAULT = COLOR_MAP_BLUE_TO_RED_RAINBOW;
const MEDPresentationScalarBarRange SCALAR_BAR_RANGE_DEFAULT = SCALAR_BAR_ALL_TIMESTEPS;
- //const ScalarBarRange SCALAR_BAR_RANGE_DEFAULT = ;
const long SCALAR_BAR_RANGE_VAL_MIN_DEFAULT = -1;
const long SCALAR_BAR_RANGE_VAL_MAX_DEFAULT = -1;
const string DISPLAY_DEFAULT = DISPLAY_EUCLIDEAN_NORM;
};
// A contour is an isoline in 2D and an isosurface in 3D
-// struct ContourParameters {
+ struct ContourParameters { // Contour are only for scalar fields
+ long fieldHandlerId;
+ MEDPresentationScalarBarRange scalarBarRange;
+ MEDPresentationColorMap colorMap;
+ long nbContours;
+ };
+
+// struct VectorFieldParameters {
// long fieldHandlerId;
// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
-// ScalarBarRange scalarBarRange;
+// MEDPresentationScalarBarRange scalarBarRange;
// MEDPresentationColorMap colorMap;
-// long nbContours;
-// };
-//
-// struct VectorFieldParameters {
-// long fieldHandlerId;
// };
//
// struct SlicesParameters {
// long fieldHandlerId;
+// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
+// MEDPresentationScalarBarRange scalarBarRange;
+// MEDPresentationColorMap colorMap;
// SliceOrientation orientation;
// long nbSlices;
// };
// struct PointSpriteParameters {
// long fieldHandlerId;
// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name
-// ScalarBarRange scalarBarRange;
+// MEDPresentationScalarBarRange scalarBarRange;
// MEDPresentationColorMap colorMap;
// };
interface MEDPresentationManager : SALOME::GenericObj
{
long makeScalarMap(in ScalarMapParameters params, in MEDPresentationViewMode viewMode);
-// long makeContour(in ContourParameters params, in MEDPresentationViewMode viewMode);
+ long makeContour(in ContourParameters params, in MEDPresentationViewMode viewMode)
+ raises (SALOME::SALOME_Exception);
// long makeVectorField(in VectorFieldParameters params, in MEDPresentationViewMode viewMode);
// long makeSlices(in SlicesParameters params, in MEDPresentationViewMode viewMode);
// long makeDeflectionShape(in DeflectionShapeParameters params, in MEDPresentationViewMode viewMode);
long getPresentationIntProperty(in long presId, in string propName);
ScalarMapParameters getScalarMapParameters(in long presId);
+ ContourParameters getContourParameters(in long presId);
void updateScalarMap(in long presId, in ScalarMapParameters params);
-// void updateContour(in long presId, in ContourParameters params);
+ void updateContour(in long presId, in ContourParameters params);
// void updateVectorField(in long presId, in VectorFieldParameters params);
// void updateSlices(in long presId, in SlicesParameters params);
// void updateDeflectionShape(in long presId, in DeflectionShapeParameters params);
// Low level ParaVis dump
string getParavisDump(in long presId);
-
+
// MEDPresentationViewMode getPresentationViewMode(in long presId);
PresentationsList getAllPresentations();
MEDPresentation.cxx
# presentations
MEDPresentationScalarMap.cxx
-# MEDPresentationContour.cxx
+ MEDPresentationContour.cxx
# MEDPresentationVectorField.cxx
# MEDPresentationSlices.cxx
# MEDPresentationDeflectionShape.cxx
_colorMap(colorMap),
_sbRange(sbRange),
_renderViewPyId(-1), // will be set by getRenderViewCommand()
- _objId(GeneratePythonId()),
- _dispId(_objId), _lutId(_objId),
_globalDict(0)
{
MEDCALC::MEDDataManager_ptr dataManager(MEDFactoryClient::getDataManager());
setIntProperty(MEDPresentation::PROP_NB_COMPONENTS, 0);
setIntProperty(MEDPresentation::PROP_SELECTED_COMPONENT, 0);
- setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast<int>(MEDCALC::COLOR_MAP_DEFAULT));
- setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast<int>(MEDCALC::SCALAR_BAR_RANGE_DEFAULT));
+ setIntProperty(MEDPresentation::PROP_COLOR_MAP, static_cast<int>(colorMap));
+ setIntProperty(MEDPresentation::PROP_SCALAR_BAR_RANGE, static_cast<int>(sbRange));
+
+ // Python variables:
+ int id = GeneratePythonId();
+ std::ostringstream oss_o, oss_d, oss_l, oss_s;
+ oss_o << "__obj" << id;
+ oss_s << "__srcObj" << id;
+ oss_d << "__disp" << id;
+ oss_l << "__lut" << id;
+ _objVar = oss_o.str();
+ _srcObjVar = oss_s.str();
+ _dispVar = oss_d.str();
+ _lutVar = oss_l.str();
}
MEDPresentation::~MEDPresentation()
STDLOG("~MEDPresentation(): clear display");
{
MEDPyLockWrapper lock;
- std::ostringstream oss_o, oss_v, oss;
- oss_o << "__obj" << _objId;
+ std::ostringstream oss_v, oss;
oss_v << "__view" << _renderViewPyId;
- oss << "pvs.Hide(" << oss_o.str() << ", view=" << oss_v.str() << ");";
+ oss << "pvs.Hide(" << _objVar << ", view=" << oss_v.str() << ");";
oss << "pvs.Render();";
PyRun_SimpleString(oss.str().c_str());
MEDPresentation::execPyLine(const std::string & lin)
{
MEDPyLockWrapper lock;
-// STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
+ STDLOG("@@@@ MEDPresentation::execPyLine() about to exec >> " << lin);
if(PyRun_SimpleString(lin.c_str()))
{
std::ostringstream oss;
STDLOG(oss.str());
throw KERNEL::createSalomeException(oss.str().c_str());
}
-
}
void
}
}
+std::string
+MEDPresentation::getRenderViewVar() const
+{
+ std::ostringstream oss;
+ oss << "__view" << _renderViewPyId;
+ return oss.str();
+}
+
std::string
MEDPresentation::getRenderViewCommand() const
{
std::ostringstream oss, oss2;
- oss << "__view" << _renderViewPyId;
- std::string view(oss.str());
+ std::string view(getRenderViewVar());
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
std::string
MEDPresentation::getResetCameraCommand() const
{
- std::ostringstream oss;
- oss << "__view" << _renderViewPyId << ".ResetCamera();";
- return oss.str();
+ return getRenderViewVar() + ".ResetCamera();";
}
std::string
MEDPresentation::getComponentSelectionCommand() const
{
std::ostringstream oss, oss_l;
- oss_l << "__lut" << _lutId; std::string lut(oss_l.str());
+ std::string ret;
if (_selectedComponentIndex != -1)
{
- oss << lut << ".VectorMode = 'Component';\n";
- oss << lut << ".VectorComponent = " << _selectedComponentIndex << ";";
+ oss << _lutVar << ".VectorMode = 'Component';\n";
+ oss << _lutVar << ".VectorComponent = " << _selectedComponentIndex << ";";
}
else // Euclidean norm
{
- oss << lut << ".VectorMode = 'Magnitude';";
+ oss << _lutVar << ".VectorMode = 'Magnitude';";
}
return oss.str();
}
std::string
MEDPresentation::getColorMapCommand() const
{
- std::ostringstream oss, oss_l;
- oss_l << "__lut" << _lutId; std::string lut(oss_l.str());
+ std::string ret;
switch (_colorMap) {
case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW:
- oss << lut << ".ApplyPreset('Blue to Red Rainbow',True);";
+ ret = _lutVar + ".ApplyPreset('Blue to Red Rainbow',True);";
break;
case MEDCALC::COLOR_MAP_COOL_TO_WARM:
- oss << lut << ".ApplyPreset('Cool to Warm',True);";
+ ret = _lutVar + ".ApplyPreset('Cool to Warm',True);";
break;
default:
STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!");
throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!");
}
- return oss.str();
+ return ret;
}
std::string
MEDPresentation::getRescaleCommand() const
{
- std::ostringstream oss, oss_d;
- oss_d << "__disp" << _dispId; std::string disp(oss_d.str());
+ std::string ret;
switch(_sbRange)
{
case MEDCALC::SCALAR_BAR_ALL_TIMESTEPS:
- oss << disp << ".RescaleTransferFunctionToDataRangeOverTime();";
+ ret = _dispVar + ".RescaleTransferFunctionToDataRangeOverTime();";
break;
case MEDCALC::SCALAR_BAR_CURRENT_TIMESTEP:
- oss << disp << ".RescaleTransferFunctionToDataRange(False);";
+ ret = _dispVar + ".RescaleTransferFunctionToDataRange(False);";
break;
default:
STDLOG("MEDPresentation::getRescaleCommand(): invalid range!");
throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!");
}
- return oss.str();
+ return ret;
}
int
MEDPresentation::activateView()
{
MEDPyLockWrapper lock;
-
- std::ostringstream oss;
- oss << "pvs.SetActiveView(__view" << _renderViewPyId << ");";
- pushAndExecPyLine(oss.str());
+ pushAndExecPyLine("pvs.SetActiveView(" + getRenderViewVar() + ");");
}
MEDPresentation::fillAvailableFieldComponents()
{
MEDPyLockWrapper lock; // GIL!
-
- std::ostringstream oss_o;
- oss_o << "__obj" << _objId; std::string obj(oss_o.str());
std::string typ;
if(_fieldType == "CELLS") {
}
std::ostringstream oss;
- oss << "__nbCompo = " << obj << "." << typ << ".GetArray('" << _fieldName << "').GetNumberOfComponents();";
+ oss << "__nbCompo = " << _srcObjVar << "." << typ << ".GetArray('" << _fieldName << "').GetNumberOfComponents();";
execPyLine(oss.str());
PyObject* p_obj = getPythonObjectFromMain("__nbCompo");
long nbCompo;
for (long i = 0; i<nbCompo; i++)
{
std::ostringstream oss2;
- oss2 << "__compo = " << obj << "." << typ << ".GetArray('" << _fieldName << "').GetComponentName(" << i << ");";
+ oss2 << "__compo = " << _srcObjVar << "." << typ << ".GetArray('" << _fieldName << "').GetComponentName(" << i << ");";
execPyLine(oss2.str());
PyObject* p_obj = getPythonObjectFromMain("__compo");
std::string compo;
const MEDCALC::MEDPresentationColorMap colorMap,
const MEDCALC::MEDPresentationScalarBarRange sbRange);
std::string getRenderViewCommand() const;
+ std::string getRenderViewVar() const;
std::string getResetCameraCommand() const;
std::string getComponentSelectionCommand() const;
///! Identifier (in the Python dump) of the render view
int _renderViewPyId;
- ///! ParaView object ID in the Python scripting commands
- int _objId;
- ///! ParaView display ID in the Python scripting commands
- int _dispId;
- ///! ParaView LUT ID in the Python scripting commands
- int _lutId;
+ ///! ParaView object variable in the Python scripting commands (source object)
+ std::string _srcObjVar;
+ ///! ParaView object variable in the Python scripting commands (final object on which all display commands are done)
+ std::string _objVar;
+ ///! ParaView display variable in the Python scripting commands
+ std::string _dispVar;
+ ///! ParaView LUT variable in the Python scripting commands
+ std::string _lutVar;
private:
///! Pipeline elements
#include "MEDPresentationContour.hxx"
+#include <SALOME_KernelServices.hxx>
+#undef LOG // should be fixed in KERNEL - double definition
+#include <Basics_Utils.hxx>
+
+#include <sstream>
+
+const std::string MEDPresentationContour::TYPE_NAME = "MEDPresentationContour";
const std::string MEDPresentationContour::PROP_NB_CONTOUR = "nbContour";
+MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters& params,
+ const MEDCALC::MEDPresentationViewMode viewMode) :
+ MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange),
+ _params(params)
+{
+ setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours);
+}
+
+std::string
+MEDPresentationContour::getContourCommand() const
+{
+ std::ostringstream oss1;
+
+ oss1 << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();\n";
+ oss1 << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");\n";
+ oss1 << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];\n";
+ return oss1.str();
+}
+
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);
+ MEDPresentation::internalGeneratePipeline();
+
+ MEDPyLockWrapper lock;
+
+ std::ostringstream oss_o, oss;
+ std::string view(getRenderViewVar());
+
+ oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
+ pushAndExecPyLine(oss.str()); oss.str("");
+
+ // Populate internal array of available components:
+ fillAvailableFieldComponents();
+ if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) > 1)
+ {
+ const char * msg = "Contour presentation only works for scalar field!"; // this message will appear in GUI too
+ STDLOG(msg);
+ throw KERNEL::createSalomeException(msg);
+ }
+
+ pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
+
+ if(_fieldType == "CELLS")
+ {
+ // In case of a CELLS field need to convert to POINT field, and update source
+ STDLOG("Applying CellDatatoPointData filter");
+ std::ostringstream oss2, oss4;
+ // Apply Cell data to point data:
+ oss2 << "__obj" << GeneratePythonId();
+ oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ // Now the source becomes the result of the CellDatatoPointData:
+ _srcObjVar = oss2.str();
+ }
+ oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];";
+ pushAndExecPyLine(oss.str()); oss.str("");
+
+ // Set number of contours
+ pushAndExecPyLine(getContourCommand());
+
+ oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << "pvs.ColorBy(" << _dispVar << ", ('POINTS', '" << _fieldName << "'));"; // necessarily POINTS
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << getRescaleCommand();
+ pushAndExecPyLine(oss.str()); oss.str("");
+ oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ pushAndExecPyLine(getColorMapCommand()); oss.str("");
+ pushAndExecPyLine(getResetCameraCommand());
+ pushAndExecPyLine("pvs.Render();");
}
void
MEDPresentationContour::updatePipeline(const MEDCALC::ContourParameters& params)
{
- // :TODO:
+ if (params.fieldHandlerId != _params.fieldHandlerId)
+ throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
+
+ if (params.scalarBarRange != _params.scalarBarRange)
+ updateScalarBarRange<MEDPresentationContour, MEDCALC::ContourParameters>(params.scalarBarRange);
+ if (params.colorMap != _params.colorMap)
+ updateColorMap<MEDPresentationContour, MEDCALC::ContourParameters>(params.colorMap);
+
+ if (params.nbContours != _params.nbContours)
+ updateNbContours(params.nbContours);
+}
+
+void
+MEDPresentationContour::updateNbContours(const int nbContours)
+{
+ _params.nbContours = nbContours;
+
+ // GUI helper:
+ setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, nbContours);
+
+ // Update the pipeline:
+ {
+ MEDPyLockWrapper lock;
+ std::string cmd = getContourCommand();
+ pushAndExecPyLine(cmd);
+ pushAndExecPyLine("pvs.Render();");
+ }
}
class MEDCALC_EXPORT MEDPresentationContour : public MEDPresentation
{
public:
+ static const std::string TYPE_NAME;
static const std::string PROP_NB_CONTOUR;
- MEDPresentationContour(const MEDCALC::ContourParameters& params) :
- MEDPresentation(params.fieldHandlerId, "MEDPresentationContour"), _params(params)
- {}
+ MEDPresentationContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode);
virtual ~MEDPresentationContour() {}
void updatePipeline(const MEDCALC::ContourParameters& params);
- MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
+// MEDCALC::MEDPresentationViewMode getViewMode() { return _params.viewMode; }
+
+ void getParameters(MEDCALC::ContourParameters & params) const { params = _params; } ;
+ void setParameters(const MEDCALC::ContourParameters & params) { _params = params; } ;
protected:
+ void updateNbContours(const int nbContours);
virtual void internalGeneratePipeline();
+ std::string getContourCommand() const;
+
private:
MEDCALC::ContourParameters _params;
};
// presentations
#include "MEDPresentationScalarMap.hxx"
-//#include "MEDPresentationContour.hxx"
-//#include "MEDPresentationVectorField.hxx"
+#include "MEDPresentationContour.hxx"
//#include "MEDPresentationSlices.hxx"
+//#include "MEDPresentationVectorField.hxx"
//#include "MEDPresentationDeflectionShape.hxx"
//#include "MEDPresentationPointSprite.hxx"
return _makePresentation<MEDPresentationScalarMap>(params, viewMode);
}
-//MEDPresentation::TypeID
-//MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params)
-//{
-// return _makePresentation<MEDPresentationContour>(params);
-//}
-//
+MEDPresentation::TypeID
+MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, const MEDCALC::MEDPresentationViewMode viewMode)
+{
+ return _makePresentation<MEDPresentationContour>(params, viewMode);
+}
+
//MEDPresentation::TypeID
//MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params)
//{
return tmp._retn();
}
+MEDCALC::ContourParameters
+MEDPresentationManager_i::getContourParameters(MEDPresentation::TypeID presentationID)
+{
+ MEDCALC::ContourParameters p;
+ _getParameters<MEDPresentationContour>(presentationID, p);
+ return p;
+}
+
void
MEDPresentationManager_i::updateScalarMap(MEDPresentation::TypeID presentationID, const MEDCALC::ScalarMapParameters& params)
{
return _updatePresentation<MEDPresentationScalarMap>(presentationID, params);
}
-//void
-//MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
-//{
-// return _updatePresentation<MEDPresentationContour>(presentationID, params);
-//}
-//
+void
+MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, const MEDCALC::ContourParameters& params)
+{
+ return _updatePresentation<MEDPresentationContour>(presentationID, params);
+}
+
//void
//MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params)
//{
presentation->activateView();
_activeViewPythonId = presentation->getPyViewID();
+ STDLOG("Activated view " << _activeViewPythonId);
return true;
}
static MEDPresentationManager_i* getInstance();
MEDCALC_EXPORT MEDPresentation::TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&, const MEDCALC::MEDPresentationViewMode);
-// MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&, const MEDCALC::MEDPresentationViewMode);
+ MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&, const MEDCALC::MEDPresentationViewMode);
// MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&);
// MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&);
// MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&);
MEDCALC_EXPORT CORBA::Long getPresentationIntProperty(MEDPresentation::TypeID presentationID, const char* propName);
MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID);
+ MEDCALC_EXPORT MEDCALC::ContourParameters getContourParameters(MEDPresentation::TypeID presentationID);
MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&);
-// MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&);
+ MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&);
// MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&);
// MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&);
// MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&);
int activeViewId = getActiveViewPythonId();
// Replace = Remove then add
+ std::vector<int> to_del;
if (viewMode == MEDCALC::VIEW_MODE_REPLACE)
{
// Remove all presentations from this view:
+ STDLOG("About to remove all presentations from view " << activeViewId);
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
_presentations.insert( std::pair<MEDPresentation::TypeID, MEDPresentation *>(newID, presentation) );
presentation->generatePipeline();
+
+ // If generatePipeline didn't throw, we can actually remove presentations to be deleted:
+ for (std::vector<int>::const_iterator it2 = to_del.begin(); it2 != to_del.end(); ++it2)
+ removePresentation(*it2);
+
// Make the view holding the newly created presentation the active one:
activateView(newID);
return newID;
MEDPyLockWrapper 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());
- oss_v << "__view" << _renderViewPyId; std::string view(oss_v.str());
+ std::ostringstream oss;
+ std::string view(getRenderViewVar());
pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX
- oss << obj << " = pvs.MEDReader(FileName='" << _fileName << "');";
+ oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');";
pushAndExecPyLine(oss.str()); oss.str("");
// Populate internal array of available components:
// dumpIntProperties();
// dumpStringProperties();
- oss << disp << " = pvs.Show(" << obj << ", " << view << ");";
+ pushAndExecPyLine(_objVar + " = " + _srcObjVar);
+
+ oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");";
pushAndExecPyLine(oss.str()); oss.str("");
- oss << "pvs.ColorBy(" << disp << ", ('" << _fieldType << "', '" << _fieldName << "'));";
+ oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));";
pushAndExecPyLine(oss.str()); oss.str("");
- oss << disp << ".SetScalarBarVisibility(" << view << ", True);";
+ oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);";
pushAndExecPyLine(oss.str()); oss.str("");
oss << getRescaleCommand();
pushAndExecPyLine(oss.str()); oss.str("");
- oss << lut << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
+ oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');";
pushAndExecPyLine(oss.str()); oss.str("");
pushAndExecPyLine(getColorMapCommand()); oss.str("");
pushAndExecPyLine(getResetCameraCommand());
if (params.fieldHandlerId != _params.fieldHandlerId)
throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
- if (params.displayedComponent != _params.displayedComponent)
- updateComponent<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(std::string(params.displayedComponent));
+ if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
+ {
+ STDLOG("about to updateCompo in scalar map");
+ STDLOG("from param " << params.displayedComponent);
+ STDLOG("from intern " << _params.displayedComponent);
+ updateComponent<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(std::string(params.displayedComponent));
+ }
if (params.scalarBarRange != _params.scalarBarRange)
updateScalarBarRange<MEDPresentationScalarMap, MEDCALC::ScalarMapParameters>(params.scalarBarRange);
if (params.colorMap != _params.colorMap)
XmedDataModel.cxx
MEDWidgetHelper.cxx
MEDWidgetHelperScalarMap.cxx
+ MEDWidgetHelperContour.cxx
)
IF(SALOME_MED_WITH_QTTESTING)
ProcessingController.hxx
MEDWidgetHelper.hxx
MEDWidgetHelperScalarMap.hxx
+ MEDWidgetHelperContour.hxx
)
IF(SALOME_MED_WITH_QTTESTING)
--- /dev/null
+// Copyright (C) 2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MEDWidgetHelperContour.hxx"
+#include "MEDPresentationContour.hxx" // from component side.
+#include "PresentationController.hxx"
+
+#include <Basics_Utils.hxx>
+
+#include <sstream>
+
+MEDWidgetHelperContour::MEDWidgetHelperContour(const PresentationController * presController,
+ MEDCALC::MEDPresentationManager_ptr presManager, int presId,
+ const std::string & presName, WidgetPresentationParameters * paramW):
+ MEDWidgetHelper(presController, presManager, presId, presName, paramW),
+ _nbContours(-1)
+{}
+
+MEDWidgetHelperContour::~MEDWidgetHelperContour()
+{}
+
+void MEDWidgetHelperContour::loadParametersFromEngine()
+{
+ MEDWidgetHelper::loadParametersFromEngine();
+ _nbContours = _presManager->getPresentationIntProperty(_presId, MEDPresentationContour::PROP_NB_CONTOUR.c_str());
+}
+
+void MEDWidgetHelperContour::udpateWidget()
+{
+ MEDWidgetHelper::udpateWidget();
+ STDLOG("MEDWidgetHelperContour::udpateWidget() nbContour is " << _nbContours);
+
+ // Contour presentation needs the number of contours
+// _paramWidget->setComponents(_allCompos, _selectedCompo);
+ _paramWidget->setNbContour(_nbContours);
+
+ // Connect combo box changes
+ QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+ _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
+// QObject::connect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
+ QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) );
+}
+
+void MEDWidgetHelperContour::releaseWidget()
+{
+ MEDWidgetHelper::releaseWidget();
+
+ QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+ _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
+// QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) );
+ QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) );
+}
+
+void MEDWidgetHelperContour::onNbContourChanged(int nbContour)
+{
+ STDLOG("MEDWidgetHelperContour::onNbContourChanged");
+ PresentationEvent* event = new PresentationEvent();
+ event->eventtype = PresentationEvent::EVENT_CHANGE_NB_CONTOUR;
+ event->presentationId = _presId;
+ event->anInteger = nbContour;
+
+ emit presentationUpdateSignal(event); // --> PresentationController::processPresentationEvent
+}
+
--- /dev/null
+// Copyright (C) 2016 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_
+#define SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_
+
+#include "MEDWidgetHelper.hxx"
+
+class PresentationController;
+
+class MEDWidgetHelperContour: public MEDWidgetHelper
+{
+ Q_OBJECT
+
+public:
+ MEDWidgetHelperContour(const PresentationController* presController,
+ MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName,
+ WidgetPresentationParameters * paramW);
+ virtual ~MEDWidgetHelperContour();
+
+ virtual void udpateWidget();
+ virtual void releaseWidget();
+
+ virtual std::string getPythonTag() const { return "Contour"; }
+
+protected slots:
+ void onNbContourChanged(int nbContour);
+
+protected:
+ virtual void loadParametersFromEngine();
+
+private:
+ int _nbContours;
+};
+
+#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERCONTOUR_HXX_ */
#define SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_
#include "MEDWidgetHelper.hxx"
-#include <QComboBox>
class PresentationController;
virtual void releaseWidget();
virtual std::string getPythonTag() const { return "ScalarMap"; }
-
-protected:
-
-
};
#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ */
#include "MEDPresentationManager_i.hxx"
#include "XmedConsoleDriver.hxx"
-#include "MEDWidgetHelperScalarMap.hxx"
#include "MEDPresentationScalarMap.hxx"
+#include "MEDPresentationContour.hxx"
+
+#include "MEDWidgetHelperScalarMap.hxx"
+#include "MEDWidgetHelperContour.hxx"
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
MEDCALC::MEDPresentationManager_ptr PresentationController::_presManager;
PresentationController::PresentationController(MEDModule* salomeModule) :
- _salomeModule(salomeModule),
- _consoleDriver(0),
- _studyEditor(salomeModule->getStudyEditor()),
- _presHelperMap(),
- _currentWidgetHelper(0)
+ _salomeModule(salomeModule),
+ _consoleDriver(0),
+ _studyEditor(salomeModule->getStudyEditor()),
+ _presHelperMap(),
+ _currentWidgetHelper(0)
{
STDLOG("Creating a PresentationController");
// 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&) ) );
+ this, SLOT(onPresentationSelected(int , const QString&, const QString&) ) );
}
PresentationController::~PresentationController()
// Read value from preferences and suffix name to select icon theme
int theme = mgr->integerValue("MEDCalc", "icons");
if (theme == 0) {
- return name + "_MODERN";
+ return name + "_MODERN";
} else if (theme == 1) {
- return name + "_CLASSIC";
+ return name + "_CLASSIC";
}
return name + "_DEFAULT";
}
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->createTool(actionId, presentationToolbarId);
+ // _salomeModule->action(actionId)->setIconVisibleInMenu(true);
_salomeModule->createMenu(actionId, presentationMenuId);
//
PresentationController::getSelectedViewMode() const
{
if (_salomeModule->action(OPTIONS_VIEW_MODE_REPLACE_ID)->isChecked()) {
- return MEDCALC::VIEW_MODE_REPLACE;
+ return MEDCALC::VIEW_MODE_REPLACE;
}
else if (_salomeModule->action(OPTIONS_VIEW_MODE_OVERLAP_ID)->isChecked()) {
- return MEDCALC::VIEW_MODE_OVERLAP;
+ return MEDCALC::VIEW_MODE_OVERLAP;
}
else if (_salomeModule->action(OPTIONS_VIEW_MODE_NEW_LAYOUT_ID)->isChecked()) {
- return MEDCALC::VIEW_MODE_NEW_LAYOUT;
+ return MEDCALC::VIEW_MODE_NEW_LAYOUT;
}
else if (_salomeModule->action(OPTIONS_VIEW_MODE_SPLIT_VIEW_ID)->isChecked()) {
- return MEDCALC::VIEW_MODE_SPLIT_VIEW;
+ return MEDCALC::VIEW_MODE_SPLIT_VIEW;
}
// Should not happen
STDLOG("Strange!! No matching view mode found - returning VIEW_MODE_REPLACE.");
// visualisation using the tui command (so that the user can see how
// 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 = getIntParamFromStudyEditor(soField, FIELD_ID);
- if (fieldId < 0) // is it a field serie ?
- {
- 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)
- continue;
- MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
- if (fieldHandlerList->length() < 0)
- continue;
- // For a field series, get the first real field entry:
- MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
- fieldId = fieldHandler.id;
- }
+ SALOMEDS::SObject_var soField = listOfSObject->at(i);
+ int fieldId = getIntParamFromStudyEditor(soField, FIELD_ID);
+ if (fieldId < 0) // is it a field serie ?
+ {
+ 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)
+ continue;
+ MEDCALC::FieldHandlerList* fieldHandlerList = MEDFactoryClient::getDataManager()->getFieldListInFieldseries(fieldSeriesId);
+ if (fieldHandlerList->length() < 0)
+ continue;
+ // For a field series, get the first real field entry:
+ MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[0];
+ fieldId = fieldHandler.id;
+ }
- MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
- if (! fieldHandler) {
- QMessageBox::warning(_salomeModule->getApp()->desktop(),
- tr("Operation not allowed"),
- tr("No field is defined"));
- return;
- }
+ MEDCALC::FieldHandler* fieldHandler = MEDFactoryClient::getDataManager()->getFieldHandler(fieldId);
+ if (! fieldHandler) {
+ QMessageBox::warning(_salomeModule->getApp()->desktop(),
+ tr("Operation not allowed"),
+ tr("No field is defined"));
+ return;
+ }
- PresentationEvent* event = new PresentationEvent();
- event->eventtype = eventType;
- event->fieldHandler = fieldHandler;
- emit presentationSignal(event); // --> processPresentationEvent()
+ PresentationEvent* event = new PresentationEvent();
+ event->eventtype = eventType;
+ event->fieldHandler = fieldHandler;
+ emit presentationSignal(event); // --> processPresentationEvent()
}
}
// 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 = 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;
-
- PresentationEvent* event = new PresentationEvent();
- event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
- event->presentationId = presId;
- emit presentationSignal(event); // --> processPresentationEvent()
+ 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;
+
+ PresentationEvent* event = new PresentationEvent();
+ event->eventtype = PresentationEvent::EVENT_DELETE_PRESENTATION;
+ event->presentationId = presId;
+ emit presentationSignal(event); // --> processPresentationEvent()
}
}
{
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";
+ 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();
}
{
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";
+ 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();
}
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();
+ 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
{
std::map<int, MEDWidgetHelper *>::const_iterator it =_presHelperMap.find(presId);
if (it != _presHelperMap.end())
- return (*it).second->getPythonTag();
+ return (*it).second->getPythonTag();
return "UNKNOWN";
}
void
PresentationController::processPresentationEvent(const PresentationEvent* event) {
// --> Send commands to SALOME Python console
+ QString viewMode = getViewModePython();
+ QString colorMap = getColorMapPython();
+ QString scalarBarRange = getScalarBarRangePython();
+ MEDCALC::FieldHandler* fieldHandler = event->fieldHandler;
+ QStringList commands;
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);
+ commands += QString("presentation_id = medcalc.MakeScalarMap(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
+ }
+ else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) {
+ commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)")
+ .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap);
+ commands += QString("presentation_id");
}
-// 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);
-// }
+ // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) {
+ // commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+ // commands += QString("presentation_id");
+ // }
+ // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) {
+ // commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+ // commands += QString("presentation_id");
+ // }
+ // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) {
+ // commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+ // commands += QString("presentation_id");
+ // }
+ // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) {
+ // commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode);
+ // commands += QString("presentation_id");
+ // }
// [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_CHANGE_NB_CONTOUR ) {
+ std::string typ = getPresTypeFromWidgetHelper(event->presentationId);
+ commands += QString("params = medcalc.GetContourParameters(%2)").arg(event->presentationId);
+ commands += QString("params.nbContours = %1").arg(event->anInteger);
+ commands += QString("medcalc.UpdateContour(%1, params)").arg(event->presentationId);
}
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");
+ STDLOG("The event "<<event->eventtype<<" is not implemented yet");
}
+ _consoleDriver->exec(commands);
}
MEDWidgetHelper *
MEDWidgetHelper * wh;
if (type == MEDPresentationScalarMap::TYPE_NAME)
wh = new MEDWidgetHelperScalarMap(this, _presManager, presId, name, _widgetPresentationParameters);
+ else if (type == MEDPresentationContour::TYPE_NAME)
+ wh = new MEDWidgetHelperContour(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:
+ // 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;
}
// 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
+ 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
}
}
PresentationController::updateTreeViewWithNewPresentation(long fieldId, long presentationId)
{
if (presentationId < 0) {
- std::cerr << "Unknown presentation\n";
- return;
+ std::cerr << "Unknown presentation\n";
+ return;
}
std::string name(_presManager->getPresentationStringProperty(presentationId, MEDPresentation::PROP_NAME.c_str()));
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::updateTreeViewForPresentationRemoval(long presentationId)
{
if (presentationId < 0) {
- std::cerr << "Unknown presentation\n";
- return;
+ std::cerr << "Unknown presentation\n";
+ return;
}
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(_salomeModule->application()->activeStudy());
}
}
else if ( event->type == MEDCALC::EVENT_REMOVE_PRESENTATION ) {
- updateTreeViewForPresentationRemoval(event->presentationId);
+ updateTreeViewForPresentationRemoval(event->presentationId);
}
}
EVENT_CHANGE_COMPONENT,
EVENT_CHANGE_COLORMAP,
- EVENT_CHANGE_TIME_RANGE
+ EVENT_CHANGE_TIME_RANGE,
+
+ EVENT_CHANGE_NB_CONTOUR
};
EventType eventtype;
#include <SUIT_ResourceMgr.h>
#include <QTimer>
+#include <QMessageBox>
/*!
* This class defines a DockWidget plugged in the SALOME application,
else if ( event->type == MEDCALC::EVENT_QUIT_SALOME ) {
emit workspaceSignal(event); // forward to TestController
}
+ else if ( event->type == MEDCALC::EVENT_ERROR ) {
+ std::string msg(event->msg);
+ QMessageBox::warning(_salomeModule->getApp()->desktop(), "Error", QString::fromStdString(msg));
+ }
}
/*!
this, SLOT(onComboScalarBarRangeIndexChanged(int)) );
QObject::connect(_ui.comboBoxColorMap, SIGNAL(currentIndexChanged(int)),
this, SLOT(onComboColorMapIndexChanged(int)) );
+ QObject::connect(_ui.spinBox, SIGNAL(valueChanged(int)),
+ this, SLOT(onSpinBoxValueChanged(int)) );
}
void
if (!_blockSig) emit comboScalarBarRangeIndexChanged(idx);
}
+void
+WidgetPresentationParameters::onSpinBoxValueChanged(int val)
+{
+ if (!_blockSig) emit spinBoxValueChanged(val);
+}
void
WidgetPresentationParameters::toggleWidget(bool show)
_blockSig = false;
}
+void
+WidgetPresentationParameters::setNbContour(int nbContour)
+{
+ if (nbContour <= 0)
+ {
+ //TODO throw?
+ STDLOG("WidgetPresentationParameters::setNbContour(): invalid number of contours!");
+ }
+
+ // Show the widget:
+ _ui.labelSpinBox->setText(tr("LAB_NB_CONTOUR"));
+ _ui.labelSpinBox->show();
+ _ui.spinBox->show();
+
+ _blockSig = true;
+ _ui.spinBox->setValue(nbContour);
+ _blockSig = false;
+}
+
+int WidgetPresentationParameters::getNbContour() const
+{
+ return _ui.spinBox->value();
+}
+
void
WidgetPresentationParameters::setScalarBarRange(MEDCALC::MEDPresentationScalarBarRange sbrange)
{
void setPresName(const std::string& name);
+ int getNbContour() const;
+ void setNbContour(int nbContour);
+
void toggleWidget(bool show);
bool isShown() const;
QComboBox * getComboBoxCompo();
void comboScalarBarRangeIndexChanged(int);
void comboColorMapIndexChanged(int);
void comboCompoIndexChanged(int);
+ void spinBoxValueChanged(int);
private slots:
void onComboScalarBarRangeIndexChanged(int);
void onComboColorMapIndexChanged(int);
void onComboCompoIndexChanged(int);
+ void onSpinBoxValueChanged(int);
private:
Ui_WidgetPresentationParameters _ui; // instance of the class defined in ui_WidgetPresentationParameters.h
--- /dev/null
+# Copyright (C) 2016 CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import os
+from time import sleep
+
+import medcalc
+medcalc.medconsole.setConsoleGlobals(globals())
+import MEDCALC
+from medcalc.medconsole import accessField
+
+from medcalc_testutils import GetMEDFileDirTUI
+
+datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med")
+source_id = medcalc.LoadDataSource(datafile)
+
+# Field 0 = CONCENTRATION_ELEM_DOM (ON_CELLS) -> scalar
+presentation_id = medcalc.MakeContour(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+sleep(2)
+medcalc.RemovePresentation(presentation_id)
+sleep(2)
+
+# Field 55 = VITESSE_ELEM_DOM (ON_CELLS) -> vector field, contour should fail.
+try:
+ presentation_id = medcalc.MakeContour(accessField(55), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+ sys.exit(-1);
+except:
+ print "Contour failed as expected."
+sleep(2)
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
+import os
+from time import sleep
+
import medcalc
medcalc.medconsole.setConsoleGlobals(globals())
import MEDCALC
-
-from medcalc.medconsole import saveWorkspace, cleanWorkspace
-from medcalc.medconsole import putInWorkspace, removeFromWorkspace
from medcalc.medconsole import accessField
-from medcalc.medconsole import getEnvironment, ls, la
-
-import os
from medcalc_testutils import GetMEDFileDirTUI
datafile = os.path.join(GetMEDFileDirTUI(), "smooth_surface_and_field.med")
source_id = medcalc.LoadDataSource(datafile)
-presentation_id = medcalc.MakeScalarMap(accessField(source_id), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
-
+presentation_id = medcalc.MakeScalarMap(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW)
+sleep(2)
medcalc.RemovePresentation(presentation_id)
+sleep(2)
# Presentations
from medpresentation import MakeScalarMap
-#from medpresentation import MakeContour
+from medpresentation import MakeContour
#from medpresentation import MakeVectorField
#from medpresentation import MakeSlices
#from medpresentation import MakeDeflectionShape
from medpresentation import RemovePresentation
from medpresentation import GetScalarMapParameters
+from medpresentation import GetContourParameters
from medpresentation import UpdateScalarMap
+from medpresentation import UpdateContour
# Console commands
import medconsole
# that they could be used in another context than the FieldProxy instances
import MEDCALC
-def __notifyGui(eventType, dataId=-1, filename="", presentationId=-1):
- medEvent = MEDCALC.MedEvent(eventType, dataId, filename, presentationId)
+def __notifyGui(eventType, dataId=-1, filename="", presentationId=-1, msg=""):
+ medEvent = MEDCALC.MedEvent(eventType, dataId, filename, presentationId, msg)
if not eventListenerIsRunning(): return
# Notify the GUI of the update event
#
def notifyGui_termination():
__notifyGui(MEDCALC.EVENT_QUIT_SALOME)
+
+def notifyGui_error(msg):
+ __notifyGui(MEDCALC.EVENT_ERROR, msg=msg)
#
import medcalc
-import MEDCALC
-from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation
+import MEDCALC, SALOME
+from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation, notifyGui_error
__manager = medcalc.medcorba.factory.getPresentationManager()
# Create the presentation instance in CORBA engine
# The engine in turn creates the ParaView pipeline elements
params = MEDCALC.ScalarMapParameters(proxy.id, displayedComponent, scalarBarRange, colorMap)
- presentation_id = __manager.makeScalarMap(params, viewMode)
- notifyGui_addPresentation(proxy.id, presentation_id)
- return presentation_id
-#
+ try:
+ presentation_id = __manager.makeScalarMap(params, viewMode)
+ notifyGui_addPresentation(proxy.id, presentation_id)
+ return presentation_id
+ except SALOME.SALOME_Exception as e:
+ notifyGui_error("An error occured while creating the scalar map:\n" + e.details.text)
+ raise Exception(e.details.text)
+
+def MakeContour(proxy,
+ viewMode=MEDCALC.VIEW_MODE_DEFAULT,
+ displayedComponent=MEDCALC.DISPLAY_DEFAULT,
+ scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
+ colorMap=MEDCALC.COLOR_MAP_DEFAULT,
+ nbContours=MEDCALC.NB_CONTOURS_DEFAULT
+ ):
+ params = MEDCALC.ContourParameters(proxy.id, scalarBarRange, colorMap, nbContours)
+ try:
+ presentation_id = __manager.makeContour(params, viewMode)
+ notifyGui_addPresentation(proxy.id, presentation_id)
+ return presentation_id
+ except SALOME.SALOME_Exception as e:
+ notifyGui_error("An error occured while creating the contour:\n" + e.details.text)
+ raise Exception(e.details.text)
-#def MakeContour(proxy,
-# viewMode=MEDCALC.VIEW_MODE_DEFAULT,
-# displayedComponent=MEDCALC.DISPLAY_DEFAULT,
-# scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
-# colorMap=MEDCALC.COLOR_MAP_DEFAULT,
-# nbContours=MEDCALC.NB_CONTOURS_DEFAULT
-# ):
-# params = MEDCALC.ContourParameters(proxy.id, viewMode, displayedComponent, scalarBarRange, colorMap, nbContours)
-# presentation_id = __manager.makeContour(params)
-# notifyGui_addPresentation(proxy.id, presentation_id)
-# return presentation_id
##
#
#def MakeVectorField(proxy,
params = __manager.getScalarMapParameters(presentation_id)
return params
+def GetContourParameters(presentation_id):
+ # TODO: check that pres id is really a ScalarMap ...
+ params = __manager.getContourParameters(presentation_id)
+ return params
+
def UpdateScalarMap(presentation_id, params):
__manager.updateScalarMap(presentation_id, params)
+
+def UpdateContour(presentation_id, params):
+ __manager.updateContour(presentation_id, params)
+