}
ResultPtr aFoundResult;
GeomShapePtr aFoundSubShape;
+ int aFoundCenterType;
// collect features from PartSet and the current part
SessionPtr aSession = ModelAPI_Session::get();
continue;
// process results of the current feature to find appropriate sub-shape
+ aFoundCenterType = (int)ModelAPI_AttributeSelection::NOT_CENTER;
if (ModelGeomAlgo_Shape::findSubshapeByPoint(*anIt, thePoint, aType,
- aFoundResult, aFoundSubShape)) {
+ aFoundResult, aFoundSubShape, aFoundCenterType)) {
if (aSelectionIndex > 0)
--aSelectionIndex; // skip this shape, because one of the previous is selected
else {
- setValue(aFoundResult, aFoundSubShape);
+ if (aFoundCenterType == (int)ModelAPI_AttributeSelection::NOT_CENTER)
+ setValue(aFoundResult, aFoundSubShape);
+ else
+ setValueCenter(aFoundResult, aFoundSubShape->edge(),
+ (ModelAPI_AttributeSelection::CenterType)aFoundCenterType);
return;
}
}
aNewAttr->setID(id());
mySize->Set(aNewTag);
aNewAttr->selectSubShape(theType, thePoint);
- if (selectionType().empty())
- setSelectionType(aNewAttr->value()->shapeTypeStr());
owner()->data()->sendAttributeUpdated(this);
}
#include "ModelGeomAlgo_Shape.h"
+#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_ResultCompSolid.h>
#include <ModelAPI_ResultConstruction.h>
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Ellipse.h>
#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_Pnt.h>
return GeomShapePtr();
}
+ // Find circular/elliptical edge, which center/focus coincide with the given point
+ static GeomShapePtr findEdgeByCenter(const GeomShapePtr& theBaseShape,
+ const GeomPointPtr& theCenter,
+ const double theTolerance,
+ int& theCenterType)
+ {
+ theCenterType = (int)ModelAPI_AttributeSelection::NOT_CENTER;
+ std::list<GeomShapePtr> anEdges = theBaseShape->subShapes(GeomAPI_Shape::EDGE);
+ for (std::list<GeomShapePtr>::const_iterator anIt = anEdges.begin();
+ anIt != anEdges.end(); ++anIt) {
+ GeomEdgePtr anEdge = (*anIt)->edge();
+ if (!anEdge)
+ continue;
+
+ if (anEdge->isCircle()) {
+ GeomCirclePtr aCircle = anEdge->circle();
+ if (aCircle->center()->distance(theCenter) < theTolerance) {
+ theCenterType = (int)ModelAPI_AttributeSelection::CIRCLE_CENTER;
+ return *anIt;
+ }
+ }
+ else if (anEdge->isEllipse()) {
+ GeomEllipsePtr anEllipse = anEdge->ellipse();
+ if (anEllipse->firstFocus()->distance(theCenter) < theTolerance)
+ theCenterType = (int)ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS;
+ else if (anEllipse->secondFocus()->distance(theCenter) < theTolerance)
+ theCenterType = (int)ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS;
+
+ if (theCenterType != (int)ModelAPI_AttributeSelection::NOT_CENTER)
+ return *anIt;
+ }
+ }
+
+ // not found
+ return GeomShapePtr();
+ }
+
bool findSubshapeByPoint(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt>& thePoint,
const GeomAPI_Shape::ShapeType& theShapeType,
std::shared_ptr<ModelAPI_Result>& theResult,
- std::shared_ptr<GeomAPI_Shape>& theSubshape)
+ std::shared_ptr<GeomAPI_Shape>& theSubshape,
+ int& theCenterType)
{
static const double TOLERANCE = 1.e-7;
theResult = ResultPtr();
theSubshape = GeomShapePtr();
+ theCenterType = (int)ModelAPI_AttributeSelection::NOT_CENTER;
+
const std::list<ResultPtr>& aResults = theFeature->results();
for (std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
aResIt != aResults.end(); ++aResIt) {
theSubshape = GeomShapePtr();
break;
}
+
+ // another special case: the center of circle or the focus of ellipse is selected;
+ // return the corresponding edge and a status of the center
+ if (theShapeType == GeomAPI_Shape::VERTEX) {
+ theSubshape = findEdgeByCenter(aCurShape, thePoint, TOLERANCE, theCenterType);
+ if (theSubshape) {
+ theResult = *aResIt;
+ break;
+ }
+ }
}
// one more special case: a vertex selected is a sketch point;
/// \param[in] theShapeType type of the selected shape
/// \param[out] theResult applicable result
/// \param[out] theSubshape sub-shape of the found result
+ /// \param[out] theCenterType type of the point if it is a center of circle or a focus of ellipse
/// \return \c true if the result and its applicable sub-shape are found
MODELGEOMALGO_EXPORT bool findSubshapeByPoint(
const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt>& thePoint,
const GeomAPI_Shape::ShapeType& theShapeType,
std::shared_ptr<ModelAPI_Result>& theResult,
- std::shared_ptr<GeomAPI_Shape>& theSubshape);
+ std::shared_ptr<GeomAPI_Shape>& theSubshape,
+ int& theCenterType);
}
#endif
ResultPtr aResult;
GeomShapePtr aSubshape;
- if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theType, aResult, aSubshape))
+ int theCenterType;
+ if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theType,
+ aResult, aSubshape, theCenterType))
++aNbPossibleSelections;
}
return aNbPossibleSelections;
if(!theValue.empty()) {
const ModelHighAPI_Selection& aSelection = theValue.front();
- std::string aSelectionType = aSelection.shapeType();
- GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aSelectionType);
- if (aType != GeomAPI_Shape::SHAPE || aSelectionType == "SHAPE")
- theAttribute->setSelectionType(aSelectionType);
+ GeomAPI_Shape::ShapeType aSelectionType = getShapeType(aSelection);
+ theAttribute->setSelectionType(strByShapeType(aSelectionType));
}
for (auto it = theValue.begin(); it != theValue.end(); ++it)
return aShapeType;
}
+std::string strByShapeType(GeomAPI_Shape::ShapeType theShapeType)
+{
+ std::string aShapeTypeStr;
+ switch (theShapeType) {
+ case GeomAPI_Shape::COMPOUND:
+ aShapeTypeStr = "COMPOUND";
+ break;
+ case GeomAPI_Shape::COMPSOLID:
+ aShapeTypeStr = "COMPSOLID";
+ break;
+ case GeomAPI_Shape::SOLID:
+ aShapeTypeStr = "SOLID";
+ break;
+ case GeomAPI_Shape::SHELL:
+ aShapeTypeStr = "SHELL";
+ break;
+ case GeomAPI_Shape::FACE:
+ aShapeTypeStr = "FACE";
+ break;
+ case GeomAPI_Shape::WIRE:
+ aShapeTypeStr = "WIRE";
+ break;
+ case GeomAPI_Shape::EDGE:
+ aShapeTypeStr = "EDGE";
+ break;
+ case GeomAPI_Shape::VERTEX:
+ aShapeTypeStr = "VERTEX";
+ break;
+ default:
+ aShapeTypeStr = "SHAPE";
+ break;
+ }
+ return aShapeTypeStr;
+}
+
//==================================================================================================
GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection)
{
MODELHIGHAPI_EXPORT
GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr);
+MODELHIGHAPI_EXPORT
+std::string strByShapeType(GeomAPI_Shape::ShapeType theShapeType);
+
MODELHIGHAPI_EXPORT
GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection);