X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetPoint2dDistance.cpp;h=ee59d8aeef8744ec7f610029c6f6488f914c03f8;hb=857b1f72d9703c46c6c8c9bb239821d314344c86;hp=29c0ad56b66f643e65626ae763fd879d33526ac9;hpb=976244bad37e04fcebaf8866d7d7a02efd2b7d35;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 29c0ad56b..ee59d8aee 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -1,16 +1,18 @@ -// File: PartSet_WidgetPoint2dDistance.h +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_WidgetPoint2dDistance.cpp // Created: 23 June 2014 // Author: Vitaly Smetannikov #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" +#include "PartSet_LockApplyMgr.h" -#include -#include +#include +#include #include - -#include -#include +#include +#include #include #include @@ -22,37 +24,24 @@ #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) { + myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop); + 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())); } 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) { @@ -62,21 +51,31 @@ 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) { - XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); - connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + return theCurrentPnt->distance(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*))); + + myLockApplyMgr->activate(); } void PartSet_WidgetPoint2dDistance::deactivate() @@ -86,10 +85,19 @@ void PartSet_WidgetPoint2dDistance::deactivate() this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); + + myLockApplyMgr->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; @@ -102,6 +110,12 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn 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; @@ -111,4 +125,9 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, setPoint(feature(), aPnt); } +void PartSet_WidgetPoint2dDistance::onValuesChanged() +{ + myLockApplyMgr->valuesChanged(); + emit valuesChanged(); +}