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 ModuleBase_ViewerPrs;
36 class PartSet_MenuMgr;
37 class PartSet_CustomPrs;
38 class PartSet_SketcherMgr;
39 class PartSet_SketcherReentrantMgr;
40 class ModelAPI_Result;
46 * Implementation of Partset module
48 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
52 /// Enumeration to specify the restart operation properties.
54 RM_None, /// the operation should not be restarted
55 RM_Forbided, /// the operation should not be restarted after there is no active widget
56 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature
57 /// for own initialization
58 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
64 /// \param theWshop a pointer to a workshop
65 PartSet_Module(ModuleBase_IWorkshop* theWshop);
66 virtual ~PartSet_Module();
68 // Add default selection filters of the module to the current viewer
69 virtual void activateSelectionFilters();
70 // Remove default selection filters of the module from the current viewer
71 virtual void deactivateSelectionFilters();
73 // Stores the current selection
74 virtual void storeSelection();
76 // Restores the current selection
77 virtual void restoreSelection();
79 /// Creates custom widgets for property panel
80 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
81 Config_WidgetAPI* theWidgetApi);
83 /// Returns the active widget, by default it is the property panel active widget
84 /// If the internal edit operation is started, this is the first widget of the operation
85 virtual ModuleBase_ModelWidget* activeWidget() const;
87 /// Call back forlast tuning of property panel before operation performance
88 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
90 /// If there is found selected attribute, widgets are created and contains
91 /// only a widget for the attribute
92 /// It is important for Property Panel filling by sketch point attribute
93 /// \param theOperation a started operation
94 /// \param theWidgets a list of created widgets
95 /// \return boolean result, false by default
96 virtual bool createWidgets(ModuleBase_Operation* theOperation,
97 QList<ModuleBase_ModelWidget*>& theWidgets) const;
99 /// Launching of a edit operation on the feature
100 /// \param theFeature feature for editing
101 virtual void editFeature(FeaturePtr theFeature);
103 /// Returns true if the operation can be committed. Result in default implementation is true.
104 /// \return boolean value
105 virtual bool canCommitOperation() const;
107 /// Creates an operation and send it to loop
108 /// \param theCmdId the operation name
109 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
111 virtual void launchOperation(const QString& theCmdId,
112 const bool& isStartAfterCommitOnly);
114 /// Realizes some functionality by an operation start
115 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
116 /// Activate the operation presentation
117 /// \param theOperation a started operation
118 virtual void operationStarted(ModuleBase_Operation* theOperation);
120 /// Realizes some functionality by an operation resume
121 /// Activate the operation presentation
122 /// \param theOperation a resumed operation
123 virtual void operationResumed(ModuleBase_Operation* theOperation);
125 /// Realizes some functionality by an operation commit
126 /// Restarts sketcher operation automatically of it is necessary
127 /// \param theOperation a committed operation
128 virtual void operationCommitted(ModuleBase_Operation* theOperation);
130 /// Realizes some functionality by an operation abort
131 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
132 /// \param theOperation an aborted operation
133 virtual void operationAborted(ModuleBase_Operation* theOperation);
135 /// Realizes some functionality by an operation stop
136 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
137 /// \param theOperation a stopped operation
138 virtual void operationStopped(ModuleBase_Operation* theOperation);
140 /// Returns current operation
141 virtual ModuleBase_Operation* currentOperation() const;
143 /// Returns True if there are available Undos and the sketch manager allows undo
144 /// \return the boolean result
145 virtual bool canUndo() const;
147 //! Returns True if there are available Redos and the sketch manager allows redo
148 /// \return the boolean result
149 virtual bool canRedo() const;
151 /// Returnas true if the action can be applyed to the object
152 /// \param theObject a checked object
153 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
154 /// \return the a booean result
155 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
157 /// Returns True if the current operation can be committed. Asks the sketch manager.
158 /// \return a boolean value
159 //virtual bool canCommitOperation() const;
161 /// Returns whether the object can be erased at the bounds of the active operation.
162 /// The sub-objects of the current operation can not be erased
163 /// \param theObject a model object
164 virtual bool canEraseObject(const ObjectPtr& theObject) const;
166 /// Returns whether the object can be displayed at the bounds of the active operation.
167 /// Display only current operation results for usual operation and ask the sketcher manager
168 /// if it is a sketch operation
169 /// \param theObject a model object
170 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
172 /// Make some functionality after the objects are hidden in viewer
173 /// \param theObjects a list of hidden objects
174 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
176 /// Returns true if selection for the object can be activate.
177 /// For sketch operation allow the selection activation if the operation is edit, for other
178 /// operation uses the default result
179 /// \param theObject a model object
180 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
182 /// Add menu atems for object browser into the given menu
183 /// \param theMenu a popup menu to be shown in the object browser
184 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
186 /// Add menu items for viewer into the actions map
187 /// \param theStdActions a map of standard actions
188 /// \param theParent a parent widget
189 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
190 /// \return true if items are added and there is no necessity to provide standard menu
191 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
193 QMap<int, QAction*>& theMenuActions) const;
195 /// Returns a list of modes, where the AIS objects should be activated
196 /// \param theModes a list of modes
197 virtual void activeSelectionModes(QIntList& theModes);
199 /// Appends specific selection modes for the module to the list of types
200 /// \param theTypes a selection modes to be extended
201 virtual void customSubShapesSelectionModes(QIntList& theTypes);
203 /// Returns whether the mouse enter the viewer's window
204 /// \return true if items are added and there is no necessity to provide standard menu
205 bool isMouseOverWindow();
207 /// Returns sketch manager object
208 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
210 /// Returns sketch reentrant manager
211 PartSet_SketcherReentrantMgr* sketchReentranceMgr() const { return mySketchReentrantMgr; }
213 /// Find object and attribute(if selected) for the given viewer selection
214 /// \param theSelected a viewer selection
215 /// \param theObject a selected model object
216 /// \param theAttribute a selected model attribute
217 virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
218 ObjectPtr& theObject, AttributePtr& theAttribute);
220 /// Returns listener of overconstraint signal
221 /// \return the listener
222 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
224 /// Returns true if the current operation is not reentrant and the current state of the
225 /// application is not in launch operation mode
226 /// \return boolean value
227 bool isSketchNeutralPointActivated() const;
229 /// Performs functionality on closing document
230 virtual void closeDocument();
232 /// Clears specific presentations in the viewer
233 virtual void clearViewer();
235 /// Event Listener method
236 /// \param theMessage an event message
237 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
239 /// Set the object with the object results are customized
240 /// \param theFeature a feature
241 void setCustomized(const FeaturePtr& theFeature);
243 /// Return true if the custom presentation is activated
244 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
245 /// \return boolean value
246 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const;
248 /// Activate custom presentation for the object
249 /// \param theFeature a feature instance
250 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
251 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
252 virtual void activateCustomPrs(const FeaturePtr& theFeature,
253 const ModuleBase_CustomizeFlag& theFlag,
254 const bool theUpdateViewer);
256 /// Deactivate custom presentation for the object
257 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
258 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
259 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
260 const bool theUpdateViewer);
262 /// Modifies the given presentation in the custom way.
263 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
265 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
267 /// Modifies the given presentation in the custom way after usual customize is performed.
268 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
270 GeomCustomPrsPtr theCustomPrs);
272 /// Update the object presentable properties such as color, lines width and other
273 /// If the object is result with the color attribute value set, it is used,
274 /// otherwise the customize is applyed to the object's feature if it is a custom prs
275 /// \param theObject an object instance
276 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
277 /// should be updated(e.g. only highlighted elements)
278 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
279 /// \returns true if the object is modified
280 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
281 const bool theUpdateViewer);
283 /// This method is called on object browser creation for customisation of module specific features
284 /// \param theObjectBrowser a pinter on Object Browser widget
285 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
287 /// Returns the viewer Z layer
288 int getVisualLayerId() const { return myVisualLayerId; }
290 /// Create specific for the module presentation
291 /// \param theResult an object for presentation
292 /// \return created presentation or NULL(default value)
293 virtual Handle(AIS_InteractiveObject) createPresentation(
294 const std::shared_ptr<ModelAPI_Result>& theResult);
296 //! Returns data object by AIS
297 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
299 //! Returns true if the presentation can be shown in shading mode
300 //! \param theAIS presentation to be checked
301 //! \return boolean value
302 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
304 /// Update state of pop-up menu items in viewer
305 /// \param theStdActions - a map of standard actions
306 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
308 /// Returns true if the action should be always enabled
309 /// \param theActionId an action index: Accept or Accept All
310 /// \return boolean value
311 virtual bool isActionEnableStateFixed(const int theActionId) const;
313 //! Returns the feature error if the current state of the feature in the module is not correct
314 //! If the feature is correct, it returns an empty value
315 //! \return string value
316 virtual QString getFeatureError(const FeaturePtr& theFeature);
318 /// Returns list of granted operation indices
319 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
321 /// Validates the current operation and send the state change to sketch manager
322 /// \param thePreviousState the previous widget value state
323 virtual void widgetStateChanged(int thePreviousState);
325 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
326 /// \param thePreviousAttributeID an index of the previous active attribute
327 virtual bool processEnter(const std::string& thePreviousAttributeID);
329 /// Performs some GUI actions before an operation transaction is stopped
330 /// Default realization is empty
331 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
333 /// Finds a shape by attribute if it is possible
334 /// \param theAttribute an attribute
335 /// \return a geom shape
336 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
338 /// Finds an attribute by geom shape if it is possible
339 /// \param theObject an object of the attribute
340 /// \param theGeomShape a geom shape
341 /// \return theAttribute
342 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
344 /// Returns reentrant message if it was accepted
345 virtual std::shared_ptr<Events_Message> reentrantMessage();
347 /// Put current selection into reentrant message
348 /// \param theMessage a message of reentrant operation
349 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
351 /// Returns the workshop
352 XGUI_Workshop* getWorkshop() const;
355 /// Slolt called on object display
356 /// \param theObject a data object
357 /// \param theAIS a presentation object
358 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
360 /// Slot called on before object erase
361 /// \param theObject a data object
362 /// \param theAIS a presentation object
363 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
365 /// Called on transformation in current viewer
366 /// \param theTrsfType type of tranformation
367 void onViewTransformed(int theTrsfType = 2);
370 /// Called when previous operation is finished
371 virtual void onSelectionChanged();
373 /// SLOT, that is called by key release in the viewer.
374 /// \param theWnd a view window
375 /// \param theEvent the key event
376 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
378 /// A slot called on view window creation
379 void onViewCreated(ModuleBase_IViewWindow*);
381 /// A slot to change property panel title by choice type change if the title information
382 /// exists in the XML definition of this control attribute
383 /// \param theWidget a sender
384 /// \param theIndex the current choice index
385 void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
388 /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
389 /// other dimensions are shown.
390 /// \param theFeatureKindId a feature kind
391 void storeConstraintsState(const std::string& theFeatureKindId);
393 /// If the feature kind is a geometrical or dimensional constraint, set visible state for
394 /// all types of constraints
395 /// \param theFeatureKindId a feature kind
396 void updateConstraintsState(const std::string& theFeatureKind);
398 /// Register validators for this module
399 virtual void registerValidators();
401 /// Connects or disconnects to the value changed signal of the property panel widgets
402 /// \param theWidget a property contol widget
403 /// \param isToConnect a boolean value whether connect or disconnect
404 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
406 /// Updates reentrant manager state or sketcher operations for the started operation
407 /// \param theOperation the started operation
408 void updateSketcherOnStart(ModuleBase_Operation* theOperation);
410 /// Updates presetnations of results and arguments by operation start
411 /// \param theOperation the started operation
412 void updatePresentationsOnStart(ModuleBase_Operation* theOperation);
415 void onTreeViewDoubleClick(const QModelIndex&);
417 void onActiveDocPopup(const QPoint&);
421 virtual bool deleteObjects();
423 void setDefaultConstraintShown();
426 bool myIsOperationIsLaunched; /// state of application between launch and stop operation
427 SelectMgr_ListOfFilter mySelectionFilters;
429 PartSet_SketcherMgr* mySketchMgr;
430 PartSet_SketcherReentrantMgr* mySketchReentrantMgr;
431 PartSet_MenuMgr* myMenuMgr;
432 /// A default custom presentation, which is used for references objects of started operation
433 PartSet_CustomPrs* myCustomPrs;
434 PartSet_OverconstraintListener* myOverconstraintListener;
437 /// backup of the visible state to restore them by operation stop
438 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
440 QModelIndex myActivePartIndex;