]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Thu, 26 Jun 2014 11:19:33 +0000 (15:19 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 26 Jun 2014 11:19:33 +0000 (15:19 +0400)
The widget value is implemented in order to remove the customization in the operation.

14 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetFeature.cpp
src/ModuleBase/ModuleBase_WidgetFeature.h
src/ModuleBase/ModuleBase_WidgetPoint2D.cpp
src/ModuleBase/ModuleBase_WidgetPoint2D.h
src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp
src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h
src/ModuleBase/ModuleBase_WidgetValue.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetValue.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetValueFeature.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetValueFeature.h [new file with mode: 0644]
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_OperationFeatureCreate.h

index 7fa463bdc6b72aae0baa47c191d813209843259c..2bd3c36c971082bcd636f500dedcb7d58f8c8619 100644 (file)
@@ -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
index 5c8e9da51a8381f0cbac9b22b65841d248d47d9c..96154b37c4245dc85afd378d12cd29f8b0c19bef 100644 (file)
@@ -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
index fc095adedfd09f19890490542e91170832f27c47..d1e2ceea66fc30ea0734f2fd7f534ec6167391da 100644 (file)
@@ -4,6 +4,9 @@
 
 #include <ModuleBase_WidgetFeature.h>
 
+#include <ModuleBase_WidgetValueFeature.h>
+#include <ModuleBase_WidgetValue.h>
+
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 
@@ -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<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()))
index 45891e9226cca19cf9af394d83879c06d66c525e..3d6c60051f4de2290388ac7e6547a85309dbb619 100644 (file)
@@ -11,6 +11,7 @@
 #include <QObject>
 #include <QStringList>
 
+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<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
index a1f5178da28411aa19f85900f8d2443ff893d665..28ddf17a29f3459b2f7789ac5b263c56e4b32638 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Natalia ERMOLAEVA
 
 #include <ModuleBase_WidgetPoint2D.h>
+#include <ModuleBase_WidgetValueFeature.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -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<ModuleBase_WidgetValueFeature*>(theValue);
+    if (aFeatureValue) {
+      setPoint(aFeatureValue->point());
+      isDone = true;
+    }
+  }
+  return isDone;
+}
+
 void ModuleBase_WidgetPoint2D::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
 {
 
index 784f02daabc4908a1915de6433efc95cc52c7db9..4a34641a7683888d3f42a109959070dff53e645f 100644 (file)
@@ -11,6 +11,7 @@
 #include <QObject>
 
 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<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
@@ -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<GeomAPI_Pnt2d>& thePoint);
+
 private:
   QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
   QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate
index 7597fe126f3b86d447dfbb9ab18486cb5e46c751..ed6ae6916f52e3e4e992a41f848762d8dba03173 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Vitaly Smetannikov
 
 #include "ModuleBase_WidgetPoint2dDistance.h"
+#include "ModuleBase_WidgetValueFeature.h"
 
 #include <GeomAPI_Pnt2d.h>
 #include <Config_WidgetAPI.h>
@@ -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<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();
index a078b9b0c8f36d13733a153cc7a681351ed4f4f1..c635aa4f5406a4b96f3bb38c85c3e74518fd37dd 100644 (file)
@@ -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<GeomAPI_Pnt2d>& thePnt);
 
diff --git a/src/ModuleBase/ModuleBase_WidgetValue.cpp b/src/ModuleBase/ModuleBase_WidgetValue.cpp
new file mode 100644 (file)
index 0000000..83a9d27
--- /dev/null
@@ -0,0 +1,13 @@
+// File:        ModuleBase_WidgetValue.cpp
+// Created:     25 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetValue.h>
+
+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 (file)
index 0000000..983d39d
--- /dev/null
@@ -0,0 +1,23 @@
+// 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
diff --git a/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp b/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp
new file mode 100644 (file)
index 0000000..51b39e1
--- /dev/null
@@ -0,0 +1,35 @@
+// 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;
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetValueFeature.h b/src/ModuleBase/ModuleBase_WidgetValueFeature.h
new file mode 100644 (file)
index 0000000..9bdaeb6
--- /dev/null
@@ -0,0 +1,50 @@
+// 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
index a72593906a95032f17e6e6f1d709576ab02e6bda..41a30c5d3533732bde8b9acb395ffd43c349fb14 100644 (file)
@@ -23,8 +23,7 @@
 
 #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>
@@ -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<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;
 }
index 885f8a80eb2ee867b1ffccc6eba59be6fed879ba..d6ca0c77b696a3b520ec9db2794ee9d4e51e1048 100644 (file)
@@ -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