From 4f811ab1edbcb077cbf58e46f9c3b287c16bb410 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Mon, 23 Nov 2020 14:00:57 +0100 Subject: [PATCH] fix #20294 --- src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp | 41 +-- src/FeaturesPlugin/FeaturesPlugin_Fillet.h | 14 +- .../FeaturesPlugin_VersionedChFi.cpp | 8 +- ...aturesPlugin_WidgetFilletMultiRadiuses.cpp | 288 +++++++++--------- ...FeaturesPlugin_WidgetFilletMultiRadiuses.h | 21 +- 5 files changed, 182 insertions(+), 190 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp index 0095a62e9..2d4955d23 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp @@ -45,6 +45,7 @@ // Extract edges from the list +//================================================================================================= static ListOfShape extractEdges(const ListOfShape& theShapes) { ListOfShape anEdges; @@ -54,11 +55,12 @@ static ListOfShape extractEdges(const ListOfShape& theShapes) return anEdges; } - +//================================================================================================= FeaturesPlugin_Fillet::FeaturesPlugin_Fillet() { } +//================================================================================================= void FeaturesPlugin_Fillet::initAttributes() { @@ -104,35 +106,35 @@ void FeaturesPlugin_Fillet::initAttributes() } +//================================================================================================= AttributePtr FeaturesPlugin_Fillet::objectsAttribute() { - if( string(CREATION_METHOD())->value() == METHOD_MULTIPLES_RADIUSES() ) - { - if( string(CREATION_MULTI_RADIUS_METHOD())->value() == CREATION_METHOD_BY_POINTS()) - { + if (string(CREATION_METHOD())->value() == METHOD_MULTIPLES_RADIUSES() ){ + if (string(CREATION_MULTI_RADIUS_METHOD())->value() == CREATION_METHOD_BY_POINTS()){ return attribute(EDGE_SELECTED_ID()); - }else{ + } else { return attribute(EDGES_FACES_MULTI_LIST_ID()); } - }else if ( string(CREATION_METHOD())->value() == CREATION_METHOD_VARYING_RADIUS() ) - { + } else if (string(CREATION_METHOD())->value() == CREATION_METHOD_VARYING_RADIUS()) { return attribute(EDGES_FACES_LIST_ID()); - } return attribute(OBJECT_LIST_ID()); } +//================================================================================================= void FeaturesPlugin_Fillet::attributeChanged(const std::string& theID) { } +//================================================================================================= const std::string& FeaturesPlugin_Fillet::modifiedShapePrefix() const { static const std::string& THE_PREFIX("Fillet"); return THE_PREFIX; } +//================================================================================================= GeomMakeShapePtr FeaturesPlugin_Fillet::performOperation(const GeomShapePtr& theSolid, const ListOfShape& theEdges) { @@ -148,19 +150,17 @@ GeomMakeShapePtr FeaturesPlugin_Fillet::performOperation(const GeomShapePtr& the ListOfShape aFilletEdges = extractEdges(theEdges); - if ( aCreationMethod->value() == METHOD_MULTIPLES_RADIUSES()) - { + if (aCreationMethod->value() == METHOD_MULTIPLES_RADIUSES()){ std::list aCoodCurv; std::list aRadiuses; AttributeTablesPtr aTablesAttr; - if( string(CREATION_MULTI_RADIUS_METHOD())->value() == CREATION_METHOD_BY_POINTS() ) - { + if (string(CREATION_MULTI_RADIUS_METHOD())->value() == CREATION_METHOD_BY_POINTS()){ aTablesAttr = tables(VALUES_ID()); - }else{ + } else { aTablesAttr = tables(VALUES_CURV_ID()); } @@ -169,15 +169,20 @@ GeomMakeShapePtr FeaturesPlugin_Fillet::performOperation(const GeomShapePtr& the for (int k = 0; k < aRows; k++) { aVal = aTablesAttr->value(k, 0); aCoodCurv.push_back(aVal.myDouble); + if (k!=0 && k!= aRows-1 && (aVal.myDouble >= 1.0 || aVal.myDouble <= 0.0)){ + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + aVal.myDouble = 2.0; + aTablesAttr->setValue(aVal, k, 0); + data()->blockSendAttributeUpdated(aWasBlocked, false); + setError("the value is not validate "); + return GeomMakeShapePtr(); + } aVal = aTablesAttr->value(k, 1); aRadiuses.push_back(aVal.myDouble); } - - aFilletBuilder.reset(new GeomAlgoAPI_Fillet(theSolid, aFilletEdges, aCoodCurv,aRadiuses)); - }else - { + } else { bool isFixedRadius = aCreationMethod->value() == CREATION_METHOD_SINGLE_RADIUS(); double aRadius1 = 0.0, aRadius2 = 0.0; if (isFixedRadius) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h index 60bba75ed..daf1803dd 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h @@ -43,47 +43,51 @@ public: return MY_KIND; } + /// Attribute name of creation method inline static const std::string& CREATION_METHOD() { static std::string MY_CREATION_METHOD("creation_method"); return MY_CREATION_METHOD; } + /// Attribute name of creation method single radius inline static const std::string CREATION_METHOD_SINGLE_RADIUS() { static std::string MY_SINGLE_RADIUS("fixed_radius"); return MY_SINGLE_RADIUS; } + /// Attribute name of creation method varying radius inline static const std::string CREATION_METHOD_VARYING_RADIUS() { static std::string MY_VARYING_RADIUS("variable_radius"); return MY_VARYING_RADIUS; } - + /// Attribute name of methode multiples radiuses inline static const std::string METHOD_MULTIPLES_RADIUSES() { static std::string MY_METHOD_MULTIPLES_RADIUSES("multiple_radiuses"); return MY_METHOD_MULTIPLES_RADIUSES; } - + /// Attribute name of creation method multi radius inline static const std::string CREATION_MULTI_RADIUS_METHOD() { static std::string MY_CREATION_MULTI_RADIUS_METHODE("multiple_radiuses_method"); return MY_CREATION_MULTI_RADIUS_METHODE; } - + /// Attribute name of creation method multi radius by curvilear abscissa inline static const std::string CREATION_METHOD_BY_CURVILEAR_ABSCISSA() { static std::string MY_CREATION_METHOD_BY_CURVILEAR_ABSCISSA("by_curvilinear_abscissa_method"); return MY_CREATION_METHOD_BY_CURVILEAR_ABSCISSA; } + /// Attribute name of creation method multi radius by point inline static const std::string CREATION_METHOD_BY_POINTS() { static std::string MY_CREATION_METHOD_BY_POINTS("by_points"); return MY_CREATION_METHOD_BY_POINTS; } - + /// Attribute name of array point inline static const std::string ARRAY_POINT_RADIUS_BY_POINTS() { static std::string MY_ARRAY_POINT_RADIUS_BY_POINTS("array_point_radius_by_point"); @@ -154,6 +158,8 @@ public: /// Request for initialization of data model of the feature: adding all attributes. FEATURESPLUGIN_EXPORT virtual void initAttributes(); + /// Called on change of any argument-attribute of this object. + /// \param[in] theID identifier of changed attribute. FEATURESPLUGIN_EXPORT void attributeChanged(const std::string& theID); /// Use plugin manager for features creation. diff --git a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp index ede9bb1d5..63add0f17 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp @@ -117,7 +117,7 @@ bool FeaturesPlugin_VersionedChFi::processAttribute(const AttributePtr& theAttri AttributeSelectionPtr anObject = std::dynamic_pointer_cast(theAttribute); - if( anObject.get() ) + if (anObject.get()) { if ( !addShapeInHierarchy(anObject , theObjects, isStoreFullHierarchy) ) return false; @@ -155,16 +155,14 @@ bool FeaturesPlugin_VersionedChFi::addShapeInHierarchy(const AttributeSelectionP return false; // store full shape hierarchy for the corresponding version only - if (anObject->shapeType() <= GeomAPI_Shape::SOLID) - { + if (anObject->shapeType() <= GeomAPI_Shape::SOLID) { ListOfShape anEdges; collectSubs(aParent, anEdges, GeomAPI_Shape::EDGE); for (ListOfShape::iterator anIt = anEdges.begin(); anIt != anEdges.end(); ++anIt) { theObjects.addObject(*anIt); theObjects.addParent(*anIt, aParent); } - }else - { + } else { theObjects.addObject(anObject); theObjects.addParent(anObject, aParent); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp index 79e14cfac..629260232 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp @@ -66,40 +66,12 @@ const char* MYFirstCol = "Shape"; const char* MYTrue = "True"; const char* MYFalse = "False"; -class TextFieldDoubleValidator : public QDoubleValidator { -public: - TextFieldDoubleValidator (QObject * theParent = 0) : QDoubleValidator(theParent) {} - TextFieldDoubleValidator (double theBottom, double theTop, int theDecimals, QObject * theParent) : - QDoubleValidator(theBottom, theTop, theDecimals, theParent) {} - - QValidator::State validate(QString & theS, int & thePos) const { - if (theS.isEmpty() || theS.startsWith("0.") || theS == "0" ){//|| s.startsWith("-")) { - // allow empty field or minus sign - return QValidator::Intermediate; - } - // check length of decimal places - QChar point = locale().decimalPoint(); - if(theS.indexOf(point) != -1) { - int alengthDecimals = theS.length() - theS.indexOf(point) - 1; - if (alengthDecimals > decimals()) { - return QValidator::Invalid; - } - } - // check range of value - bool isNumber; - double aValue = locale().toDouble(theS, &isNumber); - if (isNumber && bottom() <= aValue && aValue <= top()) { - return QValidator::Acceptable; - } - return QValidator::Invalid; - } -}; - +//================================================================================================= DataArrayItemDelegate::DataArrayItemDelegate(bool theTypeMethod) : QStyledItemDelegate(), myTypeMethodPoint(theTypeMethod) { } - +//================================================================================================= QWidget* DataArrayItemDelegate::createEditor(QWidget* theParent, const QStyleOptionViewItem & theOption, const QModelIndex& theIndex ) const @@ -117,16 +89,16 @@ QWidget* DataArrayItemDelegate::createEditor(QWidget* theParent, theOption, theIndex)); if (aLineEdt) { - if( theIndex.column() == 1 ){ - TextFieldDoubleValidator* doubleVal = - new TextFieldDoubleValidator(0.00001 , 0.99, 6, aLineEdt); - doubleVal->setNotation(TextFieldDoubleValidator::StandardNotation); - aLineEdt->setValidator(doubleVal); + if (theIndex.column() == 1 ){ + QDoubleValidator* aDoubleVal = + new QDoubleValidator( 0.00001 , 0.99, 6, aLineEdt); + aDoubleVal->setNotation(QDoubleValidator::StandardNotation); + aLineEdt->setValidator(aDoubleVal); } else{ - QDoubleValidator* doubleVal = new QDoubleValidator(0.0 , 10000.0, 6, aLineEdt); - doubleVal->setNotation(QDoubleValidator::StandardNotation); - aLineEdt->setValidator(doubleVal); + QDoubleValidator* aDoubleVal = new QDoubleValidator(0.000001, 1000000.0, 6, aLineEdt); + aDoubleVal->setNotation(QDoubleValidator::StandardNotation); + aLineEdt->setValidator(aDoubleVal); } aEditor = aLineEdt; } @@ -137,13 +109,14 @@ QWidget* DataArrayItemDelegate::createEditor(QWidget* theParent, return aEditor; } +//================================================================================================= void DataArrayItemDelegate::onEditItem(const QString& theText) { QWidget* aWgt = dynamic_cast(sender()); commitData(aWgt); } -//********************************************************************************** +//================================================================================================= FeaturesPlugin_WidgetFilletMultiRadiuses:: FeaturesPlugin_WidgetFilletMultiRadiuses(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, @@ -170,14 +143,14 @@ ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), myDataTbl->verticalHeader()->hide(); myDataTbl->setRowHeight(0, 25); - if(myTypeMethodBypoint){ + if (myTypeMethodBypoint) { myfirstRowValue.push_back("Start extremity"); myfirstRowValue.push_back("0"); myfirstRowValue.push_back("1"); myLastRowValue.push_back("End extremity"); myLastRowValue.push_back("1"); myLastRowValue.push_back("2"); - }else{ + } else { myfirstRowValue.push_back("0"); myfirstRowValue.push_back("0"); myfirstRowValue.push_back("1"); @@ -186,7 +159,7 @@ ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), myLastRowValue.push_back("2"); } - if(myTypeMethodBypoint) + if (myTypeMethodBypoint) myDataTbl->hideColumn(1); else myDataTbl->hideColumn(0); @@ -198,24 +171,24 @@ ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), myDataTbl->setHorizontalHeaderLabels(aHeaders); myDataTbl->installEventFilter(this); + myDataTbl->viewport()->installEventFilter(this); QTableWidgetItem* anItem; - for(int j =0; j<3;j++) + for (int j =0; j<3;j++) { anItem = new QTableWidgetItem(myfirstRowValue[j]); - if(j==0 || j== 1) - anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled); + if (j==0 || j== 1) + anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable); myDataTbl->setItem(0, j, anItem); anItem = new QTableWidgetItem(myLastRowValue[j]); - if(j==0 || j== 1) - anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled); + if (j==0 || j== 1) + anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable); myDataTbl->setItem(1, j, anItem); } connect(myDataTbl, SIGNAL(cellChanged(int, int)), SLOT(onTableEdited(int, int))); aRadiusesLayout->addWidget(myDataTbl); - ///======================== // Buttons below QWidget* aBtnWgt = new QWidget(this); @@ -246,6 +219,7 @@ ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), connect(myDataTbl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection())); } +//================================================================================================= QList FeaturesPlugin_WidgetFilletMultiRadiuses::getControls() const { QList aControls; @@ -254,7 +228,7 @@ QList FeaturesPlugin_WidgetFilletMultiRadiuses::getControls() const return aControls; } -//********************************************************************************** +//================================================================================================= QIntList FeaturesPlugin_WidgetFilletMultiRadiuses::shapeTypes() const { QIntList aRes; @@ -263,7 +237,7 @@ QIntList FeaturesPlugin_WidgetFilletMultiRadiuses::shapeTypes() const return aRes; } -//********************************************************************************** +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses::deactivate() { @@ -276,19 +250,31 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses::deactivate() storeValueCustom(); } -//********************************************************************************** +//================================================================================================= bool FeaturesPlugin_WidgetFilletMultiRadiuses::eventFilter(QObject* theObject, QEvent* theEvent) { if (theEvent->type() == QEvent::KeyPress) { QKeyEvent* akey = static_cast(theEvent); - if ( (akey->key()==Qt::Key_Enter) || (akey->key()==Qt::Key_Return) ) { - updateObject(myFeature); + if ((akey->key()==Qt::Key_Enter) || (akey->key()==Qt::Key_Return)) { + bool aValid = true; + int aRows = myDataTbl->rowCount(); + for (int anI = 1; anI < aRows-1; anI++) { + QString aTblVal = myDataTbl->item(anI, 1)->text(); + double aVal = aTblVal.toDouble(); + if (aVal <= 0.0 || aVal >= 1.0) + { + aValid = false; + break; + } + } + if (aValid) + updateObject(myFeature); } } return ModuleBase_WidgetSelector::eventFilter(theObject, theEvent); } -//********************************************************************************** +//================================================================================================= bool FeaturesPlugin_WidgetFilletMultiRadiuses::storeValueCustom() { @@ -296,7 +282,7 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::storeValueCustom() AttributeTablesPtr aTablesAttr; - if(myTypeMethodBypoint) + if (myTypeMethodBypoint) aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_ID()); else aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); @@ -314,10 +300,10 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::storeValueCustom() } } - if(myTypeMethodBypoint && mySortList ){ + if (myTypeMethodBypoint && mySortList){ AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); - if( aSelectionListAttr->isInitialized() ) + if (aSelectionListAttr->isInitialized()) { std::map>::iterator anItValuesSort; QList> alist = getAttributeSelection(); @@ -344,11 +330,11 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::storeValueCustom() return true; } -//********************************************************************************** +//================================================================================================= bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() { - if ( !mySetSelection) { + if (!mySetSelection) { mySetSelection = true; return false; } @@ -356,25 +342,23 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() AttributeTablesPtr aTablesAttr; - if(myTypeMethodBypoint){ + if (myTypeMethodBypoint){ aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_ID()); - } - else{ + } else { aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); } - if( aTablesAttr->rows() == 0 ) - { - aTablesAttr->setSize(2,2); - ModelAPI_AttributeTables::Value aVar; - aVar.myDouble = 0.0; - aTablesAttr->setValue(aVar,0,0); - aVar.myDouble = 1; - aTablesAttr->setValue(aVar,0,1); - aTablesAttr->setValue(aVar,1,0); - aVar.myDouble = 2; - aTablesAttr->setValue(aVar,1,1); - } + if (aTablesAttr->rows() == 0){ + aTablesAttr->setSize(2,2); + ModelAPI_AttributeTables::Value aVar; + aVar.myDouble = 0.0; + aTablesAttr->setValue(aVar,0,0); + aVar.myDouble = 1; + aTablesAttr->setValue(aVar,0,1); + aTablesAttr->setValue(aVar,1,0); + aVar.myDouble = 2; + aTablesAttr->setValue(aVar,1,1); + } AttributeSelectionPtr anEdges = std::dynamic_pointer_cast @@ -384,9 +368,8 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() double aRes; int aRows = 0; std::map>::iterator anItValuesSort; - if(myTypeMethodBypoint) - { - if( !anEdges->isInitialized() ) + if (myTypeMethodBypoint){ + if (!anEdges->isInitialized()) return false; GeomEdgePtr anEdge = GeomEdgePtr(new GeomAPI_Edge( anEdges->value())); @@ -404,17 +387,16 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() std::set aContexts; for (int anIndex = 0; anIndex < aSelectionListAttr->size(); ++anIndex) { - AttributeSelectionPtr aSelection = aSelectionListAttr->value(anIndex); - GeomShapePtr aShape = aSelection->value(); - - ResultPtr aContext = aSelection->context(); - aContexts.insert(aContext->shape()); + AttributeSelectionPtr aSelection = aSelectionListAttr->value(anIndex); + GeomShapePtr aShape = aSelection->value(); - if (!aShape.get()) { - aShape = aContext->shape(); - } + ResultPtr aContext = aSelection->context(); + aContexts.insert(aContext->shape()); - aPoints.push_back(aShape); + if (!aShape.get()) { + aShape = aContext->shape(); + } + aPoints.push_back(aShape); } int anI =0; @@ -427,7 +409,7 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() aRes = (aPntCurv->distance(aFirst) / taille); QString aName = QString::fromStdWString(attsel->namingName()); QString aRad = findRadius( QString::number(aRes) ); - if ( myValuesSort.find( aRes ) == myValuesSort.end() ) + if (myValuesSort.find( aRes ) == myValuesSort.end()) myValuesSort[ aRes ] = std::make_pair(aName, aRad ); anI++; mySortList = true; @@ -438,27 +420,29 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() aRes = 1.0; myValuesSort[ aRes ] = std::make_pair (myLastRowValue[0], findRadius( QString::number(aRes))); aRows = myValuesSort.size(); - }else{ - ModelAPI_AttributeTables::Value aVal; - if (aTablesAttr->isInitialized()){ + } else { - for (int anIndex = 0; anIndex < aTablesAttr->rows(); ++anIndex) { - aVal = aTablesAttr->value(anIndex,0); - double aCurv = getValueText(aVal).toDouble(); - if ( myValuesSort.find( aCurv ) == myValuesSort.end() ) - myValuesSort[ aCurv ] = - std::make_pair(getValueText(aVal),findRadius(getValueText(aVal))); - } - aRows = myValuesSort.size(); - }else{ + ModelAPI_AttributeTables::Value aVal; + if (aTablesAttr->isInitialized()) { + for (int anIndex = 0; anIndex < aTablesAttr->rows(); ++anIndex) { + aVal = aTablesAttr->value(anIndex,0); + double aCurv = getValueText(aVal).toDouble(); + if ((aCurv <= 0.0 && anIndex != 0) + || (aCurv >= 1.0 && anIndex != aTablesAttr->rows()-1)) + continue; + if (myValuesSort.find( aCurv ) == myValuesSort.end()) + myValuesSort[ aCurv ] = + std::make_pair(getValueText(aVal),findRadius(getValueText(aVal))); + } + aRows = myValuesSort.size(); + } else { aRes = 0.0; myValuesSort[ aRes ] = std::make_pair (myfirstRowValue[0], myfirstRowValue[2]) ; aRes = 1.0; myValuesSort[ aRes ] = std::make_pair (myLastRowValue[0], myLastRowValue[2]) ; aRows = 2; } - } QTableWidgetItem* anItem = 0; @@ -481,43 +465,43 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() anItem = myDataTbl->item(k, 0); if (anItem) { - anItem->setText( elem.first); + anItem->setText( elem.first); } else { - anItem = new QTableWidgetItem(elem.first); - myDataTbl->setItem(k, 0, anItem); + anItem = new QTableWidgetItem(elem.first); + myDataTbl->setItem(k, 0, anItem); } anItem = myDataTbl->item(k, 1); if (anItem) { - anItem->setText( aCurv); + anItem->setText( aCurv); } else { - anItem = new QTableWidgetItem(aCurv); - myDataTbl->setItem(k, 1, anItem); + anItem = new QTableWidgetItem(aCurv); + myDataTbl->setItem(k, 1, anItem); } anItem = myDataTbl->item(k, 2); if (anItem) { - anItem->setText( elem.second); + anItem->setText( elem.second); } else { - anItem = new QTableWidgetItem(elem.second); - myDataTbl->setItem(k, 2, anItem); + anItem = new QTableWidgetItem(elem.second); + myDataTbl->setItem(k, 2, anItem); } } anItem = myDataTbl->item(myDataTbl->rowCount()-1, 0 ); - anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled ); + anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable ); anItem = myDataTbl->item(myDataTbl->rowCount()-1, 1 ); - anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled ); + anItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable ); myDataTbl->blockSignals(false); return true; } -//********************************************************************************** +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses::onAdd() { QModelIndex anIndex = myDataTbl->currentIndex(); int i = anIndex.row(); - if( i != -1 - && !(!myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2)) + if (i != -1 + && myDataTbl->currentItem()->isSelected()) { myDataTbl->blockSignals(true); @@ -553,7 +537,7 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses::onRemove() { QModelIndex anIndex = myDataTbl->currentIndex(); - if( myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2 + if (myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2 && anIndex.row() != -1 && anIndex.row() != 0 && anIndex.row() != myDataTbl->rowCount() -1){ @@ -581,18 +565,11 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses::onRemove() } } -//********************************************************************************** +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses::onTableEdited(int theRow, int theCol) { // Do not store here column of names - if (theCol != 0 && myFeature.get()) - { - - if( theCol == 1 && myDataTbl->item(theRow, theCol)->text() == "0" ) { - myDataTbl->blockSignals(true); - myDataTbl->item(theRow, theCol)->setText("0.1"); - myDataTbl->blockSignals(false); - } + if (theCol != 0 && myFeature.get()) { ModelAPI_AttributeTables::Value aVal = getValue(myDataTbl->item(theRow, theCol)->text()); @@ -603,45 +580,42 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses::onTableEdited(int theRow, int the else aTablesAttr = myFeature->data()->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - if (aTablesAttr->isInitialized()) - { + if (aTablesAttr->isInitialized()){ aTablesAttr->setValue(aVal,theRow, theCol - 1); emit valuesChanged(); } } } -//********************************************************************************** +//================================================================================================= bool FeaturesPlugin_WidgetFilletMultiRadiuses:: isValidSelectionCustom(const std::shared_ptr& thePrs) { return true; } -//********************************************************************************** +//================================================================================================= bool FeaturesPlugin_WidgetFilletMultiRadiuses::processEnter() { return true; } -//********************************************************************************** +//================================================================================================= bool FeaturesPlugin_WidgetFilletMultiRadiuses:: setSelection(QList>& theValues, const bool theToValidate) { mySortList = false; - if ( theValues.size() > 1 || !myTypeMethodBypoint || theValues.size() == 0 ) - { + if (theValues.size() > 1 || !myTypeMethodBypoint || theValues.size() == 0) { mySetSelection = false; return false; } QModelIndex index = myDataTbl->currentIndex(); - if( index.row() == -1 ) - { + if (index.row() == -1) { mySetSelection = false; return false; } - if( !myDataTbl->currentItem()->isSelected()){ + if (!myDataTbl->currentItem()->isSelected()) { mySetSelection = false; return false; } @@ -654,23 +628,23 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses:: ModuleBase_ViewerPrsPtr aValue = theValues.first(); aResult = std::dynamic_pointer_cast(aValue->object()); aShape = aValue->shape(); - if ( (aResult.get() || aShape.get() ) && !aSelList->isInList(aResult, aShape)) { + if ((aResult.get() || aShape.get() ) && !aSelList->isInList(aResult, aShape)) { aSelList->append(aResult, aShape); onRemove(); - }else{ - mySetSelection = false; - return false; + } else { + mySetSelection = false; + return false; } return true; } -//********************************************************************************** +//================================================================================================= QList> FeaturesPlugin_WidgetFilletMultiRadiuses::getAttributeSelection() const { QList> aList; - if(myFeature) { + if (myFeature) { DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelList = aData->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); @@ -686,7 +660,7 @@ QList> return aList; } -//********************************************************************************** +//================================================================================================= ModelAPI_AttributeTables::Value FeaturesPlugin_WidgetFilletMultiRadiuses::getValue(QString theStrVal) const { @@ -700,16 +674,14 @@ QString FeaturesPlugin_WidgetFilletMultiRadiuses::findRadius(QString thename) co { AttributeTablesPtr aTablesAttr; - if(myTypeMethodBypoint) + if (myTypeMethodBypoint) aTablesAttr = myFeature->data()->tables(FeaturesPlugin_Fillet::VALUES_ID()); else aTablesAttr = myFeature->data()->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - for(int i = 0; i < aTablesAttr->rows(); ++i) - { + for (int i = 0; i < aTablesAttr->rows(); ++i){ ModelAPI_AttributeTables::Value aVal = aTablesAttr->value( i, 0) ; - if( getValueText(aVal) == thename ) - { + if( getValueText(aVal) == thename ){ aVal = aTablesAttr->value( i, 1); return getValueText(aVal); } @@ -717,14 +689,14 @@ QString FeaturesPlugin_WidgetFilletMultiRadiuses::findRadius(QString thename) co return "0.5"; } -//********************************************************************************** +//================================================================================================= QString FeaturesPlugin_WidgetFilletMultiRadiuses:: getValueText(ModelAPI_AttributeTables::Value& theVal) const { return QString::number(theVal.myDouble); } -//******************************************************************** +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses:: getHighlighted(QList& theValues) { @@ -734,7 +706,7 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses:: convertIndicesToViewerSelection(anAttributeIds, theValues); } -//******************************************************************** +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses:: getSelectedAttributeIndices(std::set& theAttributeIds) { @@ -746,11 +718,12 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses:: } } +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses:: convertIndicesToViewerSelection(std::set theAttributeIds, QList& theValues) const { - if(myFeature.get() == NULL) + if (myFeature.get() == NULL) return; DataPtr aData = myFeature->data(); @@ -771,14 +744,25 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses:: } } -//******************************************************************** +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses::onListSelection() { + int aRows = myDataTbl->rowCount(); + + for (int anI = 1; anI < aRows-1; anI++) { + QString aTblVal = myDataTbl->item(anI, 1)->text(); + double aVal = aTblVal.toDouble(); + if (aVal <= 0.0 || aVal >= 1.0){ + QModelIndex anIndex = myDataTbl->model()->index(anI, 1); + myDataTbl->edit(anIndex); + break; + } + } myWorkshop->module()->customizeFeature(myFeature,ModuleBase_IModule::CustomizeHighlightedObjects, true); } -//******************************************************************** +//================================================================================================= void FeaturesPlugin_WidgetFilletMultiRadiuses::activateCustom() { ModuleBase_WidgetSelector::activateCustom(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h index 4d60f3389..b68dadcca 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h +++ b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h @@ -89,7 +89,6 @@ protected: /// The methiod called when widget is activated virtual void activateCustom(); - /// Saves the internal parameters to the given feature /// \return True in success virtual bool storeValueCustom(); @@ -102,8 +101,6 @@ protected: /// \param theEvent an event virtual bool eventFilter(QObject* theObject, QEvent* theEvent); - //virtual void showEvent(QShowEvent* theEvent); - /// Returns list of widget controls /// \return a control list virtual QList getControls() const; @@ -115,12 +112,12 @@ protected: virtual bool setSelection(QList>& theValues, const bool theToValidate); - /// Return the attribute values wrapped in a list of viewer presentations + /// Return the attribute values wrapped in a list of viewer presentations /// \return a list of viewer presentations, which contains an attribute result and /// a shape. If the attribute do not uses the shape, it is empty virtual QList> getAttributeSelection() const; - /// Returns attribute indices selected in the widget selection list + /// Returns attribute indices selected in the widget selection list /// \param theIndices a list of indices void getSelectedAttributeIndices(std::set& theIndices); @@ -173,22 +170,24 @@ private: /// Editor for table header QLineEdit* myHeaderEditor; - // Choice of the method + /// Choice of the method bool myTypeMethodBypoint; - //Sort the selection + ///Sort the selection bool mySetSelection; - + + /// my sort list bool mySortList; + /// delegate array item DataArrayItemDelegate* myDelegate; - // Label for first and last row + /// Label for first and last row std::vector myfirstRowValue; std::vector myLastRowValue; - // map to sort + + /// map to sort std::map> myValuesSort; - }; #endif \ No newline at end of file -- 2.39.2