Salome HOME
9e42c193bb0937370fad680294b5da49c4984e68
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Selection.cxx
1 // Copyright (C) 2005  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/
19 //
20 #include "SUPERVGUI_Selection.h"
21 #include "SUPERVGUI.h"
22
23 #include <LightApp_DataOwner.h>
24 #include <SalomeApp_Study.h>
25
26 #include <SUIT_Session.h>
27 #include <SUIT_ViewWindow.h>
28 #include <SUIT_ViewManager.h>
29 #include <SUIT_ViewModel.h>
30
31 #include <SALOMEDSClient_SObject.hxx>
32 #include <SALOMEDSClient_Study.hxx>
33 #include <SALOMEDS_SObject.hxx>
34 #include <SALOME_Prs.h>
35 #include <SALOME_InteractiveObject.hxx>
36
37 #include <SOCC_Prs.h>
38
39 #include <OCCViewer_ViewModel.h>
40
41 SUPERVGUI_Selection::SUPERVGUI_Selection()
42 {
43 }
44
45 SUPERVGUI_Selection::~SUPERVGUI_Selection()
46 {
47 }
48
49 QtxValue SUPERVGUI_Selection::param( const int ind, const QString& p ) const
50 {
51   QtxValue val( LightApp_Selection::param( ind, p ) );
52   if ( !val.isValid() ) {
53     if ( p == "type" )  val = QtxValue( typeName( ind ) );
54   }
55
56   //printf( "--> param() : [%s] = %s\n", p.latin1(), val.toString ().latin1() );
57
58   return val;
59 }
60
61 QString SUPERVGUI_Selection::typeName( const int index ) const
62 {
63   if ( isComponent( index ) )
64     return "Component";
65   
66   _PTR(SObject) anIObj = getObject( index );
67   if ( anIObj ) {
68     bool aIsOwner, aIsDataflow;
69     SUPERVGUI::Supervision()->whatIsSelected(anIObj, aIsOwner, aIsDataflow);
70     if ( aIsDataflow ) //selected dataflow object
71       return "Dataflow";
72     if ( aIsOwner ) //selected object belongs to Supervisor
73       return "SupervisorObject";
74   }
75   return "Unknown";
76 }
77
78 bool SUPERVGUI_Selection::isComponent( const int index ) const
79 {
80   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
81     (SUIT_Session::session()->activeApplication()->activeStudy());
82
83   if ( appStudy && index >= 0 && index < count() )  {
84     _PTR(Study) study = appStudy->studyDS();
85     QString anEntry = entry( index );
86
87     if ( study && !anEntry.isNull() ) { 
88       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
89       if ( aSO && aSO->GetFatherComponent() ) 
90         return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
91     }
92   }
93   return false;
94 }
95
96 _PTR(SObject) SUPERVGUI_Selection::getObject( const int index ) const
97 {
98   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
99     (SUIT_Session::session()->activeApplication()->activeStudy());
100
101   if ( appStudy && index >= 0 && index < count() )  {
102     _PTR(Study) study = appStudy->studyDS();
103     QString anEntry = entry( index );
104
105     if ( study && !anEntry.isNull() ) { 
106       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
107       return aSO;
108     }
109   }
110   
111   _PTR(SObject) aObj1;
112   return aObj1;
113 }