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>
48 class Config_WidgetAPI;
49 class ModuleBase_ModelWidget;
50 class ModuleBase_Operation;
51 class ModuleBase_ViewerPrs;
53 class ModuleBase_IWorkshop;
54 class ModelAPI_Result;
57 class AIS_InteractiveObject;
61 * Interface to a module
63 class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
67 /// enumeration to know which objects should be customized
68 enum ModuleBase_CustomizeFlag {
69 CustomizeArguments = 0, /// references of other objects referenced to the current feature
70 CustomizeResults, /// results of the current feature
71 CustomizeHighlightedObjects /// highlighted objects of the active widget
75 /// \param theParent instance of workshop interface
76 ModuleBase_IModule(ModuleBase_IWorkshop* theParent);
78 virtual ~ModuleBase_IModule() {}
80 /// Add default selection filters of the module to the current viewer
81 virtual void activateSelectionFilters() {}
83 /// Remove default selection filters of the module from the current viewer
84 virtual void deactivateSelectionFilters() {}
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 theOperation a started operation
177 /// \param theWidgets a list of created widgets
178 /// \return boolean result, false by default
179 virtual bool createWidgets(ModuleBase_Operation* theOperation,
180 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
182 //! Returns True if there are available Undos and there is not an active operation
183 virtual bool canUndo() const;
185 //! Returns True if there are available Redos and there is not an active operation
186 virtual bool canRedo() const;
188 /// Returns true if the action can be applyed to the object
189 /// \param theObject a checked object
190 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
191 /// \return the a boolean result
192 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
194 /// Returns True if the current operation can be committed. By default it is true.
195 /// \return a boolean value
196 //virtual bool canCommitOperation() const;
198 /// Returns whether the object can be erased. The default realization returns true.
199 /// \param theObject a model object
200 virtual bool canEraseObject(const ObjectPtr& theObject) const;
202 /// Returns whether the object can be displayed. The default realization returns true.
203 /// \param theObject a model object
204 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
206 /// Returns whether the started operation may use preselection of the previous one
207 /// Cases are: previous operation is null, edit operation, previuos and started operations
208 /// kinds are the same
209 /// \param thePreviousOperationKind a kind of previous operation
210 /// \param theStartedOperationKind a kind of a started operation
211 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
212 const QString& theStartedOperationKind);
214 /// Make some functionality after the objects are hidden in viewer
215 /// \param theObjects a list of hidden objects
216 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
218 /// Returns true if selection for the object can be activate.
219 /// By default a result or feature of the current operation can not be activated
220 /// \param theObject a model object
221 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
223 /// Reacts to the delete action in module
224 /// \returns true if the action is processed
225 virtual bool deleteObjects() { return false; };
227 /// Performs functionality on closing document
228 virtual void closeDocument() = 0;
230 /// Clears specific presentations in the viewer
231 virtual void clearViewer() = 0;
233 /// Returns a list of modes, where the AIS objects should be activated
234 /// \param theModes a list of modes
235 virtual void activeSelectionModes(QIntList& theModes) {}
237 /// Appends specific selection modes for the module to the list of types
238 /// \param theTypes a selection modes to be extended
239 virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
241 /// Return true if the custom presentation is activated
242 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
243 /// \return boolean value
244 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
247 /// Activate custom presentation for the object. Default realization is empty.
248 /// \param theFeature a feature instance
249 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
250 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
251 virtual void activateCustomPrs(const FeaturePtr& theFeature,
252 const ModuleBase_CustomizeFlag& theFlag,
253 const bool theUpdateViewer) {}
255 /// Deactivate custom presentation for the object. Default realization is empty.
256 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
257 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
258 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
259 const bool theUpdateViewer) {}
261 /// Modifies the given presentation in the custom way.
262 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
264 GeomCustomPrsPtr theCustomPrs) { return false; };
266 /// Modifies the given presentation in the custom way after usual customize is performed.
267 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
269 GeomCustomPrsPtr theCustomPrs) { return false; };
271 /// Update the object presentable properties such as color, lines width and other
272 /// If the object is result with the color attribute value set, it is used,
273 /// otherwise the customize is applyed to the object's feature if it is a custom prs
274 /// \param theObject an object instance
275 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
276 /// should be updated(e.g. only highlighted elements)
277 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
278 /// \returns true if the object is modified
279 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
280 const bool theUpdateViewer);
282 /// This method is called on object browser creation for customization of module specific features
283 /// \param theObjectBrowser a pinter on Object Browser widget
284 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
286 /// Creates a new operation
287 /// \param theCmdId the operation name
288 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
290 /// Create specific for the module presentation
291 /// \param theResult an object for presentation
292 /// \return created presentation or NULL(default value)
293 virtual Handle(AIS_InteractiveObject) createPresentation(
294 const std::shared_ptr<ModelAPI_Result>& theResult);
296 //! Returns data object by AIS
297 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
299 //! Returns true if the presentation can be shown in shading mode
300 //! \param theAIS presentation to be checked
301 //! \return boolean value
302 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
304 /// Update state of pop-up menu items in object browser
305 /// \param theStdActions - a map of standard actions
306 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
308 /// Update state of pop-up menu items in viewer
309 /// \param theStdActions - a map of standard actions
310 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
312 /// Returns true if the action should be always enabled
313 /// \param theActionId an action index: Accept or Accept All
314 /// \return boolean value
315 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
317 //! Returns the feature error if the current state of the feature in the module is not correct
318 //! If the feature is correct, it returns an empty value
319 //! \return string value
320 virtual QString getFeatureError(const FeaturePtr& theFeature);
322 /// Returns list of granted operation indices
323 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
325 /// Connects or disconnects to the value changed signal of the property panel widgets
326 /// \param theWidget a property contol widget
327 /// \param isToConnect a boolean value whether connect or disconnect
328 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
330 /// Validates the operation to change the "Apply" button state.
331 /// \param thePreviousState the previous state of the widget
332 virtual void widgetStateChanged(int thePreviousState) {};
334 /// Returns true if the event is processed.
335 /// \param thePreviousAttributeID an index of the previous active attribute
336 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
338 /// Performs some GUI actions before an operation transaction is stopped
339 /// Default realization is empty
340 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
342 /// Finds a shape by attribute if it is possible
343 /// \param theAttribute an attribute
344 /// \return a geom shape
345 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
347 /// Finds an attribute by geom shape if it is possible
348 /// \param theObject an object of the attribute
349 /// \param theGeomShape a geom shape
350 /// \return theAttribute
351 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
352 const GeomShapePtr& theGeomShape) = 0;
354 /// Returns reentrant message if it was accepted
355 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
357 /// Put current selection into reentrant message
358 /// \param theMessage a message of reentrant operation
359 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
361 /// Returns XML information by the feature index
362 /// \param theFeatureId a feature id
363 /// \param theXmlCfg XML configuration
364 /// \param theDescription feature description
365 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
366 std::string& theDescription);
369 /// Segnal emitted when an operation is resumed
370 /// \param theOp a resumed operation
371 void resumed(ModuleBase_Operation* theOp);
374 /// Called on call of command corresponded to a feature
375 virtual void onFeatureTriggered();
377 /// Slot called on object display
378 /// \param theObject a data object
379 /// \param theAIS a presentation object
380 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
382 /// Slot called on before object erase
383 /// \param theObject a data object
384 /// \param theAIS a presentation object
385 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
388 /// Called on selection changed event
389 virtual void onSelectionChanged() {}
392 /// Register validators for this module
393 virtual void registerValidators() {}
395 /// Register properties of this module
396 virtual void registerProperties() {}
398 /// Returns new instance of operation object (used in createOperation for customization)
399 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
402 /// Reference to workshop
403 ModuleBase_IWorkshop* myWorkshop;
405 /// Map of features in XML
406 std::map<std::string, std::string> myFeaturesInFiles;
411 //! This function must return a new module instance.
413 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
416 #define CREATE_MODULE "createModule"
418 #endif //ModuleBase_IModule