Salome HOME
Issue #1366: "Partition" feature now modified to "Generalized Partition"
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintAngle.cpp
index 27c35724d94065a1863cb6422c255ea1d8bc3a4f..8fb29c48c33e5866c795c9acc2c01e5798af491e 100644 (file)
@@ -72,7 +72,7 @@ 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
   // inside the object transaction. This is important for creating a constraint by preselection.
@@ -110,7 +110,7 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
     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
@@ -139,10 +139,9 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
       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();
   }
 }
 
@@ -175,6 +174,10 @@ double SketchPlugin_ConstraintAngle::calculateAngle()
     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));
@@ -182,7 +185,7 @@ double SketchPlugin_ConstraintAngle::calculateAngle()
   return anAngle;
 }
 
-double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle)
+double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle, bool isPreviousValueObtuse)
 {
   double anAngle = theAngle;
 
@@ -194,8 +197,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 +216,16 @@ double SketchPlugin_ConstraintAngle::getAngleForType(double 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);
 }