1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_PopupTools.cxx
25 // Author : Sergey Anikin
28 #include "VisuGUI_PopupTools.h"
29 #include "VisuGUI_ViewTools.h"
30 #include "VisuGUI_Tools.h"
31 #include "SalomeApp_Study.h"
32 #include "LightApp_Study.h"
34 #include "VISU_Actor.h"
35 #include "VISU_ScalarMapAct.h"
36 #include "VISU_Result_i.hh"
37 #include "SalomeApp_Study.h"
41 //////////////////////////////////////////////////
42 // Class: VisuGUI_Selection
43 //////////////////////////////////////////////////
45 QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
47 QtxValue val( LightApp_Selection::param( ind, p ) );
48 if ( !val.isValid() ) {
49 if ( p == "type" ) val = QtxValue( type( ind ) );
50 else if ( p == "nbComponents" ) val = QtxValue( nbComponents( ind ) );
51 else if ( p == "medEntity" ) val = QtxValue( medEntity( ind ) );
52 else if ( p == "medSource" ) val = QtxValue( medSource( ind ) );
53 else if ( p == "representation" ) val = QtxValue( representation( ind ) );
54 else if ( p == "nbTimeStamps" ) val = QtxValue( nbTimeStamps( ind ) );
55 else if ( p == "nbChildren" ) val = QtxValue( nbChildren( ind ) );
56 else if ( p == "nbNamedChildren") val = QtxValue( nbNamedChildren( ind ) );
57 else if ( p == "isVisible" ) val = QtxValue( isVisible( ind ) );
58 else if ( p == "isShrunk" ) val = QtxValue( isShrunk( ind ) );
59 else if ( p == "hasActor" ) val = QtxValue( hasActor( ind ) );
60 else if ( p == "isShading" ) val = QtxValue( isShading( ind ) );
61 else if ( p == "isScalarMapAct" ) val = QtxValue( isScalarMapAct( ind ) );
67 // Macro for converting VISU enumeration items into corresponding strings
68 #define ENUM2STRING( x, y ) \
73 QString VisuGUI_Selection::type( const int ind ) const
76 VISU::Storable::TRestoringMap aMap;
77 SalomeApp_Study* aStudy = GetStudy();
80 CORBA::Object_var anObject = GetSelectedObj( aStudy, entry( ind ), &aMap );
82 VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject );
83 if ( !CORBA::is_nil( aVisuObj ) ){
84 VISU::VISUType aType = aVisuObj->GetType();
86 ENUM2STRING( aResStr, VISU::TVISUGEN );
87 ENUM2STRING( aResStr, VISU::TRESULT );
88 ENUM2STRING( aResStr, VISU::TTABLE );
89 ENUM2STRING( aResStr, VISU::TCURVE );
90 ENUM2STRING( aResStr, VISU::TCONTAINER );
91 ENUM2STRING( aResStr, VISU::TMESH );
92 ENUM2STRING( aResStr, VISU::TSCALARMAP );
93 ENUM2STRING( aResStr, VISU::TISOSURFACE );
94 ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
95 ENUM2STRING( aResStr, VISU::TSCALARMAPONDEFORMEDSHAPE );
96 ENUM2STRING( aResStr, VISU::TCUTPLANES );
97 ENUM2STRING( aResStr, VISU::TCUTLINES );
98 ENUM2STRING( aResStr, VISU::TVECTORS );
99 ENUM2STRING( aResStr, VISU::TSTREAMLINES );
100 ENUM2STRING( aResStr, VISU::TPLOT3D );
101 ENUM2STRING( aResStr, VISU::TANIMATION );
105 if(aResStr.isNull()){
107 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue( aMap, "myType", &isExist).toInt();
110 ENUM2STRING( aResStr, VISU::TENTITY );
111 ENUM2STRING( aResStr, VISU::TFAMILY );
112 ENUM2STRING( aResStr, VISU::TGROUP );
113 ENUM2STRING( aResStr, VISU::TVIEW3D );
114 ENUM2STRING( aResStr, VISU::TFIELD );
115 ENUM2STRING( aResStr, VISU::TTIMESTAMP );
120 if(aResStr.isNull()){
122 QString aVal = VISU::Storable::FindValue(aMap,"myComment",&isExist);
123 if ( isExist && aVal!="MESH" )
124 aResStr = "VISU::T" + aVal;
130 QString VisuGUI_Selection::nbComponents( const int ind ) const
133 VISU::Storable::TRestoringMap aMap;
134 SalomeApp_Study* aStudy = GetStudy();
137 GetSelectedObj( aStudy, entry( ind ), &aMap );
139 const QString& aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
145 QString VisuGUI_Selection::medEntity( const int ind ) const
148 VISU::Storable::TRestoringMap aMap;
149 GetSelectedObj( GetStudy(), entry( ind ), &aMap );
150 const QString& aVal = VISU::Storable::FindValue(aMap,"myEntityId",&isExist);
152 using namespace VISU;
153 TEntity anEntityId = TEntity(aVal.toInt());
156 return "NODE_ENTITY";
158 return "EDGE_ENTITY";
160 return "FACE_ENTITY";
162 return "CELL_ENTITY";
170 QString VisuGUI_Selection::medSource( const int ind ) const
172 _PTR(Study) aStudyDS = GetStudy()->studyDS();
173 if(_PTR(SObject) aSObject = aStudyDS->FindObjectID(entry(ind))){
174 VISU::Result_var aRes;
175 if(VISU::Result_i* aResult = CheckResult(myModule,aSObject,aRes)){
176 using namespace VISU;
177 Result_i::ECreationId aCreationId = aResult->GetCreationId();
179 case Result_i::eImportFile :
180 return "eImportFile";
181 case Result_i::eCopyAndImportFile :
182 return "eCopyAndImportFile";
183 case Result_i::eImportMed :
185 case Result_i::eImportMedField :
186 return "eImportMedField";
195 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
198 VISU::Storable::TRestoringMap aMap;
199 SalomeApp_Study* aStudy = GetStudy();
202 GetSelectedObj( aStudy, entry( ind ), &aMap );
204 const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
210 QString VisuGUI_Selection::representation( const int ind ) const
214 if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) ){
215 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) ){
216 int aRepresent = anVISUActor->GetRepresentation();
217 switch ( aRepresent ){
218 ENUM2STRING( aResStr, VISU::POINT );
219 ENUM2STRING( aResStr, VISU::WIREFRAME );
220 ENUM2STRING( aResStr, VISU::SHADED );
221 ENUM2STRING( aResStr, VISU::INSIDEFRAME );
222 ENUM2STRING( aResStr, VISU::SURFACEFRAME );
230 SalomeApp_Study* VisuGUI_Selection::GetStudy() const
233 LightApp_Study* aLightStudy = const_cast<LightApp_Study*>( study() );
234 return dynamic_cast<SalomeApp_Study*>( aLightStudy );
237 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
240 SalomeApp_Study* aSStudy = GetStudy();
243 _PTR(Study) aStudy = GetCStudy( aSStudy );
245 _PTR(SObject) SO = aStudy->FindObjectID( entry( ind ).latin1() );
247 for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
249 if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
257 QString VisuGUI_Selection::nbChildren( const int ind ) const
260 aResStr.setNum( nbChild( ind, false ) );
264 QString VisuGUI_Selection::nbNamedChildren( const int ind ) const
267 aResStr.setNum( nbChild( ind, true ) );
273 struct TIsVisibleFunctor
275 template<class TViewer>
277 Get(VisuGUI* theModule,
278 const QString& theEntry)
280 typedef typename TViewer::TViewWindow TViewWindow;
281 if(TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule))
282 if(VISU_Actor* anActor = FindActor(aViewWindow,theEntry.latin1()))
283 return anActor->GetVisibility() ? "true" : "false";
289 template<class TPopupFunctor>
290 struct TPopupDispatcher
293 operator()(VisuGUI* theModule,
294 const QString& theEntry)
296 if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){
297 QString aType = aViewManager->getType();
298 TPopupFunctor aFunctor;
299 if(aType == SVTK_Viewer::Type())
300 return aFunctor.template Get<SVTK_Viewer>(theModule,theEntry);
301 else if(aType == VVTK_Viewer::Type())
302 return aFunctor.template Get<VVTK_Viewer>(theModule,theEntry);
309 QString VisuGUI_Selection::isVisible( const int ind ) const
311 return TPopupDispatcher<TIsVisibleFunctor>()((VisuGUI*)myModule,entry(ind));
314 QString VisuGUI_Selection::isShrunk( const int ind ) const
318 if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
319 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
320 if ( anVISUActor->IsShrunkable() )
321 aResStr = anVISUActor->IsShrunk() ? "1" : "0";
326 QString VisuGUI_Selection::hasActor( const int ind ) const
328 return representation( ind ).isEmpty() ? "0" : "1";
331 QString VisuGUI_Selection::isShading( const int ind ) const
335 if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
336 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
337 if ( VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor) )
338 aResStr = anActor->IsShading() ? "1" : "0";
343 QString VisuGUI_Selection::isScalarMapAct( const int ind ) const
347 if ( SVTK_ViewWindow* aView = GetViewWindow( myModule ) )
348 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
350 VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor);
351 aResStr = anActor ? "1" : "0";