- FeaturePtr aCircleFeature = sketch()->addFeature(SketchPlugin_Circle::ID());
- std::shared_ptr<GeomAPI_Pnt2d> aCenter = theCircle->center();
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->setValue(aCenter->x(),
- aCenter->y());
- aCircleFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue(theCircle->radius());
- aCircleFeature->boolean(SketchPlugin_Circle::AUXILIARY_ID())
- ->setValue(boolean(AUXILIARY_ID())->value());
- aCircleFeature->execute();
- return aCircleFeature;
+ std::string aPointAttr[2] = { FIRST_POINT_ID(),
+ SECOND_POINT_ID() };
+ std::string aPointRef[2] = { FIRST_POINT_REF_ID(),
+ SECOND_POINT_REF_ID() };
+ std::shared_ptr<GeomAPI_Pnt2d> aPassedPoints[2]; // there is possible only two passed points
+ std::shared_ptr<GeomAPI_Interface> aPassedEntities[3];
+ int aPntIndex = 0;
+ for (; aPntIndex < 2; ++aPntIndex) {
+ AttributePtr aPassedAttr = attribute(aPointAttr[aPntIndex]);
+ if (!aPassedAttr->isInitialized())
+ break;
+
+ AttributeRefAttrPtr aPassedRef = refattr(aPointRef[aPntIndex]);
+ // calculate circle parameters
+ std::shared_ptr<GeomAPI_Pnt2d> aPassedPoint;
+ std::shared_ptr<GeomAPI_Shape> aTangentCurve;
+ SketchPlugin_Tools::convertRefAttrToPointOrTangentCurve(
+ aPassedRef, aPassedAttr, aTangentCurve, aPassedPoint);
+
+ if (aPassedPoint) {
+ aPassedEntities[aPntIndex] = aPassedPoint;
+ aPassedPoints[aPntIndex] = aPassedPoint;
+ } else {
+ aPassedEntities[aPntIndex] = aTangentCurve;
+ // if the circle is tangent to any curve,
+ // the third point will be initialized by the tangent point
+ aPassedEntities[2] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPassedAttr)->pnt();
+ }
+ }
+ if (aPntIndex <= 1)
+ return;
+
+ std::shared_ptr<GeomAPI_Circ2d> aCircle;
+ if (aPassedEntities[2]) {
+ std::shared_ptr<GeomAPI_Ax3> anAxis = SketchPlugin_Sketch::plane(sketch());
+ aCircle = std::shared_ptr<GeomAPI_Circ2d>(
+ new GeomAPI_Circ2d(aPassedEntities[0], aPassedEntities[1], aPassedEntities[2], anAxis));
+ } else {
+ // the circle is defined by two points, calculate its parameters manually
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter(new GeomAPI_Pnt2d(
+ (aPassedPoints[0]->x() + aPassedPoints[1]->x()) * 0.5,
+ (aPassedPoints[0]->y() + aPassedPoints[1]->y()) * 0.5));
+ aCircle = std::shared_ptr<GeomAPI_Circ2d>(new GeomAPI_Circ2d(aCenter, aPassedPoints[0]));
+ }
+ if (aCircle->implPtr<char>()) {
+ myCenter = aCircle->center();
+ myRadius = aCircle->radius();
+ }