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 #ifndef PartSet_Module_H
22 #define PartSet_Module_H
25 #include "PartSet_Tools.h"
26 #include "PartSet_OverconstraintListener.h"
27 #include "PartSet_SketcherMgr.h"
29 #include <ModuleBase_IModule.h>
30 #include <ModuleBase_Definitions.h>
31 #include <ModelAPI_Feature.h>
32 #include <ModelAPI_Attribute.h>
33 #include <ModelAPI_CompositeFeature.h>
35 #include <Events_Listener.h>
37 //#include <StdSelect_FaceFilter.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <SelectMgr_ListOfFilter.hxx>
44 #include <QModelIndex>
50 class ModuleBase_Operation;
51 class ModuleBase_IViewWindow;
52 class ModuleBase_ViewerPrs;
55 class PartSet_MenuMgr;
56 class PartSet_CustomPrs;
57 class PartSet_SketcherMgr;
58 class PartSet_SketcherReentrantMgr;
59 class ModelAPI_Result;
65 * Implementation of Partset module
67 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
71 /// Enumeration to specify the restart operation properties.
73 RM_None, /// the operation should not be restarted
74 RM_Forbided, /// the operation should not be restarted after there is no active widget
75 RM_LastFeatureUsed, /// the operation is restarted and use the previous feature
76 /// for own initialization
77 RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
83 /// \param theWshop a pointer to a workshop
84 PartSet_Module(ModuleBase_IWorkshop* theWshop);
85 virtual ~PartSet_Module();
87 // Stores the current selection
88 virtual void storeSelection();
90 // Restores the current selection
91 virtual void restoreSelection();
93 /// Creates custom widgets for property panel
94 virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
95 Config_WidgetAPI* theWidgetApi);
97 /// Returns the active widget, by default it is the property panel active widget
98 /// If the internal edit operation is started, this is the first widget of the operation
99 virtual ModuleBase_ModelWidget* activeWidget() const;
101 /// Call back forlast tuning of property panel before operation performance
102 virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
104 /// If there is found selected attribute, widgets are created and contains
105 /// only a widget for the attribute
106 /// It is important for Property Panel filling by sketch point attribute
107 /// \param theOperation a started operation
108 /// \param theWidgets a list of created widgets
109 /// \return boolean result, false by default
110 virtual bool createWidgets(ModuleBase_Operation* theOperation,
111 QList<ModuleBase_ModelWidget*>& theWidgets) const;
113 /// Launching of a edit operation on the feature
114 /// \param theFeature feature for editing
115 virtual void editFeature(FeaturePtr theFeature);
117 /// Returns true if the operation can be committed. Result in default implementation is true.
118 /// \return boolean value
119 virtual bool canCommitOperation() const;
121 /// Creates an operation and send it to loop
122 /// \param theCmdId the operation name
123 /// \param isStartAfterCommitOnly operation is launched if there is no active operation or
125 virtual void launchOperation(const QString& theCmdId,
126 const bool& isStartAfterCommitOnly);
128 /// Realizes some functionality by an operation start
129 /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
130 /// Activate the operation presentation
131 /// \param theOperation a started operation
132 virtual void operationStarted(ModuleBase_Operation* theOperation);
134 /// Realizes some functionality by an operation resume
135 /// Activate the operation presentation
136 /// \param theOperation a resumed operation
137 virtual void operationResumed(ModuleBase_Operation* theOperation);
139 /// Realizes some functionality by an operation commit
140 /// Restarts sketcher operation automatically of it is necessary
141 /// \param theOperation a committed operation
142 virtual void operationCommitted(ModuleBase_Operation* theOperation);
144 /// Realizes some functionality by an operation abort
145 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
146 /// \param theOperation an aborted operation
147 virtual void operationAborted(ModuleBase_Operation* theOperation);
149 /// Realizes some functionality by an operation stop
150 /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
151 /// \param theOperation a stopped operation
152 virtual void operationStopped(ModuleBase_Operation* theOperation);
154 /// Returns current operation
155 virtual ModuleBase_Operation* currentOperation() const;
157 /// Returns True if there are available Undos and the sketch manager allows undo
158 /// \return the boolean result
159 virtual bool canUndo() const;
161 //! Returns True if there are available Redos and the sketch manager allows redo
162 /// \return the boolean result
163 virtual bool canRedo() const;
165 /// Returnas true if the action can be applyed to the object
166 /// \param theObject a checked object
167 /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
168 /// \return the a booean result
169 virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
171 /// Returns True if the current operation can be committed. Asks the sketch manager.
172 /// \return a boolean value
173 //virtual bool canCommitOperation() const;
175 /// Returns whether the object can be erased at the bounds of the active operation.
176 /// The sub-objects of the current operation can not be erased
177 /// \param theObject a model object
178 virtual bool canEraseObject(const ObjectPtr& theObject) const;
180 /// Returns whether the object can be displayed at the bounds of the active operation.
181 /// Display only current operation results for usual operation and ask the sketcher manager
182 /// if it is a sketch operation
183 /// \param theObject a model object
184 virtual bool canDisplayObject(const ObjectPtr& theObject) const;
186 /// Returns parent result if accepted, true if the started operation is a nested operation
187 /// of the previous operation
188 /// \param thePreviousOperationKind a kind of previous operation
189 /// \param theStartedOperationKind a kind of a new operation
190 virtual bool canUsePreselection(const QString& thePreviousOperationKind,
191 const QString& theStartedOperationKind);
193 /// Make some functionality after the objects are hidden in viewer
194 /// \param theObjects a list of hidden objects
195 //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
197 /// Returns true if selection for the object can be activate.
198 /// For sketch operation allow the selection activation if the operation is edit, for other
199 /// operation uses the default result
200 /// \param theObject a model object
201 virtual bool canActivateSelection(const ObjectPtr& theObject) const;
203 /// Appends into container of workshop selection filters
204 /// \param [out] selection filters
205 virtual void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters) const;
207 /// Add menu atems for object browser into the given menu
208 /// \param theMenu a popup menu to be shown in the object browser
209 virtual void addObjectBrowserMenu(QMenu* theMenu) const;
211 /// Add menu items for viewer into the actions map
212 /// \param theStdActions a map of standard actions
213 /// \param theParent a parent widget
214 /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
215 /// \return true if items are added and there is no necessity to provide standard menu
216 virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
218 QMap<int, QAction*>& theMenuActions) const;
220 /// Returns a list of modes, where the AIS objects should be activated
221 /// \param theModes a list of modes
222 virtual void activeSelectionModes(QIntList& theModes);
224 /// Appends specific selection modes for the module to the list of types
225 /// \param theModes a selection modes to be extended
226 virtual void customSubShapesSelectionModes(QIntList& theModes);
228 /// Returns whether the mouse enter the viewer's window
229 /// \return true if items are added and there is no necessity to provide standard menu
230 bool isMouseOverWindow();
232 /// Returns sketch manager object
233 PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
235 /// Returns sketch reentrant manager
236 PartSet_SketcherReentrantMgr* sketchReentranceMgr() const { return mySketchReentrantMgr; }
238 /// Find object and attribute(if selected) for the given viewer selection
239 /// \param theSelected a viewer selection
240 /// \param theObject a selected model object
241 /// \param theAttribute a selected model attribute
242 virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
243 ObjectPtr& theObject, AttributePtr& theAttribute);
245 /// Returns listener of overconstraint signal
246 /// \return the listener
247 PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
249 /// Returns true if the current operation is not reentrant and the current state of the
250 /// application is not in launch operation mode
251 /// \return boolean value
252 bool isSketchNeutralPointActivated() const;
254 /// Performs functionality on closing document
255 virtual void closeDocument();
257 /// Clears specific presentations in the viewer
258 virtual void clearViewer();
260 /// Event Listener method
261 /// \param theMessage an event message
262 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
264 /// Set the object with the object results are customized
265 /// \param theFeature a feature
266 void setCustomized(const FeaturePtr& theFeature);
268 /// Return true if the custom presentation is activated
269 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
270 /// \return boolean value
271 virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const;
273 /// Activate custom presentation for the object
274 /// \param theFeature a feature instance
275 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
276 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
277 virtual void activateCustomPrs(const FeaturePtr& theFeature,
278 const ModuleBase_CustomizeFlag& theFlag,
279 const bool theUpdateViewer);
281 /// Deactivate custom presentation for the object
282 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
283 /// \param theUpdateViewer the parameter whether the viewer should be update immediately
284 virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
285 const bool theUpdateViewer);
287 /// Modifies the given presentation in the custom way.
288 virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
290 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
292 /// Modifies the given presentation in the custom way after usual customize is performed.
293 virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
295 GeomCustomPrsPtr theCustomPrs);
297 /// Update the object presentable properties such as color, lines width and other
298 /// If the object is result with the color attribute value set, it is used,
299 /// otherwise the customize is applyed to the object's feature if it is a custom prs
300 /// \param theObject an object instance
301 /// \param theFlag a flag of level of customization, which means that only part of sub-elements
302 /// should be updated(e.g. only highlighted elements)
303 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
304 /// \returns true if the object is modified
305 virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
306 const bool theUpdateViewer);
308 /// This method is called on object browser creation for customisation of module specific features
309 /// \param theObjectBrowser a pinter on Object Browser widget
310 virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
312 /// Returns the viewer Z layer
313 int getVisualLayerId() const { return myVisualLayerId; }
315 /// Create specific for the module presentation
316 /// \param theResult an object for presentation
317 /// \return created presentation or NULL(default value)
318 virtual Handle(AIS_InteractiveObject) createPresentation(
319 const std::shared_ptr<ModelAPI_Result>& theResult);
321 //! Returns data object by AIS
322 virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
324 //! Returns true if the presentation can be shown in shading mode
325 //! \param theAIS presentation to be checked
326 //! \return boolean value
327 virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
329 /// Update state of pop-up menu items in viewer
330 /// \param theStdActions - a map of standard actions
331 virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
333 /// Returns true if the action should be always enabled
334 /// \param theActionId an action index: Accept or Accept All
335 /// \return boolean value
336 virtual bool isActionEnableStateFixed(const int theActionId) const;
338 //! Returns the feature error if the current state of the feature in the module is not correct
339 //! If the feature is correct, it returns an empty value
340 //! \return string value
341 virtual QString getFeatureError(const FeaturePtr& theFeature);
343 /// Returns list of granted operation indices
344 virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
346 /// Validates the current operation and send the state change to sketch manager
347 /// \param thePreviousState the previous widget value state
348 virtual void widgetStateChanged(int thePreviousState);
350 /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
351 /// \param thePreviousAttributeID an index of the previous active attribute
352 virtual bool processEnter(const std::string& thePreviousAttributeID);
354 /// Performs some GUI actions before an operation transaction is stopped
355 /// Default realization is empty
356 virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
358 /// Finds a shape by attribute if it is possible
359 /// \param theAttribute an attribute
360 /// \return a geom shape
361 virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
363 /// Finds an attribute by geom shape if it is possible
364 /// \param theObject an object of the attribute
365 /// \param theGeomShape a geom shape
366 /// \return theAttribute
367 virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
369 /// Returns reentrant message if it was accepted
370 virtual std::shared_ptr<Events_Message> reentrantMessage();
372 /// Put current selection into reentrant message
373 /// \param theMessage a message of reentrant operation
374 virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
376 /// Returns the workshop
377 XGUI_Workshop* getWorkshop() const;
380 /// Slolt 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);
390 /// Called on transformation in current viewer
391 /// \param theTrsfType type of tranformation
392 void onViewTransformed(int theTrsfType = 2);
395 /// Called when previous operation is finished
396 virtual void onSelectionChanged();
398 /// SLOT, that is called by key release in the viewer.
399 /// \param theWnd a view window
400 /// \param theEvent the key event
401 void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
403 /// A slot called on view window creation
404 void onViewCreated(ModuleBase_IViewWindow*);
406 /// A slot to change property panel title by choice type change if the title information
407 /// exists in the XML definition of this control attribute
408 /// \param theWidget a sender
409 /// \param theIndex the current choice index
410 void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
413 /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
414 /// other dimensions are shown.
415 /// \param theFeatureKindId a feature kind
416 void storeConstraintsState(const std::string& theFeatureKindId);
418 /// If the feature kind is a geometrical or dimensional constraint, set visible state for
419 /// all types of constraints
420 /// \param theFeatureKindId a feature kind
421 void updateConstraintsState(const std::string& theFeatureKind);
423 /// Register validators for this module
424 virtual void registerValidators();
426 /// Connects or disconnects to the value changed signal of the property panel widgets
427 /// \param theWidget a property contol widget
428 /// \param isToConnect a boolean value whether connect or disconnect
429 virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
431 /// Updates reentrant manager state or sketcher operations for the started operation
432 /// \param theOperation the started operation
433 void updateSketcherOnStart(ModuleBase_Operation* theOperation);
435 /// Updates presetnations of results and arguments by operation start
436 /// \param theOperation the started operation
437 void updatePresentationsOnStart(ModuleBase_Operation* theOperation);
440 void onTreeViewDoubleClick(const QModelIndex&);
442 void onActiveDocPopup(const QPoint&);
446 virtual bool deleteObjects();
448 void setDefaultConstraintShown();
451 bool myIsOperationIsLaunched; /// state of application between launch and stop operation
452 SelectMgr_ListOfFilter mySelectionFilters;
454 PartSet_SketcherMgr* mySketchMgr;
455 PartSet_SketcherReentrantMgr* mySketchReentrantMgr;
456 PartSet_MenuMgr* myMenuMgr;
457 /// A default custom presentation, which is used for references objects of started operation
458 PartSet_CustomPrs* myCustomPrs;
459 PartSet_OverconstraintListener* myOverconstraintListener;
462 /// backup of the visible state to restore them by operation stop
463 QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
465 /// backup of selection in the viewer, it is used only to store selection before
466 /// redisplay and restore it after
467 PartSet_SketcherMgr::FeatureToSelectionMap myCurrentSelection;
468 QModelIndex myActivePartIndex;