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"
8 #include "PartSet_OverconstraintListener.h"
10 #include <ModuleBase_IModule.h>
11 #include <ModuleBase_Definitions.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Attribute.h>
14 #include <ModelAPI_CompositeFeature.h>
16 #include <Events_Listener.h>
18 //#include <StdSelect_FaceFilter.hxx>
19 #include <TopoDS_Shape.hxx>
20 #include <SelectMgr_ListOfFilter.hxx>
25 #include <QModelIndex>
31 class ModuleBase_Operation;
32 class ModuleBase_IViewWindow;
34 class PartSet_MenuMgr;
35 class PartSet_CustomPrs;
36 class PartSet_SketcherMgr;
37 class PartSet_SketcherReetntrantMgr;
43 * Implementation of Partset module
45 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
49 /// Enumeration to specify the restart operation properties.
51 RM_None, /// the operation should not be restarted
52 RM_Forbided, /// the operation should not be restarted after there is no active widget
53 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
54 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
60 /// \param theWshop a pointer to a workshop
61 PartSet_Module(ModuleBase_IWorkshop* theWshop);
62 virtual ~PartSet_Module();
64 // Add default selection filters of the module to the current viewer
65 virtual void activateSelectionFilters();
66 // Remove default selection filters of the module from the current viewer
67 virtual void deactivateSelectionFilters();
69 // Stores the current selection
70 virtual void storeSelection();
72 // Restores the current selection
73 virtual void restoreSelection();
75 /// Creates custom widgets for property panel
76 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
77 Config_WidgetAPI* theWidgetApi);
79 /// Returns the active widget, by default it is the property panel active widget
80 /// If the internal edit operation is started, this is the first widget of the operation
81 virtual ModuleBase_ModelWidget* activeWidget() const;
83 /// Call back forlast tuning of property panel before operation performance
84 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
86 /// If there is found selected attribute, widgets are created and contains only a widget for the attribute
87 /// It is important for Property Panel filling by sketch point attribute
88 /// \param theOperation a started operation
89 /// \param theWidgets a list of created widgets
90 /// \return boolean result, false by default
91 virtual bool createWidgets(ModuleBase_Operation* theOperation,
92 QList<ModuleBase_ModelWidget*>& theWidgets) const;
94 /// Creates an operation and send it to loop
95 /// \param theCmdId the operation name
96 virtual void launchOperation(const QString& theCmdId);
98 /// Realizes some functionality by an operation start
99 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
100 /// Activate the operation presentation
101 /// \param theOperation a started operation
102 virtual void operationStarted(ModuleBase_Operation* theOperation);
104 /// Realizes some functionality by an operation resume
105 /// Activate the operation presentation
106 /// \param theOperation a resumed operation
107 virtual void operationResumed(ModuleBase_Operation* theOperation);
109 /// Realizes some functionality by an operation commit
110 /// Restarts sketcher operation automatically of it is necessary
111 /// \param theOperation a committed operation
112 virtual void operationCommitted(ModuleBase_Operation* theOperation);
114 /// Realizes some functionality by an operation abort
115 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
116 /// \param theOperation an aborted operation
117 virtual void operationAborted(ModuleBase_Operation* theOperation);
119 /// Realizes some functionality by an operation stop
120 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
121 /// \param theOperation a stopped operation
122 virtual void operationStopped(ModuleBase_Operation* theOperation);
124 /// Returns current operation
125 virtual ModuleBase_Operation* currentOperation() const;
127 /// Returns True if there are available Undos and the sketch manager allows undo
128 /// \return the boolean result
129 virtual bool canUndo() const;
131 //! Returns True if there are available Redos and the sketch manager allows redo
132 /// \return the boolean result
133 virtual bool canRedo() const;
135 /// Returnas true if the action can be applyed to the object
136 /// \param theObject a checked object
137 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
138 /// \return the a booean result
139 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
141 /// Returns True if the current operation can be committed. Asks the sketch manager.
142 /// \return a boolean value
143 //virtual bool canCommitOperation() const;
145 /// Returns whether the object can be erased at the bounds of the active operation.
146 /// The sub-objects of the current operation can not be erased
147 /// \param theObject a model object
148 virtual bool canEraseObject(const ObjectPtr& theObject) const;
150 /// Returns whether the object can be displayed at the bounds of the active operation.
151 /// Display only current operation results for usual operation and ask the sketcher manager
152 /// if it is a sketch operation
153 /// \param theObject a model object
154 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
156 /// Make some functionality after the objects are hidden in viewer
157 /// \param theObjects a list of hidden objects
158 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
160 /// Returns true if selection for the object can be activate.
161 /// For sketch operation allow the selection activation if the operation is edit, for other
162 /// operation uses the default result
163 /// \param theObject a model object
164 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
166 /// Add menu atems for object browser into the given menu
167 /// \param theMenu a popup menu to be shown in the object browser
168 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
170 /// Add menu atems for viewer into the given menu
171 /// \param theMenu a popup menu to be shown in the viewer
172 /// \param theStdActions a map of standard actions
173 /// \return true if items are added and there is no necessity to provide standard menu
174 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
176 /// Returns a list of modes, where the AIS objects should be activated
177 /// \param theModes a list of modes
178 virtual void activeSelectionModes(QIntList& theModes);
180 /// Returns whether the mouse enter the viewer's window
181 /// \return true if items are added and there is no necessity to provide standard menu
182 bool isMouseOverWindow();
184 /// Returns sketch manager object
185 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
187 /// Returns sketch reentrant manager
188 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
190 /// Returns listener of overconstraint signal
191 /// \return the listener
192 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
194 /// Performs functionality on closing document
195 virtual void closeDocument();
197 /// Clears specific presentations in the viewer
198 virtual void clearViewer();
200 /// Event Listener method
201 /// \param theMessage an event message
202 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
204 /// Set the object with the object results are customized
205 /// \param theFeature a feature
206 void setCustomized(const FeaturePtr& theFeature);
208 /// Activate custom presentation for the object
209 /// \param theFeature a feature instance
210 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
211 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
212 virtual void activateCustomPrs(const FeaturePtr& theFeature,
213 const ModuleBase_CustomizeFlag& theFlag,
214 const bool theUpdateViewer);
216 /// Deactivate custom presentation for the object
217 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
218 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
219 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
220 const bool theUpdateViewer);
222 /// Modifies the given presentation in the custom way.
223 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
224 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
226 /// Update the object presentable properties such as color, lines width and other
227 /// If the object is result with the color attribute value set, it is used,
228 /// otherwise the customize is applyed to the object's feature if it is a custom prs
229 /// \param theObject an object instance
230 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
231 /// should be updated(e.g. only highlighted elements)
232 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
233 /// \returns true if the object is modified
234 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
235 const bool theUpdateViewer);
237 /// This method is called on object browser creation for customisation of module specific features
238 /// \param theObjectBrowser a pinter on Object Browser widget
239 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
241 /// Returns the viewer Z layer
242 int getVisualLayerId() const { return myVisualLayerId; }
244 //! Returns data object by AIS
245 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
247 /// Update state of pop-up menu items in viewer
248 /// \param theStdActions - a map of standard actions
249 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
251 //! Returns the feature error if the current state of the feature in the module is not correct
252 //! If the feature is correct, it returns an empty value
253 //! \return string value
254 virtual QString getFeatureError(const FeaturePtr& theFeature);
256 /// Returns list of granted operation indices
257 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
259 /// Validates the current operation and send the state change to sketch manager
260 /// \param thePreviousState the previous widget value state
261 virtual void widgetStateChanged(int thePreviousState);
263 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
264 /// \param thePreviousAttributeID an index of the previous active attribute
265 virtual bool processEnter(const std::string& thePreviousAttributeID);
267 /// Performs some GUI actions after an operation transaction is opened
268 /// Default realization is empty
269 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
271 /// Performs some GUI actions before an operation transaction is stopped
272 /// Default realization is empty
273 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
275 /// Finds a shape by attribute if it is possible
276 /// \param theAttribute an attribute
277 /// \return a geom shape
278 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
280 /// Finds an attribute by geom shape if it is possible
281 /// \param theObject an object of the attribute
282 /// \param theGeomShape a geom shape
283 /// \return theAttribute
284 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
287 /// Redefines the parent method in order to customize the next case:
288 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
289 /// the operation should be always aborted.
290 virtual void onFeatureTriggered();
292 /// Slolt called on object display
293 /// \param theObject a data object
294 /// \param theAIS a presentation object
295 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
297 /// Slot called on before object erase
298 /// \param theObject a data object
299 /// \param theAIS a presentation object
300 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
302 /// Called on transformation in current viewer
303 /// \param theTrsfType type of tranformation
304 void onViewTransformed(int theTrsfType = 2);
307 /// Called when previous operation is finished
308 virtual void onSelectionChanged();
310 /// SLOT, that is called by key release in the viewer.
311 /// \param theWnd a view window
312 /// \param theEvent the key event
313 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
315 /// SLOT, that is called by the current operation filling with the preselection.
316 /// It commits the operation of it is can be committed
317 void onOperationActivatedByPreselection();
319 /// A slot called on view window creation
320 void onViewCreated(ModuleBase_IViewWindow*);
322 /// A slot to change property panel title on change of boolean operation type
323 /// \param theOperation the operation type
324 void onBooleanOperationChange(int theOperation);
327 /// Register validators for this module
328 virtual void registerValidators();
330 /// Register selection filters for this module
331 virtual void registerFilters();
333 /// Register properties of this module
334 virtual void registerProperties();
336 /// Connects or disconnects to the value changed signal of the property panel widgets
337 /// \param theWidget a property contol widget
338 /// \param isToConnect a boolean value whether connect or disconnect
339 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
342 void onTreeViewDoubleClick(const QModelIndex&);
344 void onActiveDocPopup(const QPoint&);
349 virtual bool deleteObjects();
351 /// Returns the workshop
352 XGUI_Workshop* getWorkshop() const;
355 SelectMgr_ListOfFilter mySelectionFilters;
357 PartSet_SketcherMgr* mySketchMgr;
358 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
359 PartSet_MenuMgr* myMenuMgr;
360 /// A default custom presentation, which is used for references objects of started operation
361 PartSet_CustomPrs* myCustomPrs;
362 PartSet_OverconstraintListener* myOverconstraintListener;
365 /// backup of the visible state to restore them by operation stop
366 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
368 QModelIndex aActivePartIndex;