Salome HOME
Merge from V5_1_4_BR 07/05/2010
[modules/smesh.git] / src / OBJECT / SMESH_ActorUtils.cxx
1 //  Copyright (C) 2007-2010  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 #include "SMESH_ActorUtils.h"
24
25 #include "SUIT_Tools.h"
26 #include "SUIT_Session.h"
27 #include "SUIT_ResourceMgr.h"
28
29 #include "utilities.h"
30
31 #include <vtkUnstructuredGrid.h>
32 #include <vtkUnstructuredGridWriter.h>
33
34 #ifdef _DEBUG_
35 static int MYDEBUG = 1;
36 #else
37 static int MYDEBUG = 0;
38 #endif
39
40 namespace SMESH
41 {
42
43   vtkFloatingPointType
44   GetFloat( const QString& theValue, 
45             vtkFloatingPointType theDefault )
46   {
47     int pos = theValue.indexOf( ":" );
48     vtkFloatingPointType val = theDefault;
49     if( pos>=0 ) 
50     {
51       QString name = theValue.right( theValue.length()-pos-1 ),
52               sect = theValue.left( pos );
53       if( !name.isEmpty() && !sect.isEmpty() )
54         val = GetFloat( name, sect, theDefault );
55     }
56     return val;
57   }
58
59   vtkFloatingPointType
60   GetFloat( const QString& theValue, 
61             const QString& theSection, 
62             vtkFloatingPointType theDefault )
63   {
64     vtkFloatingPointType val = theDefault;
65     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
66     if( mgr )
67       val = (vtkFloatingPointType) mgr->doubleValue( theSection, theValue, theDefault );
68
69     return val;
70   }
71
72   void
73   WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, 
74                         const char* theFileName)
75   {
76     vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
77     aWriter->SetFileName(theFileName);
78     aWriter->SetInput(theGrid);
79     if(theGrid->GetNumberOfCells()){
80       aWriter->Write();
81     }
82     aWriter->Delete();
83   }
84
85   QColor
86   GetColor( const QString& theSect, 
87             const QString& theName, 
88             const QColor& def )
89   {
90     QColor c = def;
91     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
92     if ( mgr )
93       c = mgr->colorValue( theSect, theName, def );
94     return c;
95   }
96
97   void
98   GetColor( const QString& theSect, 
99             const QString& theName, 
100             int& r, 
101             int& g, 
102             int& b, 
103             const QColor& def )
104   {
105     QColor c = def;
106     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
107     if ( mgr )
108       c = mgr->colorValue( theSect, theName, def );
109
110     SUIT_Tools::rgbSet( SUIT_Tools::rgbSet( c ), r, g, b );
111   }
112
113   void
114   GetColor( const QString& theSect, 
115             const QString& theName, 
116             vtkFloatingPointType& r, 
117             vtkFloatingPointType& g, 
118             vtkFloatingPointType& b, 
119             const QColor& def )
120   {
121     int ir( 0 ), ig( 0 ), ib( 0 );
122     GetColor( theSect, theName, ir, ig, ib, def );
123     r = ir / 255.;
124     g = ig / 255.;
125     b = ib / 255.;
126   }
127 }