1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #ifndef ModuleBase_IModule_H
4 #define ModuleBase_IModule_H
6 #include "ModuleBase.h"
7 #include "ModuleBase_IWorkshop.h"
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Attribute.h>
12 #include <GeomAPI_Shape.h>
13 #include <GeomAPI_ICustomPrs.h>
28 class Config_WidgetAPI;
29 class ModuleBase_ModelWidget;
30 class ModuleBase_Operation;
31 class ModuleBase_ViewerPrs;
33 class ModuleBase_IWorkshop;
34 class ModelAPI_Result;
37 class AIS_InteractiveObject;
41 * Interface to a module
43 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
47 /// enumeration to know which objects should be customized
48 enum ModuleBase_CustomizeFlag {
49 CustomizeArguments = 0, /// references of other objects referenced to the current feature
50 CustomizeResults, /// results of the current feature
51 CustomizeHighlightedObjects /// highlighted objects of the active widget
55 /// \param theParent instance of workshop interface
56 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
58 virtual ~ModuleBase_IModule() {}
60 /// Add default selection filters of the module to the current viewer
61 virtual void activateSelectionFilters() {}
63 /// Remove default selection filters of the module from the current viewer
64 virtual void deactivateSelectionFilters() {}
66 /// Stores the current selection
67 virtual void storeSelection() {}
69 /// Restores the current selection
70 virtual void restoreSelection() {}
72 /// Reads description of features from XML file
73 virtual void createFeatures();
75 /// Called on creation of menu item in desktop
76 virtual void actionCreated(QAction*);
78 /// Launching of a edit operation on the feature
79 /// \param theFeature feature for editing
80 virtual void editFeature(FeaturePtr theFeature);
82 /// Returns true if the operation can be committed. Result in default implementation is true.
83 /// \return boolean value
84 virtual bool canCommitOperation() const { return true; }
86 /// Creates an operation and send it to loop
87 /// \param theCmdId the operation name
88 virtual void launchOperation(const QString& theCmdId);
90 /// Executes feature as a modal dialog box
91 /// \param theCmdId the operation name
92 virtual void launchModal(const QString& theCmdId);
94 /// Realizes some functionality by an operation start
95 /// \param theOperation a started operation
96 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
98 /// Realizes some functionality by an operation resume
99 /// By default it emits operationResumed signal
100 /// \param theOperation a resumed operation
101 virtual void operationResumed(ModuleBase_Operation* theOperation);
103 /// Realizes some functionality by an operation stop
104 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
106 /// Realizes some functionality by an operation commit
107 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
109 /// Realizes some functionality by an operation abort
110 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
112 /// Realizes some functionality by an operation start
113 virtual ModuleBase_Operation* currentOperation() const = 0;
115 /// Add menu items for viewer into the actions map
116 /// \param theStdActions a map of standard actions
117 /// \param theParent a parent widget
118 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
119 /// \return true if items are added and there is no necessity to provide standard menu
120 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
122 QMap<int, QAction*>& theMenuActions) const
125 /// Add menu items for object browser into the given menu
126 /// \param theMenu a popup menu to be shown in the object browser
127 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
129 /// Creates custom widgets for property panel
130 /// \param theType a type of widget
131 /// \param theParent the parent object
132 /// \param theWidgetApi the widget configuration.
133 /// The attribute of the model widget is obtained from
134 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
136 Config_WidgetAPI* theWidgetApi)
141 /// Returns the active widget, by default it is the property panel active widget
142 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
144 /// Returns current workshop
145 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
147 /// Call back forlast tuning of property panel before operation performance
148 /// It is called as on clearing of property panel as on filling with new widgets
149 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
151 /// Have an opportunity to create widgets for the current operation
152 /// instead of standard creation in workshop
153 /// \param theOperation a started operation
154 /// \param theWidgets a list of created widgets
155 /// \return boolean result, false by default
156 virtual bool createWidgets(ModuleBase_Operation* theOperation,
157 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
159 //! Returns True if there are available Undos and there is not an active operation
160 virtual bool canUndo() const;
162 //! Returns True if there are available Redos and there is not an active operation
163 virtual bool canRedo() const;
165 /// Returns true if the action can be applyed to the object
166 /// \param theObject a checked object
167 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
168 /// \return the a boolean result
169 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
171 /// Returns True if the current operation can be committed. By default it is true.
172 /// \return a boolean value
173 //virtual bool canCommitOperation() const;
175 /// Returns whether the object can be erased. The default realization returns true.
176 /// \param theObject a model object
177 virtual bool canEraseObject(const ObjectPtr& theObject) const;
179 /// Returns whether the object can be displayed. The default realization returns true.
180 /// \param theObject a model object
181 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
183 /// Make some functionality after the objects are hidden in viewer
184 /// \param theObjects a list of hidden objects
185 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
187 /// Returns true if selection for the object can be activate.
188 /// By default a result or feature of the current operation can not be activated
189 /// \param theObject a model object
190 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
192 /// Reacts to the delete action in module
193 /// \returns true if the action is processed
194 virtual bool deleteObjects() { return false; };
196 /// Performs functionality on closing document
197 virtual void closeDocument() = 0;
199 /// Clears specific presentations in the viewer
200 virtual void clearViewer() = 0;
202 /// Returns a list of modes, where the AIS objects should be activated
203 /// \param theModes a list of modes
204 virtual void activeSelectionModes(QIntList& theModes) {}
206 /// Appends specific selection modes for the module to the list of types
207 /// \param theTypes a selection modes to be extended
208 virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
210 /// Return true if the custom presentation is activated
211 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
212 /// \return boolean value
213 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
216 /// Activate custom presentation for the object. Default realization is empty.
217 /// \param theFeature a feature instance
218 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
219 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
220 virtual void activateCustomPrs(const FeaturePtr& theFeature,
221 const ModuleBase_CustomizeFlag& theFlag,
222 const bool theUpdateViewer) {}
224 /// Deactivate custom presentation for the object. Default realization is empty.
225 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
226 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
227 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
228 const bool theUpdateViewer) {}
230 /// Modifies the given presentation in the custom way.
231 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
233 GeomCustomPrsPtr theCustomPrs) { return false; };
235 /// Modifies the given presentation in the custom way after usual customize is performed.
236 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
238 GeomCustomPrsPtr theCustomPrs) { return false; };
240 /// Update the object presentable properties such as color, lines width and other
241 /// If the object is result with the color attribute value set, it is used,
242 /// otherwise the customize is applyed to the object's feature if it is a custom prs
243 /// \param theObject an object instance
244 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
245 /// should be updated(e.g. only highlighted elements)
246 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
247 /// \returns true if the object is modified
248 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
249 const bool theUpdateViewer);
251 /// This method is called on object browser creation for customization of module specific features
252 /// \param theObjectBrowser a pinter on Object Browser widget
253 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
255 /// Creates a new operation
256 /// \param theCmdId the operation name
257 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
259 /// Create specific for the module presentation
260 /// \param theResult an object for presentation
261 /// \return created presentation or NULL(default value)
262 virtual Handle(AIS_InteractiveObject) createPresentation(
263 const std::shared_ptr<ModelAPI_Result>& theResult);
265 //! Returns data object by AIS
266 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
268 //! Returns true if the presentation can be shown in shading mode
269 //! \param theAIS presentation to be checked
270 //! \return boolean value
271 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
273 /// Update state of pop-up menu items in object browser
274 /// \param theStdActions - a map of standard actions
275 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
277 /// Update state of pop-up menu items in viewer
278 /// \param theStdActions - a map of standard actions
279 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
281 /// Returns true if the action should be always enabled
282 /// \param theActionId an action index: Accept or Accept All
283 /// \return boolean value
284 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
286 //! Returns the feature error if the current state of the feature in the module is not correct
287 //! If the feature is correct, it returns an empty value
288 //! \return string value
289 virtual QString getFeatureError(const FeaturePtr& theFeature);
291 /// Returns list of granted operation indices
292 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
294 /// Connects or disconnects to the value changed signal of the property panel widgets
295 /// \param theWidget a property contol widget
296 /// \param isToConnect a boolean value whether connect or disconnect
297 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
299 /// Validates the operation to change the "Apply" button state.
300 /// \param thePreviousState the previous state of the widget
301 virtual void widgetStateChanged(int thePreviousState) {};
303 /// Returns true if the event is processed.
304 /// \param thePreviousAttributeID an index of the previous active attribute
305 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
307 /// Performs some GUI actions before an operation transaction is stopped
308 /// Default realization is empty
309 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
311 /// Finds a shape by attribute if it is possible
312 /// \param theAttribute an attribute
313 /// \return a geom shape
314 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
316 /// Finds an attribute by geom shape if it is possible
317 /// \param theObject an object of the attribute
318 /// \param theGeomShape a geom shape
319 /// \return theAttribute
320 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
321 const GeomShapePtr& theGeomShape) = 0;
323 /// Returns reentrant message if it was accepted
324 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
326 /// Put current selection into reentrant message
327 /// \param theMessage a message of reentrant operation
328 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
330 /// Returns XML information by the feature index
331 /// \param theFeatureId a feature id
332 /// \param theXmlCfg XML configuration
333 /// \param theDescription feature description
334 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
335 std::string& theDescription);
338 /// Signal which is emitted when operation is launched
339 void operationLaunched();
341 /// Segnal emitted when an operation is resumed
342 /// \param theOp a resumed operation
343 void resumed(ModuleBase_Operation* theOp);
346 /// Called on call of command corresponded to a feature
347 virtual void onFeatureTriggered();
349 /// Slot called on object display
350 /// \param theObject a data object
351 /// \param theAIS a presentation object
352 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
354 /// Slot called on before object erase
355 /// \param theObject a data object
356 /// \param theAIS a presentation object
357 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
360 /// Called on selection changed event
361 virtual void onSelectionChanged() {}
364 /// Register validators for this module
365 virtual void registerValidators() {}
367 /// Register properties of this module
368 virtual void registerProperties() {}
370 /// Returns new instance of operation object (used in createOperation for customization)
371 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
374 /// Reference to workshop
375 ModuleBase_IWorkshop* myWorkshop;
377 /// Map of features in XML
378 std::map<std::string, std::string> myFeaturesInFiles;
383 //! This function must return a new module instance.
385 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
388 #define CREATE_MODULE "createModule"
390 #endif //ModuleBase_IModule