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 /// Update selection filters depending on the module active controls
87 virtual void updateActiveSelectionFilters() {}
89 /// Stores the current selection
90 virtual void storeSelection() {}
92 /// Restores the current selection
93 virtual void restoreSelection() {}
95 /// Reads description of features from XML file
96 virtual void createFeatures();
98 /// Called on creation of menu item in desktop
99 virtual void actionCreated(QAction*);
101 /// Launching of a edit operation on the feature
102 /// \param theFeature feature for editing
103 virtual void editFeature(FeaturePtr theFeature);
105 /// Returns true if the operation can be committed. Result in default implementation is true.
106 /// \return boolean value
107 virtual bool canCommitOperation() const { return true; }
109 /// Creates an operation and send it to loop
110 /// \param theCmdId the operation name
111 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
113 virtual void launchOperation(const QString& theCmdId,
114 const bool& isStartAfterCommitOnly);
116 /// Executes feature as a modal dialog box
117 /// \param theCmdId the operation name
118 virtual void launchModal(const QString& theCmdId);
120 /// Realizes some functionality by an operation start
121 /// \param theOperation a started operation
122 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
124 /// Realizes some functionality by an operation resume
125 /// By default it emits operationResumed signal
126 /// \param theOperation a resumed operation
127 virtual void operationResumed(ModuleBase_Operation* theOperation);
129 /// Realizes some functionality by an operation stop
130 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
132 /// Realizes some functionality by an operation commit
133 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
135 /// Realizes some functionality by an operation abort
136 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
138 /// Realizes some functionality by an operation start
139 virtual ModuleBase_Operation* currentOperation() const = 0;
141 /// Add menu items for viewer into the actions map
142 /// \param theStdActions a map of standard actions
143 /// \param theParent a parent widget
144 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
145 /// \return true if items are added and there is no necessity to provide standard menu
146 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
148 QMap<int, QAction*>& theMenuActions) const
151 /// Add menu items for object browser into the given menu
152 /// \param theMenu a popup menu to be shown in the object browser
153 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
155 /// Creates custom widgets for property panel
156 /// \param theType a type of widget
157 /// \param theParent the parent object
158 /// \param theWidgetApi the widget configuration.
159 /// The attribute of the model widget is obtained from
160 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
162 Config_WidgetAPI* theWidgetApi)
167 /// Returns the active widget, by default it is the property panel active widget
168 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
170 /// Returns current workshop
171 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
173 /// Call back forlast tuning of property panel before operation performance
174 /// It is called as on clearing of property panel as on filling with new widgets
175 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
177 /// Have an opportunity to create widgets for the current operation
178 /// instead of standard creation in workshop
179 /// \param theOperation a started operation
180 /// \param theWidgets a list of created widgets
181 /// \return boolean result, false by default
182 virtual bool createWidgets(ModuleBase_Operation* theOperation,
183 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
185 //! Returns True if there are available Undos and there is not an active operation
186 virtual bool canUndo() const;
188 //! Returns True if there are available Redos and there is not an active operation
189 virtual bool canRedo() const;
191 /// Returns true if the action can be applyed to the object
192 /// \param theObject a checked object
193 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
194 /// \return the a boolean result
195 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
197 /// Returns True if the current operation can be committed. By default it is true.
198 /// \return a boolean value
199 //virtual bool canCommitOperation() const;
201 /// Returns whether the object can be erased. The default realization returns true.
202 /// \param theObject a model object
203 virtual bool canEraseObject(const ObjectPtr& theObject) const;
205 /// Returns whether the object can be displayed. The default realization returns true.
206 /// \param theObject a model object
207 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
209 /// Returns whether the started operation may use preselection of the previous one
210 /// Cases are: previous operation is null, edit operation, previuos and started operations
211 /// kinds are the same
212 /// \param thePreviousOperationKind a kind of previous operation
213 /// \param theStartedOperationKind a kind of a started operation
214 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
215 const QString& theStartedOperationKind);
217 /// Make some functionality after the objects are hidden in viewer
218 /// \param theObjects a list of hidden objects
219 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
221 /// Returns true if selection for the object can be activate.
222 /// By default a result or feature of the current operation can not be activated
223 /// \param theObject a model object
224 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
226 /// Reacts to the delete action in module
227 /// \returns true if the action is processed
228 virtual bool deleteObjects() { return false; };
230 /// Performs functionality on closing document
231 virtual void closeDocument() = 0;
233 /// Clears specific presentations in the viewer
234 virtual void clearViewer() = 0;
236 /// Returns a list of modes, where the AIS objects should be activated
237 /// \param theModes a list of modes
238 virtual void activeSelectionModes(QIntList& theModes) {}
240 /// Appends specific selection modes for the module to the list of types
241 /// \param theTypes a selection modes to be extended
242 virtual void customSubShapesSelectionModes(QIntList& theTypes) {}
244 /// Return true if the custom presentation is activated
245 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
246 /// \return boolean value
247 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
250 /// Activate custom presentation for the object. Default realization is empty.
251 /// \param theFeature a feature instance
252 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
253 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
254 virtual void activateCustomPrs(const FeaturePtr& theFeature,
255 const ModuleBase_CustomizeFlag& theFlag,
256 const bool theUpdateViewer) {}
258 /// Deactivate custom presentation for the object. Default realization is empty.
259 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
260 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
261 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
262 const bool theUpdateViewer) {}
264 /// Modifies the given presentation in the custom way.
265 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
267 GeomCustomPrsPtr theCustomPrs) { return false; };
269 /// Modifies the given presentation in the custom way after usual customize is performed.
270 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
272 GeomCustomPrsPtr theCustomPrs) { return false; };
274 /// Update the object presentable properties such as color, lines width and other
275 /// If the object is result with the color attribute value set, it is used,
276 /// otherwise the customize is applyed to the object's feature if it is a custom prs
277 /// \param theObject an object instance
278 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
279 /// should be updated(e.g. only highlighted elements)
280 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
281 /// \returns true if the object is modified
282 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
283 const bool theUpdateViewer);
285 /// This method is called on object browser creation for customization of module specific features
286 /// \param theObjectBrowser a pinter on Object Browser widget
287 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
289 /// Creates a new operation
290 /// \param theCmdId the operation name
291 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
293 /// Create specific for the module presentation
294 /// \param theResult an object for presentation
295 /// \return created presentation or NULL(default value)
296 virtual Handle(AIS_InteractiveObject) createPresentation(
297 const std::shared_ptr<ModelAPI_Result>& theResult);
299 //! Returns data object by AIS
300 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
302 //! Returns true if the presentation can be shown in shading mode
303 //! \param theAIS presentation to be checked
304 //! \return boolean value
305 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
307 /// Update state of pop-up menu items in object browser
308 /// \param theStdActions - a map of standard actions
309 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
311 /// Update state of pop-up menu items in viewer
312 /// \param theStdActions - a map of standard actions
313 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
315 /// Returns true if the action should be always enabled
316 /// \param theActionId an action index: Accept or Accept All
317 /// \return boolean value
318 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
320 //! Returns the feature error if the current state of the feature in the module is not correct
321 //! If the feature is correct, it returns an empty value
322 //! \return string value
323 virtual QString getFeatureError(const FeaturePtr& theFeature);
325 /// Returns list of granted operation indices
326 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
328 /// Connects or disconnects to the value changed signal of the property panel widgets
329 /// \param theWidget a property contol widget
330 /// \param isToConnect a boolean value whether connect or disconnect
331 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
333 /// Validates the operation to change the "Apply" button state.
334 /// \param thePreviousState the previous state of the widget
335 virtual void widgetStateChanged(int thePreviousState) {};
337 /// Returns true if the event is processed.
338 /// \param thePreviousAttributeID an index of the previous active attribute
339 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
341 /// Performs some GUI actions before an operation transaction is stopped
342 /// Default realization is empty
343 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
345 /// Finds a shape by attribute if it is possible
346 /// \param theAttribute an attribute
347 /// \return a geom shape
348 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
350 /// Finds an attribute by geom shape if it is possible
351 /// \param theObject an object of the attribute
352 /// \param theGeomShape a geom shape
353 /// \return theAttribute
354 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
355 const GeomShapePtr& theGeomShape) = 0;
357 /// Returns reentrant message if it was accepted
358 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
360 /// Put current selection into reentrant message
361 /// \param theMessage a message of reentrant operation
362 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
364 /// Returns XML information by the feature index
365 /// \param theFeatureId a feature id
366 /// \param theXmlCfg XML configuration
367 /// \param theDescription feature description
368 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
369 std::string& theDescription);
372 /// Segnal emitted when an operation is resumed
373 /// \param theOp a resumed operation
374 void resumed(ModuleBase_Operation* theOp);
377 /// Called on call of command corresponded to a feature
378 virtual void onFeatureTriggered();
380 /// Slot called on object display
381 /// \param theObject a data object
382 /// \param theAIS a presentation object
383 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
385 /// Slot called on before object erase
386 /// \param theObject a data object
387 /// \param theAIS a presentation object
388 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
391 /// Called on selection changed event
392 virtual void onSelectionChanged() {}
395 /// Register validators for this module
396 virtual void registerValidators() {}
398 /// Register properties of this module
399 virtual void registerProperties() {}
401 /// Returns new instance of operation object (used in createOperation for customization)
402 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
405 /// Reference to workshop
406 ModuleBase_IWorkshop* myWorkshop;
408 /// Map of features in XML
409 std::map<std::string, std::string> myFeaturesInFiles;
414 //! This function must return a new module instance.
416 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
419 #define CREATE_MODULE "createModule"
421 #endif //ModuleBase_IModule