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