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;
51 class ModuleBase_ModelWidget;
52 class ModuleBase_Operation;
53 class ModuleBase_ViewerPrs;
55 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 /// Appends into container of workshop selection filters
83 /// \param [out] selection filters
84 virtual void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters) const {}
86 /// Returns current selection modes that should be used in 3D viewer
87 /// \param theModes container of modes
88 virtual void selectionModes(QIntList& theModes) const {}
90 /// Stores the current selection
91 virtual void storeSelection() {}
93 /// Restores the current selection
94 virtual void restoreSelection() {}
96 /// Reads description of features from XML file
97 virtual void createFeatures();
99 /// Called on creation of menu item in desktop
100 virtual void actionCreated(QAction*);
102 /// Launching of a edit operation on the feature
103 /// \param theFeature feature for editing
104 virtual void editFeature(FeaturePtr theFeature);
106 /// Returns true if the operation can be committed. Result in default implementation is true.
107 /// \return boolean value
108 virtual bool canCommitOperation() const { return true; }
110 /// Creates an operation and send it to loop
111 /// \param theCmdId the operation name
112 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
114 virtual void launchOperation(const QString& theCmdId,
115 const bool& isStartAfterCommitOnly);
117 /// Executes feature as a modal dialog box
118 /// \param theCmdId the operation name
119 virtual void launchModal(const QString& theCmdId);
121 /// Realizes some functionality by an operation start
122 /// \param theOperation a started operation
123 virtual void operationStarted(ModuleBase_Operation* theOperation) {}
125 /// Realizes some functionality by an operation resume
126 /// By default it emits operationResumed signal
127 /// \param theOperation a resumed operation
128 virtual void operationResumed(ModuleBase_Operation* theOperation);
130 /// Realizes some functionality by an operation stop
131 virtual void operationStopped(ModuleBase_Operation* theOperation) {}
133 /// Realizes some functionality by an operation commit
134 virtual void operationCommitted(ModuleBase_Operation* theOperation) {}
136 /// Realizes some functionality by an operation abort
137 virtual void operationAborted(ModuleBase_Operation* theOperation) {}
139 /// Realizes some functionality by an operation start
140 virtual ModuleBase_Operation* currentOperation() const = 0;
142 /// Add menu items for viewer into the actions map
143 /// \param theStdActions a map of standard actions
144 /// \param theParent a parent widget
145 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
146 /// \return true if items are added and there is no necessity to provide standard menu
147 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
149 QMap<int, QAction*>& theMenuActions) const
152 /// Add menu items for object browser into the given menu
153 /// \param theMenu a popup menu to be shown in the object browser
154 virtual void addObjectBrowserMenu(QMenu* theMenu) const {};
156 /// Creates custom widgets for property panel
157 /// \param theType a type of widget
158 /// \param theParent the parent object
159 /// \param theWidgetApi the widget configuration.
160 /// The attribute of the model widget is obtained from
161 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
163 Config_WidgetAPI* theWidgetApi)
168 /// Returns the active widget, by default it is the property panel active widget
169 virtual ModuleBase_ModelWidget* activeWidget() const = 0;
171 /// Returns current workshop
172 ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
174 /// Call back forlast tuning of property panel before operation performance
175 /// It is called as on clearing of property panel as on filling with new widgets
176 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation) {}
178 /// Have an opportunity to create widgets for the current operation
179 /// instead of standard creation in workshop
180 /// \param theOperation a started operation
181 /// \param theWidgets a list of created widgets
182 /// \return boolean result, false by default
183 virtual bool createWidgets(ModuleBase_Operation* theOperation,
184 QList<ModuleBase_ModelWidget*>& theWidgets) const { return false; }
186 //! Returns True if there are available Undos and there is not an active operation
187 virtual bool canUndo() const;
189 //! Returns True if there are available Redos and there is not an active operation
190 virtual bool canRedo() const;
192 /// Returns true if the action can be applyed to the object
193 /// \param theObject a checked object
194 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
195 /// \return the a boolean result
196 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const = 0;
198 /// Returns True if the current operation can be committed. By default it is true.
199 /// \return a boolean value
200 //virtual bool canCommitOperation() const;
202 /// Returns whether the object can be erased. The default realization returns true.
203 /// \param theObject a model object
204 virtual bool canEraseObject(const ObjectPtr& theObject) const;
206 /// Returns whether the object can be displayed. The default realization returns true.
207 /// \param theObject a model object
208 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
210 /// Returns whether the started operation may use preselection of the previous one
211 /// Cases are: previous operation is null, edit operation, previuos and started operations
212 /// kinds are the same
213 /// \param thePreviousOperationKind a kind of previous operation
214 /// \param theStartedOperationKind a kind of a started operation
215 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
216 const QString& theStartedOperationKind);
218 /// Make some functionality after the objects are hidden in viewer
219 /// \param theObjects a list of hidden objects
220 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects) {};
222 /// Returns true if selection for the object can be activate.
223 /// By default a result or feature of the current operation can not be activated
224 /// \param theObject a model object
225 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
227 /// Reacts to the delete action in module
228 /// \returns true if the action is processed
229 virtual bool deleteObjects() { return false; };
231 /// Performs functionality on closing document
232 virtual void closeDocument() = 0;
234 /// Clears specific presentations in the viewer
235 virtual void clearViewer() = 0;
237 /// Returns a list of modes, where the AIS objects should be activated
238 /// \param theModes a list of modes
239 virtual void activeSelectionModes(QIntList& theModes) {}
241 /// Appends specific selection modes for the module to the list of types
242 /// \param theModes a selection modes to be extended
243 virtual void customSubShapesSelectionModes(QIntList& theModes) {}
245 /// Return true if the custom presentation is activated
246 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
247 /// \return boolean value
248 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
251 /// Activate custom presentation for the object. Default realization is empty.
252 /// \param theFeature a feature instance
253 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
254 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
255 virtual void activateCustomPrs(const FeaturePtr& theFeature,
256 const ModuleBase_CustomizeFlag& theFlag,
257 const bool theUpdateViewer) {}
259 /// Deactivate custom presentation for the object. Default realization is empty.
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 deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
263 const bool theUpdateViewer) {}
265 /// Modifies the given presentation in the custom way.
266 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
268 GeomCustomPrsPtr theCustomPrs) { return false; };
270 /// Modifies the given presentation in the custom way after usual customize is performed.
271 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
273 GeomCustomPrsPtr theCustomPrs) { return false; };
275 /// Update the object presentable properties such as color, lines width and other
276 /// If the object is result with the color attribute value set, it is used,
277 /// otherwise the customize is applyed to the object's feature if it is a custom prs
278 /// \param theObject an object instance
279 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
280 /// should be updated(e.g. only highlighted elements)
281 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
282 /// \returns true if the object is modified
283 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
284 const bool theUpdateViewer);
286 /// This method is called on object browser creation for customization of module specific features
287 /// \param theObjectBrowser a pinter on Object Browser widget
288 virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}
290 /// Creates a new operation
291 /// \param theCmdId the operation name
292 virtual ModuleBase_Operation* createOperation(const std::string& theCmdId);
294 /// Create specific for the module presentation
295 /// \param theResult an object for presentation
296 /// \return created presentation or NULL(default value)
297 virtual Handle(AIS_InteractiveObject) createPresentation(
298 const std::shared_ptr<ModelAPI_Result>& theResult);
300 //! Returns data object by AIS
301 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0;
303 //! Returns true if the presentation can be shown in shading mode
304 //! \param theAIS presentation to be checked
305 //! \return boolean value
306 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
308 /// Update state of pop-up menu items in object browser
309 /// \param theStdActions - a map of standard actions
310 virtual void updateObjectBrowserMenu(const QMap<QString, QAction*>& theStdActions) {}
312 /// Update state of pop-up menu items in viewer
313 /// \param theStdActions - a map of standard actions
314 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions) {}
316 /// Returns true if the action should be always enabled
317 /// \param theActionId an action index: Accept or Accept All
318 /// \return boolean value
319 virtual bool isActionEnableStateFixed(const int theActionId) const { return false; }
321 //! Returns the feature error if the current state of the feature in the module is not correct
322 //! If the feature is correct, it returns an empty value
323 //! \return string value
324 virtual QString getFeatureError(const FeaturePtr& theFeature);
326 /// Returns list of granted operation indices
327 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
329 /// Connects or disconnects to the value changed signal of the property panel widgets
330 /// \param theWidget a property contol widget
331 /// \param isToConnect a boolean value whether connect or disconnect
332 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect) {};
334 /// Validates the operation to change the "Apply" button state.
335 /// \param thePreviousState the previous state of the widget
336 virtual void widgetStateChanged(int thePreviousState) {};
338 /// Returns true if the event is processed.
339 /// \param thePreviousAttributeID an index of the previous active attribute
340 virtual bool processEnter(const std::string& thePreviousAttributeID) { return false; };
342 /// Performs some GUI actions before an operation transaction is stopped
343 /// Default realization is empty
344 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {};
346 /// Finds a shape by attribute if it is possible
347 /// \param theAttribute an attribute
348 /// \return a geom shape
349 virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0;
351 /// Finds an attribute by geom shape if it is possible
352 /// \param theObject an object of the attribute
353 /// \param theGeomShape a geom shape
354 /// \return theAttribute
355 virtual AttributePtr findAttribute(const ObjectPtr& theObject,
356 const GeomShapePtr& theGeomShape) = 0;
358 /// Returns reentrant message if it was accepted
359 virtual std::shared_ptr<Events_Message> reentrantMessage() = 0;
361 /// Put current selection into reentrant message
362 /// \param theMessage a message of reentrant operation
363 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage) = 0;
365 /// Returns XML information by the feature index
366 /// \param theFeatureId a feature id
367 /// \param theXmlCfg XML configuration
368 /// \param theDescription feature description
369 void getXMLRepresentation(const std::string& theFeatureId, std::string& theXmlCfg,
370 std::string& theDescription);
373 /// Segnal emitted when an operation is resumed
374 /// \param theOp a resumed operation
375 void resumed(ModuleBase_Operation* theOp);
378 /// Called on call of command corresponded to a feature
379 virtual void onFeatureTriggered();
381 /// Slot called on object display
382 /// \param theObject a data object
383 /// \param theAIS a presentation object
384 virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS) {}
386 /// Slot called on before object erase
387 /// \param theObject a data object
388 /// \param theAIS a presentation object
389 virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS) {}
392 /// Called on selection changed event
393 virtual void onSelectionChanged() {}
396 /// Register validators for this module
397 virtual void registerValidators() {}
399 /// Register properties of this module
400 virtual void registerProperties() {}
402 /// Returns new instance of operation object (used in createOperation for customization)
403 virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
406 /// Reference to workshop
407 ModuleBase_IWorkshop* myWorkshop;
409 /// Map of features in XML
410 std::map<std::string, std::string> myFeaturesInFiles;
415 //! This function must return a new module instance.
417 typedef ModuleBase_IModule* (*CREATE_FUNC)(ModuleBase_IWorkshop*);
420 #define CREATE_MODULE "createModule"
422 #endif //ModuleBase_IModule