Salome HOME
daea55bf3239416421942a60f2698bfd153b1714
[modules/gui.git] / src / LightApp / LightApp_SelectionMgr.h
1 // Copyright (C) 2007-2014  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   class SALOME_ListIO;
38   class TColStd_IndexedMapOfInteger;
39   class TColStd_MapOfInteger;
40   class TCollection_AsciiString;
41 #else
42 #include <QStringList>
43 #endif
44
45 class LightApp_Application;
46
47 /*!
48   Custom selection manager, allowing to work with object selection
49   (additionally to data owners) and to access to sub-selection of objects
50 */
51 class LIGHTAPP_EXPORT LightApp_SelectionMgr : public SUIT_SelectionMgr
52 {
53   Q_OBJECT
54
55 public:
56   LightApp_SelectionMgr( LightApp_Application*, const bool = true );
57   virtual ~LightApp_SelectionMgr();
58
59   LightApp_Application* application() const;
60
61   virtual void           setSelected( const SUIT_DataOwnerPtrList&, const bool = false );
62
63 #ifndef DISABLE_SALOMEOBJECT
64   typedef NCollection_DataMap< Handle(SALOME_InteractiveObject), TColStd_IndexedMapOfInteger > MapIOOfMapOfInteger;
65   typedef NCollection_DataMap< TCollection_AsciiString, TColStd_IndexedMapOfInteger > MapEntryOfMapOfInteger;
66
67   void                   selectedObjects( SALOME_ListIO&, const QString& = QString(), const bool = true ) const;
68   void                   setSelectedObjects( const SALOME_ListIO&, const bool = false );
69
70   void                   GetIndexes( const Handle(SALOME_InteractiveObject)& IObject, 
71                                      TColStd_IndexedMapOfInteger& theIndex );
72   void                   GetIndexes( const QString& theEntry, 
73                                      TColStd_IndexedMapOfInteger& theIndex );
74
75   //bool                   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, 
76   void                   AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject, 
77                                            const TColStd_MapOfInteger& theIndices, 
78                                            bool modeShift );
79
80   void                   selectObjects( const Handle(SALOME_InteractiveObject)& IObject, 
81                                         TColStd_IndexedMapOfInteger theIndex, bool append );
82   void                   selectObjects( MapIOOfMapOfInteger theMapIO, bool append );
83
84   void                   selectedSubOwners( MapEntryOfMapOfInteger& theMap );
85 #else
86   void                   selectedObjects( QStringList&, const QString& = QString(), const bool = true ) const;
87 #endif
88
89   void                   clearSelectionCache();
90   bool                   isSelectionCacheEnabled() const;
91   void                   setSelectionCacheEnabled( bool );
92
93 signals:
94   void                   currentSelectionChanged();
95
96 private:
97   virtual void           selectionChanged( SUIT_Selector* );
98
99 #ifndef DISABLE_SALOMEOBJECT
100   QList<Handle_SALOME_InteractiveObject> selectionCache( const QString& = QString() ) const;
101 #else
102   QStringList                            selectionCache( const QString& = QString() ) const;
103 #endif
104   bool                   isActualSelectionCache( const QString& = QString() ) const;
105
106   QStringList            selectorTypes() const;
107
108 private:
109 #ifndef DISABLE_SALOMEOBJECT
110   typedef Handle_SALOME_InteractiveObject SelObject;
111 #else
112   typedef QString                         SelObject;
113 #endif
114   typedef QList<SelObject>             SelList;
115   typedef QMap<QString, QTime>         TimeMap;
116   typedef QMap<QString, SelList>       CacheMap;
117
118 private:
119   LightApp_Application* myApp;
120
121   QTime                 myTimeStamp;
122
123   bool                  myCacheState;
124   TimeMap               myCacheTimes;
125   CacheMap              myCacheSelection;
126 };
127
128 #endif