Salome HOME
Merge remote-tracking branch 'origin/master' into gni/documentation
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.cpp
index c8068e18ca7b7a6d77f456c2b45c8ef7cdd8f7a1..8f6f4fcd5f15f096f1ee50419fa60715bb380477 100644 (file)
@@ -284,19 +284,22 @@ bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValu
       Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
       const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
       GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aTDShape, mySketch);
+
       if (aPnt) {
-        isDone = setPoint(aPnt->x(), aPnt->y());
-        setConstraintToPoint(aPnt->x(), aPnt->y(), aValue);
+        //isDone = setPoint(aPnt->x(), aPnt->y());
+        //setConstraintToPoint(aPnt->x(), aPnt->y(), aValue);
+        processSelection(aValue, aPnt->x(), aPnt->y());
+        isDone = true;
       }
     }
   }
   return isDone;
 }
 
-void PartSet_WidgetPoint2D::selectContent()
-{
- // myXSpin->selectAll();
-}
+//void PartSet_WidgetPoint2D::selectContent()
+//{
+// // myXSpin->selectAll();
+//}
 
 bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
 {
@@ -554,12 +557,36 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
     aFirstValue = myPreSelected;
   }
 
+  double aX=0, aY=0;
+  bool aHasPoint = false;
+  if (aFirstValue.get()) {
+    GeomShapePtr aShape = aFirstValue->shape();
+    if (aShape.get() && aShape->shapeType() == GeomAPI_Shape::VERTEX) {
+      const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+      GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aTDShape, mySketch);
+      aX = aPnt->x();
+      aY = aPnt->y();
+      aHasPoint = true;
+    }
+  }
+  if (!aHasPoint) {
+    gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
+    PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
+  }
+  processSelection(aFirstValue, aX, aY);
+}
+
+void PartSet_WidgetPoint2D::processSelection(const ModuleBase_ViewerPrsPtr& theValue,
+  double theX, double theY)
+{
+  if (!setPoint(theX, theY))
+    return;
   // if we have selection and use it
-  if (aFirstValue.get() && isValidSelectionCustom(aFirstValue) &&
-      aFirstValue->shape().get()) { /// Trihedron Axis may be selected, but shape is empty
-    GeomShapePtr aGeomShape = aFirstValue->shape();
+  if (theValue.get() && isValidSelectionCustom(theValue) && theValue->shape().get()) {
+    /// Trihedron Axis may be selected, but shape is empty
+    GeomShapePtr aGeomShape = theValue->shape();
     TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
-    ObjectPtr aObject = aFirstValue->object();
+    ObjectPtr aObject = theValue->object();
 
     FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
     bool anExternal = false;
@@ -585,34 +612,12 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
       }
     }
     if (anExternal) {
-      GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aShape, mySketch);
-      double aX = 0, aY = 0;
-      if (aPnt) {
-        aX = aPnt->x();
-        aY = aPnt->y();
-      }
-      if (aPnt && isFeatureContainsPoint(myFeature, aX, aY)) {
-        // do not create a constraint to the point, which already used by the feature
-        // if the feature contains the point, focus is not switched
-        setPoint(aX, aY);
-      }
-      else {
-        if (aPnt)
-          setPoint(aX, aY);
-        else {
-          if (aShape.ShapeType() == TopAbs_EDGE) {
-            // point is taken from mouse event and set in attribute. It should be done before set
-            // coinident constraint to the external line. If a point is created, it should be in
-            // the mouse clicked point
-            gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(),
-                                                               theWindow->v3dView());
-            PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
-            setPoint(aX, aY);
-          }
+      if (!isFeatureContainsPoint(myFeature, theX, theY)) {
+        if (aShape.ShapeType() == TopAbs_EDGE) {
           setValueState(Stored); // in case of edge selection, Apply state should also be updated
         }
         bool anOrphanPoint = aShape.ShapeType() == TopAbs_VERTEX ||
-                              isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
+                              isOrphanPoint(aSelectedFeature, mySketch, theX, theY);
         if (anExternal) {
           // we should not stop reentrant operation on external objects because
           anOrphanPoint = true;
@@ -620,7 +625,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
           if (aShape.ShapeType() == TopAbs_VERTEX) {
             FeaturePtr aFixedFeature = ModelAPI_Feature::feature(aFixedObject);
             if (aFixedFeature.get() && aFixedFeature->getKind() == SketchPlugin_Point::ID()) {
-              anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, aX, aY);
+              anOrphanPoint = isOrphanPoint(aFixedFeature, mySketch, theX, theY);
             }
           }
         }
@@ -637,33 +642,21 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
         emit focusOutWidget(this);
       }
     }
-    if (!anExternal) {
-      GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aShape, mySketch);
-      if (aPnt && isFeatureContainsPoint(myFeature, aPnt->x(), aPnt->y())) {
-        // 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(aPnt->x(), aPnt->y());
-      }
-      else {
+    else {
+      if (!isFeatureContainsPoint(myFeature, theX, theY)) {
         double aX = 0, aY = 0;
         bool anOrphanPoint = isOrphanPoint(aSelectedFeature, mySketch, aX, aY);
         // 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.
         bool isAuxiliaryFeature = false;
-        if (aPnt) {
-          aX = aPnt->x();
-          aY = aPnt->y();
-          setPoint(aX, aY);
-          setConstraintToPoint(aX, aY, aFirstValue);
+        if (aShape.ShapeType() == TopAbs_VERTEX) {
+          setConstraintToPoint(theX, theY, theValue);
         }
         else if (aShape.ShapeType() == TopAbs_EDGE) {
           // point is taken from mouse event and set in attribute. It should be done before setting
           // coinident constraint to the external line. If a point is created, it should be in
           // the mouse clicked point
-          gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
-          PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
-          setPoint(aX, aY);
           setConstraintToObject(aObject);
           setValueState(Stored); // in case of edge selection, Apply state should also be updated
           isAuxiliaryFeature = PartSet_Tools::isAuxiliarySketchEntity(aObject);
@@ -683,9 +676,9 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
     }
   }
   // The selection could be a center of an external circular object
-  else if (aFirstValue.get() && (!aFirstValue->interactive().IsNull())) {
+  else if (theValue.get() && (!theValue->interactive().IsNull())) {
     Handle(PartSet_CenterPrs) aAIS =
-        Handle(PartSet_CenterPrs)::DownCast(aFirstValue->interactive());
+        Handle(PartSet_CenterPrs)::DownCast(theValue->interactive());
     if (!aAIS.IsNull()) {
       gp_Pnt aPntComp = aAIS->Component()->Pnt();
       GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z()));
@@ -705,12 +698,6 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
       // external objects e.g. selection of trihedron axis when input end arc point
       updateObject(feature());
 
-      GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aShape, mySketch);
-      if (aPnt) {
-        // do not create a constraint to the point, which already used by the feature
-        // if the feature contains the point, focus is not switched
-        setPoint(aPnt->x(), aPnt->y());
-      }
       emit vertexSelected(); // it stops the reentrant operation
       myPreSelected.reset();
       emit focusOutWidget(this);
@@ -718,12 +705,9 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
   }
   else {
     // A case when point is taken from mouse event
-    gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
-    double aX = 0, aY = 0;
-    PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, aY);
 
     // if the feature contains the point, focus is not switched
-    if (!setPoint(aX, aY) || isFeatureContainsPoint(myFeature, aX, aY))
+    if (isFeatureContainsPoint(myFeature, theX, theY))
       return;
 
     myPreSelected.reset();