Salome HOME
#1857 In the Sketcher, ability to zoom the view from a given size
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.h
index 3e277c68ddd585b59468e6ce4cc2335259eebc3c..2f0c0980865c5d583b1a8669f8330460a66ea1f1 100644 (file)
@@ -9,25 +9,25 @@
 
 #include "PartSet.h"
 
+#include "PartSet_Tools.h"
+
 #include <ModuleBase_WidgetValidated.h>
 #include <ModuleBase_ViewerFilters.h>
 
-#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Dir.h>
-#include <GeomAPI_AISObject.h>
 
 #include <TopoDS_Shape.hxx>
 
+#include <QMap>
+
+class PartSet_PreviewPlanes;
+
 class QLabel;
-class QTimer;
 class XGUI_OperationMgr;
 class XGUI_Workshop;
-
-/// the plane edge width
-#define SKETCH_WIDTH        "4"
-
-/// face of the square-face displayed for selection of general plane
-#define PLANE_SIZE          "200"
+class QCheckBox;
+class QStackedWidget;
+class QLineEdit;
 
 /**
 * \ingroup Modules
@@ -37,20 +37,27 @@ class XGUI_Workshop;
 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
 {
 Q_OBJECT
- public:
+
+public:
   /// Constructor
   /// \param theParent the parent object
+  /// \param theWorkshop a reference to workshop
   /// \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
-  PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData,
-                            const std::string& theParentId);
+  /// \param toShowConstraints a current show constraints state
+  PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+                      const Config_WidgetAPI* theData,
+                      const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
 
   virtual ~PartSet_WidgetSketchLabel();
 
-  virtual bool restoreValue()
-  {
-    return true;
-  }
+  /// Set the given wrapped value to the current widget
+  /// This value should be processed in the widget according to the needs
+  /// The method is called by the current operation to process the operation preselection.
+  /// It is redefined to do nothing if the plane of the sketch has been already set.
+  /// \param theValues the wrapped selection values
+  /// \param theToValidate a validation flag
+  virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
+                            const bool theToValidate);
 
   /// Returns list of widget controls
   /// \return a control list
@@ -59,13 +66,6 @@ Q_OBJECT
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
-  /// Returns pointer to workshop
-  XGUI_Workshop* workshop() const { return myWorkshop; }
-
-  /// Set pointer to workshop
-  /// \param theWork a pointer to workshop
-  void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
-
   /// Returns sketcher plane
   std::shared_ptr<GeomAPI_Pln> plane() const;
 
@@ -74,25 +74,52 @@ Q_OBJECT
   virtual void setHighlighted(bool) { /*do nothing*/ };
   virtual void enableFocusProcessing();
 
+  /// Returns True if the selected presentation can be used for plane definition
+  /// \param thePrs a presentation
+  static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+
+  /// Set sketch plane from selected object
+  /// \param theFeature a feature of sketch
+  /// \param thePrs a presentation
+  static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
+                                         const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+
 signals:
   /// Signal on plane selection
   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
 
+  /// A show constraint toggled signal
+  /// \param theType a ConstraintVisibleState value
+  /// \param theState a state of the check box
+  void showConstraintToggled(int theType, bool theState);
+
 protected:
   /// 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 isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup);
+  /// \param theAttribute an attribute to be stored
+  virtual void storeAttributeValue(const AttributePtr& theAttribute);
+
+  /// 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 theAttribute an attribute to be restored
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const AttributePtr& theAttribute,
+                                     const bool theValid);
 
   /// Fills the attribute with the value of the selected owner
-  /// \param theOwner a selected owner
-  virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
+  /// \param thePrs a selected owner
+  virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
 
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValueCustom() const
+  virtual bool storeValueCustom()
+  {
+    return true;
+  }
+
+  virtual bool restoreValueCustom()
   {
     return true;
   }
@@ -100,45 +127,65 @@ protected:
   /// The methiod called when widget is activated
   virtual void activateCustom();
 
+  /// Block the model flush of update and intialization of attribute
+  /// In additional to curstom realization it blocks initialization for all feature attributes
+  /// as the current attribute is selection but its modification leads to other attributes change
+  /// \param theAttribute an attribute
+  /// \param theToBlock flag whether the model is blocked or unblocked
+  /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
+  /// to be used to restore flush state when unblocked
+  /// \param isAttributeSetInitializedBlocked out value if model is blocked
+  /// in value if model is unblocked to be used to restore previous state when unblocked
+  virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
+                              bool& isFlushesActived,
+                              bool& isAttributeSetInitializedBlocked);
+
+  /// Set the given wrapped value to the current widget
+  /// This value should be processed in the widget according to the needs
+  /// The method is called by the current operation to process the operation preselection.
+  /// It is redefined to do nothing if the plane of the sketch has been already set.
+  /// \param theValues the wrapped selection values
+  /// \param theToValidate a validation flag
+  bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
+                            const bool theToValidate);
+
+  /// Erase preview planes, disconnect widget, change the view projection
+  /// \param thePrs a selected presentation
+  void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+
+ protected:
+  /// Activate or deactivate selection
+  void activateSelection(bool toActivate);
+
  private slots:
-   /// Slot on plane selection
-  void onPlaneSelected();
+   /// Slot on change selection
+  void onSelectionChanged();
 
-  /// Set sketch specific mode of selection
-  void setSketchingMode();
+  /// A slot called on set sketch plane view
+  void onSetPlaneView();
 
- private:
-   /// Create preview of planes for sketch plane selection
-   /// \param theOrigin an origin of the plane
-   /// \param theNorm a normal vector of the plane
-   /// \param theRGB a color of plane presentation [r, g, b] array
-  AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
-                                  std::shared_ptr<GeomAPI_Dir> theNorm, 
-                                  const int theRGB[3]);
+  /// Emits signal about check box state changed with information about ConstraintVisibleState
+  /// \param theOn a flag show constraints or not
+  void onShowConstraint(bool theOn);
 
+ private:
   /// Set sketch plane by shape
   /// \param theShape a planar face
-  std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
-
-  /// Erase preview planes
-  void erasePreviewPlanes();
-
-  /// Show preview planes
-  void showPreviewPlanes();
+  static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
+                                                     const TopoDS_Shape& theShape);
 
 
-  QLabel* myLabel;
-  QString myText;
-  QString myTooltip;
+private:
+  /// class to show/hide preview planes
+  PartSet_PreviewPlanes* myPreviewPlanes;
 
-  XGUI_Workshop* myWorkshop;
+  QCheckBox* myViewInverted;
 
-  AISObjectPtr myYZPlane;
-  AISObjectPtr myXZPlane;
-  AISObjectPtr myXYPlane;
-  bool myPreviewDisplayed;
+  QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
 
-  QTimer* mySelectionTimer;
+  QWidget* mySizeOfViewWidget;
+  QStackedWidget* myStackWidget;
+  QLineEdit* mySizeOfView;
 };
 
 #endif