The widget value is implemented in order to remove the customization in the operation.
ModuleBase_WidgetSelector.h
ModuleBase_IWorkshop.h
ModuleBase_WidgetPoint2dDistance.h
+ ModuleBase_WidgetValue.h
+ ModuleBase_WidgetValueFeature.h
)
SET(PROJECT_SOURCES
ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetSelector.cpp
ModuleBase_WidgetPoint2dDistance.cpp
+ ModuleBase_WidgetValue.cpp
+ ModuleBase_WidgetValueFeature.cpp
)
SET(PROJECT_LIBRARIES
class Config_WidgetAPI;
class ModelAPI_Feature;
+class ModuleBase_WidgetValue;
class QKeyEvent;
/**\class ModuleBase_ModelWidget
/// 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
#include <ModuleBase_WidgetFeature.h>
+#include <ModuleBase_WidgetValueFeature.h>
+#include <ModuleBase_WidgetValue.h>
+
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
{
}
+bool ModuleBase_WidgetFeature::setValue(ModuleBase_WidgetValue* theValue)
+{
+ bool isDone = false;
+
+ if (theValue) {
+ ModuleBase_WidgetValueFeature* aFeatureValue =
+ dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+ if (aFeatureValue)
+ isDone = setFeature(aFeatureValue->feature());
+ }
+ return isDone;
+}
+
bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
{
if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str()))
#include <QObject>
#include <QStringList>
+class ModuleBase_WidgetValue;
class ModelAPI_Feature;
class QWidget;
class QLabel;
/// 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
/// \return a control list
virtual QList<QWidget*> 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
// Author: Natalia ERMOLAEVA
#include <ModuleBase_WidgetPoint2D.h>
+#include <ModuleBase_WidgetValueFeature.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
{
}
+bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue)
+{
+ bool isDone = false;
+ if (theValue) {
+ ModuleBase_WidgetValueFeature* aFeatureValue =
+ dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+ if (aFeatureValue) {
+ setPoint(aFeatureValue->point());
+ isDone = true;
+ }
+ }
+ return isDone;
+}
+
void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
{
#include <QObject>
class ModelAPI_Feature;
+class ModuleBase_WidgetValue;
class GeomAPI_Pnt2d;
class QGroupBox;
/// Destructor
virtual ~ModuleBase_WidgetPoint2D();
- /// Fill the widget values by given point
- /// \param thePoint the point
- void setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& 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
/// \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<GeomAPI_Pnt2d>& thePoint);
+
private:
QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate
// Author: Vitaly Smetannikov
#include "ModuleBase_WidgetPoint2dDistance.h"
+#include "ModuleBase_WidgetValueFeature.h"
#include <GeomAPI_Pnt2d.h>
#include <Config_WidgetAPI.h>
{
}
+bool ModuleBase_WidgetPoint2dDistance::setValue(ModuleBase_WidgetValue* theValue)
+{
+ bool isDone = false;
+
+ if (theValue) {
+ ModuleBase_WidgetValueFeature* aFeatureValue =
+ dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
+ if (aFeatureValue) {
+ setPoint(aFeatureValue->feature(), aFeatureValue->point());
+ isDone = true;
+ }
+ }
+ return isDone;
+}
+
void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const boost::shared_ptr<GeomAPI_Pnt2d>& thePnt)
{
boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
#include "ModuleBase.h"
#include "ModuleBase_WidgetDoubleValue.h"
+class ModuleBase_WidgetValue;
class GeomAPI_Pnt2d;
class MODULEBASE_EXPORT ModuleBase_WidgetPoint2dDistance: public ModuleBase_WidgetDoubleValue
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<GeomAPI_Pnt2d>& thePnt);
--- /dev/null
+// File: ModuleBase_WidgetValue.cpp
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetValue.h>
+
+ModuleBase_WidgetValue::ModuleBase_WidgetValue()
+{
+}
+
+ModuleBase_WidgetValue::~ModuleBase_WidgetValue()
+{
+}
--- /dev/null
+// File: ModuleBase_WidgetValue.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetValue_H
+#define ModuleBase_WidgetValue_H
+
+#include <ModuleBase.h>
+
+/**\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
--- /dev/null
+// File: ModuleBase_WidgetValueFeature.cpp
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetValueFeature.h>
+
+#include <GeomAPI_Pnt2d.h>
+
+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<GeomAPI_Pnt2d>& thePoint)
+{
+ myPoint = thePoint;
+}
+
+const boost::shared_ptr<GeomAPI_Pnt2d>& ModuleBase_WidgetValueFeature::point() const
+{
+ return myPoint;
+}
--- /dev/null
+// File: ModuleBase_WidgetValueFeature.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetValueFeature_H
+#define ModuleBase_WidgetValueFeature_H
+
+#include <ModuleBase.h>
+#include <ModuleBase_WidgetValue.h>
+
+#include <ModelAPI_Feature.h>
+
+#include <boost/shared_ptr.hpp>
+
+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<GeomAPI_Pnt2d>& thePoint);
+
+ /// Returns the widget point
+ /// \return the current point
+ const boost::shared_ptr<GeomAPI_Pnt2d>& point() const;
+
+private:
+ FeaturePtr myFeature;
+ boost::shared_ptr<GeomAPI_Pnt2d> myPoint;
+};
+
+#endif
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
-#include <ModuleBase_WidgetFeature.h>
-#include <ModuleBase_WidgetPoint2dDistance.h>
+#include <ModuleBase_WidgetValueFeature.h>
#include <XGUI_ViewerPrs.h>
#include <XGUI_Constants.h>
}
}
}
- 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);
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();
}
}
return aNewFeature;
}
-bool PartSet_OperationFeatureCreate::isPointWidget() const
+bool PartSet_OperationFeatureCreate::setWidgetValue(FeaturePtr theFeature, double theX, double theY)
{
- return dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget) ||
- dynamic_cast<ModuleBase_WidgetPoint2dDistance*>(myActiveWidget);
-}
+ ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
+ aValue->setFeature(theFeature);
+ aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
+ bool isApplyed = myActiveWidget->setValue(aValue);
-bool PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY)
-{
- boost::shared_ptr<GeomAPI_Pnt2d> aPoint(new GeomAPI_Pnt2d(theX, theY));
- ModuleBase_WidgetPoint2D* aWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
- if (aWidget) {
- aWidget->setPoint(aPoint);
- return true;
- } else {
- ModuleBase_WidgetPoint2dDistance* aWgt = dynamic_cast<ModuleBase_WidgetPoint2dDistance*>(myActiveWidget);
- if (aWgt) {
- aWgt->setPoint(feature(), aPoint);
- return true;
- }
- }
- return false;
-}
-
-bool PartSet_OperationFeatureCreate::setWidgetFeature(const FeaturePtr& theFeature)
-{
- ModuleBase_WidgetFeature* aWidget = dynamic_cast<ModuleBase_WidgetFeature*>(myActiveWidget);
- if (!aWidget)
- return false;
+ delete aValue;
- return aWidget->setFeature(theFeature);
+ return isApplyed;
}
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