Salome HOME
crash fix: mirror (line, axis of sketch), select with rectangle, delete
[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_IntersectionPoint.h>
10 #include <SketchPlugin_Sketch.h>
11
12 PlaneGCSSolver_EntityWrapper::PlaneGCSSolver_EntityWrapper(
13     const FeaturePtr theFeature, const GCSCurvePtr theEntity)
14   : myEntity(theEntity),
15     myID(EID_UNKNOWN)
16 {
17   myBaseFeature = theFeature;
18
19   std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(myEntity);
20   if (aLine) myType = ENTITY_LINE;
21   else {
22     std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(myEntity);
23     if (anArc) myType = ENTITY_ARC;
24     else {
25       std::shared_ptr<GCS::Circle> aCircle = std::dynamic_pointer_cast<GCS::Circle>(myEntity);
26       if (aCircle) myType = ENTITY_CIRCLE;
27     }
28   }
29
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;
36 }
37
38 void PlaneGCSSolver_EntityWrapper::setGroup(const GroupID& theGroup)
39 {
40   myGroup = 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);
47 }
48
49 bool PlaneGCSSolver_EntityWrapper::isUsed(FeaturePtr theFeature) const
50 {
51   if (isBase(theFeature))
52     return true;
53
54   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
55   for (; anIt != mySubEntities.end(); ++anIt)
56     if ((*anIt)->isUsed(theFeature))
57       return true;
58   return false;
59 }
60
61 bool PlaneGCSSolver_EntityWrapper::isUsed(AttributePtr theAttribute) const
62 {
63   if (isBase(theAttribute))
64     return true;
65
66   std::list<EntityWrapperPtr>::const_iterator anIt = mySubEntities.begin();
67   for (; anIt != mySubEntities.end(); ++anIt)
68     if ((*anIt)->isUsed(theAttribute))
69       return true;
70   return false;
71 }
72
73 bool PlaneGCSSolver_EntityWrapper::isEqual(const EntityWrapperPtr& theOther)
74 {
75   if (type() != theOther->type())
76     return false;
77
78   // Verify Equality of sub-entities
79   const std::list<EntityWrapperPtr>& anOtherSubs = theOther->subEntities();
80   if (mySubEntities.size() != anOtherSubs.size())
81     return false;
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))
86       return false;
87
88   // Verify equality of parameters
89   const std::list<ParameterWrapperPtr>& anOtherParams = theOther->parameters();
90   if (myParameters.size() != anOtherParams.size())
91     return false;
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))
96       return false;
97   return true;
98 }
99
100 bool PlaneGCSSolver_EntityWrapper::update(const EntityWrapperPtr& theOther)
101 {
102   bool isUpdated = false;
103
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;
111
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);
119   return isUpdated;
120 }