- double aV1 = theX1 - theX0, aV2 = theY1 - theY0;
- double aW1 = theX3 - theX2, aW2 = theY3 - theY2;
-
- double aT2 = 0;
- if (aV1 != 0 && aV2 != 0)
- aT2 = (( theY2 - theY0 )/aV2 - ( theX2 - theX0 )/aV1) / ( aW1/aV1 - aW2/aV2 );
- else
- aT2 = DBL_MAX;
-
- theX = theX2 + aT2*aW1;
- theY = theY2 + aT2*aW2;
-
- // the coordinates of two lines are on the common line
- //It is not possible to use Precision::Confusion(), because it is e-0.8, but V is sometimes e-6
- Standard_Real aPrec = PRECISION_TOLERANCE;
- if (fabs(theX - theX0) < aPrec && fabs(theY - theY0) < aPrec) {
- projectPointOnLine(theX2, theY2, theX3, theY3, theX1, theY1, theX, theY);
+ ObjectPtr aDeltaObject;
+
+ CompositeFeaturePtr aSketch =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
+ // 1. find it in the selected list by the selected point
+ if (!aDeltaObject) {
+ double aX, anY;
+ gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
+ PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY);
+
+ FeaturePtr aFeature;
+ double aMinDelta = -1;
+ ModuleBase_ViewerPrs aPrs;
+ foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
+ if (!aPrs.object())
+ continue;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature = std::dynamic_pointer_cast<
+ SketchPlugin_Feature>(aFeature);
+ if (!aSketchFeature || !aSketch->isSub(aSketchFeature))
+ continue;
+
+ double aDelta = aSketchFeature->distanceToPoint(
+ std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
+ if (aMinDelta < 0 || aMinDelta > aDelta) {
+ aMinDelta = aDelta;
+ // TODO aDeltaObject = aPrs.result();
+ }
+ }
+ }
+ // 2. if the object is not found, returns the first selected sketch feature
+ if (!aDeltaObject && thePresentations.size() > 0) {
+ // there can be some highlighted objects, e.g. a result of boolean operation and a sketch point
+ foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
+ if (!aPrs.object())
+ continue;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
+ if (aFeature && aSketch->isSub(aFeature))
+ aDeltaObject = aPrs.object();
+ }