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
32 class ModelAPI_Result;
\r
34 class Handle_AIS_InteractiveObject;
\r
38 * Interface to a module
\r
40 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
\r
44 /// enumeration to know which objects should be customized
\r
45 enum ModuleBase_CustomizeFlag {
\r
46 CustomizeArguments = 0, /// references of other objects referenced to the current feature
\r
47 CustomizeResults, /// results of the current feature
\r
48 CustomizeHighlightedObjects /// highlighted objects of the active widget
\r
52 /// \param theParent instance of workshop interface
\r
53 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
\r
55 virtual ~ModuleBase_IModule() {}
\r
57 /// Add default selection filters of the module to the current viewer
\r
58 virtual void activateSelectionFilters() {};
\r
60 /// Remove default selection filters of the module from the current viewer
\r
61 virtual void deactivateSelectionFilters() {};
\r
63 /// Stores the current selection
\r
64 virtual void storeSelection() {};
\r
66 /// Restores the current selection
\r
67 virtual void restoreSelection() {};
\r
69 /// Reads description of features from XML file
\r
70 virtual void createFeatures();
\r
72 /// Called on creation of menu item in desktop
\r
73 virtual void actionCreated(QAction*);
\r
75 /// Launching of a edit operation on the feature
\r
76 /// \param theFeature feature for editing
\r
77 virtual void editFeature(FeaturePtr theFeature);
\r
79 /// Returns true if the operation can be committed. Result in default implementation is true.
\r
80 /// \return boolean value
\r
81 virtual bool canCommitOperation() const { return true; }
\r
83 /// Creates an operation and send it to loop
\r
84 /// \param theCmdId the operation name
\r
85 virtual void launchOperation(const QString& theCmdId);
\r
87 /// Executes feature as a modal dialog box
\r
88 /// \param theCmdId the operation name
\r
89 virtual void launchModal(const QString& theCmdId);
\r
91 /// Realizes some functionality by an operation start
\r
92 /// \param theOperation a started operation
\r
93 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
\r
95 /// Realizes some functionality by an operation resume
\r
96 /// By default it emits operationResumed signal
\r
97 /// \param theOperation a resumed operation
\r
98 virtual void operationResumed(ModuleBase_Operation* theOperation);
\r
100 /// Realizes some functionality by an operation stop
\r
101 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
\r
103 /// Realizes some functionality by an operation commit
\r
104 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
\r
106 /// Realizes some functionality by an operation abort
\r
107 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
\r
109 /// Realizes some functionality by an operation start
\r
110 virtual ModuleBase_Operation* currentOperation() const = 0;
\r
112 /// Add menu items for viewer into the actions map
\r
113 /// \param theStdActions a map of standard actions
\r
114 /// \param theParent a parent widget
\r
115 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
\r
116 /// \return true if items are added and there is no necessity to provide standard menu
\r
117 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
\r
118 QWidget* theParent,
\r
119 QMap<int, QAction*>& theMenuActions) const
\r
122 /// Add menu items for object browser into the given menu
\r
123 /// \param theMenu a popup menu to be shown in the object browser
\r
124 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
\r
126 /// Creates custom widgets for property panel
\r
127 /// \param theType a type of widget
\r
128 /// \param theParent the parent object
\r
129 /// \param theWidgetApi the widget configuration. The attribute of the model widget is obtained from
\r
130 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
\r
131 Config_WidgetAPI* theWidgetApi)
\r
136 /// Returns the active widget, by default it is the property panel active widget
\r
137 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
\r
139 /// Returns current workshop
\r
140 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
\r
142 /// Call back forlast tuning of property panel before operation performance
\r
143 /// It is called as on clearing of property panel as on filling with new widgets
\r
144 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
\r
146 /// Have an opportunity to create widgets for the current operation instead of standard creation in workshop
\r
147 /// \param theOperation a started operation
\r
148 /// \param theWidgets a list of created widgets
\r
149 /// \return boolean result, false by default
\r
150 virtual bool createWidgets(ModuleBase_Operation* theOperation,
\r
151 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
\r
153 //! Returns True if there are available Undos and there is not an active operation
\r
154 virtual bool canUndo() const;
\r
156 //! Returns True if there are available Redos and there is not an active operation
\r
157 virtual bool canRedo() const;
\r
159 /// Returns true if the action can be applyed to the object
\r
160 /// \param theObject a checked object
\r
161 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
\r
162 /// \return the a boolean result
\r
163 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
\r
165 /// Returns True if the current operation can be committed. By default it is true.
\r
166 /// \return a boolean value
\r
167 //virtual bool canCommitOperation() const;
\r
169 /// Returns whether the object can be erased. The default realization returns true.
\r
170 /// \param theObject a model object
\r
171 virtual bool canEraseObject(const ObjectPtr& theObject) const;
\r
173 /// Returns whether the object can be displayed. The default realization returns true.
\r
174 /// \param theObject a model object
\r
175 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
\r
177 /// Make some functionality after the objects are hidden in viewer
\r
178 /// \param theObjects a list of hidden objects
\r
179 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
\r
181 /// Returns true if selection for the object can be activate.
\r
182 /// By default a result or feature of the current operation can not be activated
\r
183 /// \param theObject a model object
\r
184 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
\r
186 /// Reacts to the delete action in module
\r
187 /// \returns true if the action is processed
\r
188 virtual bool deleteObjects() { return false; };
\r
190 /// Performs functionality on closing document
\r
191 virtual void closeDocument() = 0;
\r
193 /// Clears specific presentations in the viewer
\r
194 virtual void clearViewer() = 0;
\r
196 /// Returns a list of modes, where the AIS objects should be activated
\r
197 /// \param theModes a list of modes
\r
198 virtual void activeSelectionModes(QIntList& theModes) {}
\r
200 /// Appends specific selection modes for the module to the list of types
\r
201 /// \param theTypes a selection modes to be extended
\r
202 virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
\r
204 /// Activate custom presentation for the object. Default realization is empty.
\r
205 /// \param theFeature a feature instance
\r
206 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
207 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
208 virtual void activateCustomPrs(const FeaturePtr& theFeature,
\r
209 const ModuleBase_CustomizeFlag& theFlag,
\r
210 const bool theUpdateViewer) {}
\r
212 /// Deactivate custom presentation for the object. Default realization is empty.
\r
213 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
214 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
215 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
\r
216 const bool theUpdateViewer) {}
\r
218 /// Modifies the given presentation in the custom way.
\r
219 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult, AISObjectPtr thePrs,
\r
220 GeomCustomPrsPtr theCustomPrs) { return false; };
\r
222 /// Update the object presentable properties such as color, lines width and other
\r
223 /// If the object is result with the color attribute value set, it is used,
\r
224 /// otherwise the customize is applyed to the object's feature if it is a custom prs
\r
225 /// \param theObject an object instance
\r
226 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
\r
227 /// should be updated(e.g. only highlighted elements)
\r
228 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
\r
229 /// \returns true if the object is modified
\r
230 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
\r
231 const bool theUpdateViewer);
\r
233 /// This method is called on object browser creation for customization of module specific features
\r
234 /// \param theObjectBrowser a pinter on Object Browser widget
\r
235 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
\r
237 /// Creates a new operation
\r
238 /// \param theCmdId the operation name
\r
239 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
\r
241 /// Sends the operation for launching
\r
242 /// \param theOperation the operation
\r
243 virtual void sendOperation(ModuleBase_Operation* theOperation);
\r
245 /// Create specific for the module presentation
\r
246 /// \param theResult an object for presentation
\r
247 /// \return created presentation or NULL(default value)
\r
248 virtual Handle_AIS_InteractiveObject createPresentation(
\r
249 const std::shared_ptr<ModelAPI_Result>& theResult);
\r
251 //! Returns data object by AIS
\r
252 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
\r
254 //! Returns true if the presentation can be shown in shading mode
\r
255 //! \param theAIS presentation to be checked
\r
256 //! \return boolean value
\r
257 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
\r
259 /// Update state of pop-up menu items in object browser
\r
260 /// \param theStdActions - a map of standard actions
\r
261 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
263 /// Update state of pop-up menu items in viewer
\r
264 /// \param theStdActions - a map of standard actions
\r
265 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
\r
267 //! Returns the feature error if the current state of the feature in the module is not correct
\r
268 //! If the feature is correct, it returns an empty value
\r
269 //! \return string value
\r
270 virtual QString getFeatureError(const FeaturePtr& theFeature);
\r
272 /// Returns list of granted operation indices
\r
273 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
\r
275 /// Connects or disconnects to the value changed signal of the property panel widgets
\r
276 /// \param theWidget a property contol widget
\r
277 /// \param isToConnect a boolean value whether connect or disconnect
\r
278 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
\r
280 /// Validates the operation to change the "Apply" button state.
\r
281 /// \param thePreviousState the previous state of the widget
\r
282 virtual void widgetStateChanged(int thePreviousState) {};
\r
284 /// Returns true if the event is processed.
\r
285 /// \param thePreviousAttributeID an index of the previous active attribute
\r
286 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
\r
288 /// Performs some GUI actions after an operation transaction is opened
\r
289 /// Default realization is empty
\r
290 virtual void beforeOperationStarted(ModuleBase_Operation* theOperation) {};
\r
292 /// Performs some GUI actions before an operation transaction is stopped
\r
293 /// Default realization is empty
\r
294 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
\r
296 /// Finds a shape by attribute if it is possible
\r
297 /// \param theAttribute an attribute
\r
298 /// \return a geom shape
\r
299 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
\r
301 /// Finds an attribute by geom shape if it is possible
\r
302 /// \param theObject an object of the attribute
\r
303 /// \param theGeomShape a geom shape
\r
304 /// \return theAttribute
\r
305 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
\r
306 const GeomShapePtr& theGeomShape) = 0;
\r
308 /// Returns XML information by the feature index
\r
309 /// \param theFeatureId a feature id
\r
310 /// \param theXmlCfg XML configuration
\r
311 /// \param theDescription feature description
\r
312 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
\r
313 std::string& theDescription);
\r
316 /// Signal which is emitted when operation is launched
\r
317 void operationLaunched();
\r
319 /// Segnal emitted when an operation is resumed
\r
320 /// \param theOp a resumed operation
\r
321 void resumed(ModuleBase_Operation* theOp);
\r
324 /// Called on call of command corresponded to a feature
\r
325 virtual void onFeatureTriggered();
\r
327 /// Slot called on object display
\r
328 /// \param theObject a data object
\r
329 /// \param theAIS a presentation object
\r
330 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
332 /// Slot called on before object erase
\r
333 /// \param theObject a data object
\r
334 /// \param theAIS a presentation object
\r
335 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
\r
338 /// Called on selection changed event
\r
339 virtual void onSelectionChanged() {}
\r
342 /// Register validators for this module
\r
343 virtual void registerValidators() {}
\r
345 /// Register selection filters for this module
\r
346 virtual void registerFilters() {}
\r
348 /// Register properties of this module
\r
349 virtual void registerProperties() {}
\r
351 /// Returns new instance of operation object (used in createOperation for customization)
\r
352 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
\r
355 /// Reference to workshop
\r
356 ModuleBase_IWorkshop* myWorkshop;
\r
358 /// Map of features in XML
\r
359 std::map<std::string, std::string> myFeaturesInFiles;
\r
364 //! This function must return a new module instance.
\r
366 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
\r
369 #define CREATE_MODULE "createModule"
\r
371 #endif //ModuleBase_IModule
\r