1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <Message_ProgressIndicator.ixx>
20 //=======================================================================
21 //function : Message_ProgressIndicator
23 //=======================================================================
25 Message_ProgressIndicator::Message_ProgressIndicator ()
30 //=======================================================================
33 //=======================================================================
35 void Message_ProgressIndicator::Reset ()
39 Message_ProgressScale scale;
40 scale.SetName ( "Step" );
41 scale.SetSpan ( 0., 1. );
44 myScopes.Append ( scale );
47 //=======================================================================
50 //=======================================================================
52 void Message_ProgressIndicator::SetScale (const Standard_Real min,
53 const Standard_Real max,
54 const Standard_Real step,
55 const Standard_Boolean isInf)
57 Message_ProgressScale &scale = myScopes.ChangeValue(1);
58 scale.SetRange ( min, max );
59 scale.SetStep ( step );
60 scale.SetInfinite ( isInf );
63 //=======================================================================
66 //=======================================================================
68 void Message_ProgressIndicator::GetScale (Standard_Real &min,
71 Standard_Boolean &isInf) const
73 const Message_ProgressScale &scale = myScopes(1);
76 step = scale.GetStep();
77 isInf = scale.GetInfinite();
80 //=======================================================================
83 //=======================================================================
85 void Message_ProgressIndicator::SetValue (const Standard_Real val)
87 const Message_ProgressScale &scale = myScopes(1);
88 Standard_Real p = scale.LocalToBase ( val );
89 if ( myPosition < p ) {
90 myPosition = Min ( p, 1. );
95 //=======================================================================
98 //=======================================================================
100 Standard_Real Message_ProgressIndicator::GetValue () const
102 return myScopes(1).BaseToLocal ( myPosition );
105 //=======================================================================
106 //function : NewScope
108 //=======================================================================
110 Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_Real span,
111 const Handle(TCollection_HAsciiString) &name)
113 Message_ProgressScale scale;
114 scale.SetName ( name );
115 scale.SetSpan ( myPosition, myScopes(1).LocalToBase ( GetValue() + span ) );
116 myScopes.Prepend ( scale );
117 // Show(Standard_False); // to update textual representation, if any
118 return myPosition < 1.;
121 //=======================================================================
122 //function : EndScope
124 //=======================================================================
126 Standard_Boolean Message_ProgressIndicator::EndScope ()
128 Standard_Real end = myScopes(1).GetLast();
129 Standard_Boolean ret = ( myScopes.Length() >1 );
130 if ( ret ) myScopes.Remove(1);
131 if ( myPosition != end ) {
133 Show(Standard_False);
138 //=======================================================================
139 //function : NextScope
141 //=======================================================================
143 Standard_Boolean Message_ProgressIndicator::NextScope (const Standard_Real span,
144 const Standard_CString name)
146 Message_ProgressScale &scale = myScopes.ChangeValue(1);
147 if ( myPosition != scale.GetLast() ) {
148 myPosition = scale.GetLast();
149 Show(Standard_False);
151 if ( myScopes.Length() <2 ) return Standard_False;
153 if ( name ) scale.SetName ( name );
154 const Message_ProgressScale &scale2 = myScopes(2);
155 scale.SetSpan ( myPosition, scale2.LocalToBase ( scale2.BaseToLocal(myPosition) + span ) );
156 // if ( myMax - myMin <= gp::Resolution() ) return myLast;
157 // Standard_Real next = ( myMax - myMin <= gp::Resolution() ? 1. - myPosition :
158 // span * ( scale2.GetLast() - scale2.GetFirst() ) /
159 // ( scale2.GetMax() - scale2.GetMin() ) );
160 // scale.SetSpan ( myPosition, myPosition + next );
161 return myPosition < 1.;
164 //=======================================================================
165 //function : UserBreak
167 //=======================================================================
169 Standard_Boolean Message_ProgressIndicator::UserBreak ()
171 return Standard_False;