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 /// \param isUpdatePropertyPanel if false, the property panel filling might be postponed
106 virtual void launchOperation(const QString& theCmdId, const bool isUpdatePropertyPanel = true);
108 /// Realizes some functionality by an operation start
109 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
110 /// Activate the operation presentation
111 /// \param theOperation a started operation
112 virtual void operationStarted(ModuleBase_Operation* theOperation);
114 /// Realizes some functionality by an operation resume
115 /// Activate the operation presentation
116 /// \param theOperation a resumed operation
117 virtual void operationResumed(ModuleBase_Operation* theOperation);
119 /// Realizes some functionality by an operation commit
120 /// Restarts sketcher operation automatically of it is necessary
121 /// \param theOperation a committed operation
122 virtual void operationCommitted(ModuleBase_Operation* theOperation);
124 /// Realizes some functionality by an operation abort
125 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
126 /// \param theOperation an aborted operation
127 virtual void operationAborted(ModuleBase_Operation* theOperation);
129 /// Realizes some functionality by an operation stop
130 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
131 /// \param theOperation a stopped operation
132 virtual void operationStopped(ModuleBase_Operation* theOperation);
134 /// Returns current operation
135 virtual ModuleBase_Operation* currentOperation() const;
137 /// Returns True if there are available Undos and the sketch manager allows undo
138 /// \return the boolean result
139 virtual bool canUndo() const;
141 //! Returns True if there are available Redos and the sketch manager allows redo
142 /// \return the boolean result
143 virtual bool canRedo() const;
145 /// Returnas true if the action can be applyed to the object
146 /// \param theObject a checked object
147 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
148 /// \return the a booean result
149 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
151 /// Returns True if the current operation can be committed. Asks the sketch manager.
152 /// \return a boolean value
153 //virtual bool canCommitOperation() const;
155 /// Returns whether the object can be erased at the bounds of the active operation.
156 /// The sub-objects of the current operation can not be erased
157 /// \param theObject a model object
158 virtual bool canEraseObject(const ObjectPtr& theObject) const;
160 /// Returns whether the object can be displayed at the bounds of the active operation.
161 /// Display only current operation results for usual operation and ask the sketcher manager
162 /// if it is a sketch operation
163 /// \param theObject a model object
164 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
166 /// Make some functionality after the objects are hidden in viewer
167 /// \param theObjects a list of hidden objects
168 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
170 /// Returns true if selection for the object can be activate.
171 /// For sketch operation allow the selection activation if the operation is edit, for other
172 /// operation uses the default result
173 /// \param theObject a model object
174 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
176 /// Add menu atems for object browser into the given menu
177 /// \param theMenu a popup menu to be shown in the object browser
178 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
180 /// Add menu items for viewer into the actions map
181 /// \param theStdActions a map of standard actions
182 /// \param theParent a parent widget
183 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
184 /// \return true if items are added and there is no necessity to provide standard menu
185 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
187 QMap<int, QAction*>& theMenuActions) const;
189 /// Returns a list of modes, where the AIS objects should be activated
190 /// \param theModes a list of modes
191 virtual void activeSelectionModes(QIntList& theModes);
193 /// Appends specific selection modes for the module to the list of types
194 /// \param theTypes a selection modes to be extended
195 virtual void customSubShapesSelectionModes(QIntList& theTypes);
197 /// Returns whether the mouse enter the viewer's window
198 /// \return true if items are added and there is no necessity to provide standard menu
199 bool isMouseOverWindow();
201 /// Returns sketch manager object
202 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
204 /// Returns sketch reentrant manager
205 PartSet_SketcherReetntrantMgr* sketchReentranceMgr() { return mySketchReentrantMgr; }
207 /// Returns listener of overconstraint signal
208 /// \return the listener
209 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
211 /// Performs functionality on closing document
212 virtual void closeDocument();
214 /// Clears specific presentations in the viewer
215 virtual void clearViewer();
217 /// Event Listener method
218 /// \param theMessage an event message
219 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
221 /// Set the object with the object results are customized
222 /// \param theFeature a feature
223 void setCustomized(const FeaturePtr& theFeature);
225 /// Activate custom presentation for the object
226 /// \param theFeature a feature instance
227 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
228 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
229 virtual void activateCustomPrs(const FeaturePtr& theFeature,
230 const ModuleBase_CustomizeFlag& theFlag,
231 const bool theUpdateViewer);
233 /// Deactivate custom presentation for the object
234 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
235 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
236 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
237 const bool theUpdateViewer);
239 /// Modifies the given presentation in the custom way.
240 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
242 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
244 /// Update the object presentable properties such as color, lines width and other
245 /// If the object is result with the color attribute value set, it is used,
246 /// otherwise the customize is applyed to the object's feature if it is a custom prs
247 /// \param theObject an object instance
248 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
249 /// should be updated(e.g. only highlighted elements)
250 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
251 /// \returns true if the object is modified
252 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
253 const bool theUpdateViewer);
255 /// This method is called on object browser creation for customisation of module specific features
256 /// \param theObjectBrowser a pinter on Object Browser widget
257 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
259 /// Returns the viewer Z layer
260 int getVisualLayerId() const { return myVisualLayerId; }
262 /// Create specific for the module presentation
263 /// \param theResult an object for presentation
264 /// \return created presentation or NULL(default value)
265 virtual Handle(AIS_InteractiveObject) createPresentation(
266 const std::shared_ptr<ModelAPI_Result>& theResult);
268 //! Returns data object by AIS
269 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
271 //! Returns true if the presentation can be shown in shading mode
272 //! \param theAIS presentation to be checked
273 //! \return boolean value
274 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
276 /// Update state of pop-up menu items in viewer
277 /// \param theStdActions - a map of standard actions
278 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
280 /// Returns true if the action should be always enabled
281 /// \param theActionId an action index: Accept or Accept All
282 /// \return boolean value
283 virtual bool isActionEnableStateFixed(const int theActionId) const;
285 //! Returns the feature error if the current state of the feature in the module is not correct
286 //! If the feature is correct, it returns an empty value
287 //! \return string value
288 virtual QString getFeatureError(const FeaturePtr& theFeature);
290 /// Returns list of granted operation indices
291 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
293 /// Validates the current operation and send the state change to sketch manager
294 /// \param thePreviousState the previous widget value state
295 virtual void widgetStateChanged(int thePreviousState);
297 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
298 /// \param thePreviousAttributeID an index of the previous active attribute
299 virtual bool processEnter(const std::string& thePreviousAttributeID);
301 /// Performs some GUI actions after an operation transaction is opened
302 /// Default realization is empty
303 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation);
305 /// Performs some GUI actions before an operation transaction is stopped
306 /// Default realization is empty
307 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
309 /// Finds a shape by attribute if it is possible
310 /// \param theAttribute an attribute
311 /// \return a geom shape
312 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
314 /// Finds an attribute by geom shape if it is possible
315 /// \param theObject an object of the attribute
316 /// \param theGeomShape a geom shape
317 /// \return theAttribute
318 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
321 /// Redefines the parent method in order to customize the next case:
322 /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
323 /// the operation should be always aborted.
324 virtual void onFeatureTriggered();
326 /// Slolt called on object display
327 /// \param theObject a data object
328 /// \param theAIS a presentation object
329 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
331 /// Slot called on before object erase
332 /// \param theObject a data object
333 /// \param theAIS a presentation object
334 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
336 /// Called on transformation in current viewer
337 /// \param theTrsfType type of tranformation
338 void onViewTransformed(int theTrsfType = 2);
341 /// Called when previous operation is finished
342 virtual void onSelectionChanged();
344 /// SLOT, that is called by key release in the viewer.
345 /// \param theWnd a view window
346 /// \param theEvent the key event
347 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
349 /// A slot called on view window creation
350 void onViewCreated(ModuleBase_IViewWindow*);
352 /// A slot to change property panel title by choice type change if the title information
353 /// exists in the XML definition of this control attribute
354 /// \param theWidget a sender
355 /// \param theIndex the current choice index
356 void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
359 /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
360 /// other dimensions are shown.
361 /// \param theFeatureKindId a feature kind
362 void storeConstraintsState(const std::string& theFeatureKindId);
364 /// If the feature kind is a geometrical or dimensional constraint, set visible state for
365 /// all types of constraints
366 /// \param theFeatureKindId a feature kind
367 void updateConstraintsState(const std::string& theFeatureKind);
369 /// Register validators for this module
370 virtual void registerValidators();
372 /// Register selection filters for this module
373 virtual void registerFilters();
375 /// Register properties of this module
376 virtual void registerProperties();
378 /// Connects or disconnects to the value changed signal of the property panel widgets
379 /// \param theWidget a property contol widget
380 /// \param isToConnect a boolean value whether connect or disconnect
381 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
383 /// Realizes some functionality by an operation start
384 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
385 /// Activate the operation presentation
386 /// \param theOperation a started operation
387 virtual void operationStartedInternal(ModuleBase_Operation* theOperation);
390 void onTreeViewDoubleClick(const QModelIndex&);
392 void onActiveDocPopup(const QPoint&);
396 virtual bool deleteObjects();
398 /// Returns the workshop
399 XGUI_Workshop* getWorkshop() const;
401 void setDefaultConstraintShown();
404 SelectMgr_ListOfFilter mySelectionFilters;
406 PartSet_SketcherMgr* mySketchMgr;
407 PartSet_SketcherReetntrantMgr* mySketchReentrantMgr;
408 PartSet_MenuMgr* myMenuMgr;
409 /// A default custom presentation, which is used for references objects of started operation
410 PartSet_CustomPrs* myCustomPrs;
411 PartSet_OverconstraintListener* myOverconstraintListener;
414 /// backup of the visible state to restore them by operation stop
415 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
417 QModelIndex aActivePartIndex;