0024428: Implementation of LGPL license
[occt.git] / src / Message / Message_ProgressIndicator.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_ProgressIndicator.ixx>
15
16//=======================================================================
17//function : Message_ProgressIndicator
18//purpose :
19//=======================================================================
20
21Message_ProgressIndicator::Message_ProgressIndicator ()
22{
23 Reset();
24}
25
26//=======================================================================
27//function : Reset
28//purpose :
29//=======================================================================
30
31void Message_ProgressIndicator::Reset ()
32{
33 myPosition = 0.;
34
35 Message_ProgressScale scale;
36 scale.SetName ( "Step" );
37 scale.SetSpan ( 0., 1. );
38
39 myScopes.Clear();
40 myScopes.Append ( scale );
41}
42
43//=======================================================================
44//function : SetScale
45//purpose :
46//=======================================================================
47
48void Message_ProgressIndicator::SetScale (const Standard_Real min,
49 const Standard_Real max,
50 const Standard_Real step,
51 const Standard_Boolean isInf)
52{
53 Message_ProgressScale &scale = myScopes.ChangeValue(1);
54 scale.SetRange ( min, max );
55 scale.SetStep ( step );
56 scale.SetInfinite ( isInf );
57}
58
59//=======================================================================
60//function : GetScale
61//purpose :
62//=======================================================================
63
64void Message_ProgressIndicator::GetScale (Standard_Real &min,
65 Standard_Real &max,
66 Standard_Real &step,
67 Standard_Boolean &isInf) const
68{
69 const Message_ProgressScale &scale = myScopes(1);
70 min = scale.GetMin();
71 max = scale.GetMax();
72 step = scale.GetStep();
73 isInf = scale.GetInfinite();
74}
75
76//=======================================================================
77//function : SetValue
78//purpose :
79//=======================================================================
80
81void Message_ProgressIndicator::SetValue (const Standard_Real val)
82{
83 const Message_ProgressScale &scale = myScopes(1);
84 Standard_Real p = scale.LocalToBase ( val );
85 if ( myPosition < p ) {
86 myPosition = Min ( p, 1. );
87 Show(Standard_False);
88 }
89}
90
91//=======================================================================
92//function : GetValue
93//purpose :
94//=======================================================================
95
96Standard_Real Message_ProgressIndicator::GetValue () const
97{
98 return myScopes(1).BaseToLocal ( myPosition );
99}
100
101//=======================================================================
102//function : NewScope
103//purpose :
104//=======================================================================
105
106Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_Real span,
107 const Handle(TCollection_HAsciiString) &name)
108{
109 Message_ProgressScale scale;
110 scale.SetName ( name );
111 scale.SetSpan ( myPosition, myScopes(1).LocalToBase ( GetValue() + span ) );
112 myScopes.Prepend ( scale );
113// Show(Standard_False); // to update textual representation, if any
114 return myPosition < 1.;
115}
116
117//=======================================================================
118//function : EndScope
119//purpose :
120//=======================================================================
121
122Standard_Boolean Message_ProgressIndicator::EndScope ()
123{
124 Standard_Real end = myScopes(1).GetLast();
125 Standard_Boolean ret = ( myScopes.Length() >1 );
126 if ( ret ) myScopes.Remove(1);
127 if ( myPosition != end ) {
128 myPosition = end;
129 Show(Standard_False);
130 }
131 return ret;
132}
133
134//=======================================================================
135//function : NextScope
136//purpose :
137//=======================================================================
138
139Standard_Boolean Message_ProgressIndicator::NextScope (const Standard_Real span,
140 const Standard_CString name)
141{
142 Message_ProgressScale &scale = myScopes.ChangeValue(1);
143 if ( myPosition != scale.GetLast() ) {
144 myPosition = scale.GetLast();
145 Show(Standard_False);
146 }
147 if ( myScopes.Length() <2 ) return Standard_False;
148
149 if ( name ) scale.SetName ( name );
150 const Message_ProgressScale &scale2 = myScopes(2);
151 scale.SetSpan ( myPosition, scale2.LocalToBase ( scale2.BaseToLocal(myPosition) + span ) );
152// if ( myMax - myMin <= gp::Resolution() ) return myLast;
153// Standard_Real next = ( myMax - myMin <= gp::Resolution() ? 1. - myPosition :
154// span * ( scale2.GetLast() - scale2.GetFirst() ) /
155// ( scale2.GetMax() - scale2.GetMin() ) );
156// scale.SetSpan ( myPosition, myPosition + next );
157 return myPosition < 1.;
158}
159
160//=======================================================================
161//function : UserBreak
162//purpose :
163//=======================================================================
164
165Standard_Boolean Message_ProgressIndicator::UserBreak ()
166{
167 return Standard_False;
168}
169