X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FSketchSolver%2FSketchSolver_ConstraintFixed.cpp;h=cb9ad10bc72983ca3ce87a288dbe688854a1bef4;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=ca14864cb5cf8f5b00013eaaf8f25d444f9970cf;hpb=c3aeb6b898054376c1047071ea9fea61abdc9e99;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp index ca14864cb..cb9ad10bc 100644 --- a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp @@ -1,125 +1,181 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2024 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 +#include +#include -#include -#include #include -#include +#include + +/// \brief Get list of parameters of current entity +static GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity); -#include SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(ConstraintPtr theConstraint) - : SketchSolver_Constraint() + : SketchSolver_Constraint(theConstraint) { - myBaseConstraint = theConstraint; myType = CONSTRAINT_FIXED; - AttributeRefAttrPtr anAttribute = - theConstraint->refattr(SketchPlugin_ConstraintRigid::ENTITY_A()); - if (anAttribute->isObject()) - myFixedFeature = ModelAPI_Feature::feature(anAttribute->object()); - else - myFixedAttribute = anAttribute->attr(); } -SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature) - : SketchSolver_Constraint(), - myBaseFeature(theFeature) +void SketchSolver_ConstraintFixed::blockEvents(bool isBlocked) { - myType = CONSTRAINT_FIXED; - process(); + SketchSolver_Constraint::blockEvents(isBlocked); } void SketchSolver_ConstraintFixed::process() { cleanErrorMsg(); - if ((!myBaseConstraint && !myBaseFeature) || !myStorage || myGroupID == GID_UNKNOWN) { + if (!myBaseConstraint || !myStorage) { // Not enough parameters are assigned return; } - ParameterWrapperPtr aValue; - std::vector anEntities; - getAttributes(aValue, anEntities); - if (!myErrorMsg.empty() || 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) { - // extract feature from the group - if (theFeature->baseAttribute()) - myStorage->update(theFeature->baseAttribute(), GID_OUTOFGROUP); - else if (theFeature->baseFeature()) - myStorage->update(theFeature->baseFeature(), GID_OUTOFGROUP); - - if (myBaseConstraint) - myStorage->addConstraint(myBaseConstraint, std::list()); + 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())); } -void SketchSolver_ConstraintFixed::getAttributes( - ParameterWrapperPtr& theValue, - std::vector& theAttributes) +EntityWrapperPtr SketchSolver_ConstraintFixed::entityToFix() { - BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); - - EntityWrapperPtr aSolverEntity; - if (myBaseFeature) { - // The feature is fixed. - myStorage->update(myBaseFeature/*, myGroupID*/); - aSolverEntity = myStorage->entity(myBaseFeature); - } else if (myBaseConstraint) { - // Constraint Fixed is added by user. - // Get the attribute of constraint (it should be alone in the list of constraints). - AttributePtr anAttr = myBaseConstraint->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()); - AttributeRefAttrPtr aRefAttr = - std::dynamic_pointer_cast(anAttr); - if (!aRefAttr || !aRefAttr->isInitialized()) { - myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); - return; - } + // 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(); +} - myStorage->update(anAttr, myGroupID); - aSolverEntity = myStorage->entity(anAttr); - } else - myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); - if (aSolverEntity) - theAttributes.push_back(aSolverEntity); -} -bool SketchSolver_ConstraintFixed::remove() +// ================== Auxiliary functions ================== +GCS::VEC_pD toParameters(const EntityWrapperPtr& theEntity) { - cleanErrorMsg(); - // Move fixed entities back to the current group - FeaturePtr aFeature = myBaseFeature; - if (myBaseConstraint) { - if (myFixedFeature) - aFeature = myFixedFeature; - else if (myFixedAttribute) - myStorage->update(AttributePtr(myFixedAttribute), myGroupID); + 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 (theEntity->type()) { + case ENTITY_POINT: { + std::shared_ptr aPoint = + std::dynamic_pointer_cast(theEntity); + aParameters.push_back(aPoint->point()->x); + aParameters.push_back(aPoint->point()->y); + break; + } + case ENTITY_LINE: { + std::shared_ptr aLine = std::dynamic_pointer_cast(anEntity->entity()); + aParameters.push_back(aLine->p1.x); + aParameters.push_back(aLine->p1.y); + aParameters.push_back(aLine->p2.x); + aParameters.push_back(aLine->p2.y); + break; + } + case ENTITY_CIRCLE: { + std::shared_ptr aCircle = + std::dynamic_pointer_cast(anEntity->entity()); + aParameters.push_back(aCircle->center.x); + aParameters.push_back(aCircle->center.y); + aParameters.push_back(aCircle->rad); + break; + } + case ENTITY_ARC: { + std::shared_ptr anArc = std::dynamic_pointer_cast(anEntity->entity()); + aParameters.push_back(anArc->center.x); + aParameters.push_back(anArc->center.y); + aParameters.push_back(anArc->rad); + aParameters.push_back(anArc->startAngle); + aParameters.push_back(anArc->endAngle); + break; + } + 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; + } + 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; } - if (aFeature) - myStorage->update(aFeature, myGroupID); - myStorage->setNeedToResolve(true); - - // Remove constraint or base feature - if (myBaseConstraint) { - bool isRemoved = false; - if (aFeature) - isRemoved = myStorage->removeEntity(aFeature); - return SketchSolver_Constraint::remove() || isRemoved; - } else if (myBaseFeature) - myStorage->removeEntity(myBaseFeature); - return true; + default: + break; + } + + return aParameters; }