Salome HOME
To provide a way to introduce new type of presentation
[modules/visu.git] / src / VISUGUI / VisuGUI_PopupTools.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2005  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VisuGUI_PopupTools.cxx
25 //  Author : Sergey Anikin 
26 //  Module : VISU
27
28 #include "VisuGUI_PopupTools.h"
29 #include "VisuGUI_Tools.h"
30
31 #include "VISU_Actor.h"
32
33 using namespace VISU;
34
35 //////////////////////////////////////////////////
36 // Class: VisuGUI_Selection
37 //////////////////////////////////////////////////
38
39 QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
40 {
41   QtxValue val( SalomeApp_Selection::param( ind, p ) );
42   if ( !val.isValid() ) {
43     if      ( p == "type"           ) val = QtxValue( type( ind ) );
44     else if ( p == "nbComponents"   ) val = QtxValue( nbComponents( ind ) );
45     else if ( p == "representation" ) val = QtxValue( representation( ind ) );
46     else if ( p == "nbTimeStamps"   ) val = QtxValue( nbTimeStamps( ind ) );
47     else if ( p == "nbChildren"     ) val = QtxValue( nbChildren( ind ) );
48     else if ( p == "nbNamedChildren") val = QtxValue( nbNamedChildren( ind ) );
49     else if ( p == "isVisible"      ) val = QtxValue( isVisible( ind ) );
50     else if ( p == "isShrunk"       ) val = QtxValue( isShrunk( ind ) );
51     else if ( p == "hasActor"       ) val = QtxValue( hasActor( ind ) );
52   }
53
54   return val;
55 }
56
57 // Macro for converting VISU enumeration items into corresponding strings
58 #define ENUM2STRING( x, y ) \
59   case y: \
60     x = QString( #y ); \
61     break;
62
63 QString VisuGUI_Selection::type( const int ind ) const
64 {
65   QString aResStr;
66   VISU::Storable::TRestoringMap aMap;
67   GetSelectedObj( study(), entry( ind ), &aMap );  
68   bool isExist;
69   const QString& aVal = VISU::Storable::FindValue(aMap,"myComment",&isExist);
70   if ( isExist )
71     aResStr = "VISU::T" + aVal;
72   return aResStr;
73 }
74
75 QString VisuGUI_Selection::nbComponents( const int ind ) const
76 {
77   QString aResStr;
78   VISU::Storable::TRestoringMap aMap;
79   GetSelectedObj( study(), entry( ind ), &aMap );  
80   bool isExist;
81   const QString& aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
82   if ( isExist )
83     aResStr = aVal;
84   return aResStr;
85 }
86
87 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
88 {
89   QString aResStr;
90   VISU::Storable::TRestoringMap aMap;
91   GetSelectedObj( study(), entry( ind ), &aMap );  
92   bool isExist;
93   const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
94   if ( isExist )
95     aResStr = aVal;
96   return aResStr;
97 }
98
99 QString VisuGUI_Selection::representation( const int ind ) const
100 {
101   QString aResStr;
102
103   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) ){
104     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) ){
105       int aRepresent = anVISUActor->GetRepresentation();
106       switch ( aRepresent ){
107         ENUM2STRING( aResStr, VISU::POINT )
108         ENUM2STRING( aResStr, VISU::WIREFRAME )
109         ENUM2STRING( aResStr, VISU::SHADED )
110         ENUM2STRING( aResStr, VISU::INSIDEFRAME )
111         ENUM2STRING( aResStr, VISU::SURFACEFRAME )
112       }
113     }
114   }
115
116   return aResStr;
117 }
118
119 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
120 {
121   int cnt = 0;
122   _PTR(Study) aStudy =  GetCStudy( study() );
123   if ( aStudy ){
124     _PTR(SObject) SO = aStudy->FindObjectID( entry( ind ).latin1() );
125     if ( SO ){
126       for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
127         _PTR(SObject) refSO;
128         if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
129           cnt++;
130       }
131     }
132   }
133   return cnt;
134 }
135
136 QString VisuGUI_Selection::nbChildren( const int ind ) const
137 {
138   QString aResStr;
139   aResStr.setNum( nbChild( ind, false ) );
140   return aResStr;
141 }
142
143 QString VisuGUI_Selection::nbNamedChildren( const int ind ) const
144 {
145   QString aResStr;
146   aResStr.setNum( nbChild( ind, true ) );
147   return aResStr;
148 }
149
150 QString VisuGUI_Selection::isVisible( const int ind ) const
151 {
152   QString aResStr;
153
154   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
155     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
156       aResStr = anVISUActor->GetVisibility() ? "1" : "0";
157
158   return aResStr;
159 }
160
161 QString VisuGUI_Selection::isShrunk( const int ind ) const
162 {
163   QString aResStr;
164
165   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
166     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
167       if ( anVISUActor->IsShrunkable() )
168         aResStr = anVISUActor->IsShrunk() ? "1" : "0";
169
170   return aResStr;
171 }
172
173 QString VisuGUI_Selection::hasActor( const int ind ) const
174 {
175   return representation( ind ).isEmpty() ? "0" : "1";
176 }