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
// inside the object transaction. This is important for creating a constraint by preselection.
if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
double anAngle = calculateAngle();
aValueAttr->setValue(anAngle);
- updateAngleValue();
+ updateConstraintValueByAngleValue();
}
} else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
// Recalculate flyout point in local coordinates
ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
double anAngle = calculateAngle();
aValueAttr->setValue(anAngle);
- updateAngleValue();
}
else if (theID == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) {
- updateAngleValue();
+ updateConstraintValueByAngleValue();
}
}
anAng = std::shared_ptr<GeomAPI_Angle2d>(new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2));
}
double anAngle = anAng->angleDegree();
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::VALUE()));
+ if (!aValueAttr->isInitialized())
+ aValueAttr->setValue(anAngle);
/// an angle value should be corrected by the current angle type
anAngle = getAngleForType(anAngle);
boolean(ANGLE_REVERSED_FIRST_LINE_ID())->setValue(anAng->isReversed(0));
return anAngle;
}
-double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle)
+double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle, bool isPreviousValueObtuse)
{
double anAngle = 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;
return anAngle;
}
-void SketchPlugin_ConstraintAngle::updateAngleValue()
+void SketchPlugin_ConstraintAngle::updateConstraintValueByAngleValue()
{
std::shared_ptr<ModelAPI_AttributeDouble> 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()));
+ anAngle = getAngleForType(anAngle, aValueAttr->value() > 180.0);
aValueAttr->setValue(anAngle);
}