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_IWorkshop;
32 class ModelAPI_Result;
34 class Handle_AIS_InteractiveObject;
38 * Interface to a module
40 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
44 /// enumeration to know which objects should be customized
45 enum ModuleBase_CustomizeFlag {
46 CustomizeArguments = 0, /// references of other objects referenced to the current feature
47 CustomizeResults, /// results of the current feature
48 CustomizeHighlightedObjects /// highlighted objects of the active widget
52 /// \param theParent instance of workshop interface
53 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
55 virtual ~ModuleBase_IModule() {}
57 /// Add default selection filters of the module to the current viewer
58 virtual void activateSelectionFilters() {};
60 /// Remove default selection filters of the module from the current viewer
61 virtual void deactivateSelectionFilters() {};
63 /// Stores the current selection
64 virtual void storeSelection() {};
66 /// Restores the current selection
67 virtual void restoreSelection() {};
69 /// Reads description of features from XML file
70 virtual void createFeatures();
72 /// Called on creation of menu item in desktop
73 virtual void actionCreated(QAction*);
75 /// Launching of a edit operation on the feature
76 /// \param theFeature feature for editing
77 virtual void editFeature(FeaturePtr theFeature);
79 /// Returns true if the operation can be committed. Result in default implementation is true.
80 /// \return boolean value
81 virtual bool canCommitOperation() const { return true; }
83 /// Creates an operation and send it to loop
84 /// \param theCmdId the operation name
85 virtual void launchOperation(const QString& theCmdId);
87 /// Executes feature as a modal dialog box
88 /// \param theCmdId the operation name
89 virtual void launchModal(const QString& theCmdId);
91 /// Realizes some functionality by an operation start
92 /// \param theOperation a started operation
93 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
95 /// Realizes some functionality by an operation resume
96 /// By default it emits operationResumed signal
97 /// \param theOperation a resumed operation
98 virtual void operationResumed(ModuleBase_Operation* theOperation);
100 /// Realizes some functionality by an operation stop
101 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
103 /// Realizes some functionality by an operation commit
104 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
106 /// Realizes some functionality by an operation abort
107 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
109 /// Realizes some functionality by an operation start
110 virtual ModuleBase_Operation* currentOperation() const = 0;
112 /// Add menu items for viewer into the actions map
113 /// \param theStdActions a map of standard actions
114 /// \param theParent a parent widget
115 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
116 /// \return true if items are added and there is no necessity to provide standard menu
117 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
119 QMap<int, QAction*>& theMenuActions) const
122 /// Add menu items for object browser into the given menu
123 /// \param theMenu a popup menu to be shown in the object browser
124 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
126 /// Creates custom widgets for property panel
127 /// \param theType a type of widget
128 /// \param theParent the parent object
129 /// \param theWidgetApi the widget configuration.
130 /// The attribute of the model widget is obtained from
131 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
133 Config_WidgetAPI* theWidgetApi)
138 /// Returns the active widget, by default it is the property panel active widget
139 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
141 /// Returns current workshop
142 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
144 /// Call back forlast tuning of property panel before operation performance
145 /// It is called as on clearing of property panel as on filling with new widgets
146 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
148 /// Have an opportunity to create widgets for the current operation
149 /// instead of standard creation in workshop
150 /// \param theOperation a started operation
151 /// \param theWidgets a list of created widgets
152 /// \return boolean result, false by default
153 virtual bool createWidgets(ModuleBase_Operation* theOperation,
154 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
156 //! Returns True if there are available Undos and there is not an active operation
157 virtual bool canUndo() const;
159 //! Returns True if there are available Redos and there is not an active operation
160 virtual bool canRedo() const;
162 /// Returns true if the action can be applyed to the object
163 /// \param theObject a checked object
164 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
165 /// \return the a boolean result
166 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
168 /// Returns True if the current operation can be committed. By default it is true.
169 /// \return a boolean value
170 //virtual bool canCommitOperation() const;
172 /// Returns whether the object can be erased. The default realization returns true.
173 /// \param theObject a model object
174 virtual bool canEraseObject(const ObjectPtr& theObject) const;
176 /// Returns whether the object can be displayed. The default realization returns true.
177 /// \param theObject a model object
178 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
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 /// By default a result or feature of the current operation can not be activated
186 /// \param theObject a model object
187 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
189 /// Reacts to the delete action in module
190 /// \returns true if the action is processed
191 virtual bool deleteObjects() { return false; };
193 /// Performs functionality on closing document
194 virtual void closeDocument() = 0;
196 /// Clears specific presentations in the viewer
197 virtual void clearViewer() = 0;
199 /// Returns a list of modes, where the AIS objects should be activated
200 /// \param theModes a list of modes
201 virtual void activeSelectionModes(QIntList& theModes) {}
203 /// Appends specific selection modes for the module to the list of types
204 /// \param theTypes a selection modes to be extended
205 virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
207 /// Return true if the custom presentation is activated
208 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
209 /// \return boolean value
210 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
213 /// Activate custom presentation for the object. Default realization is empty.
214 /// \param theFeature a feature instance
215 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
216 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
217 virtual void activateCustomPrs(const FeaturePtr& theFeature,
218 const ModuleBase_CustomizeFlag& theFlag,
219 const bool theUpdateViewer) {}
221 /// Deactivate custom presentation for the object. Default realization is empty.
222 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
223 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
224 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
225 const bool theUpdateViewer) {}
227 /// Modifies the given presentation in the custom way.
228 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
230 GeomCustomPrsPtr theCustomPrs) { return false; };
232 /// Update the object presentable properties such as color, lines width and other
233 /// If the object is result with the color attribute value set, it is used,
234 /// otherwise the customize is applyed to the object's feature if it is a custom prs
235 /// \param theObject an object instance
236 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
237 /// should be updated(e.g. only highlighted elements)
238 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
239 /// \returns true if the object is modified
240 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
241 const bool theUpdateViewer);
243 /// This method is called on object browser creation for customization of module specific features
244 /// \param theObjectBrowser a pinter on Object Browser widget
245 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
247 /// Creates a new operation
248 /// \param theCmdId the operation name
249 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
251 /// Create specific for the module presentation
252 /// \param theResult an object for presentation
253 /// \return created presentation or NULL(default value)
254 virtual Handle_AIS_InteractiveObject createPresentation(
255 const std::shared_ptr<ModelAPI_Result>& theResult);
257 //! Returns data object by AIS
258 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
260 //! Returns true if the presentation can be shown in shading mode
261 //! \param theAIS presentation to be checked
262 //! \return boolean value
263 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
265 /// Update state of pop-up menu items in object browser
266 /// \param theStdActions - a map of standard actions
267 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
269 /// Update state of pop-up menu items in viewer
270 /// \param theStdActions - a map of standard actions
271 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
273 /// Returns true if the action should be always enabled
274 /// \param theActionId an action index: Accept or Accept All
275 /// \return boolean value
276 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
278 //! Returns the feature error if the current state of the feature in the module is not correct
279 //! If the feature is correct, it returns an empty value
280 //! \return string value
281 virtual QString getFeatureError(const FeaturePtr& theFeature);
283 /// Returns list of granted operation indices
284 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
286 /// Connects or disconnects to the value changed signal of the property panel widgets
287 /// \param theWidget a property contol widget
288 /// \param isToConnect a boolean value whether connect or disconnect
289 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
291 /// Validates the operation to change the "Apply" button state.
292 /// \param thePreviousState the previous state of the widget
293 virtual void widgetStateChanged(int thePreviousState) {};
295 /// Returns true if the event is processed.
296 /// \param thePreviousAttributeID an index of the previous active attribute
297 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
299 /// Performs some GUI actions before an operation transaction is stopped
300 /// Default realization is empty
301 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
303 /// Finds a shape by attribute if it is possible
304 /// \param theAttribute an attribute
305 /// \return a geom shape
306 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
308 /// Finds an attribute by geom shape if it is possible
309 /// \param theObject an object of the attribute
310 /// \param theGeomShape a geom shape
311 /// \return theAttribute
312 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
313 const GeomShapePtr& theGeomShape) = 0;
315 /// Returns XML information by the feature index
316 /// \param theFeatureId a feature id
317 /// \param theXmlCfg XML configuration
318 /// \param theDescription feature description
319 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
320 std::string& theDescription);
323 /// Signal which is emitted when operation is launched
324 void operationLaunched();
326 /// Segnal emitted when an operation is resumed
327 /// \param theOp a resumed operation
328 void resumed(ModuleBase_Operation* theOp);
331 /// Called on call of command corresponded to a feature
332 virtual void onFeatureTriggered();
334 /// Slot called on object display
335 /// \param theObject a data object
336 /// \param theAIS a presentation object
337 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
339 /// Slot called on before object erase
340 /// \param theObject a data object
341 /// \param theAIS a presentation object
342 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
345 /// Called on selection changed event
346 virtual void onSelectionChanged() {}
349 /// Register validators for this module
350 virtual void registerValidators() {}
352 /// Register selection filters for this module
353 virtual void registerFilters() {}
355 /// Register properties of this module
356 virtual void registerProperties() {}
358 /// Returns new instance of operation object (used in createOperation for customization)
359 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
362 /// Reference to workshop
363 ModuleBase_IWorkshop* myWorkshop;
365 /// Map of features in XML
366 std::map<std::string, std::string> myFeaturesInFiles;
371 //! This function must return a new module instance.
373 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
376 #define CREATE_MODULE "createModule"
378 #endif //ModuleBase_IModule