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.
15 #include <Message_ProgressIndicator.hxx>
16 #include <Message_ProgressScale.hxx>
17 #include <Standard_Type.hxx>
18 #include <TCollection_HAsciiString.hxx>
20 IMPLEMENT_STANDARD_RTTIEXT(Message_ProgressIndicator,Standard_Transient)
22 //=======================================================================
23 //function : Message_ProgressIndicator
25 //=======================================================================
26 Message_ProgressIndicator::Message_ProgressIndicator ()
31 //=======================================================================
34 //=======================================================================
36 void Message_ProgressIndicator::Reset ()
40 Message_ProgressScale scale;
41 scale.SetName ( "Step" );
42 scale.SetSpan ( 0., 1. );
45 myScopes.Append ( scale );
48 //=======================================================================
51 //=======================================================================
53 void Message_ProgressIndicator::SetScale (const Standard_Real min,
54 const Standard_Real max,
55 const Standard_Real step,
56 const Standard_Boolean isInf)
58 Message_ProgressScale &scale = myScopes.ChangeValue(1);
59 scale.SetRange ( min, max );
60 scale.SetStep ( step );
61 scale.SetInfinite ( isInf );
64 //=======================================================================
67 //=======================================================================
69 void Message_ProgressIndicator::GetScale (Standard_Real &min,
72 Standard_Boolean &isInf) const
74 const Message_ProgressScale &scale = myScopes(1);
77 step = scale.GetStep();
78 isInf = scale.GetInfinite();
81 //=======================================================================
84 //=======================================================================
86 void Message_ProgressIndicator::SetValue (const Standard_Real val)
88 const Message_ProgressScale &scale = myScopes(1);
89 Standard_Real p = scale.LocalToBase ( val );
90 if ( myPosition < p ) {
91 myPosition = Min ( p, 1. );
96 //=======================================================================
99 //=======================================================================
101 Standard_Real Message_ProgressIndicator::GetValue () const
103 return myScopes(1).BaseToLocal ( myPosition );
106 //=======================================================================
107 //function : NewScope
109 //=======================================================================
111 Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_Real span,
112 const Handle(TCollection_HAsciiString) &name)
114 Message_ProgressScale scale;
115 scale.SetName ( name );
116 scale.SetSpan ( myPosition, myScopes(1).LocalToBase ( GetValue() + span ) );
117 myScopes.Prepend ( scale );
118 Show(Standard_False); // to update textual representation, if any
119 return myPosition < 1.;
122 //=======================================================================
123 //function : EndScope
125 //=======================================================================
127 Standard_Boolean Message_ProgressIndicator::EndScope ()
129 Standard_Real end = myScopes(1).GetLast();
130 Standard_Boolean ret = ( myScopes.Length() >1 );
131 if ( ret ) myScopes.Remove(1);
132 if ( myPosition != end ) {
134 Show(Standard_False);
139 //=======================================================================
140 //function : NextScope
142 //=======================================================================
144 Standard_Boolean Message_ProgressIndicator::NextScope (const Standard_Real span,
145 const Standard_CString name)
147 Message_ProgressScale &scale = myScopes.ChangeValue(1);
148 if ( myPosition != scale.GetLast() ) {
149 myPosition = scale.GetLast();
150 Show(Standard_False);
152 if ( myScopes.Length() <2 ) return Standard_False;
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.;
165 //=======================================================================
166 //function : UserBreak
168 //=======================================================================
170 Standard_Boolean Message_ProgressIndicator::UserBreak ()
172 return Standard_False;