X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintFixed.cpp;h=6b73471ab680406920680361406d173056749b74;hb=refs%2Fheads%2FV9_11_BR;hp=3ee49eccf2e09f3f39e2243df1549732afffd675;hpb=07444a809f396ba009b9da3fe09ba4c5952f6a59;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp index 3ee49eccf..6b73471ab 100644 --- a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp @@ -1,20 +1,36 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2023 CEA, EDF +// +// 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 +// #include #include #include #include +#include +#include #include #include -#include +#include -#include - -// Find parameters of the feature that have been updated during the movement -static EntityWrapperPtr getChangedEntity(const FeaturePtr& theFeature, - const StoragePtr& theStorage); +/// \brief Get list of parameters of current entity +static GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity); SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(ConstraintPtr theConstraint) @@ -23,51 +39,79 @@ SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(ConstraintPtr theCons myType = CONSTRAINT_FIXED; } -SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature) - : SketchSolver_Constraint(), - myBaseFeature(theFeature) -{ - myType = CONSTRAINT_FIXED; -} - void SketchSolver_ConstraintFixed::blockEvents(bool isBlocked) { - if (myBaseFeature) - myBaseFeature->data()->blockSendAttributeUpdated(isBlocked); - if (myBaseConstraint) - SketchSolver_Constraint::blockEvents(isBlocked); + SketchSolver_Constraint::blockEvents(isBlocked); } void SketchSolver_ConstraintFixed::process() { cleanErrorMsg(); - if ((!myBaseConstraint && !myBaseFeature) || !myStorage) { + if (!myBaseConstraint || !myStorage) { // Not enough parameters are assigned return; } - EntityWrapperPtr aValue; - std::vector anEntities; - getAttributes(aValue, anEntities); - if (anEntities.empty()) + EntityWrapperPtr aBaseEntity = entityToFix(); + if (!aBaseEntity) myErrorMsg = SketchSolver_Error::ALREADY_FIXED(); if (!myErrorMsg.empty()) return; - fixFeature(anEntities.front()); + + ConstraintWrapperPtr aConstraint = fixFeature(aBaseEntity); + myStorage->addConstraint(myBaseConstraint, aConstraint); } -void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature) +ConstraintWrapperPtr SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature) { - std::shared_ptr anEntity = - std::dynamic_pointer_cast(theFeature); + GCS::VEC_pD aParameters = toParameters(theFeature); + + // Fix given list of parameters + std::list aConstraints; + myFixedValues.reserve(aParameters.size()); + GCS::VEC_pD::const_iterator anIt = aParameters.begin(); + for (int i = 0; anIt != aParameters.end(); ++anIt, ++i) { + myFixedValues.push_back(**anIt); + aConstraints.push_back( + GCSConstraintPtr(new GCS::ConstraintEqual(&myFixedValues[i], *anIt))); + } + + return ConstraintWrapperPtr( + new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType())); +} + +EntityWrapperPtr SketchSolver_ConstraintFixed::entityToFix() +{ + // Constraint Fixed is added by user. + // Get the attribute of constraint (it should be alone in the list of constraints). + EntityWrapperPtr aValue; + std::vector anAttributes; + SketchSolver_Constraint::getAttributes(aValue, anAttributes); + std::vector::const_iterator anIt = anAttributes.begin(); + for (; anIt != anAttributes.end(); ++anIt) + if (*anIt) + return *anIt; + return EntityWrapperPtr(); +} - GCS::VEC_pD aParameters; // parameters of entity to be fixed + + + +// ================== Auxiliary functions ================== +GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity) +{ + GCS::VEC_pD aParameters; + if (!theEntity) + return aParameters; + + std::shared_ptr anEntity = + std::dynamic_pointer_cast(theEntity); // Collect parameters for each type of entity - switch (theFeature->type()) { + switch (theEntity->type()) { case ENTITY_POINT: { std::shared_ptr aPoint = - std::dynamic_pointer_cast(theFeature); + std::dynamic_pointer_cast(theEntity); aParameters.push_back(aPoint->point()->x); aParameters.push_back(aPoint->point()->y); break; @@ -89,7 +133,6 @@ void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature) break; } case ENTITY_ARC: { - myFixedValues.reserve(4); std::shared_ptr anArc = std::dynamic_pointer_cast(anEntity->entity()); aParameters.push_back(anArc->center.x); aParameters.push_back(anArc->center.y); @@ -98,96 +141,41 @@ void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature) aParameters.push_back(anArc->endAngle); break; } - default: + case ENTITY_ELLIPSE: { + std::shared_ptr anEllipse = + std::dynamic_pointer_cast(anEntity->entity()); + aParameters.push_back(anEllipse->center.x); + aParameters.push_back(anEllipse->center.y); + aParameters.push_back(anEllipse->focus1.x); + aParameters.push_back(anEllipse->focus1.y); + aParameters.push_back(anEllipse->radmin); break; - } - - // Fix given list of parameters - std::list aConstraints; - myFixedValues.reserve(aParameters.size()); - GCS::VEC_pD::const_iterator anIt = aParameters.begin(); - for (int i = 0; anIt != aParameters.end(); ++anIt, ++i) { - myFixedValues.push_back(**anIt); - aConstraints.push_back( - GCSConstraintPtr(new GCS::ConstraintEqual(*anIt, &myFixedValues[i]))); - } - - myConstraint = ConstraintWrapperPtr( - new PlaneGCSSolver_ConstraintWrapper(aConstraints, getType())); - - if (myBaseConstraint) - myStorage->addConstraint(myBaseConstraint, myConstraint); - else - myStorage->addTemporaryConstraint(myConstraint); -} - -void SketchSolver_ConstraintFixed::getAttributes( - EntityWrapperPtr& theValue, - std::vector& theAttributes) -{ - if (myBaseFeature) { - // if the feature is copy, do not move it - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(myBaseFeature); - if (aSketchFeature && aSketchFeature->isCopy()) { - myStorage->setNeedToResolve(true); - return; } - - // The feature is fixed. - EntityWrapperPtr aSolverEntity = getChangedEntity(myBaseFeature, myStorage); - myStorage->update(myBaseFeature); - if (aSolverEntity) - theAttributes.push_back(aSolverEntity); - } else if (myBaseConstraint) { - // Constraint Fixed is added by user. - // Get the attribute of constraint (it should be alone in the list of constraints). - std::vector anAttributes; - SketchSolver_Constraint::getAttributes(theValue, anAttributes); - std::vector::const_iterator anIt = anAttributes.begin(); - for (; anIt != anAttributes.end(); ++anIt) - if (*anIt) - theAttributes.push_back(*anIt); - } else - myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); -} - - - - -// ==================== Auxiliary functions =============================== -static bool isSameCoordinates(const AttributePoint2DPtr& thePointAttr, - const PointWrapperPtr& thePointWrapper) -{ - GCSPointPtr aGCSPoint = thePointWrapper->point(); - return fabs(*aGCSPoint->x - thePointAttr->x()) < tolerance && - fabs(*aGCSPoint->y - thePointAttr->y()) < tolerance; -} - -EntityWrapperPtr getChangedEntity(const FeaturePtr& theFeature, - const StoragePtr& theStorage) -{ - std::list aPoints = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); - std::list aChangedPoints; - - std::list::const_iterator aPIt = aPoints.begin(); - for (; aPIt != aPoints.end(); ++aPIt) { - AttributePoint2DPtr aPnt = std::dynamic_pointer_cast(*aPIt); - EntityWrapperPtr anEnt = theStorage->entity(*aPIt); - if (anEnt) { - PointWrapperPtr aPW = std::dynamic_pointer_cast(anEnt); - if (!isSameCoordinates(aPnt, aPW)) - aChangedPoints.push_back(anEnt); - } else { - theStorage->update(*aPIt); - aChangedPoints.push_back(theStorage->entity(*aPIt)); + case ENTITY_ELLIPTIC_ARC: { + std::shared_ptr anEllArc = + std::dynamic_pointer_cast(anEntity->entity()); + aParameters.push_back(anEllArc->center.x); + aParameters.push_back(anEllArc->center.y); + aParameters.push_back(anEllArc->focus1.x); + aParameters.push_back(anEllArc->focus1.y); + aParameters.push_back(anEllArc->radmin); + aParameters.push_back(anEllArc->startAngle); + aParameters.push_back(anEllArc->endAngle); + break; } + case ENTITY_BSPLINE: { + std::shared_ptr aBSpline = + std::dynamic_pointer_cast(anEntity->entity()); + for (GCS::VEC_P::iterator anIt = aBSpline->poles.begin(); + anIt != aBSpline->poles.end(); ++anIt) { + aParameters.push_back(anIt->x); + aParameters.push_back(anIt->y); + } + break; + } + default: + break; } - EntityWrapperPtr aChanged; - if (aChangedPoints.size() == 1) - aChanged = aChangedPoints.front(); - else if (!aChangedPoints.empty()) // update whole feature - aChanged = theStorage->entity(theFeature); - return aChanged; + return aParameters; }