]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update validation and filtration of the same shapes taking into account selection...
authormpv <mpv@opencascade.com>
Fri, 24 Aug 2018 07:22:43 +0000 (10:22 +0300)
committermpv <mpv@opencascade.com>
Fri, 24 Aug 2018 07:22:59 +0000 (10:22 +0300)
src/GeomValidators/GeomValidators_DifferentShapes.cpp
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/PartSet/PartSet_Validators.cpp

index 985f7acf061df9d556354343f239a7d42f1bd584..69a981be699f7741b1e34a6091e1d5dc344c0afb 100644 (file)
@@ -94,11 +94,13 @@ bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list<AttributePtr>
     std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theCurrentAttribute);
 
   GeomShapePtr aShape = aSelectionAttribute->value();
+  ResultPtr aResultContext = aSelectionAttribute->context();
   if (!aShape.get()) {
-    ResultPtr aResult = aSelectionAttribute->context();
-    if (aResult.get())
-      aShape = aResult->shape();
+    if (aResultContext.get())
+      aShape = aResultContext->shape();
   }
+  // whole feature selection
+  FeaturePtr aFeature = aSelectionAttribute->contextFeature();
 
   std::string aCurrentAttributeId = theCurrentAttribute->id();
   if (theAttributes.size() > 0 && aShape.get() != NULL) {
@@ -112,14 +114,31 @@ bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list<AttributePtr>
         // the shape of the attribute should be not the same
         if (aSelectionAttribute.get() != NULL) {
           GeomShapePtr anAttrShape = aSelectionAttribute->value();
+          ResultPtr aResult = aSelectionAttribute->context();
           if (!anAttrShape.get()) {
-            ResultPtr aResult = aSelectionAttribute->context();
             if (aResult.get())
               anAttrShape = aResult->shape();
           }
           if (aShape->isEqual(anAttrShape)) {
             return false;
           }
+          if (aFeature.get()) {
+            if (aResult.get()) { // check result is in feature
+              if (aResult->document()->feature(aResult) == aFeature)
+                return false;
+            }
+            else { // check selection of the same features
+              if (aFeature == aSelectionAttribute->contextFeature())
+                return false;
+            }
+          }
+          else {
+            if (!aResult.get() && aResultContext.get()) {
+              FeaturePtr aSelectedFeature = aSelectionAttribute->contextFeature();
+              if (aResultContext->document()->feature(aResultContext) == aSelectedFeature)
+                return false;
+            }
+          }
         }
       }
     }
index 91713b65bdde0e49799647589065311d34c23e3b..76dfc29094a1d461ed64b1b8504cc063ece2eef2 100644 (file)
@@ -421,31 +421,42 @@ void ModuleBase_WidgetValidated::filterPresentations(QList<ModuleBase_ViewerPrsP
 //********************************************************************
 void ModuleBase_WidgetValidated::filterCompSolids(QList<ModuleBase_ViewerPrsPtr>& theValues)
 {
-  std::set<ResultBodyPtr> aCompSolids;
+  std::set<ResultPtr> aFilterOut; // all objects that must be filtered out with their children
   QList<ModuleBase_ViewerPrsPtr> aValidatedValues;
 
   // Collect compsolids.
   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
-  for (; anIt != aLast; anIt++) {
+  for(; anIt != aLast; anIt++) {
     const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
     ObjectPtr anObject = aViewerPrs->object();
     ResultBodyPtr aResultCompSolid =
       std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
-    if(aResultCompSolid.get() && aResultCompSolid->numberOfSubs() > 0) {
-      aCompSolids.insert(aResultCompSolid);
+    if (aResultCompSolid.get()) {
+      for(int aSubIndex = 0; aSubIndex < aResultCompSolid->numberOfSubs(); aSubIndex++)
+        aFilterOut.insert(aResultCompSolid->subResult(aSubIndex));
+    } else { // it could be a whole feature selected, so, add all results of this feature
+      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+      if (aFeature.get()) {
+        std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
+        for(; aRes != aFeature->results().cend(); aRes++)
+          aFilterOut.insert(*aRes);
+      }
     }
   }
 
   // Filter sub-solids of compsolids.
   anIt = theValues.begin();
-  for (; anIt != aLast; anIt++) {
+  for(; anIt != aLast; anIt++) {
     const ModuleBase_ViewerPrsPtr& aViewerPrs = *anIt;
     ObjectPtr anObject = aViewerPrs->object();
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-    ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(aResult);
-    if(aResCompSolidPtr.get() && (aCompSolids.find(aResCompSolidPtr) != aCompSolids.end())) {
-      // Skip sub-solid of compsolid.
-      continue;
+    while(aResult.get()) {
+      if (aFilterOut.find(aResult) != aFilterOut.end()) // skip if parent is filtered out
+        break;
+      aResult = ModelAPI_Tools::bodyOwner(aResult); // iterate all parents
+    }
+    if (aResult.get()) {
+      continue; // skip
     } else {
       aValidatedValues.append(*anIt);
     }
index 32fea83989156974e215e1ba842a8fc613b67ce2..f1cef74475834d0dc22a19a8a19fec40d38d85f5 100755 (executable)
@@ -500,6 +500,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
     AttributeSelectionPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
     ResultPtr aContext = anAttr->context();
+    FeaturePtr aContextFeature = anAttr->contextFeature();
     GeomShapePtr aShape = anAttr->value();
 
     // Check selection attributes
@@ -518,6 +519,24 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
               return false;
             }
           }
+          // check the whole selected feature contains the result
+          if (aContextFeature.get()) {
+            if (aRef->contextFeature().get()) {
+              if (aContextFeature == aRef->contextFeature()) {
+                theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id());
+                return false;
+              }
+            } else if (aRef->context().get() &&
+                aRef->context()->document()->feature(aRef->context()) == aContextFeature) {
+              theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id());
+              return false;
+            }
+          } else if (aRef->contextFeature().get() && aContext.get()) {
+            if (aContext->document()->feature(aContext) == aRef->contextFeature()) {
+              theError = errorMessage(EqualShapes, "", theAttribute->id(), aRef->id());
+              return false;
+            }
+          }
         }
       }
     }
@@ -558,6 +577,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
           for(int i = 0; i < aCurSelList->size(); i++) {
             std::shared_ptr<ModelAPI_AttributeSelection> aCurSel = aCurSelList->value(i);
             ResultPtr aCurSelContext = aCurSel->context();
+            FeaturePtr aCurSelFeature = aCurSel->contextFeature();
             ResultBodyPtr aCurSelCompSolidPtr = ModelAPI_Tools::bodyOwner(aCurSelContext);
             std::shared_ptr<GeomAPI_Shape> aCurSelCompSolid;
             if(aCurSelCompSolidPtr.get()) {
@@ -566,27 +586,47 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
             for(int j = 0; j < aRefSelList->size(); j++) {
               std::shared_ptr<ModelAPI_AttributeSelection> aRefSel = aRefSelList->value(j);
               ResultPtr aRefSelContext = aRefSel->context();
+              FeaturePtr aRefSelFeature = aRefSel->contextFeature();
               ResultBodyPtr aRefSelCompSolidPtr =
                 ModelAPI_Tools::bodyOwner(aRefSelContext);
               std::shared_ptr<GeomAPI_Shape> aRefSelCompSolid;
-              if(aRefSelCompSolidPtr.get()) {
+              if (aRefSelCompSolidPtr.get()) {
                 aRefSelCompSolid = aRefSelCompSolidPtr->shape();
               }
               if ((aCurSelCompSolid.get() && aCurSelCompSolid->isEqual(aRefSel->value()))
                 || (aRefSelCompSolid.get() && aRefSelCompSolid->isEqual(aCurSel->value()))) {
-                  theError = errorMessage(EqualShapes, "", theAttribute->id(),
-                                          aRefSel->id());
-                  return false;
+                theError = errorMessage(EqualShapes, "", theAttribute->id(),
+                  aRefSel->id());
+                return false;
               }
-              if(aCurSelContext == aRefSelContext) {
+              if (aCurSelContext == aRefSelContext) {
                 if (aCurSel->value().get() == NULL || aRefSel->value().get() == NULL) {
-                  theError = errorMessage(EmptyShapes, "", theAttribute->id(),
-                                          aRefSel->id());
+                  theError = errorMessage(EmptyShapes, "", theAttribute->id(), aRefSel->id());
                   return false;
                 }
                 if (aCurSel->value()->isEqual(aRefSel->value())) {
-                  theError = errorMessage(EqualShapes, "", theAttribute->id(),
-                                          aRefSel->id());
+                  theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
+                  return false;
+                }
+              }
+
+              // check the whole selected feature contains the result
+              if (aCurSelFeature.get()) {
+                if (aRefSelFeature.get()) {
+                  if (aCurSelFeature == aRefSelFeature) {
+                    theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
+                    return false;
+                  }
+                }
+                else if (aRefSelContext.get() &&
+                  aRefSelContext->document()->feature(aRefSelContext) == aCurSelFeature) {
+                  theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
+                  return false;
+                }
+              }
+              else if (aRefSelFeature.get() && aCurSelContext.get()) {
+                if (aCurSelContext->document()->feature(aCurSelContext) == aRefSelFeature) {
+                  theError = errorMessage(EqualShapes, "", theAttribute->id(), aRefSel->id());
                   return false;
                 }
               }