}
void
-MEDPresentationSlices::setNumberOfSlices()
+MEDPresentationSlices::generateSlices()
{
- std::ostringstream oss1;
- // TODO
-// oss1 << _objVar << ".SliceType.Normal = " << norm << ";";
+ std::ostringstream oss;
+ int nbSlices = getIntProperty(MEDPresentationSlices::PROP_NB_SLICES);
+ std::string normal = getNormalVector();
+
+ oss << "import medcalc; __origins = medcalc.GetSliceOrigins(" << _srcObjVar << ", " << nbSlices << ", " << normal << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+ pushAndExecPyLine("__objLst = [];");
+ oss << "for sliceNum in range(" << nbSlices << "):\n";
+ oss << " obj = pvs.Slice(Input=" << _srcObjVar << ")\n";
+ oss << " obj.SliceType = 'Plane'\n";
+ oss << " obj.SliceType.Normal = " << normal << "\n";
+ oss << " obj.SliceType.Origin = __origins[sliceNum]\n";
+ oss << " __objLst.append(obj)\n\n";
+ pushAndExecPyLine(oss.str()); oss.str("");
+
+ oss << _objVar << " = pvs.GroupDatasets(Input=__objLst);";
+ pushAndExecPyLine(oss.str()); oss.str("");
}
void
-MEDPresentationSlices::selectSliceOrientation()
+MEDPresentationSlices::generateAndDisplay()
{
- std::ostringstream oss1;
- std::string norm;
+ generateSlices();
+ showObject();
+
+ colorBy(_fieldType);
+ showScalarBar();
+ rescaleTransferFunction();
+ selectColorMap();
+ resetCameraAndRender();
+}
+
+
+void
+MEDPresentationSlices::clearPreviousSlices()
+{
+ std::ostringstream oss;
+
+ pushAndExecPyLine("for sliceNum, _ in enumerate(__objLst):\n pvs.Delete(__objLst[sliceNum]);");
+ oss << "pvs.Delete(" << _objVar << ");";
+ pushAndExecPyLine(oss.str()); oss.str("");
+}
+std::string
+MEDPresentationSlices::getNormalVector() const
+{
switch(_params.orientation)
{
case MEDCALC::SLICE_NORMAL_TO_X:
- norm = "[1.0, 0.0, 0.0]";
- break;
+ return "[1.0, 0.0, 0.0]";
case MEDCALC::SLICE_NORMAL_TO_Y:
- norm = "[0.0, 1.0, 0.0]";
- break;
+ return "[0.0, 1.0, 0.0]";
case MEDCALC::SLICE_NORMAL_TO_Z:
- norm = "[0.0, 0.0, 1.0]";
- break;
+ return "[0.0, 0.0, 1.0]";
case MEDCALC::SLICE_NORMAL_TO_XY:
- norm = "[1.0, 1.0, 0.0]";
- break;
+ return "[1.0, 1.0, 0.0]";
case MEDCALC::SLICE_NORMAL_TO_XZ:
- norm = "[1.0, 0.0, 1.0]";
- break;
+ return "[1.0, 0.0, 1.0]";
case MEDCALC::SLICE_NORMAL_TO_YZ:
- norm = "[0.0, 1.0, 1.0]";
- break;
+ return "[0.0, 1.0, 1.0]";
case MEDCALC::SLICE_NORMAL_TO_XYZ:
- norm = "[1.0, 1.0, 1.0]";
- break;
+ return "[1.0, 1.0, 1.0]";
default:
const char * mes = "Unexpected getSliceOrientationCommand() error!";
STDLOG(mes);
throw KERNEL::createSalomeException(mes);
}
+ return ""; // never happens
+}
- oss1 << _objVar << ".SliceType.Normal = " << norm << ";";
+void
+MEDPresentationSlices::selectSliceOrientation(const std::string & obj)
+{
+ std::ostringstream oss1;
+ oss1 << obj << ".SliceType.Normal = " << getNormalVector() << ";";
pushAndExecPyLine(oss1.str()); oss1.str("");
}
-
void
MEDPresentationSlices::internalGeneratePipeline()
{
fillAvailableFieldComponents();
setOrCreateRenderView(); // instanciate __viewXXX
- oss << _objVar << " = pvs.Slice(Input=" << _srcObjVar << ");";
- pushAndExecPyLine(oss.str()); oss.str("");
-
- showObject();
-
- oss << _objVar << ".SliceType = 'Plane';";
- pushAndExecPyLine(oss.str()); oss.str("");
-
- // Set slice orientation
- selectSliceOrientation();
- colorBy(_fieldType);
- showScalarBar();
- rescaleTransferFunction();
- selectColorMap();
- resetCameraAndRender();
+ // Now create the initial number of slices
+ generateAndDisplay();
}
void
// Update the pipeline:
{
MEDPyLockWrapper lock;
- setNumberOfSlices();
- pushAndExecPyLine("pvs.Render();");
+ clearPreviousSlices();
+ generateAndDisplay();
}
}
_params.orientation = orientation;
// GUI helper:
- setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, orientation);
+ setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, static_cast<int>(orientation));
// Update the pipeline:
{
MEDPyLockWrapper lock;
- selectSliceOrientation();
- pushAndExecPyLine("pvs.Render();");
+
+ clearPreviousSlices();
+ generateAndDisplay();
}
}
void updateOrientation(const MEDCALC::SliceOrientationType orientation);
virtual void internalGeneratePipeline();
- void setNumberOfSlices();
- void selectSliceOrientation();
+ void generateSlices();
+ void clearPreviousSlices();
+ void generateAndDisplay();
+ void selectSliceOrientation(const std::string & obj);
+
+ std::string getNormalVector() const;
private:
MEDCALC::SlicesParameters _params;
_presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_RANGE.c_str()));
}
-void MEDWidgetHelper::udpateWidget()
+void MEDWidgetHelper::updateWidget(bool connect)
{
// Set presentation name
_paramWidget->setPresName(_presName);
_paramWidget->setColorMap(_colorMap);
_paramWidget->setScalarBarRange(_scalarBarRange);
- QObject::connect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) );
- QObject::connect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) );
+ if (connect)
+ {
+ QObject::connect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) );
+ QObject::connect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) );
+ }
}
void MEDWidgetHelper::releaseWidget()
public:
virtual ~MEDWidgetHelper();
- virtual void udpateWidget();
+ virtual void updateWidget(bool connect);
virtual void releaseWidget();
///! Returns the string X in the Python command "Update<X>" or "Get<X>Parameters"
MEDWidgetHelperComponent::~MEDWidgetHelperComponent()
{}
-void MEDWidgetHelperComponent::udpateWidget()
+void MEDWidgetHelperComponent::updateWidget(bool connect)
{
- MEDWidgetHelper::udpateWidget();
+ MEDWidgetHelper::updateWidget(connect);
_paramWidget->setComponents(_allCompos, _selectedCompo);
- // 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)) );
+ if (connect)
+ {
+ // 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)) );
+ }
}
void MEDWidgetHelperComponent::releaseWidget()
WidgetPresentationParameters * paramW);
virtual ~MEDWidgetHelperComponent();
- virtual void udpateWidget();
+ virtual void updateWidget(bool connect);
virtual void releaseWidget();
virtual std::string getPythonTag() const = 0;
_nbContours = _presManager->getPresentationIntProperty(_presId, MEDPresentationContour::PROP_NB_CONTOUR.c_str());
}
-void MEDWidgetHelperContour::udpateWidget()
+void MEDWidgetHelperContour::updateWidget(bool connect)
{
- MEDWidgetHelper::udpateWidget();
+ MEDWidgetHelper::updateWidget(connect);
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)) );
+ if (connect)
+ {
+ QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+ _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
+ QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbContourChanged(int)) );
+ }
}
void MEDWidgetHelperContour::releaseWidget()
WidgetPresentationParameters * paramW);
virtual ~MEDWidgetHelperContour();
- virtual void udpateWidget();
+ virtual void updateWidget(bool connect);
virtual void releaseWidget();
virtual std::string getPythonTag() const { return "Contour"; }
_presManager->getPresentationIntProperty(_presId, MEDPresentationMeshView::PROP_MESH_MODE.c_str()));
}
-void MEDWidgetHelperMeshView::udpateWidget()
+void MEDWidgetHelperMeshView::updateWidget(bool connect)
{
- MEDWidgetHelper::udpateWidget();
+ MEDWidgetHelper::updateWidget(connect);
// MeshView presentation needs the mesh mode that's all.
_paramWidget->setMeshMode(_meshMode);
// Hide color map and scalar bar range
_paramWidget->toggleCommonFieldWidget(false);
- // Connect combo box changes
- QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
- _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
- QObject::connect( _paramWidget, SIGNAL(comboMeshIndexChanged(int)), this, SLOT(onMeshModeChanged(int)) );
+ if (connect)
+ {
+ // Connect combo box changes
+ QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+ _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
+ QObject::connect( _paramWidget, SIGNAL(comboMeshIndexChanged(int)), this, SLOT(onMeshModeChanged(int)) );
+ }
}
void MEDWidgetHelperMeshView::releaseWidget()
WidgetPresentationParameters * paramW);
virtual ~MEDWidgetHelperMeshView();
- virtual void udpateWidget();
+ virtual void updateWidget(bool connect);
virtual void releaseWidget();
virtual std::string getPythonTag() const { return "MeshView"; }
_presManager->getPresentationIntProperty(_presId, MEDPresentationSlices::PROP_SLICE_ORIENTATION.c_str()));
}
-void MEDWidgetHelperSlices::udpateWidget()
+void MEDWidgetHelperSlices::updateWidget(bool connect)
{
- MEDWidgetHelper::udpateWidget();
+ MEDWidgetHelper::updateWidget(connect);
STDLOG("MEDWidgetHelperSlices::udpateWidget() nbSlices is " << _nbSlices);
-// _paramWidget->setNbSlices(_nbSlices); // TODO: uncomment when ready to deal with slice number
+ _paramWidget->setNbSlices(_nbSlices);
_paramWidget->setSliceOrientation(_sliceOrientation);
// Connect combo box changes
- QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
- _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
- QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
- QObject::connect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
+ if (connect)
+ {
+ QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)),
+ _presController, SIGNAL(presentationSignal(const PresentationEvent *)) );
+ QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) );
+ QObject::connect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) );
+ }
}
void MEDWidgetHelperSlices::releaseWidget()
void MEDWidgetHelperSlices::onSliceOrientationChanged(int sliceOrient)
{
- STDLOG("MEDWidgetHelperSlices::onNbSlicesChanged");
+ STDLOG("MEDWidgetHelperSlices::onSliceOrientationChanged");
PresentationEvent* event = new PresentationEvent();
event->eventtype = PresentationEvent::EVENT_CHANGE_SLICE_ORIENTATION;
event->presentationId = _presId;
WidgetPresentationParameters * paramW);
virtual ~MEDWidgetHelperSlices();
- virtual void udpateWidget();
+ virtual void updateWidget(bool connect);
virtual void releaseWidget();
virtual std::string getPythonTag() const { return "Slices"; }
</context>
<context>
<name>WidgetPresentationParameters</name>
+ <message>
+ <source>LAB_DEFAULT_DYN_TITLE</source>
+ <translation>Default parameters</translation>
+ </message>
<message>
<source>LAB_DISP_COMP</source>
<translation>Displayed component:</translation>
_presManager->activateView(presId);
// Update widgets parameters
_currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString());
- _currentWidgetHelper->udpateWidget();
+ _currentWidgetHelper->updateWidget(true);
}
}
else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) {
// Update parameter widget if shown:
if(_currentWidgetHelper)
- _currentWidgetHelper->udpateWidget();
+ _currentWidgetHelper->updateWidget(false);
}
}
_ui.setupUi(this); // To be done first
toggleWidget(false);
- QObject::connect(_ui.comboBoxCompo, SIGNAL(currentIndexChanged(int)),
+ QObject::connect(_ui.comboBoxCompo, SIGNAL(activated(int)),
this, SLOT(onComboCompoIndexChanged(int)) );
- QObject::connect(_ui.comboBoxMesh, SIGNAL(currentIndexChanged(int)),
+ QObject::connect(_ui.comboBoxMesh, SIGNAL(activated(int)),
this, SLOT(onComboMeshIndexChanged(int)) );
- QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(currentIndexChanged(int)),
+ QObject::connect(_ui.comboBoxScalarBarRange, SIGNAL(activated(int)),
this, SLOT(onComboScalarBarRangeIndexChanged(int)) );
- QObject::connect(_ui.comboBoxColorMap, SIGNAL(currentIndexChanged(int)),
+ QObject::connect(_ui.comboBoxColorMap, SIGNAL(activated(int)),
this, SLOT(onComboColorMapIndexChanged(int)) );
- QObject::connect(_ui.comboBoxSliceOrient, SIGNAL(currentIndexChanged(int)),
+ QObject::connect(_ui.comboBoxSliceOrient, SIGNAL(activated(int)),
this, SLOT(onComboOrientIndexChanged(int)) );
QObject::connect(_ui.spinBox, SIGNAL(valueChanged(int)),
this, SLOT(onSpinBoxValueChanged(int)) );
_blockSig = true;
_ui.widgetDynamic->hide();
- setPresName("Choose a presentation");
+ setPresName(tr("LAB_DEFAULT_DYN_TITLE").toStdString());
// reset colorMap and scalarBarRange:
setColorMap(MEDCALC::COLOR_MAP_DEFAULT);
setScalarBarRange(MEDCALC::SCALAR_BAR_RANGE_DEFAULT);
void
WidgetPresentationParameters::setComponents(vector<string> compos, int selecIndex)
{
+ _blockSig = true;
+
// Show the widget:
_ui.labelCompo->show();
_ui.comboBoxCompo->show();
- _blockSig = true;
_ui.comboBoxCompo->clear();
_ui.comboBoxCompo->addItem(tr("LAB_EUCLIDEAN_NORM"));
for(vector<string>::const_iterator it = compos.begin(); it != compos.end(); ++it)
_ui.comboBoxCompo->addItem(QString::fromStdString(*it));
_ui.comboBoxCompo->setCurrentIndex(selecIndex);
+
_blockSig = false;
}
void
WidgetPresentationParameters::setNbContour(int nbContour)
{
+ _blockSig = true;
+
if (nbContour <= 0)
{
//TODO throw?
_ui.labelSpinBox->setText(tr("LAB_NB_CONTOURS"));
_ui.labelSpinBox->show();
_ui.spinBox->show();
-
- _blockSig = true;
_ui.spinBox->setValue(nbContour);
+
_blockSig = false;
}
void
WidgetPresentationParameters::setNbSlices(int nbSlices)
{
+ _blockSig = true;
+
if (nbSlices <= 0)
{
//TODO throw?
_ui.labelSpinBox->setText(tr("LAB_NB_SLICES"));
_ui.labelSpinBox->show();
_ui.spinBox->show();
-
- _blockSig = true;
_ui.spinBox->setValue(nbSlices);
+
_blockSig = false;
}
void
WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbrange)
{
+ _blockSig = true;
+
int idx;
if (sbrange == MEDCALC::SCALAR_BAR_ALL_TIMESTEPS)
idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_ALL_TIMESTEPS"));
idx = _ui.comboBoxScalarBarRange->findText(tr("LAB_CURRENT_TIMESTEP"));
if (idx >= 0)
- {
- _blockSig = true;
_ui.comboBoxScalarBarRange->setCurrentIndex(idx);
- _blockSig = false;
- }
else
STDLOG("Strange!! No matching found - unable to set scalar bar range in GUI.");
+
+ _blockSig = false;
}
void
WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap)
{
+ _blockSig = true;
+
int idx = -1;
if (colorMap == MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW)
idx = _ui.comboBoxColorMap->findText(tr("LAB_BLUE_TO_RED"));
idx = _ui.comboBoxColorMap->findText(tr("LAB_COOL_TO_WARM"));
if (idx >= 0)
- {
- _blockSig = true;
_ui.comboBoxColorMap->setCurrentIndex(idx);
- _blockSig = false;
- }
-
else
STDLOG("Strange!! No matching found - unable to set color map in GUI.");
+
+ _blockSig = false;
}
void
WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode)
{
+ _blockSig = true;
+
// Show the widget:
_ui.labelMeshMode->show();
_ui.comboBoxMesh->show();
idx = -1;
}
if (idx >= 0)
- {
- _blockSig = true;
_ui.comboBoxMesh->setCurrentIndex(idx);
- _blockSig = false;
- }
else
STDLOG("Strange!! No matching found - unable to set mesh mode in GUI.");
+
+ _blockSig = false;
}
void
WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType orient)
{
+ _blockSig = true;
+
// Show the widget:
_ui.labelSliceOrient->show();
_ui.comboBoxSliceOrient->show();
idx = -1;
}
if (idx >= 0)
- {
- _blockSig = true;
- _ui.comboBoxSliceOrient->setCurrentIndex(idx);
- _blockSig = false;
- }
+ _ui.comboBoxSliceOrient->setCurrentIndex(idx);
else
STDLOG("Strange!! No matching found - unable to set slice orientation in GUI.");
+
+ _blockSig = false;
}
presentation_id = medcalc.MakeSlices(accessField(0), MEDCALC.VIEW_MODE_REPLACE,
colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW,
- sliceOrientation=MEDCALC.SLICE_NORMAL_TO_Z) # normal to Z to see something!
+ sliceOrientation=MEDCALC.SLICE_NORMAL_TO_Z, # normal to Z to see something!
+ nbSlices=3)
sleep(1)
medcalc.RemovePresentation(presentation_id)
sleep(1)
from medpresentation import UpdatePointSprite
#from medpresentation import UpdateDeflectionShape
-from medpresentation import SetDefaultScaleFactor, ComputeCellAverageSize, GetDomainCenter
+from medpresentation import SetDefaultScaleFactor, ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins
# Console commands
import medconsole
scalefactor = scaledextent / divisor
active.ScaleFactor = scalefactor
return
+
+def GetSliceOrigins(obj, nbSlices, normal):
+ """
+ Compute all origin points for the position of the slices.
+ @param normal is a list of 3 floats either 0 or 1 indicating the normal vector of the slices
+ """
+ from math import sqrt
+ bb = obj.GetDataInformation().GetBounds()
+ bb = zip(bb[::2], bb[1::2])
+ origin = [x[0] + 0.5*(x[1]-x[0]) for x in bb]
+ deltas = [x[1]-x[0] for x in bb]
+ # Compute extent of slices:
+ l = [normal[i]*deltas[i]**2 for i in range(3)] # either the X extend, or the XY diagonal, or the XYZ diagonal
+ plus = lambda x,y: x+y
+ extent = sqrt(reduce(plus, l, 0.0))
+ norm = sqrt(reduce(plus, normal, 0.0))
+ normal = [normal[i]/norm for i in range(3)]
+ origins = []
+ step = extent/nbSlices
+ for j in range(nbSlices):
+ orig_j = [origin[i]+normal[i]*(-0.5*extent + step*(0.5+j)) for i in range(3)]
+ origins.append(orig_j)
+ return origins
+