Salome HOME
Copyright update 2021
[samples/atomic.git] / src / ATOMICGUI / ATOMICGUI_Selection.cxx
1 // Copyright (C) 2007-2021  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 #include "ATOMICGUI_Selection.h"
21 #include "LightApp_DataOwner.h"
22
23 #include <LightApp_SelectionMgr.h>
24 #include <qstringlist.h>
25
26 /*! Constructor */
27 ATOMICGUI_Selection::ATOMICGUI_Selection ()
28 : LightApp_Selection()
29 {
30 }
31
32 /*! Destructor */
33 ATOMICGUI_Selection::~ATOMICGUI_Selection()
34 {
35 }
36
37 /*! Initialization of Selection */
38 void ATOMICGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
39 {
40   if ( mgr ) {
41     SUIT_DataOwnerPtrList sel;
42     mgr->selected( sel);
43     SUIT_DataOwnerPtrList::const_iterator anIt  = sel.begin(),
44                                           aLast = sel.end();
45     for ( ; anIt != aLast; anIt++ ) {
46       QString type = "Unknown";
47       SUIT_DataOwner* owner = (SUIT_DataOwner*)( (*anIt).get() );
48       LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>( owner );
49       QStringList es = sowner->entry().split( "_" );
50       if ( es.count() > 0 && es[ 0 ] == "ATOMICGUI" ) {
51         if ( es.count() > 1 ) {
52           if( es[ 1 ] == "root" )
53             type = "Root";
54           else
55             type = "Molecule";
56           if ( es.count() > 2 )
57             type = "Atom";
58         }
59       }
60       myTypes.append( type );
61     }
62   }
63   LightApp_Selection::init( client, mgr );
64 }
65
66 /*! Returns number of objects of supported types. */
67 int ATOMICGUI_Selection::count() const
68 {
69   return myTypes.count();
70 }
71
72 /*! Returns selection parameter value. */
73 QVariant ATOMICGUI_Selection::parameter( const int ind, const QString& p ) const
74 {
75   if ( p == "type" )
76     return myTypes[ ind ];
77   return LightApp_Selection::parameter( ind, p );
78 }