1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PlaneGCSSolver_EntityWrapper.cpp
4 // Created: 14 Dec 2015
5 // Author: Artem ZHIDKOV
7 #include <PlaneGCSSolver_EntityWrapper.h>
8 #include <SketchPlugin_Point.h>
9 #include <SketchPlugin_Sketch.h>
11 PlaneGCSSolver_EntityWrapper::PlaneGCSSolver_EntityWrapper(
12 const FeaturePtr theFeature, const GCSCurvePtr theEntity)
13 : myEntity(theEntity),
16 myBaseFeature = theFeature;
18 std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(myEntity);
19 if (aLine) myType = ENTITY_LINE;
21 std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(myEntity);
22 if (anArc) myType = ENTITY_ARC;
24 std::shared_ptr<GCS::Circle> aCircle = std::dynamic_pointer_cast<GCS::Circle>(myEntity);
25 if (aCircle) myType = ENTITY_CIRCLE;
29 // empty entity, probably this is a SketchPlugin_Point or SketchPlugin_Sketch
30 if (theFeature->getKind() == SketchPlugin_Point::ID())
31 myType = ENTITY_POINT;
32 else if (theFeature->getKind() == SketchPlugin_Sketch::ID())
33 myType = ENTITY_SKETCH;
36 void PlaneGCSSolver_EntityWrapper::setGroup(const GroupID& theGroup)
39 std::list<EntityWrapperPtr>::iterator aSubsIt = mySubEntities.begin();
40 for (; aSubsIt != mySubEntities.end(); ++aSubsIt)
41 (*aSubsIt)->setGroup(theGroup);
42 std::list<ParameterWrapperPtr>::iterator aPIt = myParameters.begin();
43 for (; aPIt != myParameters.end(); ++aPIt)
44 (*aPIt)->setGroup(theGroup);
47 bool PlaneGCSSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
49 if (isBase(theFeature))
52 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
53 for (; anIt != mySubEntities.end(); ++anIt)
54 if ((*anIt)->isUsed(theFeature))
59 bool PlaneGCSSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
61 if (isBase(theAttribute))
64 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
65 for (; anIt != mySubEntities.end(); ++anIt)
66 if ((*anIt)->isUsed(theAttribute))
71 bool PlaneGCSSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
73 if (type() != theOther->type())
76 // Verify Equality of sub-entities
77 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
78 if (mySubEntities.size() != anOtherSubs.size())
80 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = mySubEntities.begin();
81 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
82 for (; aMySubsIt != mySubEntities.end(); ++aMySubsIt, ++anOtherSubsIt)
83 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
86 // Verify equality of parameters
87 const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
88 if (myParameters.size() != anOtherParams.size())
90 std::list<ParameterWrapperPtr>::const_iterator aMyIt = myParameters.begin();
91 std::list<ParameterWrapperPtr>::const_iterator anOtherIt = anOtherParams.begin();
92 for (; aMyIt != myParameters.end(); ++aMyIt, ++anOtherIt)
93 if (!(*aMyIt)->isEqual(*anOtherIt))
98 bool PlaneGCSSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
100 bool isUpdated = false;
102 std::list<EntityWrapperPtr> aMySubs = subEntities();
103 std::list<EntityWrapperPtr> anOtherSubs = theOther->subEntities();
104 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
105 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
106 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
107 ++aMySubsIt, ++anOtherSubsIt)
108 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
110 std::list<ParameterWrapperPtr> aMyParams = parameters();
111 std::list<ParameterWrapperPtr> anOtherParams = theOther->parameters();
112 std::list<ParameterWrapperPtr>::const_iterator aMyParIt = aMyParams.begin();
113 std::list<ParameterWrapperPtr>::const_iterator anOtherParIt = anOtherParams.begin();
114 for (; aMyParIt != aMyParams.end() && anOtherParIt != anOtherParams.end();
115 ++aMyParIt, ++anOtherParIt)
116 isUpdated = (*aMyParIt)->update(*anOtherParIt);