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 onOperationStarted(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 onOperationResumed(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 onOperationCommitted(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 onOperationAborted(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 onOperationStopped(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;
215 /// Redefines the parent method in order to customize the next case:
216 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
217 /// the operation should be always aborted.
218 virtual void onFeatureTriggered();
220 /// Slolt called on object display
221 /// \param theObject a data object
222 /// \param theAIS a presentation object
223 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
225 /// Slot called on before object erase
226 /// \param theObject a data object
227 /// \param theAIS a presentation object
228 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
230 /// Called on transformation in current viewer
231 /// \param theTrsfType type of tranformation
232 void onViewTransformed(int theTrsfType = 2);
235 /// Called when previous operation is finished
236 virtual void onSelectionChanged();
238 /// SLOT, that is called by key release in the viewer.
239 /// \param theWnd a view window
240 /// \param theEvent the key event
241 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
243 /// SLOT, that is called by the current operation filling with the preselection.
244 /// It commits the operation of it is can be committed
245 void onOperationActivatedByPreselection();
247 /// A slot called on view window creation
248 void onViewCreated(ModuleBase_IViewWindow*);
251 /// Register validators for this module
252 virtual void registerValidators();
254 /// Register selection filters for this module
255 virtual void registerFilters();
257 /// Register properties of this module
258 virtual void registerProperties();
261 void onTreeViewDoubleClick(const QModelIndex&);
266 virtual bool deleteObjects();
269 SelectMgr_ListOfFilter mySelectionFilters;
271 PartSet_SketcherMgr* mySketchMgr;
272 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
273 PartSet_MenuMgr* myMenuMgr;
274 /// A default custom presentation, which is used for references objects of started operation
275 PartSet_CustomPrs* myCustomPrs;
278 bool myHasConstraintShown;
280 QModelIndex aActivePartIndex;