From: vsv Date: Tue, 22 Sep 2020 15:24:45 +0000 (+0300) Subject: bos #20081: Error in coincidence when creating two rectangles with auto apply X-Git-Tag: V9_6_0a1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e0e642f2c40a66934f6ad34c6a225ac71ae724c9;p=modules%2Fshaper.git bos #20081: Error in coincidence when creating two rectangles with auto apply --- diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index c8068e18c..ab8f1791c 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -284,19 +284,22 @@ bool PartSet_WidgetPoint2D::setSelection(QList& theValu Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); const TopoDS_Shape& aTDShape = aShape->impl(); 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->shapeType() == TopAbs_VERTEX) { + const TopoDS_Shape& aTDShape = aShape->impl(); + 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(); - 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(); diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 19846bfe7..f0a06a8ec 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -25,6 +25,7 @@ #include #include +#include #include @@ -98,7 +99,7 @@ Q_OBJECT const bool theToValidate); /// Select the internal content if it can be selected. It is empty in the default realization - virtual void selectContent(); + //virtual void selectContent(); /// Returns list of widget controls /// \return a control list @@ -222,6 +223,13 @@ protected: /// \return true if succed bool setConstraintToObject(const ObjectPtr& theObject); + /// Process selected value + /// \param theValue the selected object + /// \param theX X coordinate of clicked point + /// \param theY Y coordinate of clicked point + void processSelection(const ModuleBase_ViewerPrsPtr& theValue, double theX, double theY); + + public: /// Returns if the feature is an orphan point, circle or an arc. Returns true if it /// has no a coincident to other lines. It processes point, circle and arc features