Salome HOME
* store result only after checking if sewn
authormbs <martin.bernhard@opencascade.com>
Fri, 2 Dec 2022 09:35:32 +0000 (09:35 +0000)
committerGérald NICOLAS <gerald.nicolas@edf.fr>
Wed, 1 Feb 2023 16:32:06 +0000 (17:32 +0100)
* fixed isSewn method
* code cleanup

src/FeaturesPlugin/FeaturesPlugin_Sewing.cpp
src/FeaturesPlugin/FeaturesPlugin_Sewing.h

index 8282f66c12df149fe2787c928ab39256444d9af1..c8319e6fc09382bef1d12fda2e3882804fee8e3f 100644 (file)
 
 #include <FeaturesPlugin_Sewing.h>
 
-//#include <GeomAlgoAPI_MakeShape.h>
 #include <GeomAlgoAPI_Sewing.h>
 #include <GeomAlgoAPI_Tools.h>
 
-//#include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_Shape.h>
-//#include <GeomAPI_ShapeExplorer.h>
-//#include <GeomAPI_ShapeIterator.h>
 
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_ResultBody.h>
-//#include <ModelAPI_ResultConstruction.h>
-
-//---------------------------------------------------------
-// #define USE_DEBUG
-// #define DEBUG
-// static const char *dbg_class = "FeaturesPlugin_Sewing";
-// #include "MBDebug.h"
-// #include "MBModel.h"
-// #include "MBGeom.h"
-//---------------------------------------------------------
 
 
 
 //=================================================================================================
 FeaturesPlugin_Sewing::FeaturesPlugin_Sewing()
 {
-//  DBG_FUN();
 }
 
 //=================================================================================================
 void FeaturesPlugin_Sewing::initAttributes()
 {
-//  DBG_FUN();
-
   data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
   data()->addAttribute(ALLOW_NON_MANIFOLD_ID(), ModelAPI_AttributeBoolean::typeId());
   data()->addAttribute(TOLERANCE_ID(), ModelAPI_AttributeDouble::typeId());
@@ -65,40 +48,26 @@ void FeaturesPlugin_Sewing::initAttributes()
 //=================================================================================================
 void FeaturesPlugin_Sewing::execute()
 {
-//  DBG_FUN();
-
   // Collect all base shapes
   ListOfShape aShapes;
   getOriginalShapes(OBJECTS_LIST_ID(), aShapes);
-//  SHOW(aShapes);
 
   // Get all other feature arguments
   bool isAllowNonManifold = boolean(FeaturesPlugin_Sewing::ALLOW_NON_MANIFOLD_ID())->value();
   bool isAlwaysCreateResult = boolean(FeaturesPlugin_Sewing::ALWAYS_CREATE_RESULT_ID())->value();
   double aTolerance = real(FeaturesPlugin_Sewing::TOLERANCE_ID())->value();
-  // SHOW(isAllowNonManifold);
-  // SHOW(isAlwaysCreateResult);
-  // SHOW(aTolerance);
 
   std::shared_ptr<GeomAlgoAPI_Sewing> aSewingAlgo(new GeomAlgoAPI_Sewing(aShapes, isAllowNonManifold, aTolerance));
 
   std::string anError;
   if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSewingAlgo, getKind(), anError))
   {
-    // SHOW(anError);
     setError(anError);
     return;
   }
     
   // Store result.
   GeomShapePtr aResult = aSewingAlgo->shape();
-  // SHOW(aResult);
-
-  int anIndex = 0;
-  ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
-  // SHOW(aResultBody);
-  aResultBody->storeModified(aShapes, aResult, aSewingAlgo);
-  // SHOW(aResultBody);
 
   if (!isSewn(aShapes, aResult) && !isAlwaysCreateResult)
   {
@@ -107,6 +76,10 @@ void FeaturesPlugin_Sewing::execute()
     return;
   }
 
+  int anIndex = 0;
+  ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
+  aResultBody->storeModified(aShapes, aResult, aSewingAlgo);
+
   setResult(aResultBody, anIndex);
 }
 
@@ -114,9 +87,6 @@ void FeaturesPlugin_Sewing::execute()
 void FeaturesPlugin_Sewing::getOriginalShapes(const std::string& theAttributeName,
                                               ListOfShape&       theShapes)
 {
-  // DBG_FUN();
-  // ARG(theAttributeName);
-
   // Collect all selections into a single list of shapes
   AttributeSelectionListPtr aSelectionList = selectionList(theAttributeName);
   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex)
@@ -136,10 +106,6 @@ void FeaturesPlugin_Sewing::getOriginalShapes(const std::string& theAttributeNam
 bool FeaturesPlugin_Sewing::isSewn(const ListOfShape& theInputs,
                                    const GeomShapePtr theResult)
 {
-  // DBG_FUN();
-  // ARG(theInputs);
-  // ARG(theResult);
-
   // Consider the list of input shapes the same as the result, if
   //  * both arguments have the same number of shells
   //  * the total number of faces in these shells did NOT change.
@@ -155,13 +121,10 @@ bool FeaturesPlugin_Sewing::isSewn(const ListOfShape& theInputs,
       nbInputFaces += aShape->subShapes(GeomAPI_Shape::FACE, true).size();
     }
   }
-  // SHOW(nbInputShells);
-  // SHOW(nbInputFaces);
 
   int nbResultShells = 0, nbResultFaces = 0;
   if (theResult->isCompound())
   {
-    // MSGEL("...result is COMPOUND");
     ListOfShape shells = theResult->subShapes(GeomAPI_Shape::SHELL, true);
     nbResultShells = shells.size();
     for (ListOfShape::const_iterator anIt = shells.cbegin();
@@ -177,12 +140,9 @@ bool FeaturesPlugin_Sewing::isSewn(const ListOfShape& theInputs,
   }
   else if (theResult->isShell())
   {
-    // MSGEL("...result is single SHELL");
     nbResultShells = 1;
     nbResultFaces = theResult->subShapes(GeomAPI_Shape::FACE, true).size();
   }
-  // SHOW(nbResultShells);
-  // SHOW(nbResultFaces);
 
-  return (nbResultShells >= nbInputShells && nbResultFaces > nbInputFaces);
+  return (nbResultShells > nbInputShells || (nbResultShells == nbInputShells && nbResultFaces > nbInputFaces));
 }
index 815ad1aac0bb45d496878d6f6176fbcb1b0ff3b7..2a368f6f3625814a82da3c2a894604cca48331e4 100644 (file)
@@ -23,7 +23,6 @@
 #include <FeaturesPlugin.h>
 
 #include <ModelAPI_Feature.h>
-//#include <GeomAlgoAPI_MakeShape.h>
 #include <GeomAPI_Shape.h>