From: nds Date: Thu, 26 Jun 2014 11:19:33 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~225 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0741a16dede895f053a30112a2f2216650accce0;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc The widget value is implemented in order to remove the customization in the operation. --- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 7fa463bdc..2bd3c36c9 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -17,6 +17,8 @@ SET(PROJECT_HEADERS ModuleBase_WidgetSelector.h ModuleBase_IWorkshop.h ModuleBase_WidgetPoint2dDistance.h + ModuleBase_WidgetValue.h + ModuleBase_WidgetValueFeature.h ) SET(PROJECT_SOURCES @@ -33,6 +35,8 @@ SET(PROJECT_SOURCES ModuleBase_WidgetSwitch.cpp ModuleBase_WidgetSelector.cpp ModuleBase_WidgetPoint2dDistance.cpp + ModuleBase_WidgetValue.cpp + ModuleBase_WidgetValueFeature.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 5c8e9da51..96154b37c 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -15,6 +15,7 @@ class Config_WidgetAPI; class ModelAPI_Feature; +class ModuleBase_WidgetValue; class QKeyEvent; /**\class ModuleBase_ModelWidget @@ -36,6 +37,11 @@ public: /// Destructor virtual ~ModuleBase_ModelWidget() {}; + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValue the wrapped widget value + virtual bool setValue(ModuleBase_WidgetValue* theValue) { return false; }; + /// Returns the state whether the attribute of the feature is initialized /// \param theFeature a model feature to be checked /// \return the boolean result diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp index fc095aded..d1e2ceea6 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeature.cpp @@ -4,6 +4,9 @@ #include +#include +#include + #include #include @@ -52,6 +55,19 @@ ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature() { } +bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue) +{ + bool isDone = false; + + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue) + isDone = setFeature(aFeatureValue->feature()); + } + return isDone; +} + bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature) { if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str())) diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.h b/src/ModuleBase/ModuleBase_WidgetFeature.h index 45891e922..3d6c60051 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeature.h +++ b/src/ModuleBase/ModuleBase_WidgetFeature.h @@ -11,6 +11,7 @@ #include #include +class ModuleBase_WidgetValue; class ModelAPI_Feature; class QWidget; class QLabel; @@ -32,9 +33,10 @@ public: /// Destructor virtual ~ModuleBase_WidgetFeature(); - /// Fill the widget values by given point - /// \param thePoint the point - bool setFeature(const FeaturePtr& theFeature); + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValue the wrapped widget value + virtual bool setValue(ModuleBase_WidgetValue* theValue); /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed @@ -50,6 +52,11 @@ public: /// \return a control list virtual QList getControls() const; +protected: + /// Fill the widget values by given point + /// \param thePoint the point + bool setFeature(const FeaturePtr& theFeature); + private: FeaturePtr myFeature; ///< the current widget feature QStringList myFeatureKinds; ///< the kinds of possible features diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index a1f5178da..28ddf17a2 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -3,6 +3,7 @@ // Author: Natalia ERMOLAEVA #include +#include #include #include @@ -72,6 +73,20 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() { } +bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) +{ + bool isDone = false; + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue) { + setPoint(aFeatureValue->point()); + isDone = true; + } + } + return isDone; +} + void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr& thePoint) { diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h index 784f02daa..4a34641a7 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -11,6 +11,7 @@ #include class ModelAPI_Feature; +class ModuleBase_WidgetValue; class GeomAPI_Pnt2d; class QGroupBox; @@ -32,9 +33,10 @@ public: /// Destructor virtual ~ModuleBase_WidgetPoint2D(); - /// Fill the widget values by given point - /// \param thePoint the point - void setPoint(const boost::shared_ptr& thePoint); + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValue the wrapped widget value + virtual bool setValue(ModuleBase_WidgetValue* theValue); /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed @@ -63,6 +65,11 @@ signals: /// \param the attribute of the feature void storedPoint2D(FeaturePtr theFeature, const std::string& theAttribute); +protected: + /// Fill the widget values by given point + /// \param thePoint the point + void setPoint(const boost::shared_ptr& thePoint); + private: QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp index 7597fe126..ed6ae6916 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp @@ -3,6 +3,7 @@ // Author: Vitaly Smetannikov #include "ModuleBase_WidgetPoint2dDistance.h" +#include "ModuleBase_WidgetValueFeature.h" #include #include @@ -23,6 +24,21 @@ ModuleBase_WidgetPoint2dDistance::~ModuleBase_WidgetPoint2dDistance() { } +bool ModuleBase_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue) +{ + bool isDone = false; + + if (theValue) { + ModuleBase_WidgetValueFeature* aFeatureValue = + dynamic_cast(theValue); + if (aFeatureValue) { + setPoint(aFeatureValue->feature(), aFeatureValue->point()); + isDone = true; + } + } + return isDone; +} + void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const boost::shared_ptr& thePnt) { boost::shared_ptr aData = theFeature->data(); diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h index a078b9b0c..c635aa4f5 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h +++ b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h @@ -9,6 +9,7 @@ #include "ModuleBase.h" #include "ModuleBase_WidgetDoubleValue.h" +class ModuleBase_WidgetValue; class GeomAPI_Pnt2d; class MODULEBASE_EXPORT ModuleBase_WidgetPoint2dDistance: public ModuleBase_WidgetDoubleValue @@ -22,6 +23,12 @@ public: virtual ~ModuleBase_WidgetPoint2dDistance(); + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValue the wrapped widget value + virtual bool setValue(ModuleBase_WidgetValue* theValue); + +protected: /// 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 boost::shared_ptr& thePnt); diff --git a/src/ModuleBase/ModuleBase_WidgetValue.cpp b/src/ModuleBase/ModuleBase_WidgetValue.cpp new file mode 100644 index 000000000..83a9d27a7 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetValue.cpp @@ -0,0 +1,13 @@ +// File: ModuleBase_WidgetValue.cpp +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +ModuleBase_WidgetValue::ModuleBase_WidgetValue() +{ +} + +ModuleBase_WidgetValue::~ModuleBase_WidgetValue() +{ +} diff --git a/src/ModuleBase/ModuleBase_WidgetValue.h b/src/ModuleBase/ModuleBase_WidgetValue.h new file mode 100644 index 000000000..983d39d76 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetValue.h @@ -0,0 +1,23 @@ +// File: ModuleBase_WidgetValue.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetValue_H +#define ModuleBase_WidgetValue_H + +#include + +/**\class ModuleBase_WidgetValue + * \ingroup GUI + * \brief Custom widget value. An abstract class to be redefined and to be set in the model widget + */ +class MODULEBASE_EXPORT ModuleBase_WidgetValue +{ +public: + /// Constructor + ModuleBase_WidgetValue(); + /// Destructor + virtual ~ModuleBase_WidgetValue(); +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp b/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp new file mode 100644 index 000000000..51b39e181 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp @@ -0,0 +1,35 @@ +// File: ModuleBase_WidgetValueFeature.cpp +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include + +ModuleBase_WidgetValueFeature::ModuleBase_WidgetValueFeature() +{ +} + +ModuleBase_WidgetValueFeature::~ModuleBase_WidgetValueFeature() +{ +} + +void ModuleBase_WidgetValueFeature::setFeature(const FeaturePtr& theFeature) +{ + myFeature = theFeature; +} + +const FeaturePtr& ModuleBase_WidgetValueFeature::feature() const +{ + return myFeature; +} + +void ModuleBase_WidgetValueFeature::setPoint(const boost::shared_ptr& thePoint) +{ + myPoint = thePoint; +} + +const boost::shared_ptr& ModuleBase_WidgetValueFeature::point() const +{ + return myPoint; +} diff --git a/src/ModuleBase/ModuleBase_WidgetValueFeature.h b/src/ModuleBase/ModuleBase_WidgetValueFeature.h new file mode 100644 index 000000000..9bdaeb619 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetValueFeature.h @@ -0,0 +1,50 @@ +// File: ModuleBase_WidgetValueFeature.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetValueFeature_H +#define ModuleBase_WidgetValueFeature_H + +#include +#include + +#include + +#include + +class GeomAPI_Pnt2d; + +/**\class ModuleBase_WidgetValueFeature + * \ingroup GUI + * \brief Custom widget value. The widget contains a feature and 2D point. + */ +class MODULEBASE_EXPORT ModuleBase_WidgetValueFeature : public ModuleBase_WidgetValue +{ +public: + /// Constructor + ModuleBase_WidgetValueFeature(); + /// Destructor + virtual ~ModuleBase_WidgetValueFeature(); + + /// Fill the widget values by given point + /// \param thePoint the point + void setFeature(const FeaturePtr& theFeature); + + /// Returns the widget values by given point + /// \return theFeature the current feature + const FeaturePtr& feature() const; + + /// Fill the widget values by given point + /// \param thePoint the point + void setPoint(const boost::shared_ptr& thePoint); + + /// Returns the widget point + /// \return the current point + const boost::shared_ptr& point() const; + +private: + FeaturePtr myFeature; + boost::shared_ptr myPoint; +}; + +#endif diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index a72593906..41a30c5d3 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -23,8 +23,7 @@ #include #include -#include -#include +#include #include #include @@ -147,17 +146,15 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle } } } - bool isApplyed = false; - if (isPointWidget()) - isApplyed = setWidgetPoint(aX, anY); - else { - if (!theSelected.empty()) { - XGUI_ViewerPrs aPrs = theSelected.front(); - FeaturePtr aFeature = aPrs.feature(); - if (aFeature) - isApplyed = setWidgetFeature(aFeature); - } + FeaturePtr aFeature; + if (!theSelected.empty()) { + XGUI_ViewerPrs aPrs = theSelected.front(); + aFeature = aPrs.feature(); } + else + aFeature = feature(); // for the widget distance only + + bool isApplyed = setWidgetValue(aFeature, aX, anY); if (isApplyed) { flushUpdated(); emit activateNextWidget(myActiveWidget); @@ -174,7 +171,7 @@ void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3 double aX, anY; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView); PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - setWidgetPoint(aX, anY); + setWidgetValue(feature(), aX, anY); flushUpdated(); } } @@ -274,34 +271,14 @@ FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMess return aNewFeature; } -bool PartSet_OperationFeatureCreate::isPointWidget() const +bool PartSet_OperationFeatureCreate::setWidgetValue(FeaturePtr theFeature, double theX, double theY) { - return dynamic_cast(myActiveWidget) || - dynamic_cast(myActiveWidget); -} + ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature(); + aValue->setFeature(theFeature); + aValue->setPoint(boost::shared_ptr(new GeomAPI_Pnt2d(theX, theY))); + bool isApplyed = myActiveWidget->setValue(aValue); -bool PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY) -{ - boost::shared_ptr aPoint(new GeomAPI_Pnt2d(theX, theY)); - ModuleBase_WidgetPoint2D* aWidget = dynamic_cast(myActiveWidget); - if (aWidget) { - aWidget->setPoint(aPoint); - return true; - } else { - ModuleBase_WidgetPoint2dDistance* aWgt = dynamic_cast(myActiveWidget); - if (aWgt) { - aWgt->setPoint(feature(), aPoint); - return true; - } - } - return false; -} - -bool PartSet_OperationFeatureCreate::setWidgetFeature(const FeaturePtr& theFeature) -{ - ModuleBase_WidgetFeature* aWidget = dynamic_cast(myActiveWidget); - if (!aWidget) - return false; + delete aValue; - return aWidget->setFeature(theFeature); + return isApplyed; } diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index 885f8a80e..d6ca0c77b 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -115,20 +115,12 @@ protected: virtual FeaturePtr createFeature(const bool theFlushMessage = true); protected: - /// Returns true if the active widget is the point selector widget - /// \return the boolean value - bool isPointWidget() const; - - /// Set the point to the active widget + /// Set value to the active widget + /// \param theFeature the feature /// \param theX the horizontal coordinate /// \param theY the vertical coordinate /// \return true if the point is set - bool setWidgetPoint(double theX, double theY); - - /// Set the feature to the active widget - /// \param theFeature a feature - /// \return true if the feature is set - bool setWidgetFeature(const FeaturePtr& theFeature); + bool setWidgetValue(FeaturePtr theFeature, double theX, double theY); private: FeaturePtr myInitFeature; ///< the initial feature