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"
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_Attribute.h>
29 #include <GeomAPI_Shape.h>
30 #include <GeomAPI_ICustomPrs.h>
32 #include <SelectMgr_ListOfFilter.hxx>
47 class Config_WidgetAPI;
49 class ModuleBase_ModelWidget;
50 class ModuleBase_Operation;
51 class ModuleBase_ViewerPrs;
52 class ModuleBase_ITreeNode;
53 class ModuleBase_IWorkshop;
55 class ModelAPI_Result;
58 class AIS_InteractiveObject;
62 * Interface to a module
64 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
68 /// enumeration to know which objects should be customized
69 enum ModuleBase_CustomizeFlag {
70 CustomizeArguments = 0, /// references of other objects referenced to the current feature
71 CustomizeResults, /// results of the current feature
72 CustomizeHighlightedObjects /// highlighted objects of the active widget
76 /// \param theParent instance of workshop interface
77 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
79 virtual ~ModuleBase_IModule() {}
81 /// Stores the current selection
82 virtual void storeSelection() {}
84 /// Restores the current selection
85 virtual void restoreSelection() {}
87 /// Reads description of features from XML file
88 virtual void createFeatures();
90 /// Called on creation of menu item in desktop
91 virtual void actionCreated(QAction*);
93 /// Launching of a edit operation on the feature
94 /// \param theFeature feature for editing
95 virtual void editFeature(FeaturePtr theFeature);
97 /// Returns true if the operation can be committed. Result in default implementation is true.
98 /// \return boolean value
99 virtual bool canCommitOperation() const { return true; }
101 /// Creates an operation and send it to loop
102 /// \param theCmdId the operation name
103 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
105 virtual void launchOperation(const QString& theCmdId,
106 const bool& isStartAfterCommitOnly);
108 /// Executes feature as a modal dialog box
109 /// \param theCmdId the operation name
110 virtual void launchModal(const QString& theCmdId);
112 /// Realizes some functionality by an operation start
113 /// \param theOperation a started operation
114 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
116 /// Realizes some functionality by an operation resume
117 /// By default it emits operationResumed signal
118 /// \param theOperation a resumed operation
119 virtual void operationResumed(ModuleBase_Operation* theOperation);
121 /// Realizes some functionality by an operation stop
122 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
124 /// Realizes some functionality by an operation commit
125 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
127 /// Realizes some functionality by an operation abort
128 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
130 /// Realizes some functionality by an operation start
131 virtual ModuleBase_Operation* currentOperation() const = 0;
133 /// Add menu items for viewer into the actions map
134 /// \param theStdActions a map of standard actions
135 /// \param theParent a parent widget
136 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
137 /// \return true if items are added and there is no necessity to provide standard menu
138 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
140 QMap<int, QAction*>& theMenuActions) const
143 /// Add menu items for object browser into the given menu
144 /// \param theMenu a popup menu to be shown in the object browser
145 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
147 /// Creates custom widgets for property panel
148 /// \param theType a type of widget
149 /// \param theParent the parent object
150 /// \param theWidgetApi the widget configuration.
151 /// The attribute of the model widget is obtained from
152 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
154 Config_WidgetAPI* theWidgetApi)
159 /// Returns the active widget, by default it is the property panel active widget
160 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
162 /// Returns current workshop
163 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
165 /// Call back forlast tuning of property panel before operation performance
166 /// It is called as on clearing of property panel as on filling with new widgets
167 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
169 /// Have an opportunity to create widgets for the current operation
170 /// instead of standard creation in workshop
171 /// \param theOperation a started operation
172 /// \param theWidgets a list of created widgets
173 /// \return boolean result, false by default
174 virtual bool createWidgets(ModuleBase_Operation* theOperation,
175 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
177 //! Returns True if there are available Undos and there is not an active operation
178 virtual bool canUndo() const;
180 //! Returns True if there are available Redos and there is not an active operation
181 virtual bool canRedo() const;
183 /// Returns true if the action can be applyed to the object
184 /// \param theObject a checked object
185 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
186 /// \return the a boolean result
187 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
189 /// Returns True if the current operation can be committed. By default it is true.
190 /// \return a boolean value
191 //virtual bool canCommitOperation() const;
193 /// Returns whether the object can be erased. The default realization returns true.
194 /// \param theObject a model object
195 virtual bool canEraseObject(const ObjectPtr& theObject) const;
197 /// Returns whether the object can be displayed. The default realization returns true.
198 /// \param theObject a model object
199 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
201 /// Returns whether the started operation may use preselection of the previous one
202 /// Cases are: previous operation is null, edit operation, previuos and started operations
203 /// kinds are the same
204 /// \param thePreviousOperationKind a kind of previous operation
205 /// \param theStartedOperationKind a kind of a started operation
206 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
207 const QString& theStartedOperationKind);
209 /// Make some functionality after the objects are hidden in viewer
210 /// \param theObjects a list of hidden objects
211 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
213 /// Returns true if selection for the object can be activate.
214 /// By default a result or feature of the current operation can not be activated
215 /// \param theObject a model object
216 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
218 /// Reacts to the delete action in module
219 /// \returns true if the action is processed
220 virtual bool deleteObjects() { return false; };
222 /// Performs functionality on closing document
223 virtual void closeDocument() = 0;
225 /// Clears specific presentations in the viewer
226 virtual void clearViewer() = 0;
228 /// Returns a list of modes, where the AIS objects should be activated
229 /// \param theModes a list of modes
230 virtual void activeSelectionModes(QIntList& theModes) {}
232 /// Appends specific selection modes for the module to the list of types
233 /// \param theModesType combination of available selection filters
234 /// \param theModes a selection modes to be extended
235 virtual void moduleSelectionModes(int theModesType, QIntList& theModes) = 0;
237 /// Appends into container of filters module filters corresponded to the modes type
238 /// \param theFilterTypes container of available selection filters
239 /// \param theSelectionFilters [out] container to be extend by elements
240 virtual void moduleSelectionFilters(const QIntList& theFilterTypes,
241 SelectMgr_ListOfFilter& theSelectionFilters) = 0;
243 /// Returns types of registered module selection filters
244 /// \param theSelectionFilters [out] container of type value
245 virtual QIntList selectionFilters() { return QIntList(); }
247 /// Returns selection filter
248 /// \param theType selection filter type
249 /// \param theFilter instance of filter
250 virtual Handle(SelectMgr_Filter) selectionFilter(const int theType) = 0;
252 /// Return true if the custom presentation is activated
253 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
254 /// \return boolean value
255 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
258 /// Activate custom presentation for the object. Default realization is empty.
259 /// \param theFeature a feature instance
260 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
261 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
262 virtual void activateCustomPrs(const FeaturePtr& theFeature,
263 const ModuleBase_CustomizeFlag& theFlag,
264 const bool theUpdateViewer) {}
266 /// Deactivate custom presentation for the object. Default realization is empty.
267 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
268 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
269 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
270 const bool theUpdateViewer) {}
272 /// Modifies the given presentation in the custom way.
273 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
275 GeomCustomPrsPtr theCustomPrs) { return false; };
277 /// Modifies the given presentation in the custom way after usual customize is performed.
278 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
280 GeomCustomPrsPtr theCustomPrs) { return false; };
282 /// Update the object presentable properties such as color, lines width and other
283 /// If the object is result with the color attribute value set, it is used,
284 /// otherwise the customize is applyed to the object's feature if it is a custom prs
285 /// \param theObject an object instance
286 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
287 /// should be updated(e.g. only highlighted elements)
288 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
289 /// \returns true if the object is modified
290 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
291 const bool theUpdateViewer);
293 /// This method is called on object browser creation for customization of module specific features
294 /// \param theObjectBrowser a pinter on Object Browser widget
295 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
297 /// Creates a new operation
298 /// \param theCmdId the operation name
299 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
301 /// Create specific for the module presentation
302 /// \param theResult an object for presentation
303 /// \return created presentation or NULL(default value)
304 virtual Handle(AIS_InteractiveObject) createPresentation(
305 const std::shared_ptr<ModelAPI_Result>& theResult);
307 //! Returns data object by AIS
308 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
310 //! Returns true if the presentation can be shown in shading mode
311 //! \param theAIS presentation to be checked
312 //! \return boolean value
313 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
315 /// Update state of pop-up menu items in object browser
316 /// \param theStdActions - a map of standard actions
317 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
319 /// Update state of pop-up menu items in viewer
320 /// \param theStdActions - a map of standard actions
321 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
323 /// Returns true if the action should be always enabled
324 /// \param theActionId an action index: Accept or Accept All
325 /// \return boolean value
326 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
328 //! Returns the feature error if the current state of the feature in the module is not correct
329 //! If the feature is correct, it returns an empty value
330 //! \return string value
331 virtual QString getFeatureError(const FeaturePtr& theFeature);
333 /// Returns list of granted operation indices
334 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
336 /// Connects or disconnects to the value changed signal of the property panel widgets
337 /// \param theWidget a property contol widget
338 /// \param isToConnect a boolean value whether connect or disconnect
339 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
341 /// Validates the operation to change the "Apply" button state.
342 /// \param thePreviousState the previous state of the widget
343 virtual void widgetStateChanged(int thePreviousState) {};
345 /// Returns true if the event is processed.
346 /// \param thePreviousAttributeID an index of the previous active attribute
347 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
349 /// Performs some GUI actions before an operation transaction is stopped
350 /// Default realization is empty
351 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
353 /// Finds a shape by attribute if it is possible
354 /// \param theAttribute an attribute
355 /// \return a geom shape
356 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
358 /// Finds an attribute by geom shape if it is possible
359 /// \param theObject an object of the attribute
360 /// \param theGeomShape a geom shape
361 /// \return theAttribute
362 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
363 const GeomShapePtr& theGeomShape) = 0;
365 /// Returns reentrant message if it was accepted
366 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
368 /// Put current selection into reentrant message
369 /// \param theMessage a message of reentrant operation
370 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
372 /// Returns XML information by the feature index
373 /// \param theFeatureId a feature id
374 /// \param theXmlCfg XML configuration
375 /// \param theDescription feature description
376 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
377 std::string& theDescription);
379 /// Returns root tree node which represents a data model
380 virtual ModuleBase_ITreeNode* rootNode() const = 0;
383 /// Segnal emitted when an operation is resumed
384 /// \param theOp a resumed operation
385 void resumed(ModuleBase_Operation* theOp);
388 /// Called on call of command corresponded to a feature
389 virtual void onFeatureTriggered();
391 /// Slot called on object display
392 /// \param theObject a data object
393 /// \param theAIS a presentation object
394 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
396 /// Slot called on before object erase
397 /// \param theObject a data object
398 /// \param theAIS a presentation object
399 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
402 /// Called on selection changed event
403 virtual void onSelectionChanged() {}
406 /// Register validators for this module
407 virtual void registerValidators() {}
409 /// Register properties of this module
410 virtual void registerProperties() {}
412 /// Returns new instance of operation object (used in createOperation for customization)
413 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
416 /// Reference to workshop
417 ModuleBase_IWorkshop* myWorkshop;
419 /// Map of features in XML
420 std::map<std::string, std::string> myFeaturesInFiles;
425 //! This function must return a new module instance.
427 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
430 #define CREATE_MODULE "createModule"
432 #endif //ModuleBase_IModule