Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.h
index a7118e899e09b4035258cbe6fa80edb2e264179b..14d88a1688e56f4ea9194efdd9f4dcba0e17f280 100644 (file)
@@ -1,32 +1,63 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        PartSet_SketcherMgr.h
-// Created:     19 Dec 2014
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2023  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #ifndef PartSet_SketcherMgr_H
 #define PartSet_SketcherMgr_H
 
 #include "PartSet.h"
 
-#include "PartSet_Filters.h"
+#include "PartSet_PreviewSketchPlane.h"
 #include "PartSet_Tools.h"
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Result.h>
+#include <Events_Listener.h>
+#include <ModuleBase_SelectionFilterType.h>
 
-#include <ModuleBase_ViewerFilters.h>
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ModelWidget.h>
 
 #include <GeomAPI_Pln.h>
+#include <GeomAPI_AISObject.h>
+
+#ifdef HAVE_SALOME
+  #include <OCCViewer_ViewModel.h>
+#else
+  #include <AppElements_Viewer.h>
+#endif
+
+
 #include <SelectMgr_IndexedMapOfOwner.hxx>
+#include <SelectMgr_ListOfFilter.hxx>
+
+#include <TopoDS_Shape.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <AIS_Shape.hxx>
 
 #include <QObject>
 #include <QList>
 #include <QMap>
+#include <QPoint>
+
+#include <set>
 
 class PartSet_Module;
 class ModuleBase_IViewWindow;
@@ -34,8 +65,35 @@ class ModuleBase_ModelWidget;
 class ModuleBase_Operation;
 class XGUI_OperationMgr;
 class XGUI_Workshop;
+class XGUI_Displayer;
+class PartSet_ExternalPointsMgr;
+
+class AIS_InteractiveObject;
 
 class QMouseEvent;
+class PartSet_SketcherMgr;
+
+#ifdef HAVE_SALOME
+class PartSet_Fitter : public OCCViewer_Fitter
+#else
+class PartSet_Fitter : public AppElements_Fitter
+#endif
+{
+public:
+  PartSet_Fitter(PartSet_SketcherMgr* theSketchMgr):
+    mySketchMgr(theSketchMgr) {}
+
+  virtual ~PartSet_Fitter() {}
+
+  /// A method which has top be reimplemented to provide alterantive implementation FitAll command
+  /// \param theView - a view which has to be fit
+  virtual void fitAll(Handle(V3d_View) theView);
+
+private:
+  PartSet_SketcherMgr* mySketchMgr;
+};
+
+
 
 /**
 * \ingroup Modules
@@ -44,7 +102,7 @@ class QMouseEvent;
   displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
   are hidden, the sketch feature result is displayed
 */
-class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
+class PARTSET_EXPORT PartSet_SketcherMgr : public QObject, public Events_Listener
 {
   Q_OBJECT
   /// Struct to define gp point, with the state is the point is initialized
@@ -77,6 +135,19 @@ class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
     bool myIsInitialized;  /// the state whether the point is set
     double myCurX, myCurY; /// the point coordinates
   };
+
+public:
+  /// Struct to define selection model information to store/restore selection
+  struct SelectionInfo
+  {
+    /// the selected attributes and indices of points if array
+    std::map<AttributePtr, int> myAttributes;
+    std::set<ResultPtr> myResults; /// the selected results
+    TopoDS_Shape myFirstResultShape; /// the first shape of feature result
+    TopTools_MapOfShape myLocalSelectedShapes; /// shapes of local selection
+  };
+  typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
+
 public:
   /// Constructor
   /// \param theModule a pointer to PartSet module
@@ -89,26 +160,41 @@ public:
   /// \return the boolean result
   static bool isSketchOperation(ModuleBase_Operation* theOperation);
 
-  /// Returns true if the operation id is in the sketch operation id list
+  /// Returns true if the operation feature belongs to list of granted features of Sketch
+  /// operation. An operation of a sketch should be started before.
   /// \param theOperation an operation
   /// \return the boolean result
-  static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
+  bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
 
-  /// Returns true if the operation is a create nested feature one
+  /// Returns true if the feature kind belongs to list of granted features of Sketch
+  /// operation. An operation of a sketch should be started before.
+  /// \param theOperation an operation
+  /// \return the boolean result
+  bool isNestedSketchFeature(const QString& theFeatureKind) const;
+
+  /// Returns true if the operation is a create and nested sketch operationn
   /// \param theOperation a checked operation
+  /// \param theSketch a sketch feature
   //// \return boolean value
-  static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
+  bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
+                                      const CompositeFeaturePtr& /*theSketch*/) const;
 
   /// Returns true if the operation is an edit nested feature one
   /// \param theOperation a checked operation
   //// \return boolean value
-  static bool isNestedEditOperation(ModuleBase_Operation* theOperation);
+  bool isNestedEditOperation(ModuleBase_Operation* theOperation,
+                                    const CompositeFeaturePtr& /*theSketch*/) const;
 
   /// Returns whether the current operation is a sketch entity - line, point, arc or circle
   /// \param theId is an id of object
   /// \return a boolean value
   static bool isEntity(const std::string& theId);
 
+  /// Returns whether the feature has external attribute filled with 'true' value
+  /// \param theFeature a feature object
+  /// \return a boolean value
+  static bool isExternalFeature(const FeaturePtr& theFeature);
+
   /// Returns whether the current operation is a sketch distance - lenght, distance or radius
   /// \param theOperation the operation
   /// \return a boolean value
@@ -125,6 +211,10 @@ public:
   /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
   CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
 
+  /// Returns help class to visualize sketcher plane
+  /// \return a preview plane
+  PartSet_PreviewSketchPlane* previewSketchPlane() const { return mySketchPlane; }
+
   /// Starts sketch operation
   void startSketch(ModuleBase_Operation* );
 
@@ -143,9 +233,16 @@ public:
   /// \param theOperation a committed operation
   void commitNestedSketch(ModuleBase_Operation* theOperation);
 
-  /// Append the sketch plane filter into the current viewer
-  /// \param toActivate state whether the filter should be activated/deactivated
-  void activatePlaneFilter(const bool& toActivate);
+  /// Returns true if the filter is created by the sketch manager
+  /// \param theFilterType a checked type
+  /// \return boolean value
+  bool sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType);
+
+  /// Append selection filter into the module and type of the filter in internal container
+  /// \param theFilterType selection filter type
+  /// \param theFilter added filter
+  void registerSelectionFilter(const ModuleBase_SelectionFilterType theFilterType,
+                               const Handle(SelectMgr_Filter)& theFilter);
 
   /// Commit the operation if it is possible. If the operation is dimention constraint,
   /// it gives widget editor to input dimention value
@@ -188,7 +285,7 @@ public:
   /// Check the given objects either there are some results of the current sketch. If so,
   /// it suggests to delete them as there are no functionality to show back hidden sketch objects
   /// \param theObjects a list of hidden objects
-  virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
+  //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
 
   /// Returns true if the mouse is over viewer or property panel value is changed
   /// \return boolean result
@@ -198,7 +295,7 @@ public:
   /// \param theOperation an operation
   bool canChangeCursor(ModuleBase_Operation* theOperation) const;
 
-  /// Returns state of constraints showing flag 
+  /// Returns state of constraints showing flag
   const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
 
   /// Returns true if the object is a current sketch sub feature of a result of the feature
@@ -206,13 +303,23 @@ public:
   /// \return boolean value
   bool isObjectOfSketch(const ObjectPtr& theObject) const;
 
+  /// Enumeration for selection mode used
+  enum SelectionType {
+    ST_HighlightType, /// Only highlighted objects
+    ST_SelectType, /// Only selected objects
+    ST_SelectAndHighlightType /// Both, highlighted and selected objects
+  };
+
   /// Saves the current selection in the viewer into an internal container
-  /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
+  /// It obtains the selected attributes.
+  /// The highlighted objects can be processes as the selected ones
   /// \param theHighlightedOnly a boolean flag
-  void storeSelection(const bool theHighlightedOnly = false);
+  /// \param theCurrentSelection a container filled by the current selection
+  void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
 
   /// Restores previously saved selection state
-  void restoreSelection();
+  /// \param theCurrentSelection a container filled by the current selection
+  void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
 
   /// Return error state of the sketch feature, true if the error has happened
   /// \return boolean value
@@ -228,15 +335,21 @@ public:
   /// It nullify internal flags concerned to clicked mouse event
   void clearClickedFlags();
 
-  /// Returns list of strings which contains id's of sketch operations
-  static const QStringList& sketchOperationIdList();
+  /// Returns list of strings which contains id's of sketch replication operations
+  static const QStringList& replicationsIdList();
 
   /// Returns list of strings which contains id's of constraints operations
   static const QStringList& constraintsIdList();
 
   /// Returns a list of modes, where the AIS objects should be activated
+  /// \param theSketch a sketch object, modes are empty if sketch plane is not defined yet
   /// \param theModes a list of modes
-  static void sketchSelectionModes(QIntList& theModes);
+  static void sketchSelectionModes(const CompositeFeaturePtr& theSketch, QIntList& theModes);
+
+  /// Create specific for the module presentation
+  /// \param theResult an object for presentation
+  /// \return created presentation or NULL(default value)
+  Handle(AIS_InteractiveObject) createPresentation(const ObjectPtr& theResult);
 
   /// Connects or disconnects to the value changed signal of the property panel widgets
   /// \param theWidget a property contol widget
@@ -247,14 +360,45 @@ public:
   /// \param thePreviousState the previous widget value state
   void widgetStateChanged(int thePreviousState);
 
+  /// If the current operation is a dimention one, the style of dimension visualization is send for
+  /// the current object
+  /// \param theObject an object to be customized
+  //void customisePresentation(const ObjectPtr& theObject);
+
+  void customizeSketchPresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const;
+
+  /// Update sketch presentations according to the the state
+  /// \param theType a type of sketch visualization style
+  /// \param theState a boolean state
+  void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
+                                bool theState);
+
+  bool isShowFreePointsShown() const {
+    return myPointsHighlight.size() > 0;
+  }
+
+  PartSet_Module* module() const { return myModule; }
+
+  /** \brief Implementation of Event Listener method
+  *  \param[in] theMessage the data of the event
+  */
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
+  /// Returns true if current mode of objects creation is by drag mouse
+  bool isDragModeCreation() const;
+
+
 public slots:
   /// Process sketch plane selected event
   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
 
-  /// Toggle show constraints
-  void onShowConstraintsToggle(int theType, bool theState);
+  /// The slot is called when user checks "Show free points" button
+  /// \param toShow a state of the check box
+  void onShowPoints(bool toShow);
 
 private slots:
+  /// Toggle show constraints
+  void onShowConstraintsToggle(int theType, bool theState);
   /// Process the enter mouse to the view port. If the current operation is a create of
   /// a nested sketch feature, it updates internal flags to display the feature on mouse move
   void onEnterViewPort();
@@ -262,9 +406,10 @@ private slots:
   /// a nested sketch feature, it hides the feature in the viewer
   void onLeaveViewPort();
   /// Listens to the value changed signal and display the current operation feature
-  void onBeforeValuesChangedInPropertyPanel();
-  /// Listens to the signal about the modification of the values have been done in the property panel
-  void onAfterValuesChangedInPropertyPanel();
+  //void onBeforeValuesChangedInPropertyPanel();
+  /// Listens to the signal about the modification of the values
+  /// have been done in the property panel
+  //void onAfterValuesChangedInPropertyPanel();
 
   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
@@ -280,35 +425,19 @@ private:
   /// Launches the operation from current highlighting
   void launchEditing();
 
-  /// Converts mouse position to 2d coordinates. 
+  /// Converts mouse position to 2d coordinates.
   /// Member myCurrentSketch has to be correctly defined
-  void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
+  void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
                   Point& thePoint);
 
   /// Show distance value editor if it is a distance operation and all attribute references
   /// are filled by preseletion
   /// \return true if the value is accepted
   static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
-                                             ModuleBase_IWorkshop* theWorkshop);
+                                             ModuleBase_IWorkshop* theWorkshop,
+                                             bool& theCanCommitOperation);
 
-  typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
-                                                                       FeatureToSelectionMap;
-
-  /// Obtains the current selection of the object in the workshop viewer 
-  /// It includes the selection in all modes of activation, even local context - vertices, edges
-  /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
-  /// selection owners. If the owner is vertex, the corresponded attribute is seached in
-  /// the feature, if the owner is edge, the current result is added to the container of results.
-  /// \param theFeature a feature or result object
-  /// \param theSketch a current sketch feature
-  /// \param theWorkshop a workshop to have an access to AIS context and displayer
-  /// \param theSelection a container for the selection, to save results and attributres for a feature
-  static void getCurrentSelection(const FeaturePtr& theFeature,
-                                  const FeaturePtr& theSketch,
-                                  ModuleBase_IWorkshop* theWorkshop,
-                                  FeatureToSelectionMap& theSelection);
-
-  /// Applyes the current selection to the object in the workshop viewer 
+  /// Applyes the current selection to the object in the workshop viewer
   /// It includes the selection in all modes of activation, even local context - vertexes, edges
   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
@@ -324,10 +453,10 @@ private:
                                   const FeaturePtr& theSketch,
                                   ModuleBase_IWorkshop* theWorkshop,
                                   const FeatureToSelectionMap& theSelection,
-                                  SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
+                                  SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
 
   /// Returns true if the created feature is visible
-  /// \param 
+  /// \param
   bool isVisibleCreatedFeature() const;
 
   /// Returns a current operation
@@ -339,37 +468,56 @@ private:
 
   /// Erase or display the feature of the current operation. If the mouse over the active view or
   /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
-  /// \param theOperation an operation which feature is to be displayed, it is nested create operation
+  /// \param theOperation an operation which feature is to be displayed,
+  ///                     it is nested create operation
   /// \param isToDisplay a flag about the display or erase the feature
   void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
                         const bool isToDisplay, const bool isFlushRedisplay = true);
 
 private:
+  /// Updates selection priority of the presentation
+  /// \param theObject object to find a presentation which will be corrected
+  /// \param theFeature a feature of the presentation
+  void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
   /// Returns current workshop
   XGUI_Workshop* workshop() const;
   /// Returns operation manager
   XGUI_OperationMgr* operationMgr() const;
 
+  std::vector<int> colorOfObject(const ObjectPtr& theObject,
+    const FeaturePtr& aFeature, bool isConstruction) const;
+
 private:
   PartSet_Module* myModule;
+  PartSet_PreviewSketchPlane* mySketchPlane; // display/erase sketch plane on start/stop sketch
 
   bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
+  bool myIsEditLaunching;
   bool myIsDragging;
   bool myDragDone;
   bool myIsMouseOverWindow; /// the state that the mouse over the view
-  bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
+  /// the state whether the over view state is processed by mouseMove method
+  bool myIsMouseOverViewProcessed;
   bool myIsPopupMenuActive; /// the state of the popup menu is shown
   Point myCurrentPoint;
   //Point myClickedPoint;
 
   CompositeFeaturePtr myCurrentSketch;
 
-  Handle(PartSet_CirclePointFilter) myCirclePointFilter;
-  Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
+  std::set<ModuleBase_SelectionFilterType> mySelectionFilterTypes;
+
   FeatureToSelectionMap myCurrentSelection;
   bool myPreviousUpdateViewerEnabled;
 
   QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
+
+  PartSet_ExternalPointsMgr* myExternalPointsMgr;
+
+  QMap<ResultPtr, Handle(AIS_Shape)> myPointsHighlight;
+
+  bool myNoDragMoving;
+
+  QPoint myMousePoint;
 };