X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSketcherPrs%2FSketcherPrs_Tools.cpp;h=c2ccd87488ab57d5f11c986059ef128cd30b3b0c;hb=a976799ce75768f092d446cc70237f2e5575ba7c;hp=2c575e1a3261fbd5a26c1b8415b896e70ea40731;hpb=a731f82dccbfdb67cbf8e8d617222a4d3e32018a;p=modules%2Fshaper.git diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 2c575e1a3..c2ccd8748 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -9,20 +9,29 @@ #include #include #include +#include +#include + #include #include +#include #include +#include + +#include +#include +#include +#include +#include namespace SketcherPrs_Tools { -ObjectPtr getResult(SketchPlugin_Constraint* theFeature, const std::string& theAttrName) +ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName) { std::shared_ptr aData = theFeature->data(); - std::shared_ptr anAttr = - std::dynamic_pointer_cast(aData->attribute(theAttrName)); - + std::shared_ptr anAttr = aData->refattr(theAttrName); return anAttr->object(); } @@ -37,8 +46,8 @@ std::shared_ptr getShape(ObjectPtr theObject) } -std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, - const std::string& theAttribute) +std::shared_ptr getPoint(ModelAPI_Feature* theFeature, + const std::string& theAttribute) { std::shared_ptr aPointAttr; @@ -55,10 +64,6 @@ std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, aPointAttr = std::dynamic_pointer_cast( aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); - else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID()) - aPointAttr = std::dynamic_pointer_cast( - aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); - else if (anAttr->attr()) { aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); } @@ -67,5 +72,192 @@ std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, return std::shared_ptr(); } +//************************************************************************************* +/// 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 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::shared_ptr& thePlane) +{ + std::shared_ptr aPointAttr; + + if (!theData) + return aPointAttr; + + FeaturePtr aFeature; + std::shared_ptr anAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute)); + if (anAttr) { + if (anAttr->isObject()) { + ObjectPtr anObject = anAttr->object(); + aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) { + // Attribute refers to a point + aPointAttr = std::dynamic_pointer_cast( + aFeature->data()->attribute(SketchPlugin_Point::COORD_ID())); + } + else { + // if the attribute refers on another object + 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()) { + // If attribute is a point + aPointAttr = std::dynamic_pointer_cast(anAttr->attr()); + } + } + return aPointAttr; +} + +//************************************************************************************* +FeaturePtr getFeatureLine(DataPtr theData, + const std::string& theAttribute) +{ + FeaturePtr aLine; + if (!theData) + return aLine; + + std::shared_ptr anAttr = + std::dynamic_pointer_cast(theData->attribute(theAttribute)); + if (anAttr) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object()); + if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) { + return aFeature; + } + } + return aLine; +} + +//************************************************************************************* +std::shared_ptr getProjectionPoint(const FeaturePtr theLine, + const std::shared_ptr& thePoint) +{ + DataPtr aData = theLine->data(); + std::shared_ptr aPoint1 = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aPoint2 = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Line::END_ID())); + + GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y()); + return aLin2d.project(thePoint); +} + + +static double MyArrowSize = 24.; +double getArrowSize() +{ + return MyArrowSize; +} + +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 = + std::dynamic_pointer_cast( + const_cast(theConstraint)->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + + return aFlyoutPoint->y(); +} + +std::shared_ptr getAnchorPoint(const ModelAPI_Feature* theConstraint, + const std::shared_ptr& thePlane) +{ + ModelAPI_Feature* aConstraint = const_cast(theConstraint); + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast( + aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); + if (!aRefAttr || !aRefAttr->isObject() || !aRefAttr->object()) + return std::shared_ptr(); + + FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); + std::shared_ptr aCenter; + if (aFeature->getKind() == SketchPlugin_Arc::ID()) { // arc + aCenter = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt(); + } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) { // circle + aCenter = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->pnt(); + } else + return std::shared_ptr(); + + std::shared_ptr anOrigin(new GeomAPI_Pnt2d(0.0, 0.0)); + std::shared_ptr aFlyoutPnt = std::dynamic_pointer_cast( + aConstraint->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()))->pnt(); + double aRadius = std::dynamic_pointer_cast( + aConstraint->attribute(SketchPlugin_Constraint::VALUE()))->value(); + double aLen = aFlyoutPnt->distance(anOrigin); + aRadius *= 1.001; // a gap to make point much closer to the circle, but not lying on it + aFlyoutPnt->setX(aCenter->x() + aFlyoutPnt->x() * aRadius / aLen); + aFlyoutPnt->setY(aCenter->y() + aFlyoutPnt->y() * aRadius / aLen); + return thePlane->to3D(aFlyoutPnt->x(), aFlyoutPnt->y()); +} -}; \ No newline at end of file +};