// 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 <ModuleBase_DoubleSpinBox.h>
-#include <ModuleBase_IViewWindow.h>
-
-#include <XGUI_ViewerProxy.h>
+#include <XGUI_Tools.h>
#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
+#include <ModuleBase_ParamSpinBox.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewWindow.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_WidgetValidator.h>
#include <GeomAPI_Pnt2d.h>
#include <Config_WidgetAPI.h>
#include <QMouseEvent>
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");
+ myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
}
PartSet_WidgetPoint2dDistance::~PartSet_WidgetPoint2dDistance()
{
}
-//bool PartSet_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
-//{
-// bool isDone = false;
-//
-// if (theValue) {
-// ModuleBase_WidgetValueFeature* aFeatureValue =
-// dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
-// if (aFeatureValue) {
-// std::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
-// ObjectPtr aObject = aFeatureValue->object();
-// FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
-// if (aFeature && aPnt) {
-// setPoint(aFeature, aPnt);
-// isDone = true;
-// }
-// }
-// }
-// return isDone;
-//}
+bool PartSet_WidgetPoint2dDistance::isValidSelectionCustom(
+ const std::shared_ptr<ModuleBase_ViewerPrs>& 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<GeomAPI_Pnt2d>& thePnt)
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<GeomAPI_Pnt2d>& theFirstPnt,
+ const std::shared_ptr<GeomAPI_Pnt2d>& 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*)));
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*)));
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;
std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(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)
{
+ 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<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(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 = getValueState() == ModifiedInPP;
+ if (isModified) {
+ emit valuesChanged();
+ mySpinBox->selectAll();
+ }
+ return isModified;
+}