1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
\r
3 #ifndef ModuleBase_IModule_H
\r
4 #define ModuleBase_IModule_H
\r
6 #include "ModuleBase.h"
\r
7 #include "ModuleBase_IWorkshop.h"
\r
9 #include <ModelAPI_Feature.h>
\r
10 #include <ModelAPI_Attribute.h>
\r
12 #include <GeomAPI_Shape.h>
\r
25 class Config_WidgetAPI;
\r
26 class ModuleBase_ModelWidget;
\r
27 class ModuleBase_Operation;
\r
28 class ModuleBase_IWorkshop;
\r
32 * Interface to a module
\r
34 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
\r
38 /// enumeration to know which objects should be customized
\r
39 enum ModuleBase_CustomizeFlag {
\r
40 CustomizeArguments = 0, /// references of other objects referenced to the current feature
\r
41 CustomizeResults, /// results of the current feature
\r
42 CustomizeHighlightedObjects /// highlighted objects of the active widget
\r
46 /// \param theParent instance of workshop interface
\r
47 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
\r
49 virtual ~ModuleBase_IModule() {}
\r
51 /// Add default selection filters of the module to the current viewer
\r
52 virtual void activateSelectionFilters() {};
\r
54 /// Remove default selection filters of the module from the current viewer
\r
55 virtual void deactivateSelectionFilters() {};
\r
57 /// Reads description of features from XML file
\r
58 virtual void createFeatures();
\r
60 /// Called on creation of menu item in desktop
\r
61 virtual void actionCreated(QAction*);
\r
63 /// Launching of a edit operation on the feature
\r
64 /// \param theFeature feature for editing
\r
65 virtual void editFeature(FeaturePtr theFeature);
\r
67 /// Creates an operation and send it to loop
\r
68 /// \param theCmdId the operation name
\r
69 virtual void launchOperation(const QString& theCmdId);
\r
71 /// Realizes some functionality by an operation start
\r
72 /// \param theOperation a started operation
\r
73 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
\r
75 /// Realizes some functionality by an operation resume
\r
76 /// By default it emits operationResumed signal
\r
77 /// \param theOperation a resumed operation
\r
78 virtual void operationResumed(ModuleBase_Operation* theOperation);
\r
80 /// Realizes some functionality by an operation stop
\r
81 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
\r
83 /// Realizes some functionality by an operation commit
\r
84 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
\r
86 /// Realizes some functionality by an operation abort
\r
87 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
\r
89 /// Realizes some functionality by an operation start
\r
90 virtual ModuleBase_Operation* currentOperation() const = 0;
\r
92 /// Add menu items for viewer into the given menu
\r
93 /// \param theMenu a popup menu to be shown in the viewer
\r
94 /// \param theStdActions a map of standard actions
\r
95 /// \return true if items are added and there is no necessity to provide standard menu
\r
96 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }
\r
98 /// Add menu items for object browser into the given menu
\r
99 /// \param theMenu a popup menu to be shown in the object browser
\r
100 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
\r
102 /// Creates custom widgets for property panel
\r
103 /// \param theType a type of widget
\r
104 /// \param theParent the parent object
\r
105 /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from
\r
106 /// \param theParentId is Id of a parent of the current attribute
\r
107 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
\r
108 Config_WidgetAPI* theWidgetApi, std::string theParentId)
\r
113 /// Returns the active widget, by default it is the property panel active widget
\r
114 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
\r
116 /// Returns current workshop
\r
117 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
\r
119 /// Call back forlast tuning of property panel before operation performance
\r
120 /// It is called as on clearing of property panel as on filling with new widgets
\r
121 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
\r
123 //! Returns True if there are available Undos and there is not an active operation
\r
124 virtual bool canUndo() const;
\r
126 //! Returns True if there are available Redos and there is not an active operation
\r
127 virtual bool canRedo() const;
\r
129 /// Returns true if the action can be applyed to the object
\r
130 /// \param theObject a checked object
\r
131 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
\r
132 /// \return the a boolean result
\r
133 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
\r
135 /// Returns True if the current operation can be committed. By default it is true.
\r
136 /// \return a boolean value
\r
137 //virtual bool canCommitOperation() const;
\r
139 /// Returns whether the object can be erased. The default realization returns true.
\r
140 /// \param theObject a model object
\r
141 virtual bool canEraseObject(const ObjectPtr& theObject) const;
\r
143 /// Returns whether the object can be displayed. The default realization returns true.
\r
144 /// \param theObject a model object
\r
145 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
\r
147 /// Make some functionality after the objects are hidden in viewer
\r
148 /// \param theObjects a list of hidden objects
\r
149 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
\r
151 /// Returns true if selection for the object can be activate.
\r
152 /// By default a result or feature of the current operation can not be activated
\r
153 /// \param theObject a model object
\r
154 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
\r
156 /// Reacts to the delete action in module
\r
157 /// \returns true if the action is processed
\r
158 virtual bool deleteObjects() { return false; };
\r
160 /// Performs functionality on closing document
\r
161 virtual void closeDocument() = 0;
\r
163 /// Clears specific presentations in the viewer
\r
164 virtual void clearViewer() = 0;
\r
166 /// Returns a list of modes, where the AIS objects should be activated
\r
167 /// \param theModes a list of modes
\r
168 virtual void activeSelectionModes(QIntList& theModes) {}
\r
170 /// Activate custom presentation for the object. Default realization is empty.
\r
171 /// \param theObject an object instance
\r
172 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
173 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
174 virtual void activateCustomPrs(const FeaturePtr& theFeature,
\r
175 const ModuleBase_CustomizeFlag& theFlag,
\r
176 const bool theUpdateViewer) {}
\r
178 /// Deactivate custom presentation for the object. Default realization is empty.
\r
179 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
180 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
181 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
\r
182 const bool theUpdateViewer) {}
\r
184 /// Update the object presentable properties such as color, lines width and other
\r
185 /// If the object is result with the color attribute value set, it is used,
\r
186 /// otherwise the customize is applyed to the object's feature if it is a custom prs
\r
187 /// \param theObject an object instance
\r
188 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
189 /// should be updated(e.g. only highlighted elements)
\r
190 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
191 /// \returns true if the object is modified
\r
192 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
\r
193 const bool theUpdateViewer);
\r
195 /// This method is called on object browser creation for customization of module specific features
\r
196 /// \param theObjectBrowser a pinter on Object Browser widget
\r
197 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
\r
199 /// Creates a new operation
\r
200 /// \param theCmdId the operation name
\r
201 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
\r
203 /// Sends the operation for launching
\r
204 /// \param theOperation the operation
\r
205 virtual void sendOperation(ModuleBase_Operation* theOperation);
\r
207 //! Returns data object by AIS
\r
208 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
\r
210 /// Update state of pop-up menu items in object browser
\r
211 /// \param theStdActions - a map of standard actions
\r
212 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
214 /// Update state of pop-up menu items in viewer
\r
215 /// \param theStdActions - a map of standard actions
\r
216 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
218 //! Returns the feature error if the current state of the feature in the module is not correct
\r
219 //! If the feature is correct, it returns an empty value
\r
220 //! \return string value
\r
221 virtual QString getFeatureError(const FeaturePtr& theFeature);
\r
223 /// Returns list of granted operation indices
\r
224 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
\r
226 /// Connects or disconnects to the value changed signal of the property panel widgets
\r
227 /// \param theWidget a property contol widget
\r
228 /// \param isToConnect a boolean value whether connect or disconnect
\r
229 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
\r
231 /// Validates the operation to change the "Apply" button state.
\r
232 /// \param thePreviousState the previous state of the widget
\r
233 virtual void widgetStateChanged(int thePreviousState) {};
\r
235 /// Returns true if the event is processed.
\r
236 /// \param thePreviousAttributeID an index of the previous active attribute
\r
237 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
\r
239 /// Performs some GUI actions after an operation transaction is opened
\r
240 /// Default realization is empty
\r
241 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};
\r
243 /// Performs some GUI actions before an operation transaction is stopped
\r
244 /// Default realization is empty
\r
245 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
\r
247 /// Finds a shape by attribute if it is possible
\r
248 /// \param theAttribute an attribute
\r
249 /// \return a geom shape
\r
250 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
\r
252 /// Finds an attribute by geom shape if it is possible
\r
253 /// \param theObject an object of the attribute
\r
254 /// \param theGeomShape a geom shape
\r
255 /// \return theAttribute
\r
256 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
\r
257 const GeomShapePtr& theGeomShape) = 0;
\r
260 /// Signal which is emitted when operation is launched
\r
261 void operationLaunched();
\r
263 /// Segnal emitted when an operation is resumed
\r
264 /// \param theOp a resumed operation
\r
265 void resumed(ModuleBase_Operation* theOp);
\r
268 /// Called on call of command corresponded to a feature
\r
269 virtual void onFeatureTriggered();
\r
271 /// Slot called on object display
\r
272 /// \param theObject a data object
\r
273 /// \param theAIS a presentation object
\r
274 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
276 /// Slot called on before object erase
\r
277 /// \param theObject a data object
\r
278 /// \param theAIS a presentation object
\r
279 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
282 /// Called on selection changed event
\r
283 virtual void onSelectionChanged() {}
\r
286 /// Register validators for this module
\r
287 virtual void registerValidators() {}
\r
289 /// Register selection filters for this module
\r
290 virtual void registerFilters() {}
\r
292 /// Register properties of this module
\r
293 virtual void registerProperties() {}
\r
295 /// Returns new instance of operation object (used in createOperation for customization)
\r
296 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
\r
300 /// Reference to workshop
\r
301 ModuleBase_IWorkshop* myWorkshop;
\r
303 /// Map of features in XML
\r
304 std::map<std::string, std::string> myFeaturesInFiles;
\r
309 //! This function must return a new module instance.
\r
311 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
\r
314 #define CREATE_MODULE "createModule"
\r
316 #endif //ModuleBase_IModule
\r