f38229db25aa3ea49b44d4a3d7ea148e9a1aa3c9
[occt.git] / tools / ShapeView / ShapeView_VisibilityState.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef ShapeView_VisibilityState_H
17 #define ShapeView_VisibilityState_H
18
19 #include <inspector/TreeModel_VisibilityState.hxx>
20
21 #include <inspector/View_Displayer.hxx>
22
23 #include <Standard.hxx>
24 #include <Standard_Macro.hxx>
25 #include <TopoDS_Shape.hxx>
26
27 class TreeModel_ModelBase;
28
29 //! \class ShapeView_VisibilityState
30 //! \brief Class provides connection between model and visualization control
31 class ShapeView_VisibilityState : public QObject, public TreeModel_VisibilityState
32 {
33   Q_OBJECT
34 public:
35   //! Constructor
36   ShapeView_VisibilityState (TreeModel_ModelBase* theModel) : TreeModel_VisibilityState (theModel),
37   myPresentationType (View_PresentationType_Main) {}
38
39   //! Destructor
40   ~ShapeView_VisibilityState() {}
41
42   //! Sets current displayer
43   //! \theDisplayer class that provides connection to visualized objects
44   void SetDisplayer (View_Displayer* theDisplayer) { myDisplayer = theDisplayer; }
45
46   //! Sets presentation type for displayer
47   //! \param theType type value
48   void SetPresentationType (const View_PresentationType theType) { myPresentationType = theType; }
49
50   //! Returns true if visibility of the item can be changed
51   //! \param theIndex tree model index
52   //! \return boolean value
53   virtual bool CanBeVisible (const QModelIndex& theIndex) const Standard_OVERRIDE { return !Shape (theIndex).IsNull(); }
54
55   //! Sets visibility state
56   //! \theIndex tree model index
57   //! \param theState visibility state
58   //! \param toEmitDataChanged boolean flag whether emit of the model should be done immediatelly
59   //! \return true if state is changed
60   Standard_EXPORT virtual bool SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged) Standard_OVERRIDE;
61
62   //! Returns visibility state value
63   virtual bool IsVisible (const QModelIndex& theIndex) const Standard_OVERRIDE
64   { return myDisplayer->IsVisible (Shape (theIndex), myPresentationType); }
65
66 public slots:
67   //! Processes the mouse clicked on the index.
68   //! It changes the item visibility if model allows to change it.
69   //! \theIndex tree model index
70   void OnClicked (const QModelIndex& theIndex);
71
72 signals:
73   //! Signal after OnClicked is performed
74   //! \theIndex tree model index
75   void itemClicked (const QModelIndex& theIndex);
76
77 protected:
78   //! Gets shape of the view model by the parameter index if it has a shape
79   //! \param theIndex tree model index
80   //! \return shape instance
81   TopoDS_Shape Shape (const QModelIndex& theIndex) const;
82
83 private:
84   View_Displayer* myDisplayer; //!< view displayer
85   View_PresentationType myPresentationType; //!< presentation type
86 };
87
88 #endif