1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Message_ProgressIndicator.ixx>
16 //=======================================================================
17 //function : Message_ProgressIndicator
19 //=======================================================================
21 Message_ProgressIndicator::Message_ProgressIndicator ()
26 //=======================================================================
29 //=======================================================================
31 void Message_ProgressIndicator::Reset ()
35 Message_ProgressScale scale;
36 scale.SetName ( "Step" );
37 scale.SetSpan ( 0., 1. );
40 myScopes.Append ( scale );
43 //=======================================================================
46 //=======================================================================
48 void Message_ProgressIndicator::SetScale (const Standard_Real min,
49 const Standard_Real max,
50 const Standard_Real step,
51 const Standard_Boolean isInf)
53 Message_ProgressScale &scale = myScopes.ChangeValue(1);
54 scale.SetRange ( min, max );
55 scale.SetStep ( step );
56 scale.SetInfinite ( isInf );
59 //=======================================================================
62 //=======================================================================
64 void Message_ProgressIndicator::GetScale (Standard_Real &min,
67 Standard_Boolean &isInf) const
69 const Message_ProgressScale &scale = myScopes(1);
72 step = scale.GetStep();
73 isInf = scale.GetInfinite();
76 //=======================================================================
79 //=======================================================================
81 void Message_ProgressIndicator::SetValue (const Standard_Real val)
83 const Message_ProgressScale &scale = myScopes(1);
84 Standard_Real p = scale.LocalToBase ( val );
85 if ( myPosition < p ) {
86 myPosition = Min ( p, 1. );
91 //=======================================================================
94 //=======================================================================
96 Standard_Real Message_ProgressIndicator::GetValue () const
98 return myScopes(1).BaseToLocal ( myPosition );
101 //=======================================================================
102 //function : NewScope
104 //=======================================================================
106 Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_Real span,
107 const Handle(TCollection_HAsciiString) &name)
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.;
117 //=======================================================================
118 //function : EndScope
120 //=======================================================================
122 Standard_Boolean Message_ProgressIndicator::EndScope ()
124 Standard_Real end = myScopes(1).GetLast();
125 Standard_Boolean ret = ( myScopes.Length() >1 );
126 if ( ret ) myScopes.Remove(1);
127 if ( myPosition != end ) {
129 Show(Standard_False);
134 //=======================================================================
135 //function : NextScope
137 //=======================================================================
139 Standard_Boolean Message_ProgressIndicator::NextScope (const Standard_Real span,
140 const Standard_CString name)
142 Message_ProgressScale &scale = myScopes.ChangeValue(1);
143 if ( myPosition != scale.GetLast() ) {
144 myPosition = scale.GetLast();
145 Show(Standard_False);
147 if ( myScopes.Length() <2 ) return Standard_False;
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.;
160 //=======================================================================
161 //function : UserBreak
163 //=======================================================================
165 Standard_Boolean Message_ProgressIndicator::UserBreak ()
167 return Standard_False;