- double aX, aY;
- if (getPoint2d(aView, aShape, aX, aY)) {
- setPoint(aX, aY);
-
- PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
- emit vertexSelected();
- emit focusOutWidget(this);
- return;
- } else if (aShape.ShapeType() == TopAbs_EDGE) {
- // Create point-edge coincedence
- FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
- std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
-
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
- AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
- std::shared_ptr<GeomDataAPI_Point2D> aThisPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
- aRef1->setAttr(aThisPoint);
-
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRef2->setObject(aObject);
- aFeature->execute();
- emit vertexSelected();
- emit focusOutWidget(this);
- return;
+ if (!anExternal) {
+ double aX, aY;
+ bool isProcessed = false;
+ if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) {
+ // when the point is selected, the coordinates of the point should be set into the attribute
+ // if the feature contains the point, focus is not switched
+ setPoint(aX, aY);
+ }
+ else {
+ // do not set a coincidence constraint in the attribute if the feature contains a point
+ // with the same coordinates. It is important for line creation in order to do not set
+ // the same constraints for the same points, oterwise the result line has zero length.
+ if (getPoint2d(aView, aShape, aX, aY))
+ PartSet_Tools::setConstraints(mySketch, feature(), attributeID(), aX, aY);
+ else if (aShape.ShapeType() == TopAbs_EDGE)
+ setConstraintWith(aObject);
+
+ // it is important to perform updateObject() in order to the current value is
+ // processed by Sketch Solver. Test case: line is created from a previous point
+ // to some distance, but in the area of the highlighting of the point. Constraint
+ // coincidence is created, after the solver is performed, the distance between the
+ // points of the line becomes less than the tolerance. Validator of the line returns
+ // false, the line will be aborted, but sketch stays valid.
+ updateObject(feature());
+ emit vertexSelected();
+ emit focusOutWidget(this);
+ }