#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>
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;
}
{
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;
}
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) {
// (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
}
}
+ // 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
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
#include <ModelAPI_Tools.h>
#include <ModelGeomAlgo_Shape.h>
++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;
}
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());