Salome HOME
Sketch shape in plane selection filter should not be activated while PartSet_WidgetSh...
[modules/shaper.git] / src / PartSet / PartSet_Module.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef PartSet_Module_H
22 #define PartSet_Module_H
23
24 #include "PartSet.h"
25 #include "PartSet_Tools.h"
26 #include "PartSet_OverconstraintListener.h"
27 #include "PartSet_SketcherMgr.h"
28
29 #include <ModuleBase_IModule.h>
30 #include <ModuleBase_Definitions.h>
31 #include <ModelAPI_Feature.h>
32 #include <ModelAPI_Attribute.h>
33 #include <ModelAPI_CompositeFeature.h>
34
35 #include <Events_Listener.h>
36
37 //#include <StdSelect_FaceFilter.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <SelectMgr_ListOfFilter.hxx>
40
41 #include <QMap>
42 #include <QMenu>
43 #include <QObject>
44 #include <QModelIndex>
45
46 #include <string>
47
48 #include <memory>
49
50 class ModuleBase_Operation;
51 class ModuleBase_IViewWindow;
52 class ModuleBase_ViewerPrs;
53
54 class XGUI_Workshop;
55 class PartSet_MenuMgr;
56 class PartSet_CustomPrs;
57 class PartSet_SketcherMgr;
58 class PartSet_SketcherReentrantMgr;
59 class ModelAPI_Result;
60
61 class QAction;
62
63 /**
64 * \ingroup Modules
65 * Implementation of Partset module
66 */
67 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
68 {
69 Q_OBJECT
70
71 /// Enumeration to specify the restart operation properties.
72 enum RestartingMode {
73   RM_None, /// the operation should not be restarted
74   RM_Forbided, /// the operation should not be restarted after there is no active widget
75   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature
76                       /// for own initialization
77   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
78 };
79
80 public:
81
82   /// Constructor
83   /// \param theWshop a pointer to a workshop
84   PartSet_Module(ModuleBase_IWorkshop* theWshop);
85   virtual ~PartSet_Module();
86
87   // Stores the current selection
88   virtual void storeSelection();
89
90   // Restores the current selection
91   virtual void restoreSelection();
92
93   /// Creates custom widgets for property panel
94   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
95                                                      Config_WidgetAPI* theWidgetApi);
96
97   /// Returns the active widget, by default it is the property panel active widget
98   /// If the internal edit operation is started, this is the first widget of the operation
99   virtual ModuleBase_ModelWidget* activeWidget() const;
100
101   /// Call back forlast tuning of property panel before operation performance
102   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
103
104   /// If there is found selected attribute, widgets are created and contains
105   /// only a widget for the attribute
106   /// It is important for Property Panel filling by sketch point attribute
107   /// \param theOperation a started operation
108   /// \param theWidgets a list of created widgets
109   /// \return boolean result, false by default
110   virtual bool createWidgets(ModuleBase_Operation* theOperation,
111                              QList<ModuleBase_ModelWidget*>& theWidgets) const;
112
113   /// Launching of a edit operation on the feature
114   /// \param theFeature feature for editing
115   virtual void editFeature(FeaturePtr theFeature);
116
117   /// Returns true if the operation can be committed. Result in default implementation is true.
118   /// \return boolean value
119   virtual bool canCommitOperation() const;
120
121   /// Creates an operation and send it to loop
122   /// \param theCmdId the operation name
123   /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
124   ///        it is committed
125   virtual void launchOperation(const QString& theCmdId,
126                                const bool& isStartAfterCommitOnly);
127
128   /// Realizes some functionality by an operation start
129   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
130   /// Activate the operation presentation
131   /// \param theOperation a started operation
132   virtual void operationStarted(ModuleBase_Operation* theOperation);
133
134   /// Realizes some functionality by an operation resume
135   /// Activate the operation presentation
136   /// \param theOperation a resumed operation
137   virtual void operationResumed(ModuleBase_Operation* theOperation);
138
139   /// Realizes some functionality by an operation commit
140   /// Restarts sketcher operation automatically of it is necessary
141   /// \param theOperation a committed operation
142   virtual void operationCommitted(ModuleBase_Operation* theOperation);
143
144   /// Realizes some functionality by an operation abort
145   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
146   /// \param theOperation an aborted operation
147   virtual void operationAborted(ModuleBase_Operation* theOperation);
148
149   /// Realizes some functionality by an operation stop
150   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
151   /// \param theOperation a stopped operation
152   virtual void operationStopped(ModuleBase_Operation* theOperation);
153
154   /// Returns current operation
155   virtual ModuleBase_Operation* currentOperation() const;
156
157   /// Returns True if there are available Undos and the sketch manager allows undo
158   /// \return the boolean result
159   virtual bool canUndo() const;
160
161   //! Returns True if there are available Redos and the sketch manager allows redo
162   /// \return the boolean result
163   virtual bool canRedo() const;
164
165   /// Returnas true if the action can be applyed to the object
166   /// \param theObject a checked object
167   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
168   /// \return the a booean result
169   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
170
171   /// Returns True if the current operation can be committed. Asks the sketch manager.
172   /// \return a boolean value
173   //virtual bool canCommitOperation() const;
174
175   /// Returns whether the object can be erased at the bounds of the active operation.
176   /// The sub-objects of the current operation can not be erased
177   /// \param theObject a model object
178   virtual bool canEraseObject(const ObjectPtr& theObject) const;
179
180   /// Returns whether the object can be displayed at the bounds of the active operation.
181   /// Display only current operation results for usual operation and ask the sketcher manager
182   /// if it is a sketch operation
183   /// \param theObject a model object
184   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
185
186   /// Returns parent result if accepted, true if the started operation is a nested operation
187   /// of the previous operation
188   /// \param thePreviousOperationKind a kind of previous operation
189   /// \param theStartedOperationKind a kind of a new operation
190   virtual bool canUsePreselection(const QString& thePreviousOperationKind,
191                                   const QString& theStartedOperationKind);
192
193   /// Make some functionality after the objects are hidden in viewer
194   /// \param theObjects a list of hidden objects
195   //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
196
197   /// Returns true if selection for the object can be activate.
198   /// For sketch operation allow the selection activation if the operation is edit, for other
199   /// operation uses the default result
200   /// \param theObject a model object
201   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
202
203   /// Add menu atems for object browser into the given menu
204   /// \param theMenu a popup menu to be shown in the object browser
205   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
206
207   /// Add menu items for viewer into the actions map
208   /// \param theStdActions a map of standard actions
209   /// \param theParent a parent widget
210   /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
211   /// \return true if items are added and there is no necessity to provide standard menu
212   virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
213                              QWidget* theParent,
214                              QMap<int, QAction*>& theMenuActions) const;
215
216   /// Returns a list of modes, where the AIS objects should be activated
217   /// \param theModes a list of modes
218   virtual void activeSelectionModes(QIntList& theModes);
219
220   /// Appends specific selection modes for the module to the list of types
221   /// \param theModesType combination of available selection filters
222   /// \param theModes a selection modes to be extended
223   virtual void moduleSelectionModes(int theModesType, QIntList& theModes);
224
225   /// Appends into container of filters module filters corresponded to the modes type
226   /// \param theModesType combination of available selection filters
227   /// \param theSelectionFilters [out] container to be extend by elements
228   virtual void moduleSelectionFilters(int theModesType,
229                                       SelectMgr_ListOfFilter& theSelectionFilters);
230
231   /// Returns whether the mouse enter the viewer's window
232   /// \return true if items are added and there is no necessity to provide standard menu
233   bool isMouseOverWindow();
234
235   /// Returns sketch manager object
236   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
237
238   /// Returns sketch reentrant manager
239   PartSet_SketcherReentrantMgr* sketchReentranceMgr() const { return mySketchReentrantMgr; }
240
241   /// Find object and attribute(if selected) for the given viewer selection
242   /// \param theSelected a viewer selection
243   /// \param theObject a selected model object
244   /// \param theAttribute a selected model attribute
245   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
246                                 ObjectPtr& theObject, AttributePtr& theAttribute);
247
248   /// Returns listener of overconstraint signal
249   /// \return the listener
250   PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
251
252   /// Returns true if the current operation is not reentrant and the current state of the
253   /// application is not in launch operation mode
254   /// \return boolean value
255   bool isSketchNeutralPointActivated() const;
256
257   /// Performs functionality on closing document
258   virtual void closeDocument();
259
260   /// Clears specific presentations in the viewer
261   virtual void clearViewer();
262
263   /// Event Listener method
264   /// \param theMessage an event message
265   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
266
267   /// Set the object with the object results are customized
268   /// \param theFeature a feature
269   void setCustomized(const FeaturePtr& theFeature);
270
271   /// Return true if the custom presentation is activated
272   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
273   /// \return boolean value
274   virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const;
275
276   /// Activate custom presentation for the object
277   /// \param theFeature a feature instance
278   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
279   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
280   virtual void activateCustomPrs(const FeaturePtr& theFeature,
281                                  const ModuleBase_CustomizeFlag& theFlag,
282                                  const bool theUpdateViewer);
283
284   /// Deactivate custom presentation for the object
285   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
286   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
287   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
288                                    const bool theUpdateViewer);
289
290   /// Modifies the given presentation in the custom way.
291   virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
292                                      AISObjectPtr thePrs,
293                                      std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
294
295   /// Modifies the given presentation in the custom way after usual customize is performed.
296   virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
297                                           AISObjectPtr thePrs,
298                                           GeomCustomPrsPtr theCustomPrs);
299
300   /// Update the object presentable properties such as color, lines width and other
301   /// If the object is result with the color attribute value set, it is used,
302   /// otherwise the customize is applyed to the object's feature if it is a custom prs
303   /// \param theObject an object instance
304   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
305   /// should be updated(e.g. only highlighted elements)
306   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
307   /// \returns true if the object is modified
308   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
309                                const bool theUpdateViewer);
310
311   /// This method is called on object browser creation for customisation of module specific features
312   /// \param theObjectBrowser a pinter on Object Browser widget
313   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
314
315   /// Returns the viewer Z layer
316   int getVisualLayerId() const { return myVisualLayerId; }
317
318   /// Create specific for the module presentation
319   /// \param theResult an object for presentation
320   /// \return created presentation or NULL(default value)
321   virtual Handle(AIS_InteractiveObject) createPresentation(
322                               const std::shared_ptr<ModelAPI_Result>& theResult);
323
324   //! Returns data object by AIS
325   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
326
327   //! Returns true if the presentation can be shown in shading mode
328   //! \param theAIS presentation to be checked
329   //! \return boolean value
330   virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
331
332   /// Update state of pop-up menu items in viewer
333   /// \param theStdActions - a map of standard actions
334   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
335
336   /// Returns true if the action should be always enabled
337   /// \param theActionId an action index: Accept or Accept All
338   /// \return boolean value
339   virtual bool isActionEnableStateFixed(const int theActionId) const;
340
341   //! Returns the feature error if the current state of the feature in the module is not correct
342   //! If the feature is correct, it returns an empty value
343   //! \return string value
344   virtual QString getFeatureError(const FeaturePtr& theFeature);
345
346   /// Returns list of granted operation indices
347   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
348
349   /// Validates the current operation and send the state change to sketch manager
350   /// \param thePreviousState the previous widget value state
351   virtual void widgetStateChanged(int thePreviousState);
352
353   /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
354   /// \param thePreviousAttributeID an index of the previous active attribute
355   virtual bool processEnter(const std::string& thePreviousAttributeID);
356
357   /// Performs some GUI actions before an operation transaction is stopped
358   /// Default realization is empty
359   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
360
361   /// Finds a shape by attribute if it is possible
362   /// \param theAttribute an attribute
363   /// \return a geom shape
364   virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
365
366   /// Finds an attribute by geom shape if it is possible
367   /// \param theObject an object of the attribute
368   /// \param theGeomShape a geom shape
369   /// \return theAttribute
370   virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
371
372   /// Returns reentrant message if it was accepted
373   virtual std::shared_ptr<Events_Message> reentrantMessage();
374
375   /// Put current selection into reentrant message
376   /// \param theMessage a message of reentrant operation
377   virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
378
379   /// Returns the workshop
380   XGUI_Workshop* getWorkshop() const;
381
382 public slots:
383   /// Slolt called on object display
384   /// \param theObject a data object
385   /// \param theAIS a presentation object
386   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
387
388   /// Slot called on before object erase
389   /// \param theObject a data object
390   /// \param theAIS a presentation object
391   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
392
393   /// Called on transformation in current viewer
394   /// \param theTrsfType type of tranformation
395   void onViewTransformed(int theTrsfType = 2);
396
397 protected slots:
398   /// Called when previous operation is finished
399   virtual void onSelectionChanged();
400
401   /// SLOT, that is called by key release in the viewer.
402   /// \param theWnd a view window
403   /// \param theEvent the key event
404   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
405
406   /// A slot called on view window creation
407   void onViewCreated(ModuleBase_IViewWindow*);
408
409   /// A slot to change property panel title by choice type change if the title information
410   /// exists in the XML definition of this control attribute
411   /// \param theWidget a sender
412   /// \param theIndex the current choice index
413   void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
414
415 protected:
416   /// Appends specific selection modes for the module to the list of types
417   /// \param theModes a selection modes to be extended
418   virtual void customSubShapesSelectionModes(QIntList& theModes);
419
420   /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
421   /// other dimensions are shown.
422   /// \param theFeatureKindId a feature kind
423   void storeConstraintsState(const std::string& theFeatureKindId);
424
425   /// If the feature kind is a geometrical or dimensional constraint, set visible state for
426   /// all types of constraints
427   /// \param theFeatureKindId a feature kind
428   void updateConstraintsState(const std::string& theFeatureKind);
429
430   /// Register validators for this module
431   virtual void registerValidators();
432
433   /// Connects or disconnects to the value changed signal of the property panel widgets
434   /// \param theWidget a property contol widget
435   /// \param isToConnect a boolean value whether connect or disconnect
436   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
437
438   /// Updates reentrant manager state or sketcher operations for the started operation
439   /// \param theOperation the started operation
440   void updateSketcherOnStart(ModuleBase_Operation* theOperation);
441
442   /// Updates presetnations of results and arguments by operation start
443   /// \param theOperation the started operation
444   void updatePresentationsOnStart(ModuleBase_Operation* theOperation);
445
446  private slots:
447    void onTreeViewDoubleClick(const QModelIndex&);
448
449    void onActiveDocPopup(const QPoint&);
450
451  private:
452   //! Delete features
453   virtual bool deleteObjects();
454
455   void setDefaultConstraintShown();
456
457 private:
458   bool myIsOperationIsLaunched; /// state of application between launch and stop operation
459   SelectMgr_ListOfFilter mySelectionFilters;
460
461   PartSet_SketcherMgr* mySketchMgr;
462   PartSet_SketcherReentrantMgr* mySketchReentrantMgr;
463   PartSet_MenuMgr* myMenuMgr;
464   /// A default custom presentation, which is used for references objects of started operation
465   PartSet_CustomPrs* myCustomPrs;
466   PartSet_OverconstraintListener* myOverconstraintListener;
467   int myVisualLayerId;
468
469   /// backup of the visible state to restore them by operation stop
470   QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
471
472   /// backup of selection in the viewer, it is used only to store selection before
473   /// redisplay and restore it after
474   PartSet_SketcherMgr::FeatureToSelectionMap myCurrentSelection;
475   QModelIndex myActivePartIndex;
476 };
477
478 #endif