X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintRadius.cpp;h=391dbd451e43d63421abdf8d4abd1e3bee1eb2c6;hb=47d69c6e766821c1296c5147a6248ae49020c7dd;hp=a57df918bd87de76a418d15b5c78b1b9613cfca2;hpb=a0366082107c7651476fa984d9f238556ba34d05;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index a57df918b..391dbd451 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -13,6 +13,9 @@ #include #include +#include +#include +#include #include #include @@ -27,13 +30,39 @@ void SketchPlugin_ConstraintRadius::initAttributes() { data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT, GeomDataAPI_Point2D::type()); + data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintRadius::execute() { + if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() && + !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) { + + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + FeaturePtr aFeature = aRef->feature(); + if (aFeature) { + double aRadius = 0; + boost::shared_ptr aData = aFeature->data(); + if (aFeature->getKind() == SKETCH_CIRCLE_KIND) { + AttributeDoublePtr anAttribute = boost::dynamic_pointer_cast + (aData->attribute(CIRCLE_ATTR_RADIUS)); + if (anAttribute) + aRadius = anAttribute->value(); + } + else if (aFeature->getKind() == SKETCH_ARC_KIND) { + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_CENTER)); + boost::shared_ptr aStartAttr = + boost::dynamic_pointer_cast(aData->attribute(ARC_ATTR_START)); + if (aCenterAttr && aStartAttr) + aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + } + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); + aValueAttr->setValue(aRadius); + } + } } Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( @@ -59,7 +88,9 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( // an anchor point boost::shared_ptr aAnchorAttr = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT)); + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + if (!aAnchorAttr->isInitialized()) + return anAIS; boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); boost::shared_ptr anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y()); @@ -88,6 +119,21 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( boost::shared_ptr aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius)); + anAnchor = aCircle->project(anAnchor); + // TODO: a bug in AIS_RadiusDimension: + // The anchor point can't be myCirc.Location() - an exception is raised. + // But we need exactly this case... + // We want to show a radius dimension starting from the circle centre and + // ending at the user-defined point. + // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all. + boost::shared_ptr anAnchorXYZ = anAnchor->xyz(); + anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz()); + boost::shared_ptr aDeltaDir(new GeomAPI_Dir(anAnchorXYZ)); + const double aDelta = 1e-3; + anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x()); + anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y()); + anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z()); + if (anAIS.IsNull()) { Handle(AIS_RadiusDimension) aDimAIS = @@ -119,3 +165,40 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( return anAIS; } +void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + FeaturePtr aFeature = aRef->feature(); + if (!aFeature) + return; + std::string aCenterAttrName; + if (aFeature->getKind() == SKETCH_CIRCLE_KIND) + aCenterAttrName = CIRCLE_ATTR_CENTER; + else if (aFeature->getKind() == SKETCH_ARC_KIND) + aCenterAttrName = ARC_ATTR_CENTER; + boost::shared_ptr aCenterAttr = + boost::dynamic_pointer_cast(aFeature->data()->attribute(aCenterAttrName)); + boost::shared_ptr aCenter = aCenterAttr->pnt(); + + // The specified delta applied on the circle curve, + // so it will be scaled due to distance between flyout and center points + boost::shared_ptr aFlyoutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFlyout = aFlyoutAttr->pnt(); + + boost::shared_ptr aRadius = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + double aScale = aFlyout->distance(aCenter) / aRadius->value(); + + boost::shared_ptr aCircle(new GeomAPI_Circ2d(aCenter, aFlyout)); + aFlyout->setX(aFlyout->x() + aScale * theDeltaX); + aFlyout->setY(aFlyout->y() + aScale * theDeltaY); + aFlyout = aCircle->project(aFlyout); + + aFlyoutAttr->setValue(aFlyout->x(), aFlyout->y()); +}