0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Message / Message_ProgressScale.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <Message_ProgressScale.hxx>
16 #include <TCollection_HAsciiString.hxx>
17
18 static const Standard_Real Message_ProgressScale_ZERO = 1e-10;
19 static const Standard_Real Message_ProgressScale_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 <= Message_ProgressScale_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 <= Message_ProgressScale_ZERO ) 
59     return myInfinite ? Message_ProgressScale_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 }