]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #196 - visualize a constraint distance presentation in case of invalid value.
authornds <natalia.donis@opencascade.com>
Mon, 10 Nov 2014 13:42:57 +0000 (16:42 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 10 Nov 2014 13:42:57 +0000 (16:42 +0300)
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.h

index 3ad9b6842708241f09163cca00947d61539e21f6..23c8b546c05bfd6df2a3ce56f7fab5b315794a0d 100644 (file)
@@ -38,29 +38,8 @@ void SketchPlugin_ConstraintDistance::execute()
 
   if(anAttrValue->isInitialized())
     return;
-  boost::shared_ptr<GeomDataAPI_Point2D> aPointA =
-      getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
-  boost::shared_ptr<GeomDataAPI_Point2D> aPointB =
-      getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
 
-  double aDistance = -1.;
-  if (aPointA && aPointB) {  // both points
-    aDistance = aPointA->pnt()->distance(aPointB->pnt());
-  } else {
-    if (!aPointA && aPointB) {  //Line and point
-      boost::shared_ptr<SketchPlugin_Line> aLine =
-          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
-      if (aLine) {
-        aDistance = aLine->distanceToPoint(aPointB->pnt());
-      }
-    } else if (aPointA && !aPointB) {  // Point and line
-      boost::shared_ptr<SketchPlugin_Line> aLine =
-          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
-      if (aLine) {
-        aDistance = aLine->distanceToPoint(aPointA->pnt());
-      }
-    }
-  }
+  double aDistance = calculateCurrentDistance();
   if(aDistance >= 0) {
     anAttrValue->setValue(aDistance);
   }
@@ -125,8 +104,9 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
   double aValue = aValueAttr->value();
   // Issue #196: checking the positivity of the distance constraint
   // there is a validator for a distance constraint, that the value should be positive
+  // in case if an invalid value is set, the current distance value is shown
   if (aValue <= 0)
-    return AISObjectPtr();
+    aValue = calculateCurrentDistance();
 
   AISObjectPtr anAIS = thePrevious;
   if (!anAIS)
@@ -152,6 +132,37 @@ void SketchPlugin_ConstraintDistance::move(double theDeltaX, double theDeltaY)
   aPoint->move(theDeltaX, theDeltaY);
 }
 
+double SketchPlugin_ConstraintDistance::calculateCurrentDistance()
+{
+  double aDistance = -1.;
+
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPointA =
+    getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+  boost::shared_ptr<GeomDataAPI_Point2D> aPointB =
+      getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+
+  if (aPointA && aPointB) {  // both points
+    aDistance = aPointA->pnt()->distance(aPointB->pnt());
+  } else {
+    if (!aPointA && aPointB) {  //Line and point
+      boost::shared_ptr<SketchPlugin_Line> aLine =
+          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+      if (aLine) {
+        aDistance = aLine->distanceToPoint(aPointB->pnt());
+      }
+    } else if (aPointA && !aPointB) {  // Point and line
+      boost::shared_ptr<SketchPlugin_Line> aLine =
+          getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+      if (aLine) {
+        aDistance = aLine->distanceToPoint(aPointA->pnt());
+      }
+    }
+  }
+  return aDistance;
+}
+
+
 //*************************************************************************************
 boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
                                                        const std::string& theAttribute)
index 4f4fedc627765bc8c1c770cf9ba519e72ae6f84f..b5981d017f24d418bcb0f0e3811f8cb07906a72e 100644 (file)
@@ -56,6 +56,9 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Returns the current distance between the feature attributes
+  double calculateCurrentDistance() const;
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintDistance();
 };