0024438: Message_Algorithm - allow customized status descriptions
[occt.git] / src / Message / Message_ProgressScale.cxx
CommitLineData
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//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#include <Message_ProgressScale.ixx>
15
16static const Standard_Real ZERO = 1e-10;
17static const Standard_Real INFINITE = 1e100;
18
19//=======================================================================
20//function : Message_ProgressScale
21//purpose :
22//=======================================================================
23
24Message_ProgressScale::Message_ProgressScale () :
25 myMin(0.), myMax(100.), myStep(1.), myInfinite(Standard_False),
26 myFirst(0.), myLast(1.)
27{
28}
29
30//=======================================================================
31//function : LocalToBase
32//purpose :
33//=======================================================================
34
35Standard_Real Message_ProgressScale::LocalToBase (const Standard_Real val) const
36{
37 if ( val <= myMin ) return myFirst;
38 if ( myMax - myMin <= ZERO ) return myLast;
39
40 if ( ! myInfinite ) {
41 if ( val >= myMax ) return myLast;
42 return myFirst + ( myLast - myFirst ) * ( val - myMin ) / ( myMax - myMin );
43 }
44 Standard_Real x = ( val - myMin ) / ( myMax - myMin );
45// return myFirst + ( myLast - myFirst ) * ( 1. - exp ( -x ) ); // exponent
46 return myFirst + ( myLast - myFirst ) * x / ( 1. + x ); // hyperbola
47}
48
49//=======================================================================
50//function : BaseToLocal
51//purpose :
52//=======================================================================
53
54Standard_Real Message_ProgressScale::BaseToLocal (const Standard_Real val) const
55{
56 if ( myLast - val <= ZERO )
57 return myInfinite ? INFINITE : myMax;
58 if ( ! myInfinite )
59 return myMin + ( myMax - myMin ) * ( val - myFirst ) / ( myLast - myFirst );
60// Standard_Real x = log ( ( val - myFirst ) / ( myLast - val ) ); // exponent
61 Standard_Real x = ( val - myFirst ) / ( myLast - val ); // hyperbola
62 return myMin + x * ( myMax - myMin );
63}