Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/smesh.git] / src / OBJECT / SMESH_ActorUtils.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19
20
21 #include "SMESH_ActorUtils.h"
22
23 #include "SUIT_Tools.h"
24 #include "SUIT_Session.h"
25 #include "SUIT_ResourceMgr.h"
26
27 #include "utilities.h"
28
29 #include <vtkUnstructuredGrid.h>
30 #include <vtkUnstructuredGridWriter.h>
31
32 #ifdef _DEBUG_
33 static int MYDEBUG = 1;
34 #else
35 static int MYDEBUG = 0;
36 #endif
37
38 namespace SMESH
39 {
40
41   vtkFloatingPointType
42   GetFloat( const QString& theValue, 
43             vtkFloatingPointType theDefault )
44   {
45     int pos = theValue.find( ":" );
46     vtkFloatingPointType val = theDefault;
47     if( pos>=0 ) 
48     {
49       QString name = theValue.right( theValue.length()-pos-1 ),
50               sect = theValue.left( pos );
51       if( !name.isEmpty() && !sect.isEmpty() )
52         val = GetFloat( name, sect, theDefault );
53     }
54     return val;
55   }
56
57   vtkFloatingPointType
58   GetFloat( const QString& theValue, 
59             const QString& theSection, 
60             vtkFloatingPointType theDefault )
61   {
62     vtkFloatingPointType val = theDefault;
63     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
64     if( mgr )
65       val = (vtkFloatingPointType) mgr->doubleValue( theValue, theSection, theDefault );
66
67     return val;
68   }
69
70   void
71   WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, 
72                         const char* theFileName)
73   {
74     vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
75     aWriter->SetFileName(theFileName);
76     aWriter->SetInput(theGrid);
77     if(theGrid->GetNumberOfCells()){
78       aWriter->Write();
79     }
80     aWriter->Delete();
81   }
82
83   QColor
84   GetColor( const QString& theSect, 
85             const QString& theName, 
86             const QColor& def )
87   {
88     QColor c = def;
89     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
90     if ( mgr )
91       c = mgr->colorValue( theSect, theName, def );
92     return c;
93   }
94
95   void
96   GetColor( const QString& theSect, 
97             const QString& theName, 
98             int& r, 
99             int& g, 
100             int& b, 
101             const QColor& def )
102   {
103     QColor c = def;
104     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
105     if ( mgr )
106       c = mgr->colorValue( theSect, theName, def );
107
108     SUIT_Tools::rgbSet( SUIT_Tools::rgbSet( c ), r, g, b );
109   }
110
111   void
112   GetColor( const QString& theSect, 
113             const QString& theName, 
114             vtkFloatingPointType& r, 
115             vtkFloatingPointType& g, 
116             vtkFloatingPointType& b, 
117             const QColor& def )
118   {
119     int ir( 0 ), ig( 0 ), ib( 0 );
120     GetColor( theSect, theName, ir, ig, ib, def );
121     r = ir / 255.;
122     g = ig / 255.;
123     b = ib / 255.;
124   }
125 }