Salome HOME
IPAL20954 problem loading help pages
[modules/visu.git] / src / VISUGUI / VisuGUI_FieldFilter.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_FieldFilter.cxx
24 //  Author : Oleg UVAROV
25 //  Module : VISU
26 //
27 #include "VisuGUI_FieldFilter.h"
28
29 #include "VisuGUI_Tools.h"
30
31 #include "VISUConfig.hh"
32 #include "VISU_ColoredPrs3dFactory.hh"
33
34 #include <SUIT_Session.h>
35
36 #include <SalomeApp_Study.h>
37 #include <LightApp_DataOwner.h>
38
39 using namespace VISU;
40
41 VisuGUI_FieldFilter::VisuGUI_FieldFilter( VISU::VISUType theType ) : 
42   myType( theType )
43 {
44 }
45
46 VisuGUI_FieldFilter::~VisuGUI_FieldFilter() 
47 {
48 }
49
50 void VisuGUI_FieldFilter::setPrs3dEntry( const QString& theEntry )
51 {
52   myPrs3dEntry = theEntry;
53 }
54
55 bool VisuGUI_FieldFilter::isOk( const SUIT_DataOwner* theDataOwner ) const
56 {
57   const LightApp_DataOwner* anOwner =
58     dynamic_cast<const LightApp_DataOwner*>( theDataOwner );
59
60   SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>
61     (SUIT_Session::session()->activeApplication()->activeStudy());
62
63   if( anOwner && anAppStudy )
64   {
65     if(myPrs3dEntry == anOwner->entry())
66       return true;
67
68     _PTR(Study) aStudy = anAppStudy->studyDS();
69     _PTR(SObject) aSObject = aStudy->FindObjectID( (const char*)anOwner->entry().toLatin1() );
70     if (!aSObject)
71       return false;
72
73     _PTR(SObject) aRefSO;
74     if( aSObject->ReferencedObject( aRefSO ) )
75       aSObject = aRefSO;
76
77     if( !aSObject )
78       return false;
79
80     VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap( aSObject );
81     if( aRestoringMap.empty() )
82       return false;
83
84     VISU::VISUType aType = VISU::Storable::RestoringMap2Type( aRestoringMap );
85     if( aType == VISU::TFIELD ) {
86       VISU::Result_var aResult = FindResult( VISU::GetSObject( aSObject ).in() );
87       QString aMeshName =  aRestoringMap["myMeshName"];
88       int anEntity = aRestoringMap["myEntityId"].toInt();
89       QString aFieldName = aRestoringMap["myName"];
90
91       VISU::ColoredPrs3dHolder::BasicInput anInput;
92       anInput.myResult = aResult;
93       anInput.myMeshName = CORBA::string_dup( (const char*)aMeshName.toLatin1() );
94       anInput.myEntity = (VISU::Entity)anEntity;
95       anInput.myFieldName = CORBA::string_dup( (const char*)aFieldName.toLatin1() );
96       anInput.myTimeStampNumber = 1;
97
98       QApplication::setOverrideCursor(Qt::WaitCursor);
99
100       size_t isOk = VISU::CheckIsPossible( myType, anInput, true );
101
102       QApplication::restoreOverrideCursor();
103
104       return isOk > 0;
105     }
106   }
107   return false;
108 }