973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
15 | #include <Message_ProgressScale.hxx> |
16 | #include <TCollection_HAsciiString.hxx> |
7fd59977 |
17 | |
18 | static const Standard_Real ZERO = 1e-10; |
19 | static const Standard_Real INFINITE = 1e100; |
20 | |
21 | //======================================================================= |
22 | //function : Message_ProgressScale |
23 | //purpose : |
24 | //======================================================================= |
25 | |
26 | Message_ProgressScale::Message_ProgressScale () : |
27 | myMin(0.), myMax(100.), myStep(1.), myInfinite(Standard_False), |
28 | myFirst(0.), myLast(1.) |
29 | { |
30 | } |
31 | |
32 | //======================================================================= |
33 | //function : LocalToBase |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | Standard_Real Message_ProgressScale::LocalToBase (const Standard_Real val) const |
38 | { |
39 | if ( val <= myMin ) return myFirst; |
40 | if ( myMax - myMin <= ZERO ) return myLast; |
41 | |
42 | if ( ! myInfinite ) { |
43 | if ( val >= myMax ) return myLast; |
44 | return myFirst + ( myLast - myFirst ) * ( val - myMin ) / ( myMax - myMin ); |
45 | } |
46 | Standard_Real x = ( val - myMin ) / ( myMax - myMin ); |
47 | // return myFirst + ( myLast - myFirst ) * ( 1. - exp ( -x ) ); // exponent |
48 | return myFirst + ( myLast - myFirst ) * x / ( 1. + x ); // hyperbola |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : BaseToLocal |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | Standard_Real Message_ProgressScale::BaseToLocal (const Standard_Real val) const |
57 | { |
58 | if ( myLast - val <= ZERO ) |
59 | return myInfinite ? INFINITE : myMax; |
60 | if ( ! myInfinite ) |
61 | return myMin + ( myMax - myMin ) * ( val - myFirst ) / ( myLast - myFirst ); |
62 | // Standard_Real x = log ( ( val - myFirst ) / ( myLast - val ) ); // exponent |
63 | Standard_Real x = ( val - myFirst ) / ( myLast - val ); // hyperbola |
64 | return myMin + x * ( myMax - myMin ); |
65 | } |