X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintDistanceHorizontal.cpp;h=bfcee75e7cb65d13edd4716bbec2f665935ab095;hb=88ee9b2b81cf93a6324336b57e30cc8a3a487499;hp=c75e83bf570af3d1e3bf955d9b160993a8bffebe;hpb=35097baada6d03a680b50f52a938f0b656396da6;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp index c75e83bf5..bfcee75e7 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017 CEA/DEN, EDF R&D +// Copyright (C) 2017-2022 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 @@ -12,10 +12,9 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File: SketchPlugin_ConstraintDistanceHorizontal.cpp @@ -25,56 +24,14 @@ #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()); -} - -//************************************************************************************* -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() @@ -89,44 +46,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); }