Repository navigation
Expand file tree
/
Copy pathconfig_pages.py
More file actions
1893 lines (1791 loc) · 73.6 KB
/
Copy pathconfig_pages.py
File metadata and controls
1893 lines (1791 loc) · 73.6 KB
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
from __future__ import annotations
from collections.abc import Callable, Iterable
from typing import Any
from wolfeye.qt import (
QAbstractSpinBox,
QCheckBox,
QComboBox,
QDoubleSpinBox,
QFormLayout,
QGridLayout,
QGroupBox,
QHBoxLayout,
QHeaderView,
QLabel,
QLineEdit,
QPushButton,
QScrollArea,
QSpinBox,
QStackedWidget,
QTableWidget,
QTableWidgetItem,
QTabWidget,
QVBoxLayout,
QWidget,
)
from wolfeye.config_schema import AR_MODES, BAUD_RATES, BINARY_POINT_NAMES, TCC_TYPES
from wolfeye.services.beacheye import settings_point_catalog
from wolfeye.services.wolfeye import cycle_ar_stage
from wolfeye.numeric_schema import numeric_spec
from wolfeye.widgets.numeric_editor import configure_numeric_editor, numeric_value, set_numeric_value
from wolfeye.widgets.tcc_chart import TccChartDialog
def _get_path(root: dict[str, Any], path: str) -> Any:
value: Any = root
for part in path.split("."):
value = value[int(part)] if isinstance(value, list) else value[part]
return value
def _set_path(root: dict[str, Any], path: str, new_value: Any) -> None:
parts = path.split(".")
value: Any = root
for part in parts[:-1]:
value = value[int(part)] if isinstance(value, list) else value[part]
if isinstance(value, list):
value[int(parts[-1])] = new_value
else:
value[parts[-1]] = new_value
def _scroll_widget(content: QWidget) -> QScrollArea:
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setWidget(content)
return scroll
def _set_form_row_visible(form: QFormLayout, field: QWidget, visible: bool) -> None:
set_row_visible = getattr(form, "setRowVisible", None)
if set_row_visible is not None:
set_row_visible(field, visible)
return
label = form.labelForField(field)
if label is not None:
label.setVisible(visible)
field.setVisible(visible)
def _fit_table_rows(table: QTableWidget) -> None:
height = table.horizontalHeader().sizeHint().height()
height += sum(table.rowHeight(row) for row in range(table.rowCount()))
height += table.horizontalScrollBar().sizeHint().height()
height += table.frameWidth() * 2
table.setMinimumHeight(height)
def _set_numeric_editor_enabled(widget: QAbstractSpinBox, enabled: bool) -> None:
widget.setEnabled(enabled)
widget.setButtonSymbols(
QAbstractSpinBox.ButtonSymbols.UpDownArrows
if enabled
else QAbstractSpinBox.ButtonSymbols.NoButtons
)
class _BoundPage(QWidget):
def __init__(self) -> None:
super().__init__()
self._bindings: dict[str, list[QWidget]] = {}
def _bind(self, path: str, widget: QWidget) -> QWidget:
if isinstance(widget, (QSpinBox, QDoubleSpinBox)):
configure_numeric_editor(widget, path)
widget.setMinimumWidth(116)
self._bindings.setdefault(path, []).append(widget)
if isinstance(widget, QCheckBox):
widget.toggled.connect(
lambda _value, p=path, source=widget: self._mirror_binding(p, source)
)
elif isinstance(widget, QComboBox):
widget.currentTextChanged.connect(
lambda _value, p=path, source=widget: self._mirror_binding(p, source)
)
elif isinstance(widget, (QDoubleSpinBox, QSpinBox)):
widget.valueChanged.connect(
lambda _value, p=path, source=widget: self._mirror_binding(p, source)
)
elif isinstance(widget, QLineEdit):
widget.textChanged.connect(
lambda _value, p=path, source=widget: self._mirror_binding(p, source)
)
return widget
@staticmethod
def _widget_value(widget: QWidget) -> Any:
if isinstance(widget, QCheckBox):
return widget.isChecked()
if isinstance(widget, QComboBox):
if widget.property("bindItemData"):
return widget.currentData()
return widget.currentText()
if isinstance(widget, (QDoubleSpinBox, QSpinBox)):
return numeric_value(widget)
if isinstance(widget, (QLineEdit, QPushButton)):
return widget.text()
raise TypeError(f"Unsupported bound widget: {type(widget).__name__}")
@staticmethod
def _set_widget_value(widget: QWidget, value: Any) -> None:
blocked = widget.blockSignals(True)
try:
if isinstance(widget, QCheckBox):
widget.setChecked(bool(value))
elif isinstance(widget, QComboBox):
if widget.property("bindItemData"):
index = widget.findData(value)
if index < 0:
widget.addItem(f"Unknown point (ID {value})", value)
index = widget.count() - 1
widget.setCurrentIndex(index)
else:
widget.setCurrentText(str(value))
elif isinstance(widget, QDoubleSpinBox):
set_numeric_value(widget, float(value))
elif isinstance(widget, QSpinBox):
set_numeric_value(widget, int(value))
elif isinstance(widget, (QLineEdit, QPushButton)):
widget.setText(str(value))
finally:
widget.blockSignals(blocked)
def _mirror_binding(self, path: str, source: QWidget) -> None:
value = self._widget_value(source)
for widget in self._bindings.get(path, ()):
if widget is not source:
self._set_widget_value(widget, value)
def add_bool(self, form: QFormLayout, label: str, path: str) -> QCheckBox:
widget = QCheckBox()
self._bind(path, widget)
form.addRow(label, widget)
return widget
def add_int(
self,
form: QFormLayout,
label: str,
path: str,
minimum: int = 0,
maximum: int = 65535,
suffix: str = "",
) -> QSpinBox | QDoubleSpinBox:
spec = numeric_spec(path)
# Qt's QSpinBox is signed int32; uint32 needs a zero-decimal double.
widget = QDoubleSpinBox() if spec and spec.maximum > 2**31 - 1 else QSpinBox()
widget.setRange(minimum, maximum)
widget.setSuffix(suffix)
self._bind(path, widget)
form.addRow(label, widget)
return widget
def add_float(
self,
form: QFormLayout,
label: str,
path: str,
minimum: float = 0.0,
maximum: float = 9999.0,
decimals: int = 2,
suffix: str = "",
) -> QDoubleSpinBox:
widget = QDoubleSpinBox()
widget.setRange(minimum, maximum)
widget.setDecimals(decimals)
widget.setSuffix(suffix)
widget.setSingleStep(0.01 if decimals > 1 else 0.1)
self._bind(path, widget)
form.addRow(label, widget)
return widget
def add_combo(
self, form: QFormLayout, label: str, path: str, choices: Iterable[str]
) -> QComboBox:
widget = QComboBox()
widget.addItems([str(value) for value in choices])
self._bind(path, widget)
form.addRow(label, widget)
return widget
def add_data_combo(
self,
form: QFormLayout,
label: str,
path: str,
choices: Iterable[tuple[int, str]],
) -> QComboBox:
widget = QComboBox()
widget.setProperty("bindItemData", True)
for value, text in choices:
widget.addItem(str(text), int(value))
self._bind(path, widget)
form.addRow(label, widget)
return widget
def add_text(
self, form: QFormLayout, label: str, path: str, width: int = 160
) -> QLineEdit:
widget = QLineEdit()
widget.setMaximumWidth(width)
self._bind(path, widget)
form.addRow(label, widget)
return widget
def apply_config(self, config: dict[str, Any]) -> None:
for path, widgets in self._bindings.items():
value = _get_path(config, path)
for widget in widgets:
self._set_widget_value(widget, value)
def update_config(self, config: dict[str, Any]) -> None:
for path, widgets in self._bindings.items():
if not widgets:
continue
value = self._widget_value(widgets[0])
if isinstance(widgets[0], QLineEdit):
value = str(value).strip()
_set_path(config, path, value)
@staticmethod
def _section(title: str) -> tuple[QGroupBox, QFormLayout]:
box = QGroupBox(title)
form = QFormLayout(box)
form.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.AllNonFixedFieldsGrow)
return box, form
class GeneralPage(_BoundPage):
"""Every editable General/SCADA/I/O field exposed by the original client."""
def __init__(self) -> None:
super().__init__()
self._function_operand_boxes: dict[str, list[QComboBox]] = {
"binary": [],
"analog": [],
}
self._function_row_refreshers: list[Callable[[], None]] = []
self._point_catalog = self._load_point_catalog("FC22AR", 50)
root = QVBoxLayout(self)
self.tabs = QTabWidget()
root.addWidget(self.tabs)
self._measurement_tab()
self._dnp3_tab()
self._iec_tab()
self._ports_tab()
self._io_tab()
self._system_tab()
self._functions_tab()
self._security_tab()
@staticmethod
def _load_point_catalog(
model: str, build: int
) -> dict[str, tuple[tuple[int, str], ...]]:
try:
return settings_point_catalog(model, build)
except (AttributeError, KeyError, OSError, RuntimeError, ValueError):
return {"binary": (), "analog": ()}
@staticmethod
def _populate_operand_combo(
combo: QComboBox, choices: Iterable[tuple[int, str]]
) -> None:
selected = combo.currentData()
blocked = combo.blockSignals(True)
try:
combo.clear()
combo.addItem("NOT SELECTED", 0)
for point_id, name in choices:
combo.addItem(str(name), int(point_id))
index = combo.findData(selected)
if index < 0 and selected not in (None, 0):
combo.addItem(f"Unknown point (ID {selected})", selected)
index = combo.count() - 1
combo.setCurrentIndex(max(0, index))
finally:
combo.blockSignals(blocked)
def set_device_model(self, model: str, build: int = 50) -> None:
self._point_catalog = self._load_point_catalog(model, build)
for kind, combos in self._function_operand_boxes.items():
for combo in combos:
self._populate_operand_combo(combo, self._point_catalog[kind])
def apply_config(self, config: dict[str, Any]) -> None:
super().apply_config(config)
for refresh in self._function_row_refreshers:
refresh()
def _new_grid_tab(self, title: str) -> QGridLayout:
content = QWidget()
grid = QGridLayout(content)
grid.setAlignment(grid.alignment())
grid.setColumnStretch(0, 1)
grid.setColumnStretch(1, 1)
grid.setRowStretch(99, 1)
self.tabs.addTab(_scroll_widget(content), title)
return grid
def _measurement_tab(self) -> None:
grid = self._new_grid_tab("Measurement")
box, form = self._section("Rated Values")
self.add_combo(
form, "Frequency", "general.measurement.frequency_hz", ("50", "60")
)
self.add_int(
form, "Voltage", "general.measurement.rated_voltage_v", 0, 99900, " V"
)
self.add_combo(
form, "Source Side", "general.measurement.source_side", ("ABC", "RST")
)
self.add_combo(
form, "Phase Rotation", "general.measurement.phase_rotation", ("ABC", "ACB", "BCA", "CAB", "BAC", "CBA")
)
self.add_float(form, "LSD Level", "general.system.lsd_level", 0.5, 6.0, 1)
grid.addWidget(box, 0, 0)
box, form = self._section("Current Coefficients")
for label, name in (
("Line A", "line_a"),
("Line B", "line_b"),
("Line C", "line_c"),
("Residual", "residual"),
):
self.add_int(
form, label, f"general.measurement.coefficients.{name}", 1, 9999
)
grid.addWidget(box, 0, 1)
box, form = self._section("Deadbands")
specs = (
("Voltages", "voltages_v", "float", 0.1, 65.0, " kV"),
("Phase Currents", "phase_currents_a", "int", 1, 99, " A"),
("Residual Currents", "residual_currents_a", "int", 1, 99, " A"),
("Battery Voltage", "battery_voltage_v", "float", 1.0, 10.0, " V"),
("Power Factor", "power_factor_pct", "int", 5, 99, " %"),
("Frequency", "frequency_hz", "float", 0.0, 99.9, " Hz"),
("Powers", "powers", "int", 1000, 9999, ""),
("Counters", "counters", "int", 1, 9999, ""),
)
for label, name, kind, low, high, suffix in specs:
path = f"general.measurement.deadbands.{name}"
if kind == "int":
self.add_int(form, label, path, int(low), int(high), suffix)
else:
self.add_float(form, label, path, float(low), float(high), 1, suffix)
grid.addWidget(box, 1, 0, 1, 2)
box, form = self._section("SCADA")
self.add_bool(form, "Enabled", "general.scada.enabled")
self.add_combo(form, "Protocol", "general.scada.protocol", ("DNP3", "IEC"))
self.add_combo(
form,
"Data Port",
"general.scada.data_port",
("ETHERNET", "RS232", "RS485", "MODEM"),
)
grid.addWidget(box, 2, 0, 1, 2)
def _dnp3_tab(self) -> None:
grid = self._new_grid_tab("DNP3")
box, form = self._section("Link")
p = "general.scada.dnp3.link"
self.add_int(form, "Slave Address", f"{p}.slave_address", 0, 65534)
self.add_int(form, "Master Address", f"{p}.master_address", 0, 65534)
self.add_int(form, "Confirm Retry", f"{p}.confirm_retry", 0, 32767)
self.add_float(
form, "Confirm Timeout", f"{p}.confirm_timeout_s", 1, 255, 2, " s"
)
self.add_float(form, "Keep Alive", f"{p}.keep_alive_s", 60, 9999, 2, " s")
self.add_bool(form, "Confirm User Data", f"{p}.confirm_user_data")
self.add_bool(form, "Keep Alive Enable", f"{p}.keep_alive_enabled")
grid.addWidget(box, 0, 0)
box, form = self._section("Application")
p = "general.scada.dnp3.application"
self.add_int(form, "Cold Restart Delay", f"{p}.cold_restart_delay")
self.add_int(form, "Warm Restart Delay", f"{p}.warm_restart_delay")
self.add_float(
form,
"Solicited Confirm Timeout",
f"{p}.solicited_confirm_timeout_s",
1,
255,
2,
" s",
)
self.add_float(form, "Select Timeout", f"{p}.select_timeout_s", 1, 255, 2, " s")
grid.addWidget(box, 0, 1)
box, form = self._section("Unsolicited")
p = "general.scada.dnp3.unsolicited"
self.add_bool(form, "Enable Unsolicited", f"{p}.enabled")
for number in range(1, 4):
self.add_bool(form, f"Enable Class {number}", f"{p}.class_{number}")
unused_buffer = self.add_int(form, "Max Event Buffer", f"{p}.max_event_buffer", 1, 99)
unused_buffer.setEnabled(False)
unused_buffer.setToolTip("Not used or serialized by the company settings ABI.")
self.add_int(form, "Hold Time", f"{p}.hold_time_s", 0, 10, " s")
grid.addWidget(box, 1, 0)
box, form = self._section("Time Synchronization")
p = "general.scada.dnp3.time_sync"
self.add_bool(form, "Enable", f"{p}.enabled")
self.add_float(
form, "Request Time Interval", f"{p}.request_interval_s", 300, 9999, 2, " s"
)
grid.addWidget(box, 1, 1)
box, form = self._section("Mapping")
p = "general.scada.dnp3.mapping"
mappings = (
("Static Binary Input", "static_binary_input", ("G1V1", "G1V2")),
("Event Binary Input", "event_binary_input", ("G2V1", "G2V2", "G2V3")),
(
"Static Analog Input",
"static_analog_input",
tuple(f"G30V{i}" for i in range(1, 7)),
),
(
"Event Analog Input",
"event_analog_input",
tuple(f"G32V{i}" for i in range(1, 9)),
),
("Event Double Binary", "event_double_binary", ("G4V1", "G4V2", "G4V3")),
("Event Binary Output", "event_binary_output", ("G11V1", "G11V2")),
(
"Static Analog Output",
"static_analog_output",
tuple(f"G40V{i}" for i in range(1, 5)),
),
(
"Event Analog Output",
"event_analog_output",
tuple(f"G42V{i}" for i in range(1, 9)),
),
("Static Counter", "static_counter", ("G20V1", "G20V2", "G20V5", "G20V6")),
("Event Counter", "event_counter", ("G22V1", "G22V2", "G22V5", "G22V6")),
)
for label, name, values in mappings:
self.add_combo(form, label, f"{p}.{name}", values)
grid.addWidget(box, 2, 0, 1, 2)
def _iec_tab(self) -> None:
grid = self._new_grid_tab("IEC")
box, form = self._section("General")
p = "general.scada.iec.general"
self.add_combo(form, "ASDU Address Size", f"{p}.asdu_address_size", ("1", "2"))
self.add_int(form, "ASDU Address", f"{p}.asdu_address")
self.add_combo(form, "IOA Size", f"{p}.ioa_size", ("1", "2", "3"))
self.add_combo(form, "COT Size", f"{p}.cot_size", ("1", "2"))
self.add_int(form, "Originator Address", f"{p}.originator_address")
self.add_bool(form, "ACTTERM", f"{p}.actterm")
self.add_bool(form, "Time Synchronization", f"{p}.time_sync")
grid.addWidget(box, 0, 0)
box, form = self._section("Base Addresses")
p = "general.scada.iec.base_addresses"
for label, name in (
("Single Status", "single_status"),
("Double Status", "double_status"),
("Measured Values", "measured_values"),
("Integrated Total", "integrated_total"),
("Single Command", "single_command"),
("Double Command", "double_command"),
("Set Point Command", "set_point_command"),
("Parameter Command", "parameter_command"),
):
self.add_int(form, label, f"{p}.{name}")
grid.addWidget(box, 0, 1)
box, form = self._section("IEC 101")
p = "general.scada.iec.iec101"
self.add_combo(form, "Link Address Size", f"{p}.link_address_size", ("1", "2"))
self.add_int(form, "Link Address", f"{p}.link_address")
self.add_combo(
form, "Channel Mode", f"{p}.channel_mode", ("BALANCED", "UNBALANCED")
)
self.add_float(form, "ACK Timeout", f"{p}.ack_timeout_s", 1, 255, 2, " s")
self.add_float(form, "Repeat Timeout", f"{p}.repeat_timeout_s", 1, 255, 2, " s")
self.add_int(form, "Channel Retry", f"{p}.channel_retry")
self.add_float(form, "RX Timeout", f"{p}.rx_timeout_s", 1, 255, 2, " s")
self.add_bool(form, "Single Character ACK", f"{p}.single_char_ack")
grid.addWidget(box, 1, 0)
box, form = self._section("IEC 104")
p = "general.scada.iec.iec104"
for number in range(4):
self.add_float(
form, f"Timeout {number}", f"{p}.timeout_{number}_s", 1, 255, 2, " s"
)
self.add_int(form, "K", f"{p}.k")
self.add_int(form, "W", f"{p}.w")
grid.addWidget(box, 1, 1)
def _serial_section(self, title: str, path: str) -> QGroupBox:
box, form = self._section(title)
self.add_combo(form, "Baudrate", f"{path}.baudrate", BAUD_RATES)
self.add_combo(form, "Parity", f"{path}.parity", ("NONE", "ODD", "EVEN"))
self.add_combo(form, "Stop Bits", f"{path}.stop_bits", ("1", "2"))
self.add_combo(form, "Data Bits", f"{path}.data_bits", ("7", "8"))
return box
def _ports_tab(self) -> None:
grid = self._new_grid_tab("Ports")
grid.addWidget(self._serial_section("RS485", "general.scada.ports.rs485"), 0, 0)
grid.addWidget(self._serial_section("RS232", "general.scada.ports.rs232"), 0, 1)
box, form = self._section("Ethernet Transport")
p = "general.scada.ports.ethernet"
self.add_combo(form, "Mode", f"{p}.mode", ("SERVER", "CLIENT"))
self.add_int(form, "Local Port", f"{p}.local_port", 0, 65535)
self.add_int(form, "Remote Port", f"{p}.remote_port", 0, 65535)
self.add_text(form, "Remote IP", f"{p}.remote_ip")
grid.addWidget(box, 1, 0)
box, form = self._section("Modem")
p = "general.scada.ports.modem"
apn = self.add_text(form, "APN Name", f"{p}.apn")
apn.setMaxLength(15)
self.add_combo(form, "Network", f"{p}.network", ("AUTO", "GSM", "LTE"))
self.add_combo(form, "Baudrate", f"{p}.baudrate", BAUD_RATES)
self.add_combo(form, "Mode", f"{p}.mode", ("SERVER", "CLIENT"))
self.add_int(form, "Local Port", f"{p}.local_port", 0, 65535)
self.add_int(form, "Remote Port", f"{p}.remote_port", 0, 65535)
self.add_text(form, "Remote IP", f"{p}.remote_ip")
grid.addWidget(box, 1, 1)
def _io_tab(self) -> None:
grid = self._new_grid_tab("I/O")
box, form = self._section("Open / Close")
p = "general.io.open_close"
self.add_combo(
form, "Open Read Mode", f"{p}.open_read_mode", ("SINGLE", "DOUBLE")
)
self.add_combo(
form, "Close Read Mode", f"{p}.close_read_mode", ("SINGLE", "DOUBLE")
)
self.add_bool(form, "Open Need Confirm", f"{p}.open_need_confirm")
self.add_bool(form, "Close Need Confirm", f"{p}.close_need_confirm")
grid.addWidget(box, 0, 0)
box, form = self._section("Ethernet")
p = "general.io.ethernet"
self.add_bool(form, "DHCP", f"{p}.dhcp")
self.add_text(form, "IP", f"{p}.ip")
self.add_text(form, "Subnet Mask", f"{p}.subnet_mask")
self.add_text(form, "Gateway", f"{p}.gateway")
grid.addWidget(box, 0, 1)
box, form = self._section("Digital Inputs")
p = "general.io.digital_inputs"
self.add_bool(form, "Chatter Enabled", f"{p}.chatter_enabled")
self.add_float(
form, "Chatter Reset Time", f"{p}.chatter_reset_s", 5, 60, 3, " s"
)
self.add_float(
form, "Validation Time", f"{p}.validation_time_s", 0.002, 0.128, 3, " s"
)
for index in range(7):
self.add_combo(
form,
f"Input {index + 1}",
f"{p}.inputs.{index}",
("DISABLE", "HIGH STATE", "LOW STATE"),
)
grid.addWidget(box, 1, 0)
outputs = QGroupBox("Digital Outputs")
table = QTableWidget(7, 6, outputs)
table.setHorizontalHeaderLabels(
("Output", "If", "Get", "Recogn. (s)", "Then", "Pulse (s)")
)
table.verticalHeader().setVisible(False)
header = table.horizontalHeader()
header.setSectionResizeMode(QHeaderView.ResizeMode.Fixed)
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
for column, width in enumerate((55, 120, 68, 82, 86, 82)):
table.setColumnWidth(column, width)
layout = QVBoxLayout(outputs)
layout.addWidget(table)
for index in range(7):
table.setItem(index, 0, QTableWidgetItem(f"DO{index + 1}"))
when = QComboBox()
when.setProperty("bindItemData", True)
self._populate_operand_combo(when, self._point_catalog["binary"])
self._function_operand_boxes["binary"].append(when)
active = QComboBox()
active.addItems(("FALSE", "TRUE"))
recognition = QDoubleSpinBox()
recognition.setRange(0.01, 120)
recognition.setDecimals(3)
recognition.setSuffix(" s")
status = QComboBox()
status.addItems(("DISABLE", "LATCH ON", "PULSE ON"))
pulse = QDoubleSpinBox()
pulse.setRange(0.01, 120)
pulse.setDecimals(3)
pulse.setSuffix(" s")
for column, widget in enumerate(
(when, active, recognition, status, pulse), 1
):
widget.setStyleSheet("min-width: 0px;")
table.setCellWidget(index, column, widget)
base = f"general.io.digital_outputs.{index}"
self._bind(f"{base}.when", when)
self._bind(f"{base}.is", active)
self._bind(f"{base}.recognition_s", recognition)
self._bind(f"{base}.then", status)
self._bind(f"{base}.for_s", pulse)
status.currentTextChanged.connect(
lambda value, target=pulse: target.setEnabled(value == "PULSE ON")
)
grid.addWidget(outputs, 1, 1)
indicators = QGroupBox("Indicators")
table = QTableWidget(6, 4, indicators)
table.setHorizontalHeaderLabels(("LED", "When", "Is", "Then"))
table.verticalHeader().setVisible(False)
table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
layout = QVBoxLayout(indicators)
layout.addWidget(table)
for index in range(6):
table.setItem(index, 0, QTableWidgetItem(f"LED{index + 1}"))
when = QComboBox()
when.addItems(BINARY_POINT_NAMES)
active = QComboBox()
active.addItems(("FALSE", "TRUE"))
status = QComboBox()
status.addItems(("DISABLE", "ON", "BLINK"))
for column, widget in enumerate((when, active, status), 1):
table.setCellWidget(index, column, widget)
base = f"general.io.indicators.{index}"
self._bind(f"{base}.when", when)
self._bind(f"{base}.is", active)
self._bind(f"{base}.then", status)
_fit_table_rows(table)
grid.addWidget(indicators, 2, 0, 1, 2)
def _security_tab(self) -> None:
grid = self._new_grid_tab("Security & Heater")
box, form = self._section("Heater")
self.add_bool(form, "Enable", "general.heater.enabled")
self.add_int(
form, "On Temperature", "general.heater.on_temperature_c", 0, 60, " °C"
)
self.add_int(
form, "Off Temperature", "general.heater.off_temperature_c", 0, 60, " °C"
)
grid.addWidget(box, 0, 0)
box, form = self._section("Security")
p = "general.security"
self.add_bool(form, "TLS", f"{p}.tls")
self.add_bool(form, "Web Security", f"{p}.web")
self.add_int(form, "Password", f"{p}.password", 0, 65535)
self.add_bool(form, "Default Certificate", f"{p}.default_certificate")
for index in range(4):
self.add_text(
form, f"Allowed Remote IP {index + 1}", f"{p}.remote_ips.{index}"
)
grid.addWidget(box, 0, 1)
def _system_tab(self) -> None:
grid = self._new_grid_tab("System")
box, form = self._section("Fault Locator")
p = "general.system.fault_locator"
self.add_bool(form, "Enable", f"{p}.enabled")
for label, name in (("R0", "r0"), ("X0", "x0"), ("R1", "r1"), ("X1", "x1")):
self.add_float(form, label, f"{p}.{name}", 0.001, 50.0, 3)
self.add_float(
form, "Length of Line", f"{p}.line_length_km", 0.01, 30.0, 2, " km"
)
grid.addWidget(box, 0, 0)
box, form = self._section("Synchronization - General")
p = "general.system.synchronization"
self.add_bool(form, "Enable", f"{p}.enabled")
self.add_combo(
form,
"Phase Selection",
f"{p}.phase_selection",
("PHASE TO GROUND", "PHASE TO PHASE"),
)
self.add_combo(
form, "Bus and Line", f"{p}.bus_and_line", ("ABC/RST", "RST/ABC")
)
self.add_combo(
form,
"Live/Dead Autoreclose",
f"{p}.live_dead_autoreclose",
("DISABLE", "LIVE BUS", "LIVE LINE", "LIVE/DEAD"),
)
self.add_bool(form, "DLDB Autoreclose", f"{p}.dldb_autoreclose")
self.add_combo(
form,
"Live/Dead Manual Close",
f"{p}.live_dead_manual_close",
("DISABLE", "LIVE BUS", "LIVE LINE", "LIVE/DEAD"),
)
self.add_bool(form, "DLDB Manual Close", f"{p}.dldb_manual_close")
for label, name, low, high in (
("Live Bus Voltage Multiplier", "live_bus_voltage_multiplier", 0.3, 1.2),
("Live Line Voltage Multiplier", "live_line_voltage_multiplier", 0.3, 1.2),
("Bus Max Voltage Multiplier", "bus_max_voltage_multiplier", 0.8, 1.4),
("Line Max Voltage Multiplier", "line_max_voltage_multiplier", 0.8, 1.4),
("Voltage Difference Multiplier", "voltage_difference_multiplier", 0.03, 0.5),
):
self.add_float(form, label, f"{p}.{name}", low, high, 2)
grid.addWidget(box, 0, 1)
box, form = self._section("Synchronism")
self.add_bool(form, "Enable for Recloser", f"{p}.sync_enabled_for_recloser")
self.add_float(
form, "Max Slip Frequency", f"{p}.max_slip_frequency_hz", 0.03, 0.1, 2, " Hz"
)
self.add_int(
form,
"Phase Angle Difference",
f"{p}.phase_angle_difference_deg",
0,
90,
" °",
)
self.add_float(
form, "Manual Pre-Sync Time", f"{p}.manual_pre_sync_s", 0, 60, 2, " s"
)
grid.addWidget(box, 1, 0)
box, form = self._section("Auto Synchroniser")
self.add_int(
form,
"Fundamental Frequency",
f"{p}.fundamental_frequency_hz",
47,
64,
" Hz",
)
for label, name, low, high, suffix in (
("Max Frequency Deviation", "max_frequency_deviation_hz", 0, 1, " Hz"),
("Max Slip", "auto_max_slip_hz", 0.03, 0.5, " Hz"),
("Max ROC Slip", "max_roc_slip_hz_s", 0.01, 1, " Hz/s"),
):
self.add_float(form, label, f"{p}.{name}", low, high, 2, suffix)
self.add_float(form, "Waiting Time", f"{p}.waiting_time_s", 100, 3600, 2, " s")
self.add_bool(form, "Anti-Motoring", f"{p}.anti_motoring_s")
grid.addWidget(box, 1, 1)
def _functions_tab(self) -> None:
container = QTabWidget()
self.function_tabs = container
for index in range(16):
content = QWidget()
form = QFormLayout(content)
p = f"general.system.functions.{index}"
self.add_bool(form, "Enabled", f"{p}.enabled")
value_type = self.add_combo(
form, "Value Type", f"{p}.value_type", ("BINARY", "ANALOG")
)
binary_operator = self.add_combo(
form,
"Binary Operator",
f"{p}.operator",
("OR", "AND", "EQUAL"),
)
binary_operands: list[QComboBox] = []
for label, name in (
("Binary Value A", "value_a"),
("Binary Value B", "value_b"),
("Binary Value C", "value_c"),
):
operand = self.add_data_combo(
form,
label,
f"{p}.{name}",
((0, "NOT SELECTED"), *self._point_catalog["binary"]),
)
binary_operands.append(operand)
self._function_operand_boxes["binary"].append(operand)
compared_to = self.add_combo(
form, "Compared To", f"{p}.compared_to", ("FALSE", "TRUE")
)
analog_operator = self.add_combo(
form,
"Analog Operator",
f"{p}.analog_operator",
("GREATER", "LESS"),
)
analog_operand = self.add_data_combo(
form,
"Analog Value A",
f"{p}.analog_value_a",
((0, "NOT SELECTED"), *self._point_catalog["analog"]),
)
self._function_operand_boxes["analog"].append(analog_operand)
analog_value = self.add_int(
form,
"Analog Compared To",
f"{p}.analog_compared_to",
0,
9_999_999,
)
self.add_float(form, "Time", f"{p}.time_s", 0, 10, 3, " s")
self.add_combo(
form,
"Action",
f"{p}.action",
("NOTHING", "OPEN", "CLOSE"),
)
def refresh_rows(
_value: str = "",
*,
form: QFormLayout = form,
value_type: QComboBox = value_type,
binary_operator: QComboBox = binary_operator,
binary_operands: list[QComboBox] = binary_operands,
compared_to: QComboBox = compared_to,
analog_operator: QComboBox = analog_operator,
analog_operand: QComboBox = analog_operand,
analog_value: QSpinBox = analog_value,
) -> None:
is_binary = value_type.currentText() == "BINARY"
is_equal = binary_operator.currentText() == "EQUAL"
_set_form_row_visible(form, binary_operator, is_binary)
_set_form_row_visible(form, binary_operands[0], is_binary)
_set_form_row_visible(form, binary_operands[1], is_binary and not is_equal)
_set_form_row_visible(form, binary_operands[2], is_binary and not is_equal)
_set_form_row_visible(form, compared_to, is_binary and is_equal)
_set_form_row_visible(form, analog_operator, not is_binary)
_set_form_row_visible(form, analog_operand, not is_binary)
_set_form_row_visible(form, analog_value, not is_binary)
value_type.currentTextChanged.connect(refresh_rows)
binary_operator.currentTextChanged.connect(refresh_rows)
self._function_row_refreshers.append(refresh_rows)
refresh_rows()
container.addTab(_scroll_widget(content), f"Function {index + 1}")
self.tabs.addTab(container, "Functions")
class ProtectionPage(_BoundPage):
ELEMENT_NAMES = (
"Delayed +",
"Fast Trip +",
"Highset +",
"Delayed -",
"Fast Trip -",
"Highset -",
)
def __init__(self) -> None:
super().__init__()
self._config: dict[str, Any] | None = None
self._device_model = "FC22AR"
self._global_widgets: dict[str, QCheckBox] = {}
self._feature_widgets: dict[str, QCheckBox] = {}
self._group_tabs: list[QTabWidget] = []
self._master_extension_tabs: list[QTabWidget] = []
self._tcc_field_refreshers: list[tuple[QComboBox, Callable[[str], None]]] = []
self._chart_dialogs: set[TccChartDialog] = set()
root = QVBoxLayout(self)
general = QGroupBox("Protection")
row = QGridLayout(general)
self.group_select = QComboBox()
self.group_select.addItems(("Group 1", "Group 2", "Group 3", "Group 4"))
row.addWidget(QLabel("Selected Group"), 0, 0)
row.addWidget(self.group_select, 0, 1)
self.device_badge = QLabel("AUTO RECLOSER · FC22AR")
self.device_badge.setObjectName("protectionDeviceBadge")
row.addWidget(self.device_badge, 1, 0, 1, 2)
toggles = (
("Protection", "enabled"),
("Enable OC", "oc_enabled"),
("Enable EF", "ef_enabled"),
("Enable SEF", "sef_enabled"),
("Enable CLP", "clp_enabled"),
("Enable IR", "inrush_enabled"),
("Frequency Protection", "frequency_enabled"),
("Voltage Protection", "voltage_enabled"),
("Live Line", "live_line_enabled"),
)
for index, (label, name) in enumerate(toggles):
widget = QCheckBox(label)
self._bind(f"protection.{name}", widget)
self._global_widgets[name] = widget
row.addWidget(widget, index // 6, index % 6 + 2)
master_flags = (
"NPS",
"Admittance",
"Over Voltage",
"Over Frequency",
"Harmonic",
"ABR",
"Alarm Mode",
"Hot Line Tag",
"LL Link To HLT",
"UV4 Sag",
"OV3",
"ROCOF",
"VVS",
"PDOP",
"PDUP",
"DFT",
"SSM",
"Harmonic IR Blocking",
"Logical Block Close",
"LLB",
"Sectionalizer",
"Breaker",
)
for index, label in enumerate(master_flags):
name = label.lower().replace(" ", "_")
widget = QCheckBox(label)
self._bind(f"protection.feature_flags.{name}", widget)
self._feature_widgets[name] = widget
row.addWidget(widget, 2 + index // 7, index % 7)
sectionalizer = self._feature_widgets["sectionalizer"]
breaker = self._feature_widgets["breaker"]
sectionalizer.toggled.connect(
lambda checked: breaker.setChecked(False) if checked else None
)
breaker.toggled.connect(
lambda checked: sectionalizer.setChecked(False) if checked else None
)
root.addWidget(general)
self.group_stack = QStackedWidget()
root.addWidget(self.group_stack, 1)
for index in range(4):
self.group_stack.addWidget(self._build_group(index))
self.group_select.currentIndexChanged.connect(self.group_stack.setCurrentIndex)
self.set_device_model(self._device_model)
def _build_group(self, group_index: int) -> QWidget:
tabs = QTabWidget()
base = f"protection.groups.{group_index}"
tabs.addTab(self._ocef_tab(base), "OCEF / TCC")
tabs.addTab(self._nps_tab(base), "NPS")
tabs.addTab(self._sef_tab(base), "SEF / Reclosing")
tabs.addTab(self._auxiliary_tab(base), "Auxiliary")
tabs.addTab(self._voltage_tab(base), "Voltage / Frequency / ABR")
tabs.addTab(self._master_extensions_tab(base), "Master Extensions")
tabs.addTab(self._sectionalizer_protection_tab(base), "Protection")
tabs.addTab(self._sectionalizer_master(base), "Sectionalizing / Breaker")
tabs.addTab(self._sectionalizer_voltage_tab(base), "Voltage / BC46")
self._group_tabs.append(tabs)
return tabs
def _nps_tab(self, base: str) -> QWidget:
content = QWidget()
layout = QVBoxLayout(content)
layout.addWidget(
self._element_table(
"Negative Phase Sequence (NPS)", f"{base}.nps", self.ELEMENT_NAMES
)
)
box, form = self._section("Directional NPS")
self.add_int(form, "Torque Angle", f"{base}.nps.torque_angle_deg", 0, 359, " °")
layout.addWidget(box)
layout.addStretch()
return _scroll_widget(content)
def _master_extensions_tab(self, base: str) -> QWidget:
tabs = QTabWidget()
tabs.addTab(self._directional_master(base), "Directional / Yn")
tabs.addTab(self._quality_master(base), "Overload / IR")
tabs.addTab(self._voltage_master(base), "Voltage / AR")
tabs.addTab(self._harmonic_master(base), "Frequency / Harmonic")
tabs.addTab(self._sectionalizer_master(base), "Sectionalizer")