Salome HOME
Migration to OCCT 7.0
[modules/gui.git] / src / LightApp / LightApp_SelectionMgr.h
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef LIGHTAPP_SELECTIONMGR_H
24 #define LIGHTAPP_SELECTIONMGR_H
25
26 #include "LightApp.h"
27
28 #include <SUIT_SelectionMgr.h>
29
30 #include <QtCore/QTime>
31
32 #ifndef DISABLE_SALOMEOBJECT
33   #include <SALOME_InteractiveObject.hxx>
34   #include <QMap>
35   #include <NCollection_DataMap.hxx>
36
37   #include <TColStd_IndexedMapOfInteger.hxx>
38   #include <TColStd_MapOfInteger.hxx>
39
40   class SALOME_ListIO;
41   class TCollection_AsciiString;
42 #else
43 #include <QStringList>
44 #endif
45
46 class LightApp_Application;
47
48 /*!
49   Custom selection manager, allowing to work with object selection
50   (additionally to data owners) and to access to sub-selection of objects
51 */
52 class LIGHTAPP_EXPORT LightApp_SelectionMgr : public SUIT_SelectionMgr
53 {
54   Q_OBJECT
55
56 public:
57   LightApp_SelectionMgr( LightApp_Application*, const bool = true );
58   virtual ~LightApp_SelectionMgr();
59
60   LightApp_Application* application() const;
61
62   virtual void           setSelected( const SUIT_DataOwnerPtrList&, const bool = false );
63
64 #ifndef DISABLE_SALOMEOBJECT
65   typedef NCollection_DataMap< Handle(SALOME_InteractiveObject), TColStd_IndexedMapOfInteger > MapIOOfMapOfInteger;
66   typedef NCollection_DataMap< TCollection_AsciiString, TColStd_IndexedMapOfInteger > MapEntryOfMapOfInteger;
67
68   void                   selectedObjects( SALOME_ListIO&, const QString& = QString(), const bool = true ) const;
69   void                   setSelectedObjects( const SALOME_ListIO&, const bool = false );
70
71   void                   GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, 
72                                      TColStd_IndexedMapOfInteger& theIndex );
73   void                   GetIndexes( const QString& theEntry, 
74                                      TColStd_IndexedMapOfInteger& theIndex );
75
76   //bool                   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, 
77   void                   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, 
78                                            const TColStd_MapOfInteger& theIndices, 
79                                            bool modeShift );
80
81   void                   selectObjects( const Handle(SALOME_InteractiveObject)& IObject, 
82                                         TColStd_IndexedMapOfInteger theIndex, bool append );
83   void                   selectObjects( MapIOOfMapOfInteger theMapIO, bool append );
84
85   void                   selectedSubOwners( MapEntryOfMapOfInteger& theMap );
86 #else
87   void                   selectedObjects( QStringList&, const QString& = QString(), const bool = true ) const;
88   void                   setSelectedObjects( const QStringList&, const bool = false );
89 #endif
90
91   void                   clearSelectionCache();
92   bool                   isSelectionCacheEnabled() const;
93   void                   setSelectionCacheEnabled( bool );
94
95 signals:
96   void                   currentSelectionChanged();
97
98 private:
99   virtual void           selectionChanged( SUIT_Selector* );
100
101 #ifndef DISABLE_SALOMEOBJECT
102   QList<Handle_SALOME_InteractiveObject> selectionCache( const QString& = QString() ) const;
103 #else
104   QStringList                            selectionCache( const QString& = QString() ) const;
105 #endif
106   bool                   isActualSelectionCache( const QString& = QString() ) const;
107
108   QStringList            selectorTypes() const;
109
110 private:
111 #ifndef DISABLE_SALOMEOBJECT
112   typedef Handle_SALOME_InteractiveObject SelObject;
113 #else
114   typedef QString                         SelObject;
115 #endif
116   typedef QList<SelObject>             SelList;
117   typedef QMap<QString, QTime>         TimeMap;
118   typedef QMap<QString, SelList>       CacheMap;
119
120 private:
121   LightApp_Application* myApp;
122
123   QTime                 myTimeStamp;
124
125   bool                  myCacheState;
126   TimeMap               myCacheTimes;
127   CacheMap              myCacheSelection;
128 };
129
130 #endif