Salome HOME
Meet the coding style (line length <= 100)
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintAngle.cpp
index 432b28eb43903dd9eee6eb5d804d8e5c1075b564..108818439d2952726b478afaacf2aedcf69afc61 100644 (file)
@@ -42,14 +42,14 @@ 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(), 
+  data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID(),
                        ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(SketchPlugin_ConstraintAngle::TYPE_ID(), 
+  data()->addAttribute(SketchPlugin_ConstraintAngle::TYPE_ID(),
                        ModelAPI_AttributeInteger::typeId());
 
-  data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID(), 
+  data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID(),
                        ModelAPI_AttributeBoolean::typeId());
-  data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID(), 
+  data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID(),
                        ModelAPI_AttributeBoolean::typeId());
 }
 
@@ -65,9 +65,9 @@ void SketchPlugin_ConstraintAngle::execute()
 {
   std::shared_ptr<ModelAPI_Data> aData = data();
 
-  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttrA = 
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttrA =
     aData->refattr(SketchPlugin_Constraint::ENTITY_A());
-  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttrB = 
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttrB =
     aData->refattr(SketchPlugin_Constraint::ENTITY_B());
   if (!anAttrA->isInitialized() || !anAttrB->isInitialized())
     return;
@@ -80,7 +80,7 @@ void SketchPlugin_ConstraintAngle::execute()
     anAttrValue->setValue(anAngle);
     updateConstraintValueByAngleValue();
   }
-  // the value should to be computed here, not in the 
+  // 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
@@ -110,13 +110,13 @@ 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()) {
     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()) 
+      if (aValueAttr->isInitialized() && !aConstrValueAttr->isInitialized())
         // initialize base value of constraint
         updateConstraintValueByAngleValue();
       double anAngle = calculateAngle();
@@ -132,9 +132,9 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
 
     std::shared_ptr<ModelAPI_Data> aData = data();
     std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
-    FeaturePtr aLineA = 
+    FeaturePtr aLineA =
       SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
-    FeaturePtr aLineB = 
+    FeaturePtr aLineB =
       SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
 
     // Intersection of lines
@@ -152,7 +152,13 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
     std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
       ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
     double anAngle = calculateAngle();
-    aValueAttr->setValue(anAngle);
+    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()) {
     updateConstraintValueByAngleValue();
@@ -190,11 +196,14 @@ double SketchPlugin_ConstraintAngle::calculateAngle()
   }
   double anAngle = anAng->angleDegree();
   std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
-      ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::VALUE()));
+      ModelAPI_AttributeDouble>(data()->attribute(VALUE()));
+  std::shared_ptr<ModelAPI_AttributeDouble> 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;
@@ -217,7 +226,7 @@ double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle, bool isPre
         anAngle = theAngle - 180.0;
       else
         anAngle = 180.0 - theAngle;
-      
+
       if (anAngle < 0.0)
         anAngle += 360.0;
     }