X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintAngle.cpp;h=108818439d2952726b478afaacf2aedcf69afc61;hb=b5893b0a30fac08134c24de4565cb513a43affa6;hp=27c35724d94065a1863cb6422c255ea1d8bc3a4f;hpb=049e63c33b9c0372a3007166032ead400c788c93;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 27c35724d..108818439 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -42,11 +42,15 @@ void SketchPlugin_ConstraintAngle::initAttributes() data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(SketchPlugin_ConstraintAngle::TYPE_ID(), ModelAPI_AttributeInteger::typeId()); - - data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID(), ModelAPI_AttributeBoolean::typeId()); - data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(SketchPlugin_ConstraintAngle::TYPE_ID(), + ModelAPI_AttributeInteger::typeId()); + + data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID(), + ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID(), + ModelAPI_AttributeBoolean::typeId()); } void SketchPlugin_ConstraintAngle::colorConfigInfo(std::string& theSection, std::string& theName, @@ -61,8 +65,10 @@ void SketchPlugin_ConstraintAngle::execute() { std::shared_ptr aData = data(); - std::shared_ptr anAttrA = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); - std::shared_ptr anAttrB = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); + std::shared_ptr anAttrA = + aData->refattr(SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr anAttrB = + aData->refattr(SketchPlugin_Constraint::ENTITY_B()); if (!anAttrA->isInitialized() || !anAttrB->isInitialized()) return; @@ -72,9 +78,10 @@ void SketchPlugin_ConstraintAngle::execute() if (!anAttrValue->isInitialized()) { double anAngle = calculateAngle(); anAttrValue->setValue(anAngle); - updateAngleValue(); + updateConstraintValueByAngleValue(); } - // the value should to be computed here, not in the getAISObject in order to change the model value + // 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< @@ -103,25 +110,32 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) if (!aLineA || !aLineB) return; - if (theID == SketchPlugin_Constraint::ENTITY_A() || + if (theID == SketchPlugin_Constraint::ENTITY_A() || theID == SketchPlugin_Constraint::ENTITY_B()) { - std::shared_ptr aValueAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); - if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value + AttributeDoublePtr aValueAttr = real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()); + AttributeDoublePtr aConstrValueAttr = real(SketchPlugin_Constraint::VALUE()); + // only if one of attributes is not initialized, try to compute the current value + if (!aValueAttr->isInitialized() || !aConstrValueAttr->isInitialized()) { + if (aValueAttr->isInitialized() && !aConstrValueAttr->isInitialized()) + // initialize base value of constraint + updateConstraintValueByAngleValue(); double anAngle = calculateAngle(); aValueAttr->setValue(anAngle); - updateAngleValue(); + updateConstraintValueByAngleValue(); } } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { // Recalculate flyout point in local coordinates // coordinates are calculated according to the center of shapes intersection std::shared_ptr aFlyoutAttr = - std::dynamic_pointer_cast(attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + std::dynamic_pointer_cast( + attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); std::shared_ptr aData = data(); std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); - FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); + FeaturePtr aLineA = + SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + FeaturePtr aLineB = + SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); // Intersection of lines std::shared_ptr anInter = intersect(aLineA, aLineB); @@ -138,11 +152,16 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); double anAngle = calculateAngle(); - aValueAttr->setValue(anAngle); - updateAngleValue(); + if (aValueAttr->text().empty()) + aValueAttr->setValue(anAngle); + else { + aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::VALUE())); + aValueAttr->setValue(anAngle); + } } else if (theID == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) { - updateAngleValue(); + updateConstraintValueByAngleValue(); } } @@ -172,17 +191,25 @@ double SketchPlugin_ConstraintAngle::calculateAngle() bool isReversed1 = boolean(ANGLE_REVERSED_FIRST_LINE_ID())->value(); std::shared_ptr aLine2(new GeomAPI_Lin2d(aStartB->pnt(), aEndB->pnt())); bool isReversed2 = boolean(ANGLE_REVERSED_SECOND_LINE_ID())->value(); - anAng = std::shared_ptr(new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2)); + anAng = std::shared_ptr( + new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2)); } double anAngle = anAng->angleDegree(); + std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(VALUE())); + std::shared_ptr anAngleValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(ANGLE_VALUE_ID())); + if (!aValueAttr->isInitialized()) + aValueAttr->setValue(anAngle); /// an angle value should be corrected by the current angle type - anAngle = getAngleForType(anAngle); + anAngle = getAngleForType(anAngleValueAttr->text().empty() ? + anAngle : anAngleValueAttr->value()); boolean(ANGLE_REVERSED_FIRST_LINE_ID())->setValue(anAng->isReversed(0)); boolean(ANGLE_REVERSED_SECOND_LINE_ID())->setValue(anAng->isReversed(1)); return anAngle; } -double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle) +double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle, bool isPreviousValueObtuse) { double anAngle = theAngle; @@ -194,8 +221,15 @@ double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle) case SketcherPrs_Tools::ANGLE_DIRECT: anAngle = theAngle; break; - case SketcherPrs_Tools::ANGLE_COMPLEMENTARY: - anAngle = fabs(180.0 - theAngle); + case SketcherPrs_Tools::ANGLE_COMPLEMENTARY: { + if (theAngle > 180 || isPreviousValueObtuse) + anAngle = theAngle - 180.0; + else + anAngle = 180.0 - theAngle; + + if (anAngle < 0.0) + anAngle += 360.0; + } break; case SketcherPrs_Tools::ANGLE_BACKWARD: anAngle = 360.0 - theAngle; @@ -206,16 +240,18 @@ double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle) return anAngle; } -void SketchPlugin_ConstraintAngle::updateAngleValue() +void SketchPlugin_ConstraintAngle::updateConstraintValueByAngleValue() { std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); double anAngle = aValueAttr->value(); /// an angle value should be corrected by the current angle type - anAngle = getAngleForType(anAngle); aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); + if (!aValueAttr->isInitialized()) + calculateAngle(); + anAngle = getAngleForType(anAngle, aValueAttr->value() > 180.0); aValueAttr->setValue(anAngle); } @@ -242,7 +278,8 @@ bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId) std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(attribute(theAttributeId)); - if (fabs(aFlyOutAttr->x()) >= tolerance || fabs(aFlyOutAttr->y()) >= tolerance) + if (aFlyOutAttr->isInitialized() && + (fabs(aFlyOutAttr->x()) >= tolerance || fabs(aFlyOutAttr->y()) >= tolerance)) return false; DataPtr aData = data();