Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / gui / YACSGui_Selection.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 //  File   : YACSGui_Selection.cxx
22 //  Author : Alexander BORODIN
23 //  Module : YACS
24
25
26 #include <YACSGui_Selection.h>
27 #include <YACSGui_Module.h>
28 #include <YACSGui_DataModel.h>
29
30 #include <LightApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32 #include <SalomeApp_Study.h>
33 #include <SALOME_ListIO.hxx>
34
35 //#define _DEVDEBUG_
36 #include "YacsTrace.hxx"
37
38 //!Constructor.
39 /*!
40  */
41
42 YACSGui_Selection::YACSGui_Selection ()
43   :LightApp_Selection()
44 {  
45 }
46
47 //!Destructor
48 /*!
49  */
50 YACSGui_Selection::~YACSGui_Selection ()
51 {  
52 }
53
54 //!redefined method param
55 /*!
56  */
57 QtxValue YACSGui_Selection::param( const int k, const QString& name) const
58 {
59   DEBTRACE("YACSGui_Selection::param  name = " << name.latin1());
60   QtxValue v;
61
62   if ( name == "ObjectType" )
63   {
64     DEBTRACE("ObjectType= " <<  myCurrentObjectType.latin1());
65     v = myCurrentObjectType;
66     return v;
67   }  
68   
69   return LightApp_Selection::param( k, name );
70 }
71
72 //!detection of type of current selected object
73 /*!
74  */
75 void YACSGui_Selection::init( const QString& client, LightApp_SelectionMgr* mgr)
76 {
77   LightApp_Selection::init(client, mgr);
78
79   myCurrentObjectType = "";
80
81   YACSGui_Module* module = dynamic_cast<YACSGui_Module*>( mgr->application()->activeModule() );
82   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( mgr->application()->activeStudy() );
83   if ( study && module )
84   {
85     _PTR(Study) studyDS = study->studyDS();
86     if ( studyDS )
87     {
88       SALOME_ListIO selObjects;
89       mgr->selectedObjects( selObjects, false );
90
91       //consider only single selection
92       if ( selObjects.Extent() == 1 )
93       {
94         Handle(SALOME_InteractiveObject) io = selObjects.First();
95         YACSGui_DataModel::ObjectType type = ((YACSGui_DataModel*)module->dataModel())->objectType( io->getEntry() );
96         myCurrentObjectType = YACSGui_DataModel::Type2Str( type );
97       }
98     }
99   }
100 }