X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetPoint2dDistance.cpp;h=2c7daebdedc25ba8f850d6e3ed8010bf3b012ddf;hb=8634847ac05ce637193ec2f5234c3c8996762f94;hp=ef7bf36c0d2430458290408ec283738b2f1f4ba3;hpb=1b93f1881c5fec599aa79707f93c84dd9c287bc0;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index ef7bf36c0..2c7daebde 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -7,11 +7,16 @@ #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" +#include +#include +#include + #include #include #include #include #include +#include #include #include @@ -24,17 +29,43 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop) + const Config_WidgetAPI* theData) +: ModuleBase_WidgetDoubleValue(theParent, theData), myWorkshop(theWorkshop), + myValueIsCashed(false), myIsFeatureVisibleInCash(true), myValueInCash(0) { myFirstPntName = theData->getProperty("first_point"); + 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(); + emit objectUpdated(); + } + else + aDone = ModuleBase_WidgetDoubleValue::resetCustom(); + } + return aDone; +} + void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const std::shared_ptr& thePnt) { @@ -60,26 +91,7 @@ double PartSet_WidgetPoint2dDistance::computeValue(const std::shared_ptrdistance(theFirstPnt); } -void PartSet_WidgetPoint2dDistance::activateCustom() -{ - 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*))); -} - -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*))); -} - -void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) +void PartSet_WidgetPoint2dDistance::mouseReleased(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) @@ -95,10 +107,13 @@ 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(false).isEmpty()) + emit focusOutWidget(this); } -void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) +void PartSet_WidgetPoint2dDistance::mouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { if (isEditingMode()) return; @@ -112,18 +127,55 @@ 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(); +} + +bool PartSet_WidgetPoint2dDistance::restoreCurentValue() +{ + 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 = mySpinBox->isModified(); + bool isModified = getValueState() == ModifiedInPP; if (isModified) { emit valuesChanged(); - mySpinBox->clearModified(); mySpinBox->selectAll(); } return isModified;