From e22437d04d943269e7c3794283eea763354e4d7e Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 10 Nov 2014 16:42:57 +0300 Subject: [PATCH] refs #196 - visualize a constraint distance presentation in case of invalid value. --- .../SketchPlugin_ConstraintDistance.cpp | 57 +++++++++++-------- .../SketchPlugin_ConstraintDistance.h | 3 + 2 files changed, 37 insertions(+), 23 deletions(-) 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(); }; -- 2.39.2