1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_Tools.cpp
4 // Created: 07 July 2015
5 // Author: Sergey POKHODENKO
7 #include "SketchPlugin_Tools.h"
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>
15 namespace SketchPlugin_Tools {
17 void clearExpressions(AttributeDoublePtr theAttribute)
19 theAttribute->setText(std::string());
22 void clearExpressions(AttributePointPtr theAttribute)
24 theAttribute->setText(std::string(), std::string(), std::string());
27 void clearExpressions(AttributePoint2DPtr theAttribute)
29 theAttribute->setText(std::string(), std::string());
32 void clearExpressions(AttributePtr theAttribute)
35 AttributeDoublePtr anAttributeDouble =
36 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
37 if (anAttributeDouble.get())
38 clearExpressions(anAttributeDouble);
40 AttributePointPtr anAttributePoint =
41 std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
42 if (anAttributePoint.get())
43 clearExpressions(anAttributePoint);
45 AttributePoint2DPtr anAttributePoint2D =
46 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
47 if (anAttributePoint2D.get())
48 clearExpressions(anAttributePoint2D);
51 void clearExpressions(FeaturePtr theFeature)
53 if (!theFeature.get())
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);
63 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(FeaturePtr theStartCoin)
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());
72 void findCoincidences(FeaturePtr theStartCoin,
74 std::set<FeaturePtr>& theList)
76 AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
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)
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);
100 } // namespace SketchPlugin_Tools