+bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribute,
+ const std::set<AttributePoint2DPtr>& theFurtherCoincidences)
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+ return false;
+
+ AttributePoint2DPtr aRefPointAttr = SketchPlugin_ConstraintCoincidence::getPoint(aFeature);
+ if (!aRefPointAttr.get())
+ return false;
+ std::shared_ptr<GeomAPI_Pnt2d> aRefPnt2d = aRefPointAttr->pnt();
+
+ std::set<AttributePoint2DPtr>::const_iterator anIt = theFurtherCoincidences.begin(),
+ aLast = theFurtherCoincidences.end();
+ bool aFoundPoint = false;
+ for (; anIt != aLast && !aFoundPoint; anIt++) {
+ AttributePoint2DPtr aPointAttribute = (*anIt);
+ std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
+ if (aPoint2d->isEqual(aRefPnt2d)) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ theAttribute);
+ if (aRefAttr.get()) {
+ aRefAttr->setAttr(aPointAttribute);
+ aFoundPoint = true;
+ }
+ }
+ }
+ return aFoundPoint;
+}
+
+bool SketchPlugin_Trim::replaceCoincidenceAttribute(const AttributePtr& theCoincidenceAttribute,
+ const std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
+{
+ FeaturePtr aCoincidenceFeature = ModelAPI_Feature::feature(theCoincidenceAttribute->owner());
+ if (aCoincidenceFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+ return false;
+
+ AttributeRefAttrPtr aCAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aCoincidenceFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ AttributeRefAttrPtr aCAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aCoincidenceFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ AttributePtr aCAttrRefA = aCAttrA->attr();
+ AttributePtr aCAttrRefB = aCAttrB->attr();
+
+ bool isProcessed = false;
+ for (std::set<std::pair<AttributePtr, AttributePtr>>::const_iterator
+ anIt = theModifiedAttributes.begin(); anIt != theModifiedAttributes.end(); anIt++) {
+ AttributePtr anAttributeBefore = anIt->first;
+ if (anAttributeBefore == aCAttrRefA) {
+ aCAttrA->setAttr(anIt->second);
+ isProcessed = true;
+ }
+ if (anAttributeBefore == aCAttrRefB) {
+ aCAttrB->setAttr(anIt->second);
+ isProcessed = true;
+ }
+ }
+ return isProcessed;
+}
+