From 08faa78b7181a0e59676c75c647468d0620c409d Mon Sep 17 00:00:00 2001 From: rnc Date: Tue, 27 Aug 2013 09:16:59 +0000 Subject: [PATCH] IMP: HexoticPLUGIN/Size Maps: Added some warnings to avoid 0 value of the local size. Added a delegate to manage edition in the QTableWidget. Minor widget modifications (.ui) --- src/GUI/HexoticPLUGIN_msg_en.ts | 4 + .../HexoticPluginGUI_HypothesisCreator.cxx | 103 +++++++++++++++--- src/GUI/HexoticPluginGUI_HypothesisCreator.h | 29 +++++ .../HexoticPluginGUI_SizeMapsWidget_QTD.ui | 3 + src/HexoticPlugin/HexoticPLUGINBuilder.py | 4 +- .../HexoticPlugin_Hypothesis.cxx | 4 + 6 files changed, 133 insertions(+), 14 deletions(-) diff --git a/src/GUI/HexoticPLUGIN_msg_en.ts b/src/GUI/HexoticPLUGIN_msg_en.ts index a1b00bf..08c7c21 100644 --- a/src/GUI/HexoticPLUGIN_msg_en.ts +++ b/src/GUI/HexoticPLUGIN_msg_en.ts @@ -111,5 +111,9 @@ Hexotic_SEL_SHAPE Select a shape + + Hexotic_NULL_LOCAL_SIZE + 0 is not allowed as "Local size" + diff --git a/src/GUI/HexoticPluginGUI_HypothesisCreator.cxx b/src/GUI/HexoticPluginGUI_HypothesisCreator.cxx index b9a8d9a..8cb4ad6 100644 --- a/src/GUI/HexoticPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/HexoticPluginGUI_HypothesisCreator.cxx @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -67,10 +68,59 @@ enum { SIZE_COL }; +// +// Size map table widget delegate +// + +SizeMapsTableWidgetDelegate::SizeMapsTableWidgetDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} + +QWidget* SizeMapsTableWidgetDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &/* option */, + const QModelIndex &/* index */) const +{ + SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent); + editor->RangeStepAndValidator(0.0, COORD_MAX, 10.0, "length_precision"); + return editor; +} + +void SizeMapsTableWidgetDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + double value = index.model()->data(index, Qt::EditRole).toDouble(); + SMESHGUI_SpinBox *spinBox = static_cast(editor); + spinBox->setValue(value); +} + +void SizeMapsTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + SMESHGUI_SpinBox *spinBox = static_cast(editor); + spinBox->interpretText(); + double value = spinBox->value(); + if ( value == 0 ) + SUIT_MessageBox::critical( spinBox, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) ); + else + model->setData(index, value, Qt::EditRole); +} + +void SizeMapsTableWidgetDelegate::updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, + const QModelIndex &/* index */) const +{ + editor->setGeometry(option.rect); +} + +// END Delegate + + + HexoticPluginGUI_HypothesisCreator::HexoticPluginGUI_HypothesisCreator( const QString& theHypType ) : SMESHGUI_GenericHypothesisCreator( theHypType ), myIs3D( true ), - mySizeMapsToRemove () + mySizeMapsToRemove() { } @@ -81,11 +131,16 @@ HexoticPluginGUI_HypothesisCreator::~HexoticPluginGUI_HypothesisCreator() bool HexoticPluginGUI_HypothesisCreator::checkParams(QString& msg) const { msg.clear(); + HexoticHypothesisData data_old, data_new; readParamsFromHypo( data_old ); - readParamsFromWidgets( data_new ); + + bool res = readParamsFromWidgets( data_new ); + if ( !res ){ + return res; + } - bool res = storeParamsToHypo( data_new ); + res = storeParamsToHypo( data_new ); if ( !res ) { storeParamsToHypo( data_old ); return res; @@ -142,12 +197,14 @@ QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame() l->addWidget( myStdWidget, row++, 0, 1, 3 ); myStdWidget->onSdModeSelected(SD_MODE_4); + // SIZE MAPS TAB QWidget* aSmpGroup = new QWidget(); lay->addWidget( aSmpGroup ); // Size map widget creation and initialisation mySmpWidget = new HexoticPluginGUI_SizeMapsWidget(aSmpGroup); + mySmpWidget->doubleSpinBox->RangeStepAndValidator(0.0, COORD_MAX, 1.0, "length_precision"); mySmpWidget->doubleSpinBox->setValue(0.0); // Filters of selection @@ -160,14 +217,12 @@ QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame() SM_ShapeTypes.Add( TopAbs_COMPOUND ); SMESH_NumberFilter* aFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, SM_ShapeTypes); + // Selection widget myGeomSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( aFilter, mySmpWidget, /*multiSel=*/false,/*stretch=*/false); myGeomSelWdg->SetDefaultText(tr("Hexotic_SEL_SHAPE"), "QLineEdit { color: grey }"); mySmpWidget->gridLayout->addWidget(myGeomSelWdg, 0, 1); - QHBoxLayout* aSmpLayout = new QHBoxLayout( aSmpGroup ); - aSmpLayout->setMargin( 0 ); - aSmpLayout->addWidget( mySmpWidget); - + // Configuration of the table widget QStringList headerLabels; headerLabels << tr("Hexotic_ENTRY")<< tr("Hexotic_NAME")<< tr("Hexotic_SIZE"); mySmpWidget->tableWidget->setHorizontalHeaderLabels(headerLabels); @@ -177,6 +232,15 @@ QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame() mySmpWidget->pushButton_1->setText(tr("Hexotic_ADD")); mySmpWidget->pushButton_2->setText(tr("Hexotic_REMOVE")); + // Setting a custom delegate for the size column + SizeMapsTableWidgetDelegate* delegate = new SizeMapsTableWidgetDelegate(); + mySmpWidget->tableWidget->setItemDelegateForColumn(SIZE_COL, delegate); + + // Add the size maps widget to a layout + QHBoxLayout* aSmpLayout = new QHBoxLayout( aSmpGroup ); + aSmpLayout->setMargin( 0 ); + aSmpLayout->addWidget( mySmpWidget); + // resizeEvent(); @@ -187,8 +251,8 @@ QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame() // Size Maps mySizeMapsToRemove.clear(); - connect( mySmpWidget->pushButton_1, SIGNAL( clicked() ), this, SLOT( onAddLocalSize() ) ); - connect( mySmpWidget->pushButton_2, SIGNAL( clicked() ), this, SLOT( onRemoveLocalSize() ) ); + connect( mySmpWidget->pushButton_1, SIGNAL( clicked() ), this, SLOT( onAddLocalSize() ) ); + connect( mySmpWidget->pushButton_2, SIGNAL( clicked() ), this, SLOT( onRemoveLocalSize() ) ); return fr; } @@ -200,6 +264,9 @@ void HexoticPluginGUI_HypothesisCreator::onAddLocalSize() // Get the selected object properties GEOM::GEOM_Object_var sizeMapObject = myGeomSelWdg->GetObject< GEOM::GEOM_Object >(0); + if (sizeMapObject->_is_nil()) + return; + std::string entry, shapeName; entry = (std::string) sizeMapObject->GetStudyEntry(); shapeName = sizeMapObject->GetName(); @@ -212,6 +279,11 @@ void HexoticPluginGUI_HypothesisCreator::onAddLocalSize() // Get the size value double size = mySmpWidget->doubleSpinBox->value(); + if (size == 0) + { + SUIT_MessageBox::critical( mySmpWidget, tr( "SMESH_ERROR" ), tr( "Hexotic_NULL_LOCAL_SIZE" ) ); + return; + } // Set items for the inserted row insertLocalSizeInWidget( entry, shapeName, size, rowCount ); @@ -235,16 +307,21 @@ void HexoticPluginGUI_HypothesisCreator::insertLocalSizeInWidget( std::string en switch ( col ) { case ENTRY_COL: + item->setFlags( 0 ); value = QVariant( entry.c_str() ); + item->setData(Qt::DisplayRole, value ); break; case NAME_COL: + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); value = QVariant( shapeName.c_str() ); + item->setData(Qt::DisplayRole, value ); break; case SIZE_COL: + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); value = QVariant( size ); + item->setData(Qt::EditRole, value ); break; } - item->setData(Qt::DisplayRole, value ); mySmpWidget->tableWidget->setItem(row,col,item); } } @@ -280,9 +357,9 @@ void HexoticPluginGUI_HypothesisCreator::resizeEvent(QResizeEvent */*event*/) { QSize scaledSize = myStdWidget->imageSdMode.size(); scaledSize.scale(myStdWidget->sdModeLabel->size(), Qt::KeepAspectRatioByExpanding); if (!myStdWidget->sdModeLabel->pixmap() || scaledSize != myStdWidget->sdModeLabel->pixmap()->size()) - myStdWidget->sdModeLabel->setPixmap(myStdWidget->imageSdMode.scaled(myStdWidget->sdModeLabel->size(), - Qt::KeepAspectRatio, - Qt::SmoothTransformation)); + myStdWidget->sdModeLabel->setPixmap(myStdWidget->imageSdMode.scaled(myStdWidget->sdModeLabel->size(), + Qt::KeepAspectRatio, + Qt::SmoothTransformation)); } void HexoticPluginGUI_HypothesisCreator::retrieveParams() const diff --git a/src/GUI/HexoticPluginGUI_HypothesisCreator.h b/src/GUI/HexoticPluginGUI_HypothesisCreator.h index 219c250..a786356 100644 --- a/src/GUI/HexoticPluginGUI_HypothesisCreator.h +++ b/src/GUI/HexoticPluginGUI_HypothesisCreator.h @@ -31,9 +31,12 @@ #include "StdMeshersGUI_ObjectReferenceParamWdg.h" #include "HexoticPlugin_Hypothesis.hxx" +#include + class QtxIntSpinBox; class QCheckBox; class QLineEdit; +class QTableWidgetItem; class HexoticPluginGUI_StdWidget; class HexoticPluginGUI_SizeMapsWidget; @@ -98,11 +101,37 @@ private: bool myIs3D; std::vector< std::string > mySizeMapsToRemove; + QVariant myNotModifiedSize; protected slots: void onAddLocalSize(); void onRemoveLocalSize(); + void onItemChanged(QTableWidgetItem*); + void onItemDoubleClicked(QTableWidgetItem*); }; +class SizeMapsTableWidgetDelegate : public QItemDelegate +{ + Q_OBJECT + +public: + SizeMapsTableWidgetDelegate(QObject *parent = 0); + + QWidget *createEditor(QWidget *parent, + const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + void setEditorData(QWidget *editor, + const QModelIndex &index) const; + + void setModelData(QWidget *editor, + QAbstractItemModel *model, + const QModelIndex &index) const; + + void updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, + const QModelIndex &index) const; +}; + #endif diff --git a/src/GUI/HexoticPluginGUI_SizeMapsWidget_QTD.ui b/src/GUI/HexoticPluginGUI_SizeMapsWidget_QTD.ui index 2107ca0..6d7179e 100644 --- a/src/GUI/HexoticPluginGUI_SizeMapsWidget_QTD.ui +++ b/src/GUI/HexoticPluginGUI_SizeMapsWidget_QTD.ui @@ -33,6 +33,9 @@ 80 + + 100 + false diff --git a/src/HexoticPlugin/HexoticPLUGINBuilder.py b/src/HexoticPlugin/HexoticPLUGINBuilder.py index f0c1b77..97b1d40 100644 --- a/src/HexoticPlugin/HexoticPLUGINBuilder.py +++ b/src/HexoticPlugin/HexoticPLUGINBuilder.py @@ -93,13 +93,15 @@ class Hexotic_Algorithm(Mesh_Algorithm): # @return hypothesis object def SetSizeMap(self, theObject, theSize): AssureGeomPublished( self.mesh, theObject ) + if theSize <= 0: + raise ValueError, "The size must be > 0" self.Parameters().SetSizeMap(theObject, theSize) return self.Parameters() ## Unsets a size map : this is meant to be used only by the dump # @param theObject geometrical object to unassign local size # @return hypothesis object - def UnsetSizeMap(self, theObject, theSize): + def UnsetSizeMap(self, theObject): AssureGeomPublished( self.mesh, theObject ) self.Parameters().UnsetSizeMap(theObject) return self.Parameters() diff --git a/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx b/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx index 3548bc6..0658ec0 100644 --- a/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx +++ b/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx @@ -148,6 +148,10 @@ void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) { bool HexoticPlugin_Hypothesis::AddSizeMap(std::string theEntry, double theSize) { THexoticSizeMaps::iterator it; it=_sizeMaps.find(theEntry); + + if(theSize <= 0) + return false; + if( it == _sizeMaps.end() ) // If no size map is defined on the given object { _sizeMaps[theEntry] = theSize; -- 2.39.2