Salome HOME
IPAL9283,9286,9295,9296,9297; some icons restored
[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 aTypeStr;
66   VISU::Storable::TRestoringMap aMap;
67   CORBA::Object_var anObject = GetSelectedObj( study(), entry( ind ), &aMap );  
68
69   VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject );
70
71   if ( !CORBA::is_nil( aVisuObj ) ){
72     VISU::VISUType aType = aVisuObj->GetType();
73     switch (aType) {
74       ENUM2STRING( aTypeStr, VISU::TVISUGEN )
75       ENUM2STRING( aTypeStr, VISU::TRESULT )
76       ENUM2STRING( aTypeStr, VISU::TTABLE )
77       ENUM2STRING( aTypeStr, VISU::TCURVE )
78       ENUM2STRING( aTypeStr, VISU::TCONTAINER )
79       ENUM2STRING( aTypeStr, VISU::TMESH )
80       ENUM2STRING( aTypeStr, VISU::TSCALARMAP )
81       ENUM2STRING( aTypeStr, VISU::TISOSURFACE )
82       ENUM2STRING( aTypeStr, VISU::TDEFORMEDSHAPE )
83       ENUM2STRING( aTypeStr, VISU::TCUTPLANES )
84       ENUM2STRING( aTypeStr, VISU::TCUTLINES )
85       ENUM2STRING( aTypeStr, VISU::TVECTORS )
86       ENUM2STRING( aTypeStr, VISU::TSTREAMLINES )
87     }
88   }
89   else{
90     bool isExist;
91     VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue( aMap, "myType", &isExist).toInt();
92     if( isExist ){
93       switch (aType) {
94         ENUM2STRING( aTypeStr, VISU::TENTITY )
95         ENUM2STRING( aTypeStr, VISU::TFAMILY )
96         ENUM2STRING( aTypeStr, VISU::TGROUP )
97         ENUM2STRING( aTypeStr, VISU::TVIEW3D )
98         ENUM2STRING( aTypeStr, VISU::TFIELD )
99         ENUM2STRING( aTypeStr, VISU::TTIMESTAMP )
100       }
101     }
102   }
103
104   return aTypeStr;
105 }
106
107 QString VisuGUI_Selection::nbComponents( const int ind ) const
108 {
109   QString aResStr;
110   VISU::Storable::TRestoringMap aMap;
111   GetSelectedObj( study(), entry( ind ), &aMap );  
112   bool isExist;
113   const QString& aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
114   if ( isExist )
115     aResStr = aVal;
116   return aResStr;
117 }
118
119 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
120 {
121   QString aResStr;
122   VISU::Storable::TRestoringMap aMap;
123   GetSelectedObj( study(), entry( ind ), &aMap );  
124   bool isExist;
125   const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
126   if ( isExist )
127     aResStr = aVal;
128   return aResStr;
129 }
130
131 QString VisuGUI_Selection::representation( const int ind ) const
132 {
133   QString aResStr;
134
135   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) ){
136     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) ){
137       int aRepresent = anVISUActor->GetRepresentation();
138       switch ( aRepresent ){
139         ENUM2STRING( aResStr, VISU::POINT )
140         ENUM2STRING( aResStr, VISU::WIREFRAME )
141         ENUM2STRING( aResStr, VISU::SHADED )
142         ENUM2STRING( aResStr, VISU::INSIDEFRAME )
143         ENUM2STRING( aResStr, VISU::SURFACEFRAME )
144       }
145     }
146   }
147
148   return aResStr;
149 }
150
151 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
152 {
153   int cnt = 0;
154   _PTR(Study) aStudy =  GetCStudy( study() );
155   if ( aStudy ){
156     _PTR(SObject) SO = aStudy->FindObjectID( entry( ind ).latin1() );
157     if ( SO ){
158       for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
159         _PTR(SObject) refSO;
160         if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
161           cnt++;
162       }
163     }
164   }
165   return cnt;
166 }
167
168 QString VisuGUI_Selection::nbChildren( const int ind ) const
169 {
170   QString aResStr;
171   aResStr.setNum( nbChild( ind, false ) );
172   return aResStr;
173 }
174
175 QString VisuGUI_Selection::nbNamedChildren( const int ind ) const
176 {
177   QString aResStr;
178   aResStr.setNum( nbChild( ind, true ) );
179   return aResStr;
180 }
181
182 QString VisuGUI_Selection::isVisible( const int ind ) const
183 {
184   QString aResStr;
185
186   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
187     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
188       aResStr = anVISUActor->GetVisibility() ? "1" : "0";
189
190   return aResStr;
191 }
192
193 QString VisuGUI_Selection::isShrunk( const int ind ) const
194 {
195   QString aResStr;
196
197   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
198     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
199       if ( anVISUActor->IsShrunkable() )
200         aResStr = anVISUActor->IsShrunk() ? "1" : "0";
201
202   return aResStr;
203 }
204
205 QString VisuGUI_Selection::hasActor( const int ind ) const
206 {
207   return representation( ind ).isEmpty() ? "0" : "1";
208 }