1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Message_ProgressScale.hxx>
16 #include <TCollection_HAsciiString.hxx>
18 static const Standard_Real Message_ProgressScale_ZERO = 1e-10;
19 static const Standard_Real Message_ProgressScale_INFINITE = 1e100;
21 //=======================================================================
22 //function : Message_ProgressScale
24 //=======================================================================
26 Message_ProgressScale::Message_ProgressScale () :
27 myMin(0.), myMax(100.), myStep(1.), myInfinite(Standard_False),
28 myFirst(0.), myLast(1.)
32 //=======================================================================
33 //function : LocalToBase
35 //=======================================================================
37 Standard_Real Message_ProgressScale::LocalToBase (const Standard_Real val) const
39 if ( val <= myMin ) return myFirst;
40 if ( myMax - myMin <= Message_ProgressScale_ZERO ) return myLast;
43 if ( val >= myMax ) return myLast;
44 return myFirst + ( myLast - myFirst ) * ( val - myMin ) / ( myMax - myMin );
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
51 //=======================================================================
52 //function : BaseToLocal
54 //=======================================================================
56 Standard_Real Message_ProgressScale::BaseToLocal (const Standard_Real val) const
58 if ( myLast - val <= Message_ProgressScale_ZERO )
59 return myInfinite ? Message_ProgressScale_INFINITE : myMax;
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 );