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