Salome HOME
Fix for bug PAL9160 ( No shading on visualizations ).
[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 #include "VISU_ScalarMapAct.h"
33
34 using namespace VISU;
35
36 //////////////////////////////////////////////////
37 // Class: VisuGUI_Selection
38 //////////////////////////////////////////////////
39
40 QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
41 {
42   QtxValue val( SalomeApp_Selection::param( ind, p ) );
43   if ( !val.isValid() ) {
44     if      ( p == "type"           ) val = QtxValue( type( ind ) );
45     else if ( p == "nbComponents"   ) val = QtxValue( nbComponents( ind ) );
46     else if ( p == "representation" ) val = QtxValue( representation( ind ) );
47     else if ( p == "nbTimeStamps"   ) val = QtxValue( nbTimeStamps( ind ) );
48     else if ( p == "nbChildren"     ) val = QtxValue( nbChildren( ind ) );
49     else if ( p == "nbNamedChildren") val = QtxValue( nbNamedChildren( ind ) );
50 //    else if ( p == "isVisible"      ) val = QtxValue( isVisible( ind ) );
51     else if ( p == "isShrunk"       ) val = QtxValue( isShrunk( ind ) );
52     else if ( p == "hasActor"       ) val = QtxValue( hasActor( ind ) );
53     else if ( p == "isShading"      ) val = QtxValue( isShading( ind ) );
54     else if ( p == "isScalarMapAct" ) val = QtxValue( isScalarMapAct( ind ) );
55   }
56
57   return val;
58 }
59
60 // Macro for converting VISU enumeration items into corresponding strings
61 #define ENUM2STRING( x, y ) \
62   case y: \
63     x = QString( #y ); \
64     break
65
66 QString VisuGUI_Selection::type( const int ind ) const
67 {
68   QString aResStr;
69   VISU::Storable::TRestoringMap aMap;
70   CORBA::Object_var anObject = GetSelectedObj( study(), entry( ind ), &aMap );  
71
72   VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject );
73   if ( !CORBA::is_nil( aVisuObj ) ){
74     VISU::VISUType aType = aVisuObj->GetType();
75     switch (aType) {
76       ENUM2STRING( aResStr, VISU::TVISUGEN );
77       ENUM2STRING( aResStr, VISU::TRESULT );
78       ENUM2STRING( aResStr, VISU::TTABLE );
79       ENUM2STRING( aResStr, VISU::TCURVE );
80       ENUM2STRING( aResStr, VISU::TCONTAINER );
81       ENUM2STRING( aResStr, VISU::TMESH );
82       ENUM2STRING( aResStr, VISU::TSCALARMAP );
83       ENUM2STRING( aResStr, VISU::TISOSURFACE );
84       ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
85       ENUM2STRING( aResStr, VISU::TCUTPLANES );
86       ENUM2STRING( aResStr, VISU::TCUTLINES );
87       ENUM2STRING( aResStr, VISU::TVECTORS );
88       ENUM2STRING( aResStr, VISU::TSTREAMLINES );
89       ENUM2STRING( aResStr, VISU::TPLOT3D );
90       ENUM2STRING( aResStr, VISU::TANIMATION );
91     }
92   }
93
94   if(aResStr.isNull()){
95     bool isExist;
96     VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue( aMap, "myType", &isExist).toInt();
97     if( isExist ){
98       switch (aType) {
99         ENUM2STRING( aResStr, VISU::TENTITY );
100         ENUM2STRING( aResStr, VISU::TFAMILY );
101         ENUM2STRING( aResStr, VISU::TGROUP );
102         ENUM2STRING( aResStr, VISU::TVIEW3D );
103         ENUM2STRING( aResStr, VISU::TFIELD );
104         ENUM2STRING( aResStr, VISU::TTIMESTAMP );
105       }
106     }
107   }
108
109   if(aResStr.isNull()){
110     bool isExist;
111     QString aVal = VISU::Storable::FindValue(aMap,"myComment",&isExist);
112     if ( isExist && aVal!="MESH" )
113       aResStr = "VISU::T" + aVal;
114   }
115
116   return aResStr;
117 }
118
119 QString VisuGUI_Selection::nbComponents( 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,"myNumComponent",&isExist);
126   if ( isExist )
127     aResStr = aVal;
128   return aResStr;
129 }
130
131 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
132 {
133   QString aResStr;
134   VISU::Storable::TRestoringMap aMap;
135   GetSelectedObj( study(), entry( ind ), &aMap );  
136   bool isExist;
137   const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
138   if ( isExist )
139     aResStr = aVal;
140   return aResStr;
141 }
142
143 QString VisuGUI_Selection::representation( const int ind ) const
144 {
145   QString aResStr;
146
147   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) ){
148     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) ){
149       int aRepresent = anVISUActor->GetRepresentation();
150       switch ( aRepresent ){
151         ENUM2STRING( aResStr, VISU::POINT );
152         ENUM2STRING( aResStr, VISU::WIREFRAME );
153         ENUM2STRING( aResStr, VISU::SHADED );
154         ENUM2STRING( aResStr, VISU::INSIDEFRAME );
155         ENUM2STRING( aResStr, VISU::SURFACEFRAME );
156       }
157     }
158   }
159
160   return aResStr;
161 }
162
163 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
164 {
165   int cnt = 0;
166   _PTR(Study) aStudy =  GetCStudy( study() );
167   if ( aStudy ){
168     _PTR(SObject) SO = aStudy->FindObjectID( entry( ind ).latin1() );
169     if ( SO ){
170       for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
171         _PTR(SObject) refSO;
172         if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
173           cnt++;
174       }
175     }
176   }
177   return cnt;
178 }
179
180 QString VisuGUI_Selection::nbChildren( const int ind ) const
181 {
182   QString aResStr;
183   aResStr.setNum( nbChild( ind, false ) );
184   return aResStr;
185 }
186
187 QString VisuGUI_Selection::nbNamedChildren( const int ind ) const
188 {
189   QString aResStr;
190   aResStr.setNum( nbChild( ind, true ) );
191   return aResStr;
192 }
193
194 QString VisuGUI_Selection::isVisible( const int ind ) const
195 {
196   QString aResStr;
197
198   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
199     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
200       aResStr = anVISUActor->GetVisibility() ? "1" : "0";
201
202   return aResStr;
203 }
204
205 QString VisuGUI_Selection::isShrunk( const int ind ) const
206 {
207   QString aResStr;
208
209   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
210     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
211       if ( anVISUActor->IsShrunkable() )
212         aResStr = anVISUActor->IsShrunk() ? "1" : "0";
213
214   return aResStr;
215 }
216
217 QString VisuGUI_Selection::hasActor( const int ind ) const
218 {
219   return representation( ind ).isEmpty() ? "0" : "1";
220 }
221
222 QString VisuGUI_Selection::isShading( const int ind ) const
223 {
224   QString aResStr;
225   
226   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
227     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
228       if ( VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor) )
229         aResStr = anActor->IsShading() ? "1" : "0";
230   
231   return aResStr;       
232 }
233
234 QString VisuGUI_Selection::isScalarMapAct( const int ind ) const
235 {
236   QString aResStr;
237
238   if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
239     if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
240       {
241         VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor);
242         aResStr = anActor ? "1" : "0";
243       }
244   
245   return aResStr;
246 }