0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / Quantity / Quantity_Period.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15// -------------------------------------------------------------
7fd59977 16// C matra datavision 1993
7fd59977 17// Period class implementation.
7fd59977 18// Updated :
7fd59977 19// -------------------------------------------------------------
7fd59977 20
42cf5bc1 21#include <Quantity_Period.hxx>
22#include <Quantity_PeriodDefinitionError.hxx>
7fd59977 23
24// -----------------------------------------------------------
25// IsValid : Checks the validity of a date
26// With:
27// 0 <= dd
28// 0 <= hh
29// 0 <= mn
30// 0 <= ss
31// 0 <= mis
32// 0 <= mics
33// -----------------------------------------------------------
7fd59977 34Standard_Boolean Quantity_Period::IsValid(
35 const Standard_Integer dd,
36 const Standard_Integer hh,
37 const Standard_Integer mn,
38 const Standard_Integer ss,
39 const Standard_Integer mis,
40 const Standard_Integer mics){
41
42return ( (dd < 0 || hh < 0 || mn < 0 ||
43 ss < 0 || mis < 0 || mics < 0 ) ? Standard_False : Standard_True );
44}
45// -------------------------------------------------------------
46// IsValid : Checks the validity of a date
47// With:
48// 0 <= ss
49// 0 <= mics
50// -------------------------------------------------------------
51Standard_Boolean Quantity_Period::IsValid(
52 const Standard_Integer ss,
53 const Standard_Integer mics){
54
55return ( (ss < 0 || mics < 0 ) ? Standard_False : Standard_True );
56}
57
58// -------------------------------------------------------------
59// Create : Creates a period with a number of seconds
60// ~~~~~~ and microseconds.
61//
62// -------------------------------------------------------------
63Quantity_Period::Quantity_Period(const Standard_Integer dd,
64 const Standard_Integer hh,
65 const Standard_Integer mn,
66 const Standard_Integer ss,
67 const Standard_Integer mils,
68 const Standard_Integer mics){
69
70SetValues (dd,hh,mn,ss,mils,mics);
71}
72
73// -------------------------------------------------------------
74// Create : Creates a period with a number of seconds
75// ~~~~~~ and microseconds.
76//
77// -------------------------------------------------------------
78Quantity_Period::Quantity_Period(const Standard_Integer ss,
79 const Standard_Integer mics){
80
81 SetValues(ss,mics);
82}
83
84
85// -------------------------------------------------------------
86// Values : Returns a period with the number of days,hours,
87// ~~~~~~ minutes,seconds,milliseconds and microseconds.
88// -------------------------------------------------------------
89void Quantity_Period::Values(
90 Standard_Integer& dd,
91 Standard_Integer& hh,
92 Standard_Integer& mn,
93 Standard_Integer& ss,
94 Standard_Integer& mis,
95 Standard_Integer& mics
96 )const{
97Standard_Integer carry = mySec;
98dd = carry / ( 24 * 3600 );
99carry -= dd * 24 * 3600 ;
100hh = carry / 3600;
101carry -= 3600 * hh;
102mn = carry / 60;
103carry -= mn * 60;
104ss = carry;
105mis = myUSec / 1000;
106mics = myUSec - ( mis * 1000);
107}
108
109// -------------------------------------------------------------
110// Values : Returns a period with the number of seconds and
111// ~~~~~~ microseconds.
112// -------------------------------------------------------------
113void Quantity_Period::Values(
114 Standard_Integer& ss,
115 Standard_Integer& mics
116 )const{
117
118ss = mySec;
119mics = myUSec;
120}
121
122// -------------------------------------------------------------
123// SetValues : Sets a period with a number of days,hours,minutes,
124// ~~~~~~~~~ seconds and microseconds.
125// -------------------------------------------------------------
126void Quantity_Period::SetValues( const Standard_Integer dd,
127 const Standard_Integer hh,
128 const Standard_Integer mn,
129 const Standard_Integer ss,
130 const Standard_Integer mils,
131 const Standard_Integer mics){
132SetValues( ( dd * 24 * 3600 ) + ( hh * 3600 ) + ( 60 * mn ) + ss ,
133 mils * 1000 + mics );
134}
135
136// -------------------------------------------------------------
137// SetValues : Sets a period with a number of seconds and
138// ~~~~~~~~~ microseconds.
139// -------------------------------------------------------------
140void Quantity_Period::SetValues(
141 const Standard_Integer ss,
142 const Standard_Integer mics) {
143
144if ( ! Quantity_Period::IsValid(ss,mics) )
145 Quantity_PeriodDefinitionError::Raise(
146 "Quantity_Period::SetValues invalid parameters");
147
148mySec = ss;
149myUSec = mics;
150while ( myUSec > 1000000 )
151 {
152 myUSec -= 1000000;
153 mySec++;
154 }
155}
156// -------------------------------------------------------------
157// Subtract : Subtracts a period to another period
158// ~~~~~~~~
159// -------------------------------------------------------------
160Quantity_Period Quantity_Period::Subtract(const Quantity_Period&
161 OtherPeriod)const{
162Quantity_Period result (mySec,myUSec);
163
164
165result.mySec -= OtherPeriod.mySec;
166result.myUSec -= OtherPeriod.myUSec;
167
168if ( result.mySec >= 0 && result.myUSec < 0 ) {
169 result.mySec--;
170 result.myUSec = 1000000 + result.myUSec ;
171 }
172else if ( result.mySec <0 && result.myUSec >= 0 ) {
173 result.mySec = Abs(result.mySec);
174 if ( result.myUSec > 0 ){
175 result.mySec--;
176 result.myUSec = 1000000 - result.myUSec ;
177 }
178}
179else if ( result.mySec <0 && result.myUSec < 0 ) {
180 result.mySec = Abs(result.mySec);
181 result.myUSec = Abs(result.myUSec);
182}
183return (result);
184}
185
186// -------------------------------------------------------------
187// Add : Adds a period to another period
188// ~~~
189// -------------------------------------------------------------
190Quantity_Period Quantity_Period::Add(const Quantity_Period& OtherPeriod)
191 const{
192
193Quantity_Period result (mySec,myUSec);
194result.mySec += OtherPeriod.mySec;
195result.myUSec += OtherPeriod.myUSec;
196if (result.myUSec > 1000000)
197 {
198 result.myUSec -= 1000000;
199 result.mySec++;
200 }
201return (result);
202}
203
204
205// -------------------------------------------------------------
206// IsEqual : returns true if two periods are equal
207// ~~~~~~~
208// -------------------------------------------------------------
209Standard_Boolean Quantity_Period::IsEqual(const Quantity_Period&
210 OtherPeriod)const{
211
212return
213( ( mySec == OtherPeriod.mySec &&
214 myUSec == OtherPeriod.myUSec ) ? Standard_True : Standard_False);
215}
216
217
218// -------------------------------------------------------------
219// IsShorter : returns true if a date is shorter then an other
220// ~~~~~~~~~ date
221// -------------------------------------------------------------
222Standard_Boolean Quantity_Period::IsShorter(
223 const Quantity_Period& OtherPeriod)const{
224
225if ( mySec < OtherPeriod.mySec ) return Standard_True;
226else if ( mySec > OtherPeriod.mySec ) return Standard_False;
227else return
228 ( ( myUSec < OtherPeriod.myUSec ) ? Standard_True : Standard_False);
229}
230
231
232// -------------------------------------------------------------
233// IsLonger : returns true if a date is longer then an other
234// ~~~~~~~~ date
235// -------------------------------------------------------------
236Standard_Boolean Quantity_Period::IsLonger(
237 const Quantity_Period& OtherPeriod)const{
238
239if ( mySec > OtherPeriod.mySec ) return Standard_True;
240else if ( mySec < OtherPeriod.mySec ) return Standard_False;
241else return
242 ( ( myUSec > OtherPeriod.myUSec ) ? Standard_True : Standard_False);
243}
244
245