From: abn Date: Thu, 4 Aug 2016 10:24:10 +0000 (+0200) Subject: [MEDCalc] Multiple slices + other minor imps: X-Git-Tag: V8_1_0b1~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a119debbdcf997724c31a9177793d2f9beef6a64;p=modules%2Fmed.git [MEDCalc] Multiple slices + other minor imps: + bug fix when updating parameters + nicer mesh icons --- diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.cxx b/src/MEDCalc/cmp/MEDPresentationSlices.cxx index 16dbf4fad..83945b32d 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.cxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.cxx @@ -39,53 +39,86 @@ MEDPresentationSlices::MEDPresentationSlices(const MEDCALC::SlicesParameters& pa } 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() { @@ -101,21 +134,8 @@ 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 @@ -148,8 +168,8 @@ MEDPresentationSlices::updateNbSlices(const int nbSlices) // Update the pipeline: { MEDPyLockWrapper lock; - setNumberOfSlices(); - pushAndExecPyLine("pvs.Render();"); + clearPreviousSlices(); + generateAndDisplay(); } } @@ -159,13 +179,14 @@ MEDPresentationSlices::updateOrientation(const MEDCALC::SliceOrientationType ori _params.orientation = orientation; // GUI helper: - setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, orientation); + setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, static_cast(orientation)); // Update the pipeline: { MEDPyLockWrapper lock; - selectSliceOrientation(); - pushAndExecPyLine("pvs.Render();"); + + clearPreviousSlices(); + generateAndDisplay(); } } diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.hxx b/src/MEDCalc/cmp/MEDPresentationSlices.hxx index 81d5ae7e8..19afa196e 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.hxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.hxx @@ -43,8 +43,12 @@ protected: 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; diff --git a/src/MEDCalc/gui/MEDWidgetHelper.cxx b/src/MEDCalc/gui/MEDWidgetHelper.cxx index 4451ca9ad..8869c847b 100644 --- a/src/MEDCalc/gui/MEDWidgetHelper.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelper.cxx @@ -53,7 +53,7 @@ void MEDWidgetHelper::loadParametersFromEngine() _presManager->getPresentationIntProperty(_presId, MEDPresentation::PROP_SCALAR_BAR_RANGE.c_str())); } -void MEDWidgetHelper::udpateWidget() +void MEDWidgetHelper::updateWidget(bool connect) { // Set presentation name _paramWidget->setPresName(_presName); @@ -67,8 +67,11 @@ void MEDWidgetHelper::udpateWidget() _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() diff --git a/src/MEDCalc/gui/MEDWidgetHelper.hxx b/src/MEDCalc/gui/MEDWidgetHelper.hxx index 2fbeaadca..a5f60a561 100644 --- a/src/MEDCalc/gui/MEDWidgetHelper.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelper.hxx @@ -40,7 +40,7 @@ class MEDWidgetHelper : public QObject public: virtual ~MEDWidgetHelper(); - virtual void udpateWidget(); + virtual void updateWidget(bool connect); virtual void releaseWidget(); ///! Returns the string X in the Python command "Update" or "GetParameters" diff --git a/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx b/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx index 947fc3434..01a29e9ed 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx @@ -28,16 +28,19 @@ MEDWidgetHelperComponent::MEDWidgetHelperComponent(const PresentationController 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() diff --git a/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx b/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx index 58c774f15..fce67204d 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx @@ -37,7 +37,7 @@ public: WidgetPresentationParameters * paramW); virtual ~MEDWidgetHelperComponent(); - virtual void udpateWidget(); + virtual void updateWidget(bool connect); virtual void releaseWidget(); virtual std::string getPythonTag() const = 0; diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.cxx b/src/MEDCalc/gui/MEDWidgetHelperContour.cxx index 40ded91d5..351c558bf 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperContour.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelperContour.cxx @@ -41,20 +41,21 @@ void MEDWidgetHelperContour::loadParametersFromEngine() _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() diff --git a/src/MEDCalc/gui/MEDWidgetHelperContour.hxx b/src/MEDCalc/gui/MEDWidgetHelperContour.hxx index 0e545fe78..fc3775993 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperContour.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperContour.hxx @@ -34,7 +34,7 @@ public: WidgetPresentationParameters * paramW); virtual ~MEDWidgetHelperContour(); - virtual void udpateWidget(); + virtual void updateWidget(bool connect); virtual void releaseWidget(); virtual std::string getPythonTag() const { return "Contour"; } diff --git a/src/MEDCalc/gui/MEDWidgetHelperMeshView.cxx b/src/MEDCalc/gui/MEDWidgetHelperMeshView.cxx index 2ea424500..c75d453f0 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperMeshView.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelperMeshView.cxx @@ -42,19 +42,22 @@ void MEDWidgetHelperMeshView::loadParametersFromEngine() _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() diff --git a/src/MEDCalc/gui/MEDWidgetHelperMeshView.hxx b/src/MEDCalc/gui/MEDWidgetHelperMeshView.hxx index efbd56117..83f2b50e6 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperMeshView.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperMeshView.hxx @@ -34,7 +34,7 @@ public: WidgetPresentationParameters * paramW); virtual ~MEDWidgetHelperMeshView(); - virtual void udpateWidget(); + virtual void updateWidget(bool connect); virtual void releaseWidget(); virtual std::string getPythonTag() const { return "MeshView"; } diff --git a/src/MEDCalc/gui/MEDWidgetHelperSlices.cxx b/src/MEDCalc/gui/MEDWidgetHelperSlices.cxx index b785cfab6..eb99e8775 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperSlices.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelperSlices.cxx @@ -44,19 +44,22 @@ void MEDWidgetHelperSlices::loadParametersFromEngine() _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() @@ -83,7 +86,7 @@ void MEDWidgetHelperSlices::onNbSlicesChanged(int nbSlices) 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; diff --git a/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx b/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx index ddfcb2a84..bce48ef03 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx @@ -34,7 +34,7 @@ public: WidgetPresentationParameters * paramW); virtual ~MEDWidgetHelperSlices(); - virtual void udpateWidget(); + virtual void updateWidget(bool connect); virtual void releaseWidget(); virtual std::string getPythonTag() const { return "Slices"; } diff --git a/src/MEDCalc/gui/MED_msg_en.ts b/src/MEDCalc/gui/MED_msg_en.ts index a3564ddd2..a9a9a1ebc 100644 --- a/src/MEDCalc/gui/MED_msg_en.ts +++ b/src/MEDCalc/gui/MED_msg_en.ts @@ -179,6 +179,10 @@ WidgetPresentationParameters + + LAB_DEFAULT_DYN_TITLE + Default parameters + LAB_DISP_COMP Displayed component: diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index 44acb921e..c6fcbbe78 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -619,7 +619,7 @@ PresentationController::onPresentationSelected(int presId, const QString& presTy _presManager->activateView(presId); // Update widgets parameters _currentWidgetHelper = findOrCreateWidgetHelper(_presManager, presId, presType.toStdString(), presName.toStdString()); - _currentWidgetHelper->udpateWidget(); + _currentWidgetHelper->updateWidget(true); } } @@ -752,7 +752,7 @@ PresentationController::processWorkspaceEvent(const MEDCALC::MedEvent* event) else if ( event->type == MEDCALC::EVENT_MODIFY_PRESENTATION ) { // Update parameter widget if shown: if(_currentWidgetHelper) - _currentWidgetHelper->udpateWidget(); + _currentWidgetHelper->updateWidget(false); } } diff --git a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx index 8d7a3e1be..601e46d44 100644 --- a/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx +++ b/src/MEDCalc/gui/dialogs/WidgetPresentationParameters.cxx @@ -28,15 +28,15 @@ WidgetPresentationParameters::WidgetPresentationParameters(QWidget* parent) _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)) ); @@ -96,7 +96,7 @@ WidgetPresentationParameters::toggleWidget(bool show) _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); @@ -135,22 +135,26 @@ WidgetPresentationParameters::getComponent() const void WidgetPresentationParameters::setComponents(vector 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::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? @@ -161,15 +165,16 @@ WidgetPresentationParameters::setNbContour(int nbContour) _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? @@ -180,9 +185,8 @@ WidgetPresentationParameters::setNbSlices(int nbSlices) _ui.labelSpinBox->setText(tr("LAB_NB_SLICES")); _ui.labelSpinBox->show(); _ui.spinBox->show(); - - _blockSig = true; _ui.spinBox->setValue(nbSlices); + _blockSig = false; } @@ -200,6 +204,8 @@ int WidgetPresentationParameters::getNbSlices() const 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")); @@ -207,18 +213,18 @@ WidgetPresentationParameters::setScalarBarRange(MEDCALC::ScalarBarRangeType sbra 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")); @@ -226,19 +232,18 @@ WidgetPresentationParameters::setColorMap(MEDCALC::ColorMapType colorMap) 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(); @@ -259,18 +264,18 @@ WidgetPresentationParameters::setMeshMode(MEDCALC::MeshModeType mode) 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(); @@ -303,13 +308,11 @@ WidgetPresentationParameters::setSliceOrientation(MEDCALC::SliceOrientationType 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; } diff --git a/src/MEDCalc/res/presentations/classic/visu_mesh16.png b/src/MEDCalc/res/presentations/classic/visu_mesh16.png index 1105b3737..d2671e057 100644 Binary files a/src/MEDCalc/res/presentations/classic/visu_mesh16.png and b/src/MEDCalc/res/presentations/classic/visu_mesh16.png differ diff --git a/src/MEDCalc/res/presentations/classic/visu_mesh24.png b/src/MEDCalc/res/presentations/classic/visu_mesh24.png index 3b3de8b4a..a9708fab2 100644 Binary files a/src/MEDCalc/res/presentations/classic/visu_mesh24.png and b/src/MEDCalc/res/presentations/classic/visu_mesh24.png differ diff --git a/src/MEDCalc/res/presentations/modern/mesh16.png b/src/MEDCalc/res/presentations/modern/mesh16.png index 1105b3737..d2671e057 100644 Binary files a/src/MEDCalc/res/presentations/modern/mesh16.png and b/src/MEDCalc/res/presentations/modern/mesh16.png differ diff --git a/src/MEDCalc/res/presentations/modern/mesh24.png b/src/MEDCalc/res/presentations/modern/mesh24.png index 3b3de8b4a..a9708fab2 100644 Binary files a/src/MEDCalc/res/presentations/modern/mesh24.png and b/src/MEDCalc/res/presentations/modern/mesh24.png differ diff --git a/src/MEDCalc/test/tui/slices.py b/src/MEDCalc/test/tui/slices.py index e3edd10ba..bbfcff31d 100644 --- a/src/MEDCalc/test/tui/slices.py +++ b/src/MEDCalc/test/tui/slices.py @@ -32,7 +32,8 @@ source_id = medcalc.LoadDataSource(datafile) 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) diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index ee461af8a..1f1f0fd9d 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -64,7 +64,7 @@ from medpresentation import UpdateVectorField 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 diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index b85d3d442..6b23e20bd 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -270,3 +270,27 @@ def SetDefaultScaleFactor(active=None): 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 +