1 // Copyright (C) 2014-2019 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>
48 class Config_WidgetAPI;
50 class ModuleBase_ModelWidget;
51 class ModuleBase_Operation;
52 class ModuleBase_ViewerPrs;
53 class ModuleBase_ITreeNode;
54 class ModuleBase_IWorkshop;
56 class ModelAPI_Result;
59 class AIS_InteractiveObject;
63 * Interface to a module
65 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
69 /// enumeration to know which objects should be customized
70 enum ModuleBase_CustomizeFlag {
71 CustomizeArguments = 0, /// references of other objects referenced to the current feature
72 CustomizeResults, /// results of the current feature
73 CustomizeHighlightedObjects /// highlighted objects of the active widget
77 /// \param theParent instance of workshop interface
78 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
80 virtual ~ModuleBase_IModule();
82 /// Stores the current selection
83 virtual void storeSelection() {}
85 /// Restores the current selection
86 virtual void restoreSelection() {}
88 /// Reads description of features from XML file
89 virtual void createFeatures();
91 /// Called on creation of menu item in desktop
92 virtual void actionCreated(QAction*);
94 /// Launching of a edit operation on the feature
95 /// \param theFeature feature for editing
96 virtual void editFeature(FeaturePtr theFeature);
98 /// Returns true if the operation can be committed. Result in default implementation is true.
99 /// \return boolean value
100 virtual bool canCommitOperation() const { return true; }
102 /// Creates an operation and send it to loop
103 /// \param theCmdId the operation name
104 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
106 virtual void launchOperation(const QString& theCmdId,
107 const bool& isStartAfterCommitOnly);
109 /// Executes feature as a modal dialog box
110 /// \param theCmdId the operation name
111 virtual void launchModal(const QString& theCmdId);
113 /// Realizes some functionality by an operation start
114 /// \param theOperation a started operation
115 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
117 /// Realizes some functionality by an operation resume
118 /// By default it emits operationResumed signal
119 /// \param theOperation a resumed operation
120 virtual void operationResumed(ModuleBase_Operation* theOperation);
122 /// Realizes some functionality by an operation stop
123 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
125 /// Realizes some functionality by an operation commit
126 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
128 /// Realizes some functionality by an operation abort
129 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
131 /// Realizes some functionality by an operation start
132 virtual ModuleBase_Operation* currentOperation() const = 0;
134 /// Add menu items for viewer into the actions map
135 /// \param theStdActions a map of standard actions
136 /// \param theParent a parent widget
137 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
138 /// \return true if items are added and there is no necessity to provide standard menu
139 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
141 QMap<int, QAction*>& theMenuActions) const
144 /// Add menu items for object browser into the given menu
145 /// \param theMenu a popup menu to be shown in the object browser
146 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
148 /// Creates custom widgets for property panel
149 /// \param theType a type of widget
150 /// \param theParent the parent object
151 /// \param theWidgetApi the widget configuration.
152 /// The attribute of the model widget is obtained from
153 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
155 Config_WidgetAPI* theWidgetApi)
160 /// Returns the active widget, by default it is the property panel active widget
161 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
163 /// Returns current workshop
164 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
166 /// Call back forlast tuning of property panel before operation performance
167 /// It is called as on clearing of property panel as on filling with new widgets
168 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
170 /// Have an opportunity to create widgets for the current operation
171 /// instead of standard creation in workshop
172 /// \param theFeature a feature of the started operation
173 /// \param theXmlRepr an XML representation of the operation
174 /// \param theWidgets a list of created widgets
175 /// \return boolean result, false by default
176 virtual bool createWidgets(const FeaturePtr& theFeature, const QString& theXmlRepr,
177 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
179 //! Returns True if there are available Undos and there is not an active operation
180 virtual bool canUndo() const;
182 //! Returns True if there are available Redos and there is not an active operation
183 virtual bool canRedo() const;
185 /// Returns true if the action can be applyed to the object
186 /// \param theObject a checked object
187 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
188 /// \return the a boolean result
189 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
191 /// Returns True if the current operation can be committed. By default it is true.
192 /// \return a boolean value
193 //virtual bool canCommitOperation() const;
195 /// Returns whether the object can be erased. The default realization returns true.
196 /// \param theObject a model object
197 virtual bool canEraseObject(const ObjectPtr& theObject) const;
199 /// Returns whether the object can be displayed. The default realization returns true.
200 /// \param theObject a model object
201 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
203 /// Returns whether the started operation may use preselection of the previous one
204 /// Cases are: previous operation is null, edit operation, previuos and started operations
205 /// kinds are the same
206 /// \param thePreviousOperationKind a kind of previous operation
207 /// \param theStartedOperationKind a kind of a started operation
208 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
209 const QString& theStartedOperationKind);
211 /// Make some functionality after the objects are hidden in viewer
212 /// \param theObjects a list of hidden objects
213 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
215 /// Returns true if selection for the object can be activate.
216 /// By default a result or feature of the current operation can not be activated
217 /// \param theObject a model object
218 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
220 /// Reacts to the delete action in module
221 /// \returns true if the action is processed
222 virtual bool deleteObjects() { return false; };
224 /// Performs functionality on closing document
225 virtual void closeDocument() = 0;
227 /// Clears specific presentations in the viewer
228 virtual void clearViewer() = 0;
230 /// Returns a list of modes, where the AIS objects should be activated
231 /// \param theModes a list of modes
232 virtual void activeSelectionModes(QIntList& theModes) {}
234 /// Appends specific selection modes for the module to the list of types
235 /// \param theModesType combination of available selection filters
236 /// \param theModes a selection modes to be extended
237 virtual void moduleSelectionModes(int theModesType, QIntList& theModes) = 0;
239 /// Appends into container of filters module filters corresponded to the modes type
240 /// \param theFilterTypes container of available selection filters
241 /// \param theSelectionFilters [out] container to be extend by elements
242 virtual void moduleSelectionFilters(const QIntList& theFilterTypes,
243 SelectMgr_ListOfFilter& theSelectionFilters) = 0;
245 /// Returns types of registered module selection filters
246 /// \param theSelectionFilters [out] container of type value
247 virtual QIntList selectionFilters();
249 /// Returns selection filter
250 /// \param theType selection filter type
251 /// \param theFilter instance of filter
252 virtual Handle(SelectMgr_Filter) selectionFilter(const int theType);
254 /// Append selection filter into the module and type of the filter in internal container
255 /// \param theFilterType selection filter type
256 /// \param theFilter added filter
257 void registerSelectionFilter(const ModuleBase_SelectionFilterType theFilterType,
258 const Handle(SelectMgr_Filter)& theFilter);
260 /// Return true if the custom presentation is activated
261 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
262 /// \return boolean value
263 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
266 /// Activate custom presentation for the object. Default realization is empty.
267 /// \param theFeature a feature instance
268 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
269 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
270 virtual void activateCustomPrs(const FeaturePtr& theFeature,
271 const ModuleBase_CustomizeFlag& theFlag,
272 const bool theUpdateViewer) {}
274 /// Deactivate custom presentation for the object. Default realization is empty.
275 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
276 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
277 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
278 const bool theUpdateViewer) {}
280 /// Modifies the given presentation in the custom way.
281 //virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
282 // AISObjectPtr thePrs,
283 // GeomCustomPrsPtr theCustomPrs) { return false; };
285 ///// Modifies the given presentation in the custom way after usual customize is performed.
286 //virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
287 // AISObjectPtr thePrs,
288 // GeomCustomPrsPtr theCustomPrs) { return false; };
290 /// Update the object presentable properties such as color, lines width and other
291 /// If the object is result with the color attribute value set, it is used,
292 /// otherwise the customize is applyed to the object's feature if it is a custom prs
293 /// \param theObject an object instance
294 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
295 /// should be updated(e.g. only highlighted elements)
296 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
297 /// \returns true if the object is modified
298 virtual bool customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
299 const bool theUpdateViewer) {
303 /// Disable displaying of custom mode
304 /// \param theMode a mode to disable
305 virtual void disableCustomMode(ModuleBase_CustomizeFlag theMode) {}
307 /// Enables disabled custom mode
308 virtual void enableCustomModes() {}
310 /// This method is called on object browser creation for customization of module specific features
311 /// \param theObjectBrowser a pinter on Object Browser widget
312 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
314 /// Creates a new operation
315 /// \param theCmdId the operation name
316 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
318 /// Create specific for the module presentation. The presentation has to be
319 /// customized accordingly to the object.
320 /// \param theResult an object for presentation
321 /// \return created presentation or NULL(default value)
322 virtual AISObjectPtr createPresentation(const ObjectPtr& theResult);
324 /// Customize presentation according to objects attributes
325 /// \param theObject an object for presentation
326 /// \param thePrs a presentation object
327 virtual void customizePresentation(const ObjectPtr& theObject, const AISObjectPtr& thePrs) const
330 //! Returns data object by AIS
331 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
333 //! Returns true if the presentation can be shown in shading mode
334 //! \param theAIS presentation to be checked
335 //! \return boolean value
336 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
338 /// Update state of pop-up menu items in object browser
339 /// \param theStdActions - a map of standard actions
340 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
342 /// Update state of pop-up menu items in viewer
343 /// \param theStdActions - a map of standard actions
344 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
346 /// Returns true if the action should be always enabled
347 /// \param theActionId an action index: Accept or Accept All
348 /// \return boolean value
349 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
351 //! Returns the feature error if the current state of the feature in the module is not correct
352 //! If the feature is correct, it returns an empty value
353 //! \return string value
354 virtual QString getFeatureError(const FeaturePtr& theFeature);
356 /// Returns list of granted operation indices
357 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
359 /// Connects or disconnects to the value changed signal of the property panel widgets
360 /// \param theWidget a property contol widget
361 /// \param isToConnect a boolean value whether connect or disconnect
362 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
364 /// Validates the operation to change the "Apply" button state.
365 /// \param thePreviousState the previous state of the widget
366 virtual void widgetStateChanged(int thePreviousState) {};
368 /// Returns true if the event is processed.
369 /// \param thePreviousAttributeID an index of the previous active attribute
370 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
372 /// Performs some GUI actions before an operation transaction is stopped
373 /// Default realization is empty
374 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
376 /// Finds a shape by attribute if it is possible
377 /// \param theAttribute an attribute
378 /// \return a geom shape
379 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
381 /// Finds an attribute by geom shape if it is possible
382 /// \param theObject an object of the attribute
383 /// \param theGeomShape a geom shape
384 /// \return theAttribute
385 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
386 const GeomShapePtr& theGeomShape) = 0;
388 /// Returns reentrant message if it was accepted
389 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
391 /// Put current selection into reentrant message
392 /// \param theMessage a message of reentrant operation
393 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
395 /// Returns XML information by the feature index
396 /// \param theFeatureId a feature id
397 /// \param theXmlCfg XML configuration
398 /// \param theDescription feature description
399 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
400 std::string& theDescription);
402 /// Returns root tree node which represents a data model
403 virtual ModuleBase_ITreeNode* rootNode() const = 0;
406 /// Segnal emitted when an operation is resumed
407 /// \param theOp a resumed operation
408 void resumed(ModuleBase_Operation* theOp);
411 /// Called on call of command corresponded to a feature
412 virtual void onFeatureTriggered();
414 /// Slot called on object display
415 /// \param theObject a data object
416 /// \param theAIS a presentation object
417 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
419 /// Slot called on before object erase
420 /// \param theObject a data object
421 /// \param theAIS a presentation object
422 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
425 /// Called on selection changed event
426 virtual void onSelectionChanged() {}
429 /// Register validators for this module
430 virtual void registerValidators() {}
432 /// Register properties of this module
433 virtual void registerProperties() {}
435 /// Returns new instance of operation object (used in createOperation for customization)
436 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
439 /// Reference to workshop
440 ModuleBase_IWorkshop* myWorkshop;
442 /// Map of features in XML
443 std::map<std::string, std::string> myFeaturesInFiles;
445 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)> mySelectionFilters;
451 //! This function must return a new module instance.
453 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
456 #define CREATE_MODULE "createModule"
458 #endif //ModuleBase_IModule