+++ /dev/null
-// 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 <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 <ModuleBase_LabelValue.h>
-
-#include <GeomAPI_Pnt2d.h>
-#include <Config_WidgetAPI.h>
-#include <GeomDataAPI_Point2D.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDouble.h>
-
-#include <QMouseEvent>
-
-PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent,
- ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData)
-: ModuleBase_WidgetLabelValue(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<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 {
- bool isOk;
- double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
- // it is important to block the spin box control in order to do not through out the
- // locking of the validating state.
- myLabel->setValue(isOk ? aDefValue : 0.0);
- storeValue();
- aDone = true;
- }
- }
- return aDone;
-}
-
-void PartSet_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePnt)
-{
- std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aData->attribute(myFirstPntName));
- if (!aPoint)
- return;
-
- double aValue = computeValue(aPoint->pnt(), thePnt);
- AttributeDoublePtr aReal = aData->real(attributeID());
- if (aReal && (aReal->value() != aValue)) {
- aReal->setValue(aValue);
-
- myLabel->setValue(aValue);
- storeValue();
- }
-}
-
-double PartSet_WidgetPoint2dDistance::computeValue(
- const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
- const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt)
-{
- return theCurrentPnt->distance(theFirstPnt);
-}
-
-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)
- 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));
- setPoint(feature(), aPnt);
-
- // if the validator of the control returns false, focus should not be switched
- if (getError(false).isEmpty())
- emit focusOutWidget(this);
-}
-
-void PartSet_WidgetPoint2dDistance::mouseMoved(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 = myLabel->value();
-}
-
-bool PartSet_WidgetPoint2dDistance::restoreCurentValue()
-{
- bool aRestoredAndHidden = true;
-
- bool isVisible = myIsFeatureVisibleInCash;
- // fill the control widgets by the cashed value
-
- myValueIsCashed = false;
- myIsFeatureVisibleInCash = true;
- myLabel->setValue(myValueInCash);
-
- // store value to the model
- storeValueCustom();
- if (isVisible) {
- setValueState(Stored);
- aRestoredAndHidden = false;
- }
- else
- aRestoredAndHidden = true;
-
- return aRestoredAndHidden;
-}
-
-bool PartSet_WidgetPoint2dDistance::processEnter()
-{
- return false;
- /*
- bool isModified = getValueState() == ModifiedInPP;
- if (isModified) {
- emit valuesChanged();
- //mySpinBox->selectAll();
- }
- return isModified;*/
-}
-
-bool PartSet_WidgetPoint2dDistance::storeValueCustom()
-{
- std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
- if (!aData) // can be on abort of sketcher element
- return false;
- AttributeDoublePtr anAttribute = myFeature->data()->real(attributeID());
- anAttribute->setValue(myLabel->value());
-
- // after movement the solver will call the update event: optimization
- updateObject(myFeature);
-
- return true;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PartSet_WidgetPoint2dDistance.h
-// Created: 23 June 2014
-// Author: Vitaly Smetannikov
-
-#ifndef PartSet_WidgetPoint2dDistance_H
-#define PartSet_WidgetPoint2dDistance_H
-
-#include "PartSet.h"
-#include "PartSet_MouseProcessor.h"
-
-#include <ModuleBase_WidgetLabelValue.h>
-
-#include <ModelAPI_CompositeFeature.h>
-
-class GeomAPI_Pnt2d;
-class ModuleBase_IWorkshop;
-class ModuleBase_IViewWindow;
-class QMouseEvent;
-
-/**
-* \ingroup Modules
-* Implementation of model widget for widget which provides input of a distance between two points
-* In XML file can be defined as following:
-* \code
-* <point2ddistance id="CircleRadius"
-* first_point="CircleCenter"
-* label="Radius:"
-* min="0"
-* step="1.0"
-* default="0"
-* icon=":icons/radius.png"
-* tooltip="Set radius">
-* <validator id="GeomValidators_Positive"/>
-* </point2ddistance>
-* \endcode
-*/
-class PARTSET_EXPORT PartSet_WidgetPoint2dDistance : public ModuleBase_WidgetLabelValue,
- public PartSet_MouseProcessor
-{
-Q_OBJECT
- public:
- /// Constructor
- /// \param theParent the parent object
- /// \param theWorkshop a current workshop
- /// \param theData the widget configuation. The attribute of the model widget is obtained from
- PartSet_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData);
-
- virtual ~PartSet_WidgetPoint2dDistance();
-
- /// Checks if the selection presentation is valid in widget
- /// \param theValue a selected presentation in the view
- /// \return a boolean value
- virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
-
- /// \returns the sketch instance
- CompositeFeaturePtr sketch() const { return mySketch; }
-
- /// Set sketch instance
- void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
-
- /// Returns true if the event is processed.
- virtual bool processEnter();
-
- /// Processing the mouse move event in the viewer
- /// \param theWindow a view window
- /// \param theEvent a mouse event
- virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
-
- /// Processing the mouse release event in the viewer
- /// \param theWindow a view window
- /// \param theEvent a mouse event
- virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
-
-protected:
- /// Store current value in cashed value
- void storeCurentValue();
-
- /// Restore cashed value in the model attribute
- /// \return boolean state if the restored feature shoud be hidden
- bool restoreCurentValue();
-
- /// Fills the widget with default values
- /// \return true if the widget current value is reset
- virtual bool resetCustom();
-
- /// Set the second point which defines a value in the widget as
- /// a distance with a first point defined by feature
- void setPoint(FeaturePtr theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePnt);
-
- /// Compute the distance between points
- /// \param theFirstPnt a point value of the out point attribute
- /// \param theCurrentPnt a point of the current widget
- /// \return a double value
- virtual double computeValue(const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPnt,
- const std::shared_ptr<GeomAPI_Pnt2d>& theCurrentPnt);
-
- /// Saves the internal parameters to the given feature
- /// \return True in success
- virtual bool storeValueCustom();
-
-protected:
- /// A reference to workshop
- ModuleBase_IWorkshop* myWorkshop;
-
- /// A name of the first point
- std::string myFirstPntName;
-
- /// Reference to sketch
- CompositeFeaturePtr mySketch;
-
- bool myValueIsCashed; ///< boolean state if the value is cashed during value state change
- bool myIsFeatureVisibleInCash; ///< boolean value if the feature was visible when cash if filled
- double myValueInCash; ///< the cashed X value during value state change
-};
-
-#endif