]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_EntityWrapper.cpp
Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / SketchSolver / SolveSpaceSolver / SolveSpaceSolver_EntityWrapper.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <SolveSpaceSolver_EntityWrapper.h>
22
23 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
24     const FeaturePtr theFeature, const Slvs_Entity& theEntity)
25   : myEntity(theEntity)
26 {
27   myBaseFeature = theFeature;
28 }
29
30 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
31     const AttributePtr theAttribute, const Slvs_Entity& theEntity)
32   : myEntity(theEntity)
33 {
34   myBaseAttribute = theAttribute;
35 }
36
37 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
38     const FeaturePtr thePointFeature,
39     const AttributePtr thePointAttribute,
40     const Slvs_Entity& theEntity)
41   : myEntity(theEntity)
42 {
43   myBaseFeature = thePointFeature;
44   myBaseAttribute = thePointAttribute;
45 }
46
47
48 EntityID SolveSpaceSolver_EntityWrapper::id() const
49 {
50   return (EntityID)myEntity.h;
51 }
52
53 void SolveSpaceSolver_EntityWrapper::setGroup(const GroupID& theGroup)
54 {
55   myEntity.group = (Slvs_hGroup)theGroup;
56   std::list<EntityWrapperPtr>::iterator aSubsIt = mySubEntities.begin();
57   for (; aSubsIt != mySubEntities.end(); ++aSubsIt)
58     (*aSubsIt)->setGroup(theGroup);
59   std::list<ParameterWrapperPtr>::iterator aPIt = myParameters.begin();
60   for (; aPIt != myParameters.end(); ++aPIt)
61     (*aPIt)->setGroup(theGroup);
62 }
63
64 SketchSolver_EntityType SolveSpaceSolver_EntityWrapper::type() const
65 {
66   switch (myEntity.type) {
67   case SLVS_E_POINT_IN_3D:
68   case SLVS_E_POINT_IN_2D:    return ENTITY_POINT;
69   case SLVS_E_LINE_SEGMENT:   return ENTITY_LINE;
70   case SLVS_E_CIRCLE:         return ENTITY_CIRCLE;
71   case SLVS_E_ARC_OF_CIRCLE:  return ENTITY_ARC;
72   case SLVS_E_NORMAL_IN_3D:
73   case SLVS_E_NORMAL_IN_2D:   return ENTITY_NORMAL;
74   case SLVS_E_DISTANCE:       return ENTITY_SCALAR;
75   case SLVS_E_WORKPLANE:      return ENTITY_SKETCH;
76   default: break;
77   }
78   return ENTITY_UNKNOWN;
79 }
80
81 bool SolveSpaceSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
82 {
83   if (isBase(theFeature))
84     return true;
85
86   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
87   for (; anIt != mySubEntities.end(); ++anIt)
88     if ((*anIt)->isUsed(theFeature))
89       return true;
90   return false;
91 }
92
93 bool SolveSpaceSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
94 {
95   if (isBase(theAttribute))
96     return true;
97
98   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
99   for (; anIt != mySubEntities.end(); ++anIt)
100     if ((*anIt)->isUsed(theAttribute))
101       return true;
102   return false;
103 }
104
105 bool SolveSpaceSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
106 {
107   if (type() != theOther->type())
108     return false;
109
110   // Verify Equality of sub-entities
111   const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
112   if (mySubEntities.size() != anOtherSubs.size())
113     return false;
114   std::list<EntityWrapperPtr>::const_iterator aMySubsIt = mySubEntities.begin();
115   std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
116   for (; aMySubsIt != mySubEntities.end(); ++aMySubsIt, ++anOtherSubsIt)
117     if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
118       return false;
119
120   // Verify equality of parameters
121   const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
122   if (myParameters.size() != anOtherParams.size())
123     return false;
124   std::list<ParameterWrapperPtr>::const_iterator aMyIt = myParameters.begin();
125   std::list<ParameterWrapperPtr>::const_iterator anOtherIt = anOtherParams.begin();
126   for (; aMyIt != myParameters.end(); ++aMyIt, ++anOtherIt)
127     if (!(*aMyIt)->isEqual(*anOtherIt))
128       return false;
129   return true;
130 }
131
132 bool SolveSpaceSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
133 {
134   bool isUpdated = false;
135
136   std::list<EntityWrapperPtr> aMySubs = subEntities();
137   std::list<EntityWrapperPtr> anOtherSubs = theOther->subEntities();
138   std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
139   std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
140   for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
141        ++aMySubsIt, ++anOtherSubsIt)
142      isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
143
144   std::list<ParameterWrapperPtr> aMyParams = parameters();
145   std::list<ParameterWrapperPtr> anOtherParams = theOther->parameters();
146   std::list<ParameterWrapperPtr>::const_iterator aMyParIt = aMyParams.begin();
147   std::list<ParameterWrapperPtr>::const_iterator anOtherParIt = anOtherParams.begin();
148   for (; aMyParIt != aMyParams.end() && anOtherParIt != anOtherParams.end();
149       ++aMyParIt, ++anOtherParIt)
150     isUpdated = (*aMyParIt)->update(*anOtherParIt);
151   return isUpdated;
152 }