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::setId(const ConstraintID& theID)
38 std::list<GCSConstraintPtr>::iterator anIt = myGCSConstraints.begin();
39 for (; anIt != myGCSConstraints.end(); ++anIt)
40 (*anIt)->setTag((int)theID);
43 void PlaneGCSSolver_ConstraintWrapper::setValueParameter(const ParameterWrapperPtr& theValue)
45 myValueParam = theValue;
46 myValue = myValueParam->value();
49 void PlaneGCSSolver_ConstraintWrapper::setValue(const double& theValue)
52 myValueParam->setValue(theValue);
56 void PlaneGCSSolver_ConstraintWrapper::setGroup(const GroupID& theGroup)
59 std::list<EntityWrapperPtr>::iterator aSubsIt = myConstrained.begin();
60 for (; aSubsIt != myConstrained.end(); ++aSubsIt)
61 (*aSubsIt)->setGroup(theGroup);
64 bool PlaneGCSSolver_ConstraintWrapper::isUsed(FeaturePtr theFeature) const
66 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
67 for (; anIt != myConstrained.end(); ++anIt)
68 if ((*anIt)->isUsed(theFeature))
73 bool PlaneGCSSolver_ConstraintWrapper::isUsed(AttributePtr theAttribute) const
75 std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
76 for (; anIt != myConstrained.end(); ++anIt)
77 if ((*anIt)->isUsed(theAttribute))
82 bool PlaneGCSSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOther)
84 if (type() != theOther->type())
87 // Verify equality of values
88 if (fabs(myValue - theOther->value()) > tolerance)
91 // Verify equality of entities
92 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->entities();
93 if (myConstrained.size() != anOtherSubs.size())
95 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = myConstrained.begin();
96 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
97 for (; aMySubsIt != myConstrained.end(); ++aMySubsIt, ++anOtherSubsIt)
98 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
103 bool PlaneGCSSolver_ConstraintWrapper::update(const ConstraintWrapperPtr& theOther)
105 bool isUpdated = false;
107 std::list<EntityWrapperPtr> aMySubs = entities();
108 std::list<EntityWrapperPtr> anOtherSubs = theOther->entities();
109 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
110 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
111 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
112 ++aMySubsIt, ++anOtherSubsIt)
113 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
115 if (fabs(value() - theOther->value()) > tolerance) {
116 myValue = theOther->value();