Salome HOME
Issue #1863: Edit multi-lines
[modules/shaper.git] / src / PartSet / PartSet_SketcherReetntrantMgr.h
index a3513ac6dfd4ed7864c271340d741e2f59dd1a8e..647d214eed91f79f0bdac0ac078eea7567c0086c 100755 (executable)
 class ModuleBase_IWorkshop;
 class ModuleBase_Operation;
 class ModuleBase_ModelWidget;
+class ModuleBase_IViewWindow;
+
+class ModelAPI_CompositeFeature;
+
+class QMouseEvent;
 
 class XGUI_Workshop;
 class PartSet_Module;
@@ -21,10 +26,11 @@ class PartSet_Module;
 /// \ingroup PartSet_SketcherReetntrantMgr
 /// It provides reentrant create operations in sketch, that is when all inputs are valid,
 /// automatic validation of the creation and switch the created entity to edit mode
-/// ('internal' edit operation),
-/// with the ability to simultaneously create the next entity of same type (re-entrance of the operation).
+/// ('internal' edit operation), with the ability to simultaneously create the next entity
+/// of same type (re-entrance of the operation).
 /// OK valids the current edition and exits from the operation (no re-entrance).
-/// Cancel removes (undo) the entity currently edited and exits from the operation (no re-entrance).
+/// Cancel removes (undo) the entity currently edited and 
+/// exits from the operation (no re-entrance).
 class PARTSET_EXPORT PartSet_SketcherReetntrantMgr : public QObject
 {
 Q_OBJECT
@@ -33,89 +39,155 @@ Q_OBJECT
 enum RestartingMode {
   RM_None, /// the operation should not be restarted
   RM_Forbided, /// the operation should not be restarted after there is no active widget
-  RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
+  RM_LastFeatureUsed, /// the operation is restarted and use 
+                      /// the previous feature for own initialization
   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
 };
 
 public:
   /// Constructor
-  /// \param theParent a parent object
+  /// \param theWorkshop a workshop instance
   PartSet_SketcherReetntrantMgr(ModuleBase_IWorkshop* theWorkshop);
   virtual ~PartSet_SketcherReetntrantMgr();
 
 public:
-  /// If the internal edit operation is started, this is the first widget of the operation
-  ModuleBase_ModelWidget* activeWidget() const;
-
-  /// Restarts sketcher operation automatically. If the commited operation is created, it starts
-  /// an 'internal' edit operation for the created feature. If an 'internal' operation is committed,
-  /// a create operation for a new feature with the current feature kind is started.
-  /// Some internal flags are taken into accout, such as whether the previous feature should be
-  /// used for initialization of created one or whether the restart of operation is forbidden.
-  /// \param theOperation a committed operation
-  /// \return true if an operation restarted
+  /// Returns a first widget of the current opeation if the internal edit operation is active
+  /// or return null. If the current widget of the operation is a viewer selector, it returns null.
+  ModuleBase_ModelWidget* internalActiveWidget() const;
+
+  /// Return true if the current edit operation is an internal
+  bool isInternalEditActive() const;
+
+  /// Stop internal edit if the operation feature is invalid
+  void updateInternalEditActiveState();
+
+  /// if the internal flags allow it and the manager is active, it starts an internal edit operation
+  /// for the created operation.
+  /// \param thePreviousAttributeID an index of the previous active attribute
+  //bool restartOperation(const std::string& thePreviousAttributeID);
+  bool processEnter(const std::string& thePreviousAttributeID);
+
+  /// Resets the internal flags
+  /// \param theOperation a started operation
+  void operationStarted(ModuleBase_Operation* theOperation);
+
+  /// Resets the internal flags
+  /// \param theOperation a started operation
+  /// \return state whether the internal edit operation was active
   bool operationCommitted(ModuleBase_Operation* theOperation);
 
-  /// \param theOperation a committed operation
+  /// Resets the internal flags
+  /// \param theOperation a started operation
   void operationAborted(ModuleBase_Operation* theOperation);
 
   /// Return true if the manager processes the mouse move event
   /// It happens if the current operation is an internal edit operation and the first
-  /// control can be filled by the mouse move event. The operation is committed.
+  /// control can be filled by the mouse move event. The operation is restarted.
   /// \return true if operation is committed.
-  bool processMouseMoved();
+  bool processMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
 
   /// Return true if the manager processes the mouse press event
   /// \return true if the current operation is an internal edit operation.
-  bool processMousePressed();
+  bool processMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
 
   /// Return true if the manager processes the mouse enter event
   /// It happens if the current operation is an internal edit operation.
-  /// The operation is committed.
+  /// The operation is restarted. If the first widget of the started operation is
+  /// the point 2d, it processes this mouse event
   /// \return true if operation is committed.
-  bool processMouseReleased();
+  bool processMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
 
-  /// Activates the operation widgets relatively the internal reentrant flags
-  void propertyPanelDefined(ModuleBase_Operation* theOperation);
+  /// It is called by the current operation filling with the preselection.
+  /// Returns false if the reentrant mode of the operation is not empty.
+  bool canBeCommittedByPreselection();
 
-  /// It is called by no more widget signal emitted by property panel
-  /// Set a specific flag to restart the sketcher operation
-  void noMoreWidgets(const std::string& thePreviousAttributeID);
+  /// returns true if an internal edit operation is started
+  /// \return boolean value
+  bool isInternalEditStarted() const;
 
-  /// Processing of vertex selected, if the feature is line, save flags to stop reentrant operation
-  void vertexSelected();
+private slots:
+  /// SLOT, that is called by a widget activating in the property panel
+  /// If the 'internal' edit operation is started, it activates the first widget selection
+  void onWidgetActivated();
 
-  /// It is called by enter key released
-  /// Set a specific type of restarting the current operation
-  void enterReleased();
+  /// SLOT, that is called by no more widget signal emitted by property panel
+  /// Start an internal edit operation or, if the internal flag is forbided, commits
+  /// the current operation
+  /// \param thePreviousAttributeID an index of the previous active attribute
+  void onNoMoreWidgets(const std::string& thePreviousAttributeID);
 
-  /// It is called by the current operation filling with the preselection.
-  /// Returns false if the reentrant mode of the operation is not empty.
-  bool canBeCommittedByPreselection();
+  /// Processing of vertex selected. Set an internal reentrant flag to forbiddent state if
+  /// the current feature is a line and there are not obligate widgets anymore
+  void onVertexSelected();
 
-public slots:
-  void onInternalActivateFirstWidgetSelection();
+  /// Deactivates selection and filters of the first operation widget if it is an internal
+  /// 'edit' operation
+  void onBeforeStopped();
 
 private:
+  /// Returns true if the current operation is a sketch or a nested sketch operation
+  bool isActiveMgr() const;
+
+  /// Sets the focus to the last control of the property panel and activates selection
+  /// of the first widget to can select first value of the next create operation
+  /// \param thePreviousAttributeID an index of the previous attribute to set focus to this widget
+  /// \return true if it is started
+  bool startInternalEdit(const std::string& thePreviousAttributeID);
+
+  /// Disconnects this manager from operation signals, deactivate selection of the first control
+  /// in the viewer.
+  void beforeStopInternalEdit();
+
+  /// Commits the current operation and launches a new with the commited operation feature index
+  void restartOperation();
+
+  /// Creates an internal feature and controls to process it
+  void createInternalFeature();
+
+  /// A pair method for an internal creation to remove it and clear all created controls
+  void deleteInternalFeature();
+
   /// Breaks sequense of automatically resterted operations
-  void breakOperationSequence();
+  void resetFlags();
+
+  /// Copy some feature specific attributes from the source to a new feature
+  /// This is type for Circle and Arc features
+  /// \param theSourceFeature a source feature
+  /// \param theNewFeature a new feature
+  /// \param theSketch an active sketch
+  /// \param isTemporary is used to do not create additional features(e.g. coicidence for line)
+  /// \return true is something is copied
+  static bool copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
+                                      const FeaturePtr& theNewFeature,
+                                      const std::shared_ptr<ModelAPI_CompositeFeature>& theSketch,
+                                      const bool isTemporary = false);
+
+  /// Checks whethe the feature of the given operation has kind an arc and the arc type is tangent
+  bool isTangentArc(ModuleBase_Operation* theOperation,
+                    const std::shared_ptr<ModelAPI_CompositeFeature>& /*theSketch*/) const;
+
+  /// Accept All action is enabled if an internal edit is started. 
+  /// It updates the state of the button
+  void updateAcceptAllAction();
 
   /// Returns the workshop
-  XGUI_Workshop* workshop();
+  XGUI_Workshop* workshop() const;
 
   /// Returns the workshop module
-  PartSet_Module* module();
+  PartSet_Module* module() const;
 
 private:
   ModuleBase_IWorkshop* myWorkshop; /// the workshop
 
+  RestartingMode myRestartingMode;  /// automatical restarting mode flag
+  bool myIsFlagsBlocked; /// true when reset of flags should not be perfromed
   bool myIsInternalEditOperation; /// true when the 'internal' edit is started
 
-  std::string myLastOperationId;
-  FeaturePtr myLastFeature;
-
-  std::string myPreviousAttributeID;
-  RestartingMode myRestartingMode;  /// Automatical restarting mode flag
+  FeaturePtr myPreviousFeature; /// feature of the previous operation, which is restarted
+  FeaturePtr myInternalFeature;
+  QWidget* myInternalWidget;
+  ModuleBase_ModelWidget* myInternalActiveWidget;
+  std::string myNoMoreWidgetsAttribute;
 };
 
 #endif