Salome HOME
Fillet creation by point
[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 <SketchPlugin_ConstraintCoincidence.h>
13 #include <SketcherPrs_Tools.h>
14
15 namespace SketchPlugin_Tools {
16
17 void clearExpressions(AttributeDoublePtr theAttribute)
18 {
19   theAttribute->setText(std::string());
20 }
21
22 void clearExpressions(AttributePointPtr theAttribute)
23 {
24   theAttribute->setText(std::string(), std::string(), std::string());
25 }
26
27 void clearExpressions(AttributePoint2DPtr theAttribute)
28 {
29   theAttribute->setText(std::string(), std::string());
30 }
31
32 void clearExpressions(AttributePtr theAttribute)
33 {
34   // Double
35   AttributeDoublePtr anAttributeDouble = 
36       std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
37   if (anAttributeDouble.get())
38     clearExpressions(anAttributeDouble);
39   // Point
40   AttributePointPtr anAttributePoint = 
41       std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
42   if (anAttributePoint.get())
43     clearExpressions(anAttributePoint);
44   // Point2D
45   AttributePoint2DPtr anAttributePoint2D = 
46       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
47   if (anAttributePoint2D.get())
48     clearExpressions(anAttributePoint2D);
49 }
50
51 void clearExpressions(FeaturePtr theFeature)
52 {
53   if (!theFeature.get())
54     return;
55
56   std::list<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());  
57   std::list<AttributePtr>::iterator anAttributeIt = anAttributes.begin();
58   for (; anAttributeIt != anAttributes.end(); ++anAttributeIt) {
59     clearExpressions(*anAttributeIt);
60   }
61 }
62
63 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(FeaturePtr theStartCoin)
64 {
65   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), 
66                                                                     SketchPlugin_Constraint::ENTITY_A());
67   if (aPnt.get() == NULL)
68     aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), SketchPlugin_Constraint::ENTITY_B());
69   return aPnt;
70 }
71
72 void findCoincidences(FeaturePtr theStartCoin,
73                       std::string theAttr,
74                       std::set<FeaturePtr>& theList)
75 {
76   AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
77   if (!aPnt) return;
78   FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object());
79   if (theList.find(aObj) == theList.end()) {
80     std::shared_ptr<GeomAPI_Pnt2d> aOrig = getCoincidencePoint(theStartCoin);
81     if (aOrig.get() == NULL)
82       return;
83     theList.insert(aObj);
84     const std::set<AttributePtr>& aRefsList = aObj->data()->refsToMe();
85     std::set<AttributePtr>::const_iterator aIt;
86     for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
87       std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
88       FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
89       if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { 
90         std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(aConstrFeature);
91         if (aPnt.get() && aOrig->isEqual(aPnt)) {
92           findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(), theList);
93           findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(), theList);
94         }
95       }
96     }
97   }
98 }
99
100 } // namespace SketchPlugin_Tools