+ std::shared_ptr<GeomAPI_Ax3> anAxis = SketchPlugin_Sketch::plane(sketch());
+ std::shared_ptr<GeomAPI_Circ2d> aCircle = std::shared_ptr<GeomAPI_Circ2d>(
+ new GeomAPI_Circ2d(aPassedEntities[0], aPassedEntities[1], aPassedEntities[2], anAxis));
+ if (!aCircle->implPtr<char>())
+ return std::shared_ptr<GeomAPI_Circ2d>();
+ return aCircle;
+}
+
+std::shared_ptr<GeomAPI_Circ2d> SketchPlugin_MacroCircle::shapeByTwoPassedPoints()
+{
+ 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;
+ convertToPointOrTangent(aPassedRef, aPassedAttr, aPassedPoint, aTangentCurve);
+
+ 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>();
+
+ 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>())
+ return std::shared_ptr<GeomAPI_Circ2d>();
+ return aCircle;
+}
+
+AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious)
+{