1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
\r
3 // File: ModuleBase_WidgetSelector.h
\r
4 // Created: 19 June 2015
\r
5 // Author: Natalia ERMOLAEVA
\r
7 #ifndef ModuleBase_WidgetSelector_H
\r
8 #define ModuleBase_WidgetSelector_H
\r
10 #include "ModuleBase.h"
\r
11 #include "ModuleBase_WidgetValidated.h"
\r
12 #include "ModuleBase_Definitions.h"
\r
14 #include <ModelAPI_Object.h>
\r
15 #include <ModelAPI_Attribute.h>
\r
16 #include <GeomAPI_Shape.h>
\r
18 class Config_WidgetAPI;
\r
20 class ModuleBase_IWorkshop;
\r
21 class ModuleBase_ViewerPrs;
\r
22 class ModelAPI_Result;
\r
26 * Implementation of widget for selection.
\r
27 * This abstract interface is designed to be used for shape/multi shape selector widgets.
\r
29 class MODULEBASE_EXPORT ModuleBase_WidgetSelector : public ModuleBase_WidgetValidated
\r
35 /// \param theParent the parent object
\r
36 /// \param theWorkshop instance of workshop interface
\r
37 /// \param theData the widget configuation. The attribute of the model widget is obtained from
\r
38 ModuleBase_WidgetSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
\r
39 const Config_WidgetAPI* theData);
\r
41 virtual ~ModuleBase_WidgetSelector();
\r
43 /// Defines if it is supposed that the widget should interact with the viewer.
\r
44 virtual bool isViewerSelector() { return true; }
\r
46 /// Activate or deactivate selection and selection filters
\r
47 /// \return true if the selection filter of the widget is activated in viewer context
\r
48 virtual bool activateSelectionAndFilters(bool toActivate);
\r
50 /// Checks the widget validity. By default, it returns true.
\r
51 /// \param thePrs a selected presentation in the view
\r
52 /// \return a boolean value
\r
53 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
\r
55 /// Fills the attribute with the value of the selected owner
\r
56 /// \param thePrs a selected owner
\r
57 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
\r
59 /// The methiod called when widget is deactivated
\r
60 virtual void deactivate();
\r
62 /// Return the attribute values wrapped in a list of viewer presentations
\r
63 /// \return a list of viewer presentations, which contains an attribute result and
\r
64 /// a shape. If the attribute do not uses the shape, it is empty
\r
65 virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
\r
68 /// Slot which is called on selection event
\r
69 virtual void onSelectionChanged();
\r
72 /// Emits model changed info, updates the current control by selection change
\r
73 /// \param theDone a state whether the selection is set
\r
74 virtual void updateOnSelectionChanged(const bool theDone);
\r
76 /// Update focus after the attribute value change
\r
77 // NDS: has body is temporary
\r
78 virtual void updateFocus() {};
\r
80 /// Retunrs a list of possible shape types
\r
81 /// \return a list of shapes
\r
82 QIntList getShapeTypes() const;
\r
84 /// Retunrs a list of possible shape types
\r
85 /// \return a list of shapes
\r
86 virtual QIntList shapeTypes() const = 0;
\r
88 /// Computes and updates name of selected object in the widget
\r
89 // NDS: has body is temporary
\r
90 virtual void updateSelectionName() {};
\r
92 /// The methiod called when widget is activated
\r
93 virtual void activateCustom();
\r
95 /// Returns true if selected shape corresponds to requested shape types.
\r
96 /// If the widget type of shapes contains the faces item, the result is converted
\r
97 /// to construction result and the method returns true if there is at least one face
\r
98 /// in the construction.
\r
99 /// \param theShape a shape
\r
100 /// \param theResult a selected result
\r
101 bool acceptSubShape(const GeomShapePtr& theShape,
\r
102 const std::shared_ptr<ModelAPI_Result>& theResult) const;
\r
104 /// Return an object and geom shape by the viewer presentation
\r
105 /// \param thePrs a selection
\r
106 /// \param theObject an output object
\r
107 /// \param theShape a shape of the selection
\r
108 virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
\r
109 ObjectPtr& theObject,
\r
110 GeomShapePtr& theShape);
\r
112 //----------- Class members -------------
\r
113 /// Returns a name in the next form: attribute_feature_name/attribute_id
\r
114 /// \param theAttribute a model attribute
\r
115 /// \param theWorkshop a workshop class instance
\r
116 /// \return string value
\r
117 static std::string generateName(const AttributePtr& theAttribute,
\r
118 ModuleBase_IWorkshop* theWorkshop);
\r