Salome HOME
Add test function : QApplication::postEvent(SALOME_Event)
[modules/visu.git] / src / VISU_SWIG / VISU_Gen_s.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_Gen_s.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_Gen_s.hh"
28
29 #include "VISU_Convertor.hxx"
30 #include "VISU_ScalarMapPL.hxx"
31
32 #include <vtkUnstructuredGrid.h>
33 #include <vtkDataSetMapper.h>
34
35 #include <vtkRenderWindowInteractor.h>
36 #include <vtkRenderWindow.h> 
37 #include <vtkRenderer.h>
38 #include <vtkCamera.h>
39 #include <vtkActor.h>
40
41 using namespace std;
42
43 Convertor::Convertor(const char* theFileName) : myConvertor(CreateConvertor(theFileName)){}
44
45
46 ScalarMap::ScalarMap(Convertor* theConvertor, const char* theMeshName, int theEntity, 
47                      const char* theFieldName, int theIteration)
48   : myScalarMap(NULL)
49 {
50   if(VISU_Convertor* aConvertor = theConvertor->GetImpl()){
51     vtkUnstructuredGrid* aDataSet = 
52       aConvertor->GetTimeStampOnMesh(theMeshName,VISU::TEntity(theEntity),theFieldName,theIteration);
53     if(aDataSet){
54       myScalarMap = VISU_ScalarMapPL::New();
55       myScalarMap->SetInput(aDataSet);
56       myScalarMap->Build();
57       myScalarMap->Init();
58       myScalarMap->SetSourceRange();
59     }
60   }
61 }
62
63
64 View3D::View3D(){
65   myRen = vtkRenderer::New();
66   myRenWin = vtkRenderWindow::New();
67   myRenWin->AddRenderer(myRen);
68   myRenWin->SetSize(300, 300);
69   myRen->Delete();
70   myRen->GetActiveCamera()->ParallelProjectionOn();
71   myIRen = vtkRenderWindowInteractor::New();
72   myIRen->SetRenderWindow(myRenWin);
73   myRenWin->Delete();
74 }
75
76 void View3D::SetPosition(int theX, int theY) {
77   myRenWin->SetPosition(theX, theY);
78 }
79
80 View3D::~View3D(){
81   myIRen->Delete();
82 }
83
84 void View3D::Display(ScalarMap* theScalarMap){
85   if(VISU_ScalarMapPL* aScalarMap = theScalarMap->GetImpl()){
86     aScalarMap->Update();
87     
88     myRen->RemoveAllProps();
89     vtkActor* anActor = vtkActor::New();
90     anActor->SetMapper(aScalarMap->GetMapper());
91     
92     VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New();
93     aScalarBar->SetLookupTable(aScalarMap->GetBarTable());
94     
95     aScalarMap->Build();
96     
97     myRen->AddActor(anActor);
98     myRen->AddActor2D(aScalarBar);
99     myRen->ResetCameraClippingRange();
100     
101     myRenWin->Render();
102   }
103 }