1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #ifndef PartSet_Module_H
4 #define PartSet_Module_H
7 #include "PartSet_DocumentDataModel.h"
9 #include <ModuleBase_IModule.h>
10 #include <ModuleBase_Definitions.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Attribute.h>
13 #include <ModelAPI_CompositeFeature.h>
15 #include <Events_Listener.h>
17 //#include <StdSelect_FaceFilter.hxx>
18 #include <TopoDS_Shape.hxx>
19 #include <SelectMgr_ListOfFilter.hxx>
29 class ModuleBase_Operation;
30 class ModuleBase_IViewWindow;
31 class PartSet_MenuMgr;
32 class PartSet_CustomPrs;
33 class PartSet_SketcherMgr;
39 * Implementation of Partset module
41 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
45 /// Enumeration to specify the restart operation properties.
47 RM_None, /// the operation should not be restarted
48 RM_Forbided, /// the operation should not be restarted after there is no active widget
49 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
50 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
56 /// \param theWshop a pointer to a workshop
57 PartSet_Module(ModuleBase_IWorkshop* theWshop);
58 virtual ~PartSet_Module();
60 // Add default selection filters of the module to the current viewer
61 virtual void activateSelectionFilters();
62 // Remove default selection filters of the module from the current viewer
63 virtual void deactivateSelectionFilters();
65 /// Creates custom widgets for property panel
66 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
67 Config_WidgetAPI* theWidgetApi, std::string theParentId);
69 /// Call back forlast tuning of property panel before operation performance
70 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
72 /// Realizes some functionality by an operation start
73 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
74 /// Activate the operation presentation
75 /// \param theOperation a started operation
76 virtual void onOperationStarted(ModuleBase_Operation* theOperation);
78 /// Realizes some functionality by an operation resume
79 /// Activate the operation presentation
80 /// \param theOperation a resumed operation
81 virtual void onOperationResumed(ModuleBase_Operation* theOperation);
83 /// Realizes some functionality by an operation commit
84 /// Restarts sketcher operation automatically of it is necessary
85 /// \param theOperation a committed operation
86 virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
88 /// Realizes some functionality by an operation abort
89 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
90 /// \param theOperation an aborted operation
91 virtual void onOperationAborted(ModuleBase_Operation* theOperation);
93 /// Realizes some functionality by an operation stop
94 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
95 /// \param theOperation a stopped operation
96 virtual void onOperationStopped(ModuleBase_Operation* theOperation);
98 /// Returns current operation
99 virtual ModuleBase_Operation* currentOperation() const;
101 /// Returns True if there are available Undos and the sketch manager allows undo
102 /// \return the boolean result
103 virtual bool canUndo() const;
105 //! Returns True if there are available Redos and the sketch manager allows redo
106 /// \return the boolean result
107 virtual bool canRedo() const;
109 /// Returnas true if the action can be applyed to the object
110 /// \param theObject a checked object
111 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
112 /// \return the a booean result
113 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
115 /// Returns True if the current operation can be committed. Asks the sketch manager.
116 /// \return a boolean value
117 virtual bool canCommitOperation() const;
119 /// Returns whether the object can be erased at the bounds of the active operation.
120 /// The sub-objects of the current operation can not be erased
121 /// \param theObject a model object
122 virtual bool canEraseObject(const ObjectPtr& theObject) const;
124 /// Returns whether the object can be displayed at the bounds of the active operation.
125 /// Display only current operation results for usual operation and ask the sketcher manager
126 /// if it is a sketch operation
127 /// \param theObject a model object
128 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
130 /// Returns true if selection for the object can be activate.
131 /// For sketch operation allow the selection activation if the operation is edit, for other
132 /// operation uses the default result
133 /// \param theObject a model object
134 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
136 /// Add menu atems for object browser into the given menu
137 /// \param theMenu a popup menu to be shown in the object browser
138 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
140 /// Add menu atems for viewer into the given menu
141 /// \param theMenu a popup menu to be shown in the viewer
142 /// \param theStdActions a map of standard actions
143 /// \return true if items are added and there is no necessity to provide standard menu
144 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
146 /// Returns a list of modes, where the AIS objects should be activated
147 /// \param theModes a list of modes
148 virtual void activeSelectionModes(QIntList& theModes);
150 /// Returns whether the mouse enter the viewer's window
151 /// \return true if items are added and there is no necessity to provide standard menu
152 bool isMouseOverWindow();
154 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
156 /// Returns data model object for representation of data tree in Object browser
157 virtual ModuleBase_IDocumentDataModel* dataModel() const { return myDataModel; }
159 /// Performs functionality on closing document
160 virtual void closeDocument();
162 /// Clears specific presentations in the viewer
163 virtual void clearViewer();
165 /// Event Listener method
166 /// \param theMessage an event message
167 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
169 /// Set the object with the object results are customized
170 /// \param theFeature a feature
171 void setCustomized(const FeaturePtr& theFeature);
173 /** Update the object presentable properties such as color, lines width and other
174 * If the object is result with the color attribute value set, it is used,
175 * otherwise the customize is applyed to the object's feature if it is a custom prs
176 * \param theObject an object instance
178 virtual void customizeObject(ObjectPtr theObject);
180 /// This method is called on object browser creation for customisation of module specific features
181 /// \param theObjectBrowser a pinter on Object Browser widget
182 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
184 /// Returns the viewer Z layer
185 int getVisualLayerId() const { return myVisualLayerId; }
187 //! Returns data object by AIS
188 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
190 /// Update state of pop-up menu items in viewer
191 /// \param theStdActions - a map of standard actions
192 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
195 /// SLOT, that is called by no more widget signal emitted by property panel
196 /// Set a specific flag to restart the sketcher operation
197 void onNoMoreWidgets();
199 /// Redefines the parent method in order to customize the next case:
200 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
201 /// the operation should be always aborted.
202 virtual void onFeatureTriggered();
204 /// Slolt called on object display
205 /// \param theObject a data object
206 /// \param theAIS a presentation object
207 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
209 /// Slot called on before object erase
210 /// \param theObject a data object
211 /// \param theAIS a presentation object
212 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
214 /// Called on transformation in current viewer
215 /// \param theTrsfType type of tranformation
216 void onViewTransformed(int theTrsfType = 2);
219 /// Called when previous operation is finished
220 virtual void onSelectionChanged();
222 /// SLOT, that is called by key release in the viewer.
223 /// \param theWnd a view window
224 /// \param theEvent the key event
225 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
227 /// SLOT, that is called by enter key released
228 /// Set a specific type of restarting the current operation
229 void onEnterReleased();
231 /// SLOT, that is called by the current operation filling with the preselection.
232 /// It commits the operation of it is can be committed
233 void onOperationActivatedByPreselection();
235 /// A slot called on view window creation
236 void onViewCreated(ModuleBase_IViewWindow*);
239 /// Register validators for this module
240 virtual void registerValidators();
242 /// Register selection filters for this module
243 virtual void registerFilters();
245 /// Register properties of this module
246 virtual void registerProperties();
249 /// Processing of vertex selected
250 void onVertexSelected();
252 void onTreeViewDoubleClick(const QModelIndex&);
255 /// Breaks sequense of automatically resterted operations
256 void breakOperationSequence();
259 virtual bool deleteObjects();
262 QString myLastOperationId;
263 FeaturePtr myLastFeature;
265 // Automatical restarting mode flag
266 RestartingMode myRestartingMode;
268 SelectMgr_ListOfFilter mySelectionFilters;
270 PartSet_SketcherMgr* mySketchMgr;
271 PartSet_MenuMgr* myMenuMgr;
272 /// A default custom presentation, which is used for references objects of started operation
273 PartSet_CustomPrs* myCustomPrs;
276 PartSet_DocumentDataModel* myDataModel;
278 QModelIndex aActivePartIndex;