1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SolveSpaceSolver_ConstraintWrapper.cpp
5 // Author: Artem ZHIDKOV
7 #include <SolveSpaceSolver_ConstraintWrapper.h>
8 #include <SolveSpaceSolver_ConstraintType.h>
11 SolveSpaceSolver_ConstraintWrapper::SolveSpaceSolver_ConstraintWrapper(
12 const ConstraintPtr& theOriginal,
13 const Slvs_Constraint& theConstraint)
14 : mySlvsConstraint(theConstraint)
16 myBaseConstraint = theOriginal;
17 myValue = mySlvsConstraint.valA;
20 ConstraintID SolveSpaceSolver_ConstraintWrapper::id() const
22 return (ConstraintID)mySlvsConstraint.h;
25 void SolveSpaceSolver_ConstraintWrapper::setGroup(const GroupID& theGroup)
27 mySlvsConstraint.group = (Slvs_hGroup)theGroup;
28 std::list<EntityWrapperPtr>::iterator aSubsIt = myConstrained.begin();
29 for (; aSubsIt != myConstrained.end(); ++aSubsIt)
30 (*aSubsIt)->setGroup(theGroup);
33 SketchSolver_ConstraintType SolveSpaceSolver_ConstraintWrapper::type() const
35 return ConstraintType::fromSolveSpace(mySlvsConstraint.type);
38 bool SolveSpaceSolver_ConstraintWrapper::isUsed(FeaturePtr theFeature) const
40 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
41 for (; anIt != myConstrained.end(); ++anIt)
42 if ((*anIt)->isUsed(theFeature))
47 bool SolveSpaceSolver_ConstraintWrapper::isUsed(AttributePtr theAttribute) const
49 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
50 for (; anIt != myConstrained.end(); ++anIt)
51 if ((*anIt)->isUsed(theAttribute))
56 bool SolveSpaceSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOther)
58 const Slvs_Constraint anOtherConstraint =
59 std::dynamic_pointer_cast<SolveSpaceSolver_ConstraintWrapper>(theOther)->constraint();
60 if (mySlvsConstraint.type != anOtherConstraint.type)
63 // Verify SolveSpace entities. If they are equal, no need additional checking of parameters.
64 if (mySlvsConstraint.group == anOtherConstraint.group &&
65 mySlvsConstraint.ptA == anOtherConstraint.ptA &&
66 mySlvsConstraint.ptB == anOtherConstraint.ptB &&
67 mySlvsConstraint.entityA == anOtherConstraint.entityA &&
68 mySlvsConstraint.entityB == anOtherConstraint.entityB &&
69 mySlvsConstraint.entityC == anOtherConstraint.entityC &&
70 mySlvsConstraint.entityD == anOtherConstraint.entityD &&
71 fabs(mySlvsConstraint.valA - anOtherConstraint.valA) < tolerance) {
75 // Verify equality of values
76 if (fabs(myValue - theOther->value()) > tolerance)
79 // Verify equality of entities
80 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->entities();
81 if (myConstrained.size() != anOtherSubs.size())
83 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = myConstrained.begin();
84 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
85 for (; aMySubsIt != myConstrained.end(); ++aMySubsIt, ++anOtherSubsIt)
86 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
91 bool SolveSpaceSolver_ConstraintWrapper::update(const ConstraintWrapperPtr& theOther)
93 bool isUpdated = false;
95 std::list<EntityWrapperPtr> aMySubs = entities();
96 std::list<EntityWrapperPtr> anOtherSubs = theOther->entities();
97 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
98 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
99 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
100 ++aMySubsIt, ++anOtherSubsIt)
101 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
103 if (fabs(value() - theOther->value()) > tolerance) {
104 myValue = theOther->value();