- const std::set<AttributePtr>& aRefsList = aObj->data()->refsToMe();
- std::set<AttributePtr>::const_iterator aIt;
- for(aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- if(aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(aConstrFeature);
- if(aPnt.get() && aOrig->isEqual(aPnt)) {
- findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(), theList);
- findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(), theList);
+ std::set<FeaturePtr> aCoincidences = findCoincidentConstraints(aObj);
+ std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
+ for (; aCIt != aCoincidences.end(); ++aCIt) {
+ FeaturePtr aConstrFeature = *aCIt;
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(aConstrFeature);
+ if(aPnt.get() && aOrig->isEqual(aPnt)) {
+ findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(), theList);
+ findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(), theList);
+ }
+ }
+ }
+}
+
+std::set<FeaturePtr> findFeaturesCoincidentToPoint(const AttributePoint2DPtr& thePoint)
+{
+ std::set<FeaturePtr> aCoincidentFeatures;
+
+ FeaturePtr anOwner = ModelAPI_Feature::feature(thePoint->owner());
+ aCoincidentFeatures.insert(anOwner);
+
+ std::set<FeaturePtr> aCoincidences = findCoincidentConstraints(anOwner);
+ std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
+ for (; aCIt != aCoincidences.end(); ++aCIt) {
+ bool isPointUsedInCoincidence = false;
+ AttributeRefAttrPtr anOtherCoincidentAttr;
+ for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
+ AttributeRefAttrPtr aRefAttr = (*aCIt)->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
+ if (!aRefAttr)
+ continue;
+ if (!aRefAttr->isObject() && aRefAttr->attr() == thePoint)
+ isPointUsedInCoincidence = true;
+ else
+ anOtherCoincidentAttr = aRefAttr;
+ }
+
+ if (isPointUsedInCoincidence) {
+ ObjectPtr anObj;
+ if (anOtherCoincidentAttr->isObject())
+ anObj = anOtherCoincidentAttr->object();
+ else
+ anObj = anOtherCoincidentAttr->attr()->owner();
+ aCoincidentFeatures.insert(ModelAPI_Feature::feature(anObj));
+ }
+ }
+
+ return aCoincidentFeatures;
+}
+
+void resetAttribute(SketchPlugin_Feature* theFeature,
+ const std::string& theId)
+{
+ AttributePtr anAttr = theFeature->attribute(theId);
+ if(anAttr.get()) {
+ anAttr->reset();
+ }
+}
+
+void createConstraint(SketchPlugin_Feature* theFeature,
+ const std::string& theId,
+ const AttributePtr theAttr,
+ const ObjectPtr theObject,
+ const bool theIsCanBeTangent)
+{
+ AttributeRefAttrPtr aRefAttr = theFeature->refattr(theId);
+ if(aRefAttr.get() && aRefAttr->isInitialized()) {
+ FeaturePtr aConstraint;
+ if(!theIsCanBeTangent) {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ if(aRefAttr->isObject()) {
+ ObjectPtr anObject = aRefAttr->object();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if(aFeature->getKind() == SketchPlugin_Point::ID()) {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintTangent::ID());