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;
33 class PartSet_MenuMgr;
34 class PartSet_CustomPrs;
35 class PartSet_SketcherMgr;
36 class PartSet_SketcherReetntrantMgr;
42 * Implementation of Partset module
44 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
48 /// Enumeration to specify the restart operation properties.
50 RM_None, /// the operation should not be restarted
51 RM_Forbided, /// the operation should not be restarted after there is no active widget
52 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
53 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
59 /// \param theWshop a pointer to a workshop
60 PartSet_Module(ModuleBase_IWorkshop* theWshop);
61 virtual ~PartSet_Module();
63 // Add default selection filters of the module to the current viewer
64 virtual void activateSelectionFilters();
65 // Remove default selection filters of the module from the current viewer
66 virtual void deactivateSelectionFilters();
68 /// Creates custom widgets for property panel
69 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
70 Config_WidgetAPI* theWidgetApi, std::string theParentId);
72 /// Returns the active widget, by default it is the property panel active widget
73 /// If the internal edit operation is started, this is the first widget of the operation
74 virtual ModuleBase_ModelWidget* activeWidget() const;
76 /// Call back forlast tuning of property panel before operation performance
77 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
79 /// Creates an operation and send it to loop
80 /// \param theCmdId the operation name
81 virtual void launchOperation(const QString& theCmdId);
83 /// Realizes some functionality by an operation start
84 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
85 /// Activate the operation presentation
86 /// \param theOperation a started operation
87 virtual void operationStarted(ModuleBase_Operation* theOperation);
89 /// Realizes some functionality by an operation resume
90 /// Activate the operation presentation
91 /// \param theOperation a resumed operation
92 virtual void operationResumed(ModuleBase_Operation* theOperation);
94 /// Realizes some functionality by an operation commit
95 /// Restarts sketcher operation automatically of it is necessary
96 /// \param theOperation a committed operation
97 virtual void operationCommitted(ModuleBase_Operation* theOperation);
99 /// Realizes some functionality by an operation abort
100 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
101 /// \param theOperation an aborted operation
102 virtual void operationAborted(ModuleBase_Operation* theOperation);
104 /// Realizes some functionality by an operation stop
105 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
106 /// \param theOperation a stopped operation
107 virtual void operationStopped(ModuleBase_Operation* theOperation);
109 /// Returns current operation
110 virtual ModuleBase_Operation* currentOperation() const;
112 /// Returns True if there are available Undos and the sketch manager allows undo
113 /// \return the boolean result
114 virtual bool canUndo() const;
116 //! Returns True if there are available Redos and the sketch manager allows redo
117 /// \return the boolean result
118 virtual bool canRedo() const;
120 /// Returnas true if the action can be applyed to the object
121 /// \param theObject a checked object
122 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
123 /// \return the a booean result
124 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
126 /// Returns True if the current operation can be committed. Asks the sketch manager.
127 /// \return a boolean value
128 //virtual bool canCommitOperation() const;
130 /// Returns whether the object can be erased at the bounds of the active operation.
131 /// The sub-objects of the current operation can not be erased
132 /// \param theObject a model object
133 virtual bool canEraseObject(const ObjectPtr& theObject) const;
135 /// Returns whether the object can be displayed at the bounds of the active operation.
136 /// Display only current operation results for usual operation and ask the sketcher manager
137 /// if it is a sketch operation
138 /// \param theObject a model object
139 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
141 /// Make some functionality after the objects are hidden in viewer
142 /// \param theObjects a list of hidden objects
143 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
145 /// Returns true if selection for the object can be activate.
146 /// For sketch operation allow the selection activation if the operation is edit, for other
147 /// operation uses the default result
148 /// \param theObject a model object
149 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
151 /// Add menu atems for object browser into the given menu
152 /// \param theMenu a popup menu to be shown in the object browser
153 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
155 /// Add menu atems for viewer into the given menu
156 /// \param theMenu a popup menu to be shown in the viewer
157 /// \param theStdActions a map of standard actions
158 /// \return true if items are added and there is no necessity to provide standard menu
159 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
161 /// Returns a list of modes, where the AIS objects should be activated
162 /// \param theModes a list of modes
163 virtual void activeSelectionModes(QIntList& theModes);
165 /// Returns whether the mouse enter the viewer's window
166 /// \return true if items are added and there is no necessity to provide standard menu
167 bool isMouseOverWindow();
169 /// Returns sketch manager object
170 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
172 /// Returns sketch reentrant manager
173 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
175 /// Returns listener of overconstraint signal
176 /// \return the listener
177 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
179 /// Performs functionality on closing document
180 virtual void closeDocument();
182 /// Clears specific presentations in the viewer
183 virtual void clearViewer();
185 /// Event Listener method
186 /// \param theMessage an event message
187 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
189 /// Set the object with the object results are customized
190 /// \param theFeature a feature
191 void setCustomized(const FeaturePtr& theFeature);
193 /// Activate custom presentation for the object
194 /// \param theFeature a feature instance
195 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
196 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
197 virtual void activateCustomPrs(const FeaturePtr& theFeature,
198 const ModuleBase_CustomizeFlag& theFlag,
199 const bool theUpdateViewer);
201 /// Deactivate custom presentation for the object
202 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
203 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
204 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
205 const bool theUpdateViewer);
207 /// Modifies the given presentation in the custom way.
208 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
209 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
211 /// Update the object presentable properties such as color, lines width and other
212 /// If the object is result with the color attribute value set, it is used,
213 /// otherwise the customize is applyed to the object's feature if it is a custom prs
214 /// \param theObject an object instance
215 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
216 /// should be updated(e.g. only highlighted elements)
217 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
218 /// \returns true if the object is modified
219 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
220 const bool theUpdateViewer);
222 /// This method is called on object browser creation for customisation of module specific features
223 /// \param theObjectBrowser a pinter on Object Browser widget
224 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
226 /// Returns the viewer Z layer
227 int getVisualLayerId() const { return myVisualLayerId; }
229 //! Returns data object by AIS
230 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
232 /// Update state of pop-up menu items in viewer
233 /// \param theStdActions - a map of standard actions
234 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
236 //! Returns the feature error if the current state of the feature in the module is not correct
237 //! If the feature is correct, it returns an empty value
238 //! \return string value
239 virtual QString getFeatureError(const FeaturePtr& theFeature);
241 /// Returns list of granted operation indices
242 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
244 /// Validates the current operation and send the state change to sketch manager
245 /// \param thePreviousState the previous widget value state
246 virtual void widgetStateChanged(int thePreviousState);
248 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
249 /// \param thePreviousAttributeID an index of the previous active attribute
250 virtual bool processEnter(const std::string& thePreviousAttributeID);
252 /// Performs some GUI actions after an operation transaction is opened
253 /// Default realization is empty
254 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
256 /// Performs some GUI actions before an operation transaction is stopped
257 /// Default realization is empty
258 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
260 /// Finds a shape by attribute if it is possible
261 /// \param theAttribute an attribute
262 /// \return a geom shape
263 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
265 /// Finds an attribute by geom shape if it is possible
266 /// \param theObject an object of the attribute
267 /// \param theGeomShape a geom shape
268 /// \return theAttribute
269 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
271 /// Returns color of the object
272 /// \param theObject a result of a feature object
273 /// \param theColor a vector of three values in [0, 255] range
274 virtual void getColor(const ObjectPtr& theObject, std::vector<int>& theColor);
277 /// Redefines the parent method in order to customize the next case:
278 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
279 /// the operation should be always aborted.
280 virtual void onFeatureTriggered();
282 /// Slolt called on object display
283 /// \param theObject a data object
284 /// \param theAIS a presentation object
285 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
287 /// Slot called on before object erase
288 /// \param theObject a data object
289 /// \param theAIS a presentation object
290 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
292 /// Called on transformation in current viewer
293 /// \param theTrsfType type of tranformation
294 void onViewTransformed(int theTrsfType = 2);
297 /// Called when previous operation is finished
298 virtual void onSelectionChanged();
300 /// SLOT, that is called by key release in the viewer.
301 /// \param theWnd a view window
302 /// \param theEvent the key event
303 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
305 /// SLOT, that is called by the current operation filling with the preselection.
306 /// It commits the operation of it is can be committed
307 void onOperationActivatedByPreselection();
309 /// A slot called on view window creation
310 void onViewCreated(ModuleBase_IViewWindow*);
312 /// A slot to change property panel title on change of boolean operation type
313 /// \param theOperation the operation type
314 void onBooleanOperationChange(int theOperation);
317 /// Register validators for this module
318 virtual void registerValidators();
320 /// Register selection filters for this module
321 virtual void registerFilters();
323 /// Register properties of this module
324 virtual void registerProperties();
326 /// Connects or disconnects to the value changed signal of the property panel widgets
327 /// \param theWidget a property contol widget
328 /// \param isToConnect a boolean value whether connect or disconnect
329 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
332 void onTreeViewDoubleClick(const QModelIndex&);
334 void onActiveDocPopup(const QPoint&);
339 virtual bool deleteObjects();
342 SelectMgr_ListOfFilter mySelectionFilters;
344 PartSet_SketcherMgr* mySketchMgr;
345 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
346 PartSet_MenuMgr* myMenuMgr;
347 /// A default custom presentation, which is used for references objects of started operation
348 PartSet_CustomPrs* myCustomPrs;
349 PartSet_OverconstraintListener* myOverconstraintListener;
352 /// backup of the visible state to restore them by operation stop
353 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
355 QModelIndex aActivePartIndex;