-AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
-{
- SketchPlugin_Sketch* aSketch = sketch();
- if (aSketch) {
- // if the feature is valid, the execute() method should be performed, AIS object is empty
- if (!isFeatureValid()) {
- // compute a circle point in 3D view
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
- if (aCenterAttr->isInitialized()) {
- std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
-
- std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
- if (aStartAttr->isInitialized()) {
- // make a visible circle
- std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0);
- if (aHasPlane) {
- std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
- std::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
- std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
- aCenter, aStartPoint, aStartPoint, aNormal);
- if (aCircleShape) {
- std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
- // make a visible point
- std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
- aShapes.push_back(aCenterPointShape);
-
- aShapes.push_back(aCircleShape);
- if (!aShapes.empty())
- {
- std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createShape(aCompound);
- anAIS->setWidth(3);
- return anAIS;
- }
- }
- }
- }
+ // calculate tolerances for start and end points of the arc and set them to the result shape
+ // (this is done to fix gaps which appear because of inaccurate computation of arcs in PlaneGCS,
+ // which leads to difference in SketchPlugin_Arc attributes and boundary points of result shape)
+ if (anArcShape) {
+ for (int ind = 0; ind < 2; ++ind) {
+ bool isFirst = ind == 0;
+ GeomPointPtr anArcBndPoint = isFirst == isReversed ? anEnd : aStart;
+ GeomPointPtr aShapePoint = isFirst ? anArcShape->firstPoint() : anArcShape->lastPoint();
+ double aDistance = anArcBndPoint->distance(aShapePoint);
+ // avoid setting too high tolerance because it may be caused by incomplete update of an arc
+ if (aDistance > tolerance && aDistance < 100. * tolerance) {
+ if (isFirst)
+ anArcShape->setFirstPointTolerance(aDistance);
+ else
+ anArcShape->setLastPointTolerance(aDistance);