X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetPoint2dDistance.cpp;h=562604dc05578878b5ef62c137adebad2296788b;hb=031179ada6681b874314c450eeda806f9f8abd28;hp=2e722d02891ee77815a9855f8c914ad4207178e3;hpb=3874b57fe5aba25ff5aee2a07654fc23c1ee8eb0;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 2e722d028..562604dc0 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -1,17 +1,17 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: PartSet_WidgetPoint2dDistance.h +// File: PartSet_WidgetPoint2dDistance.cpp // Created: 23 June 2014 // Author: Vitaly Smetannikov #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" -#include +#include +#include #include - -#include -#include +#include +#include #include #include @@ -23,9 +23,10 @@ #include PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop) { myFirstPntName = theData->getProperty("first_point"); } @@ -34,26 +35,6 @@ PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() { } -//bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue) -//{ -// bool isDone = false; -// -// if (theValue) { -// ModuleBase_WidgetValueFeature* aFeatureValue = -// dynamic_cast(theValue); -// if (aFeatureValue) { -// std::shared_ptr aPnt = aFeatureValue->point(); -// ObjectPtr aObject = aFeatureValue->object(); -// FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); -// if (aFeature && aPnt) { -// setPoint(aFeature, aPnt); -// isDone = true; -// } -// } -// } -// return isDone; -//} - void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt) { @@ -63,18 +44,26 @@ void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, if (!aPoint) return; - double aRadius = thePnt->distance(aPoint->pnt()); + double aValue = computeValue(aPoint->pnt(), thePnt); AttributeDoublePtr aReal = aData->real(attributeID()); - if (aReal && (aReal->value() != aRadius)) { - aReal->setValue(aRadius); - mySpinBox->setValue(aRadius); + if (aReal && (aReal->value() != aValue)) { + aReal->setValue(aValue); + + ModuleBase_Tools::setSpinValue(mySpinBox, aValue); + storeValue(); } } -void PartSet_WidgetPoint2dDistance::activate() +double PartSet_WidgetPoint2dDistance::computeValue(const std::shared_ptr& theFirstPnt, + const std::shared_ptr& theCurrentPnt) +{ + return theCurrentPnt->distance(theFirstPnt); +} + +void PartSet_WidgetPoint2dDistance::activateCustom() { - XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); - connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); @@ -82,6 +71,7 @@ void PartSet_WidgetPoint2dDistance::activate() void PartSet_WidgetPoint2dDistance::deactivate() { + ModuleBase_ModelWidget::deactivate(); ModuleBase_IViewer* aViewer = myWorkshop->viewer(); disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); @@ -91,6 +81,13 @@ void PartSet_WidgetPoint2dDistance::deactivate() void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + // the contex menu release by the right button should not be processed by this widget + if (theEvent->button() != Qt::LeftButton) + return; + + if (mySpinBox->hasVariable()) + return; + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); double aX, aY; @@ -98,18 +95,38 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); setPoint(feature(), aPnt); - emit focusOutWidget(this); + + // if the validator of the control returns false, focus should not be switched + if (getError().isEmpty()) + emit focusOutWidget(this); } void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { + if (isEditingMode()) + return; + + if (mySpinBox->hasVariable()) + return; + gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); double aX, aY; PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); + bool isBlocked = blockValueState(true); setPoint(feature(), aPnt); + blockValueState(isBlocked); + setValueState(ModifiedInViewer); } - +bool PartSet_WidgetPoint2dDistance::processEnter() +{ + bool isModified = getValueState() == ModifiedInPP; + if (isModified) { + emit valuesChanged(); + mySpinBox->selectAll(); + } + return isModified; +}