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 void SolveSpaceSolver_ConstraintWrapper::setValue(const double& theValue)
40 double aValue = theValue;
41 if (type() == CONSTRAINT_RADIUS)
42 aValue *= 2.0; // NOTE: SolveSpace uses constraint DIAMETER
44 SketchSolver_IConstraintWrapper::setValue(aValue);
47 bool SolveSpaceSolver_ConstraintWrapper::isUsed(FeaturePtr theFeature) const
49 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
50 for (; anIt != myConstrained.end(); ++anIt)
51 if ((*anIt)->isUsed(theFeature))
56 bool SolveSpaceSolver_ConstraintWrapper::isUsed(AttributePtr theAttribute) const
58 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
59 for (; anIt != myConstrained.end(); ++anIt)
60 if ((*anIt)->isUsed(theAttribute))
65 bool SolveSpaceSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOther)
67 const Slvs_Constraint anOtherConstraint =
68 std::dynamic_pointer_cast<SolveSpaceSolver_ConstraintWrapper>(theOther)->constraint();
69 if (mySlvsConstraint.type != anOtherConstraint.type)
72 // Verify SolveSpace entities. If they are equal, no need additional checking of parameters.
73 if (mySlvsConstraint.group == anOtherConstraint.group &&
74 mySlvsConstraint.ptA == anOtherConstraint.ptA &&
75 mySlvsConstraint.ptB == anOtherConstraint.ptB &&
76 mySlvsConstraint.entityA == anOtherConstraint.entityA &&
77 mySlvsConstraint.entityB == anOtherConstraint.entityB &&
78 mySlvsConstraint.entityC == anOtherConstraint.entityC &&
79 mySlvsConstraint.entityD == anOtherConstraint.entityD &&
80 fabs(mySlvsConstraint.valA - anOtherConstraint.valA) < tolerance) {
84 // Verify equality of values
85 if (fabs(myValue - theOther->value()) > tolerance)
88 // Verify equality of entities
89 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->entities();
90 if (myConstrained.size() != anOtherSubs.size())
92 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = myConstrained.begin();
93 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
94 for (; aMySubsIt != myConstrained.end(); ++aMySubsIt, ++anOtherSubsIt)
95 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
100 bool SolveSpaceSolver_ConstraintWrapper::update(const ConstraintWrapperPtr& theOther)
102 bool isUpdated = false;
104 std::list<EntityWrapperPtr> aMySubs = entities();
105 std::list<EntityWrapperPtr> anOtherSubs = theOther->entities();
106 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
107 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
108 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
109 ++aMySubsIt, ++anOtherSubsIt)
110 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
112 if (fabs(value() - theOther->value()) > tolerance) {
113 myValue = theOther->value();