Salome HOME
Movement of examples to CVS EXAMPLES SAMPLES_SRC.
[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   float GetFloat( const QString& theValue, float theDefault )
41   {
42     int pos = theValue.find( ":" );
43     float val = theDefault;
44     if( pos>=0 ) 
45     {
46       QString name = theValue.right( theValue.length()-pos-1 ),
47               sect = theValue.left( pos );
48       if( !name.isEmpty() && !sect.isEmpty() )
49         val = GetFloat( name, sect, theDefault );
50     }
51     return val;
52   }
53
54   float GetFloat( const QString& theValue, const QString& theSection, float theDefault )
55   {
56     float val = theDefault;
57     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
58     if( mgr )
59       val = (float) mgr->doubleValue( theValue, theSection, theDefault );
60
61     return val;
62   }
63
64   void WriteUnstructuredGrid(vtkUnstructuredGrid* theGrid, const char* theFileName){
65     vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
66     aWriter->SetFileName(theFileName);
67     aWriter->SetInput(theGrid);
68     if(theGrid->GetNumberOfCells()){
69       aWriter->Write();
70     }
71     aWriter->Delete();
72   }
73
74   QColor GetColor( const QString& theSect, const QString& theName, const QColor& def )
75   {
76     QColor c = def;
77     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
78     if ( mgr )
79       c = mgr->colorValue( theSect, theName, def );
80     return c;
81   }
82
83   void GetColor( const QString& theSect, const QString& theName, int& r, int& g, int& b, const QColor& def )
84   {
85     QColor c = def;
86     SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr();
87     if ( mgr )
88       c = mgr->colorValue( theSect, theName, def );
89
90     SUIT_Tools::rgbSet( SUIT_Tools::rgbSet( c ), r, g, b );
91   }
92
93   void GetColor( const QString& theSect, const QString& theName, float& r, float& g, float& b, const QColor& def )
94   {
95     int ir( 0 ), ig( 0 ), ib( 0 );
96     GetColor( theSect, theName, ir, ig, ib, def );
97     r = ir / 255.;
98     g = ig / 255.;
99     b = ib / 255.;
100   }
101 }