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
13 #include <GeomAPI_ICustomPrs.h>
\r
28 class Config_WidgetAPI;
\r
29 class ModuleBase_ModelWidget;
\r
30 class ModuleBase_Operation;
\r
31 class ModuleBase_IWorkshop;
\r
35 * Interface to a module
\r
37 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
\r
41 /// enumeration to know which objects should be customized
\r
42 enum ModuleBase_CustomizeFlag {
\r
43 CustomizeArguments = 0, /// references of other objects referenced to the current feature
\r
44 CustomizeResults, /// results of the current feature
\r
45 CustomizeHighlightedObjects /// highlighted objects of the active widget
\r
49 /// \param theParent instance of workshop interface
\r
50 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
\r
52 virtual ~ModuleBase_IModule() {}
\r
54 /// Add default selection filters of the module to the current viewer
\r
55 virtual void activateSelectionFilters() {};
\r
57 /// Remove default selection filters of the module from the current viewer
\r
58 virtual void deactivateSelectionFilters() {};
\r
60 // Stores the current selection
\r
61 virtual void storeSelection() {};
\r
63 // Restores the current selection
\r
64 virtual void restoreSelection() {};
\r
66 /// Reads description of features from XML file
\r
67 virtual void createFeatures();
\r
69 /// Called on creation of menu item in desktop
\r
70 virtual void actionCreated(QAction*);
\r
72 /// Launching of a edit operation on the feature
\r
73 /// \param theFeature feature for editing
\r
74 virtual void editFeature(FeaturePtr theFeature);
\r
76 /// Creates an operation and send it to loop
\r
77 /// \param theCmdId the operation name
\r
78 virtual void launchOperation(const QString& theCmdId);
\r
80 /// Realizes some functionality by an operation start
\r
81 /// \param theOperation a started operation
\r
82 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
\r
84 /// Realizes some functionality by an operation resume
\r
85 /// By default it emits operationResumed signal
\r
86 /// \param theOperation a resumed operation
\r
87 virtual void operationResumed(ModuleBase_Operation* theOperation);
\r
89 /// Realizes some functionality by an operation stop
\r
90 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
\r
92 /// Realizes some functionality by an operation commit
\r
93 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
\r
95 /// Realizes some functionality by an operation abort
\r
96 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
\r
98 /// Realizes some functionality by an operation start
\r
99 virtual ModuleBase_Operation* currentOperation() const = 0;
\r
101 /// Add menu items for viewer into the given menu
\r
102 /// \param theMenu a popup menu to be shown in the viewer
\r
103 /// \param theStdActions a map of standard actions
\r
104 /// \return true if items are added and there is no necessity to provide standard menu
\r
105 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
\r
108 /// Add menu items for object browser into the given menu
\r
109 /// \param theMenu a popup menu to be shown in the object browser
\r
110 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
\r
112 /// Creates custom widgets for property panel
\r
113 /// \param theType a type of widget
\r
114 /// \param theParent the parent object
\r
115 /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from
\r
116 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
\r
117 Config_WidgetAPI* theWidgetApi)
\r
122 /// Returns the active widget, by default it is the property panel active widget
\r
123 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
\r
125 /// Returns current workshop
\r
126 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
\r
128 /// Call back forlast tuning of property panel before operation performance
\r
129 /// It is called as on clearing of property panel as on filling with new widgets
\r
130 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
\r
132 /// Have an opportunity to create widgets for the current operation instead of standard creation in workshop
\r
133 /// \param theOperation a started operation
\r
134 /// \param theWidgets a list of created widgets
\r
135 /// \return boolean result, false by default
\r
136 virtual bool createWidgets(ModuleBase_Operation* theOperation,
\r
137 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
\r
139 //! Returns True if there are available Undos and there is not an active operation
\r
140 virtual bool canUndo() const;
\r
142 //! Returns True if there are available Redos and there is not an active operation
\r
143 virtual bool canRedo() const;
\r
145 /// Returns true if the action can be applyed to the object
\r
146 /// \param theObject a checked object
\r
147 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
\r
148 /// \return the a boolean result
\r
149 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
\r
151 /// Returns True if the current operation can be committed. By default it is true.
\r
152 /// \return a boolean value
\r
153 //virtual bool canCommitOperation() const;
\r
155 /// Returns whether the object can be erased. The default realization returns true.
\r
156 /// \param theObject a model object
\r
157 virtual bool canEraseObject(const ObjectPtr& theObject) const;
\r
159 /// Returns whether the object can be displayed. The default realization returns true.
\r
160 /// \param theObject a model object
\r
161 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
\r
163 /// Make some functionality after the objects are hidden in viewer
\r
164 /// \param theObjects a list of hidden objects
\r
165 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
\r
167 /// Returns true if selection for the object can be activate.
\r
168 /// By default a result or feature of the current operation can not be activated
\r
169 /// \param theObject a model object
\r
170 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
\r
172 /// Reacts to the delete action in module
\r
173 /// \returns true if the action is processed
\r
174 virtual bool deleteObjects() { return false; };
\r
176 /// Performs functionality on closing document
\r
177 virtual void closeDocument() = 0;
\r
179 /// Clears specific presentations in the viewer
\r
180 virtual void clearViewer() = 0;
\r
182 /// Returns a list of modes, where the AIS objects should be activated
\r
183 /// \param theModes a list of modes
\r
184 virtual void activeSelectionModes(QIntList& theModes) {}
\r
186 /// Activate custom presentation for the object. Default realization is empty.
\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 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
190 virtual void activateCustomPrs(const FeaturePtr& theFeature,
\r
191 const ModuleBase_CustomizeFlag& theFlag,
\r
192 const bool theUpdateViewer) {}
\r
194 /// Deactivate custom presentation for the object. Default realization is empty.
\r
195 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
196 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
197 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
\r
198 const bool theUpdateViewer) {}
\r
200 /// Modifies the given presentation in the custom way.
\r
201 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
\r
202 GeomCustomPrsPtr theCustomPrs) { return false; };
\r
204 /// Update the object presentable properties such as color, lines width and other
\r
205 /// If the object is result with the color attribute value set, it is used,
\r
206 /// otherwise the customize is applyed to the object's feature if it is a custom prs
\r
207 /// \param theObject an object instance
\r
208 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
209 /// should be updated(e.g. only highlighted elements)
\r
210 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
211 /// \returns true if the object is modified
\r
212 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
\r
213 const bool theUpdateViewer);
\r
215 /// This method is called on object browser creation for customization of module specific features
\r
216 /// \param theObjectBrowser a pinter on Object Browser widget
\r
217 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
\r
219 /// Creates a new operation
\r
220 /// \param theCmdId the operation name
\r
221 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
\r
223 /// Sends the operation for launching
\r
224 /// \param theOperation the operation
\r
225 virtual void sendOperation(ModuleBase_Operation* theOperation);
\r
227 //! Returns data object by AIS
\r
228 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
\r
230 /// Update state of pop-up menu items in object browser
\r
231 /// \param theStdActions - a map of standard actions
\r
232 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
234 /// Update state of pop-up menu items in viewer
\r
235 /// \param theStdActions - a map of standard actions
\r
236 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
238 //! Returns the feature error if the current state of the feature in the module is not correct
\r
239 //! If the feature is correct, it returns an empty value
\r
240 //! \return string value
\r
241 virtual QString getFeatureError(const FeaturePtr& theFeature);
\r
243 /// Returns list of granted operation indices
\r
244 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
\r
246 /// Connects or disconnects to the value changed signal of the property panel widgets
\r
247 /// \param theWidget a property contol widget
\r
248 /// \param isToConnect a boolean value whether connect or disconnect
\r
249 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
\r
251 /// Validates the operation to change the "Apply" button state.
\r
252 /// \param thePreviousState the previous state of the widget
\r
253 virtual void widgetStateChanged(int thePreviousState) {};
\r
255 /// Returns true if the event is processed.
\r
256 /// \param thePreviousAttributeID an index of the previous active attribute
\r
257 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
\r
259 /// Performs some GUI actions after an operation transaction is opened
\r
260 /// Default realization is empty
\r
261 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};
\r
263 /// Performs some GUI actions before an operation transaction is stopped
\r
264 /// Default realization is empty
\r
265 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
\r
267 /// Finds a shape by attribute if it is possible
\r
268 /// \param theAttribute an attribute
\r
269 /// \return a geom shape
\r
270 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
\r
272 /// Finds an attribute by geom shape if it is possible
\r
273 /// \param theObject an object of the attribute
\r
274 /// \param theGeomShape a geom shape
\r
275 /// \return theAttribute
\r
276 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
\r
277 const GeomShapePtr& theGeomShape) = 0;
\r
279 /// Returns XML information by the feature index
\r
280 /// \param theFeatureId a feature id
\r
281 /// \param theXmlCfg XML configuration
\r
282 /// \param theDescription feature description
\r
283 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
\r
284 std::string& theDescription);
\r
287 /// Signal which is emitted when operation is launched
\r
288 void operationLaunched();
\r
290 /// Segnal emitted when an operation is resumed
\r
291 /// \param theOp a resumed operation
\r
292 void resumed(ModuleBase_Operation* theOp);
\r
295 /// Called on call of command corresponded to a feature
\r
296 virtual void onFeatureTriggered();
\r
298 /// Slot called on object display
\r
299 /// \param theObject a data object
\r
300 /// \param theAIS a presentation object
\r
301 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
303 /// Slot called on before object erase
\r
304 /// \param theObject a data object
\r
305 /// \param theAIS a presentation object
\r
306 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
309 /// Called on selection changed event
\r
310 virtual void onSelectionChanged() {}
\r
313 /// Register validators for this module
\r
314 virtual void registerValidators() {}
\r
316 /// Register selection filters for this module
\r
317 virtual void registerFilters() {}
\r
319 /// Register properties of this module
\r
320 virtual void registerProperties() {}
\r
322 /// Returns new instance of operation object (used in createOperation for customization)
\r
323 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
\r
326 /// Reference to workshop
\r
327 ModuleBase_IWorkshop* myWorkshop;
\r
329 /// Map of features in XML
\r
330 std::map<std::string, std::string> myFeaturesInFiles;
\r
335 //! This function must return a new module instance.
\r
337 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
\r
340 #define CREATE_MODULE "createModule"
\r
342 #endif //ModuleBase_IModule
\r