Salome HOME
Merge remote-tracking branch 'origin/EDF_2019'
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintAngle.cpp
index 3d2440b154b49fdec541e78000417988201c493d..137acd0cdebab5ef7d9d51b737bba25ce6fd5d6f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "SketchPlugin_ConstraintAngle.h"
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Tools.h>
+#include <SketcherPrs_Tools.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
 
 #include <GeomDataAPI_Point2D.h>
 
@@ -65,6 +68,10 @@ void SketchPlugin_ConstraintAngle::initAttributes()
                        ModelAPI_AttributeBoolean::typeId());
   data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID(),
                        ModelAPI_AttributeBoolean::typeId());
+
+  data()->addAttribute(SketchPlugin_ConstraintAngle::LOCATION_TYPE_ID(),
+                       ModelAPI_AttributeInteger::typeId());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATION_TYPE_ID());
 }
 
 void SketchPlugin_ConstraintAngle::colorConfigInfo(std::string& theSection, std::string& theName,
@@ -109,8 +116,10 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious
   if (!sketch())
     return thePrevious;
 
-  AISObjectPtr anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane(),
+  AISObjectPtr anAIS = SketcherPrs_Factory::angleConstraint(this, sketch(),
                                                             thePrevious);
+  if (anAIS.get() && !thePrevious.get())
+    SketchPlugin_Tools::setDimensionColor(anAIS);
   return anAIS;
 }
 
@@ -269,20 +278,6 @@ void SketchPlugin_ConstraintAngle::updateConstraintValueByAngleValue()
   aValueAttr->setValue(anAngle);
 }
 
-void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY)
-{
-  std::shared_ptr<ModelAPI_Data> aData = data();
-  if (!aData->isValid())
-    return;
-
-  myFlyoutUpdate = true;
-  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
-      GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-  aFlyoutAttr->setValue(aFlyoutAttr->x() + theDeltaX, aFlyoutAttr->y() + theDeltaY);
-  myFlyoutUpdate = false;
-}
-
-
 bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId)
 {
   if (theAttributeId != SketchPlugin_Constraint::FLYOUT_VALUE_PNT())
@@ -315,9 +310,19 @@ bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId)
   if (aStartA->distance(aEndA) < tolerance)
     return false;
 
+  std::shared_ptr<GeomDataAPI_Point2D> aPointB1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aLineB->attribute(SketchPlugin_Line::START_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aPointB2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aLineB->attribute(SketchPlugin_Line::END_ID()));
+
+  std::shared_ptr<GeomAPI_Pnt2d> aStartB = aPointB1->pnt();
+  std::shared_ptr<GeomAPI_Pnt2d> aEndB = aPointB2->pnt();
+  if (aStartB->distance(aEndB) < tolerance)
+    return false;
+
   myFlyoutUpdate = true;
-  double aX = (aStartA->x() + aEndA->x()) / 2.;
-  double aY = (aStartA->y() + aEndA->y()) / 2.;
+  double aX = (aStartA->x() + aEndA->x() + aStartB->x() + aEndB->x()) / 4.;
+  double aY = (aStartA->y() + aEndA->y() + aStartB->y() + aEndB->y()) / 4.;
 
   aFlyOutAttr->setValue(aX, aY);
   myFlyoutUpdate = false;