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=0514fe7bb0a4af70000e3ac26bc60be6a44d3893;hpb=4d28b860188b4ad9550d6ccbd3fbf9f9f6c1d5ff;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 0514fe7bb..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, aY; 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, aY; 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())); @@ -442,14 +441,17 @@ QList PartSet_WidgetPoint2D::getControls() const return aControls; } +//******************************************************************** +void PartSet_WidgetPoint2D::selectionModes(int& theModuleSelectionModes, QIntList& theModes) +{ + theModuleSelectionModes = -1; + theModes << TopAbs_VERTEX; + theModes << TopAbs_EDGE; +} +//******************************************************************** void PartSet_WidgetPoint2D::activateCustom() { - QIntList aModes; - aModes << TopAbs_VERTEX; - aModes << TopAbs_EDGE; - myWorkshop->activateSubShapesSelection(aModes); - if (!isEditingMode()) { FeaturePtr aFeature = feature(); if (aFeature.get() && aFeature->getKind() == SketchPlugin_Point::ID()) @@ -472,25 +474,6 @@ void PartSet_WidgetPoint2D::deactivate() storeValue(); ModuleBase_ModelWidget::deactivate(); - myWorkshop->deactivateSubShapesSelection(); -} - -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, @@ -519,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 { @@ -548,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()); } @@ -626,14 +609,19 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo } } if (anExternal) { - double aX, aY; - if (getPoint2d(aView, aShape, aX, aY) && isFeatureContainsPoint(myFeature, aX, aY)) { + 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 (getPoint2d(aView, aShape, aX, aY)) + if (aPnt) setPoint(aX, aY); else { if (aShape.ShapeType() == TopAbs_EDGE) { @@ -669,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, aY; 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); } @@ -710,6 +702,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo updateObject(feature()); if (!anOrphanPoint && !anExternal && !isAuxiliaryFeature) emit vertexSelected(); + myPreSelected.reset(); emit focusOutWidget(this); } } @@ -737,26 +730,28 @@ 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, aY; - 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); } } else { // A case when point is taken from mouse event gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); - double aX, anY; - PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY); + 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, anY) || isFeatureContainsPoint(myFeature, aX, anY)) + if (!setPoint(aX, aY) || isFeatureContainsPoint(myFeature, aX, aY)) return; + myPreSelected.reset(); emit focusOutWidget(this); } } @@ -768,7 +763,6 @@ void PartSet_WidgetPoint2D::setPreSelection( { myPreSelected = thePreSelected; mouseReleased(theWnd, theEvent); - myPreSelected = ModuleBase_ViewerPrsPtr(); } void PartSet_WidgetPoint2D::getGeomSelection_(const std::shared_ptr& theValue, @@ -787,13 +781,13 @@ void PartSet_WidgetPoint2D::mouseMoved(ModuleBase_IViewWindow* theWindow, QMouse gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); - double aX, anY; - PartSet_Tools::convertTo2D(aPoint, mySketch, theWindow->v3dView(), aX, anY); + double aX = 0, aY = 0; + PartSet_Tools::convertTo2D(aPoint, mySketch, theWindow->v3dView(), aX, aY); if (myState != ModifiedInViewer) storeCurentValue(); // we need to block the value state change bool isBlocked = blockValueState(true); - setPoint(aX, anY); + setPoint(aX, aY); blockValueState(isBlocked); setValueState(ModifiedInViewer); }