Salome HOME
Update copyrights
[modules/shaper.git] / src / SketchSolver / SolveSpaceSolver / SolveSpaceSolver_EntityWrapper.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <SolveSpaceSolver_EntityWrapper.h>
21
22 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
23     const FeaturePtr theFeature, const Slvs_Entity& theEntity)
24   : myEntity(theEntity)
25 {
26   myBaseFeature = theFeature;
27 }
28
29 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
30     const AttributePtr theAttribute, const Slvs_Entity& theEntity)
31   : myEntity(theEntity)
32 {
33   myBaseAttribute = theAttribute;
34 }
35
36 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
37     const FeaturePtr thePointFeature,
38     const AttributePtr thePointAttribute,
39     const Slvs_Entity& theEntity)
40   : myEntity(theEntity)
41 {
42   myBaseFeature = thePointFeature;
43   myBaseAttribute = thePointAttribute;
44 }
45
46
47 EntityID SolveSpaceSolver_EntityWrapper::id() const
48 {
49   return (EntityID)myEntity.h;
50 }
51
52 void SolveSpaceSolver_EntityWrapper::setGroup(const GroupID& theGroup)
53 {
54   myEntity.group = (Slvs_hGroup)theGroup;
55   std::list<EntityWrapperPtr>::iterator aSubsIt = mySubEntities.begin();
56   for (; aSubsIt != mySubEntities.end(); ++aSubsIt)
57     (*aSubsIt)->setGroup(theGroup);
58   std::list<ParameterWrapperPtr>::iterator aPIt = myParameters.begin();
59   for (; aPIt != myParameters.end(); ++aPIt)
60     (*aPIt)->setGroup(theGroup);
61 }
62
63 SketchSolver_EntityType SolveSpaceSolver_EntityWrapper::type() const
64 {
65   switch (myEntity.type) {
66   case SLVS_E_POINT_IN_3D:
67   case SLVS_E_POINT_IN_2D:    return ENTITY_POINT;
68   case SLVS_E_LINE_SEGMENT:   return ENTITY_LINE;
69   case SLVS_E_CIRCLE:         return ENTITY_CIRCLE;
70   case SLVS_E_ARC_OF_CIRCLE:  return ENTITY_ARC;
71   case SLVS_E_NORMAL_IN_3D:
72   case SLVS_E_NORMAL_IN_2D:   return ENTITY_NORMAL;
73   case SLVS_E_DISTANCE:       return ENTITY_SCALAR;
74   case SLVS_E_WORKPLANE:      return ENTITY_SKETCH;
75   default: break;
76   }
77   return ENTITY_UNKNOWN;
78 }
79
80 bool SolveSpaceSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
81 {
82   if (isBase(theFeature))
83     return true;
84
85   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
86   for (; anIt != mySubEntities.end(); ++anIt)
87     if ((*anIt)->isUsed(theFeature))
88       return true;
89   return false;
90 }
91
92 bool SolveSpaceSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
93 {
94   if (isBase(theAttribute))
95     return true;
96
97   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
98   for (; anIt != mySubEntities.end(); ++anIt)
99     if ((*anIt)->isUsed(theAttribute))
100       return true;
101   return false;
102 }
103
104 bool SolveSpaceSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
105 {
106   if (type() != theOther->type())
107     return false;
108
109   // Verify Equality of sub-entities
110   const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
111   if (mySubEntities.size() != anOtherSubs.size())
112     return false;
113   std::list<EntityWrapperPtr>::const_iterator aMySubsIt = mySubEntities.begin();
114   std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
115   for (; aMySubsIt != mySubEntities.end(); ++aMySubsIt, ++anOtherSubsIt)
116     if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
117       return false;
118
119   // Verify equality of parameters
120   const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
121   if (myParameters.size() != anOtherParams.size())
122     return false;
123   std::list<ParameterWrapperPtr>::const_iterator aMyIt = myParameters.begin();
124   std::list<ParameterWrapperPtr>::const_iterator anOtherIt = anOtherParams.begin();
125   for (; aMyIt != myParameters.end(); ++aMyIt, ++anOtherIt)
126     if (!(*aMyIt)->isEqual(*anOtherIt))
127       return false;
128   return true;
129 }
130
131 bool SolveSpaceSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
132 {
133   bool isUpdated = false;
134
135   std::list<EntityWrapperPtr> aMySubs = subEntities();
136   std::list<EntityWrapperPtr> anOtherSubs = theOther->subEntities();
137   std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
138   std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
139   for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
140        ++aMySubsIt, ++anOtherSubsIt)
141      isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
142
143   std::list<ParameterWrapperPtr> aMyParams = parameters();
144   std::list<ParameterWrapperPtr> anOtherParams = theOther->parameters();
145   std::list<ParameterWrapperPtr>::const_iterator aMyParIt = aMyParams.begin();
146   std::list<ParameterWrapperPtr>::const_iterator anOtherParIt = anOtherParams.begin();
147   for (; aMyParIt != aMyParams.end() && anOtherParIt != anOtherParams.end();
148       ++aMyParIt, ++anOtherParIt)
149     isUpdated = (*aMyParIt)->update(*anOtherParIt);
150   return isUpdated;
151 }