From: cg246364 Date: Mon, 25 Apr 2022 13:50:11 +0000 (+0200) Subject: Fix problems with updating the number of faces and the list of faces X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fcgt%2FsharedFaces;p=modules%2Fshaper.git Fix problems with updating the number of faces and the list of faces --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp index a53129891..8c154ed14 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp @@ -57,19 +57,21 @@ void FeaturesPlugin_CommonSharedFaces::updateFaces() ListOfShape::const_iterator anIt = aFaces.cbegin(); for(; anIt != aFaces.cend(); ++anIt) { GeomShapePtr aFacePtr = *anIt; - aFacesListAttr->append(aCompSolidAttr->context(), aFacePtr); + if (!(aFacesListAttr->isInList(aCompSolidAttr->context(), aFacePtr))) { + aFacesListAttr->append(aCompSolidAttr->context(), aFacePtr); + } } - std::stringstream alabel; - alabel << aFacesListAttr->size(); + std::stringstream aLabel; + aLabel << aFacesListAttr->size(); AttributeStringPtr aNumberFacesAttr = std::dynamic_pointer_cast(attributNumberFaces()); - aNumberFacesAttr->setValue(alabel.str()); + aNumberFacesAttr->setValue(aLabel.str()); } } } //================================================================================================= -void FeaturesPlugin_CommonSharedFaces::setFacesGroup(const std::wstring& theName ) +void FeaturesPlugin_CommonSharedFaces::setFacesGroup(const std::wstring& theName) { std::vector aColor; ResultGroupPtr aGroup = document()->createGroup(data()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp index cfed4a5b1..994a78852 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp @@ -30,6 +30,8 @@ #include +#include + //================================================================================================= FeaturesPlugin_GroupSharedFaces::FeaturesPlugin_GroupSharedFaces() { @@ -38,11 +40,8 @@ FeaturesPlugin_GroupSharedFaces::FeaturesPlugin_GroupSharedFaces() //================================================================================================= void FeaturesPlugin_GroupSharedFaces::initAttributes() { - // attribute for object selected data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - AttributeSelectionListPtr aList = std::dynamic_pointer_cast( - data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId())); - + data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId()); data()->addAttribute(NUMBER_FACES_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(GROUP_NAME_ID(), ModelAPI_AttributeString::typeId()); @@ -51,6 +50,8 @@ void FeaturesPlugin_GroupSharedFaces::initAttributes() ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TRANSPARENCY_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), NUMBER_FACES_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LIST_FACES_ID()); + data()->boolean(COMPUTE_ID())->setValue(true); } @@ -83,7 +84,7 @@ void FeaturesPlugin_GroupSharedFaces::execute() { if (selectionList(LIST_FACES_ID())->isInitialized() && string(GROUP_NAME_ID())->value() != "") { - AttributeStringPtr aNameAtt = string( GROUP_NAME_ID() ) ; + AttributeStringPtr aNameAtt = string(GROUP_NAME_ID()) ; std::wstring aNameFace = aNameAtt->isUValue() ? Locale::Convert::toWString(aNameAtt->valueU()) : Locale::Convert::toWString(aNameAtt->value()); @@ -111,11 +112,20 @@ void FeaturesPlugin_GroupSharedFaces::execute() ModelAPI_Tools::setTransparency(*aRes, aTranparency); } } + + // Update the number of shared faces + AttributeSelectionListPtr aFacesListAttr = + std::dynamic_pointer_cast (attributListFaces()); + AttributeStringPtr aNumberFacesAttr = + std::dynamic_pointer_cast (attributNumberFaces()); + std::stringstream aLabel; + aLabel << aFacesListAttr->size(); + aNumberFacesAttr->setValue(aLabel.str()); } //================================================================================================= void FeaturesPlugin_GroupSharedFaces::attributeChanged(const std::string& theID) { - if (theID == OBJECT_ID()) + if (theID == OBJECT_ID() || theID == LIST_FACES_ID()) updateFaces(); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp index 8015f36ca..15eebf6d5 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp @@ -30,6 +30,8 @@ #include #include +#include + //================================================================================================= FeaturesPlugin_SharedFaces::FeaturesPlugin_SharedFaces() { @@ -38,10 +40,8 @@ FeaturesPlugin_SharedFaces::FeaturesPlugin_SharedFaces() //================================================================================================= void FeaturesPlugin_SharedFaces::initAttributes() { - // attribute for object selected data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - AttributeSelectionListPtr aList = std::dynamic_pointer_cast( - data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId())); + data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId()); data()->addAttribute(NUMBER_FACES_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeInteger::typeId()); @@ -127,13 +127,21 @@ void FeaturesPlugin_SharedFaces::execute() ModelAPI_Tools::setTransparency(*aRes, aTranparency); } } + + // Update the number of shared faces + AttributeSelectionListPtr aFacesListAttr = + std::dynamic_pointer_cast (attributListFaces()); + AttributeStringPtr aNumberFacesAttr = + std::dynamic_pointer_cast (attributNumberFaces()); + std::stringstream aLabel; + aLabel << aFacesListAttr->size(); + aNumberFacesAttr->setValue(aLabel.str()); } //================================================================================================= void FeaturesPlugin_SharedFaces::attributeChanged(const std::string& theID) { if (theID == OBJECT_ID()) { - updateFaces(); if (myCreateGroupFeature.get()) updateGroup(); @@ -158,11 +166,10 @@ void FeaturesPlugin_SharedFaces::updateGroup() { myCreateGroupFeature->boolean(FeaturesPlugin_GroupSharedFaces::COMPUTE_ID())->setValue(false); myCreateGroupFeature->string(FeaturesPlugin_GroupSharedFaces::GROUP_NAME_ID()) - ->setValue( string(GROUP_NAME_ID())->value()); + ->setValue(string(GROUP_NAME_ID())->value()); myCreateGroupFeature->selection(FeaturesPlugin_GroupSharedFaces::OBJECT_ID()) - ->setValue( selection(OBJECT_ID())->context() , - selection(OBJECT_ID())->value() ); + ->setValue(selection(OBJECT_ID())->context(), selection(OBJECT_ID())->value()); AttributeSelectionListPtr aFacesFeatures = std::dynamic_pointer_cast (myCreateGroupFeature->attribute(LIST_FACES_ID()));