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. The attribute of the model widget is obtained from
130 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
131 Config_WidgetAPI* theWidgetApi)
136 /// Returns the active widget, by default it is the property panel active widget
137 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
139 /// Returns current workshop
140 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
142 /// Call back forlast tuning of property panel before operation performance
143 /// It is called as on clearing of property panel as on filling with new widgets
144 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
146 /// Have an opportunity to create widgets for the current operation instead of standard creation in workshop
147 /// \param theOperation a started operation
148 /// \param theWidgets a list of created widgets
149 /// \return boolean result, false by default
150 virtual bool createWidgets(ModuleBase_Operation* theOperation,
151 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
153 //! Returns True if there are available Undos and there is not an active operation
154 virtual bool canUndo() const;
156 //! Returns True if there are available Redos and there is not an active operation
157 virtual bool canRedo() const;
159 /// Returns true if the action can be applyed to the object
160 /// \param theObject a checked object
161 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
162 /// \return the a boolean result
163 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
165 /// Returns True if the current operation can be committed. By default it is true.
166 /// \return a boolean value
167 //virtual bool canCommitOperation() const;
169 /// Returns whether the object can be erased. The default realization returns true.
170 /// \param theObject a model object
171 virtual bool canEraseObject(const ObjectPtr& theObject) const;
173 /// Returns whether the object can be displayed. The default realization returns true.
174 /// \param theObject a model object
175 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
177 /// Make some functionality after the objects are hidden in viewer
178 /// \param theObjects a list of hidden objects
179 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
181 /// Returns true if selection for the object can be activate.
182 /// By default a result or feature of the current operation can not be activated
183 /// \param theObject a model object
184 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
186 /// Reacts to the delete action in module
187 /// \returns true if the action is processed
188 virtual bool deleteObjects() { return false; };
190 /// Performs functionality on closing document
191 virtual void closeDocument() = 0;
193 /// Clears specific presentations in the viewer
194 virtual void clearViewer() = 0;
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 /// Return true if the custom presentation is activated
205 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
206 /// \return boolean value
207 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const { return false; };
209 /// Activate custom presentation for the object. Default realization is empty.
210 /// \param theFeature a feature instance
211 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
212 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
213 virtual void activateCustomPrs(const FeaturePtr& theFeature,
214 const ModuleBase_CustomizeFlag& theFlag,
215 const bool theUpdateViewer) {}
217 /// Deactivate custom presentation for the object. Default realization is empty.
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 deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
221 const bool theUpdateViewer) {}
223 /// Modifies the given presentation in the custom way.
224 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult, AISObjectPtr thePrs,
225 GeomCustomPrsPtr theCustomPrs) { return false; };
227 /// Update the object presentable properties such as color, lines width and other
228 /// If the object is result with the color attribute value set, it is used,
229 /// otherwise the customize is applyed to the object's feature if it is a custom prs
230 /// \param theObject an object instance
231 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
232 /// should be updated(e.g. only highlighted elements)
233 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
234 /// \returns true if the object is modified
235 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
236 const bool theUpdateViewer);
238 /// This method is called on object browser creation for customization of module specific features
239 /// \param theObjectBrowser a pinter on Object Browser widget
240 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
242 /// Creates a new operation
243 /// \param theCmdId the operation name
244 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
246 /// Create specific for the module presentation
247 /// \param theResult an object for presentation
248 /// \return created presentation or NULL(default value)
249 virtual Handle_AIS_InteractiveObject createPresentation(
250 const std::shared_ptr<ModelAPI_Result>& theResult);
252 //! Returns data object by AIS
253 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
255 //! Returns true if the presentation can be shown in shading mode
256 //! \param theAIS presentation to be checked
257 //! \return boolean value
258 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
260 /// Update state of pop-up menu items in object browser
261 /// \param theStdActions - a map of standard actions
262 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
264 /// Update state of pop-up menu items in viewer
265 /// \param theStdActions - a map of standard actions
266 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
268 /// Returns true if the action should be always enabled
269 /// \param theActionId an action index: Accept or Accept All
270 /// \return boolean value
271 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
273 //! Returns the feature error if the current state of the feature in the module is not correct
274 //! If the feature is correct, it returns an empty value
275 //! \return string value
276 virtual QString getFeatureError(const FeaturePtr& theFeature);
278 /// Returns list of granted operation indices
279 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
281 /// Connects or disconnects to the value changed signal of the property panel widgets
282 /// \param theWidget a property contol widget
283 /// \param isToConnect a boolean value whether connect or disconnect
284 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
286 /// Validates the operation to change the "Apply" button state.
287 /// \param thePreviousState the previous state of the widget
288 virtual void widgetStateChanged(int thePreviousState) {};
290 /// Returns true if the event is processed.
291 /// \param thePreviousAttributeID an index of the previous active attribute
292 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
294 /// Performs some GUI actions before an operation transaction is stopped
295 /// Default realization is empty
296 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
298 /// Finds a shape by attribute if it is possible
299 /// \param theAttribute an attribute
300 /// \return a geom shape
301 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
303 /// Finds an attribute by geom shape if it is possible
304 /// \param theObject an object of the attribute
305 /// \param theGeomShape a geom shape
306 /// \return theAttribute
307 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
308 const GeomShapePtr& theGeomShape) = 0;
310 /// Returns XML information by the feature index
311 /// \param theFeatureId a feature id
312 /// \param theXmlCfg XML configuration
313 /// \param theDescription feature description
314 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
315 std::string& theDescription);
318 /// Signal which is emitted when operation is launched
319 void operationLaunched();
321 /// Segnal emitted when an operation is resumed
322 /// \param theOp a resumed operation
323 void resumed(ModuleBase_Operation* theOp);
326 /// Called on call of command corresponded to a feature
327 virtual void onFeatureTriggered();
329 /// Slot called on object display
330 /// \param theObject a data object
331 /// \param theAIS a presentation object
332 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
334 /// Slot called on before object erase
335 /// \param theObject a data object
336 /// \param theAIS a presentation object
337 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
340 /// Called on selection changed event
341 virtual void onSelectionChanged() {}
344 /// Register validators for this module
345 virtual void registerValidators() {}
347 /// Register selection filters for this module
348 virtual void registerFilters() {}
350 /// Register properties of this module
351 virtual void registerProperties() {}
353 /// Returns new instance of operation object (used in createOperation for customization)
354 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
357 /// Reference to workshop
358 ModuleBase_IWorkshop* myWorkshop;
360 /// Map of features in XML
361 std::map<std::string, std::string> myFeaturesInFiles;
366 //! This function must return a new module instance.
368 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
371 #define CREATE_MODULE "createModule"
373 #endif //ModuleBase_IModule