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"
34 #include "VISU_Gen_i.hh"
36 #include "VISU_Actor.h"
37 #include "VISU_ScalarMapAct.h"
39 #include "SalomeApp_Study.h"
40 #include "LightApp_Study.h"
44 //////////////////////////////////////////////////
45 // Class: VisuGUI_Selection
46 //////////////////////////////////////////////////
48 QtxValue VisuGUI_Selection::param( const int ind, const QString& p ) const
50 QtxValue val( LightApp_Selection::param( ind, p ) );
51 if ( !val.isValid() ) {
52 if ( p == "type" ) val = QtxValue( type( ind ) );
53 else if ( p == "nbComponents" ) val = QtxValue( nbComponents( ind ) );
54 else if ( p == "medEntity" ) val = QtxValue( medEntity( ind ) );
55 else if ( p == "medSource" ) val = QtxValue( medSource( ind ) );
56 else if ( p == "representation" ) val = QtxValue( representation( ind ) );
57 else if ( p == "nbTimeStamps" ) val = QtxValue( nbTimeStamps( ind ) );
58 else if ( p == "nbChildren" ) val = QtxValue( nbChildren( ind ) );
59 else if ( p == "nbNamedChildren") val = QtxValue( nbNamedChildren( ind ) );
60 else if ( p == "isVisible" ) val = QtxValue( isVisible( ind ) );
61 else if ( p == "isShrunk" ) val = QtxValue( isShrunk( ind ) );
62 else if ( p == "hasActor" ) val = QtxValue( hasActor( ind ) );
63 else if ( p == "isShading" ) val = QtxValue( isShading( ind ) );
64 else if ( p == "isScalarMapAct" ) val = QtxValue( isScalarMapAct( ind ) );
65 else if ( p == "isVisuComponent") val = QtxValue( isVisuComponent( ind ) );
71 // Macro for converting VISU enumeration items into corresponding strings
72 #define ENUM2STRING( x, y ) \
77 QString VisuGUI_Selection::type( const int ind ) const
80 VISU::Storable::TRestoringMap aMap;
81 SalomeApp_Study* aStudy = GetStudy();
84 CORBA::Object_var anObject = GetSelectedObj( aStudy, entry( ind ), &aMap );
86 VISU::Base_var aVisuObj = VISU::Base::_narrow( anObject );
87 if ( !CORBA::is_nil( aVisuObj ) ){
88 VISU::VISUType aType = aVisuObj->GetType();
90 ENUM2STRING( aResStr, VISU::TVISUGEN );
91 ENUM2STRING( aResStr, VISU::TRESULT );
92 ENUM2STRING( aResStr, VISU::TTABLE );
93 ENUM2STRING( aResStr, VISU::TCURVE );
94 ENUM2STRING( aResStr, VISU::TCONTAINER );
95 ENUM2STRING( aResStr, VISU::TMESH );
96 ENUM2STRING( aResStr, VISU::TSCALARMAP );
97 ENUM2STRING( aResStr, VISU::TISOSURFACE );
98 ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
99 ENUM2STRING( aResStr, VISU::TSCALARMAPONDEFORMEDSHAPE );
100 ENUM2STRING( aResStr, VISU::TCUTPLANES );
101 ENUM2STRING( aResStr, VISU::TCUTLINES );
102 ENUM2STRING( aResStr, VISU::TVECTORS );
103 ENUM2STRING( aResStr, VISU::TSTREAMLINES );
104 ENUM2STRING( aResStr, VISU::TPLOT3D );
105 ENUM2STRING( aResStr, VISU::TANIMATION );
109 if(aResStr.isNull()){
111 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue( aMap, "myType", &isExist).toInt();
114 ENUM2STRING( aResStr, VISU::TENTITY );
115 ENUM2STRING( aResStr, VISU::TFAMILY );
116 ENUM2STRING( aResStr, VISU::TGROUP );
117 ENUM2STRING( aResStr, VISU::TVIEW3D );
118 ENUM2STRING( aResStr, VISU::TFIELD );
119 ENUM2STRING( aResStr, VISU::TTIMESTAMP );
124 if(aResStr.isNull()){
126 QString aVal = VISU::Storable::FindValue(aMap,"myComment",&isExist);
127 if ( isExist && aVal!="MESH" )
128 aResStr = "VISU::T" + aVal;
134 QString VisuGUI_Selection::nbComponents( const int ind ) const
137 VISU::Storable::TRestoringMap aMap;
138 SalomeApp_Study* aStudy = GetStudy();
141 GetSelectedObj( aStudy, entry( ind ), &aMap );
143 const QString& aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
149 QString VisuGUI_Selection::medEntity( const int ind ) const
152 VISU::Storable::TRestoringMap aMap;
153 GetSelectedObj( GetStudy(), entry( ind ), &aMap );
154 const QString& aVal = VISU::Storable::FindValue(aMap,"myEntityId",&isExist);
156 using namespace VISU;
157 TEntity anEntityId = TEntity(aVal.toInt());
160 return "NODE_ENTITY";
162 return "EDGE_ENTITY";
164 return "FACE_ENTITY";
166 return "CELL_ENTITY";
174 QString VisuGUI_Selection::medSource( const int ind ) const
176 _PTR(Study) aStudyDS = GetStudy()->studyDS();
177 if(_PTR(SObject) aSObject = aStudyDS->FindObjectID(entry(ind).latin1())){
178 VISU::Result_var aRes;
179 if(VISU::Result_i* aResult = CheckResult(myModule,aSObject,aRes)){
180 using namespace VISU;
181 Result_i::ECreationId aCreationId = aResult->GetCreationId();
183 case Result_i::eImportFile :
184 return "eImportFile";
185 case Result_i::eCopyAndImportFile :
186 return "eCopyAndImportFile";
187 case Result_i::eImportMed :
189 case Result_i::eImportMedField :
190 return "eImportMedField";
199 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
202 VISU::Storable::TRestoringMap aMap;
203 SalomeApp_Study* aStudy = GetStudy();
206 GetSelectedObj( aStudy, entry( ind ), &aMap );
208 const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
214 QString VisuGUI_Selection::representation( const int ind ) const
218 if (SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule)) {
219 if (VISU_Actor* anVISUActor = FindActor(aView, entry(ind).latin1())) {
220 int aRepresent = anVISUActor->GetRepresentation();
221 switch (aRepresent) {
222 ENUM2STRING( aResStr, VISU::POINT );
223 ENUM2STRING( aResStr, VISU::WIREFRAME );
224 ENUM2STRING( aResStr, VISU::SHADED );
225 ENUM2STRING( aResStr, VISU::INSIDEFRAME );
226 ENUM2STRING( aResStr, VISU::SURFACEFRAME );
234 SalomeApp_Study* VisuGUI_Selection::GetStudy() const
237 LightApp_Study* aLightStudy = const_cast<LightApp_Study*>( study() );
238 return dynamic_cast<SalomeApp_Study*>( aLightStudy );
241 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
244 SalomeApp_Study* aSStudy = GetStudy();
247 _PTR(Study) aStudy = GetCStudy( aSStudy );
249 _PTR(SObject) SO = aStudy->FindObjectID( entry( ind ).latin1() );
251 for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
253 if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
261 QString VisuGUI_Selection::nbChildren( const int ind ) const
264 aResStr.setNum( nbChild( ind, false ) );
268 QString VisuGUI_Selection::nbNamedChildren( const int ind ) const
271 aResStr.setNum( nbChild( ind, true ) );
277 struct TIsVisibleFunctor
279 template<class TViewer>
281 Get(VisuGUI* theModule,
282 const QString& theEntry)
284 typedef typename TViewer::TViewWindow TViewWindow;
285 if (TViewWindow* aViewWindow = GetActiveViewWindow<TViewWindow>(theModule))
286 if (VISU_Actor* anActor = FindActor(aViewWindow,theEntry.latin1()))
287 return anActor->GetVisibility() ? "true" : "false";
293 template<class TPopupFunctor>
294 struct TPopupDispatcher
297 operator()(VisuGUI* theModule,
298 const QString& theEntry)
300 if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){
301 QString aType = aViewManager->getType();
302 TPopupFunctor aFunctor;
303 if(aType == SVTK_Viewer::Type())
304 return aFunctor.template Get<SVTK_Viewer>(theModule,theEntry);
305 else if(aType == VVTK_Viewer::Type())
306 return aFunctor.template Get<VVTK_Viewer>(theModule,theEntry);
313 QString VisuGUI_Selection::isVisible( const int ind ) const
315 return TPopupDispatcher<TIsVisibleFunctor>()((VisuGUI*)myModule,entry(ind));
318 QString VisuGUI_Selection::isShrunk( const int ind ) const
322 if ( SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
323 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
324 if ( anVISUActor->IsShrunkable() )
325 aResStr = anVISUActor->IsShrunk() ? "1" : "0";
330 QString VisuGUI_Selection::hasActor( const int ind ) const
332 return representation( ind ).isEmpty() ? "0" : "1";
335 QString VisuGUI_Selection::isShading( const int ind ) const
339 if ( SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
340 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
341 if ( VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor) )
342 aResStr = anActor->IsShading() ? "1" : "0";
347 QString VisuGUI_Selection::isScalarMapAct( const int ind ) const
351 if ( SVTK_ViewWindow* aView = GetActiveViewWindow<SVTK_ViewWindow>(myModule) )
352 if ( VISU_Actor* anVISUActor = FindActor( aView, entry( ind ).latin1() ) )
354 VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(anVISUActor);
355 aResStr = anActor ? "1" : "0";
361 bool VisuGUI_Selection::isVisuComponent( const int ind ) const
363 SalomeApp_Study* study = GetStudy();
367 _PTR(SObject) obj = study->studyDS()->FindObjectID( entry( ind ).latin1() );
370 CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
371 if( CORBA::is_nil( anObj ) )
374 return dynamic_cast<VISU::VISU_Gen_i*>( VISU::GetServant( anObj ).in() );