Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCKGUI / MyDlgRef / MyDlgRef.cxx
1 // Copyright (C) 2009-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20
21 #include "MyDlgRef.hxx"
22
23
24 //////////////////////////////////////////
25 // MyDlgRef_1Sel2Spin
26 //////////////////////////////////////////
27
28 MyDlgRef_1Sel2Spin::MyDlgRef_1Sel2Spin( QWidget* parent, Qt::WindowFlags f )
29 : QWidget( parent, f )
30 {
31   setupUi( this );
32 }
33
34 MyDlgRef_1Sel2Spin::~MyDlgRef_1Sel2Spin()
35 {
36 }
37
38 //////////////////////////////////////////
39 // MyDlgRef_1Sel3Spin
40 //////////////////////////////////////////
41
42 MyDlgRef_1Sel3Spin::MyDlgRef_1Sel3Spin( QWidget* parent, Qt::WindowFlags f )
43 : QWidget( parent, f )
44 {
45   setupUi( this );
46 }
47
48 MyDlgRef_1Sel3Spin::~MyDlgRef_1Sel3Spin()
49 {
50 }
51
52 //////////////////////////////////////////
53 // MyDlgRef_2Sel1Spin
54 //////////////////////////////////////////
55
56 MyDlgRef_2Sel1Spin::MyDlgRef_2Sel1Spin( QWidget* parent, Qt::WindowFlags f )
57 : QWidget( parent, f )
58 {
59   setupUi( this );
60 }
61
62 MyDlgRef_2Sel1Spin::~MyDlgRef_2Sel1Spin()
63 {
64 }
65
66 //////////////////////////////////////////
67 // MyDlgRef_2Sel
68 //////////////////////////////////////////
69
70 MyDlgRef_2Sel::MyDlgRef_2Sel( QWidget* parent, Qt::WindowFlags f )
71 : QWidget( parent, f )
72 {
73   setupUi( this );
74 }
75
76 MyDlgRef_2Sel::~MyDlgRef_2Sel()
77 {
78 }
79
80 //////////////////////////////////////////
81 // MyDlgRef_3Spin
82 //////////////////////////////////////////
83
84 MyDlgRef_3Spin::MyDlgRef_3Spin( QWidget* parent, Qt::WindowFlags f )
85 : QWidget( parent, f )
86 {
87   setupUi( this );
88 }
89
90 MyDlgRef_3Spin::~MyDlgRef_3Spin()
91 {
92 }
93
94 //////////////////////////////////////////
95 // MyDlgRef_Skeleton
96 //////////////////////////////////////////
97
98 MyDlgRef_Skeleton::MyDlgRef_Skeleton( QWidget* parent, Qt::WindowFlags f )
99 : QWidget( parent, f )
100 {
101   setupUi( this );
102 }
103
104 MyDlgRef_Skeleton::~MyDlgRef_Skeleton()
105 {
106 }
107
108 //////////////////////////////////////////
109 // Utility functions
110 //////////////////////////////////////////
111
112 QString MyDlgRef::PrintDoubleValue( double theValue, int thePrecision )
113 {
114   const double prec = 1e-12;
115   
116   if ( qAbs(theValue) < prec )
117     return "0";
118
119   QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( thePrecision ) );
120
121   if ( prec > 0 ) {
122     int p = 0;
123     while ( p < thePrecision ) {
124       QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( p++ ) );
125       double v = aRes.toDouble();
126       double err = qAbs( theValue - v );
127       if ( err > 0 && err <= prec )
128         break;
129     }
130   }
131
132   // remove trailing zeroes
133
134   QRegExp expre( QString( "(%1|%2)[+-]?[0-9]+$" ).arg( QLocale().exponential().toLower(), 
135                                                        QLocale().exponential().toUpper() ) );
136
137   int idx = aRes.indexOf( expre );
138   QString aResExp = "";
139   if ( idx >= 0 ) {
140     aResExp = aRes.mid( idx );
141     aRes = aRes.left( idx );
142   }
143
144   if ( aRes.contains( QLocale().decimalPoint() ) )
145     aRes.remove( QRegExp( QString( "(\\%1|0)0*$" ).arg( QLocale().decimalPoint() ) ) );
146
147   return aRes == "-0" ? QString( "0" ) : aRes + aResExp;
148 }