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