Salome HOME
f361615dc062055a0814be9f86e2bbc1eb38e3e3
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Selection.cxx
1 #include "SUPERVGUI_Selection.h"
2 #include "SUPERVGUI.h"
3
4 #include <SalomeApp_DataOwner.h>
5 #include <SalomeApp_Study.h>
6
7 #include <SUIT_Session.h>
8 #include <SUIT_ViewWindow.h>
9 #include <SUIT_ViewManager.h>
10 #include <SUIT_ViewModel.h>
11
12 #include <SALOMEDSClient_SObject.hxx>
13 #include <SALOMEDSClient_Study.hxx>
14 #include <SALOMEDS_SObject.hxx>
15 #include <SALOME_Prs.h>
16 #include <SALOME_InteractiveObject.hxx>
17
18 #include <SOCC_Prs.h>
19
20 #include <OCCViewer_ViewModel.h>
21
22 SUPERVGUI_Selection::SUPERVGUI_Selection()
23 {
24 }
25
26 SUPERVGUI_Selection::~SUPERVGUI_Selection()
27 {
28 }
29
30 QtxValue SUPERVGUI_Selection::param( const int ind, const QString& p ) const
31 {
32   QtxValue val( SalomeApp_Selection::param( ind, p ) );
33   if ( !val.isValid() ) {
34     if ( p == "type" )  val = QtxValue( typeName( ind ) );
35   }
36
37   //printf( "--> param() : [%s] = %s\n", p.latin1(), val.toString ().latin1() );
38
39   return val;
40 }
41
42 QString SUPERVGUI_Selection::typeName( const int index ) const
43 {
44   if ( isComponent( index ) )
45     return "Component";
46   
47   _PTR(SObject) anIObj = getObject( index );
48   if ( anIObj ) {
49     bool aIsOwner, aIsDataflow;
50     SUPERVGUI::Supervision()->whatIsSelected(anIObj, aIsOwner, aIsDataflow);
51     if ( aIsDataflow ) //selected dataflow object
52       return "Dataflow";
53     if ( aIsOwner ) //selected object belongs to Supervisor
54       return "SupervisorObject";
55   }
56   return "Unknown";
57 }
58
59 bool SUPERVGUI_Selection::isComponent( const int index ) const
60 {
61   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
62     (SUIT_Session::session()->activeApplication()->activeStudy());
63
64   if ( appStudy && index >= 0 && index < count() )  {
65     _PTR(Study) study = appStudy->studyDS();
66     QString anEntry = entry( index );
67
68     if ( study && !anEntry.isNull() ) { 
69       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
70       if ( aSO && aSO->GetFatherComponent() ) 
71         return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
72     }
73   }
74   return false;
75 }
76
77 _PTR(SObject) SUPERVGUI_Selection::getObject( const int index ) const
78 {
79   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
80     (SUIT_Session::session()->activeApplication()->activeStudy());
81
82   if ( appStudy && index >= 0 && index < count() )  {
83     _PTR(Study) study = appStudy->studyDS();
84     QString anEntry = entry( index );
85
86     if ( study && !anEntry.isNull() ) { 
87       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
88       return aSO;
89     }
90   }
91   
92   _PTR(SObject) aObj1;
93   return aObj1;
94 }