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 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
90 virtual void launchOperation(const QString& theCmdId,
91 const bool& isStartAfterCommitOnly);
93 /// Executes feature as a modal dialog box
94 /// \param theCmdId the operation name
95 virtual void launchModal(const QString& theCmdId);
97 /// Realizes some functionality by an operation start
98 /// \param theOperation a started operation
99 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
101 /// Realizes some functionality by an operation resume
102 /// By default it emits operationResumed signal
103 /// \param theOperation a resumed operation
104 virtual void operationResumed(ModuleBase_Operation* theOperation);
106 /// Realizes some functionality by an operation stop
107 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
109 /// Realizes some functionality by an operation commit
110 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
112 /// Realizes some functionality by an operation abort
113 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
115 /// Realizes some functionality by an operation start
116 virtual ModuleBase_Operation* currentOperation() const = 0;
118 /// Add menu items for viewer into the actions map
119 /// \param theStdActions a map of standard actions
120 /// \param theParent a parent widget
121 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
122 /// \return true if items are added and there is no necessity to provide standard menu
123 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
125 QMap<int, QAction*>& theMenuActions) const
128 /// Add menu items for object browser into the given menu
129 /// \param theMenu a popup menu to be shown in the object browser
130 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
132 /// Creates custom widgets for property panel
133 /// \param theType a type of widget
134 /// \param theParent the parent object
135 /// \param theWidgetApi the widget configuration.
136 /// The attribute of the model widget is obtained from
137 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
139 Config_WidgetAPI* theWidgetApi)
144 /// Returns the active widget, by default it is the property panel active widget
145 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
147 /// Returns current workshop
148 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
150 /// Call back forlast tuning of property panel before operation performance
151 /// It is called as on clearing of property panel as on filling with new widgets
152 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
154 /// Have an opportunity to create widgets for the current operation
155 /// instead of standard creation in workshop
156 /// \param theOperation a started operation
157 /// \param theWidgets a list of created widgets
158 /// \return boolean result, false by default
159 virtual bool createWidgets(ModuleBase_Operation* theOperation,
160 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
162 //! Returns True if there are available Undos and there is not an active operation
163 virtual bool canUndo() const;
165 //! Returns True if there are available Redos and there is not an active operation
166 virtual bool canRedo() const;
168 /// Returns true if the action can be applyed to the object
169 /// \param theObject a checked object
170 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
171 /// \return the a boolean result
172 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
174 /// Returns True if the current operation can be committed. By default it is true.
175 /// \return a boolean value
176 //virtual bool canCommitOperation() const;
178 /// Returns whether the object can be erased. The default realization returns true.
179 /// \param theObject a model object
180 virtual bool canEraseObject(const ObjectPtr& theObject) const;
182 /// Returns whether the object can be displayed. The default realization returns true.
183 /// \param theObject a model object
184 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
186 /// Returns whether the started operation may use preselection of the previous one
187 /// Cases are: previous operation is null, edit operation, previuos and started operations
188 /// kinds are the same
189 /// \param thePreviousOperationKind a kind of previous operation
190 /// \param theStartedOperationKind a kind of a started operation
191 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
192 const QString& theStartedOperationKind);
194 /// Make some functionality after the objects are hidden in viewer
195 /// \param theObjects a list of hidden objects
196 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
198 /// Returns true if selection for the object can be activate.
199 /// By default a result or feature of the current operation can not be activated
200 /// \param theObject a model object
201 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
203 /// Reacts to the delete action in module
204 /// \returns true if the action is processed
205 virtual bool deleteObjects() { return false; };
207 /// Performs functionality on closing document
208 virtual void closeDocument() = 0;
210 /// Clears specific presentations in the viewer
211 virtual void clearViewer() = 0;
213 /// Returns a list of modes, where the AIS objects should be activated
214 /// \param theModes a list of modes
215 virtual void activeSelectionModes(QIntList& theModes) {}
217 /// Appends specific selection modes for the module to the list of types
218 /// \param theTypes a selection modes to be extended
219 virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
221 /// Return true if the custom presentation is activated
222 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
223 /// \return boolean value
224 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
227 /// Activate custom presentation for the object. Default realization is empty.
228 /// \param theFeature a feature instance
229 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
230 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
231 virtual void activateCustomPrs(const FeaturePtr& theFeature,
232 const ModuleBase_CustomizeFlag& theFlag,
233 const bool theUpdateViewer) {}
235 /// Deactivate custom presentation for the object. Default realization is empty.
236 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
237 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
238 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
239 const bool theUpdateViewer) {}
241 /// Modifies the given presentation in the custom way.
242 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
244 GeomCustomPrsPtr theCustomPrs) { return false; };
246 /// Modifies the given presentation in the custom way after usual customize is performed.
247 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
249 GeomCustomPrsPtr theCustomPrs) { return false; };
251 /// Update the object presentable properties such as color, lines width and other
252 /// If the object is result with the color attribute value set, it is used,
253 /// otherwise the customize is applyed to the object's feature if it is a custom prs
254 /// \param theObject an object instance
255 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
256 /// should be updated(e.g. only highlighted elements)
257 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
258 /// \returns true if the object is modified
259 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
260 const bool theUpdateViewer);
262 /// This method is called on object browser creation for customization of module specific features
263 /// \param theObjectBrowser a pinter on Object Browser widget
264 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
266 /// Creates a new operation
267 /// \param theCmdId the operation name
268 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
270 /// Create specific for the module presentation
271 /// \param theResult an object for presentation
272 /// \return created presentation or NULL(default value)
273 virtual Handle(AIS_InteractiveObject) createPresentation(
274 const std::shared_ptr<ModelAPI_Result>& theResult);
276 //! Returns data object by AIS
277 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
279 //! Returns true if the presentation can be shown in shading mode
280 //! \param theAIS presentation to be checked
281 //! \return boolean value
282 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
284 /// Update state of pop-up menu items in object browser
285 /// \param theStdActions - a map of standard actions
286 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
288 /// Update state of pop-up menu items in viewer
289 /// \param theStdActions - a map of standard actions
290 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
292 /// Returns true if the action should be always enabled
293 /// \param theActionId an action index: Accept or Accept All
294 /// \return boolean value
295 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
297 //! Returns the feature error if the current state of the feature in the module is not correct
298 //! If the feature is correct, it returns an empty value
299 //! \return string value
300 virtual QString getFeatureError(const FeaturePtr& theFeature);
302 /// Returns list of granted operation indices
303 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
305 /// Connects or disconnects to the value changed signal of the property panel widgets
306 /// \param theWidget a property contol widget
307 /// \param isToConnect a boolean value whether connect or disconnect
308 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
310 /// Validates the operation to change the "Apply" button state.
311 /// \param thePreviousState the previous state of the widget
312 virtual void widgetStateChanged(int thePreviousState) {};
314 /// Returns true if the event is processed.
315 /// \param thePreviousAttributeID an index of the previous active attribute
316 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
318 /// Performs some GUI actions before an operation transaction is stopped
319 /// Default realization is empty
320 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
322 /// Finds a shape by attribute if it is possible
323 /// \param theAttribute an attribute
324 /// \return a geom shape
325 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
327 /// Finds an attribute by geom shape if it is possible
328 /// \param theObject an object of the attribute
329 /// \param theGeomShape a geom shape
330 /// \return theAttribute
331 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
332 const GeomShapePtr& theGeomShape) = 0;
334 /// Returns reentrant message if it was accepted
335 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
337 /// Put current selection into reentrant message
338 /// \param theMessage a message of reentrant operation
339 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
341 /// Returns XML information by the feature index
342 /// \param theFeatureId a feature id
343 /// \param theXmlCfg XML configuration
344 /// \param theDescription feature description
345 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
346 std::string& theDescription);
349 /// Signal which is emitted when operation is launched
350 void operationLaunched();
352 /// Segnal emitted when an operation is resumed
353 /// \param theOp a resumed operation
354 void resumed(ModuleBase_Operation* theOp);
357 /// Called on call of command corresponded to a feature
358 virtual void onFeatureTriggered();
360 /// Slot called on object display
361 /// \param theObject a data object
362 /// \param theAIS a presentation object
363 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
365 /// Slot called on before object erase
366 /// \param theObject a data object
367 /// \param theAIS a presentation object
368 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
371 /// Called on selection changed event
372 virtual void onSelectionChanged() {}
375 /// Register validators for this module
376 virtual void registerValidators() {}
378 /// Register properties of this module
379 virtual void registerProperties() {}
381 /// Returns new instance of operation object (used in createOperation for customization)
382 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
385 /// Reference to workshop
386 ModuleBase_IWorkshop* myWorkshop;
388 /// Map of features in XML
389 std::map<std::string, std::string> myFeaturesInFiles;
394 //! This function must return a new module instance.
396 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
399 #define CREATE_MODULE "createModule"
401 #endif //ModuleBase_IModule