Salome HOME
Fix compilation on Linux
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_EntityWrapper.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    PlaneGCSSolver_EntityWrapper.cpp
4 // Created: 14 Dec 2015
5 // Author:  Artem ZHIDKOV
6
7 #include <PlaneGCSSolver_EntityWrapper.h>
8 #include <SketchPlugin_Point.h>
9 #include <SketchPlugin_Sketch.h>
10
11 PlaneGCSSolver_EntityWrapper::PlaneGCSSolver_EntityWrapper(
12     const FeaturePtr theFeature, const GCSCurvePtr theEntity)
13   : myEntity(theEntity),
14     myID(EID_UNKNOWN)
15 {
16   myBaseFeature = theFeature;
17
18   std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(myEntity);
19   if (aLine) myType = ENTITY_LINE;
20   else {
21     std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(myEntity);
22     if (anArc) myType = ENTITY_ARC;
23     else {
24       std::shared_ptr<GCS::Circle> aCircle = std::dynamic_pointer_cast<GCS::Circle>(myEntity);
25       if (aCircle) myType = ENTITY_CIRCLE;
26     }
27   }
28
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;
34 }
35
36 void PlaneGCSSolver_EntityWrapper::setGroup(const GroupID& theGroup)
37 {
38   myGroup = 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);
45 }
46
47 bool PlaneGCSSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
48 {
49   if (isBase(theFeature))
50     return true;
51
52   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
53   for (; anIt != mySubEntities.end(); ++anIt)
54     if ((*anIt)->isUsed(theFeature))
55       return true;
56   return false;
57 }
58
59 bool PlaneGCSSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
60 {
61   if (isBase(theAttribute))
62     return true;
63
64   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
65   for (; anIt != mySubEntities.end(); ++anIt)
66     if ((*anIt)->isUsed(theAttribute))
67       return true;
68   return false;
69 }
70
71 bool PlaneGCSSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
72 {
73   if (type() != theOther->type())
74     return false;
75
76   // Verify Equality of sub-entities
77   const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
78   if (mySubEntities.size() != anOtherSubs.size())
79     return false;
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))
84       return false;
85
86   // Verify equality of parameters
87   const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
88   if (myParameters.size() != anOtherParams.size())
89     return false;
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))
94       return false;
95   return true;
96 }
97
98 bool PlaneGCSSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
99 {
100   bool isUpdated = false;
101
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;
109
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);
117   return isUpdated;
118 }