Salome HOME
#2309 Possibility to hide faces
[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   // Add default selection filters of the module to the current viewer
88   virtual void activateSelectionFilters();
89   // Remove default selection filters of the module from the current viewer
90   virtual void deactivateSelectionFilters();
91   /// Update selection filters depending on the module active controls
92   virtual void updateActiveSelectionFilters();
93
94   // Stores the current selection
95   virtual void storeSelection();
96
97   // Restores the current selection
98   virtual void restoreSelection();
99
100   /// Creates custom widgets for property panel
101   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
102                                                      Config_WidgetAPI* theWidgetApi);
103
104   /// Returns the active widget, by default it is the property panel active widget
105   /// If the internal edit operation is started, this is the first widget of the operation
106   virtual ModuleBase_ModelWidget* activeWidget() const;
107
108   /// Call back forlast tuning of property panel before operation performance
109   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
110
111   /// If there is found selected attribute, widgets are created and contains
112   /// only a widget for the attribute
113   /// It is important for Property Panel filling by sketch point attribute
114   /// \param theOperation a started operation
115   /// \param theWidgets a list of created widgets
116   /// \return boolean result, false by default
117   virtual bool createWidgets(ModuleBase_Operation* theOperation,
118                              QList<ModuleBase_ModelWidget*>& theWidgets) const;
119
120   /// Launching of a edit operation on the feature
121   /// \param theFeature feature for editing
122   virtual void editFeature(FeaturePtr theFeature);
123
124   /// Returns true if the operation can be committed. Result in default implementation is true.
125   /// \return boolean value
126   virtual bool canCommitOperation() const;
127
128   /// Creates an operation and send it to loop
129   /// \param theCmdId the operation name
130   /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
131   ///        it is committed
132   virtual void launchOperation(const QString& theCmdId,
133                                const bool& isStartAfterCommitOnly);
134
135   /// Realizes some functionality by an operation start
136   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
137   /// Activate the operation presentation
138   /// \param theOperation a started operation
139   virtual void operationStarted(ModuleBase_Operation* theOperation);
140
141   /// Realizes some functionality by an operation resume
142   /// Activate the operation presentation
143   /// \param theOperation a resumed operation
144   virtual void operationResumed(ModuleBase_Operation* theOperation);
145
146   /// Realizes some functionality by an operation commit
147   /// Restarts sketcher operation automatically of it is necessary
148   /// \param theOperation a committed operation
149   virtual void operationCommitted(ModuleBase_Operation* theOperation);
150
151   /// Realizes some functionality by an operation abort
152   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
153   /// \param theOperation an aborted operation
154   virtual void operationAborted(ModuleBase_Operation* theOperation);
155
156   /// Realizes some functionality by an operation stop
157   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
158   /// \param theOperation a stopped operation
159   virtual void operationStopped(ModuleBase_Operation* theOperation);
160
161   /// Returns current operation
162   virtual ModuleBase_Operation* currentOperation() const;
163
164   /// Returns True if there are available Undos and the sketch manager allows undo
165   /// \return the boolean result
166   virtual bool canUndo() const;
167
168   //! Returns True if there are available Redos and the sketch manager allows redo
169   /// \return the boolean result
170   virtual bool canRedo() const;
171
172   /// Returnas true if the action can be applyed to the object
173   /// \param theObject a checked object
174   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
175   /// \return the a booean result
176   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
177
178   /// Returns True if the current operation can be committed. Asks the sketch manager.
179   /// \return a boolean value
180   //virtual bool canCommitOperation() const;
181
182   /// Returns whether the object can be erased at the bounds of the active operation.
183   /// The sub-objects of the current operation can not be erased
184   /// \param theObject a model object
185   virtual bool canEraseObject(const ObjectPtr& theObject) const;
186
187   /// Returns whether the object can be displayed at the bounds of the active operation.
188   /// Display only current operation results for usual operation and ask the sketcher manager
189   /// if it is a sketch operation
190   /// \param theObject a model object
191   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
192
193   /// Returns parent result if accepted, true if the started operation is a nested operation
194   /// of the previous operation
195   /// \param thePreviousOperationKind a kind of previous operation
196   /// \param theStartedOperationKind a kind of a new operation
197   virtual bool canUsePreselection(const QString& thePreviousOperationKind,
198                                   const QString& theStartedOperationKind);
199
200   /// Make some functionality after the objects are hidden in viewer
201   /// \param theObjects a list of hidden objects
202   //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
203
204   /// Returns true if selection for the object can be activate.
205   /// For sketch operation allow the selection activation if the operation is edit, for other
206   /// operation uses the default result
207   /// \param theObject a model object
208   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
209
210   /// Add menu atems for object browser into the given menu
211   /// \param theMenu a popup menu to be shown in the object browser
212   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
213
214   /// Add menu items for viewer into the actions map
215   /// \param theStdActions a map of standard actions
216   /// \param theParent a parent widget
217   /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
218   /// \return true if items are added and there is no necessity to provide standard menu
219   virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
220                              QWidget* theParent,
221                              QMap<int, QAction*>& theMenuActions) const;
222
223   /// Returns a list of modes, where the AIS objects should be activated
224   /// \param theModes a list of modes
225   virtual void activeSelectionModes(QIntList& theModes);
226
227   /// Appends specific selection modes for the module to the list of types
228   /// \param theTypes a selection modes to be extended
229   virtual void customSubShapesSelectionModes(QIntList& theTypes);
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   /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
417   /// other dimensions are shown.
418   /// \param theFeatureKindId a feature kind
419   void storeConstraintsState(const std::string& theFeatureKindId);
420
421   /// If the feature kind is a geometrical or dimensional constraint, set visible state for
422   /// all types of constraints
423   /// \param theFeatureKindId a feature kind
424   void updateConstraintsState(const std::string& theFeatureKind);
425
426   /// Register validators for this module
427   virtual void registerValidators();
428
429   /// Connects or disconnects to the value changed signal of the property panel widgets
430   /// \param theWidget a property contol widget
431   /// \param isToConnect a boolean value whether connect or disconnect
432   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
433
434   /// Updates reentrant manager state or sketcher operations for the started operation
435   /// \param theOperation the started operation
436   void updateSketcherOnStart(ModuleBase_Operation* theOperation);
437
438   /// Updates presetnations of results and arguments by operation start
439   /// \param theOperation the started operation
440   void updatePresentationsOnStart(ModuleBase_Operation* theOperation);
441
442  private slots:
443    void onTreeViewDoubleClick(const QModelIndex&);
444
445    void onActiveDocPopup(const QPoint&);
446
447  private:
448   //! Delete features
449   virtual bool deleteObjects();
450
451   void setDefaultConstraintShown();
452
453 private:
454   bool myIsOperationIsLaunched; /// state of application between launch and stop operation
455   SelectMgr_ListOfFilter mySelectionFilters;
456
457   PartSet_SketcherMgr* mySketchMgr;
458   PartSet_SketcherReentrantMgr* mySketchReentrantMgr;
459   PartSet_MenuMgr* myMenuMgr;
460   /// A default custom presentation, which is used for references objects of started operation
461   PartSet_CustomPrs* myCustomPrs;
462   PartSet_OverconstraintListener* myOverconstraintListener;
463   int myVisualLayerId;
464
465   /// backup of the visible state to restore them by operation stop
466   QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
467
468   /// backup of selection in the viewer, it is used only to store selection before
469   /// redisplay and restore it after
470   PartSet_SketcherMgr::FeatureToSelectionMap myCurrentSelection;
471   QModelIndex myActivePartIndex;
472 };
473
474 #endif