Salome HOME
Correct processing of the fixed arc in PlaneGCS (issue #1280)
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintDistance.cpp
index 11672f77a14bd074d4cf09d1a91ffdc1124a6bde..7eeee42670cd1c92051ff22e969147ea675eb403 100644 (file)
@@ -80,10 +80,11 @@ bool SketchPlugin_ConstraintDistance::compute(const std::string& theAttributeId)
     return false;
 
   DataPtr aData = data();
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
   std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
-      aData, SketchPlugin_Constraint::ENTITY_A());
+      aData, SketchPlugin_Constraint::ENTITY_A(), aPlane);
   std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
-      aData, SketchPlugin_Constraint::ENTITY_B());
+      aData, SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
   std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
@@ -133,6 +134,9 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
   if (!anAIS) {
     anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane());
   }
+  std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
+                                                    SKETCH_DIMENSION_COLOR);
+  anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
   return anAIS;
 }
 
@@ -145,10 +149,11 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY)
 
   // Recalculate a shift of flyout point in terms of local coordinates
   std::shared_ptr<GeomAPI_XY> aDir(new GeomAPI_XY(theDeltaX, theDeltaY));
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
   std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
-      data(), SketchPlugin_Constraint::ENTITY_A());
+      data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
   std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
-      data(), SketchPlugin_Constraint::ENTITY_B());
+      data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
   std::shared_ptr<GeomAPI_XY> aStartPnt;
   std::shared_ptr<GeomAPI_XY> aEndPnt;
@@ -185,15 +190,16 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY)
   myFlyoutUpdate = false;
 }
 
-double SketchPlugin_ConstraintDistance::calculateCurrentDistance() const
+double SketchPlugin_ConstraintDistance::calculateCurrentDistance()
 {
   double aDistance = -1.;
 
   std::shared_ptr<ModelAPI_Data> aData = data();
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
   std::shared_ptr<GeomDataAPI_Point2D> aPointA =
-    SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+    SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A(), aPlane);
   std::shared_ptr<GeomDataAPI_Point2D> aPointB =
-      SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+      SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
   if (aPointA.get() && aPointB.get()) {  // both points
     aDistance = aPointA->pnt()->distance(aPointB->pnt());
@@ -241,10 +247,11 @@ void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID)
         attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
     std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
 
+    std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
     std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_A());
+        data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
     std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_B());
+        data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
     std::shared_ptr<GeomAPI_XY> aStartPnt;
     std::shared_ptr<GeomAPI_XY> aEndPnt;
@@ -270,6 +277,9 @@ void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID)
     } else
       return;
 
+    if (aEndPnt->distance(aStartPnt) < tolerance)
+      return;
+
     std::shared_ptr<GeomAPI_Dir2d> aLineDir(new GeomAPI_Dir2d(aEndPnt->decreased(aStartPnt)));
     std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aStartPnt);
 
@@ -280,15 +290,3 @@ void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID)
   }
 }
 
-bool SketchPlugin_ConstraintDistance::customisePresentation(ResultPtr theResult,
-                                    AISObjectPtr thePrs,
-                                    std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
-{
-  bool isCustomized = false;
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
-                                                    SKETCH_DIMENSION_COLOR);
-  isCustomized = thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-
-  return isCustomized;
-}
-