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 /// Returns parent result if accepted, true if the started operation is a nested operation
174 /// of the previous operation
175 /// \param thePreviousOperationKind a kind of previous operation
176 /// \param theStartedOperationKind a kind of a new operation
177 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
178 const QString& theStartedOperationKind);
180 /// Make some functionality after the objects are hidden in viewer
181 /// \param theObjects a list of hidden objects
182 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
184 /// Returns true if selection for the object can be activate.
185 /// For sketch operation allow the selection activation if the operation is edit, for other
186 /// operation uses the default result
187 /// \param theObject a model object
188 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
190 /// Add menu atems for object browser into the given menu
191 /// \param theMenu a popup menu to be shown in the object browser
192 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
194 /// Add menu items for viewer into the actions map
195 /// \param theStdActions a map of standard actions
196 /// \param theParent a parent widget
197 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
198 /// \return true if items are added and there is no necessity to provide standard menu
199 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
201 QMap<int, QAction*>& theMenuActions) const;
203 /// Returns a list of modes, where the AIS objects should be activated
204 /// \param theModes a list of modes
205 virtual void activeSelectionModes(QIntList& theModes);
207 /// Appends specific selection modes for the module to the list of types
208 /// \param theTypes a selection modes to be extended
209 virtual void customSubShapesSelectionModes(QIntList& theTypes);
211 /// Returns whether the mouse enter the viewer's window
212 /// \return true if items are added and there is no necessity to provide standard menu
213 bool isMouseOverWindow();
215 /// Returns sketch manager object
216 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
218 /// Returns sketch reentrant manager
219 PartSet_SketcherReentrantMgr* sketchReentranceMgr() const { return mySketchReentrantMgr; }
221 /// Find object and attribute(if selected) for the given viewer selection
222 /// \param theSelected a viewer selection
223 /// \param theObject a selected model object
224 /// \param theAttribute a selected model attribute
225 virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
226 ObjectPtr& theObject, AttributePtr& theAttribute);
228 /// Returns listener of overconstraint signal
229 /// \return the listener
230 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
232 /// Returns true if the current operation is not reentrant and the current state of the
233 /// application is not in launch operation mode
234 /// \return boolean value
235 bool isSketchNeutralPointActivated() const;
237 /// Performs functionality on closing document
238 virtual void closeDocument();
240 /// Clears specific presentations in the viewer
241 virtual void clearViewer();
243 /// Event Listener method
244 /// \param theMessage an event message
245 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
247 /// Set the object with the object results are customized
248 /// \param theFeature a feature
249 void setCustomized(const FeaturePtr& theFeature);
251 /// Return true if the custom presentation is activated
252 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
253 /// \return boolean value
254 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const;
256 /// Activate custom presentation for the object
257 /// \param theFeature a feature instance
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 activateCustomPrs(const FeaturePtr& theFeature,
261 const ModuleBase_CustomizeFlag& theFlag,
262 const bool theUpdateViewer);
264 /// Deactivate custom presentation for the object
265 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
266 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
267 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
268 const bool theUpdateViewer);
270 /// Modifies the given presentation in the custom way.
271 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
273 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
275 /// Modifies the given presentation in the custom way after usual customize is performed.
276 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
278 GeomCustomPrsPtr theCustomPrs);
280 /// Update the object presentable properties such as color, lines width and other
281 /// If the object is result with the color attribute value set, it is used,
282 /// otherwise the customize is applyed to the object's feature if it is a custom prs
283 /// \param theObject an object instance
284 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
285 /// should be updated(e.g. only highlighted elements)
286 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
287 /// \returns true if the object is modified
288 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
289 const bool theUpdateViewer);
291 /// This method is called on object browser creation for customisation of module specific features
292 /// \param theObjectBrowser a pinter on Object Browser widget
293 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
295 /// Returns the viewer Z layer
296 int getVisualLayerId() const { return myVisualLayerId; }
298 /// Create specific for the module presentation
299 /// \param theResult an object for presentation
300 /// \return created presentation or NULL(default value)
301 virtual Handle(AIS_InteractiveObject) createPresentation(
302 const std::shared_ptr<ModelAPI_Result>& theResult);
304 //! Returns data object by AIS
305 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
307 //! Returns true if the presentation can be shown in shading mode
308 //! \param theAIS presentation to be checked
309 //! \return boolean value
310 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
312 /// Update state of pop-up menu items in viewer
313 /// \param theStdActions - a map of standard actions
314 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
316 /// Returns true if the action should be always enabled
317 /// \param theActionId an action index: Accept or Accept All
318 /// \return boolean value
319 virtual bool isActionEnableStateFixed(const int theActionId) const;
321 //! Returns the feature error if the current state of the feature in the module is not correct
322 //! If the feature is correct, it returns an empty value
323 //! \return string value
324 virtual QString getFeatureError(const FeaturePtr& theFeature);
326 /// Returns list of granted operation indices
327 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
329 /// Validates the current operation and send the state change to sketch manager
330 /// \param thePreviousState the previous widget value state
331 virtual void widgetStateChanged(int thePreviousState);
333 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
334 /// \param thePreviousAttributeID an index of the previous active attribute
335 virtual bool processEnter(const std::string& thePreviousAttributeID);
337 /// Performs some GUI actions before an operation transaction is stopped
338 /// Default realization is empty
339 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
341 /// Finds a shape by attribute if it is possible
342 /// \param theAttribute an attribute
343 /// \return a geom shape
344 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
346 /// Finds an attribute by geom shape if it is possible
347 /// \param theObject an object of the attribute
348 /// \param theGeomShape a geom shape
349 /// \return theAttribute
350 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
352 /// Returns reentrant message if it was accepted
353 virtual std::shared_ptr<Events_Message> reentrantMessage();
355 /// Put current selection into reentrant message
356 /// \param theMessage a message of reentrant operation
357 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
359 /// Returns the workshop
360 XGUI_Workshop* getWorkshop() const;
363 /// Slolt called on object display
364 /// \param theObject a data object
365 /// \param theAIS a presentation object
366 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
368 /// Slot called on before object erase
369 /// \param theObject a data object
370 /// \param theAIS a presentation object
371 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
373 /// Called on transformation in current viewer
374 /// \param theTrsfType type of tranformation
375 void onViewTransformed(int theTrsfType = 2);
378 /// Called when previous operation is finished
379 virtual void onSelectionChanged();
381 /// SLOT, that is called by key release in the viewer.
382 /// \param theWnd a view window
383 /// \param theEvent the key event
384 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
386 /// A slot called on view window creation
387 void onViewCreated(ModuleBase_IViewWindow*);
389 /// A slot to change property panel title by choice type change if the title information
390 /// exists in the XML definition of this control attribute
391 /// \param theWidget a sender
392 /// \param theIndex the current choice index
393 void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
396 /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
397 /// other dimensions are shown.
398 /// \param theFeatureKindId a feature kind
399 void storeConstraintsState(const std::string& theFeatureKindId);
401 /// If the feature kind is a geometrical or dimensional constraint, set visible state for
402 /// all types of constraints
403 /// \param theFeatureKindId a feature kind
404 void updateConstraintsState(const std::string& theFeatureKind);
406 /// Register validators for this module
407 virtual void registerValidators();
409 /// Connects or disconnects to the value changed signal of the property panel widgets
410 /// \param theWidget a property contol widget
411 /// \param isToConnect a boolean value whether connect or disconnect
412 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
414 /// Updates reentrant manager state or sketcher operations for the started operation
415 /// \param theOperation the started operation
416 void updateSketcherOnStart(ModuleBase_Operation* theOperation);
418 /// Updates presetnations of results and arguments by operation start
419 /// \param theOperation the started operation
420 void updatePresentationsOnStart(ModuleBase_Operation* theOperation);
423 void onTreeViewDoubleClick(const QModelIndex&);
425 void onActiveDocPopup(const QPoint&);
429 virtual bool deleteObjects();
431 void setDefaultConstraintShown();
434 bool myIsOperationIsLaunched; /// state of application between launch and stop operation
435 SelectMgr_ListOfFilter mySelectionFilters;
437 PartSet_SketcherMgr* mySketchMgr;
438 PartSet_SketcherReentrantMgr* mySketchReentrantMgr;
439 PartSet_MenuMgr* myMenuMgr;
440 /// A default custom presentation, which is used for references objects of started operation
441 PartSet_CustomPrs* myCustomPrs;
442 PartSet_OverconstraintListener* myOverconstraintListener;
445 /// backup of the visible state to restore them by operation stop
446 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
448 /// backup of selection in the viewer, it is used only to store selection before
449 /// redisplay and restore it after
450 PartSet_SketcherMgr::FeatureToSelectionMap myCurrentSelection;
451 QModelIndex myActivePartIndex;