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