1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <SolveSpaceSolver_EntityWrapper.h>
23 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
24 const FeaturePtr theFeature, const Slvs_Entity& theEntity)
27 myBaseFeature = theFeature;
30 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
31 const AttributePtr theAttribute, const Slvs_Entity& theEntity)
34 myBaseAttribute = theAttribute;
37 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
38 const FeaturePtr thePointFeature,
39 const AttributePtr thePointAttribute,
40 const Slvs_Entity& theEntity)
43 myBaseFeature = thePointFeature;
44 myBaseAttribute = thePointAttribute;
48 EntityID SolveSpaceSolver_EntityWrapper::id() const
50 return (EntityID)myEntity.h;
53 void SolveSpaceSolver_EntityWrapper::setGroup(const GroupID& theGroup)
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);
64 SketchSolver_EntityType SolveSpaceSolver_EntityWrapper::type() const
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;
78 return ENTITY_UNKNOWN;
81 bool SolveSpaceSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
83 if (isBase(theFeature))
86 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
87 for (; anIt != mySubEntities.end(); ++anIt)
88 if ((*anIt)->isUsed(theFeature))
93 bool SolveSpaceSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
95 if (isBase(theAttribute))
98 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
99 for (; anIt != mySubEntities.end(); ++anIt)
100 if ((*anIt)->isUsed(theAttribute))
105 bool SolveSpaceSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
107 if (type() != theOther->type())
110 // Verify Equality of sub-entities
111 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
112 if (mySubEntities.size() != anOtherSubs.size())
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))
120 // Verify equality of parameters
121 const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
122 if (myParameters.size() != anOtherParams.size())
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))
132 bool SolveSpaceSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
134 bool isUpdated = false;
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;
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);