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"
9 #include "PartSet_SketcherMgr.h"
11 #include <ModuleBase_IModule.h>
12 #include <ModuleBase_Definitions.h>
13 #include <ModelAPI_Feature.h>
14 #include <ModelAPI_Attribute.h>
15 #include <ModelAPI_CompositeFeature.h>
17 #include <Events_Listener.h>
19 //#include <StdSelect_FaceFilter.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <SelectMgr_ListOfFilter.hxx>
26 #include <QModelIndex>
32 class ModuleBase_Operation;
33 class ModuleBase_IViewWindow;
34 class ModuleBase_ViewerPrs;
37 class PartSet_MenuMgr;
38 class PartSet_CustomPrs;
39 class PartSet_SketcherMgr;
40 class PartSet_SketcherReentrantMgr;
41 class ModelAPI_Result;
47 * Implementation of Partset module
49 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
53 /// Enumeration to specify the restart operation properties.
55 RM_None, /// the operation should not be restarted
56 RM_Forbided, /// the operation should not be restarted after there is no active widget
57 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature
58 /// for own initialization
59 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
65 /// \param theWshop a pointer to a workshop
66 PartSet_Module(ModuleBase_IWorkshop* theWshop);
67 virtual ~PartSet_Module();
69 // Add default selection filters of the module to the current viewer
70 virtual void activateSelectionFilters();
71 // Remove default selection filters of the module from the current viewer
72 virtual void deactivateSelectionFilters();
74 // Stores the current selection
75 virtual void storeSelection();
77 // Restores the current selection
78 virtual void restoreSelection();
80 /// Creates custom widgets for property panel
81 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
82 Config_WidgetAPI* theWidgetApi);
84 /// Returns the active widget, by default it is the property panel active widget
85 /// If the internal edit operation is started, this is the first widget of the operation
86 virtual ModuleBase_ModelWidget* activeWidget() const;
88 /// Call back forlast tuning of property panel before operation performance
89 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
91 /// If there is found selected attribute, widgets are created and contains
92 /// only a widget for the attribute
93 /// It is important for Property Panel filling by sketch point attribute
94 /// \param theOperation a started operation
95 /// \param theWidgets a list of created widgets
96 /// \return boolean result, false by default
97 virtual bool createWidgets(ModuleBase_Operation* theOperation,
98 QList<ModuleBase_ModelWidget*>& theWidgets) const;
100 /// Launching of a edit operation on the feature
101 /// \param theFeature feature for editing
102 virtual void editFeature(FeaturePtr theFeature);
104 /// Returns true if the operation can be committed. Result in default implementation is true.
105 /// \return boolean value
106 virtual bool canCommitOperation() const;
108 /// Creates an operation and send it to loop
109 /// \param theCmdId the operation name
110 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
112 virtual void launchOperation(const QString& theCmdId,
113 const bool& isStartAfterCommitOnly);
115 /// Realizes some functionality by an operation start
116 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
117 /// Activate the operation presentation
118 /// \param theOperation a started operation
119 virtual void operationStarted(ModuleBase_Operation* theOperation);
121 /// Realizes some functionality by an operation resume
122 /// Activate the operation presentation
123 /// \param theOperation a resumed operation
124 virtual void operationResumed(ModuleBase_Operation* theOperation);
126 /// Realizes some functionality by an operation commit
127 /// Restarts sketcher operation automatically of it is necessary
128 /// \param theOperation a committed operation
129 virtual void operationCommitted(ModuleBase_Operation* theOperation);
131 /// Realizes some functionality by an operation abort
132 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
133 /// \param theOperation an aborted operation
134 virtual void operationAborted(ModuleBase_Operation* theOperation);
136 /// Realizes some functionality by an operation stop
137 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
138 /// \param theOperation a stopped operation
139 virtual void operationStopped(ModuleBase_Operation* theOperation);
141 /// Returns current operation
142 virtual ModuleBase_Operation* currentOperation() const;
144 /// Returns True if there are available Undos and the sketch manager allows undo
145 /// \return the boolean result
146 virtual bool canUndo() const;
148 //! Returns True if there are available Redos and the sketch manager allows redo
149 /// \return the boolean result
150 virtual bool canRedo() const;
152 /// Returnas true if the action can be applyed to the object
153 /// \param theObject a checked object
154 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
155 /// \return the a booean result
156 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
158 /// Returns True if the current operation can be committed. Asks the sketch manager.
159 /// \return a boolean value
160 //virtual bool canCommitOperation() const;
162 /// Returns whether the object can be erased at the bounds of the active operation.
163 /// The sub-objects of the current operation can not be erased
164 /// \param theObject a model object
165 virtual bool canEraseObject(const ObjectPtr& theObject) const;
167 /// Returns whether the object can be displayed at the bounds of the active operation.
168 /// Display only current operation results for usual operation and ask the sketcher manager
169 /// if it is a sketch operation
170 /// \param theObject a model object
171 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
173 /// Make some functionality after the objects are hidden in viewer
174 /// \param theObjects a list of hidden objects
175 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
177 /// Returns true if selection for the object can be activate.
178 /// For sketch operation allow the selection activation if the operation is edit, for other
179 /// operation uses the default result
180 /// \param theObject a model object
181 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
183 /// Add menu atems for object browser into the given menu
184 /// \param theMenu a popup menu to be shown in the object browser
185 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
187 /// Add menu items for viewer into the actions map
188 /// \param theStdActions a map of standard actions
189 /// \param theParent a parent widget
190 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
191 /// \return true if items are added and there is no necessity to provide standard menu
192 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
194 QMap<int, QAction*>& theMenuActions) const;
196 /// Returns a list of modes, where the AIS objects should be activated
197 /// \param theModes a list of modes
198 virtual void activeSelectionModes(QIntList& theModes);
200 /// Appends specific selection modes for the module to the list of types
201 /// \param theTypes a selection modes to be extended
202 virtual void customSubShapesSelectionModes(QIntList& theTypes);
204 /// Returns whether the mouse enter the viewer's window
205 /// \return true if items are added and there is no necessity to provide standard menu
206 bool isMouseOverWindow();
208 /// Returns sketch manager object
209 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
211 /// Returns sketch reentrant manager
212 PartSet_SketcherReentrantMgr* sketchReentranceMgr() const { return mySketchReentrantMgr; }
214 /// Find object and attribute(if selected) for the given viewer selection
215 /// \param theSelected a viewer selection
216 /// \param theObject a selected model object
217 /// \param theAttribute a selected model attribute
218 virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
219 ObjectPtr& theObject, AttributePtr& theAttribute);
221 /// Returns listener of overconstraint signal
222 /// \return the listener
223 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
225 /// Returns true if the current operation is not reentrant and the current state of the
226 /// application is not in launch operation mode
227 /// \return boolean value
228 bool isSketchNeutralPointActivated() const;
230 /// Performs functionality on closing document
231 virtual void closeDocument();
233 /// Clears specific presentations in the viewer
234 virtual void clearViewer();
236 /// Event Listener method
237 /// \param theMessage an event message
238 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
240 /// Set the object with the object results are customized
241 /// \param theFeature a feature
242 void setCustomized(const FeaturePtr& theFeature);
244 /// Return true if the custom presentation is activated
245 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
246 /// \return boolean value
247 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const;
249 /// Activate custom presentation for the object
250 /// \param theFeature a feature instance
251 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
252 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
253 virtual void activateCustomPrs(const FeaturePtr& theFeature,
254 const ModuleBase_CustomizeFlag& theFlag,
255 const bool theUpdateViewer);
257 /// Deactivate custom presentation for the object
258 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
259 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
260 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
261 const bool theUpdateViewer);
263 /// Modifies the given presentation in the custom way.
264 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
266 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
268 /// Modifies the given presentation in the custom way after usual customize is performed.
269 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
271 GeomCustomPrsPtr theCustomPrs);
273 /// Update the object presentable properties such as color, lines width and other
274 /// If the object is result with the color attribute value set, it is used,
275 /// otherwise the customize is applyed to the object's feature if it is a custom prs
276 /// \param theObject an object instance
277 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
278 /// should be updated(e.g. only highlighted elements)
279 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
280 /// \returns true if the object is modified
281 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
282 const bool theUpdateViewer);
284 /// This method is called on object browser creation for customisation of module specific features
285 /// \param theObjectBrowser a pinter on Object Browser widget
286 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
288 /// Returns the viewer Z layer
289 int getVisualLayerId() const { return myVisualLayerId; }
291 /// Create specific for the module presentation
292 /// \param theResult an object for presentation
293 /// \return created presentation or NULL(default value)
294 virtual Handle(AIS_InteractiveObject) createPresentation(
295 const std::shared_ptr<ModelAPI_Result>& theResult);
297 //! Returns data object by AIS
298 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
300 //! Returns true if the presentation can be shown in shading mode
301 //! \param theAIS presentation to be checked
302 //! \return boolean value
303 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
305 /// Update state of pop-up menu items in viewer
306 /// \param theStdActions - a map of standard actions
307 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
309 /// Returns true if the action should be always enabled
310 /// \param theActionId an action index: Accept or Accept All
311 /// \return boolean value
312 virtual bool isActionEnableStateFixed(const int theActionId) const;
314 //! Returns the feature error if the current state of the feature in the module is not correct
315 //! If the feature is correct, it returns an empty value
316 //! \return string value
317 virtual QString getFeatureError(const FeaturePtr& theFeature);
319 /// Returns list of granted operation indices
320 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
322 /// Validates the current operation and send the state change to sketch manager
323 /// \param thePreviousState the previous widget value state
324 virtual void widgetStateChanged(int thePreviousState);
326 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
327 /// \param thePreviousAttributeID an index of the previous active attribute
328 virtual bool processEnter(const std::string& thePreviousAttributeID);
330 /// Performs some GUI actions before an operation transaction is stopped
331 /// Default realization is empty
332 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
334 /// Finds a shape by attribute if it is possible
335 /// \param theAttribute an attribute
336 /// \return a geom shape
337 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
339 /// Finds an attribute by geom shape if it is possible
340 /// \param theObject an object of the attribute
341 /// \param theGeomShape a geom shape
342 /// \return theAttribute
343 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
345 /// Returns reentrant message if it was accepted
346 virtual std::shared_ptr<Events_Message> reentrantMessage();
348 /// Put current selection into reentrant message
349 /// \param theMessage a message of reentrant operation
350 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
352 /// Returns the workshop
353 XGUI_Workshop* getWorkshop() const;
356 /// Slolt called on object display
357 /// \param theObject a data object
358 /// \param theAIS a presentation object
359 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
361 /// Slot called on before object erase
362 /// \param theObject a data object
363 /// \param theAIS a presentation object
364 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
366 /// Called on transformation in current viewer
367 /// \param theTrsfType type of tranformation
368 void onViewTransformed(int theTrsfType = 2);
371 /// Called when previous operation is finished
372 virtual void onSelectionChanged();
374 /// SLOT, that is called by key release in the viewer.
375 /// \param theWnd a view window
376 /// \param theEvent the key event
377 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
379 /// A slot called on view window creation
380 void onViewCreated(ModuleBase_IViewWindow*);
382 /// A slot to change property panel title by choice type change if the title information
383 /// exists in the XML definition of this control attribute
384 /// \param theWidget a sender
385 /// \param theIndex the current choice index
386 void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
389 /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
390 /// other dimensions are shown.
391 /// \param theFeatureKindId a feature kind
392 void storeConstraintsState(const std::string& theFeatureKindId);
394 /// If the feature kind is a geometrical or dimensional constraint, set visible state for
395 /// all types of constraints
396 /// \param theFeatureKindId a feature kind
397 void updateConstraintsState(const std::string& theFeatureKind);
399 /// Register validators for this module
400 virtual void registerValidators();
402 /// Connects or disconnects to the value changed signal of the property panel widgets
403 /// \param theWidget a property contol widget
404 /// \param isToConnect a boolean value whether connect or disconnect
405 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
407 /// Updates reentrant manager state or sketcher operations for the started operation
408 /// \param theOperation the started operation
409 void updateSketcherOnStart(ModuleBase_Operation* theOperation);
411 /// Updates presetnations of results and arguments by operation start
412 /// \param theOperation the started operation
413 void updatePresentationsOnStart(ModuleBase_Operation* theOperation);
416 void onTreeViewDoubleClick(const QModelIndex&);
418 void onActiveDocPopup(const QPoint&);
422 virtual bool deleteObjects();
424 void setDefaultConstraintShown();
427 bool myIsOperationIsLaunched; /// state of application between launch and stop operation
428 SelectMgr_ListOfFilter mySelectionFilters;
430 PartSet_SketcherMgr* mySketchMgr;
431 PartSet_SketcherReentrantMgr* mySketchReentrantMgr;
432 PartSet_MenuMgr* myMenuMgr;
433 /// A default custom presentation, which is used for references objects of started operation
434 PartSet_CustomPrs* myCustomPrs;
435 PartSet_OverconstraintListener* myOverconstraintListener;
438 /// backup of the visible state to restore them by operation stop
439 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
441 /// backup of selection in the viewer, it is used only to store selection before
442 /// redisplay and restore it after
443 PartSet_SketcherMgr::FeatureToSelectionMap myCurrentSelection;
444 QModelIndex myActivePartIndex;