+ FeaturePtr aNewFeatureB = sketch()->addFeature(aFeatureB->getKind());
+ aFeatureB->data()->copyTo(aNewFeatureB->data());
+ aNewFeatureB->execute();
+ aRefListOfFillet->append(aNewFeatureB->firstResult());
+ // create filleting arc (it will be attached to the list later)
+ FeaturePtr aNewArc = sketch()->addFeature(SketchPlugin_Arc::ID());
+
+ // Wait all constraints being created, then send update events
+ static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+ if (isUpdateFlushed)
+ Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+
+ // Calculate arc attributes
+ static const int aNbFeatures = 2;
+ FeaturePtr aFeature[aNbFeatures] = {aNewFeatureA, aNewFeatureB};
+ std::shared_ptr<GeomAPI_Dir2d> aTangentDir[aNbFeatures]; // tangent directions of the features in coincident point
+ bool isStart[aNbFeatures]; // indicates which point the features share
+ std::shared_ptr<GeomAPI_Pnt2d> aStartEndPnt[aNbFeatures * 2]; // first pair of points relate to first feature, second pair - to second
+ std::string aFeatAttributes[aNbFeatures * 2]; // attributes of features
+ for (int i = 0; i < aNbFeatures; i++) {
+ std::string aStartAttr, aEndAttr;
+ if (aFeature[i]->getKind() == SketchPlugin_Line::ID()) {
+ aStartAttr = SketchPlugin_Line::START_ID();
+ aEndAttr = SketchPlugin_Line::END_ID();
+ } else if (aFeature[i]->getKind() == SketchPlugin_Arc::ID()) {
+ aStartAttr = SketchPlugin_Arc::START_ID();
+ aEndAttr = SketchPlugin_Arc::END_ID();
+ } else { // wrong argument
+ aRefListOfFillet->remove(aNewFeatureA);
+ aRefListOfFillet->remove(aNewFeatureB);
+ aRefListOfFillet->remove(aNewArc);
+ return;
+ }
+ aFeatAttributes[2*i] = aStartAttr;
+ aStartEndPnt[2*i] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature[i]->attribute(aStartAttr))->pnt();
+ aFeatAttributes[2*i+1] = aEndAttr;
+ aStartEndPnt[2*i+1] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature[i]->attribute(aEndAttr))->pnt();
+ }
+ for (int i = 0; i < aNbFeatures; i++) {
+ int j = aNbFeatures;
+ for (; j < 2 * aNbFeatures; j++)
+ if (aStartEndPnt[i]->distance(aStartEndPnt[j]) < 1.e-10) {
+ isStart[0] = i==0;
+ isStart[1] = j==aNbFeatures;
+ break;
+ }
+ if (j < 2 * aNbFeatures)
+ break;
+ }
+ // tangent directions of the features
+ for (int i = 0; i < aNbFeatures; i++) {
+ std::shared_ptr<GeomAPI_XY> aDir;
+ if (aFeature[i]->getKind() == SketchPlugin_Line::ID()) {
+ aDir = aStartEndPnt[2*i+1]->xy()->decreased(aStartEndPnt[2*i]->xy());
+ if (!isStart[i])
+ aDir = aDir->multiplied(-1.0);
+ } else if (aFeature[i]->getKind() == SketchPlugin_Arc::ID()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aCenterPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature[i]->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
+ aDir = isStart[i] ? aStartEndPnt[2*i]->xy() : aStartEndPnt[2*i+1]->xy();
+ aDir = aDir->decreased(aCenterPoint->xy());
+
+ double x = aDir->x();
+ double y = aDir->y();
+ aDir->setX(-y);
+ aDir->setY(x);
+ if (!isStart[i])
+ aDir = aDir->multiplied(-1.0);
+ }
+ aTangentDir[i] = std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(aDir));
+ }
+ // By default, the start point of fillet arc is connected to FeatureA,
+ // and the end point - to FeatureB. But when the angle between TangentDirA and
+ // TangentDirB greater 180 degree, the sequaence of features need to be reversed.
+ double cosBA = aTangentDir[0]->cross(aTangentDir[1]); // cos(B-A), where A and B - angles between corresponding tanget direction and the X axis
+ bool isReversed = cosBA > 0.0;
+
+ std::shared_ptr<GeomAPI_Pnt2d> aSharedPoint = aStartEndPnt[isStart[0] ? 0 : 1];
+ std::shared_ptr<GeomAPI_Dir2d> aBisect(new GeomAPI_Dir2d(
+ aTangentDir[0]->xy()->added(aTangentDir[1]->xy())));
+ std::shared_ptr<GeomAPI_XY> aStep = aBisect->xy()->multiplied(aFilletRadius);
+ std::shared_ptr<GeomAPI_XY> aCenter = aSharedPoint->xy()->added(aStep);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aNewArc->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(
+ aCenter->x(), aCenter->y());
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aNewArc->attribute(SketchPlugin_Arc::START_ID()))->setValue(
+ aSharedPoint->x() - 1.e-5 * aStep->y(), aSharedPoint->y() + 1.e-5 * aStep->x());
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aNewArc->attribute(SketchPlugin_Arc::END_ID()))->setValue(
+ aSharedPoint->x() + 1.e-5 * aStep->y(), aSharedPoint->y() - 1.e-5 * aStep->x());
+ aNewArc->execute();
+ // attach new arc to the list
+ aRefListOfFillet->append(aNewArc->lastResult());