From: nds Date: Mon, 10 Nov 2014 13:42:57 +0000 (+0300) Subject: refs #196 - visualize a constraint distance presentation in case of invalid value. X-Git-Tag: V_0.5~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e22437d04d943269e7c3794283eea763354e4d7e;p=modules%2Fshaper.git refs #196 - visualize a constraint distance presentation in case of invalid value. --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 3ad9b6842..23c8b546c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -38,29 +38,8 @@ void SketchPlugin_ConstraintDistance::execute() if(anAttrValue->isInitialized()) return; - boost::shared_ptr aPointA = - getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); - boost::shared_ptr 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 aLine = - getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); - if (aLine) { - aDistance = aLine->distanceToPoint(aPointB->pnt()); - } - } else if (aPointA && !aPointB) { // Point and line - boost::shared_ptr 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 aData = data(); + boost::shared_ptr aPointA = + getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A()); + boost::shared_ptr 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 aLine = + getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + if (aLine) { + aDistance = aLine->distanceToPoint(aPointB->pnt()); + } + } else if (aPointA && !aPointB) { // Point and line + boost::shared_ptr aLine = + getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); + if (aLine) { + aDistance = aLine->distanceToPoint(aPointA->pnt()); + } + } + } + return aDistance; +} + + //************************************************************************************* boost::shared_ptr getFeaturePoint(DataPtr theData, const std::string& theAttribute) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 4f4fedc62..b5981d017 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -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(); };