From: azv Date: Tue, 24 Oct 2017 14:07:54 +0000 (+0300) Subject: Horizontal and vertical distances now show positive value (but store signed value... X-Git-Tag: V_2.9.1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=803c5fda09029cf64d9a21daac18d08cd19e6585;p=modules%2Fshaper.git Horizontal and vertical distances now show positive value (but store signed value internally) (issue #2203) --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 4b4c0b15c..e7ec8b7c7 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -31,6 +31,7 @@ SET(PROJECT_HEADERS SketchPlugin_ConstraintCoincidence.h SketchPlugin_ConstraintCollinear.h SketchPlugin_ConstraintDistance.h + SketchPlugin_ConstraintDistanceAlongDir.h SketchPlugin_ConstraintDistanceHorizontal.h SketchPlugin_ConstraintDistanceVertical.h SketchPlugin_ConstraintEqual.h @@ -76,6 +77,7 @@ SET(PROJECT_SOURCES SketchPlugin_ConstraintCoincidence.cpp SketchPlugin_ConstraintCollinear.cpp SketchPlugin_ConstraintDistance.cpp + SketchPlugin_ConstraintDistanceAlongDir.cpp SketchPlugin_ConstraintDistanceHorizontal.cpp SketchPlugin_ConstraintDistanceVertical.cpp SketchPlugin_ConstraintEqual.cpp diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp new file mode 100644 index 000000000..779d08205 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp @@ -0,0 +1,144 @@ +// Copyright (C) 2017 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +// File: SketchPlugin_ConstraintDistanceAlongDir.cpp +// Created: 24 October 2017 +// Author: Artem ZHIDKOV + +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +const double tolerance = 1e-7; + + +SketchPlugin_ConstraintDistanceAlongDir::SketchPlugin_ConstraintDistanceAlongDir() + : SketchPlugin_ConstraintDistance(), + myValue(-1.e100), + myValueUpdate(false) +{ +} + +//************************************************************************************* +void SketchPlugin_ConstraintDistanceAlongDir::initAttributes() +{ + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); + + data()->addAttribute(LOCATION_TYPE_ID(), ModelAPI_AttributeInteger::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATION_TYPE_ID()); + + data()->addAttribute(DISTANCE_VALUE_ID(), ModelAPI_AttributeDouble::typeId()); + + data()->addAttribute(NEGATIVE_TYPE_ID(), ModelAPI_AttributeBoolean::typeId()); + boolean(NEGATIVE_TYPE_ID())->setValue(false); +} + +//************************************************************************************* +void SketchPlugin_ConstraintDistanceAlongDir::execute() +{ + AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE()); + if (anAttrValue->isInitialized() || !areAttributesInitialized()) + return; + + double aDistance = calculateCurrentDistance(); + anAttrValue->setValue(aDistance); +} + +//************************************************************************************* +AISObjectPtr SketchPlugin_ConstraintDistanceAlongDir::getAISObject(AISObjectPtr thePrevious) +{ + if (!sketch()) + return thePrevious; + + AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, + sketch()->coordinatePlane(), + thePrevious); + return anAIS; +} + +void SketchPlugin_ConstraintDistanceAlongDir::attributeChanged(const std::string& theID) +{ + if (theID == SketchPlugin_Constraint::ENTITY_A() || + theID == SketchPlugin_Constraint::ENTITY_B()) + { + AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE()); + if (!aValueAttr->isInitialized() && areAttributesInitialized()) { + // only if it is not initialized, try to compute the current value + double aDistance = calculateCurrentDistance(); + aValueAttr->setValue(aDistance); + } + } else if (theID == SketchPlugin_Constraint::VALUE() && !myValueUpdate) { + myValueUpdate = true; + // value of the distance shown to the user should be always positive + AttributeDoublePtr aDistanceValueAttr = real(DISTANCE_VALUE_ID()); + double aConstraintValue = real(SketchPlugin_Constraint::VALUE())->value(); + aDistanceValueAttr->setValue(fabs(aConstraintValue)); + myValueUpdate = false; + } else if (theID == DISTANCE_VALUE_ID() && !myValueUpdate){ + myValueUpdate = true; + // update value of the distance according to the value set by user + double aDistanceValue = real(DISTANCE_VALUE_ID())->value(); + AttributeDoublePtr aConstraintValueAttr = real(SketchPlugin_Constraint::VALUE()); + if (aConstraintValueAttr->value() < 0.0) + aDistanceValue = -aDistanceValue; + aConstraintValueAttr->setValue(aDistanceValue); + myValueUpdate = false; + } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { + // Recalculate flyout point in local coordinates of the distance constraint: + // the X coordinate is a length of projection of the flyout point on the + // line binding two distanced points + // or a line of projection of the distanced point onto the distanced segment + // the Y coordinate is a distance from the flyout point to the line + std::shared_ptr aFlyoutAttr = + std::dynamic_pointer_cast( + attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + std::shared_ptr aFlyoutPnt = aFlyoutAttr->pnt(); + + std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); + std::shared_ptr aPointA = SketcherPrs_Tools::getFeaturePoint( + data(), SketchPlugin_Constraint::ENTITY_A(), aPlane); + std::shared_ptr aPointB = SketcherPrs_Tools::getFeaturePoint( + data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); + + std::shared_ptr aStartPnt = aPointA->pnt()->xy(); + std::shared_ptr aEndPnt = aPointB->pnt()->xy(); + + if (aEndPnt->distance(aStartPnt) < tolerance) + return; + + std::shared_ptr aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPnt); + myFlyoutUpdate = true; + updateFlyoutPoint(); + myFlyoutUpdate = false; + } +} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.h b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.h new file mode 100644 index 000000000..bd38dad7b --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.h @@ -0,0 +1,91 @@ +// Copyright (C) 2017 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +// File: SketchPlugin_ConstraintDistanceAlongDir.h +// Created: 24 October 2017 +// Author: Artem ZHIDKOV + +#ifndef SketchPlugin_ConstraintDistanceAlongDir_H_ +#define SketchPlugin_ConstraintDistanceAlongDir_H_ + +#include +#include + +/** \class SketchPlugin_ConstraintDistanceAlongDir + * \ingroup Plugins + * \brief Feature for creation of a new constraint which defines a distance along direction. + * The base class for horizontal and vertical constraints. + * + * This constraint has three attributes: + * SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() + */ +class SketchPlugin_ConstraintDistanceAlongDir : public SketchPlugin_ConstraintDistance +{ +public: + /// attribute name of dimension location type + inline static const std::string& LOCATION_TYPE_ID() + { + static const std::string MY_LOCATION_TYPE_ID("LocationType"); + return MY_LOCATION_TYPE_ID; + } + + /// attribute name of the distance value shown to the user + inline static const std::string& DISTANCE_VALUE_ID() + { + static const std::string& MY_DISTANCE_VALUE("DistanceValue"); + return MY_DISTANCE_VALUE; + } + + /// attribute name of the sign of distance + inline static const std::string& NEGATIVE_TYPE_ID() + { + static const std::string MY_NEGATIVE_VALUE("NegativeValue"); + return MY_NEGATIVE_VALUE; + } + + /// \brief Creates a new part document if needed + SKETCHPLUGIN_EXPORT virtual void execute(); + + /// \brief Request for initialization of data model of the feature: adding all attributes + SKETCHPLUGIN_EXPORT virtual void initAttributes(); + + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + + /// \brief Use plugin manager for features creation + SketchPlugin_ConstraintDistanceAlongDir(); + +protected: + /// Returns the current distance between the feature attributes + virtual double calculateCurrentDistance() = 0; + + /// Update flyout point + virtual void updateFlyoutPoint() = 0; + +protected: + double myValue; + bool myValueUpdate; +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp index 355292413..ae3a5e0a5 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp @@ -25,59 +25,14 @@ #include #include -#include -#include #include #include -#include -#include -#include -#include - -const double tolerance = 1e-7; - SketchPlugin_ConstraintDistanceHorizontal::SketchPlugin_ConstraintDistanceHorizontal() - : SketchPlugin_ConstraintDistance() -{ -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceHorizontal::initAttributes() -{ - data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); - - data()->addAttribute(SketchPlugin_ConstraintDistanceHorizontal::LOCATION_TYPE_ID(), - ModelAPI_AttributeInteger::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATION_TYPE_ID()); -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceHorizontal::execute() -{ - AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE()); - if (anAttrValue->isInitialized() || !areAttributesInitialized()) - return; - - double aDistance = calculateCurrentDistance(); - anAttrValue->setValue(aDistance); -} - -//************************************************************************************* -AISObjectPtr SketchPlugin_ConstraintDistanceHorizontal::getAISObject(AISObjectPtr thePrevious) + : SketchPlugin_ConstraintDistanceAlongDir() { - if (!sketch()) - return thePrevious; - - AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, - sketch()->coordinatePlane(), - thePrevious); - return anAIS; } double SketchPlugin_ConstraintDistanceHorizontal::calculateCurrentDistance() @@ -92,44 +47,19 @@ double SketchPlugin_ConstraintDistanceHorizontal::calculateCurrentDistance() return aPointB->x() - aPointA->x(); } -void SketchPlugin_ConstraintDistanceHorizontal::attributeChanged(const std::string& theID) +void SketchPlugin_ConstraintDistanceHorizontal::updateFlyoutPoint() { - if (theID == SketchPlugin_Constraint::ENTITY_A() || - theID == SketchPlugin_Constraint::ENTITY_B()) - { - AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE()); - if (!aValueAttr->isInitialized() && areAttributesInitialized()) { - // only if it is not initialized, try to compute the current value - double aDistance = calculateCurrentDistance(); - aValueAttr->setValue(aDistance); - } - } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { - // Recalculate flyout point in local coordinates of the distance constraint: - // the X coordinate is a length of projection of the flyout point on the - // line binding two distanced points - // or a line of projection of the distanced point onto the distanced segment - // the Y coordinate is a distance from the flyout point to the line - std::shared_ptr aFlyoutAttr = - std::dynamic_pointer_cast( - attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt = aFlyoutAttr->pnt(); + std::shared_ptr aFlyoutAttr = + std::dynamic_pointer_cast( + attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + std::shared_ptr aFlyoutPnt = aFlyoutAttr->pnt(); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); - - std::shared_ptr aStartPnt = aPointA->pnt()->xy(); - std::shared_ptr aEndPnt = aPointB->pnt()->xy(); - if (aEndPnt->distance(aStartPnt) < tolerance) - return; + std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); + std::shared_ptr aEndPoint = SketcherPrs_Tools::getFeaturePoint( + data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); - myFlyoutUpdate = true; - std::shared_ptr aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPnt); - double X = aFlyoutDir->x(); // Dot on OX axis - double Y = aFlyoutDir->y(); // Cross to OX axis - aFlyoutAttr->setValue(X, Y); - myFlyoutUpdate = false; - } + std::shared_ptr aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPoint->pnt()->xy()); + double X = aFlyoutDir->x(); // Dot on OX axis + double Y = aFlyoutDir->y(); // Cross to OX axis + aFlyoutAttr->setValue(X, Y); } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h index c5ddc47fe..689cf57d3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h @@ -26,7 +26,7 @@ #define SketchPlugin_ConstraintDistanceHorizontal_H_ #include -#include +#include /** \class SketchPlugin_ConstraintDistanceHorizontal * \ingroup Plugins @@ -35,7 +35,7 @@ * This constraint has three attributes: * SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ -class SketchPlugin_ConstraintDistanceHorizontal : public SketchPlugin_ConstraintDistance +class SketchPlugin_ConstraintDistanceHorizontal : public SketchPlugin_ConstraintDistanceAlongDir { public: /// Distance constraint kind @@ -52,33 +52,15 @@ public: return MY_KIND; } - /// attribute name of dimension location type - inline static const std::string& LOCATION_TYPE_ID() - { - static const std::string MY_LOCATION_TYPE_ID("LocationType"); - return MY_LOCATION_TYPE_ID; - } - - - /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(); - - /// \brief Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - - /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); - - /// Called on change of any argument-attribute of this object - /// \param theID identifier of changed attribute - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// \brief Use plugin manager for features creation SketchPlugin_ConstraintDistanceHorizontal(); protected: /// Returns the current distance between the feature attributes virtual double calculateCurrentDistance(); + + /// Update flyout point + virtual void updateFlyoutPoint(); }; #endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp index 8823c3aa0..d0dae6161 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp @@ -25,61 +25,16 @@ #include #include -#include -#include #include #include -#include -#include -#include -#include - -const double tolerance = 1e-7; - SketchPlugin_ConstraintDistanceVertical::SketchPlugin_ConstraintDistanceVertical() - : SketchPlugin_ConstraintDistance() + : SketchPlugin_ConstraintDistanceAlongDir() { } -//************************************************************************************* -void SketchPlugin_ConstraintDistanceVertical::initAttributes() -{ - data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); - - data()->addAttribute(SketchPlugin_ConstraintDistanceVertical::LOCATION_TYPE_ID(), - ModelAPI_AttributeInteger::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATION_TYPE_ID()); -} - -//************************************************************************************* -void SketchPlugin_ConstraintDistanceVertical::execute() -{ - AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE()); - if (anAttrValue->isInitialized() || !areAttributesInitialized()) - return; - - double aDistance = calculateCurrentDistance(); - anAttrValue->setValue(aDistance); -} - -//************************************************************************************* -AISObjectPtr SketchPlugin_ConstraintDistanceVertical::getAISObject(AISObjectPtr thePrevious) -{ - if (!sketch()) - return thePrevious; - - AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, - sketch()->coordinatePlane(), - thePrevious); - return anAIS; -} - double SketchPlugin_ConstraintDistanceVertical::calculateCurrentDistance() { std::shared_ptr aData = data(); @@ -92,45 +47,19 @@ double SketchPlugin_ConstraintDistanceVertical::calculateCurrentDistance() return aPointB->y() - aPointA->y(); } -void SketchPlugin_ConstraintDistanceVertical::attributeChanged(const std::string& theID) +void SketchPlugin_ConstraintDistanceVertical::updateFlyoutPoint() { - if (theID == SketchPlugin_Constraint::ENTITY_A() || - theID == SketchPlugin_Constraint::ENTITY_B()) - { - AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE()); - if (!aValueAttr->isInitialized() && areAttributesInitialized()) { - // only if it is not initialized, try to compute the current value - double aDistance = calculateCurrentDistance(); - aValueAttr->setValue(aDistance); - } - } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { - // Recalculate flyout point in local coordinates of the distance constraint: - // the X coordinate is a length of projection of the flyout point on the - // line binding two distanced points - // or a line of projection of the distanced point onto the distanced segment - // the Y coordinate is a distance from the flyout point to the line - std::shared_ptr aFlyoutAttr = - std::dynamic_pointer_cast( - attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - std::shared_ptr aFlyoutPnt = aFlyoutAttr->pnt(); - - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPointA = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPointB = SketcherPrs_Tools::getFeaturePoint( - data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); + std::shared_ptr aFlyoutAttr = + std::dynamic_pointer_cast( + attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + std::shared_ptr aFlyoutPnt = aFlyoutAttr->pnt(); - std::shared_ptr aStartPnt = aPointA->pnt()->xy(); - std::shared_ptr aEndPnt = aPointB->pnt()->xy(); - - if (aEndPnt->distance(aStartPnt) < tolerance) - return; + std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); + std::shared_ptr aEndPoint = SketcherPrs_Tools::getFeaturePoint( + data(), SketchPlugin_Constraint::ENTITY_B(), aPlane); - std::shared_ptr aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPnt); - myFlyoutUpdate = true; - double X = aFlyoutDir->y(); // Dot on OY axis - double Y = -aFlyoutDir->x(); // Cross to OY axis - aFlyoutAttr->setValue(X, Y); - myFlyoutUpdate = false; - } + std::shared_ptr aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPoint->pnt()->xy()); + double X = aFlyoutDir->y(); // Dot on OY axis + double Y = -aFlyoutDir->x(); // Cross to OY axis + aFlyoutAttr->setValue(X, Y); } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h b/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h index 1bfb6f144..a9d7284b9 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h @@ -26,7 +26,7 @@ #define SketchPlugin_ConstraintDistanceVertical_H_ #include -#include +#include /** \class SketchPlugin_ConstraintDistanceVertical * \ingroup Plugins @@ -35,7 +35,7 @@ * This constraint has three attributes: * SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ -class SketchPlugin_ConstraintDistanceVertical : public SketchPlugin_ConstraintDistance +class SketchPlugin_ConstraintDistanceVertical : public SketchPlugin_ConstraintDistanceAlongDir { public: /// Distance constraint kind @@ -52,32 +52,15 @@ public: return MY_KIND; } - /// attribute name of dimension location type - inline static const std::string& LOCATION_TYPE_ID() - { - static const std::string MY_LOCATION_TYPE_ID("LocationType"); - return MY_LOCATION_TYPE_ID; - } - - /// \brief Creates a new part document if needed - SKETCHPLUGIN_EXPORT virtual void execute(); - - /// \brief Request for initialization of data model of the feature: adding all attributes - SKETCHPLUGIN_EXPORT virtual void initAttributes(); - - /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); - - /// Called on change of any argument-attribute of this object - /// \param theID identifier of changed attribute - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// \brief Use plugin manager for features creation SketchPlugin_ConstraintDistanceVertical(); protected: /// Returns the current distance between the feature attributes virtual double calculateCurrentDistance(); + + /// Update flyout point + virtual void updateFlyoutPoint(); }; #endif diff --git a/src/SketchPlugin/Test/TestConstraintDistanceBehavior.py b/src/SketchPlugin/Test/TestConstraintDistanceBehavior.py index 35ab1496c..a38089083 100644 --- a/src/SketchPlugin/Test/TestConstraintDistanceBehavior.py +++ b/src/SketchPlugin/Test/TestConstraintDistanceBehavior.py @@ -45,6 +45,8 @@ model.do() # changing the parameter for param in range(-30, 31, 2): + if param == 0: + continue DistanceParam.setValue(param) model.do() dist = secondPoint.x() - firstPoint.x() @@ -66,6 +68,8 @@ model.do() # changing the parameter for param in range(-30, 31, 2): + if param == 0: + continue DistanceParam.setValue(param) model.do() dist = secondPoint.y() - firstPoint.y() diff --git a/src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py b/src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py index 242787471..29cfb5680 100644 --- a/src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py +++ b/src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py @@ -125,7 +125,10 @@ while d >= -30.: DISTANCE1 = d aDistance.setValue(DISTANCE1) aSession.finishOperation() - assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) + if DISTANCE1 == 0: + assert(aHDist1.error() != "") + else: + assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) d += dStep assert (model.dof(aSketchFeature) == 3) @@ -158,9 +161,12 @@ while d >= -50.: DISTANCE2 = d aDistance.setValue(DISTANCE2) aSession.finishOperation() - assert math.fabs(horizontalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(anExtCoords, aPoint1Coords), DISTANCE2) - assert math.fabs(aPoint1Coords.x() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected x = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) - assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) + if DISTANCE2 == 0: + assert(aHDist2.error() != "") + else: + assert math.fabs(horizontalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(anExtCoords, aPoint1Coords), DISTANCE2) + assert math.fabs(aPoint1Coords.x() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected x = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) + assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) d += dStep assert (model.dof(aSketchFeature) == 2) @@ -217,7 +223,10 @@ while d >= -50.: DISTANCE3 = d aDistance.setValue(DISTANCE3) aSession.finishOperation() - assert math.fabs(horizontalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aStartPoint, aEndPoint), DISTANCE3) + if DISTANCE3 == 0: + assert(aHDist3.error() != "") + else: + assert math.fabs(horizontalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aStartPoint, aEndPoint), DISTANCE3) d += dStep assert (model.dof(aSketchFeature) == 6) diff --git a/src/SketchPlugin/Test/TestConstraintDistanceVertical.py b/src/SketchPlugin/Test/TestConstraintDistanceVertical.py index 8910edcbf..5045080d3 100644 --- a/src/SketchPlugin/Test/TestConstraintDistanceVertical.py +++ b/src/SketchPlugin/Test/TestConstraintDistanceVertical.py @@ -125,7 +125,10 @@ while d >= -30.: DISTANCE1 = d aDistance.setValue(DISTANCE1) aSession.finishOperation() - assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) + if DISTANCE1 == 0: + assert(aVDist1.error() != "") + else: + assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) d += dStep assert (model.dof(aSketchFeature) == 3) @@ -158,9 +161,12 @@ while d >= -50.: DISTANCE2 = d aDistance.setValue(DISTANCE2) aSession.finishOperation() - assert math.fabs(verticalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(anExtCoords, aPoint1Coords), DISTANCE2) - assert math.fabs(aPoint1Coords.y() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected y = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) - assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) + if DISTANCE2 == 0: + assert(aVDist2.error() != "") + else: + assert math.fabs(verticalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(anExtCoords, aPoint1Coords), DISTANCE2) + assert math.fabs(aPoint1Coords.y() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected y = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2) + assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1) d += dStep assert (model.dof(aSketchFeature) == 2) @@ -217,7 +223,10 @@ while d >= -50.: DISTANCE3 = d aDistance.setValue(DISTANCE3) aSession.finishOperation() - assert math.fabs(verticalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aStartPoint, aEndPoint), DISTANCE3) + if DISTANCE3 == 0: + assert(aVDist3.error() != "") + else: + assert math.fabs(verticalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aStartPoint, aEndPoint), DISTANCE3) d += dStep assert (model.dof(aSketchFeature) == 6) diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 2c004c890..4372af645 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -703,7 +703,9 @@ email : webmaster.salome@opencascade.com - + + + - + + + impl()); DataPtr aData = myConstraint->data(); - AttributeDoublePtr anAttributeValue = aData->real(SketchPlugin_Constraint::VALUE()); + AttributeDoublePtr anAttributeValue; + if (myConstraint->getKind() == SketchPlugin_ConstraintDistanceHorizontal::ID() || + myConstraint->getKind() == SketchPlugin_ConstraintDistanceVertical::ID()) + anAttributeValue = aData->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()); + else + anAttributeValue = aData->real(SketchPlugin_Constraint::VALUE()); myValue.init(anAttributeValue); }