1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #ifndef PartSet_Module_H
4 #define PartSet_Module_H
7 #include "PartSet_Tools.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>
24 #include <QModelIndex>
30 class ModuleBase_Operation;
31 class ModuleBase_IViewWindow;
32 class PartSet_MenuMgr;
33 class PartSet_CustomPrs;
34 class PartSet_SketcherMgr;
35 class PartSet_SketcherReetntrantMgr;
41 * Implementation of Partset module
43 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
47 /// Enumeration to specify the restart operation properties.
49 RM_None, /// the operation should not be restarted
50 RM_Forbided, /// the operation should not be restarted after there is no active widget
51 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
52 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
58 /// \param theWshop a pointer to a workshop
59 PartSet_Module(ModuleBase_IWorkshop* theWshop);
60 virtual ~PartSet_Module();
62 // Add default selection filters of the module to the current viewer
63 virtual void activateSelectionFilters();
64 // Remove default selection filters of the module from the current viewer
65 virtual void deactivateSelectionFilters();
67 /// Creates custom widgets for property panel
68 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
69 Config_WidgetAPI* theWidgetApi, std::string theParentId);
71 /// Returns the active widget, by default it is the property panel active widget
72 /// If the internal edit operation is started, this is the first widget of the operation
73 virtual ModuleBase_ModelWidget* activeWidget() const;
75 /// Call back forlast tuning of property panel before operation performance
76 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
78 /// Creates an operation and send it to loop
79 /// \param theCmdId the operation name
80 virtual void launchOperation(const QString& theCmdId);
82 /// Realizes some functionality by an operation start
83 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
84 /// Activate the operation presentation
85 /// \param theOperation a started operation
86 virtual void operationStarted(ModuleBase_Operation* theOperation);
88 /// Realizes some functionality by an operation resume
89 /// Activate the operation presentation
90 /// \param theOperation a resumed operation
91 virtual void operationResumed(ModuleBase_Operation* theOperation);
93 /// Realizes some functionality by an operation commit
94 /// Restarts sketcher operation automatically of it is necessary
95 /// \param theOperation a committed operation
96 virtual void operationCommitted(ModuleBase_Operation* theOperation);
98 /// Realizes some functionality by an operation abort
99 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
100 /// \param theOperation an aborted operation
101 virtual void operationAborted(ModuleBase_Operation* theOperation);
103 /// Realizes some functionality by an operation stop
104 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
105 /// \param theOperation a stopped operation
106 virtual void operationStopped(ModuleBase_Operation* theOperation);
108 /// Returns current operation
109 virtual ModuleBase_Operation* currentOperation() const;
111 /// Returns True if there are available Undos and the sketch manager allows undo
112 /// \return the boolean result
113 virtual bool canUndo() const;
115 //! Returns True if there are available Redos and the sketch manager allows redo
116 /// \return the boolean result
117 virtual bool canRedo() const;
119 /// Returnas true if the action can be applyed to the object
120 /// \param theObject a checked object
121 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
122 /// \return the a booean result
123 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
125 /// Returns True if the current operation can be committed. Asks the sketch manager.
126 /// \return a boolean value
127 //virtual bool canCommitOperation() const;
129 /// Returns whether the object can be erased at the bounds of the active operation.
130 /// The sub-objects of the current operation can not be erased
131 /// \param theObject a model object
132 virtual bool canEraseObject(const ObjectPtr& theObject) const;
134 /// Returns whether the object can be displayed at the bounds of the active operation.
135 /// Display only current operation results for usual operation and ask the sketcher manager
136 /// if it is a sketch operation
137 /// \param theObject a model object
138 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
140 /// Make some functionality after the objects are hidden in viewer
141 /// \param theObjects a list of hidden objects
142 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
144 /// Returns true if selection for the object can be activate.
145 /// For sketch operation allow the selection activation if the operation is edit, for other
146 /// operation uses the default result
147 /// \param theObject a model object
148 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
150 /// Add menu atems for object browser into the given menu
151 /// \param theMenu a popup menu to be shown in the object browser
152 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
154 /// Add menu atems for viewer into the given menu
155 /// \param theMenu a popup menu to be shown in the viewer
156 /// \param theStdActions a map of standard actions
157 /// \return true if items are added and there is no necessity to provide standard menu
158 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
160 /// Returns a list of modes, where the AIS objects should be activated
161 /// \param theModes a list of modes
162 virtual void activeSelectionModes(QIntList& theModes);
164 /// Returns whether the mouse enter the viewer's window
165 /// \return true if items are added and there is no necessity to provide standard menu
166 bool isMouseOverWindow();
168 /// Returns sketch manager object
169 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
171 /// Returns sketch reentrant manager
172 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
174 /// Performs functionality on closing document
175 virtual void closeDocument();
177 /// Clears specific presentations in the viewer
178 virtual void clearViewer();
180 /// Event Listener method
181 /// \param theMessage an event message
182 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
184 /// Set the object with the object results are customized
185 /// \param theFeature a feature
186 void setCustomized(const FeaturePtr& theFeature);
188 /// Activate custom presentation for the object
189 /// \param theFeature a feature instance
190 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
191 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
192 virtual void activateCustomPrs(const FeaturePtr& theFeature,
193 const ModuleBase_CustomizeFlag& theFlag,
194 const bool theUpdateViewer);
196 /// Deactivate custom presentation for the object
197 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
198 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
199 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
200 const bool theUpdateViewer);
202 /// Update the object presentable properties such as color, lines width and other
203 /// If the object is result with the color attribute value set, it is used,
204 /// otherwise the customize is applyed to the object's feature if it is a custom prs
205 /// \param theObject an object instance
206 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
207 /// should be updated(e.g. only highlighted elements)
208 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
209 /// \returns true if the object is modified
210 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
211 const bool theUpdateViewer);
213 /// This method is called on object browser creation for customisation of module specific features
214 /// \param theObjectBrowser a pinter on Object Browser widget
215 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
217 /// Returns the viewer Z layer
218 int getVisualLayerId() const { return myVisualLayerId; }
220 //! Returns data object by AIS
221 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
223 /// Update state of pop-up menu items in viewer
224 /// \param theStdActions - a map of standard actions
225 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
227 //! Returns the feature error if the current state of the feature in the module is not correct
228 //! If the feature is correct, it returns an empty value
229 //! \return string value
230 virtual QString getFeatureError(const FeaturePtr& theFeature);
232 /// Returns list of granted operation indices
233 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
235 /// Validates the current operation and send the state change to sketch manager
236 /// \param thePreviousState the previous widget value state
237 virtual void widgetStateChanged(int thePreviousState);
239 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
240 /// \param thePreviousAttributeID an index of the previous active attribute
241 virtual bool processEnter(const std::string& thePreviousAttributeID);
243 /// Performs some GUI actions after an operation transaction is opened
244 /// Default realization is empty
245 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
247 /// Performs some GUI actions before an operation transaction is stopped
248 /// Default realization is empty
249 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
251 /// Finds a shape by attribute if it is possible
252 /// \param theAttribute an attribute
253 /// \return a geom shape
254 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
256 /// Finds an attribute by geom shape if it is possible
257 /// \param theObject an object of the attribute
258 /// \param theGeomShape a geom shape
259 /// \return theAttribute
260 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
263 /// Redefines the parent method in order to customize the next case:
264 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
265 /// the operation should be always aborted.
266 virtual void onFeatureTriggered();
268 /// Slolt called on object display
269 /// \param theObject a data object
270 /// \param theAIS a presentation object
271 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
273 /// Slot called on before object erase
274 /// \param theObject a data object
275 /// \param theAIS a presentation object
276 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
278 /// Called on transformation in current viewer
279 /// \param theTrsfType type of tranformation
280 void onViewTransformed(int theTrsfType = 2);
283 /// Called when previous operation is finished
284 virtual void onSelectionChanged();
286 /// SLOT, that is called by key release in the viewer.
287 /// \param theWnd a view window
288 /// \param theEvent the key event
289 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
291 /// SLOT, that is called by the current operation filling with the preselection.
292 /// It commits the operation of it is can be committed
293 void onOperationActivatedByPreselection();
295 /// A slot called on view window creation
296 void onViewCreated(ModuleBase_IViewWindow*);
298 /// A slot to change property panel title on change of boolean operation type
299 /// \param theOperation the operation type
300 void onBooleanOperationChange(int theOperation);
303 /// Register validators for this module
304 virtual void registerValidators();
306 /// Register selection filters for this module
307 virtual void registerFilters();
309 /// Register properties of this module
310 virtual void registerProperties();
312 /// Connects or disconnects to the value changed signal of the property panel widgets
313 /// \param theWidget a property contol widget
314 /// \param isToConnect a boolean value whether connect or disconnect
315 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
318 void onTreeViewDoubleClick(const QModelIndex&);
320 void onActiveDocPopup(const QPoint&);
325 virtual bool deleteObjects();
328 SelectMgr_ListOfFilter mySelectionFilters;
330 PartSet_SketcherMgr* mySketchMgr;
331 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
332 PartSet_MenuMgr* myMenuMgr;
333 /// A default custom presentation, which is used for references objects of started operation
334 PartSet_CustomPrs* myCustomPrs;
337 /// backup of the visible state to restore them by operation stop
338 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
340 QModelIndex aActivePartIndex;