1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PlaneGCSSolver_ConstraintWrapper.cpp
4 // Created: 14 Dec 2015
5 // Author: Artem ZHIDKOV
7 #include <PlaneGCSSolver_ConstraintWrapper.h>
11 PlaneGCSSolver_ConstraintWrapper::PlaneGCSSolver_ConstraintWrapper(
12 const ConstraintPtr& theOriginal,
13 const GCSConstraintPtr& theConstraint,
14 const SketchSolver_ConstraintType& theType)
15 : myGCSConstraints(1, theConstraint),
19 myBaseConstraint = theOriginal;
23 PlaneGCSSolver_ConstraintWrapper::PlaneGCSSolver_ConstraintWrapper(
24 const ConstraintPtr& theOriginal,
25 const std::list<GCSConstraintPtr>& theConstraints,
26 const SketchSolver_ConstraintType& theType)
27 : myGCSConstraints(theConstraints),
31 myBaseConstraint = theOriginal;
35 void PlaneGCSSolver_ConstraintWrapper::setValueParameter(const ParameterWrapperPtr& theValue)
37 myValueParam = theValue;
38 myValue = myValueParam->value();
41 void PlaneGCSSolver_ConstraintWrapper::setValue(const double& theValue)
44 myValueParam->setValue(theValue);
48 void PlaneGCSSolver_ConstraintWrapper::setGroup(const GroupID& theGroup)
51 std::list<EntityWrapperPtr>::iterator aSubsIt = myConstrained.begin();
52 for (; aSubsIt != myConstrained.end(); ++aSubsIt)
53 (*aSubsIt)->setGroup(theGroup);
56 bool PlaneGCSSolver_ConstraintWrapper::isUsed(FeaturePtr theFeature) const
58 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
59 for (; anIt != myConstrained.end(); ++anIt)
60 if ((*anIt)->isUsed(theFeature))
65 bool PlaneGCSSolver_ConstraintWrapper::isUsed(AttributePtr theAttribute) const
67 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
68 for (; anIt != myConstrained.end(); ++anIt)
69 if ((*anIt)->isUsed(theAttribute))
74 bool PlaneGCSSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOther)
76 if (type() != theOther->type())
78 //// const Slvs_Constraint anOtherConstraint =
79 //// std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(theOther)->constraint();
80 //// if (mySlvsConstraint.type != anOtherConstraint.type)
83 //// // Verify SolveSpace entities. If they are equal, no need additional checking of parameters.
84 //// if (mySlvsConstraint.group == anOtherConstraint.group &&
85 //// mySlvsConstraint.ptA == anOtherConstraint.ptA &&
86 //// mySlvsConstraint.ptB == anOtherConstraint.ptB &&
87 //// mySlvsConstraint.entityA == anOtherConstraint.entityA &&
88 //// mySlvsConstraint.entityB == anOtherConstraint.entityB &&
89 //// mySlvsConstraint.entityC == anOtherConstraint.entityC &&
90 //// mySlvsConstraint.entityD == anOtherConstraint.entityD &&
91 //// fabs(mySlvsConstraint.valA - anOtherConstraint.valA) < tolerance) {
95 // Verify equality of values
96 if (fabs(myValue - theOther->value()) > tolerance)
99 // Verify equality of entities
100 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->entities();
101 if (myConstrained.size() != anOtherSubs.size())
103 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = myConstrained.begin();
104 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
105 for (; aMySubsIt != myConstrained.end(); ++aMySubsIt, ++anOtherSubsIt)
106 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
111 bool PlaneGCSSolver_ConstraintWrapper::update(const ConstraintWrapperPtr& theOther)
113 bool isUpdated = false;
115 std::list<EntityWrapperPtr> aMySubs = entities();
116 std::list<EntityWrapperPtr> anOtherSubs = theOther->entities();
117 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
118 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
119 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
120 ++aMySubsIt, ++anOtherSubsIt)
121 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
123 if (fabs(value() - theOther->value()) > tolerance) {
124 myValue = theOther->value();