]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOMGUI_TextTreeWdg.h
Salome HOME
Prepare OCCT version 7.1.0+ for SALOME-8.2.0
[modules/geom.git] / src / GEOMGUI / GEOMGUI_TextTreeWdg.h
1 // Copyright (C) 2015-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef GEOMGUI_TEXTTREEWDG_H
21 #define GEOMGUI_TEXTTREEWDG_H
22
23 #include "GEOM_GEOMGUI.hxx"
24 #include "GEOM_Displayer.h"
25
26 #include <QHash>
27 #include <QMap>
28 #include <QList>
29 #include <QSharedPointer>
30 #include <QTreeWidget>
31
32 #include <SALOMEDSClient.hxx>
33
34 class QLabel;
35 class QLineEdit;
36 class QString;
37 class QTreeWidgetItem;
38 class SalomeApp_Application;
39 class SalomeApp_Study;
40
41 /*!
42  * \brief Tree view contains Dimension and Annotation text items:
43  *  - text visibility in OCC viewer
44  *  - text object name
45  */
46 class GEOMGUI_EXPORT GEOMGUI_TextTreeWdg : public QTreeWidget
47 {
48   Q_OBJECT
49
50 public:
51   enum BranchType { DimensionShape, AnnotationShape };
52
53 public:
54   GEOMGUI_TextTreeWdg( SalomeApp_Application* app );
55   ~GEOMGUI_TextTreeWdg();
56
57   int getWinID() { return myWindowID; }
58
59   void                          removeBranch( const BranchType& theBranchType, const QString& theEntry,
60                                               bool force = true );
61   int                           idFromItem( QTreeWidgetItem* theItem );
62   QString                       entryFromItem( QTreeWidgetItem* theShapeItem ) const;
63   QTreeWidgetItem*              itemFromEntry( const BranchType& theBranchType, QString theEntry );
64   void                          setAllShapeItemsVisibility( const BranchType& theBranchType,
65                                                             const QString& theEntry,
66                                                             const bool theVisibility );
67   void                          setShapeItemVisibility( const BranchType& theBranchType,
68                                                         const QString& theEntry,
69                                                         QTreeWidgetItem* theWidgetItem,
70                                                         const bool theVisibility );
71   void                          updateVisibility();
72
73   void                          getSelected( QMap<QString, QList<int> >& theAnnotations );
74   void                          setSelected( const QMap<QString, QList<int> >& theAnnotations );
75
76   QList<QString>                getAllEntries( const BranchType& theBranchType );
77
78   QString                       getSingleSelectedObject();
79
80 protected:
81   void                          createActions();
82   void                          redisplay( QString theEntry );
83
84 public slots:
85   void                          updateTree();
86   void                          updateBranches( const QString& theEntry );
87   void                          updateDimensionBranch( const QString& theEntry );
88   void                          updateAnnotationBranch( const QString& theEntry );
89   void                          updateObjectName( const QString& theEntry );
90
91 private slots:
92   void                          onUpdateVisibilityColumn( QString theEntry, Qtx::VisibilityState theState );
93   void                          onItemClicked(QTreeWidgetItem*, int );
94   void                          setVisibility( QTreeWidgetItem* theItem, bool visibility );
95   void                          showContextMenu( const QPoint& pos );
96
97 public:
98
99   /*!
100    * \brief Common interface for working with shape dimension and annotation properties
101    *        of object in a unified way irrespectively of the implementation.
102    */ 
103   class VisualProperty
104   {
105   public:
106     virtual int GetNumber() = 0;
107     virtual QString GetName( const int theIndex ) = 0;
108     virtual bool GetIsVisible( const int theIndex ) = 0;
109     virtual void SetIsVisible( const int theIndex, const bool theIsVisible ) = 0;
110     virtual void Save() = 0;
111   };
112
113 private:
114   bool                              setShapeItemVisibility( QSharedPointer<VisualProperty>& theProps,
115                                                             QTreeWidgetItem* theWidgetItem,
116                                                             const bool theVisibility );
117   QSharedPointer<VisualProperty>    getVisualProperty( const BranchType& theBranchType,
118                                                        SalomeApp_Study* theStudy,
119                                                        const std::string& theEntry );
120   void                              fillBranch( const BranchType& theBranchType,
121                                                 const QString& theEntry );
122   void                              updateVisibilityColumn( const BranchType& theBranchType,
123                                                             QString theEntry,
124                                                             Qtx::VisibilityState theState );
125   QTreeWidgetItem*                  getPropertyRootItem( const BranchType& theBranchType );
126   QHash<QString, QTreeWidgetItem*>& getObjects( const BranchType& theBranchType );
127   BranchType                        branchTypeFromItem( QTreeWidgetItem* theItem );
128
129 private:
130
131   int                              myWindowID;
132   QIcon                            myVisibleIcon;
133   QIcon                            myInvisibleIcon;
134   QHash<QString, QTreeWidgetItem*> myDimensionObjects;
135   QHash<QString, QTreeWidgetItem*> myAnnotationObjects;
136   SalomeApp_Study*                 myStudy;
137   QTreeWidgetItem*                 myDimensionsItem;
138   QTreeWidgetItem*                 myAnnotationsItem;
139   GEOM_Displayer                   myDisplayer;
140   QMap<int, QAction*>              myActions; //!< menu actions list
141 };
142
143 #endif