@@ -1003,5 +1003,361 @@ Dlg_Operation_histo2ds::Dlg_Operation_histo2ds(
1003
1003
1004
1004
}
1005
1005
1006
+
1007
+
1008
+
1009
+ // ///////////////////////////////////////////////////////////////////////////////////
1010
+
1011
+
1012
+ // for Expand_2d_dlg()
1013
+
1014
+ class Dlg_Set_XYRange : public TGMainFrame {
1015
+
1016
+ private:
1017
+ int fFocus ;
1018
+ float fPrimitive_xmin ;
1019
+ float fPrimitive_ymin ;
1020
+ float fPrimitive_xmax ;
1021
+ float fPrimitive_ymax ;
1022
+
1023
+ float * fxUserMax;
1024
+ float * fxUserMin;
1025
+ float * fyUserMax;
1026
+ float * fyUserMin;
1027
+
1028
+
1029
+
1030
+ TString fxEntry_out;
1031
+ TString fyEntry_out;
1032
+ TGHorizontalFrame* fxHF;
1033
+ TGHorizontalFrame* fyHF;
1034
+ TGHorizontalFrame* fHF_btns ;
1035
+ TGLabel* fxLabel;
1036
+ TGLabel* fyLabel;
1037
+
1038
+ TGTextEntry* fxTextEntries;
1039
+ TGTextEntry* fyTextEntries;
1040
+
1041
+
1042
+ TGTextButton* fBtn_close ;
1043
+ TGTextButton* fBtn_cancel ;
1044
+
1045
+
1046
+
1047
+ public:
1048
+
1049
+ // class constructor
1050
+ Dlg_Set_XYRange ( const TGWindow* p,
1051
+ UInt_t w,
1052
+ UInt_t h,
1053
+ float primitive_xmin,
1054
+ float primitive_xmax,
1055
+ float & user_xmin,
1056
+ float & user_xmax,
1057
+ float primitive_ymin,
1058
+ float primitive_ymax,
1059
+ float & user_ymin,
1060
+ float & user_ymax );
1061
+
1062
+ void To_response_key ( Event_t* );
1063
+
1064
+ void To_focus_on_entry ( Event_t* );
1065
+
1066
+ void Cancel ();
1067
+
1068
+ void CloseWindow ();
1069
+
1070
+ void Change_focus ();
1071
+
1072
+ void Update_marker ();
1073
+
1074
+ void Update_entry_output_x ( char * entry_output );
1075
+
1076
+ void Update_entry_output_y ( char * entry_output );
1077
+
1078
+ private:
1079
+
1080
+ vector<const char *> ToParseString ( TString , const char * );
1081
+
1082
+ };
1083
+
1084
+
1085
+
1086
+
1087
+ void Dlg_Set_XYRange::Update_entry_output_x ( char * entry_output ) {
1088
+
1089
+ fxEntry_out = entry_output;
1090
+ }
1091
+
1092
+
1093
+ void Dlg_Set_XYRange::Update_entry_output_y ( char * entry_output ) {
1094
+
1095
+ fyEntry_out = entry_output;
1096
+ }
1097
+
1098
+
1099
+ // my function to parse a TString which is split by delim
1100
+ vector<const char *> Dlg_Set_XYRange::ToParseString
1101
+ ( TString s_input , const char * delim )
1102
+ {
1103
+
1104
+ TObjArray* objarray = s_input.Tokenize ( delim );
1105
+ Int_t substringN = objarray->GetEntries ();
1106
+ vector<const char *> substrings;
1107
+
1108
+
1109
+
1110
+ for ( Int_t i = 0 ; i < substringN; i++ )
1111
+ {
1112
+ TString tmp = ( (TObjString*)objarray->At (i) ) -> GetString ();
1113
+
1114
+ substrings.push_back ( Form ( " %s" , tmp.Data () ) );
1115
+
1116
+ }
1117
+
1118
+ return substrings;
1119
+ }
1120
+
1121
+
1122
+
1123
+ void Dlg_Set_XYRange::Update_marker ( ){
1124
+
1125
+ bool done_x = false ;
1126
+ bool done_y = false ;
1127
+
1128
+ if ( fxEntry_out != " " )
1129
+ {
1130
+
1131
+ vector<const char *> ranges = ToParseString ( fxEntry_out, " " );
1132
+ if ( ranges.size ()>=2 ) {
1133
+ TString s1 = ranges[0 ] ;
1134
+ TString s2 = ranges[1 ] ;
1135
+
1136
+ *fxUserMax = TMath::Max ( s1.Atof (), s2.Atof () );
1137
+ *fxUserMin = TMath::Min ( s1.Atof (), s2.Atof () );
1138
+ if ( *fxUserMax > fPrimitive_xmax ) { *fxUserMax = fPrimitive_xmax ; }
1139
+ if ( *fxUserMin < fPrimitive_xmin ) { *fxUserMin = fPrimitive_xmin ; }
1140
+ done_x = true ;
1141
+ }
1142
+
1143
+ }
1144
+
1145
+
1146
+ if ( fyEntry_out != " " )
1147
+ {
1148
+
1149
+ vector<const char *> ranges = ToParseString ( fyEntry_out, " " );
1150
+ if ( ranges.size ()>=2 ) {
1151
+ TString s1 = ranges[0 ] ;
1152
+ TString s2 = ranges[1 ] ;
1153
+
1154
+ *fyUserMax = TMath::Max ( s1.Atof (), s2.Atof () );
1155
+ *fyUserMin = TMath::Min ( s1.Atof (), s2.Atof () );
1156
+ if ( *fyUserMax > fPrimitive_ymax ) { *fyUserMax = fPrimitive_ymax ; }
1157
+ if ( *fyUserMin < fPrimitive_ymin ) { *fyUserMin = fPrimitive_ymin ; }
1158
+ done_y = true ;
1159
+
1160
+ }
1161
+
1162
+ }
1163
+
1164
+ if ( done_x && done_y ) { CloseWindow (); }
1165
+
1166
+ }
1167
+
1168
+
1169
+
1170
+ void Dlg_Set_XYRange::Cancel (){
1171
+
1172
+ *fxUserMax = 0 ;
1173
+ *fxUserMin = 0 ;
1174
+ *fyUserMax = 0 ;
1175
+ *fyUserMin = 0 ;
1176
+ CloseWindow ();
1177
+
1178
+
1179
+ }
1180
+
1181
+
1182
+ void Dlg_Set_XYRange::CloseWindow (){
1183
+
1184
+
1185
+ fBtn_close ->SetState (kButtonDisabled ); // to avoid double click.
1186
+ fBtn_cancel ->SetState (kButtonDisabled );
1187
+ DeleteWindow ();
1188
+
1189
+
1190
+ }
1191
+
1192
+
1193
+ void Dlg_Set_XYRange::Change_focus ( ) {
1194
+
1195
+ fFocus += 1 ;
1196
+ if ( fFocus % 2 == 0 ) {
1197
+ fyTextEntries->SetFocus ();
1198
+ fyTextEntries->SelectAll ();
1199
+ } else {
1200
+ fxTextEntries->SetFocus ();
1201
+ fxTextEntries->SelectAll ();
1202
+ }
1203
+ }
1204
+
1205
+
1206
+ void Dlg_Set_XYRange::To_focus_on_entry ( Event_t* e) {
1207
+
1208
+ fxTextEntries->SetFocus ();
1209
+ fxTextEntries->SelectAll ();
1210
+ }
1211
+
1212
+
1213
+
1214
+ void Dlg_Set_XYRange::To_response_key (Event_t* e) {
1215
+
1216
+ if ( e->fType == kGKeyPress )
1217
+ {
1218
+ // using LookuString to get the key mapping.
1219
+ UInt_t key_symbol;
1220
+ char tmp[2 ];
1221
+ gVirtualX ->LookupString ( e, tmp,sizeof (tmp), key_symbol );
1222
+
1223
+ const unsigned key_enter = 36 ;
1224
+
1225
+
1226
+
1227
+ if ( key_symbol == kKey_Enter ) { Update_marker (); } // the enter key near num pad
1228
+
1229
+ else if ( e->fCode == key_enter ) { Update_marker (); } // the enter key in regular position.
1230
+
1231
+ else if ( key_symbol == kKey_Escape ) { CloseWindow (); }
1232
+
1233
+ else if ( key_symbol == kKey_Tab ) { Change_focus (); }
1234
+
1235
+ }
1236
+
1237
+ }
1238
+
1239
+
1240
+
1241
+
1242
+ // class constructor
1243
+ Dlg_Set_XYRange::Dlg_Set_XYRange ( const TGWindow* p,
1244
+ UInt_t w,
1245
+ UInt_t h,
1246
+ float primitive_xmin,
1247
+ float primitive_xmax,
1248
+ float & user_xmin,
1249
+ float & user_xmax,
1250
+ float primitive_ymin,
1251
+ float primitive_ymax,
1252
+ float & user_ymin,
1253
+ float & user_ymax )
1254
+ : TGMainFrame(p, w, h)
1255
+ {
1256
+
1257
+ fxUserMax = & user_xmax;
1258
+ fxUserMin = & user_xmin;
1259
+ fyUserMax = & user_ymax;
1260
+ fyUserMin = & user_ymin;
1261
+
1262
+ fPrimitive_xmin = primitive_xmin;
1263
+ fPrimitive_ymin = primitive_ymin;
1264
+ fPrimitive_xmax = primitive_xmax;
1265
+ fPrimitive_ymax = primitive_ymax;
1266
+
1267
+ // for user know the range
1268
+ TString xlabel_text = Form ( " [%.1f to %.1f] " , primitive_xmin, primitive_xmax );
1269
+ TString ylabel_text = Form ( " [%.1f to %.1f] " , primitive_ymin, primitive_ymax );
1270
+
1271
+
1272
+ SetCleanup (kDeepCleanup ); // important step for closing windows properly.
1273
+
1274
+ TGLayoutHints* Layout1 = new TGLayoutHints ( kLHintsCenterY , 2 , 2 , 2 , 2 );
1275
+
1276
+
1277
+ // -------------------------------------------------------------------| Label-Entry pair
1278
+
1279
+ fxHF = new TGHorizontalFrame ( this , 200 , 30 );
1280
+ AddFrame ( fxHF, Layout1 );
1281
+
1282
+ fxLabel = new TGLabel ( fxHF, xlabel_text.Data () ); /* base, text */
1283
+ fxTextEntries = new TGTextEntry ( fxHF, " " , 1 ); /* base, inital txt, ID */
1284
+ fxHF->AddFrame ( fxTextEntries, Layout1 );
1285
+ fxHF->AddFrame ( fxLabel, Layout1 );
1286
+
1287
+
1288
+
1289
+ fyHF = new TGHorizontalFrame ( this , 200 , 30 );
1290
+ AddFrame ( fyHF, Layout1 );
1291
+
1292
+ fyLabel = new TGLabel ( fyHF, ylabel_text.Data () ); /* base, text */
1293
+ fyTextEntries = new TGTextEntry ( fyHF, " " , 1 ); /* base, inital txt, ID */
1294
+ fyHF->AddFrame ( fyTextEntries, Layout1 );
1295
+ fyHF->AddFrame ( fyLabel, Layout1 );
1296
+
1297
+
1298
+
1299
+ // ------------------------------------------------------------------| Connect
1300
+ fxTextEntries
1301
+ -> Connect ( " TextChanged(char*)" ,
1302
+ " Dlg_Set_XYRange" , this , " Update_entry_output_x(char*)" );
1303
+
1304
+ fxTextEntries
1305
+ -> Connect ( " ProcessedEvent(Event_t*)" ,
1306
+ " Dlg_Set_XYRange" , this ,
1307
+ " To_response_key(Event_t*)" );
1308
+
1309
+ fyTextEntries
1310
+ -> Connect ( " TextChanged(char*)" ,
1311
+ " Dlg_Set_XYRange" , this , " Update_entry_output_y(char*)" );
1312
+
1313
+ fyTextEntries
1314
+ -> Connect ( " ProcessedEvent(Event_t*)" ,
1315
+ " Dlg_Set_XYRange" , this ,
1316
+ " To_response_key(Event_t*)" );
1317
+
1318
+
1319
+
1320
+
1321
+
1322
+ TGLayoutHints* Layout2 = new TGLayoutHints ( kLHintsExpandX , 2 , 2 , 2 , 2 );
1323
+ fHF_btns = new TGHorizontalFrame ( this , 200 , 30 );
1324
+
1325
+ // -------------------------------------------------------------------| Btn for OK
1326
+ fBtn_close = new TGTextButton ( fHF_btns , " OK" );
1327
+ fBtn_close -> Connect ( " Clicked()" , " Dlg_Set_XYRange" , this , " Update_marker()" );
1328
+ fHF_btns ->AddFrame ( fBtn_close , Layout2);
1329
+
1330
+ // -------------------------------------------------------------------| Btn for cancel the change
1331
+
1332
+ fBtn_cancel = new TGTextButton ( fHF_btns , " Cancel" );
1333
+ fBtn_cancel -> Connect ( " Clicked()" , " Dlg_Set_XYRange" , this , " Cancel()" );
1334
+ fHF_btns ->AddFrame ( fBtn_cancel , Layout2);
1335
+
1336
+
1337
+ AddFrame ( fHF_btns , Layout2);
1338
+
1339
+
1340
+
1341
+ // -----------------------------------------------------------to focus on entry
1342
+ this ->Connect ( " ProcessedEvent(Event_t*)" , " Dlg_Set_XYRange" , this ,
1343
+ " To_focus_on_entry(Event_t*)" );
1344
+
1345
+
1346
+
1347
+ SetName (" Dlg_Set_XY_Expand_Range" );
1348
+ SetWindowName (" Set XY Expand Range" );
1349
+
1350
+
1351
+ MapSubwindows ();
1352
+ Resize ( GetDefaultSize () );
1353
+ MapWindow ();
1354
+
1355
+ gClient ->WaitFor (this );
1356
+
1357
+ fFocus = 1 ;
1358
+ }
1359
+
1360
+
1361
+
1006
1362
// ///////////////////////////////////////////////////////////////////////////////////
1007
1363
0 commit comments