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