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