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 /// Make some functionality after the objects are hidden in viewer
187 /// \param theObjects a list of hidden objects
188 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
190 /// Returns true if selection for the object can be activate.
191 /// By default a result or feature of the current operation can not be activated
192 /// \param theObject a model object
193 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
195 /// Reacts to the delete action in module
196 /// \returns true if the action is processed
197 virtual bool deleteObjects() { return false; };
199 /// Performs functionality on closing document
200 virtual void closeDocument() = 0;
202 /// Clears specific presentations in the viewer
203 virtual void clearViewer() = 0;
205 /// Returns a list of modes, where the AIS objects should be activated
206 /// \param theModes a list of modes
207 virtual void activeSelectionModes(QIntList& theModes) {}
209 /// Appends specific selection modes for the module to the list of types
210 /// \param theTypes a selection modes to be extended
211 virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
213 /// Return true if the custom presentation is activated
214 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
215 /// \return boolean value
216 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
219 /// Activate custom presentation for the object. Default realization is empty.
220 /// \param theFeature a feature instance
221 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
222 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
223 virtual void activateCustomPrs(const FeaturePtr& theFeature,
224 const ModuleBase_CustomizeFlag& theFlag,
225 const bool theUpdateViewer) {}
227 /// Deactivate custom presentation for the object. Default realization is empty.
228 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
229 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
230 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
231 const bool theUpdateViewer) {}
233 /// Modifies the given presentation in the custom way.
234 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
236 GeomCustomPrsPtr theCustomPrs) { return false; };
238 /// Modifies the given presentation in the custom way after usual customize is performed.
239 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
241 GeomCustomPrsPtr theCustomPrs) { return false; };
243 /// Update the object presentable properties such as color, lines width and other
244 /// If the object is result with the color attribute value set, it is used,
245 /// otherwise the customize is applyed to the object's feature if it is a custom prs
246 /// \param theObject an object instance
247 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
248 /// should be updated(e.g. only highlighted elements)
249 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
250 /// \returns true if the object is modified
251 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
252 const bool theUpdateViewer);
254 /// This method is called on object browser creation for customization of module specific features
255 /// \param theObjectBrowser a pinter on Object Browser widget
256 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
258 /// Creates a new operation
259 /// \param theCmdId the operation name
260 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
262 /// Create specific for the module presentation
263 /// \param theResult an object for presentation
264 /// \return created presentation or NULL(default value)
265 virtual Handle(AIS_InteractiveObject) createPresentation(
266 const std::shared_ptr<ModelAPI_Result>& theResult);
268 //! Returns data object by AIS
269 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
271 //! Returns true if the presentation can be shown in shading mode
272 //! \param theAIS presentation to be checked
273 //! \return boolean value
274 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
276 /// Update state of pop-up menu items in object browser
277 /// \param theStdActions - a map of standard actions
278 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
280 /// Update state of pop-up menu items in viewer
281 /// \param theStdActions - a map of standard actions
282 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
284 /// Returns true if the action should be always enabled
285 /// \param theActionId an action index: Accept or Accept All
286 /// \return boolean value
287 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
289 //! Returns the feature error if the current state of the feature in the module is not correct
290 //! If the feature is correct, it returns an empty value
291 //! \return string value
292 virtual QString getFeatureError(const FeaturePtr& theFeature);
294 /// Returns list of granted operation indices
295 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
297 /// Connects or disconnects to the value changed signal of the property panel widgets
298 /// \param theWidget a property contol widget
299 /// \param isToConnect a boolean value whether connect or disconnect
300 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
302 /// Validates the operation to change the "Apply" button state.
303 /// \param thePreviousState the previous state of the widget
304 virtual void widgetStateChanged(int thePreviousState) {};
306 /// Returns true if the event is processed.
307 /// \param thePreviousAttributeID an index of the previous active attribute
308 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
310 /// Performs some GUI actions before an operation transaction is stopped
311 /// Default realization is empty
312 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
314 /// Finds a shape by attribute if it is possible
315 /// \param theAttribute an attribute
316 /// \return a geom shape
317 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
319 /// Finds an attribute by geom shape if it is possible
320 /// \param theObject an object of the attribute
321 /// \param theGeomShape a geom shape
322 /// \return theAttribute
323 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
324 const GeomShapePtr& theGeomShape) = 0;
326 /// Returns reentrant message if it was accepted
327 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
329 /// Put current selection into reentrant message
330 /// \param theMessage a message of reentrant operation
331 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
333 /// Returns XML information by the feature index
334 /// \param theFeatureId a feature id
335 /// \param theXmlCfg XML configuration
336 /// \param theDescription feature description
337 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
338 std::string& theDescription);
341 /// Signal which is emitted when operation is launched
342 void operationLaunched();
344 /// Segnal emitted when an operation is resumed
345 /// \param theOp a resumed operation
346 void resumed(ModuleBase_Operation* theOp);
349 /// Called on call of command corresponded to a feature
350 virtual void onFeatureTriggered();
352 /// Slot called on object display
353 /// \param theObject a data object
354 /// \param theAIS a presentation object
355 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
357 /// Slot called on before object erase
358 /// \param theObject a data object
359 /// \param theAIS a presentation object
360 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
363 /// Called on selection changed event
364 virtual void onSelectionChanged() {}
367 /// Register validators for this module
368 virtual void registerValidators() {}
370 /// Register properties of this module
371 virtual void registerProperties() {}
373 /// Returns new instance of operation object (used in createOperation for customization)
374 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
377 /// Reference to workshop
378 ModuleBase_IWorkshop* myWorkshop;
380 /// Map of features in XML
381 std::map<std::string, std::string> myFeaturesInFiles;
386 //! This function must return a new module instance.
388 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
391 #define CREATE_MODULE "createModule"
393 #endif //ModuleBase_IModule