X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetPoint2dDistance.cpp;h=f3991587b375a6180473b803b6d5efe74d197e1b;hb=def1d660542e39cc9ed4ee27ab8cce8d231be01a;hp=c3cba967bb8490347938c04084fe4779876bc915;hpb=72cb66f9c09b0f8fa224f6f8ab43548658015b49;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index c3cba967b..f3991587b 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -1,19 +1,22 @@ // 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 +#include +#include +#include +#include #include #include @@ -25,21 +28,43 @@ #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) +: ModuleBase_WidgetDoubleValue(theParent, theData), myWorkshop(theWorkshop), + myValueIsCashed(false), myIsFeatureVisibleInCash(true), myValueInCash(0) { myFirstPntName = theData->getProperty("first_point"); - - // Reconnect to local slot - disconnect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); - connect(mySpinBox, SIGNAL(valueChanged(double)), this, SLOT(onValuesChanged())); + myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop); } PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance() { } +bool PartSet_WidgetPoint2dDistance::isValidSelectionCustom( + const std::shared_ptr& theValue) +{ + return false; +} + +bool PartSet_WidgetPoint2dDistance::resetCustom() +{ + bool aDone = false; + if (!isUseReset() || isComputedDefault() || mySpinBox->hasVariable()) { + aDone = false; + } + else { + if (myValueIsCashed) { + // if the restored value should be hidden, aDone = true to set + // reset state for the widget in the parent + aDone = restoreCurentValue(); + } + else + aDone = ModuleBase_WidgetDoubleValue::resetCustom(); + } + return aDone; +} + void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt) { @@ -49,21 +74,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->blockSignals(true); - mySpinBox->setValue(aRadius); - mySpinBox->blockSignals(false); - emit valuesChanged(); + 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*))); @@ -71,16 +101,23 @@ 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*))); disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); - myWorkshop->operationMgr()->setLockValidating(false); } 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; @@ -88,13 +125,19 @@ 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) { - myWorkshop->operationMgr()->setLockValidating(true); - myWorkshop->operationMgr()->setApplyEnabled(false); + if (isEditingMode()) + return; + + if (mySpinBox->hasVariable()) + return; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); @@ -102,12 +145,56 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); + if (myState != ModifiedInViewer) + storeCurentValue(); + + bool isBlocked = blockValueState(true); setPoint(feature(), aPnt); + blockValueState(isBlocked); + setValueState(ModifiedInViewer); +} + +void PartSet_WidgetPoint2dDistance::storeCurentValue() +{ + // do not use cash if a variable is used + if (mySpinBox->hasVariable()) + return; + + myValueIsCashed = true; + myIsFeatureVisibleInCash = XGUI_Displayer::isVisible( + XGUI_Tools::workshop(myWorkshop)->displayer(), myFeature); + myValueInCash = mySpinBox->value(); } -void PartSet_WidgetPoint2dDistance::onValuesChanged() +bool PartSet_WidgetPoint2dDistance::restoreCurentValue() { - myWorkshop->operationMgr()->setLockValidating(false); - emit valuesChanged(); + bool aRestoredAndHidden = true; + + bool isVisible = myIsFeatureVisibleInCash; + // fill the control widgets by the cashed value + + myValueIsCashed = false; + myIsFeatureVisibleInCash = true; + ModuleBase_Tools::setSpinValue(mySpinBox, myValueInCash); + + // store value to the model + storeValueCustom(); + if (isVisible) { + setValueState(Stored); + aRestoredAndHidden = false; + } + else + aRestoredAndHidden = true; + + return aRestoredAndHidden; } +bool PartSet_WidgetPoint2dDistance::processEnter() +{ + bool isModified = getValueState() == ModifiedInPP; + if (isModified) { + emit valuesChanged(); + mySpinBox->selectAll(); + } + return isModified; +}