Salome HOME
A separation of WidgetSelector class in order to unite the logic of shape/multi shape...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.h
index 9396c21e63167184d10598e9b85b3a0dc9b9fcbc..7cb2427d271c4ca73153d94906d6e7d32f309301 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModuleBase_WidgetShapeSelector.h
 // Created:     2 June 2014
 // Author:      Vitaly Smetannikov
@@ -6,16 +8,17 @@
 #define ModuleBase_WidgetShapeSelector_H
 
 #include "ModuleBase.h"
-#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_WidgetSelector.h"
 #include "ModuleBase_ViewerFilters.h"
+#include <ModuleBase_ViewerPrs.h>
 
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
 #include <GeomAPI_Shape.h>
 
 #include <TopAbs_ShapeEnum.hxx>
 
 #include <QStringList>
-#include <QPalette>
 
 class Config_WidgetAPI;
 class QWidget;
@@ -23,99 +26,123 @@ class QLabel;
 class QLineEdit;
 class QToolButton;
 class ModuleBase_IWorkshop;
-
-class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_ModelWidget
+class ModelAPI_Validator;
+class GeomValidators_ShapeType;
+
+/**
+* \ingroup GUI
+* Implementation of widget for shapes selection.
+* This type of widget can be defined in XML file with 'shape_selector' keyword.
+* For example:
+* \code
+*   <shape_selector id="main_object" 
+*    label="Main object" 
+*    icon=":icons/cut_shape.png" 
+*    tooltip="Select an object solid"
+*    shape_types="solid shell"
+*    concealment="true"
+*  />
+* \endcode
+* It can use following parameters:
+* - id - name of object attribute
+* - label - content of widget's label
+* - icon - icon which can be used instead label
+* - tooltip - the witget's tooltip text
+* - shape_types - list of shape types for selection. 
+*       Possible values: face, vertex, wire, edge, shell, solid
+* - object_types - types of selectable objects. 
+*       For today it supports only one type "construction" 
+*        which corresponds to ModelAPI_ResultConstruction object type
+* - concealment - hide or not hide selected object after operation
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_WidgetSelector
 {
 Q_OBJECT
  public:
-  static TopAbs_ShapeEnum shapeType(const QString& theType);
 
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theWorkshop instance of workshop interface
+  /// \param theData the widget configuation. The attribute of the model widget is obtained from
+  /// \param theParentId is Id of a parent of the current attribute
   ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
-                            const Config_WidgetAPI* theData, const std::string& theParentId);
+                                 const Config_WidgetAPI* theData, const std::string& theParentId);
 
   virtual ~ModuleBase_WidgetShapeSelector();
 
-  /// Saves the internal parameters to the given feature
-  /// \param theObject a model feature to be changed
-  virtual bool storeValue() const;
-
   virtual bool restoreValue();
 
-  virtual bool focusTo();
-
-  /// Returns the internal parent wiget control, that can be shown anywhere
-  /// \returns the widget
-  QWidget* getControl() const
-  {
-    return myContainer;
-  }
-
   /// Returns list of widget controls
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
-  ObjectPtr selectedFeature() const
-  {
-    return mySelectedObject;
-  }
-
-  /// 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);
-
-public slots:
+ protected:
+  /// Saves the internal parameters to the given feature
+  /// \return True in success
+  virtual bool storeValueCustom() const;
 
-  /// Activate or deactivate selection
-  void activateSelection(bool toActivate);
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  virtual void storeAttributeValue();
 
-private slots:
-  void onSelectionChanged();
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid);
 
-protected:
-  bool eventFilter(QObject* theObj, QEvent* theEvent);
+  /// Computes and updates name of selected object in the widget
+  virtual void updateSelectionName();
 
-  void updateSelectionName();
-  void raisePanel() const;
+  /// Clear attribute
+  virtual void clearAttribute();
 
-  /// Returns true if Sape of given object corresponds to requested shape type
-  /// This method is called only in non sub-shapes selection mode
-  virtual bool acceptObjectShape(const ObjectPtr theObject) const;
+  // Update focus after the attribute value change
+  virtual void updateFocus();
 
-  /// Returns true if selected shape corresponds to requested shape types
-  /// This method is called only in sub-shapes selection mode
-  virtual bool acceptSubShape(boost::shared_ptr<GeomAPI_Shape> theShape) const;
+  /// Retunrs a list of possible shape types
+  /// \return a list of shapes
+  virtual QIntList getShapeTypes() const;
 
-  /// Returns true if selected object corresponds to requested Object type
-  /// Thid method is used in any selection mode
-  virtual bool acceptObjectType(const ObjectPtr theObject) const;
+  /// Store the values to the model attribute of the widget. It casts this attribute to
+  /// the specific type and set the given values
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  /// \return true if it is succeed
+  virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
+  /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
+  /// \return a shape
+  virtual GeomShapePtr getShape() const;
 
-  // Set the given object as a value of the widget
-  void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
+  /// Return the attribute values wrapped in a list of viewer presentations
+  /// \return a list of viewer presentations, which contains an attribute result and
+  /// a shape. If the attribute do not uses the shape, it is empty
+  virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
 
   //----------- Class members -------------
-  QWidget* myContainer;
+  protected:
+  /// Label of the widget
   QLabel* myLabel;
-  QLineEdit* myTextLine;
 
-  ModuleBase_IWorkshop* myWorkshop;
-
-  ObjectPtr mySelectedObject;
-  boost::shared_ptr<GeomAPI_Shape> myShape;
+  /// Input control of the widget
+  QLineEdit* myTextLine;
 
+  /// List of accepting shapes types
   QStringList myShapeTypes;
-  QStringList myObjectTypes;
-
-  /// If true then local selector has to be activated in context
-  bool myUseSubShapes;
-
-  QPalette myBasePalet;
-  QPalette myInactivePalet;
-
-  bool myIsActive;
 
-  Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
+  /// backup parameters of the model attribute. The class processes three types of attribute:
+  /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
+  /// values are reserved in the backup
+  /// An attribute object
+  ObjectPtr myObject;
+  /// An attribute shape
+  GeomShapePtr myShape;
+  /// A reference of the attribute
+  AttributePtr myRefAttribute;
+  /// A boolean value whether refAttr uses reference of object
+  bool myIsObject;
 };
 
 #endif