Skip to content

Commit db6ff45

Browse files
authored
[TGNumberEntry] add centisecond display option
Adds support for centiseconds in TGNumberentry.
1 parent a10884c commit db6ff45

File tree

3 files changed

+80
-10
lines changed

3 files changed

+80
-10
lines changed

documentation/users-guide/WritingGUI.md

+2
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,8 @@ The following styles are supported:
16761676

16771677
- `kNESMinSec` - time in minutes:seconds format
16781678

1679+
- `kNESMinSecCent` - time in minutes:seconds.centiseconds format
1680+
16791681
- `kNESHourMin` - time in hour:minutes format
16801682

16811683
- `kNESHourMinSec` - time in hour:minutes:seconds format

gui/gui/inc/TGNumberEntry.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class TGNumberFormat {
3434
kNESHourMinSec = 9, ///< Hour:minute:seconds
3535
kNESDayMYear = 10, ///< Day/month/year
3636
kNESMDayYear = 11, ///< Month/day/year
37-
kNESHex = 12 ///< Hex
37+
kNESHex = 12, ///< Hex
38+
kNESMinSecCent = 13 ///< Minute:seconds.centiseconds
3839
};
3940

4041
enum EAttribute { ///< Attributes of number entry field
@@ -147,7 +148,7 @@ class TGNumberEntry : public TGCompositeFrame, public TGWidget,
147148
public TGNumberFormat {
148149

149150
// dummy data members - just to say about options for context menu
150-
EStyle fNumStyle;//*OPTION={GetMethod="GetNumStyle";SetMethod="SetNumStyle";Items=(0="Int",5="Real",6="Degree",9="Hour:Min:Sec",10="Day/Month/Year",12="Hex")}*
151+
EStyle fNumStyle;//*OPTION={GetMethod="GetNumStyle";SetMethod="SetNumStyle";Items=(0="Int",5="Real",6="Degree",9="Hour:Min:Sec",10="Day/Month/Year",12="Hex",13="Min:Sec.Centisec")}*
151152
EAttribute fNumAttr; // *OPTION={GetMethod="GetNumAttr";SetMethod="SetNumAttr";Items=(0="&AnyNumber",1="&Non negative",2="&Positive")}*
152153
ELimit fNumLimits; // *OPTION={GetMethod="GetNumLimits";SetMethod="SetNumLimits";Items=(0="&No Limits",1="Limit M&in",2="Limit M&ax",2="Min &and Max")}*
153154

gui/gui/src/TGNumberEntry.cxx

+75-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The following styles are supported:
3232
- kNESReal: arbitrary real number
3333
- kNESDegree: angle in degree:minutes:seconds format
3434
- kNESMinSec: time in minutes:seconds format
35+
- kNESMinSecCent: time in minutes:seconds.centiseconds format
3536
- kNESHourMin: time in hour:minutes format
3637
- kNESHourMinSec: time in hour:minutes:seconds format
3738
- kNESDayMYear: date in day/month/year format
@@ -184,7 +185,8 @@ static Bool_t IsGoodChar(char c, TGNumberFormat::EStyle style,
184185
(style == TGNumberFormat::kNESRealFour) ||
185186
(style == TGNumberFormat::kNESReal) ||
186187
(style == TGNumberFormat::kNESDegree) ||
187-
(style == TGNumberFormat::kNESMinSec)) &&
188+
(style == TGNumberFormat::kNESMinSec) ||
189+
(style == TGNumberFormat::kNESMinSecCent)) &&
188190
(attr == TGNumberFormat::kNEAAnyNumber)) {
189191
return kTRUE;
190192
}
@@ -199,6 +201,7 @@ static Bool_t IsGoodChar(char c, TGNumberFormat::EStyle style,
199201
(style == TGNumberFormat::kNESReal) ||
200202
(style == TGNumberFormat::kNESDegree) ||
201203
(style == TGNumberFormat::kNESMinSec) ||
204+
(style == TGNumberFormat::kNESMinSecCent) ||
202205
(style == TGNumberFormat::kNESHourMin) ||
203206
(style == TGNumberFormat::kNESHourMinSec) ||
204207
(style == TGNumberFormat::kNESDayMYear) ||
@@ -208,6 +211,7 @@ static Bool_t IsGoodChar(char c, TGNumberFormat::EStyle style,
208211
if ((c == ':') &&
209212
((style == TGNumberFormat::kNESDegree) ||
210213
(style == TGNumberFormat::kNESMinSec) ||
214+
(style == TGNumberFormat::kNESMinSecCent) ||
211215
(style == TGNumberFormat::kNESHourMin) ||
212216
(style == TGNumberFormat::kNESHourMinSec) ||
213217
(style == TGNumberFormat::kNESDayMYear) ||
@@ -504,6 +508,22 @@ static char *DIntToStr(char *text, Long_t l, Bool_t Sec, char Del)
504508
return text;
505509
}
506510

511+
////////////////////////////////////////////////////////////////////////////////
512+
/// For kNESMinSecCent
513+
514+
static char *DIntToStr(char *text, Long_t l, char Del, char Del2)
515+
{
516+
TString s;
517+
s = StringInt(TMath::Abs(l) / 6000, 0) + Del +
518+
StringInt((TMath::Abs(l) % 6000) / 100, 2) + Del2 +
519+
StringInt(TMath::Abs(l) % 100, 2);
520+
if (l < 0) {
521+
s = "-" + s;
522+
}
523+
strlcpy(text, (const char *) s, 256);
524+
return text;
525+
}
526+
507527
////////////////////////////////////////////////////////////////////////////////
508528

509529
static void GetNumbers(const char *s, Int_t & Sign,
@@ -657,6 +677,10 @@ static Long_t TranslateToNum(const char *text,
657677
case TGNumberFormat::kNESMinSec:
658678
GetNumbers(text, sign, n1, 12, n2, 2, n3, 0, ".,:");
659679
return sign * (60 * n1 + GetSignificant(n2, 60));
680+
case TGNumberFormat::kNESMinSecCent:
681+
GetNumbers(text, sign, n1, 12, n2, 2, n3, 2, ".,:");
682+
return 6000 * n1 + 100*GetSignificant(n2, 60) +
683+
GetSignificant(n3, 100);
660684
case TGNumberFormat::kNESHourMin:
661685
GetNumbers(text, sign, n1, 12, n2, 2, n3, 0, ".,:");
662686
return 60 * n1 + GetSignificant(n2, 60);
@@ -697,6 +721,8 @@ static char *TranslateToStr(char *text, Long_t l,
697721
return DIntToStr(text, l % (24 * 3600), kTRUE, ':');
698722
case TGNumberFormat::kNESMinSec:
699723
return DIntToStr(text, l, kFALSE, ':');
724+
case TGNumberFormat::kNESMinSecCent:
725+
return DIntToStr(text, l % (60 * 6000), ':', '.');
700726
case TGNumberFormat::kNESHourMin:
701727
return DIntToStr(text, l % (24 * 60), kFALSE, ':');
702728
case TGNumberFormat::kNESDayMYear:
@@ -1146,6 +1172,9 @@ void TGNumberEntryField::SetNumber(Double_t val, Bool_t emit)
11461172
case kNESMinSec:
11471173
SetIntNumber(Round(val), emit);
11481174
break;
1175+
case kNESMinSecCent:
1176+
SetIntNumber(Round(val), emit);
1177+
break;
11491178
case kNESHourMin:
11501179
SetIntNumber(Round(val), emit);
11511180
break;
@@ -1177,7 +1206,8 @@ void TGNumberEntryField::SetIntNumber(Long_t val, Bool_t emit)
11771206
}
11781207

11791208
////////////////////////////////////////////////////////////////////////////////
1180-
/// Set the numeric value (time format).
1209+
/// Set the numeric value (time format). In case of kNESMinSecCent, pass the
1210+
/// centiseconds in the hour variable.
11811211

11821212
void TGNumberEntryField::SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit)
11831213
{
@@ -1187,10 +1217,11 @@ void TGNumberEntryField::SetTime(Int_t hour, Int_t min, Int_t sec, Bool_t emit)
11871217
TMath::Abs(sec), emit);
11881218
break;
11891219
case kNESMinSec:
1190-
{
1191-
SetIntNumber(60 * min + sec, emit);
1192-
break;
1193-
}
1220+
SetIntNumber(60 * TMath::Abs(min) + TMath::Abs(sec), emit);
1221+
break;
1222+
case kNESMinSecCent:
1223+
SetIntNumber(6000 *TMath::Abs(min) + 100 * TMath::Abs(sec) + TMath::Abs(hour), emit);
1224+
break;
11941225
case kNESHourMin:
11951226
SetIntNumber(60 * TMath::Abs(hour) + TMath::Abs(min), emit);
11961227
break;
@@ -1267,6 +1298,8 @@ Double_t TGNumberEntryField::GetNumber() const
12671298
return (Double_t) GetIntNumber();
12681299
case kNESMinSec:
12691300
return (Double_t) GetIntNumber();
1301+
case kNESMinSecCent:
1302+
return (Double_t) GetIntNumber();
12701303
case kNESHourMin:
12711304
return (Double_t) GetIntNumber();
12721305
case kNESDayMYear:
@@ -1289,7 +1322,8 @@ Long_t TGNumberEntryField::GetIntNumber() const
12891322
}
12901323

12911324
////////////////////////////////////////////////////////////////////////////////
1292-
/// Get the numeric value (time format).
1325+
/// Get the numeric value (time format). In case of kNESMinSecCent, the first
1326+
/// variable (hour) will store instead the centiseconds.
12931327

12941328
void TGNumberEntryField::GetTime(Int_t & hour, Int_t & min, Int_t & sec) const
12951329
{
@@ -1314,6 +1348,14 @@ void TGNumberEntryField::GetTime(Int_t & hour, Int_t & min, Int_t & sec) const
13141348
}
13151349
break;
13161350
}
1351+
case kNESMinSecCent:
1352+
{
1353+
Long_t l = GetIntNumber();
1354+
min = TMath::Abs(l) / 6000;
1355+
sec = (TMath::Abs(l) % 60) / 100;
1356+
hour = TMath::Abs(l) % 100;// centisec is stored in variable named hour
1357+
break;
1358+
}
13171359
case kNESHourMin:
13181360
{
13191361
Long_t l = GetIntNumber();
@@ -1398,7 +1440,7 @@ void TGNumberEntryField::IncreaseNumber(EStepSize step,
13981440
if ((fNumStyle == kNESDegree) || (fNumStyle == kNESHourMinSec) ||
13991441
(fNumStyle == kNESMinSec) || (fNumStyle == kNESHourMin) ||
14001442
(fNumStyle == kNESDayMYear) || (fNumStyle == kNESMDayYear) ||
1401-
(fNumStyle == kNESHex)) {
1443+
(fNumStyle == kNESHex) || (fNumStyle == kNESMinSecCent)) {
14021444
logstep = kFALSE;
14031445
switch (step) {
14041446
case kNSSSmall:
@@ -1518,6 +1560,21 @@ void TGNumberEntryField::IncreaseNumber(EStepSize step,
15181560
l = 1;
15191561
break;
15201562
}
1563+
case kNESMinSecCent:
1564+
{
1565+
if (mag > 60)
1566+
l += sign * 36 * mag;
1567+
else if (mag > 6)
1568+
l += sign * 6 * mag;
1569+
else
1570+
l += sign * mag;
1571+
CheckMinMax(l, fNumStyle, fNumLimits, fNumMin, fNumMax);
1572+
if (l < 0)
1573+
l = (60 * 6000) - ((-l) % (60 * 6000));
1574+
if (l > 0)
1575+
l = l % (60 * 6000);
1576+
break;
1577+
}
15211578
case kNESHourMin:
15221579
{
15231580
if (mag > 6)
@@ -2185,6 +2242,11 @@ void TGNumberEntry::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
21852242
out << min*60 + sec << "," << digits << "," << WidgetId()
21862243
<< ",(TGNumberFormat::EStyle) " << GetNumStyle();
21872244
break;
2245+
case kNESMinSecCent:
2246+
//GetTime returns the centisecs in the hour variable
2247+
out << min*6000 + sec*100 + hour << "," << digits << "," << WidgetId()
2248+
<< ",(TGNumberFormat::EStyle) " << GetNumStyle();
2249+
break;
21882250
case kNESHourMin:
21892251
out << hour*60 + min << "," << digits << "," << WidgetId()
21902252
<< ",(TGNumberFormat::EStyle) " << GetNumStyle();
@@ -2300,6 +2362,11 @@ void TGNumberEntryField::SavePrimitive(std::ostream &out, Option_t *option /*= "
23002362
out << min*60 + sec
23012363
<< ",(TGNumberFormat::EStyle) " << GetNumStyle();
23022364
break;
2365+
case kNESMinSecCent:
2366+
//GetTime returns centisec in the hour variable
2367+
out << min*6000 + sec*100 + hour
2368+
<< ",(TGNumberFormat::EStyle) " << GetNumStyle();
2369+
break;
23032370
case kNESHourMin:
23042371
out << hour*60 + min
23052372
<< ",(TGNumberFormat::EStyle) " << GetNumStyle();

0 commit comments

Comments
 (0)