X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FPartSet%2FPartSet_WidgetPoint2d.cpp;h=0574f2e0003c37ab6bdbb81eff764a6af4d1bb77;hb=ccebb4b23e0354829c9636110b903c59923d8e30;hp=8782a90acd49dfcecd4be4b191d7e037bf019a00;hpb=dc7d4d86b58b81684abc9b5a2be8ec30f210c2da;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 8782a90ac..0574f2e00 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "PartSet_WidgetPoint2d.h" @@ -103,7 +102,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, // the control should accept the focus, so the boolean flag is corrected to be true myIsObligatory = true; - QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME)); + QString aPageName = translate(theData->getProperty(CONTAINER_PAGE_NAME)); myGroupBox = new QGroupBox(aPageName, theParent); myGroupBox->setFlat(false); @@ -244,10 +243,10 @@ bool PartSet_WidgetPoint2D::setSelectionCustom(const ModuleBase_ViewerPrsPtr& th GeomShapePtr aShape = theValue->shape(); if (aShape.get() && !aShape->isNull()) { Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); - double aX = 0, aY = 0; const TopoDS_Shape& aTDShape = aShape->impl(); - if (getPoint2d(aView, aTDShape, aX, aY)) { - fillRefAttribute(aX, aY, theValue); + GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aTDShape, mySketch); + if (aPnt) { + fillRefAttribute(aPnt->x(), aPnt->y(), theValue); isDone = true; } else if (aTDShape.ShapeType() == TopAbs_EDGE) { @@ -307,11 +306,11 @@ bool PartSet_WidgetPoint2D::setSelection(QList& theValu GeomShapePtr aShape = aValue->shape(); if (aShape.get() && !aShape->isNull()) { Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); - double aX = 0, aY = 0; const TopoDS_Shape& aTDShape = aShape->impl(); - if (getPoint2d(aView, aTDShape, aX, aY)) { - isDone = setPoint(aX, aY); - setConstraintToPoint(aX, aY, aValue); + GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aTDShape, mySketch); + if (aPnt) { + isDone = setPoint(aPnt->x(), aPnt->y()); + setConstraintToPoint(aPnt->x(), aPnt->y(), aValue); } } } @@ -343,7 +342,7 @@ bool PartSet_WidgetPoint2D::setPoint(double theX, double theY) bool PartSet_WidgetPoint2D::storeValueCustom() { std::shared_ptr aData = myFeature->data(); - if (!aData) // can be on abort of sketcher element + if (!aData || !aData->isValid()) // can be on abort of sketcher element return false; AttributePoint2DPtr aPoint = std::dynamic_pointer_cast( aData->attribute(attributeID())); @@ -477,24 +476,6 @@ void PartSet_WidgetPoint2D::deactivate() ModuleBase_ModelWidget::deactivate(); } -bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, - const TopoDS_Shape& theShape, - double& theX, double& theY) const -{ - if (!theShape.IsNull()) { - if (theShape.ShapeType() == TopAbs_VERTEX) { - const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape); - if (!aVertex.IsNull()) { - // A case when point is taken from existing vertex - gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); - PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY); - return true; - } - } - } - return false; -} - bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY, const std::shared_ptr& theValue) { @@ -521,7 +502,7 @@ bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theC AttributePoint2DPtr aFeaturePoint; if (aFeature->isMacro()) { // the macro feature will be removed after the operation is stopped, so we need to build - // coicidence to possible sub-features + // coincidence to possible sub-features aFeaturePoint = findFirstEqualPointInArgumentFeatures(aFeature, aClickedPoint); } else { @@ -550,7 +531,7 @@ bool PartSet_WidgetPoint2D::setConstraintToObject(const ObjectPtr& theObject) AttributePoint2DPtr anAttrPoint = std::dynamic_pointer_cast(aThisAttr); if (anAttrPoint.get()) { // the macro feature will be removed after the operation is stopped, so we need to build - // coicidence to possible sub-features + // coincidence to possible sub-features aFeaturePoint = findFirstEqualPointInArgumentFeatures(feature(), anAttrPoint->pnt()); } @@ -628,14 +609,19 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo } } if (anExternal) { + GeomPnt2dPtr aPnt = PartSet_Tools::getPnt2d(aView, aShape, mySketch); double aX = 0, aY = 0; - if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) { + 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 (getPoint2d(aView, aShape, aX, aY)) + if (aPnt) setPoint(aX, aY); else { if (aShape.ShapeType() == TopAbs_EDGE) { @@ -671,24 +657,28 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo if (!anOrphanPoint) emit vertexSelected(); // it stops the reentrant operation + myPreSelected.reset(); emit focusOutWidget(this); } } if (!anExternal) { - double aX = 0, aY = 0; bool isProcessed = false; - if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) { + 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(aX, aY); + setPoint(aPnt->x(), aPnt->y()); } else { + 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 (getPoint2d(aView, aShape, aX, aY)) { + if (aPnt) { + aX = aPnt->x(); + aY = aPnt->y(); setPoint(aX, aY); setConstraintToPoint(aX, aY, aFirstValue); } @@ -712,6 +702,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo updateObject(feature()); if (!anOrphanPoint && !anExternal && !isAuxiliaryFeature) emit vertexSelected(); + myPreSelected.reset(); emit focusOutWidget(this); } } @@ -739,13 +730,14 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo // external objects e.g. selection of trihedron axis when input end arc point updateObject(feature()); - double aX = 0, aY = 0; - if (getPoint2d(aView, aShape, aX, aY)) { + 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(aX, aY); + setPoint(aPnt->x(), aPnt->y()); } emit vertexSelected(); // it stops the reentrant operation + myPreSelected.reset(); emit focusOutWidget(this); } } @@ -759,6 +751,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo if (!setPoint(aX, aY) || isFeatureContainsPoint(myFeature, aX, aY)) return; + myPreSelected.reset(); emit focusOutWidget(this); } } @@ -770,7 +763,6 @@ void PartSet_WidgetPoint2D::setPreSelection( { myPreSelected = thePreSelected; mouseReleased(theWnd, theEvent); - myPreSelected = ModuleBase_ViewerPrsPtr(); } void PartSet_WidgetPoint2D::getGeomSelection_(const std::shared_ptr& theValue,