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