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 <SketcherPrs_Tools.h>
13 #include <SketchPlugin_ConstraintCoincidence.h>
14 #include <SketchPlugin_SketchEntity.h>
16 namespace SketchPlugin_Tools {
18 void clearExpressions(AttributeDoublePtr theAttribute)
20 theAttribute->setText(std::string());
23 void clearExpressions(AttributePointPtr theAttribute)
25 theAttribute->setText(std::string(), std::string(), std::string());
28 void clearExpressions(AttributePoint2DPtr theAttribute)
30 theAttribute->setText(std::string(), std::string());
33 void clearExpressions(AttributePtr theAttribute)
36 AttributeDoublePtr anAttributeDouble =
37 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
38 if (anAttributeDouble.get())
39 clearExpressions(anAttributeDouble);
41 AttributePointPtr anAttributePoint =
42 std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
43 if (anAttributePoint.get())
44 clearExpressions(anAttributePoint);
46 AttributePoint2DPtr anAttributePoint2D =
47 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
48 if (anAttributePoint2D.get())
49 clearExpressions(anAttributePoint2D);
52 void clearExpressions(FeaturePtr theFeature)
54 if (!theFeature.get())
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);
64 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(const FeaturePtr theStartCoin)
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());
73 void findCoincidences(const FeaturePtr theStartCoin,
74 const std::string& theAttr,
75 std::set<FeaturePtr>& theList)
77 AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr);
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) {
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);
104 } // namespace SketchPlugin_Tools