-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIPControls.ipf
executable file
·3620 lines (3451 loc) · 173 KB
/
GUIPControls.ipf
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma rtGlobals=3 // Use modern global access method.
#pragma IgorVersion=6.1
#pragma version = 1 // Last Modified: 2017/08/12 by Jamie Boyd
#pragma ModuleName= GUIPControls
#include "GUIPList"
#include "GUIPprotoFuncs"
#include "GUIPMath"
//********************************************************************************************************
//**********************************************GUIPSetVar**************************************************
// GUIPSIsetVarProc is a SetVariable Proc for SI Prefixes with Wavemetrics' %w Conversion Specifier
// The %w formatting specifier prints very large or small numbers in an easily readable manner using an SI prefix such as µ, m, k, M, etc
// It would be nice to use this in a setvariable control, especially if a large range of numbers might be displayed. Unfortunately, the manual says:
// "Never use leading text or the "%W" format for numbers, because Igor reads the value back without interpreting the extra text."
// This procedure provides a work-around for that behaviour
// Igor's usual handling variable minimum and maximum can cause problems when users enter values in the setvariable, so leave them
// as default values of -INF and +INF. The procedure handles Minimum and Maximum values set in the userdata, as 3rd and 4th items in
// the semicolon-separated list.
// pressing command/ctrl when clicking on the setvariable means multiply the current setvariable increment by 10
// option/Alt means divide the increment by10
// shift-command/ctrl means multiply by 100
// shift-option/alt means divide by 100
// To Summarize
// Set formatting string to something like "%.0W1Ps".
// Set setvariable procedure to SIformattedSetVarProc
//
// If desired, put name of another function to run in the userdata for the setvariable
// Put Min and Max values for the setvariable in the user data separated by semicolons from each other and the additional procedure
//*****************************************************************************************************
// The Setvariable procedure reads and interprets the SI prefix
// userdata: 0 = additional funtion to run; 1= min; 2= max;3 = addjust increment if equals "autoInc";4=allow user to change unit string is equals "adjustUnits"
Function GUIPSIsetVarProc(sva) : SetVariableControl
STRUCT WMSetVariableAction &sva
switch( sva.eventCode )
case 1: // mouse up
#if IgorVersion() < 7.00
case 2: // Enter key not neded in Igor 7 because we always get a finish edit
#else
case 8: // finish edit
#endif
case 3: // Live update
//printf "%.12f\r", sva.dVal
/// get user data for extra function and max and min
string addFuncStr = stringfromlist (0,sva.userdata)
variable valMin = str2num (stringfromlist (1,sva.userdata))
if (numtype (ValMin) == 2)
ValMin = -inf
endif
variable valMax = str2num (stringfromlist (2,sva.userdata))
if (numtype (ValMax) == 2)
valMax =inf
endif
variable adjustUnits = (cmpstr ("adjustUnits", stringfromlist (4, sva.userdata)) == 0)
variable minIncr = str2num (stringfromlist (5, sva.userdata))
if (numtype (minIncr) == 2)
minIncr = 0
endif
// we need to parse data from controlinfo for current increment
controlinfo/w=$sva.win $sva.ctrlName
string formatStr, unitStr
variable inc, UnitsChanged, mult
GUIPSIsetVarParseRecStr (S_recreation, formatStr, unitStr, inc)
if ((sva.eventCode == 2) || (sva.eventCode == 8))
string oldUnitStr = unitStr
variable rawVal = sva.dval
UnitsChanged = GUIPSIsetVarParseSVALstr (sva.sval, rawVal, unitStr, mult, adjustUnits)
if (UnitsChanged)
formatStr = ReplaceString(oldUnitStr, formatStr, unitStr)
SetVariable $sva.ctrlname win = $sva.win, format=formatStr
sva.dval = rawVal
endif
sva.dVal *= mult
elseif (sva.eventCode == 1)
//do modifier keys for mouse up
// shift = 2
// command/ctrl = 8 and means x10
// option/Alt = 4 and means /10
// shift-command/ctrl = 10 and means *100
// shift-option/alt = 6 and means /100
if ((sva.eventMod & 8) || (sva.eventMod & 4))// modifiers
variable HalfWay = sva.ctrlRect.top + (sva.ctrlRect.bottom - sva.ctrlRect.top)/2
if (sva.mouseLoc.v > HalfWay) // Down was clicked
inc *= -1
endif
// we've already moved by inc
sva.dVal -= inc
if ((sva.eventMod & 10) == 10) //mult by 100
sva.dVal += (inc*100)
elseif ((sva.eventMod & 6) == 6) // divide by 100
sva.dVal += (inc/100)
elseif (sva.eventMod & 8) //mult by 10
sva.dVal += (inc*10)
elseif (sva.eventMod & 4)// divide by 10
sva.dVal += (inc/10)
endif
endif
endif
// Make sure use of modifiers has not clobbered max or min
if (sva.dVal < ValMin)
sva.dVal = valMin
elseif (sva.dVal > ValMax)
sva.dVal = valMax
endif
// scrunch min values to 0
if (abs (sva.dVal) < minIncr)
sva.dVal = 0
endif
// write the value back to the global variable/setvariable
if (cmpStr (sva.vName, "") ==0) // no variable, so must be internal value
SetVariable $sva.ctrlName win=$sva.win, value=_NUM:sva.dVal
else
NVAR gVal = $(S_DataFolder + S_Value)
gval = sva.dVal
endif
// Adjust increment, if requested
if (cmpstr ("autoInc", stringfromlist (3, sva.userdata)) == 0)
GUIPSIsetVarAdjustIncr (sva.win, sva.ctrlName, sva.dVal, minIncr)
endif
if (cmpstr (addFuncStr, "") != 0)
string newSvalStr
Sprintf newSvalStr, formatStr, sva.dval // update sval before calling additional function
sva.sval = newSvalStr
FUNCREF GUIPProtoFuncSetVariable extraFunc = $addFuncStr //reference to additional function to run, if any
extraFunc (sva)
endif
//printf "Eventcode =%d and entered value=%s while actual value is %.3W0PV \r", sva.eventCode,sva.sval, sva.dval
break
endswitch
return 0
End
//*****************************************************************************************************
// Sets user data for name of additional funtion to run when setvariable is activated
// Last modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarSetFunc (panelName, setVariableName, funcName)
String PanelName
String setVariableName
String funcName
return GUIPSISetvarSetData (panelName, setVariableName, 0, funcName)
end
//*****************************************************************************************************
// Sets user data for minimum value for the setvariable
// Last modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarSetMin (panelName, setVariableName, minVal)
String PanelName
String setVariableName
variable minVal
return GUIPSISetvarSetData (panelName, setVariableName, 1, num2str (minVal))
end
//*****************************************************************************************************
// Sets user data for macimum value for the setvariable
// Last modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarSetMax (panelName, setVariableName, maxVal)
String PanelName
String setVariableName
variable maxVal
return GUIPSISetvarSetData (panelName, setVariableName, 2, num2str (maxVal))
end
//*****************************************************************************************************
// toggles user data for automatically adjusting increment for the setvariable
// Last modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarSetAutoInc (panelName, setVariableName, autoIncOn)
String PanelName
String setVariableName
variable autoIncOn
if (autoIncOn)
return GUIPSISetvarSetData (panelName, setVariableName, 3, "autoinc")
else
return GUIPSISetvarSetData (panelName, setVariableName, 3, "no")
endif
end
//*****************************************************************************************************
// toggles user data for allowing user to change the unit string for the setvariable
// Last modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarSetAdustUnits (panelName, setVariableName, adjustUnitsOn)
String PanelName
String setVariableName
variable adjustUnitsOn
if (adjustUnitsOn)
return GUIPSISetvarSetData (panelName, setVariableName, 4, "adjustUnits")
else
return GUIPSISetvarSetData (panelName, setVariableName, 4, "no")
endif
end
//*****************************************************************************************************
// Sets any of the user data for the setvariable
// Last modified 2015/05/05 by Jamie Boyd
Static Function GUIPSISetvarSetData (panelName, setVariableName, dataPos, value)
string panelName // name of panel the control is on
string setVariableName // name of the Setvariable control
variable dataPos // 0 - 4
String value // string to replace previosu value
variable useTopWindow = 0
if ((CmpStr (panelname , "kwTopWin") ==0) || (CmpStr (panelName , "") ==0))
useTopWindow = 1
endif
if ((!(UseTopWindow)) && (StrLen (WinList(panelname, "", "WIN:65")) == 0))
print "GUIPSISetvarSetData could not find window, \"" +panelName + "\"."
return 1
else
if (UseTopWindow)
ControlInfo $setVariableName
else
ControlInfo/W=$panelName $setVariableName
endif
if (abs (V_Flag) !=5)
printf "GUIPSISetvarSetData could not find a Setvariable named \"%s\" on window \"%s\".\r", setVariableName, panelName
return 1
else
// make sure we have enough items in User data list
variable iData
for (iData = itemsinlist (S_UserData, ";"); iData < 5; iData +=1)
S_UserData += ";"
endfor
S_UserData = RemoveListItem(dataPos, S_UserData, ";")
S_UserData = AddListItem (value, S_UserData, ";", dataPos)
if (useTopWindow)
SetVariable $setVariableName userData = S_UserData
else
SetVariable $setVariableName win = $panelName, userData = S_UserData
endif
return 0
endif
endif
end
//*****************************************************************************************************
// Returns a string with name of extra function to run after GUIPSIsetVarProc has intrepreted the value.
// last Modified 2015/05/05 by Jamie Boyd
Function/S GUIPSISetVarGetString (panelName, SetVariableName)
String panelName
String SetVariableName
return GUIPSISetVarGetData (panelName, SetVariableName, 0)
end
//*****************************************************************************************************
//Returns minimum value that the variable controlled by the SetVariable can take.
// last Modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarGetMin (panelName, SetVariableName)
String panelName
String SetVariableName
return Str2Num (GUIPSISetVarGetData (panelName, SetVariableName, 1))
end
//*****************************************************************************************************
// Returns maximum value that the variable controlled by the SetVariable can take.
// last Modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarGetMax (panelName, SetVariableName)
String panelName
String SetVariableName
return Str2Num (GUIPSISetVarGetData (panelName, SetVariableName, 2))
end
//*****************************************************************************************************
// Returns the truth (0=false, non-zero = true) that autoincrementing is on
// last Modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarGetAutoInc (panelName, SetVariableName)
String panelName
String SetVariableName
if (CmpStr (GUIPSISetVarGetData (panelName, SetVariableName, 3), "autoinc") == 0)
return 1
else
return 0
endif
end
//*****************************************************************************************************
// Returns the truth (0=false, non-zero = true) that user can change the SI unit string
// last Modified 2015/05/05 by Jamie Boyd
Function GUIPSISetVarGetAdustUnits (panelName, SetVariableName)
String panelName
String SetVariableName
if (CmpStr (GUIPSISetVarGetData (panelName, SetVariableName, 4), "adjustUnits") == 0)
return 1
else
return 0
endif
end
//*****************************************************************************************************
// Gets data from the Setvariable Userdata
// last Modified 2015/05/05 by Jamie Boyd
Static Function/S GUIPSISetVarGetData (panelName, SetVariableName, dataPos)
String panelName
String SetVariableName
variable dataPos
variable useTopWindow = 0
if ((CmpStr (panelname , "kwTopWin") ==0) || (CmpStr (panelName , "") ==0))
useTopWindow = 1
endif
if ((!(UseTopWindow)) && (StrLen (WinList(panelname, "", "WIN:65")) == 0))
print "GUIPSISetVarGetData could not find window, \"" +panelName + "\"."
return ""
else
if (UseTopWindow)
ControlInfo $SetVariableName
else
ControlInfo/W=$panelName $SetVariableName
endif
if (abs (V_Flag) !=5)
printf "GUIPSISetVarGetData could not find a Setvariable named \"%s\" on window \"%s\".\r", SetVariableName, panelName
return ""
else
return StringFromList(dataPos, S_UserData, ";")
endif
endif
end
//*****************************************************************************************************
// Parses setvariable recreation string to get format string and separate out unit string and increment
// Last modified 2014/06/30 by Jamie Boyd
static function GUIPSIsetVarParseRecStr (S_recreation, formatStr, unitStr, inc)
string &S_Recreation
string &formatStr
string &unitStr
variable &inc
// get increment
variable startPos = strsearch(S_recreation, "limits={", 0) + 8
variable endPos = strsearch(S_recreation, "}", startPos)-1
string limtStr = S_Recreation [startPos, endPos]
inc = str2num (stringfromlist (2, limtStr, ","))
// get format string
startPos= strsearch(S_recreation, "format=\"", 0) + 8
endPos = strsearch(S_recreation, "\"", startPos)-1
formatStr = S_Recreation [startPos, endPos]
// get unit string from format string
startPos = strsearch(formatStr, "P", 0) + 1
endPos =strlen (formatStr) -1
unitStr = formatStr [startPos, endPos]
end
//*****************************************************************************************************
// Parses formatted setvariable value string to get current SI character and unit string
// sets multiplier based on SI char
// returns 1 if unitStr has changed from the unit string set in S_recreation, else 0
// Last modified 2014/07/17 by Jamie Boyd
static function GUIPSIsetVarParseSVALstr (svalStr, rawVal, unitStr, mult, adjustUnits)
string svalStr // sva.sval from control structure.
variable &rawVal
string &unitStr // pass in unit string from S_recreation. May be replaced with new unit str
variable &mult
variable adjustUnits
String SIprefix=""
variable hasChanged =0
String newUnitStr
String regExp = "^-?[0-9]*\.?[0-9]*e?-?[0-9]* ?([yzafpnµumkMGTPEZY])" + UnitStr + "$"
if (GrepString(svalStr, regExp)) // same units, and formatted o.k.
hasChanged =0
SplitString /E=(regExp) svalStr, SIprefix
else
regExp = "^-?[0-9]*\.?[0-9]*e?-?[0-9]* ?" + UnitStr + "$"
if (GrepString(svalStr, regExp)) // same units,but no SI prefix
hasChanged =0
SIprefix=""
else // at this point we will query user, but will try to make a reasonable guess first
hasChanged = 1
regExp = "^-?[0-9]*\.?[0-9]*e?-?[0-9]* ?([yzafpnµumkMGTPEZY])([A-Za-z]+)$"
if (GrepString(svalStr, regExp)) // has SI prefix and new unit string
SplitString /E=(regExp) svalStr, SIprefix, newUnitStr
else
regExp = "^-?[0-9]*\.?[0-9]*e?-?[0-9]* ?([yzafpnµumkMGTPEZY])$"
if (GrepString(svalStr, regExp)) // has SI prefix but missing unit str
SplitString /E=(regExp) svalStr, SIprefix
else
regExp = "^-?[0-9]*\.?[0-9]*e?-?[0-9]* ?([A-Za-z]+)$"
if (GrepString(svalStr, regExp)) // missing SI prefix but present unit str
SplitString /E=(regExp) svalStr, newUnitStr
else
newUnitStr = unitStr
endif
endif
endif
endif
endif
if (hasChanged)
string helpStr = "The format for this control is a number followed by an SI/metric system prefix (e.g., m,k) followed by a unit str (e.g., m,s, Hz). "
helpStr += "The SI prefix can be empty to specifiy use of base units."
variable isOK
variable newRawVal = rawVal
prompt newRawVal, "Reset value:"
prompt SIprefix, "SI prefix (or blank):"
prompt newUnitStr, "Units:"
do
isOk =0
if (adjustUnits)
doPrompt/HELP=helpStr "Re-Set the value for this Control:", newRawVal,SIPrefix, NewUnitStr
else
doPrompt/HELP=helpStr "Re-Set the value for this Control:", newRawVal,SIPrefix
endif
if (V_Flag ==0)
/// check values
if (numtype (newRawVal)== 0)
rawVal = newRawVal
if ((GrepString(SIprefix,"^[yzafpnµumkMGTPEZY]$")) || ((cmpStr (SIprefix, "") ==0)))
if (adjustUnits)
if (GrepString(newUnitStr,"^[A-Z,a-z]+$"))
unitStr = newUnitStr
isOK =1
endif
else
isOk=1
endif
endif
endif
endif
while (!(isOK))
endif
// get multiplier from SIprefix
if (cmpStr (SIprefix, "") ==0)
mult = 1
else
strswitch (SIprefix)
case "y":// 121: //y
mult = 1e-24
break
case "z": //122: //z
mult = 1e-21
break
case "a": //97: //a
mult = 1e-19
break
case "f": //102: //f
mult = 1e-15
break
case "p": //112: //p
mult = 1e-12
break
case "n": //110: //n
mult = 1e-9
break
case "µ": //-75: //µ greek "mu" - hard to type
case "u": // 117: // u - easier to type, so we let it pass
mult = 1e-6
break
case "m": // 109: // m
mult = 1e-3
break
case "k": //107: //k
mult = 1e3
break
case "M": //77: //M
mult = 1e6
break
case "G": //71: //G
mult = 1e9
break
case "T": //84: //T
mult = 1e12
break
case "P": //80: //P
mult = 1e15
break
case "E": //69: //E
mult = 1e18
break
case "Z": //90: //Z
mult = 1e21
break
case "Y": //89: // Y
mult = 1e24
break
endSwitch
endif
return hasChanged
end
//*****************************************************************************************************
// Adjusts the increment of the setvariable to 1% of current order of magnitude.
// You need to set uservalue for min and max with this procedure
static Function GUIPSIsetVarAdjustIncr (windowName, ctrlName, theVal, minIncr)
string windowName
string ctrlName
variable theVal
variable minIncr
variable absGval = abs (theVal)
if (absGval< 10.0001^-24)
SetVariable $ctrlname win = $windowName, limits={(-INF),(INF), (max (minIncr, 10^-26))}
elseif (absGval< 10.0001^-23)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-25))}
elseif (absGval< 10.0001^-22)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^-24))}
elseif (absGval< 10.0001^-21)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-23))}
elseif (absGval< 10.0001^-20)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-22))}
elseif (absGval< 10.0001^-19)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-21))}
elseif (absGval< 10.0001^-18)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-20))}
elseif (absGval< 10.0001^-17)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-19))}
elseif (absGval< 10.0001^-16)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-18))}
elseif (absGval< 10.0001^-15)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-17))}
elseif (absGval< 10.0001^-14)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-16))}
elseif (absGval< 10.0001^-13)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-15))}
elseif (absGval< 10.0001^-12)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-14))}
elseif (absGval< 10.0001^-11)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-13))}
elseif (absGval< 10.0001^-10)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-12))}
elseif (absGval< 10.0001^-9)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-11))}
elseif (absGval< 10.0001^-8)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-10))}
elseif (absGval< 10.0001^-7)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-9))}
elseif (absGval < 10.0001^-6)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-8))}
elseif (absGval < 10.0001^-5)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-7))}
elseif (absGval< 10.0001^-4)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF), (max (minIncr, 10^-6))}
elseif (absGval< 10.0001^-3)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^-5))}
elseif (absGval< 10.0001^-2)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^-4))}
elseif (absGval< 10.0001^-1)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^-3))}
elseif (absGval< 10.0001^0)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^-2))}
elseif (absGval< 9.9999^1)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^-1))}
elseif (absGval< 9.9999^2)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^0))}
elseif (absGval< 9.9999^3)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^1))}
elseif (absGval< 9.9999^4)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^2))}
elseif (absGval< 9.9999^5)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^3))}
elseif (absGval< 9.9999^6)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^4))}
elseif (absGval< 9.9999^7)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^5))}
elseif (absGval< 9.9999^8)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^6))}
elseif (absGval< 9.9999^9)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^7))}
elseif (absGval< 9.9999^10)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^8))}
elseif (absGval< 9.9999^11)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^9))}
elseif (absGval< 9.9999^12)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^10))}
elseif (absGval< 9.9999^13)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^11))}
elseif (absGval< 9.9999^14)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^12))}
elseif (absGval< 9.9999^15)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^13))}
elseif (absGval< 9.9999^16)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^14))}
elseif (absGval< 9.9999^17)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^15))}
elseif (absGval< 9.9999^18)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^16))}
elseif (absGval< 9.9999^19)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^17))}
elseif (absGval< 9.9999^20)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^18))}
elseif (absGval< 9.9999^21)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^19))}
elseif (absGval< 9.9999^22)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^20))}
elseif (absGval< 9.9999^23)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^21))}
elseif (absGval< 9.9999^24)
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^22))}
else
SetVariable $ctrlname win=$windowName, limits={(-INF),(INF),(max (minIncr, 10^23))}
endif
end
end
//**********************************************GUIPTabControl***********************************************
// The programmer is responsible for showing the controls for the selected tab, and hiding controls for other tabs. This can get out of hand quickly if your
// tab controls are complicated. These procedures provide a way to automate the process of hiding and showing controls. They do no other tab-related
// processing, but include the option of calling an extra function to do so. This tab control procedure puts the database of which controls belong to
// which tabs in a set of waves in a packages folder.
//******************************************************************************************************
// The Tab Control procedure
// Last Modified 2013/04/26 by Jamie Boyd
//******************************************************************************************************
//**********************************************GUIPTab Database Creation *************************************
//******************************************************************************************************
//Makes a new database for a tab control
// last modified 2013/04/25 by Jamie Boyd
Function GUIPTabNewTabCtrl (tabWinStr, tabControlStr, [TabList, UserFunc, curTab])
string tabWinStr // name of panel window containing the tabcontrol
string tabControlStr // name of the tabControl
string TabList // semicolon separated list of tabs on the tabControl. First item in list must be current tab (if not given, reads it from the tabcontrol)
string UserFunc // optional user-provided function
variable curTab // optional number of currently-selected tab on tabcontrol
// make sure packages sub-folder exists for tabcontols (root:packages:GUIP:TCD)
if (!(dataFolderExists ("root:packages")))
newDataFolder root:packages
endif
if (!(dataFolderExists ("root:packages:GUIP")))
newDataFolder root:packages:GUIP
endif
if (!(datafolderexists ("root:packages:GUIP:TCD")))
newDataFolder root:packages:GUIP:TCD
endif
// make a datafolder for this control panel in the tabControls datafolder
if (!(dataFolderExists ("root:packages:GUIP:TCD:" + possiblyquotename (tabWinStr))))
newDataFolder/o $"root:packages:GUIP:TCD:" + tabWinStr
endif
// make a datafolder for this tab control in the control panels's data folder
newDataFolder/o $"root:packages:GUIP:TCD:" + possiblyquotename (tabWinStr) + ":" + tabControlStr
string folderPath = "root:packages:GUIP:TCD:" + PossiblyQuoteName (tabWinStr) + ":" + tabControlStr + ":"
// make global strings in the tab control's folder for the list of tabs, and for the current tab
// if TabList is defaut, read tablist and current tab from the controlinfo of the tabControl
if (ParamIsDefault (TabList))
controlinfo /W=$tabWinStr $tabControlStr
if (V_Flag == 0) // the control does not exist, so return 1, for error
return 1
endif
string/g $folderPath + "tabList" = GUIPTabListFromRecStr (S_recreation)
string/g $folderPath + "currentTab" = S_Value
else
string/g $folderPath + "tabList" = TabList
if (ParamisDefault (curTab))
curTab =0
endif
string/g $folderPath + "currentTab" = stringFromList (curTab, tabList, ";")
endif
SVAR tabListG = $folderPath + "tabList"
// if provided, make global string for user function
if (!(ParamIsDefault (UserFunc)))
string/G $folderPath + "UserUpdateFunc" = UserFunc
endif
// for each tab, make textwaves for control names on that tab, and the type of each control
// plus a numeric wave for the able state of the control when the tab is selected
variable iTab, nTabs = itemsinlist (TabListG, ";")
string aTab
for (iTab=0;iTab < nTabs; iTab +=1)
aTab = stringFromList (iTab, TabListG, ";")
make/o/t/n=0 $folderPath + PossiblyQuoteName (aTab) + "_ctrlNames"
make/o/t/n=0 $folderPath + PossiblyQuoteName (aTab) + "_ctrlTypes"
make/o/n=0 $folderPath + PossiblyQuoteName (aTab) + "_ctrlAbles"
endfor
return 0
end
//******************************************************************************************************
// adds a tab to the tab control database, adds its name to the tablist, and makes an empty set of waves for it in the database
// last modified 2012/06/30 by Jamie Boyd
Function GUIPTabAddTab (tabWinStr, tabControlStr, tabStr, ModTabControl)
string tabWinStr // Name of the controlpanel/graph to modify
string tabControlStr // name of the tab control to modify
string tabStr // name of the new tab to add to the control panel
variable modTabControl // Set bit 0 to add the tab to the tab control, and bit 1 to bring new tab to front
// database for each tabcontrol is stored in a set of waves in a datafolder within the packages folder
string folderPath = "root:packages:GUIP:TCD:" + possiblyquotename (tabWinStr) + ":" + tabControlStr + ":"
SVAR tabList = $folderPath + "tabList"
if (WhichListItem(tabStr, tabList, ";") > -1) // tab is already there
return 1
endif
// add new tab to end of tab list
variable nTabs = itemsinList (tabList, ";")
tabList += tabStr + ";"
// make waves for this tab
make/o/t/n=0 $folderPath + PossiblyQuoteName (tabStr) + "_ctrlNames"
make/o/t/n=0 $folderPath + PossiblyQuoteName (tabStr) + "_ctrlTypes"
make/o/n=0 $folderPath + PossiblyQuoteName (tabStr) + "_ctrlAbles"
// if requested, add tab to tab control and bring tab to front
if (modTabControl & 1)
TabControl $tabControlStr, win = $tabWinStr, tabLabel (nTabs)= tabStr
if (modTabControl & 2)
GUIPTabClick (tabWinStr, tabControlStr, tabStr)
endif
endif
return 0
end
//******************************************************************************************************
//Adds controls to the database for a tab control
// last modified 2015/04/30 by Jamie Boyd
Function GUIPTabAddCtrls (tabWinStr, tabControlStr, tabStr, ctrlList, [applyAbleState])
string tabWinStr //name of the window or subwindow containing the tabcontrol
string tabControlStr //name of the tabControl
string tabStr // name of the tab to add the controls to
string ctrlList // list of entries to database in triplet format ControlType controlName ableState;
variable applyAbleState // if set, apply show/hide to the controls as appropriate
if (paramisDefault (applyAbleState))
applyAbleState = 0
endif
// get path to folder for this tabcontrol and to waves for this tab of the tabcontrol
// if folder does not exist, exit with an error
string folderPath = "root:packages:GUIP:TCD:" + PossiblyQuoteName (tabWinStr) + ":" + tabControlStr + ":"
WAVE/z/T ctrlNames = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlNames"
WAVE/z/T ctrlTypes = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlTypes"
WAVE/z ctrlAbles = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlAbles"
// if waves do not exist, exit
if (!((waveExists (ctrlNames) && waveExists (ctrlTypes)) && waveExists (ctrlAbles)))
return 1
endif
// if Applyging able state, only hide controls if tabWinStr is NOT showing tab, but always change disable state
variable isCurrentTab = 0
if (applyAbleState)
ControlInfo/W = $tabWinStr $tabControlStr
if (cmpStr (tabStr, S_Value) ==0)
isCurrentTab =1
endif
endif
// insert controls into the database
// keep them sorted alphabetically
// check values of control type and able state
variable returnVal = 0
variable iControl, nControls = itemsinlist (ctrlList, ";")
string aControlTriplet, aControl, aCtrlType
variable insertPos, aCtrlAble
for (iControl =0; iControl < nControls; iControl +=1)
aControlTriplet = stringFromList (iControl, ctrlList, ";")
aCtrlType = stringFromList (0, aControlTriplet, " ")
aControl = stringFromList (1, aControlTriplet, " ")
aCtrlAble = str2num (stringFromList (2, aControlTriplet, " "))
if (GUIPTabCheckControlType (aCtrlType))
printf "Control Type for %s was an invalid value, %s.\r", aControl, aCtrlType
returnVal +=1
continue
endif
if (numtype (aCtrlAble) != 0)
aCtrlAble = 0
endif
insertPos = GUIPMathFindText (ctrlNames, aControl, 0, inf, 0)
if (insertPos < 0) // control not already added
insertPos = -(insertPos +1)
insertpoints insertPos, 1, ctrlNames, ctrlTypes, ctrlAbles
endif
ctrlNames [insertPos] = aControl
ctrlTypes [insertPos] = aCtrltype
ctrlAbles [insertPos] = ~4 & aCtrlAble
if (ApplyAbleState)
if (isCurrentTab==0) // hide controls not on the current tab
aCtrlAble = 1 | aCtrlable
endif
GUIPTabShowHide (aControl, aCtrltype, 4 + aCtrlAble, tabWinStr)
endif
endfor
return returnVal
end
//******************************************************************************************************
//**********************************************GUIPTab Dynamic Stuff******* ********************************
//******************************************************************************************************
//Removes controls from the database for a tab control
// last modified 2014/08/19 by Jamie Boyd
Function GUIPTabRemoveControls (tabWinStr, tabControlStr, tabList, ctrlList, ModTabControl)
string tabWinStr //name of the window or subwindow containing the tabcontrol
string tabControlStr //name of the tabControl
string tabList // list of the tabs to remove the controls from. Pass "" to remove control from all tabs
string ctrlList // list of entries of controls to remove from the database
variable modTabControl // set to 1 to delete control from panel as well
// get path to folder for this tabcontrol and to waves for this tab of the tabcontrol
string folderPath = "root:packages:GUIP:TCD:" + PossiblyQuoteName (tabWinStr) + ":" + tabControlStr + ":"
string toDoList
if (cmpStr (tabList, "") ==0)
SVAR tabListAll = $folderPath + "tabList"
toDoList = tabListAll
else
toDoList = tabList
endif
// Variables to Iterate through controls
variable iControl, nControls = itemsinlist (ctrlList, ";")
string aControl
variable controlPos
//Variables to iterate through tabList
variable iTab, nTabs = itemsinList (tabList, ";")
string tabStr
for (iTab =0; iTab < nTabs; iTab +=1)
tabStr = stringFromList (iTab, tabList, ";")
// reference list of dbase waves for this tab
WAVE/z/T ctrlNames = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlNames"
WAVE/z/T ctrlTypes = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlTypes"
WAVE/z ctrlAbles = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlAbles"
// if waves do not exist, exit with error
if (!((waveExists (ctrlNames) && waveExists (ctrlTypes)) && waveExists (ctrlAbles)))
return 1
endif
// remove controls from the database for this tab
for (iControl =0; iControl < nControls; iControl +=1)
aControl = stringFromList (iControl, ctrlList, ";")
// find control
controlPos = GUIPMathFindText (ctrlNames, aControl, 0, inf, 0)
if (controlPos >= 0) // control is in database for this tab
// first time through, delete control from control panel, if requested
if ((itab ==0) && (modTabControl))
if (CmpStr (ctrlTypes [controlPos], "SubWindow") ==0)
killwindow $tabWinStr#$aControl
elseif (cmpStr (ctrlTypes [iControl], "TabControl") ==0)
GUIPTabKillTabControl (tabWinStr, aControl, 1)
else
KillControl/W=$tabWinStr $aControl
endif
endif
deletepoints controlPos, 1, ctrlNames, ctrlTypes, ctrlAbles
endif
endfor
endFor
return 0
end
//******************************************************************************************************
// sets the able state for when a control's tab is shown as recorded in the database for a list of controls
// (0 = enabled and shown, 1 = hidden, 2 = disabled but shown, 3 = hidden and disabled); set bit 2 (add 4) for subWindow re-enabling
// Last Modified 2015/04/30 by Jamie Boyd
Function GUIPTabSetAbleState (tabWinStr, tabControlStr, tabList, ctrlList, ableState, modTabControl)
string tabWinStr //name of the window or subwindow of tabcontrol
string tabControlStr // name of the tabcontrol
string tabList // list of tabs for which to change controls state. Pass "" for all tabs
string ctrlList // list of controls to set ablestate
variable ableState
variable modTabControl
// get path to folder for this tabcontrol
string folderPath = "root:packages:GUIP:TCD:" + PossiblyQuoteName (tabWinStr) + ":" + tabControlStr + ":"
// variables to iterate through controls
variable iControl, nControls = itemsInlist (ctrlList, ";")
string aControl
// variables to iterate through list of tabs for this tabcontrol
if (cmpStr (tabList, "") ==0)
SVAR tabListG = $folderPath + "tabList"
tabList= tabListG
endif
variable iTab, nTabs = itemsinList (tabList, ";")
string aTab
// position of control in list of control
variable ctrlPos
string curTab = GUIPTabGetCurrentTab (tabWinStr, tabControlStr), commadStr
for (iTab =0 ; iTab < nTabs; iTab +=1)
aTab = stringFromList (iTab, tabList, ";")
WAVE/z/T ctrlNames = $folderPath + PossiblyQuoteName (aTab) + "_ctrlNames"
WAVE/z ctrlAbles = $folderPath + PossiblyQuoteName (aTab) + "_ctrlAbles"
WAVE/z/T ctrlTypes = $folderPath + PossiblyQuoteName (aTab) + "_ctrlTypes"
if (!((WaveExists (ctrlNames) && (waveExists (ctrlAbles))) && waveExists (ctrlTypes)))
printf "Could not find database for tab %s of tabcontrol %s on window %s.", aTab, tabControlStr, tabWinStr
continue
endif
for (iControl =0; iControl < nControls; iControl +=1)
aControl = stringFromList (iControl, ctrlList, ";")
ctrlPos = GUIPMathFindText (ctrlNames, aControl, 0, inf, 0)
if (ctrlPos >= 0) // control is shown for this tab
ctrlAbles [ctrlPos] = ableState
if (modTabControl)
if ((ableState & 4) || (cmpStr (aTab, curTab) ==0))
GUIPTabShowHide (aControl, ctrlTypes [ctrlPos], ableState, tabWinStr)
endif
endif
endif
endfor
endfor
end
//******************************************************************************************************
// Renames a control in the tab control database, and (optionally) renames the control on the control panel
// Last Modified 2015/04/29 by Jamie Boyd
Function GUIPTabRenameControl (tabWinStr, tabControlStr, oldControlName, newControlName, modControl)
String tabWinStr
String tabControlStr
String oldControlName // original control name
String newControlName // what the control will be renamed to in the dataBase
Variable modControl // if set, the control will be renamed on the control panel, as well as in the database
// database for each tabcontrol is stored in a set of waves in a datafolder within the packages folder
string folderPath = "root:packages:GUIP:TCD:" + possiblyquotename (tabWinStr) + ":" + tabControlStr + ":"
SVAR/Z tabList = $folderPath + "tabList"
if (!(SVAR_EXISTS (tabList))) // tab is not there
return 1
endif
// iterate through list of tabs on the tabcontrol
variable iTab, nTabs = ItemsInList(tabList, ";"), tabPos
string tabStr, selectedCtrlType
for (iTab = 0; iTab < nTabs; iTab +=1)
tabStr = StringFromList(iTab, tabList, ";")
// waves for this tabControl
WAVE/z/T ctrlNames = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlNames"
WAVE/z/T ctrlTypes = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlTypes"
WAVE/z ctrlAbles = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlAbles"
// if waves do not exist, exit
if (!((waveExists (ctrlNames) && waveExists (ctrlTypes)) && waveExists (ctrlAbles)))
return 1
endif
// look for control name on this tab
tabPos = GUIPMathFindText (ctrlNames, oldControlName, 0, inf, 0)
// if we found it, rename it, and re-sort the database waves
if (tabPos >= 0)
ctrlNames [tabPos] = newControlName
selectedCtrlType = ctrlTypes [tabPos]
sort ctrlNames ctrlNames, ctrlTypes, ctrlAbles
endif
endfor
if (modControl)
string executeStr
Sprintf executeStr "%s %s win =%s, rename = %s", selectedCtrlType, oldControlName, tabWinStr, newControlName
Execute executeStr
endif
end
//******************************************************************************************************
// Removes a tab info from a tab control database, and (optionally) modifies the tab control and removes from the panel controls belonging only to the removed tab
// Last Modified 2014/08/19 by Jamie Boyd
Function GUIPTabRemoveTab(tabWinStr, tabControlStr, tabStr, ModTabControl)
string tabWinStr // Name of the controlpanel/graph to modify
string tabControlStr // name of the tab control to modify
string tabStr // name of the tab to remove from the control panel
variable modTabControl // Set bit 0=1 to modifiy the tab control to remove the tab. Set bit1=2 to remove controls present only on this tab
// database for each tabcontrol is stored in a set of waves in a datafolder within the packages folder
string folderPath = "root:packages:GUIP:TCD:" + possiblyquotename (tabWinStr) + ":" + tabControlStr + ":"
SVAR/Z tabList = $folderPath + "tabList"
if ((!(SVAR_EXISTS (tabList))) || (WhichListItem(tabStr, tabList, ";") == -1)) // tab is not there
return 1
endif
// waves for this tabControl
WAVE/z/T ctrlNames = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlNames"
WAVE/z/T ctrlTypes = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlTypes"
WAVE/z ctrlAbles = $folderPath + PossiblyQuoteName (tabStr) + "_ctrlAbles"
// if waves do not exist, exit
if (!((waveExists (ctrlNames) && waveExists (ctrlTypes)) && waveExists (ctrlAbles)))
return 1
endif
// get position of tab in database and on the tabCOntrol
variable iTab, nTabs = itemsinList (tabList, ";")
variable removeTabPos = WhichListItem(tabStr, tabList, ";")
if (removeTabPos == -1)
return 1
endif
tabList = RemoveListItem(removeTabPos, tabList, ";")
nTabs -=1
SVAR curTab = $folderPath + "currentTab"
if (ModTabControl & 2)
// remove controls present on this tab, but not other tabs
variable iControl, nControls = numPnts (ctrlNames)
string aControl
variable otherTabPos
for (iControl =0 ;iControl < nControls; iControl +=1)
aControl = ctrlNames [iControl]
for (iTab =0; iTab < nTabs; iTab +=1)
wave otherTabControlNames = $folderPath + PossiblyQuoteName (stringFromList (iTab, tabStr)) + "_ctrlNames"
otherTabPos = GUIPMathFindText (otherTabControlNames, aControl, 0, inf, 0)
if (otherTabPos > -1) // control is on another tab
break
endif
endfor
if (iTab == nTabs) // we checked all other tabs without finding this control, so kill it
// is control a subWIndow?
if (cmpStr (ctrlTypes [iControl], "SubWindow") ==0)
killwindow $tabWinStr#$aControl
elseif (cmpStr (ctrlTypes [iControl], "TabControl") ==0)
GUIPTabKillTabControl (tabWinStr, tabControlStr, 1)
else
KillControl /W=$tabWinStr $aControl
endif
endif
endfor
endif
// remove tab from tabcontrol, moving tab names to fill blank spave and preserve order