]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Dump with geometrical selection
authorazv <azv@opencascade.com>
Mon, 20 Aug 2018 13:25:32 +0000 (16:25 +0300)
committerazv <azv@opencascade.com>
Thu, 30 Aug 2018 08:39:21 +0000 (11:39 +0300)
* Fix problem with selection of shapes in compsolid
* Correct selection of separate vertices in sketch
* Dump by geometric: avoid checking parent features for searching selection point

src/GeomAPI/GeomAPI_Shape.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Shape.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Tools.cpp

index c686bbf77ad6c1f70b68ddaf88317dac9dbb2ab8..369ad7ef128e41cdb5157ed0364b7c1110418b81 100644 (file)
@@ -568,6 +568,8 @@ bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmi
     return false;
   Bnd_Box aBndBox;
   BRepBndLib::Add(aShape, aBndBox);
+  if (aBndBox.IsVoid())
+    return false;
   aBndBox.Get(theXmin, theYmin, theZmin, theXmax, theYmax, theZmax);
   return true;
 }
index ca7809b3906a09014590f8416afec48dec5d93d5..f5fe49d129033927821fb6a8725fd47e8b18cd3d 100644 (file)
 
 #include "ModelGeomAlgo_Shape.h"
 
+#include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultCompSolid.h>
 #include <ModelAPI_ResultConstruction.h>
 
 #include <GeomAPI_PlanarEdges.h>
@@ -57,8 +59,8 @@ namespace ModelGeomAlgo_Shape
                               const double theTolerance)
   {
     double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
-    theShape->computeSize(aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
-    return thePoint->x() >= aXMin - theTolerance && thePoint->x() <= aXMax + theTolerance &&
+    return theShape->computeSize(aXMin, aYMin, aZMin, aXMax, aYMax, aZMax) &&
+           thePoint->x() >= aXMin - theTolerance && thePoint->x() <= aXMax + theTolerance &&
            thePoint->y() >= aYMin - theTolerance && thePoint->y() <= aYMax + theTolerance &&
            thePoint->z() >= aZMin - theTolerance && thePoint->z() <= aZMax + theTolerance;
   }
@@ -71,8 +73,9 @@ namespace ModelGeomAlgo_Shape
   {
     std::list<GeomShapePtr> aSubs = theShape->subShapes(theType);
     for (std::list<GeomShapePtr>::const_iterator aSubIt = aSubs.begin();
-      aSubIt != aSubs.end(); ++aSubIt) {
-      if ((*aSubIt)->middlePoint()->distance(thePoint) < theTolerance)
+         aSubIt != aSubs.end(); ++aSubIt) {
+      GeomPointPtr aMiddlePoint = (*aSubIt)->middlePoint();
+      if (aMiddlePoint && aMiddlePoint->distance(thePoint) < theTolerance)
         return *aSubIt;
     }
 
@@ -89,6 +92,7 @@ namespace ModelGeomAlgo_Shape
     static const double TOLERANCE = 1.e-7;
 
     theResult = ResultPtr();
+    theSubshape = GeomShapePtr();
     const std::list<ResultPtr>& aResults = theFeature->results();
     for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
          aResIt != aResults.end(); ++aResIt) {
@@ -101,11 +105,31 @@ namespace ModelGeomAlgo_Shape
       // (it will be processed later)
       std::shared_ptr<GeomAPI_PlanarEdges> aSketchEdges =
           std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aCurShape);
-      if (theShapeType != GeomAPI_Shape::COMPOUND || !aSketchEdges)
-        theSubshape = findSubShape(aCurShape, theShapeType, thePoint, TOLERANCE);
-      if (theSubshape) {
-        theResult = *aResIt;
-        break;
+      if (theShapeType != GeomAPI_Shape::COMPOUND || !aSketchEdges) {
+        ResultCompSolidPtr aCompSolid =
+            std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIt);
+        if (aCompSolid) {
+          // process solids
+          int aNbSolids = aCompSolid->numberOfSubs();
+          for (int i = 0; i < aNbSolids && !theSubshape; ++i) {
+            ResultPtr aSubResult = aCompSolid->subResult(i);
+            GeomShapePtr aSubSolid = aSubResult->shape();
+            if (aSubSolid && isPointWithinBB(thePoint, aSubSolid, TOLERANCE)) {
+              theSubshape = findSubShape(aSubSolid, theShapeType, thePoint, TOLERANCE);
+              if (theSubshape)
+                theResult = aSubResult;
+            }
+          }
+          if (theSubshape)
+            break;
+        }
+
+        if (!theSubshape)
+          theSubshape = findSubShape(aCurShape, theShapeType, thePoint, TOLERANCE);
+        if (theSubshape) {
+          theResult = *aResIt;
+          break;
+        }
       }
 
       // special case for ResultConstruction if the FACE is selected
@@ -139,6 +163,34 @@ namespace ModelGeomAlgo_Shape
       }
     }
 
+    // one more special case: a vertex selected is a sketch point;
+    // it is not included into sketch result; thus, it is necessary
+    // to pass through the sketch sub-features and verify all points
+    if (!theResult && theShapeType == GeomAPI_Shape::VERTEX && !aResults.empty()) {
+      CompositeFeaturePtr aCF = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
+      std::shared_ptr<GeomAPI_PlanarEdges> aSketchEdges =
+          std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aResults.front()->shape());
+
+      if (aSketchEdges && aCF) {
+        bool isContinue = true;
+        int aNbSubs = aCF->numberOfSubs();
+        for (int aSubInd = 0; aSubInd < aNbSubs && isContinue; ++aSubInd) {
+          FeaturePtr aSub = aCF->subFeature(aSubInd);
+          const std::list<ResultPtr>& aSubResults = aSub->results();
+          for (std::list<ResultPtr>::const_iterator aSRIt = aSubResults.begin();
+               aSRIt != aSubResults.end(); ++aSRIt) {
+            GeomShapePtr aCurShape = (*aSRIt)->shape();
+            theSubshape = findSubShape(aCurShape, theShapeType, thePoint, TOLERANCE);
+            if (theSubshape) {
+              theResult = aResults.front();
+              isContinue = false;
+              break;
+            }
+          }
+        }
+      }
+    }
+
     return (bool)theResult;
   }
 } // namespace ModelGeomAlgo_Shape
index 1cbee858ccde9c64986d022ac75321d186033e1d..d9169c62901dc4f7adeef301227679982d7c7e34 100644 (file)
@@ -51,6 +51,7 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
 
 #include <ModelGeomAlgo_Shape.h>
@@ -961,16 +962,64 @@ static int possibleSelectionsByPoint(const GeomPointPtr& thePoint,
     ++aFIt;
   }
 
-  ResultPtr aResult;
-  GeomShapePtr aSubshape;
+  // collect the list of composite features, containing the last feature;
+  // these features should be excluded from searching,
+  // because the feature cannot select sub-shapes from its parent
+  std::set<CompositeFeaturePtr> aEndFeatureParents;
+  for (FeaturePtr aCurFeat = theEndFeature; aCurFeat;) {
+    CompositeFeaturePtr aFoundComposite;
+    const std::set<AttributePtr>& aRefs = aCurFeat->data()->refsToMe();
+    for (std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
+         anIt != aRefs.end(); ++anIt) {
+      FeaturePtr aF = ModelAPI_Feature::feature((*anIt)->owner());
+      aFoundComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aF);
+      if (aFoundComposite && aFoundComposite->isSub(aCurFeat))
+        break;
+      else
+        aFoundComposite = CompositeFeaturePtr();
+    }
+
+    if (aFoundComposite) {
+      aEndFeatureParents.insert(aFoundComposite);
+      aCurFeat = aFoundComposite;
+    }
+    else {
+      // add the part containing high-level feature
+      SessionPtr aSession = ModelAPI_Session::get();
+      DocumentPtr aPartSetDoc = aSession->moduleDocument();
+      std::list<FeaturePtr> aPartSetFeatures = aPartSetDoc->allFeatures();
+      for (std::list<FeaturePtr>::const_iterator anIt = aPartSetFeatures.begin();
+           anIt != aPartSetFeatures.end(); ++anIt) {
+        aFoundComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anIt);
+        if (aFoundComposite && aFoundComposite->isSub(aCurFeat)) {
+          aEndFeatureParents.insert(aFoundComposite);
+          break;
+        }
+      }
+
+      aCurFeat = FeaturePtr();
+    }
+  }
+
   int aNbPossibleSelections = 0;
   for (; aFIt != aFeatures.end() && *aFIt != theEndFeature; ++aFIt) {
+    bool isSkipFeature = false;
     if (aLastCompositeFeature && aLastCompositeFeature->isSub(*aFIt))
-      continue;
+      isSkipFeature = true;
     CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFIt);
-    if (aCompFeat)
+    if (aCompFeat) {
       aLastCompositeFeature = aCompFeat;
+      if (aEndFeatureParents.find(aLastCompositeFeature) != aEndFeatureParents.end()) {
+        // do not process the parent for the last feature,
+        // because it cannot select objects from its parent
+        isSkipFeature = true;
+      }
+    }
+    if (isSkipFeature)
+      continue;
 
+    ResultPtr aResult;
+    GeomShapePtr aSubshape;
     if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theType, aResult, aSubshape))
       ++aNbPossibleSelections;
   }
@@ -1011,6 +1060,13 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
 
   myDumpBuffer << "\"" << aShape->shapeTypeStr();
   if (isDumpByGeom) {
+    // check the selected item is a ResultPart;
+    // in this case it is necessary to get shape with full transformation
+    // for correct calculation of the middle point
+    ResultPartPtr aResPart =
+        std::dynamic_pointer_cast<ModelAPI_ResultPart>(theAttrSelect->context());
+    if (aResPart)
+      aShape = aResPart->shape();
     GeomPointPtr aMiddlePoint = aShape->middlePoint();
     // calculate number of features, which could be selected by the same point
     FeaturePtr anOwner = ModelAPI_Feature::feature(theAttrSelect->owner());
index 87146a7a7fe6e2954fe8be60f1bc8e1787a7afb6..f11d8c09902f42f2e2e36c8b0968ff4b96a4ac49 100644 (file)
@@ -305,6 +305,13 @@ GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection
       aShapeType = shapeTypeByStr(aType);
       break;
     }
+    case ModelHighAPI_Selection::VT_TypeInnerPointPair: {
+      TypeInnerPointPair aPair = theSelection.typeInnerPointPair();
+      std::string aType = aPair.first;
+      aType = aType.substr(0, aType.find_first_of('_'));
+      aShapeType = shapeTypeByStr(aType);
+      break;
+    }
   }
 
   return aShapeType;