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 /// Update the object presentable properties such as color, lines width and other
208 /// If the object is result with the color attribute value set, it is used,
209 /// otherwise the customize is applyed to the object's feature if it is a custom prs
210 /// \param theObject an object instance
211 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
212 /// should be updated(e.g. only highlighted elements)
213 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
214 /// \returns true if the object is modified
215 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
216 const bool theUpdateViewer);
218 /// This method is called on object browser creation for customisation of module specific features
219 /// \param theObjectBrowser a pinter on Object Browser widget
220 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
222 /// Returns the viewer Z layer
223 int getVisualLayerId() const { return myVisualLayerId; }
225 //! Returns data object by AIS
226 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
228 /// Update state of pop-up menu items in viewer
229 /// \param theStdActions - a map of standard actions
230 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
232 //! Returns the feature error if the current state of the feature in the module is not correct
233 //! If the feature is correct, it returns an empty value
234 //! \return string value
235 virtual QString getFeatureError(const FeaturePtr& theFeature);
237 /// Returns list of granted operation indices
238 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
240 /// Validates the current operation and send the state change to sketch manager
241 /// \param thePreviousState the previous widget value state
242 virtual void widgetStateChanged(int thePreviousState);
244 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
245 /// \param thePreviousAttributeID an index of the previous active attribute
246 virtual bool processEnter(const std::string& thePreviousAttributeID);
248 /// Performs some GUI actions after an operation transaction is opened
249 /// Default realization is empty
250 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
252 /// Performs some GUI actions before an operation transaction is stopped
253 /// Default realization is empty
254 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
256 /// Finds a shape by attribute if it is possible
257 /// \param theAttribute an attribute
258 /// \return a geom shape
259 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
261 /// Finds an attribute by geom shape if it is possible
262 /// \param theObject an object of the attribute
263 /// \param theGeomShape a geom shape
264 /// \return theAttribute
265 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
267 /// Returns color of the object
268 /// \param theObject a result of a feature object
269 /// \param theColor a vector of three values in [0, 255] range
270 virtual void getColor(const ObjectPtr& theObject, std::vector<int>& theColor);
273 /// Redefines the parent method in order to customize the next case:
274 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
275 /// the operation should be always aborted.
276 virtual void onFeatureTriggered();
278 /// Slolt called on object display
279 /// \param theObject a data object
280 /// \param theAIS a presentation object
281 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
283 /// Slot called on before object erase
284 /// \param theObject a data object
285 /// \param theAIS a presentation object
286 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
288 /// Called on transformation in current viewer
289 /// \param theTrsfType type of tranformation
290 void onViewTransformed(int theTrsfType = 2);
293 /// Called when previous operation is finished
294 virtual void onSelectionChanged();
296 /// SLOT, that is called by key release in the viewer.
297 /// \param theWnd a view window
298 /// \param theEvent the key event
299 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
301 /// SLOT, that is called by the current operation filling with the preselection.
302 /// It commits the operation of it is can be committed
303 void onOperationActivatedByPreselection();
305 /// A slot called on view window creation
306 void onViewCreated(ModuleBase_IViewWindow*);
308 /// A slot to change property panel title on change of boolean operation type
309 /// \param theOperation the operation type
310 void onBooleanOperationChange(int theOperation);
313 /// Register validators for this module
314 virtual void registerValidators();
316 /// Register selection filters for this module
317 virtual void registerFilters();
319 /// Register properties of this module
320 virtual void registerProperties();
322 /// Connects or disconnects to the value changed signal of the property panel widgets
323 /// \param theWidget a property contol widget
324 /// \param isToConnect a boolean value whether connect or disconnect
325 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
328 void onTreeViewDoubleClick(const QModelIndex&);
330 void onActiveDocPopup(const QPoint&);
335 virtual bool deleteObjects();
338 SelectMgr_ListOfFilter mySelectionFilters;
340 PartSet_SketcherMgr* mySketchMgr;
341 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
342 PartSet_MenuMgr* myMenuMgr;
343 /// A default custom presentation, which is used for references objects of started operation
344 PartSet_CustomPrs* myCustomPrs;
345 PartSet_OverconstraintListener* myOverconstraintListener;
348 /// backup of the visible state to restore them by operation stop
349 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
351 QModelIndex aActivePartIndex;