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
27 class Config_WidgetAPI;
\r
28 class ModuleBase_ModelWidget;
\r
29 class ModuleBase_Operation;
\r
30 class ModuleBase_IWorkshop;
\r
34 * Interface to a module
\r
36 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
\r
40 /// enumeration to know which objects should be customized
\r
41 enum ModuleBase_CustomizeFlag {
\r
42 CustomizeArguments = 0, /// references of other objects referenced to the current feature
\r
43 CustomizeResults, /// results of the current feature
\r
44 CustomizeHighlightedObjects /// highlighted objects of the active widget
\r
48 /// \param theParent instance of workshop interface
\r
49 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
\r
51 virtual ~ModuleBase_IModule() {}
\r
53 /// Add default selection filters of the module to the current viewer
\r
54 virtual void activateSelectionFilters() {};
\r
56 /// Remove default selection filters of the module from the current viewer
\r
57 virtual void deactivateSelectionFilters() {};
\r
59 /// Reads description of features from XML file
\r
60 virtual void createFeatures();
\r
62 /// Called on creation of menu item in desktop
\r
63 virtual void actionCreated(QAction*);
\r
65 /// Launching of a edit operation on the feature
\r
66 /// \param theFeature feature for editing
\r
67 virtual void editFeature(FeaturePtr theFeature);
\r
69 /// Creates an operation and send it to loop
\r
70 /// \param theCmdId the operation name
\r
71 virtual void launchOperation(const QString& theCmdId);
\r
73 /// Realizes some functionality by an operation start
\r
74 /// \param theOperation a started operation
\r
75 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
\r
77 /// Realizes some functionality by an operation resume
\r
78 /// By default it emits operationResumed signal
\r
79 /// \param theOperation a resumed operation
\r
80 virtual void operationResumed(ModuleBase_Operation* theOperation);
\r
82 /// Realizes some functionality by an operation stop
\r
83 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
\r
85 /// Realizes some functionality by an operation commit
\r
86 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
\r
88 /// Realizes some functionality by an operation abort
\r
89 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
\r
91 /// Realizes some functionality by an operation start
\r
92 virtual ModuleBase_Operation* currentOperation() const = 0;
\r
94 /// Add menu items for viewer into the given menu
\r
95 /// \param theMenu a popup menu to be shown in the viewer
\r
96 /// \param theStdActions a map of standard actions
\r
97 /// \return true if items are added and there is no necessity to provide standard menu
\r
98 virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const { return false; }
\r
100 /// Add menu items for object browser into the given menu
\r
101 /// \param theMenu a popup menu to be shown in the object browser
\r
102 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
\r
104 /// Creates custom widgets for property panel
\r
105 /// \param theType a type of widget
\r
106 /// \param theParent the parent object
\r
107 /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from
\r
108 /// \param theParentId is Id of a parent of the current attribute
\r
109 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
\r
110 Config_WidgetAPI* theWidgetApi, std::string theParentId)
\r
115 /// Returns the active widget, by default it is the property panel active widget
\r
116 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
\r
118 /// Returns current workshop
\r
119 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
\r
121 /// Call back forlast tuning of property panel before operation performance
\r
122 /// It is called as on clearing of property panel as on filling with new widgets
\r
123 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
\r
125 //! Returns True if there are available Undos and there is not an active operation
\r
126 virtual bool canUndo() const;
\r
128 //! Returns True if there are available Redos and there is not an active operation
\r
129 virtual bool canRedo() const;
\r
131 /// Returns true if the action can be applyed to the object
\r
132 /// \param theObject a checked object
\r
133 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
\r
134 /// \return the a boolean result
\r
135 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
\r
137 /// Returns True if the current operation can be committed. By default it is true.
\r
138 /// \return a boolean value
\r
139 //virtual bool canCommitOperation() const;
\r
141 /// Returns whether the object can be erased. The default realization returns true.
\r
142 /// \param theObject a model object
\r
143 virtual bool canEraseObject(const ObjectPtr& theObject) const;
\r
145 /// Returns whether the object can be displayed. The default realization returns true.
\r
146 /// \param theObject a model object
\r
147 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
\r
149 /// Make some functionality after the objects are hidden in viewer
\r
150 /// \param theObjects a list of hidden objects
\r
151 virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
\r
153 /// Returns true if selection for the object can be activate.
\r
154 /// By default a result or feature of the current operation can not be activated
\r
155 /// \param theObject a model object
\r
156 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
\r
158 /// Reacts to the delete action in module
\r
159 /// \returns true if the action is processed
\r
160 virtual bool deleteObjects() { return false; };
\r
162 /// Performs functionality on closing document
\r
163 virtual void closeDocument() = 0;
\r
165 /// Clears specific presentations in the viewer
\r
166 virtual void clearViewer() = 0;
\r
168 /// Returns a list of modes, where the AIS objects should be activated
\r
169 /// \param theModes a list of modes
\r
170 virtual void activeSelectionModes(QIntList& theModes) {}
\r
172 /// Activate custom presentation for the object. Default realization is empty.
\r
173 /// \param theObject an object instance
\r
174 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
175 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
176 virtual void activateCustomPrs(const FeaturePtr& theFeature,
\r
177 const ModuleBase_CustomizeFlag& theFlag,
\r
178 const bool theUpdateViewer) {}
\r
180 /// Deactivate custom presentation for the object. Default realization is empty.
\r
181 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
182 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
183 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
\r
184 const bool theUpdateViewer) {}
\r
186 /// Modifies the given presentation in the custom way.
\r
187 virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
\r
188 GeomCustomPrsPtr theCustomPrs) { return false; };
\r
190 /// Update the object presentable properties such as color, lines width and other
\r
191 /// If the object is result with the color attribute value set, it is used,
\r
192 /// otherwise the customize is applyed to the object's feature if it is a custom prs
\r
193 /// \param theObject an object instance
\r
194 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
195 /// should be updated(e.g. only highlighted elements)
\r
196 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
197 /// \returns true if the object is modified
\r
198 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
\r
199 const bool theUpdateViewer);
\r
201 /// This method is called on object browser creation for customization of module specific features
\r
202 /// \param theObjectBrowser a pinter on Object Browser widget
\r
203 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
\r
205 /// Creates a new operation
\r
206 /// \param theCmdId the operation name
\r
207 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
\r
209 /// Sends the operation for launching
\r
210 /// \param theOperation the operation
\r
211 virtual void sendOperation(ModuleBase_Operation* theOperation);
\r
213 //! Returns data object by AIS
\r
214 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
\r
216 /// Update state of pop-up menu items in object browser
\r
217 /// \param theStdActions - a map of standard actions
\r
218 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
220 /// Update state of pop-up menu items in viewer
\r
221 /// \param theStdActions - a map of standard actions
\r
222 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
224 //! Returns the feature error if the current state of the feature in the module is not correct
\r
225 //! If the feature is correct, it returns an empty value
\r
226 //! \return string value
\r
227 virtual QString getFeatureError(const FeaturePtr& theFeature);
\r
229 /// Returns list of granted operation indices
\r
230 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
\r
232 /// Connects or disconnects to the value changed signal of the property panel widgets
\r
233 /// \param theWidget a property contol widget
\r
234 /// \param isToConnect a boolean value whether connect or disconnect
\r
235 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
\r
237 /// Validates the operation to change the "Apply" button state.
\r
238 /// \param thePreviousState the previous state of the widget
\r
239 virtual void widgetStateChanged(int thePreviousState) {};
\r
241 /// Returns true if the event is processed.
\r
242 /// \param thePreviousAttributeID an index of the previous active attribute
\r
243 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
\r
245 /// Performs some GUI actions after an operation transaction is opened
\r
246 /// Default realization is empty
\r
247 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};
\r
249 /// Performs some GUI actions before an operation transaction is stopped
\r
250 /// Default realization is empty
\r
251 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
\r
253 /// Finds a shape by attribute if it is possible
\r
254 /// \param theAttribute an attribute
\r
255 /// \return a geom shape
\r
256 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
\r
258 /// Finds an attribute by geom shape if it is possible
\r
259 /// \param theObject an object of the attribute
\r
260 /// \param theGeomShape a geom shape
\r
261 /// \return theAttribute
\r
262 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
\r
263 const GeomShapePtr& theGeomShape) = 0;
\r
265 /// Returns color of the object
\r
266 /// \param theObject a result of a feature object
\r
267 /// \param theColor a vector of three values in [0, 255] range
\r
268 virtual void getColor(const ObjectPtr& theObject, std::vector<int>& theColor) {}
\r
270 /// Returns XML information by the feature index
\r
271 /// \param theFeatureId a feature id
\r
272 /// \param theXmlCfg XML configuration
\r
273 /// \param theDescription feature description
\r
274 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
\r
275 std::string& theDescription);
\r
278 /// Signal which is emitted when operation is launched
\r
279 void operationLaunched();
\r
281 /// Segnal emitted when an operation is resumed
\r
282 /// \param theOp a resumed operation
\r
283 void resumed(ModuleBase_Operation* theOp);
\r
286 /// Called on call of command corresponded to a feature
\r
287 virtual void onFeatureTriggered();
\r
289 /// Slot called on object display
\r
290 /// \param theObject a data object
\r
291 /// \param theAIS a presentation object
\r
292 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
294 /// Slot called on before object erase
\r
295 /// \param theObject a data object
\r
296 /// \param theAIS a presentation object
\r
297 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
300 /// Called on selection changed event
\r
301 virtual void onSelectionChanged() {}
\r
304 /// Register validators for this module
\r
305 virtual void registerValidators() {}
\r
307 /// Register selection filters for this module
\r
308 virtual void registerFilters() {}
\r
310 /// Register properties of this module
\r
311 virtual void registerProperties() {}
\r
313 /// Returns new instance of operation object (used in createOperation for customization)
\r
314 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
\r
317 /// Reference to workshop
\r
318 ModuleBase_IWorkshop* myWorkshop;
\r
320 /// Map of features in XML
\r
321 std::map<std::string, std::string> myFeaturesInFiles;
\r
326 //! This function must return a new module instance.
\r
328 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
\r
331 #define CREATE_MODULE "createModule"
\r
333 #endif //ModuleBase_IModule
\r