1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_Fillet.cpp
4 // Created: 19 Mar 2015
5 // Author: Artem ZHIDKOV
7 #include "SketchPlugin_Fillet.h"
9 #include "SketchPlugin_Arc.h"
10 #include "SketchPlugin_Line.h"
11 #include "SketchPlugin_Point.h"
12 #include "SketchPlugin_Sketch.h"
13 #include "SketchPlugin_ConstraintEqual.h"
14 #include "SketchPlugin_ConstraintCoincidence.h"
15 #include "SketchPlugin_ConstraintLength.h"
16 #include "SketchPlugin_ConstraintMiddle.h"
17 #include "SketchPlugin_ConstraintTangent.h"
18 #include "SketchPlugin_ConstraintRadius.h"
19 #include "SketchPlugin_Tools.h"
21 #include <ModelAPI_AttributeRefAttr.h>
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Events.h>
24 #include <ModelAPI_Session.h>
25 #include <ModelAPI_Tools.h>
26 #include <ModelAPI_Validator.h>
28 #include <GeomAlgoAPI_Circ2dBuilder.h>
29 #include <GeomAlgoAPI_EdgeBuilder.h>
31 #include <GeomAPI_Circ2d.h>
32 #include <GeomAPI_Dir2d.h>
33 #include <GeomAPI_Lin2d.h>
34 #include <GeomAPI_Pnt2d.h>
35 #include <GeomAPI_XY.h>
37 #include <GeomDataAPI_Point2D.h>
39 #include <Events_Loop.h>
43 const double tolerance = 1.e-7;
44 const double paramTolerance = 1.e-4;
45 const double PI = 3.141592653589793238463;
47 /// \brief Attract specified point on theNewArc to the attribute of theFeature
48 static void recalculateAttributes(FeaturePtr theNewArc, const std::string& theNewArcAttribute,
49 FeaturePtr theFeature, const std::string& theFeatureAttribute);
52 /// \brief Calculate radius of a fillet.
53 /// It should not be greater than 1/3 of shortest edge length.
54 static double calculateFilletRadius(FeaturePtr theFilletFeatures[2]);
56 /// \brief Calculates center of fillet arc and coordinates of tangency points
57 static void calculateFilletCenter(FeaturePtr theFilletFeatures[2],
58 double theFilletRadius,
59 const std::shared_ptr<GeomAPI_Ax3>& theSketchPlane,
60 std::shared_ptr<GeomAPI_XY>& theCenter,
61 std::shared_ptr<GeomAPI_XY>& theTangentA,
62 std::shared_ptr<GeomAPI_XY>& theTangentB);
64 /// Get coincide edges for fillet
65 static std::set<FeaturePtr> getCoincides(const FeaturePtr& theConstraintCoincidence);
67 static std::set<FeaturePtr> findFeaturesToRemove(const FeaturePtr theFeature,
68 const AttributePtr theAttribute);
70 SketchPlugin_Fillet::SketchPlugin_Fillet()
71 : myFilletCreated(false)
75 void SketchPlugin_Fillet::initAttributes()
77 data()->addAttribute(FILLET_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
80 void SketchPlugin_Fillet::execute()
82 // Wait all constraints being created, then send update events
83 static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
84 bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
86 Events_Loop::loop()->setFlushed(anUpdateEvent, false);
88 // set flag here to avoid building Fillet presentation if "Redisplay" event appears
89 myFilletCreated = true;
91 // Calculate Fillet parameters if does not yet
92 if (!myBaseFeatures[0] || !myBaseFeatures[1])
93 calculateFilletParameters();
95 // Create arc feature.
96 FeaturePtr aFilletArc = sketch()->addFeature(SketchPlugin_Arc::ID());
98 // Set arc attributes.
99 bool aWasBlocked = aFilletArc->data()->blockSendAttributeUpdated(true);
100 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
101 aFilletArc->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenterXY->x(),
103 std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
104 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
105 aFilletArc->attribute(SketchPlugin_Arc::START_ID()));
106 std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
107 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
108 aFilletArc->attribute(SketchPlugin_Arc::END_ID()));
109 if(aStartPoint->isInitialized() && aEndPoint->isInitialized()
110 && (aStartPoint->pnt()->xy()->distance(myTangentXY1) > tolerance
111 || aEndPoint->pnt()->xy()->distance(myTangentXY2) > tolerance)) {
112 std::dynamic_pointer_cast<SketchPlugin_Arc>(aFilletArc)->setReversed(false);
114 aStartPoint->setValue(myTangentXY1->x(), myTangentXY1->y());
115 aEndPoint->setValue(myTangentXY2->x(), myTangentXY2->y());
116 aFilletArc->data()->blockSendAttributeUpdated(aWasBlocked);
117 aFilletArc->execute();
119 // Delete features with refs to points of edges.
120 std::shared_ptr<GeomDataAPI_Point2D> aStartPoint1;
121 int aFeatInd1 = myIsReversed ? 1 : 0;
122 int anAttrInd1 = (myIsReversed ? 2 : 0) + (myIsNotInversed[aFeatInd1] ? 0 : 1);
123 aStartPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
124 myBaseFeatures[aFeatInd1]->attribute(myFeatAttributes[anAttrInd1]));
125 std::set<FeaturePtr> aFeaturesToBeRemoved1 =
126 findFeaturesToRemove(myBaseFeatures[aFeatInd1], aStartPoint1);
128 std::shared_ptr<GeomDataAPI_Point2D> aStartPoint2;
129 int aFeatInd2 = myIsReversed ? 0 : 1;
130 int anAttrInd2 = (myIsReversed ? 0 : 2) + (myIsNotInversed[aFeatInd2] ? 0 : 1);
131 aStartPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
132 myBaseFeatures[aFeatInd2]->attribute(myFeatAttributes[anAttrInd2]));
133 std::set<FeaturePtr> aFeaturesToBeRemoved2 =
134 findFeaturesToRemove(myBaseFeatures[aFeatInd2], aStartPoint2);
136 aFeaturesToBeRemoved1.insert(aFeaturesToBeRemoved2.begin(), aFeaturesToBeRemoved2.end());
137 ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved1);
138 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
140 // Update fillet edges.
141 recalculateAttributes(aFilletArc, SketchPlugin_Arc::START_ID(),
142 myBaseFeatures[aFeatInd1], myFeatAttributes[anAttrInd1]);
143 recalculateAttributes(aFilletArc, SketchPlugin_Arc::END_ID(),
144 myBaseFeatures[aFeatInd2], myFeatAttributes[anAttrInd2]);
146 // Create coincidence features.
147 FeaturePtr aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
148 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
149 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
150 aRefAttr->setAttr(aFilletArc->attribute(SketchPlugin_Arc::START_ID()));
151 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
152 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
153 aRefAttr->setAttr(myBaseFeatures[aFeatInd1]->attribute(myFeatAttributes[anAttrInd1]));
154 aConstraint->execute();
155 ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
156 aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
157 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
158 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
159 aRefAttr->setAttr(aFilletArc->attribute(SketchPlugin_Arc::END_ID()));
160 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
161 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
162 aRefAttr->setAttr(myBaseFeatures[aFeatInd2]->attribute(myFeatAttributes[anAttrInd2]));
163 aConstraint->execute();
164 ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
166 // Create tangent features.
167 for (int i = 0; i < 2; i++) {
168 aConstraint = sketch()->addFeature(SketchPlugin_ConstraintTangent::ID());
169 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
170 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
171 aRefAttr->setObject(aFilletArc->lastResult());
172 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
173 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
174 bool isArc = myBaseFeatures[i]->getKind() == SketchPlugin_Arc::ID();
175 aRefAttr->setObject(isArc ? myBaseFeatures[i]->lastResult() :
176 myBaseFeatures[i]->firstResult());
177 aConstraint->execute();
178 ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
181 // Send events to update the sub-features by the solver.
182 if(isUpdateFlushed) {
183 Events_Loop::loop()->setFlushed(anUpdateEvent, true);
187 AISObjectPtr SketchPlugin_Fillet::getAISObject(AISObjectPtr thePrevious)
189 if(myFilletCreated) {
190 return AISObjectPtr();
193 SketchPlugin_Sketch* aSketch = sketch();
195 return AISObjectPtr();
198 if (!calculateFilletParameters())
199 return AISObjectPtr();
201 // Create arc for presentation.
202 std::shared_ptr<GeomAPI_Pnt> aCenterPnt(aSketch->to3D(myCenterXY->x(), myCenterXY->y()));
203 std::shared_ptr<GeomAPI_Pnt> aTangentPnt1(aSketch->to3D(myTangentXY1->x(),
205 std::shared_ptr<GeomAPI_Pnt> aTangentPnt2(aSketch->to3D(myTangentXY2->x(),
207 std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
208 aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
209 std::shared_ptr<GeomAPI_Shape> anArcShape =
210 GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenterPnt, aTangentPnt1, aTangentPnt2, aNDir->dir());
212 AISObjectPtr anAISObject = thePrevious;
213 if(!anAISObject.get()) {
214 anAISObject = AISObjectPtr(new GeomAPI_AISObject);
216 anAISObject->createShape(anArcShape);
220 bool SketchPlugin_Fillet::calculateFilletParameters()
223 AttributeRefAttrPtr aPointRefAttr = refattr(FILLET_POINT_ID());
224 if (!aPointRefAttr->isInitialized() || aPointRefAttr->isObject())
226 std::shared_ptr<GeomDataAPI_Point2D> aFilletPoint2D =
227 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointRefAttr->attr());
228 if (!aFilletPoint2D.get())
231 if (!findFeaturesContainingFilletPoint(aFilletPoint2D)) {
232 setError("Error: Selected point does not have two suitable edges for fillet.");
236 std::shared_ptr<GeomAPI_Pnt2d> aFilletPnt2d = aFilletPoint2D->pnt();
237 double aRadius = calculateFilletRadius(myBaseFeatures);
239 // Calculate arc attributes.
240 static const int aNbFeatures = 2;
241 // First pair of points relate to first feature, second pair - to second.
242 std::shared_ptr<GeomAPI_Pnt2d> aStartEndPnt[aNbFeatures * 2];
243 for (int i = 0; i < aNbFeatures; i++) {
244 std::string aStartAttr, aEndAttr;
245 if (myBaseFeatures[i]->getKind() == SketchPlugin_Line::ID()) {
246 aStartAttr = SketchPlugin_Line::START_ID();
247 aEndAttr = SketchPlugin_Line::END_ID();
248 } else if (myBaseFeatures[i]->getKind() == SketchPlugin_Arc::ID()) {
249 aStartAttr = SketchPlugin_Arc::START_ID();
250 aEndAttr = SketchPlugin_Arc::END_ID();
251 } else { // Wrong argument.
252 setError("Error: One of the points has wrong coincide feature");
255 myFeatAttributes[2*i] = aStartAttr;
256 aStartEndPnt[2*i] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
257 myBaseFeatures[i]->attribute(aStartAttr))->pnt();
258 myFeatAttributes[2*i+1] = aEndAttr;
259 aStartEndPnt[2*i+1] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
260 myBaseFeatures[i]->attribute(aEndAttr))->pnt();
262 for (int aFeatInd = 0; aFeatInd < aNbFeatures; aFeatInd++) {
263 for (int j = 0; j < 2; j++) // loop on start-end of each feature
264 if (aStartEndPnt[aFeatInd * aNbFeatures + j]->distance(aFilletPnt2d) < 1.e-10) {
265 myIsNotInversed[aFeatInd] = (j==0);
270 std::shared_ptr<GeomAPI_Ax3> aSketchPlane = SketchPlugin_Sketch::plane(sketch());
271 calculateFilletCenter(myBaseFeatures, aRadius, aSketchPlane,
272 myCenterXY, myTangentXY1, myTangentXY2);
274 // Tangent directions of the features in coincident point.
275 std::shared_ptr<GeomAPI_Dir2d> aTangentDir[aNbFeatures];
276 for (int i = 0; i < aNbFeatures; i++) {
277 std::shared_ptr<GeomAPI_XY> aDir;
278 if (myBaseFeatures[i]->getKind() == SketchPlugin_Line::ID()) {
279 aDir = aStartEndPnt[2*i+1]->xy()->decreased(aStartEndPnt[2*i]->xy());
280 if (!myIsNotInversed[i])
281 aDir = aDir->multiplied(-1.0);
282 } else if (myBaseFeatures[i]->getKind() == SketchPlugin_Arc::ID()) {
283 std::shared_ptr<GeomAPI_Pnt2d> aCenterPoint =
284 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
285 myBaseFeatures[i]->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
286 aDir = myIsNotInversed[i] ? aStartEndPnt[2*i]->xy() : aStartEndPnt[2*i+1]->xy();
287 aDir = aDir->decreased(aCenterPoint->xy());
289 double x = aDir->x();
290 double y = aDir->y();
293 if (myIsNotInversed[i] ==
294 std::dynamic_pointer_cast<SketchPlugin_Arc>(myBaseFeatures[i])->isReversed())
295 aDir = aDir->multiplied(-1.0);
297 aTangentDir[i] = std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(aDir));
300 // By default, the start point of fillet arc is connected to FeatureA,
301 // and the end point - to FeatureB. But when the angle between TangentDirA and
302 // TangentDirB greater 180 degree, the sequaence of features need to be reversed.
303 double cosBA = aTangentDir[0]->cross(aTangentDir[1]); // cos(B-A),
304 // where A and B - angles between corresponding tanget direction and the X axis
305 myIsReversed = cosBA > 0.0;
308 std::shared_ptr<GeomAPI_XY> aTmp = myTangentXY1;
309 myTangentXY1 = myTangentXY2;
315 bool SketchPlugin_Fillet::findFeaturesContainingFilletPoint(
316 std::shared_ptr<GeomDataAPI_Point2D> theFilletPoint)
318 // Obtain constraint coincidence for the fillet point.
319 FeaturePtr aConstraintCoincidence;
320 const std::set<AttributePtr>& aRefsList = theFilletPoint->owner()->data()->refsToMe();
321 for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin();
322 anIt != aRefsList.cend();
324 std::shared_ptr<ModelAPI_Attribute> anAttr = (*anIt);
325 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
326 if(aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
327 AttributeRefAttrPtr anAttrRefA =
328 aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A());
329 AttributeRefAttrPtr anAttrRefB =
330 aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B());
331 if(anAttrRefA.get() && !anAttrRefA->isObject()) {
332 AttributePtr anAttrA = anAttrRefA->attr();
333 if(theFilletPoint == anAttrA) {
334 aConstraintCoincidence = aFeature;
338 if(anAttrRefB.get() && !anAttrRefB->isObject()) {
339 AttributePtr anAttrB = anAttrRefB->attr();
340 if(theFilletPoint == anAttrB) {
341 aConstraintCoincidence = aFeature;
348 if(!aConstraintCoincidence.get())
351 // Get coincide edges.
352 std::set<FeaturePtr> anEdgeFeatures = getCoincides(aConstraintCoincidence);
353 std::set<FeaturePtr>::iterator aLinesIt = anEdgeFeatures.begin();
354 for (int i = 0; aLinesIt != anEdgeFeatures.end() && i < 2; ++aLinesIt, ++i)
355 myBaseFeatures[i] = *aLinesIt;
357 return myBaseFeatures[0] && myBaseFeatures[1];
360 // ========= Auxiliary functions =================
361 void recalculateAttributes(FeaturePtr theNewArc, const std::string& theNewArcAttribute,
362 FeaturePtr theFeature, const std::string& theFeatureAttribute)
364 std::shared_ptr<GeomAPI_Pnt2d> anArcPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
365 theNewArc->attribute(theNewArcAttribute))->pnt();
366 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
367 theFeature->attribute(theFeatureAttribute))->setValue(anArcPoint->x(), anArcPoint->y());
370 static std::shared_ptr<GeomAPI_Pnt2d> toPoint(const AttributePtr& theAttribute)
372 std::shared_ptr<GeomAPI_Pnt2d> aPoint;
373 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
375 aPoint = aPointAttr->pnt();
379 static std::shared_ptr<GeomAPI_Lin2d> toLine(const FeaturePtr& theFeature)
381 std::shared_ptr<GeomAPI_Lin2d> aLine;
382 if (theFeature->getKind() == SketchPlugin_Line::ID()) {
383 std::shared_ptr<GeomAPI_Pnt2d> aStart =
384 toPoint( theFeature->attribute(SketchPlugin_Line::START_ID()) );
385 std::shared_ptr<GeomAPI_Pnt2d> aEnd =
386 toPoint( theFeature->attribute(SketchPlugin_Line::END_ID()) );
387 aLine = std::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aStart, aEnd));
392 static std::shared_ptr<GeomAPI_Circ2d> toCircle(const FeaturePtr& theFeature)
394 std::shared_ptr<GeomAPI_Circ2d> aCircle;
395 if (theFeature->getKind() == SketchPlugin_Arc::ID()) {
396 std::shared_ptr<GeomAPI_Pnt2d> aCenter =
397 toPoint( theFeature->attribute(SketchPlugin_Arc::CENTER_ID()) );
398 std::shared_ptr<GeomAPI_Pnt2d> aStart =
399 toPoint( theFeature->attribute(SketchPlugin_Arc::START_ID()) );
400 aCircle = std::shared_ptr<GeomAPI_Circ2d>(new GeomAPI_Circ2d(aCenter, aStart));
406 void calculateFilletCenter(FeaturePtr theFilletFeatures[2],
407 double theFilletRadius,
408 const std::shared_ptr<GeomAPI_Ax3>& theSketchPlane,
409 std::shared_ptr<GeomAPI_XY>& theCenter,
410 std::shared_ptr<GeomAPI_XY>& theTangentA,
411 std::shared_ptr<GeomAPI_XY>& theTangentB)
413 GeomShapePtr aShapeA = theFilletFeatures[0]->lastResult()->shape();
414 GeomShapePtr aShapeB = theFilletFeatures[1]->lastResult()->shape();
416 GeomAlgoAPI_Circ2dBuilder aCircBuilder(theSketchPlane);
417 aCircBuilder.addTangentCurve(aShapeA);
418 aCircBuilder.addTangentCurve(aShapeB);
419 aCircBuilder.setRadius(theFilletRadius);
421 std::shared_ptr<GeomAPI_Circ2d> aFilletCircle = aCircBuilder.circle();
425 theCenter = aFilletCircle->center()->xy();
427 std::shared_ptr<GeomAPI_Pnt2d> aTgPoints[2];
428 for (int i = 0; i < 2; ++i) {
429 std::shared_ptr<GeomAPI_Circ2d> aCircle = toCircle(theFilletFeatures[i]);
431 aTgPoints[i] = aCircle->project(aFilletCircle->center());
433 std::shared_ptr<GeomAPI_Lin2d> aLine = toLine(theFilletFeatures[i]);
435 aTgPoints[i] = aLine->project(aFilletCircle->center());
438 theTangentA = aTgPoints[0]->xy();
439 theTangentB = aTgPoints[1]->xy();
442 double calculateFilletRadius(FeaturePtr theFilletFeatures[2])
444 double aLengths[2] = { 0, 0 };
445 for (int i = 0; i < 2; ++i) {
446 GeomShapePtr aShape = theFilletFeatures[i]->lastResult()->shape();
447 std::shared_ptr<GeomAPI_Edge> anEdge = std::dynamic_pointer_cast<GeomAPI_Edge>(aShape);
449 aLengths[i] = anEdge->length();
451 return std::min(aLengths[0], aLengths[1]) / 6.0;
454 std::set<FeaturePtr> getCoincides(const FeaturePtr& theConstraintCoincidence)
456 std::set<FeaturePtr> aCoincides;
458 std::shared_ptr<GeomAPI_Pnt2d> aFilletPnt =
459 SketchPlugin_Tools::getCoincidencePoint(theConstraintCoincidence);
461 SketchPlugin_Tools::findCoincidences(theConstraintCoincidence,
462 SketchPlugin_ConstraintCoincidence::ENTITY_A(),
464 SketchPlugin_Tools::findCoincidences(theConstraintCoincidence,
465 SketchPlugin_ConstraintCoincidence::ENTITY_B(),
468 // Remove points from set of coincides.
469 std::set<FeaturePtr> aNewSetOfCoincides;
470 for(std::set<FeaturePtr>::iterator anIt = aCoincides.begin(); anIt != aCoincides.end(); ++anIt) {
471 std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
472 std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(*anIt);
473 if(aSketchEntity.get() && aSketchEntity->isCopy()) {
476 if((*anIt)->getKind() == SketchPlugin_Line::ID()) {
477 aNewSetOfCoincides.insert(*anIt);
478 } else if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
479 AttributePtr anAttrCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
480 std::shared_ptr<GeomDataAPI_Point2D> aPointCenter2D =
481 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttrCenter);
482 if(aPointCenter2D.get() && aFilletPnt->isEqual(aPointCenter2D->pnt())) {
485 aNewSetOfCoincides.insert(*anIt);
488 aCoincides = aNewSetOfCoincides;
490 // If we still have more than two coincides remove auxilary entities from set of coincides.
491 if(aCoincides.size() > 2) {
492 aNewSetOfCoincides.clear();
493 for(std::set<FeaturePtr>::iterator
494 anIt = aCoincides.begin(); anIt != aCoincides.end(); ++anIt) {
495 if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
496 aNewSetOfCoincides.insert(*anIt);
499 aCoincides = aNewSetOfCoincides;
505 std::set<FeaturePtr> findFeaturesToRemove(const FeaturePtr theFeature,
506 const AttributePtr theAttribute) {
507 std::set<FeaturePtr> aFeaturesToBeRemoved;
508 std::set<AttributePtr> aRefs = theFeature->data()->refsToMe();
509 std::list<ResultPtr> aResults = theFeature->results();
510 for(std::list<ResultPtr>::const_iterator aResultsIt = aResults.cbegin();
511 aResultsIt != aResults.cend();
513 ResultPtr aResult = *aResultsIt;
514 std::set<AttributePtr> aResultRefs = aResult->data()->refsToMe();
515 aRefs.insert(aResultRefs.begin(), aResultRefs.end());
517 for(std::set<AttributePtr>::const_iterator anIt = aRefs.cbegin();
518 anIt != aRefs.cend();
520 std::shared_ptr<ModelAPI_Attribute> anAttr = (*anIt);
521 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
522 if(aFeature->getKind() == SketchPlugin_Fillet::ID()) {
525 if(aFeature->getKind() == SketchPlugin_ConstraintLength::ID()
526 || aFeature->getKind() == SketchPlugin_ConstraintEqual::ID()
527 || aFeature->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
528 aFeaturesToBeRemoved.insert(aFeature);
530 std::list<AttributePtr> anAttrs =
531 aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
532 for(std::list<AttributePtr>::const_iterator aRefAttrsIt = anAttrs.cbegin();
533 aRefAttrsIt != anAttrs.cend();
535 AttributeRefAttrPtr anAttrRefAttr =
536 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefAttrsIt);
537 if(anAttrRefAttr.get() && anAttrRefAttr->attr() == theAttribute) {
538 aFeaturesToBeRemoved.insert(aFeature);
543 return aFeaturesToBeRemoved;