1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_ConstraintCoincidence.cpp
4 // Created: 08 May 2014
5 // Author: Artem ZHIDKOV
7 #include "SketchPlugin_ConstraintCoincidence.h"
9 #include <SketchPlugin_Point.h>
10 #include <SketchPlugin_Line.h>
11 #include <SketchPlugin_Arc.h>
12 #include <SketchPlugin_Circle.h>
14 #include <ModelGeomAlgo_Point2D.h>
15 #include <GeomDataAPI_Point2D.h>
17 #include <SketcherPrs_Factory.h>
19 SketchPlugin_ConstraintCoincidence::SketchPlugin_ConstraintCoincidence()
23 void SketchPlugin_ConstraintCoincidence::initAttributes()
25 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
26 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
29 void SketchPlugin_ConstraintCoincidence::execute()
33 AISObjectPtr SketchPlugin_ConstraintCoincidence::getAISObject(AISObjectPtr thePrevious)
38 AISObjectPtr anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane(),
43 FeaturePtr SketchPlugin_ConstraintCoincidence::findCoincidenceFeature(const FeaturePtr& theFeature1,
44 const FeaturePtr& theFeature2)
46 FeaturePtr aResultFeature;
48 std::list<AttributePtr> anAttrList;
49 if (theFeature1->getKind() == SketchPlugin_Circle::ID() ||
50 theFeature2->getKind() == SketchPlugin_Circle::ID())
51 return aResultFeature;
53 if (theFeature2->getKind() == SketchPlugin_Line::ID()) {
54 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Line::START_ID()));
55 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Line::END_ID()));
56 } else if (theFeature2->getKind() == SketchPlugin_Arc::ID()) {
57 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Arc::START_ID()));
58 anAttrList.push_back(theFeature2->attribute(SketchPlugin_Arc::END_ID()));
61 const std::set<AttributePtr>& aRefsList = theFeature1->data()->refsToMe();
62 std::set<AttributePtr>::const_iterator aRefIt = aRefsList.begin();
63 for (; aRefIt != aRefsList.end() && !aResultFeature.get(); ++aRefIt) {
64 FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
65 if (aConstrFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
67 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
68 AttributePtr anAttr = aRefAttr->attr();
69 if (anAttr->id() == SketchPlugin_Arc::CENTER_ID())
72 anAttr = aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_A());
73 if (anAttr == *aRefIt)
74 anAttr = aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B());
76 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
79 anAttr = aRefAttr->attr();
80 for (std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
81 anIt != anAttrList.end() && !aResultFeature.get(); ++anIt)
83 aResultFeature = aConstrFeature;
85 return aResultFeature;
88 AttributePoint2DPtr SketchPlugin_ConstraintCoincidence::getPoint(const FeaturePtr& theFeature)
90 AttributePoint2DPtr aPoint = ModelGeomAlgo_Point2D::getPointOfRefAttr(theFeature.get(),
91 SketchPlugin_Constraint::ENTITY_A(),
92 SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
94 aPoint = ModelGeomAlgo_Point2D::getPointOfRefAttr(theFeature.get(),
95 SketchPlugin_Constraint::ENTITY_B(),
96 SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());