X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketcherPrs%2FSketcherPrs_Tools.cpp;h=912ea14467ee32d7c7b9fecd0c925422e72d2a6e;hb=bb4472b719a70fac9842ed33f16a4ce1f6877d79;hp=f8891b2253bdf2025369ea887e7c5e977ae99b4b;hpb=47bc42239a014ab54525f88916f2633b9d520f58;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index f8891b225..912ea1446 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -19,6 +19,12 @@ #include #include +#include +#include +#include + +#include +#include namespace SketcherPrs_Tools { @@ -66,9 +72,49 @@ std::shared_ptr getPoint(ModelAPI_Feature* theFeature, return std::shared_ptr(); } +//************************************************************************************* +std::shared_ptr findGeomPoint(ObjectPtr theObject, + const TopoDS_Shape& theShape, + const std::shared_ptr& thePlane) +{ + std::shared_ptr 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 aShapeGeomPnt = std::shared_ptr( + new GeomAPI_Pnt(aShapePoint.X(), aShapePoint.Y(), aShapePoint.Z())); + + // find the given point in the feature attributes + std::list anObjectAttiributes = + anObjectFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list::const_iterator anIt = anObjectAttiributes.begin(), + aLast = anObjectAttiributes.end(); + for (; anIt != aLast && !aGeomPoint; anIt++) { + std::shared_ptr anAttributePoint = + std::dynamic_pointer_cast(*anIt); + + std::shared_ptr anAttributePnt = thePlane->to3D(anAttributePoint->x(), + anAttributePoint->y()); + if (anAttributePnt.get() && + anAttributePnt->distance(aShapeGeomPnt) < Precision::Confusion()) { + aGeomPoint = anAttributePoint; + break; + } + } + } + } + } + return aGeomPoint; +} + //************************************************************************************* std::shared_ptr getFeaturePoint(DataPtr theData, - const std::string& theAttribute) + const std::string& theAttribute, + const std::shared_ptr& thePlane) { std::shared_ptr aPointAttr; @@ -78,15 +124,28 @@ std::shared_ptr getFeaturePoint(DataPtr theData, FeaturePtr aFeature; std::shared_ptr anAttr = std::dynamic_pointer_cast< ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute)); - if (anAttr) - aFeature = ModelAPI_Feature::feature(anAttr->object()); - - if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) - aPointAttr = std::dynamic_pointer_cast( - aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); - - else if (anAttr->attr()) { - aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + if (anAttr) { + if (anAttr->isObject()) { + ObjectPtr anObject = anAttr->object(); + aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) { + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); + } + else { + ResultPtr aRes = std::dynamic_pointer_cast(anObject); + if (aRes.get()) { + GeomShapePtr aShape = aRes->shape(); + if (aShape.get()) { + TopoDS_Shape aTDSShape = aShape->impl(); + aPointAttr = findGeomPoint(anObject, aTDSShape, thePlane); + } + } + } + } + else if (anAttr->attr()) { + aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + } } return aPointAttr; } @@ -125,7 +184,7 @@ std::shared_ptr getProjectionPoint(const FeaturePtr theLine, } -static double MyArrowSize = 30.; +static double MyArrowSize = 24.; double getArrowSize() { return MyArrowSize; @@ -136,6 +195,22 @@ void setArrowSize(double theSize) MyArrowSize = theSize; } +static double MyTextHeight = 16; +double getTextHeight() +{ + return MyTextHeight; +} + +void setTextHeight(double theHeight) +{ + MyTextHeight = theHeight; +} + +double getDefaultTextHeight() +{ + return 16; +} + double getFlyoutDistance(const ModelAPI_Feature* theConstraint) { std::shared_ptr aFlyoutPoint =