From c895db3f0dd8412e18e70565610632bf47a0ee50 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Fri, 16 Oct 2020 17:01:32 +0200 Subject: [PATCH] Fix issues for choice of shape --- src/FeaturesAPI/FeaturesAPI_Fillet.cpp | 28 ++--- src/FeaturesAPI/FeaturesAPI_Fillet.h | 13 ++- src/FeaturesPlugin/CMakeLists.txt | 1 + src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp | 41 ++++--- src/FeaturesPlugin/FeaturesPlugin_Fillet.h | 6 ++ .../FeaturesPlugin_VersionedChFi.cpp | 101 +++++++++++------- .../FeaturesPlugin_VersionedChFi.h | 6 ++ ...aturesPlugin_WidgetFilletMultiRadiuses.cpp | 51 ++++----- src/FeaturesPlugin/fillet_widget.xml | 40 +++---- 9 files changed, 158 insertions(+), 129 deletions(-) diff --git a/src/FeaturesAPI/FeaturesAPI_Fillet.cpp b/src/FeaturesAPI/FeaturesAPI_Fillet.cpp index 49af22190..531586796 100644 --- a/src/FeaturesAPI/FeaturesAPI_Fillet.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Fillet.cpp @@ -141,14 +141,14 @@ FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr& theFeature, - const std::list& theBaseObjects, + const std::list& theEdgesFaces, const ModelHighAPI_Double& theRadius1, const ModelHighAPI_Double& theRadius2) : FeaturesAPI_Fillet(theFeature) { if (initialize()) { fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS(), mycreationMethod); - fillAttribute(theBaseObjects, mybaseObjects); + fillAttribute(theEdgesFaces, myedgesfacesselected); fillAttribute(theRadius1, mystartRadius); fillAttribute(theRadius2, myendRadius); @@ -218,16 +218,15 @@ FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptr& theFeature, - const std::list& theBaseObjects, + const std::list& theEdgesFaces, const std::list& thepointCurvCood, const std::list& theRadius) : FeaturesAPI_Fillet(theFeature) { if (initialize()) { fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_MULTIPLES_RADIUSES(), mycreationMethod); - fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_BY_CURVILEAR_ABSCISSA(), - mycreationMethodmulti); - fillAttribute(theBaseObjects, mybaseObjects); + fillAttribute(FeaturesPlugin_Fillet::CREATION_METHOD_BY_CURVILEAR_ABSCISSA(), mycreationMethodmulti); + fillAttribute(theEdgesFaces, myedgesfacesselected); int aRowIndex = 0; myvaluescurv()->setSize( thepointCurvCood.size(), 2 ); @@ -298,8 +297,7 @@ void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const aBase->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); AttributeTablesPtr anAttrTable = aBase->tables(FeaturesPlugin_Fillet::VALUES_ID()); - theDumper << aBase << " = model.addFilletMultiRadiusByPoints(" << aDocName; - theDumper << ", " << anAttrEdgeSelec; + theDumper << aBase << " = model.addFilletMultiRadiusByPoints(" << aDocName << ", " << anAttrEdgeSelec; theDumper << ", " << anAttrPoint ; theDumper<<", ["; for(int aRow = 0; aRow < myvalues()->rows(); aRow++) { @@ -311,10 +309,10 @@ void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const theDumper<<"]"; }else{ - AttributeTablesPtr anAttrTable = - aBase->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - theDumper << aBase << " = model.addFilletMultiRadiusBycurvAbs(" << aDocName; - theDumper << ", " << anAttrObjects; + AttributeSelectionListPtr anAttrEdgesFaces = + aBase->selectionList(FeaturesPlugin_Fillet::EDGES_FACES_LIST_ID()); + AttributeTablesPtr anAttrTable = aBase->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); + theDumper << aBase << " = model.addFilletMultiRadiusBycurvAbs(" << aDocName << ", " << anAttrEdgesFaces; theDumper << ", "; theDumper<<"["; for(int aRow = 0; aRow < myvaluescurv()->rows(); aRow++) { @@ -332,14 +330,18 @@ void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const theDumper<<"]"; } }else - { theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrObjects; + { std::string aCreationMethod = aBase->string(FeaturesPlugin_Fillet::CREATION_METHOD())->value(); if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_SINGLE_RADIUS()) { + theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrObjects; AttributeDoublePtr anAttrRadius = aBase->real(FeaturesPlugin_Fillet::RADIUS_ID()); theDumper << ", " << anAttrRadius; } else if(aCreationMethod == FeaturesPlugin_Fillet::CREATION_METHOD_VARYING_RADIUS()) { + AttributeSelectionListPtr anAttrEdgesFaces = + aBase->selectionList(FeaturesPlugin_Fillet::EDGES_FACES_LIST_ID()); + theDumper << aBase << " = model.addFillet(" << aDocName << ", " << anAttrEdgesFaces; AttributeDoublePtr anAttrRadius1 = aBase->real(FeaturesPlugin_Fillet::START_RADIUS_ID()); AttributeDoublePtr anAttrRadius2 = aBase->real(FeaturesPlugin_Fillet::END_RADIUS_ID()); theDumper << ", " << anAttrRadius1 << ", " << anAttrRadius2; diff --git a/src/FeaturesAPI/FeaturesAPI_Fillet.h b/src/FeaturesAPI/FeaturesAPI_Fillet.h index 367ec3523..c61c032d2 100644 --- a/src/FeaturesAPI/FeaturesAPI_Fillet.h +++ b/src/FeaturesAPI/FeaturesAPI_Fillet.h @@ -127,7 +127,7 @@ public: /// Constructor with values. FEATURESAPI_EXPORT explicit FeaturesAPI_Fillet2D(const std::shared_ptr& theFeature, - const std::list& theBaseObjects, + const std::list& theEdgesFaces, const ModelHighAPI_Double& theRadius1, const ModelHighAPI_Double& theRadius2); @@ -141,14 +141,14 @@ public: /// Constructor with values. FEATURESAPI_EXPORT explicit FeaturesAPI_Fillet2D(const std::shared_ptr& theFeature, - const std::list& theBaseObjects, + const std::list& theEdgesFaces, const std::list& thepointCurvCood, const std::list& theRadius); /// Destructor. FEATURESAPI_EXPORT virtual ~FeaturesAPI_Fillet2D(); - INTERFACE_10(FeaturesPlugin_Fillet::ID(), + INTERFACE_11(FeaturesPlugin_Fillet::ID(), creationMethod, FeaturesPlugin_Fillet::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, @@ -160,10 +160,13 @@ public: /** Base objects */, edgeselected, FeaturesPlugin_Fillet::EDGE_SELECTED_ID(), ModelAPI_AttributeSelection, - /** Base objects */, + /** edge objects */, + edgesfacesselected, FeaturesPlugin_Fillet::EDGES_FACES_LIST_ID(), + ModelAPI_AttributeSelectionList, + /** edge and face objects */, arraypointradiusbypoint, FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS(), ModelAPI_AttributeSelectionList, - /** Base objects */, + /** selection points */, myvalues, FeaturesPlugin_Fillet::VALUES_ID(), ModelAPI_AttributeTables, /** table for methode multi-radiuses by point */, diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 5c3ecc45c..089805750 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -683,6 +683,7 @@ ADD_UNIT_TESTS(TestExtrusion.py TestFillet_MultiLevelCompound_v95_2.py TestFillet_MultiLevelCompound_v95_3.py TestFillet_MultiLevelCompound_v95_4.py + TestFillet_MultiRadius.py TestChamfer_MultiLevelCompound_v0_1.py TestChamfer_MultiLevelCompound_v0_2.py TestChamfer_MultiLevelCompound_v0_3.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp index eb8794a03..41b786e73 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp @@ -66,6 +66,9 @@ void FeaturesPlugin_Fillet::initAttributes() AttributePtr aSelectionList = data()->addAttribute(OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + + data()->addAttribute(EDGES_FACES_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + data()->addAttribute(START_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(END_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); @@ -107,32 +110,26 @@ void FeaturesPlugin_Fillet::initAttributes() AttributePtr FeaturesPlugin_Fillet::objectsAttribute() { - return attribute(OBJECT_LIST_ID()); -} - -void FeaturesPlugin_Fillet::attributeChanged(const std::string& theID) -{ - if (theID == EDGE_SELECTED_ID() - && string(CREATION_METHOD())->value() == CREATION_METHOD_MULTIPLES_RADIUSES() - && string(CREATION_METHOD_MULTIPLES_RADIUSES())->value() == CREATION_METHOD_BY_POINTS()) { - - AttributeSelectionPtr anEdges = - std::dynamic_pointer_cast(attribute(EDGE_SELECTED_ID())); - AttributeSelectionListPtr array = selectionList(OBJECT_LIST_ID()); - if(array->isInitialized()) - array->clear(); - array->append(anEdges->context(), anEdges->value()); // anEdges->namingName() ); + if( string(CREATION_METHOD())->value() == CREATION_METHOD_MULTIPLES_RADIUSES() ) + { + if( string(CREATION_METHOD_MULTIPLES_RADIUSES())->value() == CREATION_METHOD_BY_POINTS()) + { + return attribute(EDGE_SELECTED_ID()); + }else{ + return attribute(EDGES_FACES_LIST_ID()); + } + }else if ( string(CREATION_METHOD())->value() == CREATION_METHOD_VARYING_RADIUS() ) + { + return attribute(EDGES_FACES_LIST_ID()); } - if( theID == OBJECT_LIST_ID() && - !(string(CREATION_METHOD())->value() == CREATION_METHOD_MULTIPLES_RADIUSES() - && string(CREATION_METHOD_MULTIPLES_RADIUSES())->value() == CREATION_METHOD_BY_POINTS() ) ){ - - data()->selection(EDGE_SELECTED_ID())->setValue(ObjectPtr(),GeomShapePtr()); - } + return attribute(OBJECT_LIST_ID()); - data()->execState(ModelAPI_StateMustBeUpdated); +} + +void FeaturesPlugin_Fillet::attributeChanged(const std::string& theID) +{ } const std::string& FeaturesPlugin_Fillet::modifiedShapePrefix() const diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h index ff7f2774d..98b406cbe 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h @@ -91,6 +91,12 @@ public: static const std::string MY_OBJECT_LIST_ID("main_objects"); return MY_OBJECT_LIST_ID; } + /// Attribute name of main objects. + inline static const std::string& EDGES_FACES_LIST_ID() + { + static const std::string MY_EDGES_FACES_LIST_ID("edges_faces_seleted"); + return MY_EDGES_FACES_LIST_ID; + } /// Attribute name of start radius. inline static const std::string& START_RADIUS_ID() diff --git a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp index 7738cf1fe..5a13070b2 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp @@ -114,58 +114,77 @@ bool FeaturesPlugin_VersionedChFi::processAttribute(const AttributePtr& theAttri { bool isStoreFullHierarchy = data()->version() == CHAMFERFILLET_VERSION_1; + AttributeSelectionPtr anObject = + std::dynamic_pointer_cast(theAttribute); + + if( anObject.get() ) + { + if ( !addShapeInHierarchy(anObject , theObjects, isStoreFullHierarchy) ) + return false; + return true; + } AttributeSelectionListPtr anObjectsSelList = std::dynamic_pointer_cast(theAttribute); for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); ++anObjectsIndex) { AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex); - GeomShapePtr anObject = anObjectAttr->value(); - if (!anObject) + + if ( !addShapeInHierarchy(anObjectAttr , theObjects, isStoreFullHierarchy) ) + return false; + } + return true; +} + +bool FeaturesPlugin_VersionedChFi::addShapeInHierarchy(const AttributeSelectionPtr& theAttribute, + GeomAPI_ShapeHierarchy& theObjects, + bool theIsStoreFullHierarchy) +{ + GeomShapePtr anObject = theAttribute->value(); + if (!anObject) + return false; + + ResultPtr aContext = theAttribute->context(); + GeomShapePtr aParent; + if (aContext.get()) { + ResultBodyPtr aCtxOwner = ModelAPI_Tools::bodyOwner(aContext); + if (aCtxOwner && aCtxOwner->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) + { + aContext = aCtxOwner; + } + aParent = aContext->shape(); + if (!aParent) return false; - ResultPtr aContext = anObjectAttr->context(); - GeomShapePtr aParent; - if (aContext.get()) { - ResultBodyPtr aCtxOwner = ModelAPI_Tools::bodyOwner(aContext); - if (aCtxOwner && aCtxOwner->shape()->shapeType() == GeomAPI_Shape::COMPSOLID) - { - aContext = aCtxOwner; + // store full shape hierarchy for the corresponding version only + 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); } - aParent = aContext->shape(); + }else + { + theObjects.addObject(anObject); + theObjects.addParent(anObject, aParent); + } + + if (theIsStoreFullHierarchy) + ModelAPI_Tools::fillShapeHierarchy(aParent, aContext, theObjects); + } else { // get it from a feature + FeaturePtr aFeature = theAttribute->contextFeature(); + if (aFeature.get()) { + aParent = aFeature->firstResult()->shape(); if (!aParent) return false; - // store full shape hierarchy for the corresponding version only - 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 - { - theObjects.addObject(anObject); - theObjects.addParent(anObject, aParent); - } - - if (isStoreFullHierarchy) - ModelAPI_Tools::fillShapeHierarchy(aParent, aContext, theObjects); - } else { // get it from a feature - FeaturePtr aFeature = anObjectAttr->contextFeature(); - if (aFeature.get()) { - aParent = aFeature->firstResult()->shape(); - if (!aParent) - return false; - - 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); - } + 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); } } } return true; -} +} \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h index 85072f996..8e51fe6e4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h +++ b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h @@ -24,6 +24,7 @@ #include #include +#include #include @@ -48,6 +49,11 @@ protected: /// Process SelectionList attribute and fill the objects hierarchy. bool processAttribute(const std::shared_ptr& theAttribute, GeomAPI_ShapeHierarchy& theObjects); + + // Add Shape in the object hierarchy + bool addShapeInHierarchy(const AttributeSelectionPtr& theAttribute, + GeomAPI_ShapeHierarchy& theObjects, + bool theIsStoreFullHierarchy); /// Return attribute storing the selected objects of the operation. virtual std::shared_ptr objectsAttribute() = 0; diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp index bcd3c225d..4dfe53b66 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp @@ -175,12 +175,10 @@ ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), myDelegate = new DataArrayItemDelegate(myTypeMethodeBypoint); - //JL_CGLB myDataTbl->installEventFilter(this); myDataTbl->setItemDelegate(myDelegate); myDataTbl->verticalHeader()->hide(); myDataTbl->setRowHeight(0, 25); - //JL_CGLB myDataTbl->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); if(myTypeMethodeBypoint){ myfirstRowValue.push_back("Start extremity"); @@ -210,7 +208,6 @@ ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), myDataTbl->setHorizontalHeaderLabels(aHeaders); - //myDataTbl->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); QTableWidgetItem* aItem; for(int j =0; j<3;j++) @@ -492,38 +489,36 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses::onAdd() { QModelIndex index = myDataTbl->currentIndex(); int i = index.row(); - if( i == -1 ) - return false; - - if( !myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2 ) - return false; - - myDataTbl->blockSignals(true); + if( i != -1 + && !(!myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2)) + { - if ( i == myDataTbl->rowCount() -1) - i = myDataTbl->rowCount() - 2; + myDataTbl->blockSignals(true); - if ( i == 0) - i = 1; - else - i= i+1; - myDataTbl->model()->insertRow(i); + if ( i == myDataTbl->rowCount() -1) + i = myDataTbl->rowCount() - 2; - QTableWidgetItem* aItem =0; + if ( i == 0) + i = 1; + else + i= i+1; + myDataTbl->model()->insertRow(i); - aItem = myDataTbl->item( i, 0 ); - aItem = new QTableWidgetItem( "" ); - myDataTbl->setItem(i, 0, aItem); + QTableWidgetItem* aItem =0; - aItem = new QTableWidgetItem("0.1"); - myDataTbl->setItem(i, 1, aItem); + aItem = myDataTbl->item( i, 0 ); + aItem = new QTableWidgetItem( "" ); + myDataTbl->setItem(i, 0, aItem); + aItem = new QTableWidgetItem("0.1"); + myDataTbl->setItem(i, 1, aItem); - aItem = new QTableWidgetItem("0.5"); - myDataTbl->setItem(i, 2, aItem); - myDataTbl->blockSignals(false); + aItem = new QTableWidgetItem("0.5"); + myDataTbl->setItem(i, 2, aItem); + myDataTbl->blockSignals(false); - emit valuesChanged(); - myDataTbl->setCurrentCell( i, 0); + emit valuesChanged(); + myDataTbl->setCurrentCell( i, 0); + } } //********************************************************************************** diff --git a/src/FeaturesPlugin/fillet_widget.xml b/src/FeaturesPlugin/fillet_widget.xml index 766fb0cb4..bedfb94e3 100644 --- a/src/FeaturesPlugin/fillet_widget.xml +++ b/src/FeaturesPlugin/fillet_widget.xml @@ -26,7 +26,7 @@ title="Varying radius" tooltip="Fillet with varying radius" icon="icons/Features/fillet_var_radius.png"> - - - - - - - - - - + + + + + + + + + -- 2.39.2