summaryrefslogtreecommitdiff
path: root/src/Message/Message_ProgressIndicator.cxx
blob: bbb7b1aa189fde41a286eff123e3548cef892cdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <Message_ProgressIndicator.ixx>

//=======================================================================
//function : Message_ProgressIndicator
//purpose  : 
//=======================================================================

Message_ProgressIndicator::Message_ProgressIndicator ()
{
  Reset();
}

//=======================================================================
//function : Reset
//purpose  : 
//=======================================================================

void Message_ProgressIndicator::Reset ()
{
  myPosition = 0.;
  
  Message_ProgressScale scale;
  scale.SetName ( "Step" );
  scale.SetSpan ( 0., 1. );

  myScopes.Clear();
  myScopes.Append ( scale );
}

//=======================================================================
//function : SetScale
//purpose  : 
//=======================================================================

void Message_ProgressIndicator::SetScale (const Standard_Real min, 
                                           const Standard_Real max, 
                                           const Standard_Real step,
                                           const Standard_Boolean isInf)
{
  Message_ProgressScale &scale = myScopes.ChangeValue(1);
  scale.SetRange ( min, max );
  scale.SetStep ( step );
  scale.SetInfinite ( isInf );  
}
    
//=======================================================================
//function : GetScale
//purpose  : 
//=======================================================================

void Message_ProgressIndicator::GetScale (Standard_Real &min, 
                                           Standard_Real &max, 
                                           Standard_Real &step,
                                           Standard_Boolean &isInf) const
{
  const Message_ProgressScale &scale = myScopes(1);
  min   = scale.GetMin();
  max   = scale.GetMax();
  step  = scale.GetStep();
  isInf = scale.GetInfinite();
}
	
//=======================================================================
//function : SetValue
//purpose  : 
//=======================================================================

void Message_ProgressIndicator::SetValue (const Standard_Real val)
{
  const Message_ProgressScale &scale = myScopes(1);
  Standard_Real p = scale.LocalToBase ( val );
  if ( myPosition < p ) {
    myPosition = Min ( p, 1. );
    Show(Standard_False);
  }
}

//=======================================================================
//function : GetValue
//purpose  : 
//=======================================================================

Standard_Real Message_ProgressIndicator::GetValue () const
{
  return myScopes(1).BaseToLocal ( myPosition );
}
    
//=======================================================================
//function : NewScope
//purpose  : 
//=======================================================================

Standard_Boolean Message_ProgressIndicator::NewScope (const Standard_Real span,
                                                       const Handle(TCollection_HAsciiString) &name)
{
  Message_ProgressScale scale;
  scale.SetName ( name );
  scale.SetSpan ( myPosition, myScopes(1).LocalToBase ( GetValue() + span ) );
  myScopes.Prepend ( scale );
//  Show(Standard_False); // to update textual representation, if any
  return myPosition < 1.;
}

//=======================================================================
//function : EndScope
//purpose  : 
//=======================================================================

Standard_Boolean Message_ProgressIndicator::EndScope ()
{
  Standard_Real end = myScopes(1).GetLast();
  Standard_Boolean ret = ( myScopes.Length() >1 );
  if ( ret ) myScopes.Remove(1);
  if ( myPosition != end ) {
    myPosition = end;
    Show(Standard_False);
  }
  return ret;
}

//=======================================================================
//function : NextScope
//purpose  : 
//=======================================================================

Standard_Boolean Message_ProgressIndicator::NextScope (const Standard_Real span, 
                                                        const Standard_CString name)
{
  Message_ProgressScale &scale = myScopes.ChangeValue(1);
  if ( myPosition != scale.GetLast() ) {
    myPosition = scale.GetLast();
    Show(Standard_False);
  }
  if ( myScopes.Length() <2 ) return Standard_False;

  if ( name ) scale.SetName ( name );
  const Message_ProgressScale &scale2 = myScopes(2);
  scale.SetSpan ( myPosition, scale2.LocalToBase ( scale2.BaseToLocal(myPosition) + span ) );
//   if ( myMax - myMin <= gp::Resolution() ) return myLast;
//   Standard_Real next = ( myMax - myMin <= gp::Resolution() ? 1. - myPosition :
//                          span * ( scale2.GetLast() - scale2.GetFirst() ) / 
//                                 ( scale2.GetMax()  - scale2.GetMin() ) );
//   scale.SetSpan ( myPosition, myPosition + next );
  return myPosition < 1.;
}

//=======================================================================
//function : UserBreak
//purpose  : 
//=======================================================================

Standard_Boolean Message_ProgressIndicator::UserBreak () 
{
  return Standard_False;
}