Salome HOME
Delete key regression corrections: in previous implementation sketch entities did...
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_ConstraintWrapper.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_ConstraintWrapper.cpp
4 // Created: 14 Dec 2015
5 // Author:  Artem ZHIDKOV
6
7 #include <PlaneGCSSolver_ConstraintWrapper.h>
8
9 #include <math.h>
10
11 PlaneGCSSolver_ConstraintWrapper::PlaneGCSSolver_ConstraintWrapper(
12     const ConstraintPtr& theOriginal,
13     const GCSConstraintPtr& theConstraint,
14     const SketchSolver_ConstraintType& theType)
15   : myGCSConstraints(1, theConstraint),
16     myType(theType),
17     myID(CID_UNKNOWN)
18 {
19   myBaseConstraint = theOriginal;
20   myValue = 0.0;
21 }
22
23 PlaneGCSSolver_ConstraintWrapper::PlaneGCSSolver_ConstraintWrapper(
24     const ConstraintPtr& theOriginal,
25     const std::list<GCSConstraintPtr>& theConstraints,
26     const SketchSolver_ConstraintType& theType)
27   : myGCSConstraints(theConstraints),
28     myType(theType),
29     myID(CID_UNKNOWN)
30 {
31   myBaseConstraint = theOriginal;
32   myValue = 0.0;
33 }
34
35 void PlaneGCSSolver_ConstraintWrapper::setValueParameter(const ParameterWrapperPtr& theValue)
36 {
37   myValueParam = theValue;
38   myValue = myValueParam->value();
39 }
40
41 void PlaneGCSSolver_ConstraintWrapper::setValue(const double& theValue)
42 {
43   myValue = theValue;
44   myValueParam->setValue(theValue);
45 }
46
47
48 void PlaneGCSSolver_ConstraintWrapper::setGroup(const GroupID& theGroup)
49 {
50   myGroup = theGroup;
51   std::list<EntityWrapperPtr>::iterator aSubsIt = myConstrained.begin();
52   for (; aSubsIt != myConstrained.end(); ++aSubsIt)
53     (*aSubsIt)->setGroup(theGroup);
54 }
55
56 bool PlaneGCSSolver_ConstraintWrapper::isUsed(FeaturePtr theFeature) const
57 {
58   std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
59   for (; anIt != myConstrained.end(); ++anIt)
60     if ((*anIt)->isUsed(theFeature))
61       return true;
62   return false;
63 }
64
65 bool PlaneGCSSolver_ConstraintWrapper::isUsed(AttributePtr theAttribute) const
66 {
67   std::list<EntityWrapperPtr>::const_iterator anIt = myConstrained.begin();
68   for (; anIt != myConstrained.end(); ++anIt)
69     if ((*anIt)->isUsed(theAttribute))
70       return true;
71   return false;
72 }
73
74 bool PlaneGCSSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOther)
75 {
76   if (type() != theOther->type())
77     return false;
78
79   // Verify equality of values
80   if (fabs(myValue - theOther->value()) > tolerance)
81     return false;
82
83   // Verify equality of entities
84   const std::list<EntityWrapperPtr>& anOtherSubs = theOther->entities();
85   if (myConstrained.size() != anOtherSubs.size())
86     return false;
87   std::list<EntityWrapperPtr>::const_iterator aMySubsIt = myConstrained.begin();
88   std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
89   for (; aMySubsIt != myConstrained.end(); ++aMySubsIt, ++anOtherSubsIt)
90     if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
91       return false;
92   return true;
93 }
94
95 bool PlaneGCSSolver_ConstraintWrapper::update(const ConstraintWrapperPtr& theOther)
96 {
97   bool isUpdated = false;
98
99   std::list<EntityWrapperPtr> aMySubs = entities();
100   std::list<EntityWrapperPtr> anOtherSubs = theOther->entities();
101   std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
102   std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
103   for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
104        ++aMySubsIt, ++anOtherSubsIt)
105      isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
106
107   if (fabs(value() - theOther->value()) > tolerance) {
108     myValue = theOther->value();
109     isUpdated = true;
110   }
111   return isUpdated;
112 }