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;
38 class ModelAPI_Result;
44 * Implementation of Partset module
46 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
50 /// Enumeration to specify the restart operation properties.
52 RM_None, /// the operation should not be restarted
53 RM_Forbided, /// the operation should not be restarted after there is no active widget
54 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
55 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
61 /// \param theWshop a pointer to a workshop
62 PartSet_Module(ModuleBase_IWorkshop* theWshop);
63 virtual ~PartSet_Module();
65 // Add default selection filters of the module to the current viewer
66 virtual void activateSelectionFilters();
67 // Remove default selection filters of the module from the current viewer
68 virtual void deactivateSelectionFilters();
70 // Stores the current selection
71 virtual void storeSelection();
73 // Restores the current selection
74 virtual void restoreSelection();
76 /// Creates custom widgets for property panel
77 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
78 Config_WidgetAPI* theWidgetApi);
80 /// Returns the active widget, by default it is the property panel active widget
81 /// If the internal edit operation is started, this is the first widget of the operation
82 virtual ModuleBase_ModelWidget* activeWidget() const;
84 /// Call back forlast tuning of property panel before operation performance
85 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
87 /// If there is found selected attribute, widgets are created and contains only a widget for the attribute
88 /// It is important for Property Panel filling by sketch point attribute
89 /// \param theOperation a started operation
90 /// \param theWidgets a list of created widgets
91 /// \return boolean result, false by default
92 virtual bool createWidgets(ModuleBase_Operation* theOperation,
93 QList<ModuleBase_ModelWidget*>& theWidgets) const;
95 /// Launching of a edit operation on the feature
96 /// \param theFeature feature for editing
97 virtual void editFeature(FeaturePtr theFeature);
99 /// Returns true if the operation can be committed. Result in default implementation is true.
100 /// \return boolean value
101 virtual bool canCommitOperation() const;
103 /// Creates an operation and send it to loop
104 /// \param theCmdId the operation name
105 virtual void launchOperation(const QString& theCmdId);
107 /// Realizes some functionality by an operation start
108 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
109 /// Activate the operation presentation
110 /// \param theOperation a started operation
111 virtual void operationStarted(ModuleBase_Operation* theOperation);
113 /// Realizes some functionality by an operation resume
114 /// Activate the operation presentation
115 /// \param theOperation a resumed operation
116 virtual void operationResumed(ModuleBase_Operation* theOperation);
118 /// Realizes some functionality by an operation commit
119 /// Restarts sketcher operation automatically of it is necessary
120 /// \param theOperation a committed operation
121 virtual void operationCommitted(ModuleBase_Operation* theOperation);
123 /// Realizes some functionality by an operation abort
124 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
125 /// \param theOperation an aborted operation
126 virtual void operationAborted(ModuleBase_Operation* theOperation);
128 /// Realizes some functionality by an operation stop
129 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
130 /// \param theOperation a stopped operation
131 virtual void operationStopped(ModuleBase_Operation* theOperation);
133 /// Returns current operation
134 virtual ModuleBase_Operation* currentOperation() const;
136 /// Returns True if there are available Undos and the sketch manager allows undo
137 /// \return the boolean result
138 virtual bool canUndo() const;
140 //! Returns True if there are available Redos and the sketch manager allows redo
141 /// \return the boolean result
142 virtual bool canRedo() const;
144 /// Returnas true if the action can be applyed to the object
145 /// \param theObject a checked object
146 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
147 /// \return the a booean result
148 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
150 /// Returns True if the current operation can be committed. Asks the sketch manager.
151 /// \return a boolean value
152 //virtual bool canCommitOperation() const;
154 /// Returns whether the object can be erased at the bounds of the active operation.
155 /// The sub-objects of the current operation can not be erased
156 /// \param theObject a model object
157 virtual bool canEraseObject(const ObjectPtr& theObject) const;
159 /// Returns whether the object can be displayed at the bounds of the active operation.
160 /// Display only current operation results for usual operation and ask the sketcher manager
161 /// if it is a sketch operation
162 /// \param theObject a model object
163 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
165 /// Make some functionality after the objects are hidden in viewer
166 /// \param theObjects a list of hidden objects
167 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
169 /// Returns true if selection for the object can be activate.
170 /// For sketch operation allow the selection activation if the operation is edit, for other
171 /// operation uses the default result
172 /// \param theObject a model object
173 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
175 /// Add menu atems for object browser into the given menu
176 /// \param theMenu a popup menu to be shown in the object browser
177 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
179 /// Add menu items for viewer into the actions map
180 /// \param theStdActions a map of standard actions
181 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
182 /// \return true if items are added and there is no necessity to provide standard menu
183 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
185 QMap<int, QAction*>& theMenuActions) const;
187 /// Returns a list of modes, where the AIS objects should be activated
188 /// \param theModes a list of modes
189 virtual void activeSelectionModes(QIntList& theModes);
191 /// Returns whether the mouse enter the viewer's window
192 /// \return true if items are added and there is no necessity to provide standard menu
193 bool isMouseOverWindow();
195 /// Returns sketch manager object
196 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
198 /// Returns sketch reentrant manager
199 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
201 /// Returns listener of overconstraint signal
202 /// \return the listener
203 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
205 /// Performs functionality on closing document
206 virtual void closeDocument();
208 /// Clears specific presentations in the viewer
209 virtual void clearViewer();
211 /// Event Listener method
212 /// \param theMessage an event message
213 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
215 /// Set the object with the object results are customized
216 /// \param theFeature a feature
217 void setCustomized(const FeaturePtr& theFeature);
219 /// Activate custom presentation for the object
220 /// \param theFeature a feature instance
221 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
222 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
223 virtual void activateCustomPrs(const FeaturePtr& theFeature,
224 const ModuleBase_CustomizeFlag& theFlag,
225 const bool theUpdateViewer);
227 /// Deactivate custom presentation for the object
228 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
229 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
230 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
231 const bool theUpdateViewer);
233 /// Modifies the given presentation in the custom way.
234 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
236 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
238 /// Update the object presentable properties such as color, lines width and other
239 /// If the object is result with the color attribute value set, it is used,
240 /// otherwise the customize is applyed to the object's feature if it is a custom prs
241 /// \param theObject an object instance
242 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
243 /// should be updated(e.g. only highlighted elements)
244 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
245 /// \returns true if the object is modified
246 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
247 const bool theUpdateViewer);
249 /// This method is called on object browser creation for customisation of module specific features
250 /// \param theObjectBrowser a pinter on Object Browser widget
251 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
253 /// Returns the viewer Z layer
254 int getVisualLayerId() const { return myVisualLayerId; }
256 /// Create specific for the module presentation
257 /// \param theResult an object for presentation
258 /// \return created presentation or NULL(default value)
259 virtual Handle(AIS_InteractiveObject) createPresentation(
260 const std::shared_ptr<ModelAPI_Result>& theResult);
262 //! Returns data object by AIS
263 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
265 //! Returns true if the presentation can be shown in shading mode
266 //! \param theAIS presentation to be checked
267 //! \return boolean value
268 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
270 /// Update state of pop-up menu items in viewer
271 /// \param theStdActions - a map of standard actions
272 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
274 //! Returns the feature error if the current state of the feature in the module is not correct
275 //! If the feature is correct, it returns an empty value
276 //! \return string value
277 virtual QString getFeatureError(const FeaturePtr& theFeature);
279 /// Returns list of granted operation indices
280 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
282 /// Validates the current operation and send the state change to sketch manager
283 /// \param thePreviousState the previous widget value state
284 virtual void widgetStateChanged(int thePreviousState);
286 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
287 /// \param thePreviousAttributeID an index of the previous active attribute
288 virtual bool processEnter(const std::string& thePreviousAttributeID);
290 /// Performs some GUI actions after an operation transaction is opened
291 /// Default realization is empty
292 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
294 /// Performs some GUI actions before an operation transaction is stopped
295 /// Default realization is empty
296 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
298 /// Finds a shape by attribute if it is possible
299 /// \param theAttribute an attribute
300 /// \return a geom shape
301 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
303 /// Finds an attribute by geom shape if it is possible
304 /// \param theObject an object of the attribute
305 /// \param theGeomShape a geom shape
306 /// \return theAttribute
307 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
310 /// Redefines the parent method in order to customize the next case:
311 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
312 /// the operation should be always aborted.
313 virtual void onFeatureTriggered();
315 /// Slolt called on object display
316 /// \param theObject a data object
317 /// \param theAIS a presentation object
318 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
320 /// Slot called on before object erase
321 /// \param theObject a data object
322 /// \param theAIS a presentation object
323 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
325 /// Called on transformation in current viewer
326 /// \param theTrsfType type of tranformation
327 void onViewTransformed(int theTrsfType = 2);
330 /// Called when previous operation is finished
331 virtual void onSelectionChanged();
333 /// SLOT, that is called by key release in the viewer.
334 /// \param theWnd a view window
335 /// \param theEvent the key event
336 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
338 /// A slot called on view window creation
339 void onViewCreated(ModuleBase_IViewWindow*);
341 /// A slot to change property panel title by choice type change if the title information
342 /// exists in the XML definition of this control attribute
343 /// \param theWidget a sender
344 /// \param theIndex the current choice index
345 void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
348 /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
349 /// other dimensions are shown.
350 /// \param theFeatureKindId a feature kind
351 void storeConstraintsState(const std::string& theFeatureKindId);
353 /// Register validators for this module
354 virtual void registerValidators();
356 /// Register selection filters for this module
357 virtual void registerFilters();
359 /// Register properties of this module
360 virtual void registerProperties();
362 /// Connects or disconnects to the value changed signal of the property panel widgets
363 /// \param theWidget a property contol widget
364 /// \param isToConnect a boolean value whether connect or disconnect
365 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
367 /// Realizes some functionality by an operation start
368 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
369 /// Activate the operation presentation
370 /// \param theOperation a started operation
371 virtual void operationStartedInternal(ModuleBase_Operation* theOperation);
374 void onTreeViewDoubleClick(const QModelIndex&);
376 void onActiveDocPopup(const QPoint&);
381 virtual bool deleteObjects();
383 /// Returns the workshop
384 XGUI_Workshop* getWorkshop() const;
387 SelectMgr_ListOfFilter mySelectionFilters;
389 PartSet_SketcherMgr* mySketchMgr;
390 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
391 PartSet_MenuMgr* myMenuMgr;
392 /// A default custom presentation, which is used for references objects of started operation
393 PartSet_CustomPrs* myCustomPrs;
394 PartSet_OverconstraintListener* myOverconstraintListener;
397 /// backup of the visible state to restore them by operation stop
398 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
400 QModelIndex aActivePartIndex;