X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintCoincidence.cpp;h=ae4a89bcc63d3d457fab1f59da8ce078b4b2a7ba;hb=4df4bd61da1ea5d357671c819a8ced6ec9ba77ac;hp=8501289fd2b475d9532f2d77cc5eba1796d783d6;hpb=e066abaa17e20d15934c0c83cdd8de07ffd93122;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp index 8501289fd..ae4a89bcc 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp @@ -1,10 +1,55 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-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 +// #include #include -#include +#include #include +#include +#include + +static void getCoincidentFeatureExtremities(const ConstraintPtr& theConstraint, + const StoragePtr& theStorage, + EntityWrapperPtr theExtremities[2]) +{ + for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { + AttributeRefAttrPtr aRefAttr = theConstraint->refattr(SketchPlugin_Constraint::ATTRIBUTE(i)); + if (!aRefAttr || !aRefAttr->isObject()) + continue; + + FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); + if (!aFeature) + continue; + + if (aFeature->getKind() == SketchPlugin_Line::ID()) { + theExtremities[0] = theStorage->entity(aFeature->attribute(SketchPlugin_Line::START_ID())); + theExtremities[1] = theStorage->entity(aFeature->attribute(SketchPlugin_Line::END_ID())); + } else if (aFeature->getKind() == SketchPlugin_Arc::ID()) { + theExtremities[0] = theStorage->entity(aFeature->attribute(SketchPlugin_Arc::START_ID())); + theExtremities[1] = theStorage->entity(aFeature->attribute(SketchPlugin_Arc::END_ID())); + } + } +} + + void SketchSolver_ConstraintCoincidence::process() { cleanErrorMsg(); @@ -23,8 +68,7 @@ void SketchSolver_ConstraintCoincidence::process() return; } - BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); - mySolverConstraint = aBuilder->createConstraint( + mySolverConstraint = PlaneGCSSolver_Tools::createConstraint( myBaseConstraint, getType(), aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]); @@ -32,6 +76,14 @@ void SketchSolver_ConstraintCoincidence::process() myStorage->notify(myBaseConstraint); } +bool SketchSolver_ConstraintCoincidence::remove() +{ + myInSolver = false; + myFeatureExtremities[0] = EntityWrapperPtr(); + myFeatureExtremities[1] = EntityWrapperPtr(); + return SketchSolver_Constraint::remove(); +} + void SketchSolver_ConstraintCoincidence::getAttributes( EntityWrapperPtr& theValue, std::vector& theAttributes) @@ -53,6 +105,9 @@ void SketchSolver_ConstraintCoincidence::getAttributes( myType = CONSTRAINT_PT_ON_CIRCLE; else myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE(); + + // obtain extremity points of the coincident feature for further checking of multi-coincidence + getCoincidentFeatureExtremities(myBaseConstraint, myStorage, myFeatureExtremities); } else myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE(); } @@ -62,7 +117,17 @@ void SketchSolver_ConstraintCoincidence::notify(const FeaturePtr& theFeatur { PlaneGCSSolver_UpdateCoincidence* anUpdater = static_cast(theUpdater); - bool isAccepted = anUpdater->checkCoincidence(myAttributes.front(), myAttributes.back()); + bool isAccepted = anUpdater->addCoincidence(myAttributes.front(), myAttributes.back()); + + // additionally check the point is coincident to extremity of coincident feature + if (myFeatureExtremities[0] && myFeatureExtremities[1]) { + EntityWrapperPtr aPoint = + myAttributes.front()->type() == ENTITY_POINT ? myAttributes.front() : myAttributes.back(); + + for (int i = 0; i < 2; ++i) + isAccepted = isAccepted && !anUpdater->isPointOnEntity(aPoint, myFeatureExtremities[i]); + } + if (isAccepted) { if (!myInSolver) { myInSolver = true;