-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmy_parameters.py
2804 lines (1972 loc) · 108 KB
/
my_parameters.py
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
import math
import os
from pyqtgraph.parametertree import registerParameterType
from qgis.PyQt.QtCore import QFileInfo, QPointF, QSettings
from qgis.PyQt.QtGui import QColor, QVector3D
from qgis.PyQt.QtWidgets import QMessageBox
from . import config # used to pass initial settings
from .my_cmap import MyCmapParameter
from .my_crs import MyCrsParameter
from .my_crs2 import MyCrs2Parameter
from .my_group import MyGroupParameter, MyGroupParameterItem
from .my_list import MyListParameter
from .my_marker import MyMarkerParameter
from .my_n_vector import MyNVectorParameter
from .my_numerics import MyFloatParameter, MyIntParameter
from .my_pen import MyPenParameter
from .my_point2D import MyPoint2DParameter
from .my_point3D import MyPoint3DParameter
from .my_preview_label import MyPreviewLabel
from .my_range import MyRangeParameter
from .my_rectf import MyRectParameter
from .my_slider import MySliderParameter
from .my_symbols import MySymbolParameter
from .my_vector import MyVectorParameter
from .roll_angles import RollAngles
from .roll_bingrid import RollBinGrid
from .roll_binning import BinningList, BinningType, RollBinning
from .roll_block import RollBlock
from .roll_circle import RollCircle
from .roll_offset import RollOffset
from .roll_pattern import RollPattern
from .roll_pattern_seed import RollPatternSeed
from .roll_plane import RollPlane
from .roll_seed import RollSeed
from .roll_sphere import RollSphere
from .roll_spiral import RollSpiral
from .roll_survey import RollSurvey, SurveyType
from .roll_template import RollTemplate
from .roll_translate import RollTranslate
from .roll_well import RollWell
### class MyBinAngles #########################################################
class MyBinAnglesPreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
self.decimals = param.opts.get('decimals', 3)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
d = self.decimals
y = val.reflection.y()
x = val.reflection.x()
if x == 0.0:
t = f'AoI < {y:.{d}g} deg'
else:
t = f'{x:.{d}g} < AoI < {y:.{d}g} deg'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MyBinAnglesPreviewLabel.ValueChanging | {t} <<<')
class MyBinAnglesParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyBinAnglesPreviewLabel(param))
class MyBinAnglesParameter(MyGroupParameter):
itemClass = MyBinAnglesParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyBinAnglesParameter opts')
d = opts.get('decimals', 7)
self.angles = RollAngles()
self.angles = opts.get('value', self.angles)
tip1 = 'for angles around 0° use min > max. E.g. from 330° (min) to 30° (max)'
tip2 = 'incidence angles are not used with the Cmp binning method'
self.addChild(dict(name='Min azimuth', value=self.angles.azimuthal.x(), type='float', decimals=d, suffix='°E-ccw', limits=[0.0, 360.0], tip=tip1))
self.addChild(dict(name='Max azimuth', value=self.angles.azimuthal.y(), type='float', decimals=d, suffix='°E-ccw', limits=[0.0, 360.0], tip=tip1))
self.addChild(dict(name='Min inclination', value=self.angles.reflection.x(), type='float', decimals=d, suffix='°Aoi', limits=[0.0, 90.0], tip=tip2))
self.addChild(dict(name='Max inclination', value=self.angles.reflection.y(), type='float', decimals=d, suffix='°Aoi', limits=[0.0, 90.0], tip=tip2))
self.parAx = self.child('Min azimuth')
self.parAy = self.child('Max azimuth')
self.parIx = self.child('Min inclination')
self.parIy = self.child('Max inclination')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
self.angles.azimuthal.setX(self.parAx.value())
self.angles.azimuthal.setY(self.parAy.value())
self.angles.reflection.setX(self.parIx.value())
self.angles.reflection.setY(self.parIy.value())
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.angles
### class MyBinOffset #########################################################
class MyBinOffsetPreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
x = max(abs(val.rctOffsets.left()), abs(val.rctOffsets.right()))
y = max(abs(val.rctOffsets.top()), abs(val.rctOffsets.bottom()))
d = math.hypot(x, y)
r = val.radOffsets.y()
if r >= d:
t = 'rectangular constraints'
elif r < x:
t = 'radial constraints'
else:
t = 'mixed constraints'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MyBinOffsetPreviewLabel.ValueChanging | {t} <<<')
class MyBinOffsetParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyBinOffsetPreviewLabel(param))
class MyBinOffsetParameter(MyGroupParameter):
itemClass = MyBinOffsetParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyBinOffsetParameter opts')
d = opts.get('decimals', 7)
s = opts.get('suffix', 'm')
self.offset = RollOffset()
self.offset = opts.get('value', self.offset)
self.addChild(dict(name='Min x-offset', value=self.offset.rctOffsets.left(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Max x-offset', value=self.offset.rctOffsets.right(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Min y-offset', value=self.offset.rctOffsets.top(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Max y-offset', value=self.offset.rctOffsets.bottom(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Min r-offset', value=self.offset.radOffsets.x(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Max r-offset', value=self.offset.radOffsets.y(), type='float', decimals=d, suffix=s))
self.parXmin = self.child('Min x-offset')
self.parXmax = self.child('Max x-offset')
self.parYmin = self.child('Min y-offset')
self.parYmax = self.child('Max y-offset')
self.parRmin = self.child('Min r-offset')
self.parRmax = self.child('Max r-offset')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
# read parameter changes here
xmin = self.parXmin.value()
xmax = self.parXmax.value()
ymin = self.parYmin.value()
ymax = self.parYmax.value()
rmin = self.parRmin.value()
rmax = self.parRmax.value()
self.offset.rctOffsets.setLeft(min(xmin, xmax))
self.offset.rctOffsets.setRight(max(xmin, xmax))
self.offset.rctOffsets.setTop(min(ymin, ymax))
self.offset.rctOffsets.setBottom(max(ymin, ymax))
self.offset.radOffsets.setX(min(rmin, rmax))
self.offset.radOffsets.setY(max(rmin, rmax))
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.offset
### class MyUniqOff ###########################################################
class MyUniqOffPreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
if not val.apply:
t = 'Not used'
else:
t = f'@ {val.dOffset}m, {val.dAzimuth}°'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MyUniqOffPreviewLabel.ValueChanging | {t} <<<')
class MyUniqOffParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyUniqOffPreviewLabel(param))
class MyUniqOffParameter(MyGroupParameter):
itemClass = MyUniqOffParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyUniqOffParameter opts')
d = opts.get('decimals', 7)
self.unique = RollOffset()
self.unique = opts.get('value', self.unique)
tip = 'Write back rounded offset- and azimuth values back to analysis results'
self.addChild(dict(name='Apply pruning', value=self.unique.apply, type='bool'))
self.addChild(dict(name='Write rounded', value=self.unique.write, type='bool', tip=tip))
self.addChild(dict(name='Delta offset', value=self.unique.dOffset, type='float', decimals=d, suffix='m'))
self.addChild(dict(name='Delta azimuth', value=self.unique.dAzimuth, type='float', decimals=d, suffix='deg'))
self.parP = self.child('Apply pruning')
self.parR = self.child('Write rounded')
self.parO = self.child('Delta offset')
self.parA = self.child('Delta azimuth')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
self.unique.apply = self.parP.value()
self.unique.write = self.parR.value()
self.unique.dOffset = self.parO.value()
self.unique.dAzimuth = self.parA.value()
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.unique
### class MyBinMethod #########################################################
class MyBinMethodPreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
binningMethod = val.method.value
method = BinningList[binningMethod]
t = f'{method} @ Vint={val.vint}m/s'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MyBinMethodPreviewLabel.ValueChanging | {t} <<<')
class MyBinMethodParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyBinMethodPreviewLabel(param))
class MyBinMethodParameter(MyGroupParameter):
itemClass = MyBinMethodParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyBinMethodParameter opts')
self.binning = RollBinning()
self.binning = opts.get('value', self.binning)
d = opts.get('decimals', 7)
binningMethod = self.binning.method.value
self.addChild(dict(name='Binning method', type='myList', value=BinningList[binningMethod], default=BinningList[binningMethod], limits=BinningList))
self.addChild(dict(name='Interval velocity', type='float', value=self.binning.vint, decimals=d, suffix='m/s'))
self.parM = self.child('Binning method')
self.parV = self.child('Interval velocity')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
index = BinningList.index(self.parM.value())
self.binning.method = BinningType(index)
self.binning.vint = self.parV.value()
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.binning
### class MyPlane #############################################################
class MyPlanePreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
param.sigTreeStateChanged.connect(self.onTreeStateChanged)
self.decimals = param.opts.get('decimals', 5)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
dip = val.dip
azi = val.azi
z = val.anchor.z()
d = self.decimals
if dip == 0:
t = f'horizontal, depth={-z:.{d}g}m'
else:
t = f'dipping, azi={azi:.{d}g}°, dip={dip:.{d}g}°'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MyPlanePreviewLabel.ValueChanging | {t} <<<')
def onTreeStateChanged(self, param, _): # unused changes replaced by _
# print(f'>>>{lineNo():5d} MyPlaneParameter.TreeStateChanged <<<')
val = param.opts.get('value', None)
self.onValueChanging(None, val)
class MyPlaneParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyPlanePreviewLabel(param))
class MyPlaneParameter(MyGroupParameter):
itemClass = MyPlaneParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyPlaneParameter opts')
self.plane = RollPlane()
self.plane = opts.get('value', self.plane)
d = opts.get('decimals', 7)
s = opts.get('suffix', 'm')
tip = 'plane is dipping upwards in the azimuth direction'
self.addChild(dict(name='Plane anchor', type='myPoint3D', value=self.plane.anchor, decimals=d, suffix=s, expanded=False, flat=True))
self.addChild(dict(name='Plane azimuth', type='float', value=self.plane.azi, decimals=d, suffix='°E-ccw'))
self.addChild(dict(name='Plane dip', type='float', value=self.plane.dip, decimals=d, suffix='°', tip=tip))
self.parO = self.child('Plane anchor')
self.parA = self.child('Plane azimuth')
self.parD = self.child('Plane dip')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
self.plane.anchor = self.parO.value()
self.plane.azi = self.parA.value()
self.plane.dip = self.parD.value()
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.plane
### class MySphere ############################################################
class MySpherePreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
param.sigTreeStateChanged.connect(self.onTreeStateChanged)
self.decimals = param.opts.get('decimals', 5)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
r = val.radius
z = val.origin.z()
d = self.decimals
t = f'r={r:.{d}g}m, depth={-z:.{d}g}m'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MySpherePreviewLabel.ValueChanging | {t} <<<')
def onTreeStateChanged(self, param, _): # unused changes replaced by _
# print(f'>>>{lineNo():5d} MySphereParameter.TreeStateChanged <<<')
val = param.opts.get('value', None)
self.onValueChanging(None, val)
class MySphereParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MySpherePreviewLabel(param))
class MySphereParameter(MyGroupParameter):
itemClass = MySphereParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MySphereParameter opts')
self.sphere = RollSphere()
self.sphere = opts.get('value', self.sphere)
d = opts.get('decimals', 7)
s = opts.get('suffix', 'm')
self.addChild(dict(name='Sphere origin', type='myPoint3D', value=self.sphere.origin, decimals=d, suffix=s, expanded=False, flat=True))
self.addChild(dict(name='Sphere radius', type='float', value=self.sphere.radius, decimals=d, suffix=s))
self.parO = self.child('Sphere origin')
self.parR = self.child('Sphere radius')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
self.sphere.origin = self.parO.value()
self.sphere.radius = self.parR.value()
self.sigValueChanging.emit(self, self.sphere)
def value(self):
return self.sphere
### class MyLocalGrid #########################################################
class MyLocalGridPreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
fold = val.fold
if fold < 0:
t = f'{val.binSize.x()}x{val.binSize.y()}m, fold undefined'
else:
t = f'{val.binSize.x()}x{val.binSize.y()}m, fold {fold} max'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MyLocalGridPreviewLabel.ValueChanging | {t} <<<')
class MyLocalGridParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyLocalGridPreviewLabel(param))
class MyLocalGridParameter(MyGroupParameter):
itemClass = MyLocalGridParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyLocalGridParameter opts')
d = opts.get('decimals', 7)
s = opts.get('suffix', 'm')
self.binGrid = RollBinGrid()
self.binGrid = opts.get('value', self.binGrid)
self.addChild(dict(name='Bin size [x]', value=self.binGrid.binSize.x(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Bin size [y]', value=self.binGrid.binSize.y(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Bin offset [x]', value=self.binGrid.binShift.x(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Bin offset [y]', value=self.binGrid.binShift.y(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Stake nr @ origin', value=self.binGrid.stakeOrig.x(), type='float', decimals=d, suffix='#'))
self.addChild(dict(name='Line nr @ origin', value=self.binGrid.stakeOrig.y(), type='float', decimals=d, suffix='#'))
self.addChild(dict(name='Stake increments', value=self.binGrid.stakeSize.x(), type='float', decimals=d, suffix='m'))
self.addChild(dict(name='Line increments', value=self.binGrid.stakeSize.y(), type='float', decimals=d, suffix='m'))
self.addChild(dict(name='Max fold', value=self.binGrid.fold, type='int'))
self.parBx = self.child('Bin size [x]')
self.parBy = self.child('Bin size [y]')
self.parDx = self.child('Bin offset [x]')
self.parDy = self.child('Bin offset [y]')
self.parLx = self.child('Stake nr @ origin')
self.parLy = self.child('Line nr @ origin')
self.parSx = self.child('Stake increments')
self.parSy = self.child('Line increments')
self.parFo = self.child('Max fold')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
# local grid
self.binGrid.binSize.setX(self.parBx.value())
self.binGrid.binSize.setY(self.parBy.value())
self.binGrid.binShift.setX(self.parDx.value())
self.binGrid.binShift.setY(self.parDy.value())
self.binGrid.stakeOrig.setX(self.parLx.value())
self.binGrid.stakeOrig.setY(self.parLy.value())
self.binGrid.stakeSize.setX(self.parSx.value())
self.binGrid.stakeSize.setY(self.parSy.value())
self.binGrid.fold = self.parFo.value()
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.binGrid
### class MyGlobalGrid ########################################################
class MyGlobalGridPreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
self.decimals = param.opts.get('decimals', 3)
val = param.opts.get('value', None)
self.onValueChanging(None, val)
def onValueChanging(self, _, val): # unused param replaced by _
x = val.orig.x()
y = val.orig.y()
a = val.angle
d = self.decimals
# self.setText(f'o({x:.{d}g}, {y:.{d}g}), a={a:.{d}g} deg')
# self.setText(f'o({x:,.{d}f}, {y:,.{d}f}), a={a:.{d}g} deg')
t = f'o({x:,}, {y:,}), a={a:.{d}g} deg'
self.setText(t)
self.update()
# print(f'>>>{lineNo():5d} MyGlobalGridPreviewLabel.ValueChanging | {t} <<<')
class MyGlobalGridParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyGlobalGridPreviewLabel(param))
class MyGlobalGridParameter(MyGroupParameter):
itemClass = MyGlobalGridParameterItem
def __init__(self, **opts):
# opts['expanded'] = False # to overrule user-requested options
# opts['flat'] = True
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyGlobalGridParameter opts')
d = opts.get('decimals', 7)
s = opts.get('suffix', 'm')
self.binGrid = RollBinGrid()
self.binGrid = opts.get('value', self.binGrid)
self.addChild(dict(name='Bin origin [E]', value=self.binGrid.orig.x(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Bin origin [N]', value=self.binGrid.orig.y(), type='float', decimals=d, suffix=s))
self.addChild(dict(name='Scale factor [E]', value=self.binGrid.scale.x(), type='float', decimals=d, suffix='x'))
self.addChild(dict(name='Scale factor [N]', value=self.binGrid.scale.y(), type='float', decimals=d, suffix='x'))
self.addChild(dict(name='Azimuth', value=self.binGrid.angle, type='float', decimals=d, suffix='°E-ccw'))
self.parOx = self.child('Bin origin [E]')
self.parOy = self.child('Bin origin [N]')
self.parSx = self.child('Scale factor [E]')
self.parSy = self.child('Scale factor [N]')
self.parAz = self.child('Azimuth')
self.sigTreeStateChanged.connect(self.changed)
def changed(self):
# global grid
self.binGrid.orig.setX(self.parOx.value())
self.binGrid.orig.setY(self.parOy.value())
self.binGrid.scale.setX(self.parSx.value())
self.binGrid.scale.setY(self.parSy.value())
self.binGrid.angle = self.parAz.value()
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.binGrid
### class MyBlock #############################################################
class MyBlockPreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
# these are the signals that a parameter can generate with some objects that clarify what happened
# sigValueChanged = QtCore.Signal(object, object) ## self, value emitted when value is finished being edited
# sigValueChanging = QtCore.Signal(object, object) ## self, value emitted as value is being edited
# sigChildAdded = QtCore.Signal(object, object, object) ## self, child, index
# sigChildRemoved = QtCore.Signal(object, object) ## self, child
# sigRemoved = QtCore.Signal(object) ## self
# sigParentChanged = QtCore.Signal(object, object) ## self, parent
# sigLimitsChanged = QtCore.Signal(object, object) ## self, limits
# sigDefaultChanged = QtCore.Signal(object, object) ## self, default
# sigNameChanged = QtCore.Signal(object, object) ## self, name
# sigOptionsChanged = QtCore.Signal(object, object) ## self, {opt:val, ...}
# Emitted when anything changes about this parameter at all.
# The second argument is a string indicating what changed ('value', 'childAdded', etc..)
# The third argument can be any extra information about the change
#
# sigStateChanged = QtCore.Signal(object, object, object) ## self, change, info
# emitted when any child in the tree changes state
# (but only if monitorChildren() is called)
# sigTreeStateChanged = QtCore.Signal(object, object) ## self, changes
# ## changes = [(param, change, info), ...]
param.sigValueChanging.connect(self.onValueChanging)
param.sigTreeStateChanged.connect(self.onTreeStateChanged)
self.showInformation(param)
def showInformation(self, param):
# block's source- and receiver boundaries are ignored
templates = param.child('Template list')
nTemplates = 0
nBlockShots = 0
if templates.hasChildren():
for template in templates:
nTemplates += 1
nTemplateShots = 0
seeds = template.child('Seed list')
if seeds.hasChildren():
for seed in seeds:
nSeedShots = 0
bSource = seed.child('Source seed').opts['value']
if bSource:
seedType = seed.child('Seed type').opts['value']
if seedType == 'Circle':
nSeedShots = seed.child('Circle grow steps', 'Points').opts['value']
elif seedType == 'Spiral':
nSeedShots = seed.child('Spiral grow steps', 'Points').opts['value']
elif seedType == 'Well':
nSeedShots = seed.child('Well grow steps', 'Points').opts['value']
else:
# grid stationary or rolling
nPlane = seed.child('Grid grow steps', 'Planes', 'N').opts['value']
nLines = seed.child('Grid grow steps', 'Lines', 'N').opts['value']
nPoint = seed.child('Grid grow steps', 'Points', 'N').opts['value']
nSeedShots = nPlane * nLines * nPoint
if seedType == 'Grid (roll along)':
# only the rolling shots are afffected by roll along operations
nPlane = template.child('Roll steps', 'Planes', 'N').opts['value']
nLines = template.child('Roll steps', 'Lines', 'N').opts['value']
nPoint = template.child('Roll steps', 'Points', 'N').opts['value']
nRollSteps = nPlane * nLines * nPoint
nSeedShots *= nRollSteps
nTemplateShots += nSeedShots
nBlockShots += nTemplateShots
t = f'{nTemplates} template(s), {int(nBlockShots + 0.5)} src points'
self.setText(t)
self.update()
# print(f'+++{lineNo():5d} MyBlockPreviewLabel.showInformation | {t} +++')
def onValueChanging(self, param, _): # val unused and replaced by _
# print(f'>>>{lineNo():5d} MyBlockPreviewLabel.ValueChanging <<<')
self.showInformation(param)
def onTreeStateChanged(self, param, _): # unused changes replaced by _
# print(f'>>>{lineNo():5d} MyBlockParameter.TreeStateChanged <<<')
self.showInformation(param)
class MyBlockParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyBlockPreviewLabel(param))
class MyBlockParameter(MyGroupParameter):
itemClass = MyBlockParameterItem
def __init__(self, **opts):
opts['context'] = {'rename': 'Rename', 'remove': 'Remove', 'moveUp': 'Move up', 'moveDown': 'Move dn', 'separator': '----', 'preview': 'Preview', 'export': 'Export'}
opts['tip'] = 'Right click to manage block'
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyBlockParameter opts')
self.block = RollBlock()
self.block = opts.get('value', self.block)
self.addChild(dict(name='Source boundary', type='myRectF', value=self.block.borders.srcBorder, flat=True, expanded=False))
self.addChild(dict(name='Receiver boundary', type='myRectF', value=self.block.borders.recBorder, flat=True, expanded=False))
self.addChild(dict(name='Template list', type='myTemplateList', value=self.block.templateList, flat=True, expanded=True, brush='#add8e6', decimals=5, suffix='m'))
self.parS = self.child('Source boundary')
self.parR = self.child('Receiver boundary')
self.parT = self.child('Template list')
self.parS.sigValueChanged.connect(self.valueChanged)
self.parR.sigValueChanged.connect(self.valueChanged)
self.parT.sigValueChanged.connect(self.valueChanged)
self.sigNameChanged.connect(self.nameChanged)
self.sigContextMenu.connect(self.contextMenu)
def nameChanged(self, _):
self.block.name = self.name()
def valueChanged(self):
self.block.borders.recBorder = self.parR.value()
self.block.borders.srcBorder = self.parS.value()
self.block.templateList = self.parT.value()
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.block
def contextMenu(self, name=None):
parent = self.parent()
index = parent.children().index(self)
if not isinstance(parent, MyBlockListParameter):
raise ValueError("Need 'MyBlockListParameter' instances at this point")
## name == 'rename' already resolved by self.editName() in MyGroupParameterItem
if name == 'remove':
reply = QMessageBox.question(None, 'Please confirm', 'Delete selected block ?', QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.Yes:
self.remove()
parent.blockList.pop(index)
parent.sigChildRemoved.emit(self, parent)
elif name == 'moveUp':
if index > 0:
self.remove()
block = parent.blockList.pop(index)
parent.blockList.insert(index - 1, block)
parent.insertChild(index - 1, dict(name=block.name, type='myBlock', value=block, expanded=False, renamable=True, flat=True, decimals=5, suffix='m'))
elif name == 'moveDown':
n = len(parent.children())
if index < n - 1:
self.remove()
block = parent.blockList.pop(index)
parent.blockList.insert(index + 1, block)
parent.insertChild(index + 1, dict(name=block.name, type='myBlock', value=block, expanded=False, renamable=True, flat=True, decimals=5, suffix='m'))
elif name == 'preview':
...
elif name == 'export':
...
### class MyTemplate ##########################################################
class MyTemplatePreviewLabel(MyPreviewLabel):
def __init__(self, param):
super().__init__()
param.sigValueChanging.connect(self.onValueChanging)
param.sigTreeStateChanged.connect(self.onTreeStateChanged)
self.showInformation(param)
def showInformation(self, param):
nSeeds = 0
nTemplateShots = 0
seeds = param.child('Seed list')
if seeds.hasChildren():
for seed in seeds:
nSeeds += 1
bSource = seed.child('Source seed').opts['value']
if bSource:
seedType = seed.child('Seed type').opts['value']
if seedType == 'Circle':
nSeedShots = seed.child('Circle grow steps', 'Points').opts['value']
elif seedType == 'Spiral':
nSeedShots = seed.child('Spiral grow steps', 'Points').opts['value']
elif seedType == 'Well':
nSeedShots = seed.child('Well grow steps', 'Points').opts['value']
else:
# grid stationary or rolling
nPlane = seed.child('Grid grow steps', 'Planes', 'N').opts['value']
nLines = seed.child('Grid grow steps', 'Lines', 'N').opts['value']
nPoint = seed.child('Grid grow steps', 'Points', 'N').opts['value']
nSeedShots = nPlane * nLines * nPoint
if seedType == 'Grid (roll along)':
# only the rolling shots are afffected by roll along operations
nPlane = param.child('Roll steps', 'Planes', 'N').opts['value']
nLines = param.child('Roll steps', 'Lines', 'N').opts['value']
nPoint = param.child('Roll steps', 'Points', 'N').opts['value']
nRollSteps = nPlane * nLines * nPoint
nSeedShots *= nRollSteps
nTemplateShots += nSeedShots
t = f'{nSeeds} seed(s), {int(nTemplateShots + 0.5)} src points'
self.setText(t)
self.update()
# print(f'+++{lineNo():5d} MyTemplatePreviewLabel.showInformation | {t} +++')
def onValueChanging(self, param, _): # val unused and replaced by _
# print(f'>>>{lineNo():5d} MyTemplatePreviewLabel.ValueChanging <<<')
self.showInformation(param)
def onTreeStateChanged(self, param, _): # unused changes replaced by _
# print(f'>>>{lineNo():5d} MyTemplateParameter.TreeStateChanged <<<')
self.showInformation(param)
class MyTemplateParameterItem(MyGroupParameterItem):
def __init__(self, param, depth):
super().__init__(param, depth)
self.setPreviewLabel(MyTemplatePreviewLabel(param))
class MyTemplateParameter(MyGroupParameter):
itemClass = MyTemplateParameterItem
def __init__(self, **opts):
opts['context'] = {'rename': 'Rename', 'remove': 'Remove', 'moveUp': 'Move up', 'moveDown': 'Move dn', 'separator': '----', 'preview': 'Preview', 'export': 'Export'}
opts['tip'] = 'Right click to manage template'
MyGroupParameter.__init__(self, **opts)
if 'children' in opts:
raise KeyError('Cannot set "children" argument in MyTemplateParameter opts')
d = opts.get('decimals', 5)
s = opts.get('suffix', 'm')
template = RollTemplate()
self.template = opts.get('value', template)
self.addChild(dict(name='Roll steps', type='myRollList', value=self.template.rollList, default=self.template.rollList, expanded=True, flat=True, decimals=d, suffix=s))
self.addChild(dict(name='Seed list', type='myTemplateSeedList', value=self.template.seedList, brush='#add8e6', flat=True))
self.parR = self.child('Roll steps')
self.parS = self.child('Seed list')
self.parR.sigValueChanged.connect(self.changed)
self.parS.sigValueChanged.connect(self.changed)
self.sigNameChanged.connect(self.nameChanged)
self.sigContextMenu.connect(self.contextMenu)
def nameChanged(self, _):
self.template.name = self.name()
def changed(self):
self.template.rollList = self.parR.value()
self.template.seedList = self.parS.value()
self.sigValueChanging.emit(self, self.value())
def value(self):
return self.template
def contextMenu(self, name=None):
parent = self.parent()
index = parent.children().index(self)
if not isinstance(parent, MyTemplateListParameter):
raise ValueError("Need 'MyTemplateListParameter' instances at this point")