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 /// Launching of a edit operation on the feature
95 /// \param theFeature feature for editing
96 virtual void editFeature(FeaturePtr theFeature);
98 /// Creates an operation and send it to loop
99 /// \param theCmdId the operation name
100 virtual void launchOperation(const QString& theCmdId);
102 /// Realizes some functionality by an operation start
103 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
104 /// Activate the operation presentation
105 /// \param theOperation a started operation
106 virtual void operationStarted(ModuleBase_Operation* theOperation);
108 /// Realizes some functionality by an operation resume
109 /// Activate the operation presentation
110 /// \param theOperation a resumed operation
111 virtual void operationResumed(ModuleBase_Operation* theOperation);
113 /// Realizes some functionality by an operation commit
114 /// Restarts sketcher operation automatically of it is necessary
115 /// \param theOperation a committed operation
116 virtual void operationCommitted(ModuleBase_Operation* theOperation);
118 /// Realizes some functionality by an operation abort
119 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
120 /// \param theOperation an aborted operation
121 virtual void operationAborted(ModuleBase_Operation* theOperation);
123 /// Realizes some functionality by an operation stop
124 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
125 /// \param theOperation a stopped operation
126 virtual void operationStopped(ModuleBase_Operation* theOperation);
128 /// Returns current operation
129 virtual ModuleBase_Operation* currentOperation() const;
131 /// Returns True if there are available Undos and the sketch manager allows undo
132 /// \return the boolean result
133 virtual bool canUndo() const;
135 //! Returns True if there are available Redos and the sketch manager allows redo
136 /// \return the boolean result
137 virtual bool canRedo() const;
139 /// Returnas true if the action can be applyed to the object
140 /// \param theObject a checked object
141 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
142 /// \return the a booean result
143 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
145 /// Returns True if the current operation can be committed. Asks the sketch manager.
146 /// \return a boolean value
147 //virtual bool canCommitOperation() const;
149 /// Returns whether the object can be erased at the bounds of the active operation.
150 /// The sub-objects of the current operation can not be erased
151 /// \param theObject a model object
152 virtual bool canEraseObject(const ObjectPtr& theObject) const;
154 /// Returns whether the object can be displayed at the bounds of the active operation.
155 /// Display only current operation results for usual operation and ask the sketcher manager
156 /// if it is a sketch operation
157 /// \param theObject a model object
158 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
160 /// Make some functionality after the objects are hidden in viewer
161 /// \param theObjects a list of hidden objects
162 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
164 /// Returns true if selection for the object can be activate.
165 /// For sketch operation allow the selection activation if the operation is edit, for other
166 /// operation uses the default result
167 /// \param theObject a model object
168 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
170 /// Add menu atems for object browser into the given menu
171 /// \param theMenu a popup menu to be shown in the object browser
172 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
174 /// Add menu atems for viewer into the given menu
175 /// \param theMenu a popup menu to be shown in the viewer
176 /// \param theStdActions a map of standard actions
177 /// \return true if items are added and there is no necessity to provide standard menu
178 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
180 /// Returns a list of modes, where the AIS objects should be activated
181 /// \param theModes a list of modes
182 virtual void activeSelectionModes(QIntList& theModes);
184 /// Returns whether the mouse enter the viewer's window
185 /// \return true if items are added and there is no necessity to provide standard menu
186 bool isMouseOverWindow();
188 /// Returns sketch manager object
189 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
191 /// Returns sketch reentrant manager
192 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
194 /// Returns listener of overconstraint signal
195 /// \return the listener
196 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
198 /// Performs functionality on closing document
199 virtual void closeDocument();
201 /// Clears specific presentations in the viewer
202 virtual void clearViewer();
204 /// Event Listener method
205 /// \param theMessage an event message
206 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
208 /// Set the object with the object results are customized
209 /// \param theFeature a feature
210 void setCustomized(const FeaturePtr& theFeature);
212 /// Activate custom presentation for the object
213 /// \param theFeature a feature instance
214 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
215 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
216 virtual void activateCustomPrs(const FeaturePtr& theFeature,
217 const ModuleBase_CustomizeFlag& theFlag,
218 const bool theUpdateViewer);
220 /// Deactivate custom presentation for the object
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 deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
224 const bool theUpdateViewer);
226 /// Modifies the given presentation in the custom way.
227 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
228 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
230 /// Update the object presentable properties such as color, lines width and other
231 /// If the object is result with the color attribute value set, it is used,
232 /// otherwise the customize is applyed to the object's feature if it is a custom prs
233 /// \param theObject an object instance
234 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
235 /// should be updated(e.g. only highlighted elements)
236 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
237 /// \returns true if the object is modified
238 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
239 const bool theUpdateViewer);
241 /// This method is called on object browser creation for customisation of module specific features
242 /// \param theObjectBrowser a pinter on Object Browser widget
243 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
245 /// Returns the viewer Z layer
246 int getVisualLayerId() const { return myVisualLayerId; }
248 //! Returns data object by AIS
249 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
251 /// Update state of pop-up menu items in viewer
252 /// \param theStdActions - a map of standard actions
253 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
255 //! Returns the feature error if the current state of the feature in the module is not correct
256 //! If the feature is correct, it returns an empty value
257 //! \return string value
258 virtual QString getFeatureError(const FeaturePtr& theFeature);
260 /// Returns list of granted operation indices
261 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
263 /// Validates the current operation and send the state change to sketch manager
264 /// \param thePreviousState the previous widget value state
265 virtual void widgetStateChanged(int thePreviousState);
267 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
268 /// \param thePreviousAttributeID an index of the previous active attribute
269 virtual bool processEnter(const std::string& thePreviousAttributeID);
271 /// Performs some GUI actions after an operation transaction is opened
272 /// Default realization is empty
273 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
275 /// Performs some GUI actions before an operation transaction is stopped
276 /// Default realization is empty
277 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
279 /// Finds a shape by attribute if it is possible
280 /// \param theAttribute an attribute
281 /// \return a geom shape
282 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
284 /// Finds an attribute by geom shape if it is possible
285 /// \param theObject an object of the attribute
286 /// \param theGeomShape a geom shape
287 /// \return theAttribute
288 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
291 /// Redefines the parent method in order to customize the next case:
292 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
293 /// the operation should be always aborted.
294 virtual void onFeatureTriggered();
296 /// Slolt called on object display
297 /// \param theObject a data object
298 /// \param theAIS a presentation object
299 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
301 /// Slot called on before object erase
302 /// \param theObject a data object
303 /// \param theAIS a presentation object
304 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
306 /// Called on transformation in current viewer
307 /// \param theTrsfType type of tranformation
308 void onViewTransformed(int theTrsfType = 2);
311 /// Called when previous operation is finished
312 virtual void onSelectionChanged();
314 /// SLOT, that is called by key release in the viewer.
315 /// \param theWnd a view window
316 /// \param theEvent the key event
317 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
319 /// A slot called on view window creation
320 void onViewCreated(ModuleBase_IViewWindow*);
322 /// A slot to change property panel title by choice type change if the title information
323 /// exists in the XML definition of this control attribute
324 /// \param theWidget a sender
325 /// \param theIndex the current choice index
326 void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
329 /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
330 /// other dimensions are shown.
331 /// \param theFeatureKindId a feature kind
332 void storeConstraintsState(const std::string& theFeatureKindId);
334 /// Register validators for this module
335 virtual void registerValidators();
337 /// Register selection filters for this module
338 virtual void registerFilters();
340 /// Register properties of this module
341 virtual void registerProperties();
343 /// Connects or disconnects to the value changed signal of the property panel widgets
344 /// \param theWidget a property contol widget
345 /// \param isToConnect a boolean value whether connect or disconnect
346 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
348 /// Realizes some functionality by an operation start
349 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
350 /// Activate the operation presentation
351 /// \param theOperation a started operation
352 virtual void operationStartedInternal(ModuleBase_Operation* theOperation);
355 void onTreeViewDoubleClick(const QModelIndex&);
357 void onActiveDocPopup(const QPoint&);
362 virtual bool deleteObjects();
364 /// Returns the workshop
365 XGUI_Workshop* getWorkshop() const;
368 SelectMgr_ListOfFilter mySelectionFilters;
370 PartSet_SketcherMgr* mySketchMgr;
371 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
372 PartSet_MenuMgr* myMenuMgr;
373 /// A default custom presentation, which is used for references objects of started operation
374 PartSet_CustomPrs* myCustomPrs;
375 PartSet_OverconstraintListener* myOverconstraintListener;
378 /// backup of the visible state to restore them by operation stop
379 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
381 QModelIndex aActivePartIndex;