]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix problems with updating the number of faces and the list of faces cgt/sharedFaces
authorcg246364 <clarisse.genrault@cea.fr>
Mon, 25 Apr 2022 13:50:11 +0000 (15:50 +0200)
committercg246364 <clarisse.genrault@cea.fr>
Mon, 25 Apr 2022 13:50:11 +0000 (15:50 +0200)
src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp
src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp
src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp

index a531298919b965062d490e9771c6920e596e40f5..8c154ed14d82c3648cb74d7d70b4e22098ad722c 100644 (file)
@@ -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<ModelAPI_AttributeString>(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<int> aColor;
   ResultGroupPtr aGroup = document()->createGroup(data());
index cfed4a5b1b043ee4d2b95a97f8cb16f64d527a0f..994a7885281411993945ebbd55c2135ba08f9104 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <Locale_Convert.h>
 
+#include <sstream>
+
 //=================================================================================================
 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<ModelAPI_AttributeSelectionList>(
-    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<ModelAPI_AttributeSelectionList> (attributListFaces());
+  AttributeStringPtr aNumberFacesAttr =
+    std::dynamic_pointer_cast<ModelAPI_AttributeString> (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();
 }
index 8015f36ca7071b72eb311261cbb5f3faa6cea050..15eebf6d580cc8e24249cea71b2af26fdac175fe 100644 (file)
@@ -30,6 +30,8 @@
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_Validator.h>
 
+#include <sstream>
+
 //=================================================================================================
 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<ModelAPI_AttributeSelectionList>(
-    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<ModelAPI_AttributeSelectionList> (attributListFaces());
+  AttributeStringPtr aNumberFacesAttr =
+    std::dynamic_pointer_cast<ModelAPI_AttributeString> (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<ModelAPI_AttributeSelectionList>
                                (myCreateGroupFeature->attribute(LIST_FACES_ID()));