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
22 class Config_WidgetAPI;
\r
23 class ModuleBase_ModelWidget;
\r
24 class ModuleBase_Operation;
\r
25 class ModuleBase_IWorkshop;
\r
29 * Interface to a module
\r
31 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
\r
35 /// enumeration to know which objects should be customized
\r
36 enum ModuleBase_CustomizeFlag {
\r
37 CustomizeDependedAndResults = 0x00000000,
\r
38 CustomizeHighlightedObjects = 0x00000001
\r
42 /// \param theParent instance of workshop interface
\r
43 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
\r
45 virtual ~ModuleBase_IModule() {}
\r
47 /// Add default selection filters of the module to the current viewer
\r
48 virtual void activateSelectionFilters() {};
\r
50 /// Remove default selection filters of the module from the current viewer
\r
51 virtual void deactivateSelectionFilters() {};
\r
53 /// Reads description of features from XML file
\r
54 virtual void createFeatures();
\r
56 /// Called on creation of menu item in desktop
\r
57 virtual void actionCreated(QAction*);
\r
59 /// Launching of a edit operation on the feature
\r
60 /// \param theFeature feature for editing
\r
61 virtual void editFeature(FeaturePtr theFeature);
\r
63 /// Creates an operation and send it to loop
\r
64 /// \param theCmdId the operation name
\r
65 virtual void launchOperation(const QString& theCmdId);
\r
67 /// Realizes some functionality by an operation start
\r
68 /// \param theOperation a started operation
\r
69 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
\r
71 /// Realizes some functionality by an operation resume
\r
72 /// By default it emits operationResumed signal
\r
73 /// \param theOperation a resumed operation
\r
74 virtual void operationResumed(ModuleBase_Operation* theOperation);
\r
76 /// Realizes some functionality by an operation stop
\r
77 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
\r
79 /// Realizes some functionality by an operation commit
\r
80 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
\r
82 /// Realizes some functionality by an operation abort
\r
83 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
\r
85 /// Realizes some functionality by an operation start
\r
86 virtual ModuleBase_Operation* currentOperation() const = 0;
\r
88 /// Add menu items for viewer into the given menu
\r
89 /// \param theMenu a popup menu to be shown in the viewer
\r
90 /// \param theStdActions a map of standard actions
\r
91 /// \return true if items are added and there is no necessity to provide standard menu
\r
92 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }
\r
94 /// Add menu items for object browser into the given menu
\r
95 /// \param theMenu a popup menu to be shown in the object browser
\r
96 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
\r
98 /// Creates custom widgets for property panel
\r
99 /// \param theType a type of widget
\r
100 /// \param theParent the parent object
\r
101 /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from
\r
102 /// \param theParentId is Id of a parent of the current attribute
\r
103 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
\r
104 Config_WidgetAPI* theWidgetApi, std::string theParentId)
\r
109 /// Returns the active widget, by default it is the property panel active widget
\r
110 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
\r
112 /// Returns current workshop
\r
113 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
\r
115 /// Call back forlast tuning of property panel before operation performance
\r
116 /// It is called as on clearing of property panel as on filling with new widgets
\r
117 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
\r
119 //! Returns True if there are available Undos and there is not an active operation
\r
120 virtual bool canUndo() const;
\r
122 //! Returns True if there are available Redos and there is not an active operation
\r
123 virtual bool canRedo() const;
\r
125 /// Returns true if the action can be applyed to the object
\r
126 /// \param theObject a checked object
\r
127 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
\r
128 /// \return the a boolean result
\r
129 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
\r
131 /// Returns True if the current operation can be committed. By default it is true.
\r
132 /// \return a boolean value
\r
133 //virtual bool canCommitOperation() const;
\r
135 /// Returns whether the object can be erased. The default realization returns true.
\r
136 /// \param theObject a model object
\r
137 virtual bool canEraseObject(const ObjectPtr& theObject) const;
\r
139 /// Returns whether the object can be displayed. The default realization returns true.
\r
140 /// \param theObject a model object
\r
141 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
\r
143 /// Returns true if selection for the object can be activate.
\r
144 /// By default a result or feature of the current operation can not be activated
\r
145 /// \param theObject a model object
\r
146 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
\r
148 /// Reacts to the delete action in module
\r
149 /// \returns true if the action is processed
\r
150 virtual bool deleteObjects() { return false; };
\r
152 /// Performs functionality on closing document
\r
153 virtual void closeDocument() = 0;
\r
155 /// Clears specific presentations in the viewer
\r
156 virtual void clearViewer() = 0;
\r
158 /// Returns a list of modes, where the AIS objects should be activated
\r
159 /// \param theModes a list of modes
\r
160 virtual void activeSelectionModes(QIntList& theModes) {}
\r
162 /** Update the object presentable properties such as color, lines width and other
\r
163 * If the object is result with the color attribute value set, it is used,
\r
164 * otherwise the customize is applyed to the object's feature if it is a custom prs
\r
165 * \param theObject an object instance
\r
166 * \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
167 * should be updated(e.g. only highlighted elements)
\r
168 * \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
169 * \returns true if the object is modified
\r
171 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
\r
172 const bool theUpdateViewer);
\r
174 /// This method is called on object browser creation for customization of module specific features
\r
175 /// \param theObjectBrowser a pinter on Object Browser widget
\r
176 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
\r
178 /// Creates a new operation
\r
179 /// \param theCmdId the operation name
\r
180 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
\r
182 /// Sends the operation for launching
\r
183 /// \param theOperation the operation
\r
184 virtual void sendOperation(ModuleBase_Operation* theOperation);
\r
186 //! Returns data object by AIS
\r
187 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
\r
189 /// Update state of pop-up menu items in object browser
\r
190 /// \param theStdActions - a map of standard actions
\r
191 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
193 /// Update state of pop-up menu items in viewer
\r
194 /// \param theStdActions - a map of standard actions
\r
195 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
197 //! Returns the feature error if the current state of the feature in the module is not correct
\r
198 //! If the feature is correct, it returns an empty value
\r
199 //! \return string value
\r
200 virtual QString getFeatureError(const FeaturePtr& theFeature);
\r
202 /// Returns list of granted operation indices
\r
203 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
\r
205 /// Connects or disconnects to the value changed signal of the property panel widgets
\r
206 /// \param theWidget a property contol widget
\r
207 /// \param isToConnect a boolean value whether connect or disconnect
\r
208 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
\r
210 /// Validates the operation to change the "Apply" button state.
\r
211 /// \param thePreviousState the previous state of the widget
\r
212 virtual void widgetStateChanged(int thePreviousState) {};
\r
214 /// Returns true if the event is processed.
\r
215 /// \param thePreviousAttributeID an index of the previous active attribute
\r
216 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
\r
218 /// Performs some GUI actions after an operation transaction is opened
\r
219 /// Default realization is empty
\r
220 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};
\r
222 /// Performs some GUI actions before an operation transaction is stopped
\r
223 /// Default realization is empty
\r
224 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
\r
227 /// Signal which is emitted when operation is launched
\r
228 void operationLaunched();
\r
230 /// Segnal emitted when an operation is resumed
\r
231 /// \param theOp a resumed operation
\r
232 void resumed(ModuleBase_Operation* theOp);
\r
235 /// Called on call of command corresponded to a feature
\r
236 virtual void onFeatureTriggered();
\r
238 /// Slot called on object display
\r
239 /// \param theObject a data object
\r
240 /// \param theAIS a presentation object
\r
241 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
243 /// Slot called on before object erase
\r
244 /// \param theObject a data object
\r
245 /// \param theAIS a presentation object
\r
246 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
249 /// Called on selection changed event
\r
250 virtual void onSelectionChanged() {}
\r
253 /// Register validators for this module
\r
254 virtual void registerValidators() {}
\r
256 /// Register selection filters for this module
\r
257 virtual void registerFilters() {}
\r
259 /// Register properties of this module
\r
260 virtual void registerProperties() {}
\r
262 /// Returns new instance of operation object (used in createOperation for customization)
\r
263 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
\r
267 /// Reference to workshop
\r
268 ModuleBase_IWorkshop* myWorkshop;
\r
270 /// Map of features in XML
\r
271 std::map<std::string, std::string> myFeaturesInFiles;
\r
276 //! This function must return a new module instance.
\r
278 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
\r
281 #define CREATE_MODULE "createModule"
\r
283 #endif //ModuleBase_IModule
\r