X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintRadius.cpp;h=528d636ae9160d295624c811a77c473a70a1fe12;hb=2e9c8b6bbbc29447cd5c68e9ca9f341d022bdd1b;hp=135b6bbdb285d2b66a5671251c11866f814a2869;hpb=3874b57fe5aba25ff5aee2a07654fc23c1ee8eb0;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 135b6bbdb..528d636ae 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -60,7 +60,45 @@ void SketchPlugin_ConstraintRadius::execute() //if(!aValueAttr->isInitialized()) { // aValueAttr->setValue(aRadius); //} + + // the value should to be computed here, not in the getAISObject in order to change the model value + // inside the object transaction. This is important for creating a constraint by preselection. + // The display of the presentation in this case happens after the transaction commit + std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + if (!aFlyoutAttr->isInitialized()) + compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); + } +} + +bool SketchPlugin_ConstraintRadius::compute(const std::string& theAttributeId) +{ + if (theAttributeId != SketchPlugin_Constraint::FLYOUT_VALUE_PNT()) + return false; + + std::shared_ptr aCyrcFeature; + double aRadius = circleRadius(aCyrcFeature); + if (aRadius < 0) + return false; + + // Flyout point + std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(theAttributeId)); + // Prepare a circle + if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle + std::shared_ptr aCenterAttr = std::dynamic_pointer_cast( + aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); + double aShift = aRadius * 1.1; + std::shared_ptr aPnt = aCenterAttr->pnt(); + std::shared_ptr aFPnt = + std::shared_ptr(new GeomAPI_Pnt2d(aPnt->x() + aShift, aPnt->y() + aShift)); + aFlyoutAttr->setValue(aFPnt); + } else { // arc + std::shared_ptr aStartAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID())); + aFlyoutAttr->setValue(aStartAttr->pnt()); } + return true; } double SketchPlugin_ConstraintRadius::circleRadius(std::shared_ptr& theCirc) @@ -105,35 +143,19 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou // Flyout point std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt; - if (aFlyoutAttr->isInitialized()) { - aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); - } + if (!aFlyoutAttr->isInitialized()) + return thePrevious; // can not create a good presentation + std::shared_ptr aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y()); // Prepare a circle std::shared_ptr aCenterAttr; if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle aCenterAttr = std::dynamic_pointer_cast( aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID())); - if (!aFlyoutPnt) { - double aShift = aRadius * 1.1; - std::shared_ptr aPnt = aCenterAttr->pnt(); - std::shared_ptr aFPnt = - std::shared_ptr(new GeomAPI_Pnt2d(aPnt->x() + aShift, aPnt->y() + aShift)); - aFlyoutAttr->setValue(aFPnt); - aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y()); - } } else { // arc aCenterAttr = std::dynamic_pointer_cast( aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID())); - if (!aFlyoutPnt) { - std::shared_ptr aStartAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID())); - aFlyoutAttr->setValue(aStartAttr->pnt()); - aFlyoutPnt = sketch()->to3D(aStartAttr->pnt()->x(), aStartAttr->pnt()->y()); - } } - std::shared_ptr aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y()); std::shared_ptr aNDir = std::dynamic_pointer_cast( sketch()->data()->attribute(SketchPlugin_Sketch::NORM_ID())); @@ -151,7 +173,8 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou anAIS->createRadius(aCircle, aFlyoutPnt, aRadius); // Set color from preferences - std::vector aRGB = Config_PropManager::color("Visualization", "radius_color", RADIUS_COLOR); + std::vector aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color", + SKETCH_DIMENSION_COLOR); anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]); return anAIS; }