1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <SolveSpaceSolver_ConstraintWrapper.h>
21 #include <SolveSpaceSolver_ConstraintType.h>
24 SolveSpaceSolver_ConstraintWrapper::SolveSpaceSolver_ConstraintWrapper(
25 const ConstraintPtr& theOriginal,
26 const Slvs_Constraint& theConstraint)
27 : mySlvsConstraint(theConstraint)
29 myBaseConstraint = theOriginal;
30 myValue = mySlvsConstraint.valA;
33 ConstraintID SolveSpaceSolver_ConstraintWrapper::id() const
35 return (ConstraintID)mySlvsConstraint.h;
38 void SolveSpaceSolver_ConstraintWrapper::setGroup(const GroupID& theGroup)
40 mySlvsConstraint.group = (Slvs_hGroup)theGroup;
41 std::list<EntityWrapperPtr>::iterator aSubsIt = myConstrained.begin();
42 for (; aSubsIt != myConstrained.end(); ++aSubsIt)
43 (*aSubsIt)->setGroup(theGroup);
46 SketchSolver_ConstraintType SolveSpaceSolver_ConstraintWrapper::type() const
48 return ConstraintType::fromSolveSpace(mySlvsConstraint.type);
51 bool SolveSpaceSolver_ConstraintWrapper::isUsed(FeaturePtr theFeature) const
53 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
54 for (; anIt != myConstrained.end(); ++anIt)
55 if ((*anIt)->isUsed(theFeature))
60 bool SolveSpaceSolver_ConstraintWrapper::isUsed(AttributePtr theAttribute) const
62 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
63 for (; anIt != myConstrained.end(); ++anIt)
64 if ((*anIt)->isUsed(theAttribute))
69 bool SolveSpaceSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOther)
71 const Slvs_Constraint anOtherConstraint =
72 std::dynamic_pointer_cast<SolveSpaceSolver_ConstraintWrapper>(theOther)->constraint();
73 if (mySlvsConstraint.type != anOtherConstraint.type)
76 // Verify SolveSpace entities. If they are equal, no need additional checking of parameters.
77 if (mySlvsConstraint.group == anOtherConstraint.group &&
78 mySlvsConstraint.ptA == anOtherConstraint.ptA &&
79 mySlvsConstraint.ptB == anOtherConstraint.ptB &&
80 mySlvsConstraint.entityA == anOtherConstraint.entityA &&
81 mySlvsConstraint.entityB == anOtherConstraint.entityB &&
82 mySlvsConstraint.entityC == anOtherConstraint.entityC &&
83 mySlvsConstraint.entityD == anOtherConstraint.entityD &&
84 fabs(mySlvsConstraint.valA - anOtherConstraint.valA) < tolerance) {
88 // Verify equality of values
89 if (fabs(myValue - theOther->value()) > tolerance)
92 // Verify equality of entities
93 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->entities();
94 if (myConstrained.size() != anOtherSubs.size())
96 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = myConstrained.begin();
97 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
98 for (; aMySubsIt != myConstrained.end(); ++aMySubsIt, ++anOtherSubsIt)
99 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
104 bool SolveSpaceSolver_ConstraintWrapper::update(const ConstraintWrapperPtr& theOther)
106 bool isUpdated = false;
108 std::list<EntityWrapperPtr> aMySubs = entities();
109 std::list<EntityWrapperPtr> anOtherSubs = theOther->entities();
110 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
111 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
112 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
113 ++aMySubsIt, ++anOtherSubsIt)
114 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
116 if (fabs(value() - theOther->value()) > tolerance) {
117 myValue = theOther->value();