1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #ifndef PartSet_Module_H
4 #define PartSet_Module_H
8 #include <ModuleBase_IModule.h>
9 #include <ModuleBase_Definitions.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Attribute.h>
12 #include <ModelAPI_CompositeFeature.h>
14 #include <Events_Listener.h>
16 //#include <StdSelect_FaceFilter.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <SelectMgr_ListOfFilter.hxx>
23 #include <QModelIndex>
29 class ModuleBase_Operation;
30 class ModuleBase_IViewWindow;
31 class PartSet_MenuMgr;
32 class PartSet_CustomPrs;
33 class PartSet_SketcherMgr;
34 class PartSet_SketcherReetntrantMgr;
40 * Implementation of Partset module
42 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
46 /// Enumeration to specify the restart operation properties.
48 RM_None, /// the operation should not be restarted
49 RM_Forbided, /// the operation should not be restarted after there is no active widget
50 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
51 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
57 /// \param theWshop a pointer to a workshop
58 PartSet_Module(ModuleBase_IWorkshop* theWshop);
59 virtual ~PartSet_Module();
61 // Add default selection filters of the module to the current viewer
62 virtual void activateSelectionFilters();
63 // Remove default selection filters of the module from the current viewer
64 virtual void deactivateSelectionFilters();
66 /// Creates custom widgets for property panel
67 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
68 Config_WidgetAPI* theWidgetApi, std::string theParentId);
70 /// Returns the active widget, by default it is the property panel active widget
71 /// If the internal edit operation is started, this is the first widget of the operation
72 virtual ModuleBase_ModelWidget* activeWidget() const;
74 /// Call back forlast tuning of property panel before operation performance
75 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
77 /// Creates an operation and send it to loop
78 /// \param theCmdId the operation name
79 virtual void launchOperation(const QString& theCmdId);
81 /// Realizes some functionality by an operation start
82 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
83 /// Activate the operation presentation
84 /// \param theOperation a started operation
85 virtual void operationStarted(ModuleBase_Operation* theOperation);
87 /// Realizes some functionality by an operation resume
88 /// Activate the operation presentation
89 /// \param theOperation a resumed operation
90 virtual void operationResumed(ModuleBase_Operation* theOperation);
92 /// Realizes some functionality by an operation commit
93 /// Restarts sketcher operation automatically of it is necessary
94 /// \param theOperation a committed operation
95 virtual void operationCommitted(ModuleBase_Operation* theOperation);
97 /// Realizes some functionality by an operation abort
98 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
99 /// \param theOperation an aborted operation
100 virtual void operationAborted(ModuleBase_Operation* theOperation);
102 /// Realizes some functionality by an operation stop
103 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
104 /// \param theOperation a stopped operation
105 virtual void operationStopped(ModuleBase_Operation* theOperation);
107 /// Returns current operation
108 virtual ModuleBase_Operation* currentOperation() const;
110 /// Returns True if there are available Undos and the sketch manager allows undo
111 /// \return the boolean result
112 virtual bool canUndo() const;
114 //! Returns True if there are available Redos and the sketch manager allows redo
115 /// \return the boolean result
116 virtual bool canRedo() const;
118 /// Returnas true if the action can be applyed to the object
119 /// \param theObject a checked object
120 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
121 /// \return the a booean result
122 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
124 /// Returns True if the current operation can be committed. Asks the sketch manager.
125 /// \return a boolean value
126 //virtual bool canCommitOperation() const;
128 /// Returns whether the object can be erased at the bounds of the active operation.
129 /// The sub-objects of the current operation can not be erased
130 /// \param theObject a model object
131 virtual bool canEraseObject(const ObjectPtr& theObject) const;
133 /// Returns whether the object can be displayed at the bounds of the active operation.
134 /// Display only current operation results for usual operation and ask the sketcher manager
135 /// if it is a sketch operation
136 /// \param theObject a model object
137 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
139 /// Returns true if selection for the object can be activate.
140 /// For sketch operation allow the selection activation if the operation is edit, for other
141 /// operation uses the default result
142 /// \param theObject a model object
143 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
145 /// Add menu atems for object browser into the given menu
146 /// \param theMenu a popup menu to be shown in the object browser
147 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
149 /// Add menu atems for viewer into the given menu
150 /// \param theMenu a popup menu to be shown in the viewer
151 /// \param theStdActions a map of standard actions
152 /// \return true if items are added and there is no necessity to provide standard menu
153 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
155 /// Returns a list of modes, where the AIS objects should be activated
156 /// \param theModes a list of modes
157 virtual void activeSelectionModes(QIntList& theModes);
159 /// Returns whether the mouse enter the viewer's window
160 /// \return true if items are added and there is no necessity to provide standard menu
161 bool isMouseOverWindow();
163 /// Returns sketch manager object
164 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
166 /// Returns sketch reentrant manager
167 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
169 /// Performs functionality on closing document
170 virtual void closeDocument();
172 /// Clears specific presentations in the viewer
173 virtual void clearViewer();
175 /// Event Listener method
176 /// \param theMessage an event message
177 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
179 /// Set the object with the object results are customized
180 /// \param theFeature a feature
181 void setCustomized(const FeaturePtr& theFeature);
183 /** Update the object presentable properties such as color, lines width and other
184 * If the object is result with the color attribute value set, it is used,
185 * otherwise the customize is applyed to the object's feature if it is a custom prs
186 * \param theObject an object instance
187 * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
188 * \returns true if the object is modified
190 virtual bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);
192 /// This method is called on object browser creation for customisation of module specific features
193 /// \param theObjectBrowser a pinter on Object Browser widget
194 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
196 /// Returns the viewer Z layer
197 int getVisualLayerId() const { return myVisualLayerId; }
199 //! Returns data object by AIS
200 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
202 /// Update state of pop-up menu items in viewer
203 /// \param theStdActions - a map of standard actions
204 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
206 //! Returns the feature error if the current state of the feature in the module is not correct
207 //! If the feature is correct, it returns an empty value
208 //! \return string value
209 virtual QString getFeatureError(const FeaturePtr& theFeature);
211 /// Returns list of granted operation indices
212 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
214 /// Validates the current operation and send the state change to sketch manager
215 /// \param thePreviousState the previous widget value state
216 virtual void widgetStateChanged(int thePreviousState);
218 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
219 /// \param thePreviousAttributeID an index of the previous active attribute
220 virtual bool processEnter(const std::string& thePreviousAttributeID);
222 /// Performs some GUI actions after an operation transaction is opened
223 /// Default realization is empty
224 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
226 /// Performs some GUI actions before an operation transaction is stopped
227 /// Default realization is empty
228 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
231 /// Redefines the parent method in order to customize the next case:
232 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
233 /// the operation should be always aborted.
234 virtual void onFeatureTriggered();
236 /// Slolt called on object display
237 /// \param theObject a data object
238 /// \param theAIS a presentation object
239 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
241 /// Slot called on before object erase
242 /// \param theObject a data object
243 /// \param theAIS a presentation object
244 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
246 /// Called on transformation in current viewer
247 /// \param theTrsfType type of tranformation
248 void onViewTransformed(int theTrsfType = 2);
251 /// Called when previous operation is finished
252 virtual void onSelectionChanged();
254 /// SLOT, that is called by key release in the viewer.
255 /// \param theWnd a view window
256 /// \param theEvent the key event
257 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
259 /// SLOT, that is called by the current operation filling with the preselection.
260 /// It commits the operation of it is can be committed
261 void onOperationActivatedByPreselection();
263 /// A slot called on view window creation
264 void onViewCreated(ModuleBase_IViewWindow*);
266 /// A slot to change property panel title on change of boolean operation type
267 /// \param theOperation the operation type
268 void onBooleanOperationChange(int theOperation);
271 /// Register validators for this module
272 virtual void registerValidators();
274 /// Register selection filters for this module
275 virtual void registerFilters();
277 /// Register properties of this module
278 virtual void registerProperties();
280 /// Connects or disconnects to the value changed signal of the property panel widgets
281 /// \param theWidget a property contol widget
282 /// \param isToConnect a boolean value whether connect or disconnect
283 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
286 void onTreeViewDoubleClick(const QModelIndex&);
288 void onActiveDocPopup(const QPoint&);
293 virtual bool deleteObjects();
296 SelectMgr_ListOfFilter mySelectionFilters;
298 PartSet_SketcherMgr* mySketchMgr;
299 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
300 PartSet_MenuMgr* myMenuMgr;
301 /// A default custom presentation, which is used for references objects of started operation
302 PartSet_CustomPrs* myCustomPrs;
305 bool myHasConstraintShown;
307 QModelIndex aActivePartIndex;