]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Tools.cpp
Salome HOME
Fixed validators for Boolean and Intersection
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_Tools.cpp
4 // Created:     07 July 2015
5 // Author:      Sergey POKHODENKO
6
7 #include "SketchPlugin_Tools.h"
8
9 #include <GeomDataAPI_Point.h>
10 #include <GeomDataAPI_Point2D.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <SketcherPrs_Tools.h>
13 #include <SketchPlugin_ConstraintCoincidence.h>
14 #include <SketchPlugin_SketchEntity.h>
15
16 namespace SketchPlugin_Tools {
17
18 void clearExpressions(AttributeDoublePtr theAttribute)
19 {
20   theAttribute->setText(std::string());
21 }
22
23 void clearExpressions(AttributePointPtr theAttribute)
24 {
25   theAttribute->setText(std::string(), std::string(), std::string());
26 }
27
28 void clearExpressions(AttributePoint2DPtr theAttribute)
29 {
30   theAttribute->setText(std::string(), std::string());
31 }
32
33 void clearExpressions(AttributePtr theAttribute)
34 {
35   // Double
36   AttributeDoublePtr anAttributeDouble = 
37       std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
38   if (anAttributeDouble.get())
39     clearExpressions(anAttributeDouble);
40   // Point
41   AttributePointPtr anAttributePoint = 
42       std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
43   if (anAttributePoint.get())
44     clearExpressions(anAttributePoint);
45   // Point2D
46   AttributePoint2DPtr anAttributePoint2D = 
47       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
48   if (anAttributePoint2D.get())
49     clearExpressions(anAttributePoint2D);
50 }
51
52 void clearExpressions(FeaturePtr theFeature)
53 {
54   if (!theFeature.get())
55     return;
56
57   std::list<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());  
58   std::list<AttributePtr>::iterator anAttributeIt = anAttributes.begin();
59   for (; anAttributeIt != anAttributes.end(); ++anAttributeIt) {
60     clearExpressions(*anAttributeIt);
61   }
62 }
63
64 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(const FeaturePtr theStartCoin)
65 {
66   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), 
67                                                                     SketchPlugin_Constraint::ENTITY_A());
68   if (aPnt.get() == NULL)
69     aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), SketchPlugin_Constraint::ENTITY_B());
70   return aPnt;
71 }
72
73 void findCoincidences(const FeaturePtr theStartCoin,
74                       const std::string& theAttr,
75                       std::set<FeaturePtr>& theList)
76 {
77   AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
78   if(!aPnt) {
79     return;
80   }
81   FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object());
82   if(theList.find(aObj) == theList.end()) {
83     std::shared_ptr<GeomAPI_Pnt2d> aOrig = getCoincidencePoint(theStartCoin);
84     if(aOrig.get() == NULL) {
85       return;
86     }
87     theList.insert(aObj);
88     const std::set<AttributePtr>& aRefsList = aObj->data()->refsToMe();
89     std::set<AttributePtr>::const_iterator aIt;
90     for(aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
91       std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
92       FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
93       if(aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
94         std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(aConstrFeature);
95         if(aPnt.get() && aOrig->isEqual(aPnt)) {
96           findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(), theList);
97           findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(), theList);
98         }
99       }
100     }
101   }
102 }
103
104 } // namespace SketchPlugin_Tools