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