+//*************************************************************************************
+/// Find an attribute of the given object which corresponds to a vetrex
+/// defined by a shape
+/// \param theObject an object
+/// \param theShape a vertex
+/// \param thePlane a projection plane (sketcher plane)
+std::shared_ptr<GeomDataAPI_Point2D> findGeomPoint(ObjectPtr theObject,
+ const TopoDS_Shape& theShape,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aGeomPoint;
+
+ FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
+ if (anObjectFeature) {
+ if (theShape.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aShapeVertex = TopoDS::Vertex(theShape);
+ if (!aShapeVertex.IsNull()) {
+ gp_Pnt aShapePoint = BRep_Tool::Pnt(aShapeVertex);
+ std::shared_ptr<GeomAPI_Pnt> aShapeGeomPnt = std::shared_ptr<GeomAPI_Pnt>(
+ new GeomAPI_Pnt(aShapePoint.X(), aShapePoint.Y(), aShapePoint.Z()));
+
+ // find the given point in the feature attributes
+ std::list<AttributePtr> anObjectAttiributes =
+ anObjectFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::const_iterator anIt = anObjectAttiributes.begin(),
+ aLast = anObjectAttiributes.end();
+ for (; anIt != aLast && !aGeomPoint; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+
+ std::shared_ptr<GeomAPI_Pnt> anAttributePnt = thePlane->to3D(anAttributePoint->x(),
+ anAttributePoint->y());
+ if (anAttributePnt.get() &&
+ anAttributePnt->distance(aShapeGeomPnt) < Precision::Confusion()) {
+ aGeomPoint = anAttributePoint;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return aGeomPoint;
+}
+