1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <SolveSpaceSolver_EntityWrapper.h>
22 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
23 const FeaturePtr theFeature, const Slvs_Entity& theEntity)
26 myBaseFeature = theFeature;
29 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
30 const AttributePtr theAttribute, const Slvs_Entity& theEntity)
33 myBaseAttribute = theAttribute;
36 SolveSpaceSolver_EntityWrapper::SolveSpaceSolver_EntityWrapper(
37 const FeaturePtr thePointFeature,
38 const AttributePtr thePointAttribute,
39 const Slvs_Entity& theEntity)
42 myBaseFeature = thePointFeature;
43 myBaseAttribute = thePointAttribute;
47 EntityID SolveSpaceSolver_EntityWrapper::id() const
49 return (EntityID)myEntity.h;
52 void SolveSpaceSolver_EntityWrapper::setGroup(const GroupID& theGroup)
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);
63 SketchSolver_EntityType SolveSpaceSolver_EntityWrapper::type() const
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;
77 return ENTITY_UNKNOWN;
80 bool SolveSpaceSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
82 if (isBase(theFeature))
85 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
86 for (; anIt != mySubEntities.end(); ++anIt)
87 if ((*anIt)->isUsed(theFeature))
92 bool SolveSpaceSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
94 if (isBase(theAttribute))
97 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
98 for (; anIt != mySubEntities.end(); ++anIt)
99 if ((*anIt)->isUsed(theAttribute))
104 bool SolveSpaceSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
106 if (type() != theOther->type())
109 // Verify Equality of sub-entities
110 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
111 if (mySubEntities.size() != anOtherSubs.size())
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))
119 // Verify equality of parameters
120 const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
121 if (myParameters.size() != anOtherParams.size())
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))
131 bool SolveSpaceSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
133 bool isUpdated = false;
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;
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);