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"
30 #include "VisuGUI_ViewTools.h"
31 #include "VisuGUI_Tools.h"
33 #include "VISU_Result_i.hh"
35 #include "VISU_Actor.h"
36 #include "VISU_ScalarMapAct.h"
38 #include "SalomeApp_Study.h"
39 #include "LightApp_Study.h"
43 //////////////////////////////////////////////////
44 // Class: VisuGUI_Selection
45 //////////////////////////////////////////////////
47 QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
49 QtxValue val( LightApp_Selection::param( ind, p ) );
50 if ( !val.isValid() ) {
51 if ( p == "type" ) val = QtxValue( type( ind ) );
52 else if ( p == "nbComponents" ) val = QtxValue( nbComponents( ind ) );
53 else if ( p == "medEntity" ) val = QtxValue( medEntity( ind ) );
54 else if ( p == "medSource" ) val = QtxValue( medSource( ind ) );
55 else if ( p == "representation" ) val = QtxValue( representation( ind ) );
56 else if ( p == "nbTimeStamps" ) val = QtxValue( nbTimeStamps( ind ) );
57 else if ( p == "nbChildren" ) val = QtxValue( nbChildren( ind ) );
58 else if ( p == "nbNamedChildren") val = QtxValue( nbNamedChildren( ind ) );
59 else if ( p == "isVisible" ) val = QtxValue( isVisible( ind ) );
60 else if ( p == "isShrunk" ) val = QtxValue( isShrunk( ind ) );
61 else if ( p == "hasActor" ) val = QtxValue( hasActor( ind ) );
62 else if ( p == "isShading" ) val = QtxValue( isShading( ind ) );
63 else if ( p == "isScalarMapAct" ) val = QtxValue( isScalarMapAct( ind ) );
69 // Macro for converting VISU enumeration items into corresponding strings
70 #define ENUM2STRING( x, y ) \
75 QString VisuGUI_Selection::type( const int ind ) const
78 VISU::Storable::TRestoringMap aMap;
79 SalomeApp_Study* aStudy = GetStudy();
82 CORBA::Object_var anObject = GetSelectedObj( aStudy, entry( ind ), &aMap );
84 VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject );
85 if ( !CORBA::is_nil( aVisuObj ) ){
86 VISU::VISUType aType = aVisuObj->GetType();
88 ENUM2STRING( aResStr, VISU::TVISUGEN );
89 ENUM2STRING( aResStr, VISU::TRESULT );
90 ENUM2STRING( aResStr, VISU::TTABLE );
91 ENUM2STRING( aResStr, VISU::TCURVE );
92 ENUM2STRING( aResStr, VISU::TCONTAINER );
93 ENUM2STRING( aResStr, VISU::TMESH );
94 ENUM2STRING( aResStr, VISU::TSCALARMAP );
95 ENUM2STRING( aResStr, VISU::TISOSURFACE );
96 ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
97 ENUM2STRING( aResStr, VISU::TSCALARMAPONDEFORMEDSHAPE );
98 ENUM2STRING( aResStr, VISU::TCUTPLANES );
99 ENUM2STRING( aResStr, VISU::TCUTLINES );
100 ENUM2STRING( aResStr, VISU::TVECTORS );
101 ENUM2STRING( aResStr, VISU::TSTREAMLINES );
102 ENUM2STRING( aResStr, VISU::TPLOT3D );
103 ENUM2STRING( aResStr, VISU::TANIMATION );
107 if(aResStr.isNull()){
109 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue( aMap, "myType", &isExist).toInt();
112 ENUM2STRING( aResStr, VISU::TENTITY );
113 ENUM2STRING( aResStr, VISU::TFAMILY );
114 ENUM2STRING( aResStr, VISU::TGROUP );
115 ENUM2STRING( aResStr, VISU::TVIEW3D );
116 ENUM2STRING( aResStr, VISU::TFIELD );
117 ENUM2STRING( aResStr, VISU::TTIMESTAMP );
122 if(aResStr.isNull()){
124 QString aVal = VISU::Storable::FindValue(aMap,"myComment",&isExist);
125 if ( isExist && aVal!="MESH" )
126 aResStr = "VISU::T" + aVal;
132 QString VisuGUI_Selection::nbComponents( const int ind ) const
135 VISU::Storable::TRestoringMap aMap;
136 SalomeApp_Study* aStudy = GetStudy();
139 GetSelectedObj( aStudy, entry( ind ), &aMap );
141 const QString& aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
147 QString VisuGUI_Selection::medEntity( const int ind ) const
150 VISU::Storable::TRestoringMap aMap;
151 GetSelectedObj( GetStudy(), entry( ind ), &aMap );
152 const QString& aVal = VISU::Storable::FindValue(aMap,"myEntityId",&isExist);
154 using namespace VISU;
155 TEntity anEntityId = TEntity(aVal.toInt());
158 return "NODE_ENTITY";
160 return "EDGE_ENTITY";
162 return "FACE_ENTITY";
164 return "CELL_ENTITY";
172 QString VisuGUI_Selection::medSource( const int ind ) const
174 _PTR(Study) aStudyDS = GetStudy()->studyDS();
175 if(_PTR(SObject) aSObject = aStudyDS->FindObjectID(entry(ind))){
176 VISU::Result_var aRes;
177 if(VISU::Result_i* aResult = CheckResult(myModule,aSObject,aRes)){
178 using namespace VISU;
179 Result_i::ECreationId aCreationId = aResult->GetCreationId();
181 case Result_i::eImportFile :
182 return "eImportFile";
183 case Result_i::eCopyAndImportFile :
184 return "eCopyAndImportFile";
185 case Result_i::eImportMed :
187 case Result_i::eImportMedField :
188 return "eImportMedField";
197 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
200 VISU::Storable::TRestoringMap aMap;
201 SalomeApp_Study* aStudy = GetStudy();
204 GetSelectedObj( aStudy, entry( ind ), &aMap );
206 const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
212 QString VisuGUI_Selection::representation( const int ind ) const
216 if (SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule)) {
217 if (VISU_Actor* anVISUActor = FindActor(aView, entry(ind).latin1())) {
218 int aRepresent = anVISUActor->GetRepresentation();
219 switch (aRepresent) {
220 ENUM2STRING( aResStr, VISU::POINT );
221 ENUM2STRING( aResStr, VISU::WIREFRAME );
222 ENUM2STRING( aResStr, VISU::SHADED );
223 ENUM2STRING( aResStr, VISU::INSIDEFRAME );
224 ENUM2STRING( aResStr, VISU::SURFACEFRAME );
232 SalomeApp_Study* VisuGUI_Selection::GetStudy() const
235 LightApp_Study* aLightStudy = const_cast<LightApp_Study*>( study() );
236 return dynamic_cast<SalomeApp_Study*>( aLightStudy );
239 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
242 SalomeApp_Study* aSStudy = GetStudy();
245 _PTR(Study) aStudy = GetCStudy( aSStudy );
247 _PTR(SObject) SO = aStudy->FindObjectID( entry( ind ).latin1() );
249 for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
251 if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
259 QString VisuGUI_Selection::nbChildren( const int ind ) const
262 aResStr.setNum( nbChild( ind, false ) );
266 QString VisuGUI_Selection::nbNamedChildren( const int ind ) const
269 aResStr.setNum( nbChild( ind, true ) );
275 struct TIsVisibleFunctor
277 template<class TViewer>
279 Get(VisuGUI* theModule,
280 const QString& theEntry)
282 typedef typename TViewer::TViewWindow TViewWindow;
283 if (TViewWindow* aViewWindow = GetActiveViewWindow<TViewWindow>(theModule))
284 if (VISU_Actor* anActor = FindActor(aViewWindow,theEntry.latin1()))
285 return anActor->GetVisibility() ? "true" : "false";
291 template<class TPopupFunctor>
292 struct TPopupDispatcher
295 operator()(VisuGUI* theModule,
296 const QString& theEntry)
298 if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){
299 QString aType = aViewManager->getType();
300 TPopupFunctor aFunctor;
301 if(aType == SVTK_Viewer::Type())
302 return aFunctor.template Get<SVTK_Viewer>(theModule,theEntry);
303 else if(aType == VVTK_Viewer::Type())
304 return aFunctor.template Get<VVTK_Viewer>(theModule,theEntry);
311 QString VisuGUI_Selection::isVisible( const int ind ) const
313 return TPopupDispatcher<TIsVisibleFunctor>()((VisuGUI*)myModule,entry(ind));
316 QString VisuGUI_Selection::isShrunk( const int ind ) const
320 if ( SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
321 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
322 if ( anVISUActor->IsShrunkable() )
323 aResStr = anVISUActor->IsShrunk() ? "1" : "0";
328 QString VisuGUI_Selection::hasActor( const int ind ) const
330 return representation( ind ).isEmpty() ? "0" : "1";
333 QString VisuGUI_Selection::isShading( const int ind ) const
337 if ( SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
338 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
339 if ( VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor) )
340 aResStr = anActor->IsShading() ? "1" : "0";
345 QString VisuGUI_Selection::isScalarMapAct( const int ind ) const
349 if ( SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
350 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
352 VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor);
353 aResStr = anActor ? "1" : "0";