1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_IModule_H
21 #define ModuleBase_IModule_H
23 #include "ModuleBase.h"
24 #include "ModuleBase_IWorkshop.h"
25 #include <ModuleBase_SelectionFilterType.h>
27 #include <ModelAPI_Feature.h>
28 #include <ModelAPI_Attribute.h>
30 #include <GeomAPI_Shape.h>
31 #include <GeomAPI_ICustomPrs.h>
33 #include <SelectMgr_ListOfFilter.hxx>
45 #pragma warning(disable: 4100)
52 class Config_WidgetAPI;
54 class ModuleBase_ModelWidget;
55 class ModuleBase_Operation;
56 class ModuleBase_ViewerPrs;
57 class ModuleBase_ITreeNode;
58 class ModuleBase_IWorkshop;
60 class ModelAPI_Result;
63 class AIS_InteractiveObject;
67 * Interface to a module
69 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
73 /// enumeration to know which objects should be customized
74 enum ModuleBase_CustomizeFlag {
75 CustomizeArguments = 0, /// references of other objects referenced to the current feature
76 CustomizeResults, /// results of the current feature
77 CustomizeHighlightedObjects /// highlighted objects of the active widget
81 /// \param theParent instance of workshop interface
82 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
84 virtual ~ModuleBase_IModule();
86 /// Stores the current selection
87 virtual void storeSelection() {}
89 /// Restores the current selection
90 virtual void restoreSelection() {}
92 /// Reads description of features from XML file
93 virtual void createFeatures();
95 /// Called on creation of menu item in desktop
96 virtual void actionCreated(QAction*);
98 /// Launching of a edit operation on the feature
99 /// \param theFeature feature for editing
100 virtual void editFeature(FeaturePtr theFeature);
102 /// Returns true if the operation can be committed. Result in default implementation is true.
103 /// \return boolean value
104 virtual bool canCommitOperation() const { return true; }
106 /// Creates an operation and send it to loop
107 /// \param theCmdId the operation name
108 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
110 virtual void launchOperation(const QString& theCmdId,
111 const bool& isStartAfterCommitOnly);
113 /// Executes feature as a modal dialog box
114 /// \param theCmdId the operation name
115 virtual void launchModal(const QString& theCmdId);
117 /// Realizes some functionality by an operation start
118 /// \param theOperation a started operation
119 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
121 /// Realizes some functionality by an operation resume
122 /// By default it emits operationResumed signal
123 /// \param theOperation a resumed operation
124 virtual void operationResumed(ModuleBase_Operation* theOperation);
126 /// Realizes some functionality by an operation stop
127 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
129 /// Realizes some functionality by an operation commit
130 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
132 /// Realizes some functionality by an operation abort
133 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
135 /// Realizes some functionality by an operation start
136 virtual ModuleBase_Operation* currentOperation() const = 0;
138 /// Add menu items for viewer into the actions map
139 /// \param theStdActions a map of standard actions
140 /// \param theParent a parent widget
141 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
142 /// \return true if items are added and there is no necessity to provide standard menu
143 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
145 QMap<int, QAction*>& theMenuActions) const
148 /// Add menu items for object browser into the given menu
149 /// \param theMenu a popup menu to be shown in the object browser
150 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
152 /// Creates custom widgets for property panel
153 /// \param theType a type of widget
154 /// \param theParent the parent object
155 /// \param theWidgetApi the widget configuration.
156 /// The attribute of the model widget is obtained from
157 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
159 Config_WidgetAPI* theWidgetApi)
164 /// Returns the active widget, by default it is the property panel active widget
165 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
167 /// Returns current workshop
168 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
170 /// Call back forlast tuning of property panel before operation performance
171 /// It is called as on clearing of property panel as on filling with new widgets
172 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
174 /// Have an opportunity to create widgets for the current operation
175 /// instead of standard creation in workshop
176 /// \param theFeature a feature of the started operation
177 /// \param theXmlRepr an XML representation of the operation
178 /// \param theWidgets a list of created widgets
179 /// \return boolean result, false by default
180 virtual bool createWidgets(const FeaturePtr& theFeature, const QString& theXmlRepr,
181 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
183 //! Returns True if there are available Undos and there is not an active operation
184 virtual bool canUndo() const;
186 //! Returns True if there are available Redos and there is not an active operation
187 virtual bool canRedo() const;
189 /// Returns true if the action can be applyed to the object
190 /// \param theObject a checked object
191 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
192 /// \return the a boolean result
193 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
195 /// Returns True if the current operation can be committed. By default it is true.
196 /// \return a boolean value
197 //virtual bool canCommitOperation() const;
199 /// Returns whether the object can be erased. The default realization returns true.
200 /// \param theObject a model object
201 virtual bool canEraseObject(const ObjectPtr& theObject) const;
203 /// Returns whether the object can be displayed. The default realization returns true.
204 /// \param theObject a model object
205 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
207 /// Returns whether the started operation may use preselection of the previous one
208 /// Cases are: previous operation is null, edit operation, previuos and started operations
209 /// kinds are the same
210 /// \param thePreviousOperationKind a kind of previous operation
211 /// \param theStartedOperationKind a kind of a started operation
212 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
213 const QString& theStartedOperationKind);
215 /// Make some functionality after the objects are hidden in viewer
216 /// \param theObjects a list of hidden objects
217 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
219 /// Returns true if selection for the object can be activate.
220 /// By default a result or feature of the current operation can not be activated
221 /// \param theObject a model object
222 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
224 /// Reacts to the delete action in module
225 /// \returns true if the action is processed
226 virtual bool deleteObjects() { return false; };
228 /// Performs functionality on closing document
229 virtual void closeDocument() = 0;
231 /// Clears specific presentations in the viewer
232 virtual void clearViewer() = 0;
234 /// Returns a list of modes, where the AIS objects should be activated
235 /// \param theModes a list of modes
236 virtual void activeSelectionModes(QIntList& theModes) {}
238 /// Appends specific selection modes for the module to the list of types
239 /// \param theModesType combination of available selection filters
240 /// \param theModes a selection modes to be extended
241 virtual void moduleSelectionModes(int theModesType, QIntList& theModes) = 0;
243 /// Appends into container of filters module filters corresponded to the modes type
244 /// \param theFilterTypes container of available selection filters
245 /// \param theSelectionFilters [out] container to be extend by elements
246 virtual void moduleSelectionFilters(const QIntList& theFilterTypes,
247 SelectMgr_ListOfFilter& theSelectionFilters) = 0;
249 /// Returns types of registered module selection filters
250 /// \param theSelectionFilters [out] container of type value
251 virtual QIntList selectionFilters();
253 /// Returns selection filter
254 /// \param theType selection filter type
255 /// \param theFilter instance of filter
256 virtual Handle(SelectMgr_Filter) selectionFilter(const int theType);
258 /// Append selection filter into the module and type of the filter in internal container
259 /// \param theFilterType selection filter type
260 /// \param theFilter added filter
261 void registerSelectionFilter(const ModuleBase_SelectionFilterType theFilterType,
262 const Handle(SelectMgr_Filter)& theFilter);
264 /// Return true if the custom presentation is activated
265 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
266 /// \return boolean value
267 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
270 /// Activate custom presentation for the object. Default realization is empty.
271 /// \param theFeature a feature instance
272 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
273 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
274 virtual void activateCustomPrs(const FeaturePtr& theFeature,
275 const ModuleBase_CustomizeFlag& theFlag,
276 const bool theUpdateViewer) {}
278 /// Deactivate custom presentation for the object. Default realization is empty.
279 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
280 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
281 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
282 const bool theUpdateViewer) {}
284 /// Modifies the given presentation in the custom way.
285 //virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
286 // AISObjectPtr thePrs,
287 // GeomCustomPrsPtr theCustomPrs) { return false; };
289 ///// Modifies the given presentation in the custom way after usual customize is performed.
290 //virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
291 // AISObjectPtr thePrs,
292 // GeomCustomPrsPtr theCustomPrs) { return false; };
294 /// Update the object presentable properties such as color, lines width and other
295 /// If the object is result with the color attribute value set, it is used,
296 /// otherwise the customize is applyed to the object's feature if it is a custom prs
297 /// \param theObject an object instance
298 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
299 /// should be updated(e.g. only highlighted elements)
300 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
301 /// \returns true if the object is modified
302 virtual bool customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
303 const bool theUpdateViewer) {
307 /// Disable displaying of custom mode
308 /// \param theMode a mode to disable
309 virtual void disableCustomMode(ModuleBase_CustomizeFlag theMode) {}
311 /// Enables disabled custom mode
312 virtual void enableCustomModes() {}
314 /// This method is called on object browser creation for customization of module specific features
315 /// \param theObjectBrowser a pinter on Object Browser widget
316 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
318 /// Creates a new operation
319 /// \param theCmdId the operation name
320 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
322 /// Create specific for the module presentation. The presentation has to be
323 /// customized accordingly to the object.
324 /// \param theResult an object for presentation
325 /// \return created presentation or NULL(default value)
326 virtual AISObjectPtr createPresentation(const ObjectPtr& theResult);
328 /// Customize presentation according to objects attributes
329 /// \param theObject an object for presentation
330 /// \param thePrs a presentation object
331 virtual void customizePresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const
334 //! Returns data object by AIS
335 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
337 //! Returns true if the presentation can be shown in shading mode
338 //! \param theAIS presentation to be checked
339 //! \return boolean value
340 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
342 /// Update state of pop-up menu items in object browser
343 /// \param theStdActions - a map of standard actions
344 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
346 /// Update state of pop-up menu items in viewer
347 /// \param theStdActions - a map of standard actions
348 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
350 /// Returns true if the action should be always enabled
351 /// \param theActionId an action index: Accept or Accept All
352 /// \return boolean value
353 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
355 //! Returns the feature error if the current state of the feature in the module is not correct
356 //! If the feature is correct, it returns an empty value
357 //! \return string value
358 virtual QString getFeatureError(const FeaturePtr& theFeature);
360 /// Returns list of granted operation indices
361 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
363 /// Connects or disconnects to the value changed signal of the property panel widgets
364 /// \param theWidget a property contol widget
365 /// \param isToConnect a boolean value whether connect or disconnect
366 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
368 /// Validates the operation to change the "Apply" button state.
369 /// \param thePreviousState the previous state of the widget
370 virtual void widgetStateChanged(int thePreviousState) {};
372 /// Returns true if the event is processed.
373 /// \param thePreviousAttributeID an index of the previous active attribute
374 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
376 /// Performs some GUI actions before an operation transaction is stopped
377 /// Default realization is empty
378 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
380 /// Finds a shape by attribute if it is possible
381 /// \param theAttribute an attribute
382 /// \return a geom shape
383 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
385 /// Finds an attribute by geom shape if it is possible
386 /// \param theObject an object of the attribute
387 /// \param theGeomShape a geom shape
388 /// \return theAttribute
389 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
390 const GeomShapePtr& theGeomShape) = 0;
392 /// Returns reentrant message if it was accepted
393 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
395 /// Put current selection into reentrant message
396 /// \param theMessage a message of reentrant operation
397 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
399 /// Returns XML information by the feature index
400 /// \param theFeatureId a feature id
401 /// \param theXmlCfg XML configuration
402 /// \param theDescription feature description
403 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
404 std::string& theDescription);
406 /// Returns root tree node which represents a data model
407 virtual ModuleBase_ITreeNode* rootNode() const = 0;
410 /// Segnal emitted when an operation is resumed
411 /// \param theOp a resumed operation
412 void resumed(ModuleBase_Operation* theOp);
415 /// Called on call of command corresponded to a feature
416 virtual void onFeatureTriggered();
418 /// Slot called on object display
419 /// \param theObject a data object
420 /// \param theAIS a presentation object
421 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
423 /// Slot called on before object erase
424 /// \param theObject a data object
425 /// \param theAIS a presentation object
426 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
428 /// Called on transformation in current viewer
429 /// \param theTrsfType type of tranformation
430 virtual void onViewTransformed(int theTrsfType = 2) {}
433 /// Called on selection changed event
434 virtual void onSelectionChanged() {}
437 /// Register validators for this module
438 virtual void registerValidators() {}
440 /// Register properties of this module
441 virtual void registerProperties() {}
443 /// Returns new instance of operation object (used in createOperation for customization)
444 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
447 /// Reference to workshop
448 ModuleBase_IWorkshop* myWorkshop;
450 /// Map of features in XML
451 std::map<std::string, std::string> myFeaturesInFiles;
453 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)> mySelectionFilters;
459 //! This function must return a new module instance.
461 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
464 #define CREATE_MODULE "createModule"
466 #endif //ModuleBase_IModule