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 /// Creates custom widgets for property panel
70 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
71 Config_WidgetAPI* theWidgetApi, std::string theParentId);
73 /// Returns the active widget, by default it is the property panel active widget
74 /// If the internal edit operation is started, this is the first widget of the operation
75 virtual ModuleBase_ModelWidget* activeWidget() const;
77 /// Call back forlast tuning of property panel before operation performance
78 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
80 /// If there is found selected attribute, widgets are created and contains only a widget for the attribute
81 /// It is important for Property Panel filling by sketch point attribute
82 /// \param theOperation a started operation
83 /// \param theWidgets a list of created widgets
84 /// \return boolean result, false by default
85 virtual bool createWidgets(ModuleBase_Operation* theOperation,
86 QList<ModuleBase_ModelWidget*>& theWidgets) const;
88 /// Creates an operation and send it to loop
89 /// \param theCmdId the operation name
90 virtual void launchOperation(const QString& theCmdId);
92 /// Realizes some functionality by an operation start
93 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
94 /// Activate the operation presentation
95 /// \param theOperation a started operation
96 virtual void operationStarted(ModuleBase_Operation* theOperation);
98 /// Realizes some functionality by an operation resume
99 /// Activate the operation presentation
100 /// \param theOperation a resumed operation
101 virtual void operationResumed(ModuleBase_Operation* theOperation);
103 /// Realizes some functionality by an operation commit
104 /// Restarts sketcher operation automatically of it is necessary
105 /// \param theOperation a committed operation
106 virtual void operationCommitted(ModuleBase_Operation* theOperation);
108 /// Realizes some functionality by an operation abort
109 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
110 /// \param theOperation an aborted operation
111 virtual void operationAborted(ModuleBase_Operation* theOperation);
113 /// Realizes some functionality by an operation stop
114 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
115 /// \param theOperation a stopped operation
116 virtual void operationStopped(ModuleBase_Operation* theOperation);
118 /// Returns current operation
119 virtual ModuleBase_Operation* currentOperation() const;
121 /// Returns True if there are available Undos and the sketch manager allows undo
122 /// \return the boolean result
123 virtual bool canUndo() const;
125 //! Returns True if there are available Redos and the sketch manager allows redo
126 /// \return the boolean result
127 virtual bool canRedo() const;
129 /// Returnas true if the action can be applyed to the object
130 /// \param theObject a checked object
131 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
132 /// \return the a booean result
133 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
135 /// Returns True if the current operation can be committed. Asks the sketch manager.
136 /// \return a boolean value
137 //virtual bool canCommitOperation() const;
139 /// Returns whether the object can be erased at the bounds of the active operation.
140 /// The sub-objects of the current operation can not be erased
141 /// \param theObject a model object
142 virtual bool canEraseObject(const ObjectPtr& theObject) const;
144 /// Returns whether the object can be displayed at the bounds of the active operation.
145 /// Display only current operation results for usual operation and ask the sketcher manager
146 /// if it is a sketch operation
147 /// \param theObject a model object
148 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
150 /// Make some functionality after the objects are hidden in viewer
151 /// \param theObjects a list of hidden objects
152 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
154 /// Returns true if selection for the object can be activate.
155 /// For sketch operation allow the selection activation if the operation is edit, for other
156 /// operation uses the default result
157 /// \param theObject a model object
158 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
160 /// Add menu atems for object browser into the given menu
161 /// \param theMenu a popup menu to be shown in the object browser
162 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
164 /// Add menu atems for viewer into the given menu
165 /// \param theMenu a popup menu to be shown in the viewer
166 /// \param theStdActions a map of standard actions
167 /// \return true if items are added and there is no necessity to provide standard menu
168 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
170 /// Returns a list of modes, where the AIS objects should be activated
171 /// \param theModes a list of modes
172 virtual void activeSelectionModes(QIntList& theModes);
174 /// Returns whether the mouse enter the viewer's window
175 /// \return true if items are added and there is no necessity to provide standard menu
176 bool isMouseOverWindow();
178 /// Returns sketch manager object
179 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
181 /// Returns sketch reentrant manager
182 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
184 /// Returns listener of overconstraint signal
185 /// \return the listener
186 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
188 /// Performs functionality on closing document
189 virtual void closeDocument();
191 /// Clears specific presentations in the viewer
192 virtual void clearViewer();
194 /// Event Listener method
195 /// \param theMessage an event message
196 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
198 /// Set the object with the object results are customized
199 /// \param theFeature a feature
200 void setCustomized(const FeaturePtr& theFeature);
202 /// Activate custom presentation for the object
203 /// \param theFeature a feature instance
204 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
205 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
206 virtual void activateCustomPrs(const FeaturePtr& theFeature,
207 const ModuleBase_CustomizeFlag& theFlag,
208 const bool theUpdateViewer);
210 /// Deactivate custom presentation for the object
211 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
212 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
213 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
214 const bool theUpdateViewer);
216 /// Modifies the given presentation in the custom way.
217 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
218 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
220 /// Update the object presentable properties such as color, lines width and other
221 /// If the object is result with the color attribute value set, it is used,
222 /// otherwise the customize is applyed to the object's feature if it is a custom prs
223 /// \param theObject an object instance
224 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
225 /// should be updated(e.g. only highlighted elements)
226 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
227 /// \returns true if the object is modified
228 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
229 const bool theUpdateViewer);
231 /// This method is called on object browser creation for customisation of module specific features
232 /// \param theObjectBrowser a pinter on Object Browser widget
233 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
235 /// Returns the viewer Z layer
236 int getVisualLayerId() const { return myVisualLayerId; }
238 //! Returns data object by AIS
239 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
241 /// Update state of pop-up menu items in viewer
242 /// \param theStdActions - a map of standard actions
243 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
245 //! Returns the feature error if the current state of the feature in the module is not correct
246 //! If the feature is correct, it returns an empty value
247 //! \return string value
248 virtual QString getFeatureError(const FeaturePtr& theFeature);
250 /// Returns list of granted operation indices
251 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
253 /// Validates the current operation and send the state change to sketch manager
254 /// \param thePreviousState the previous widget value state
255 virtual void widgetStateChanged(int thePreviousState);
257 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
258 /// \param thePreviousAttributeID an index of the previous active attribute
259 virtual bool processEnter(const std::string& thePreviousAttributeID);
261 /// Performs some GUI actions after an operation transaction is opened
262 /// Default realization is empty
263 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
265 /// Performs some GUI actions before an operation transaction is stopped
266 /// Default realization is empty
267 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
269 /// Finds a shape by attribute if it is possible
270 /// \param theAttribute an attribute
271 /// \return a geom shape
272 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
274 /// Finds an attribute by geom shape if it is possible
275 /// \param theObject an object of the attribute
276 /// \param theGeomShape a geom shape
277 /// \return theAttribute
278 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
281 /// Redefines the parent method in order to customize the next case:
282 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
283 /// the operation should be always aborted.
284 virtual void onFeatureTriggered();
286 /// Slolt called on object display
287 /// \param theObject a data object
288 /// \param theAIS a presentation object
289 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
291 /// Slot called on before object erase
292 /// \param theObject a data object
293 /// \param theAIS a presentation object
294 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
296 /// Called on transformation in current viewer
297 /// \param theTrsfType type of tranformation
298 void onViewTransformed(int theTrsfType = 2);
301 /// Called when previous operation is finished
302 virtual void onSelectionChanged();
304 /// SLOT, that is called by key release in the viewer.
305 /// \param theWnd a view window
306 /// \param theEvent the key event
307 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
309 /// SLOT, that is called by the current operation filling with the preselection.
310 /// It commits the operation of it is can be committed
311 void onOperationActivatedByPreselection();
313 /// A slot called on view window creation
314 void onViewCreated(ModuleBase_IViewWindow*);
316 /// A slot to change property panel title on change of boolean operation type
317 /// \param theOperation the operation type
318 void onBooleanOperationChange(int theOperation);
321 /// Register validators for this module
322 virtual void registerValidators();
324 /// Register selection filters for this module
325 virtual void registerFilters();
327 /// Register properties of this module
328 virtual void registerProperties();
330 /// Connects or disconnects to the value changed signal of the property panel widgets
331 /// \param theWidget a property contol widget
332 /// \param isToConnect a boolean value whether connect or disconnect
333 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
336 void onTreeViewDoubleClick(const QModelIndex&);
338 void onActiveDocPopup(const QPoint&);
343 virtual bool deleteObjects();
345 /// Returns the workshop
346 XGUI_Workshop* getWorkshop() const;
349 SelectMgr_ListOfFilter mySelectionFilters;
351 PartSet_SketcherMgr* mySketchMgr;
352 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
353 PartSet_MenuMgr* myMenuMgr;
354 /// A default custom presentation, which is used for references objects of started operation
355 PartSet_CustomPrs* myCustomPrs;
356 PartSet_OverconstraintListener* myOverconstraintListener;
359 /// backup of the visible state to restore them by operation stop
360 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
362 QModelIndex aActivePartIndex;