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