1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <SolveSpaceSolver_ConstraintWrapper.h>
22 #include <SolveSpaceSolver_ConstraintType.h>
25 SolveSpaceSolver_ConstraintWrapper::SolveSpaceSolver_ConstraintWrapper(
26 const ConstraintPtr& theOriginal,
27 const Slvs_Constraint& theConstraint)
28 : mySlvsConstraint(theConstraint)
30 myBaseConstraint = theOriginal;
31 myValue = mySlvsConstraint.valA;
34 ConstraintID SolveSpaceSolver_ConstraintWrapper::id() const
36 return (ConstraintID)mySlvsConstraint.h;
39 void SolveSpaceSolver_ConstraintWrapper::setGroup(const GroupID& theGroup)
41 mySlvsConstraint.group = (Slvs_hGroup)theGroup;
42 std::list<EntityWrapperPtr>::iterator aSubsIt = myConstrained.begin();
43 for (; aSubsIt != myConstrained.end(); ++aSubsIt)
44 (*aSubsIt)->setGroup(theGroup);
47 SketchSolver_ConstraintType SolveSpaceSolver_ConstraintWrapper::type() const
49 return ConstraintType::fromSolveSpace(mySlvsConstraint.type);
52 bool SolveSpaceSolver_ConstraintWrapper::isUsed(FeaturePtr theFeature) const
54 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
55 for (; anIt != myConstrained.end(); ++anIt)
56 if ((*anIt)->isUsed(theFeature))
61 bool SolveSpaceSolver_ConstraintWrapper::isUsed(AttributePtr theAttribute) const
63 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
64 for (; anIt != myConstrained.end(); ++anIt)
65 if ((*anIt)->isUsed(theAttribute))
70 bool SolveSpaceSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOther)
72 const Slvs_Constraint anOtherConstraint =
73 std::dynamic_pointer_cast<SolveSpaceSolver_ConstraintWrapper>(theOther)->constraint();
74 if (mySlvsConstraint.type != anOtherConstraint.type)
77 // Verify SolveSpace entities. If they are equal, no need additional checking of parameters.
78 if (mySlvsConstraint.group == anOtherConstraint.group &&
79 mySlvsConstraint.ptA == anOtherConstraint.ptA &&
80 mySlvsConstraint.ptB == anOtherConstraint.ptB &&
81 mySlvsConstraint.entityA == anOtherConstraint.entityA &&
82 mySlvsConstraint.entityB == anOtherConstraint.entityB &&
83 mySlvsConstraint.entityC == anOtherConstraint.entityC &&
84 mySlvsConstraint.entityD == anOtherConstraint.entityD &&
85 fabs(mySlvsConstraint.valA - anOtherConstraint.valA) < tolerance) {
89 // Verify equality of values
90 if (fabs(myValue - theOther->value()) > tolerance)
93 // Verify equality of entities
94 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->entities();
95 if (myConstrained.size() != anOtherSubs.size())
97 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = myConstrained.begin();
98 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
99 for (; aMySubsIt != myConstrained.end(); ++aMySubsIt, ++anOtherSubsIt)
100 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
105 bool SolveSpaceSolver_ConstraintWrapper::update(const ConstraintWrapperPtr& theOther)
107 bool isUpdated = false;
109 std::list<EntityWrapperPtr> aMySubs = entities();
110 std::list<EntityWrapperPtr> anOtherSubs = theOther->entities();
111 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
112 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
113 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
114 ++aMySubsIt, ++anOtherSubsIt)
115 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
117 if (fabs(value() - theOther->value()) > tolerance) {
118 myValue = theOther->value();