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_IntersectionPoint.h>
10 #include <SketchPlugin_Sketch.h>
12 PlaneGCSSolver_EntityWrapper::PlaneGCSSolver_EntityWrapper(
13 const FeaturePtr theFeature, const GCSCurvePtr theEntity)
14 : myEntity(theEntity),
17 myBaseFeature = theFeature;
19 std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(myEntity);
20 if (aLine) myType = ENTITY_LINE;
22 std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(myEntity);
23 if (anArc) myType = ENTITY_ARC;
25 std::shared_ptr<GCS::Circle> aCircle = std::dynamic_pointer_cast<GCS::Circle>(myEntity);
26 if (aCircle) myType = ENTITY_CIRCLE;
30 // empty entity, probably this is a SketchPlugin_Point or SketchPlugin_Sketch
31 if (theFeature->getKind() == SketchPlugin_Point::ID() ||
32 theFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
33 myType = ENTITY_POINT;
34 else if (theFeature->getKind() == SketchPlugin_Sketch::ID())
35 myType = ENTITY_SKETCH;
38 void PlaneGCSSolver_EntityWrapper::setGroup(const GroupID& theGroup)
41 std::list<EntityWrapperPtr>::iterator aSubsIt = mySubEntities.begin();
42 for (; aSubsIt != mySubEntities.end(); ++aSubsIt)
43 (*aSubsIt)->setGroup(theGroup);
44 std::list<ParameterWrapperPtr>::iterator aPIt = myParameters.begin();
45 for (; aPIt != myParameters.end(); ++aPIt)
46 (*aPIt)->setGroup(theGroup);
49 bool PlaneGCSSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
51 if (isBase(theFeature))
54 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
55 for (; anIt != mySubEntities.end(); ++anIt)
56 if ((*anIt)->isUsed(theFeature))
61 bool PlaneGCSSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
63 if (isBase(theAttribute))
66 std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
67 for (; anIt != mySubEntities.end(); ++anIt)
68 if ((*anIt)->isUsed(theAttribute))
73 bool PlaneGCSSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
75 if (type() != theOther->type())
78 // Verify Equality of sub-entities
79 const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
80 if (mySubEntities.size() != anOtherSubs.size())
82 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = mySubEntities.begin();
83 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
84 for (; aMySubsIt != mySubEntities.end(); ++aMySubsIt, ++anOtherSubsIt)
85 if (!(*aMySubsIt)->isEqual(*anOtherSubsIt))
88 // Verify equality of parameters
89 const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
90 if (myParameters.size() != anOtherParams.size())
92 std::list<ParameterWrapperPtr>::const_iterator aMyIt = myParameters.begin();
93 std::list<ParameterWrapperPtr>::const_iterator anOtherIt = anOtherParams.begin();
94 for (; aMyIt != myParameters.end(); ++aMyIt, ++anOtherIt)
95 if (!(*aMyIt)->isEqual(*anOtherIt))
100 bool PlaneGCSSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
102 bool isUpdated = false;
104 std::list<EntityWrapperPtr> aMySubs = subEntities();
105 std::list<EntityWrapperPtr> anOtherSubs = theOther->subEntities();
106 std::list<EntityWrapperPtr>::const_iterator aMySubsIt = aMySubs.begin();
107 std::list<EntityWrapperPtr>::const_iterator anOtherSubsIt = anOtherSubs.begin();
108 for (; aMySubsIt != aMySubs.end() && anOtherSubsIt != anOtherSubs.end();
109 ++aMySubsIt, ++anOtherSubsIt)
110 isUpdated = (*aMySubsIt)->update(*anOtherSubsIt) || isUpdated;
112 std::list<ParameterWrapperPtr> aMyParams = parameters();
113 std::list<ParameterWrapperPtr> anOtherParams = theOther->parameters();
114 std::list<ParameterWrapperPtr>::const_iterator aMyParIt = aMyParams.begin();
115 std::list<ParameterWrapperPtr>::const_iterator anOtherParIt = anOtherParams.begin();
116 for (; aMyParIt != aMyParams.end() && anOtherParIt != anOtherParams.end();
117 ++aMyParIt, ++anOtherParIt)
118 isUpdated = (*aMyParIt)->update(*anOtherParIt);