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