179 lines
7.7 KiB
GDScript
179 lines
7.7 KiB
GDScript
@tool
|
||
extends 'res://scenes/контроль/прибор.gd'
|
||
|
||
enum STATE_VAL { NONE = 0, GOOD = 1, ERROR = 2 }
|
||
|
||
# Основные переменные
|
||
var unit_prd_n: Object
|
||
var ctrl_pos = 0
|
||
|
||
|
||
func _ready() -> void:
|
||
if Engine.is_editor_hint():
|
||
return
|
||
var unit_name = get_meta('unit_name')[0]
|
||
var prd_n_module = prd.prd_dict[unit_name]
|
||
unit_prd_n = prd_n_module.unit_control
|
||
var power_amplifier: Array = get_tree().get_nodes_in_group('power_amplifier')
|
||
for temp in power_amplifier:
|
||
temp.value1 = -70
|
||
unit_prd_n.connect('control_is_over', Callable(self, 'on_press_device'))
|
||
start_control()
|
||
on_press_device()
|
||
|
||
|
||
func _process(_delta: float) -> void:
|
||
if Engine.is_editor_hint():
|
||
return
|
||
set_frame($input_0, unit_prd_n.ems_input_1)
|
||
set_frame($input_1, unit_prd_n.ems_input_2)
|
||
set_frame($output_0, unit_prd_n.ems_output_1)
|
||
set_frame($output_1, unit_prd_n.ems_output_2)
|
||
|
||
|
||
func set_frame(node_frame: Node, val: int): node_frame.set_frame(val)
|
||
|
||
|
||
func start_control() -> void:
|
||
set_default_state(get_tree().get_nodes_in_group('default_reset'), get_tree().get_nodes_in_group('power_amplifier'))
|
||
find_labels(self)
|
||
|
||
|
||
static func set_default_state(default_reset_array_node: Array, power_amplifier_arr_node: Array) -> void:
|
||
for group in default_reset_array_node:
|
||
group.state = STATE_VAL.NONE
|
||
|
||
for group in power_amplifier_arr_node:
|
||
group.state = STATE_VAL.NONE
|
||
|
||
|
||
func _enter_tree() -> void:
|
||
if Engine.is_editor_hint():
|
||
return
|
||
$control_result.text = 'Ожидается запуск контроля ...' # TODO: Необходимо сделать пулл сообщений
|
||
$control_result.add_theme_color_override('font_color', Color.ALICE_BLUE)
|
||
|
||
|
||
func _exit_tree() -> void:
|
||
if Engine.is_editor_hint():
|
||
return
|
||
#prd_n_module.cmd_array.append([unit_prd_n.CmdCode.WRITE_ISA, [constants_n.ADDR_UG_LITERA_1, ug_work_1, constants_n.ADDR_UG_LITERA_2, ug_work_2]])
|
||
|
||
|
||
static func temperature_fill(temperature_arr_node: Array, temperature_dic: Dictionary)->void:
|
||
for i_node_temperature in temperature_arr_node:
|
||
var temperature_meta: String = i_node_temperature.get_meta('um')
|
||
if not temperature_dic.has(temperature_meta): return
|
||
i_node_temperature.value1 = temperature_dic[temperature_meta]
|
||
|
||
|
||
static func power_fill(pow_dic: Dictionary, fs_result: Dictionary, power_amplifier_arr_node: Array, POWER_THRESHOLD: int) -> void:
|
||
for i_node_powapm in power_amplifier_arr_node:
|
||
var powamp_meta: String = i_node_powapm.get_meta('um')
|
||
var status = STATE_VAL.GOOD if pow_dic else STATE_VAL.NONE
|
||
if not pow_dic.has(powamp_meta): return
|
||
if powamp_meta in ['um_1', 'um_2', 'um_3', 'um_4', 'um_5', 'um_6'] and not fs_result.fs_2: return
|
||
if powamp_meta in ['um_9', 'um_10', 'um_11', 'um_12', 'um_13', 'um_14'] and not fs_result.fs_3: return
|
||
i_node_powapm.value0 = pow_dic[powamp_meta]
|
||
var count_above_threshold = 0
|
||
for i_p in pow_dic[powamp_meta]:
|
||
if i_p >= POWER_THRESHOLD:
|
||
count_above_threshold += 1
|
||
|
||
status = STATE_VAL.GOOD if count_above_threshold >= 3 else STATE_VAL.ERROR
|
||
i_node_powapm.state = status
|
||
|
||
|
||
func on_press_device() -> void:
|
||
var nodes_y5: Array = get_tree().get_nodes_in_group('y-5')
|
||
var node_ip_power_arr: Array = get_tree().get_nodes_in_group('power_supply')
|
||
var fs_nodes: Array = get_tree().get_nodes_in_group('fs_group')
|
||
var power_amplifier_arr_node: Array = get_tree().get_nodes_in_group('power_amplifier')
|
||
var default_reset_array_node = get_tree().get_nodes_in_group('default_reset')
|
||
var module_fs_2: Node = $kasseta_FS_ND/ref_A4
|
||
var dou_2: Node = $dou2_A5
|
||
var module_fs_3: Node = $kasseta_FS_ND/ref_A3
|
||
var dou_3: Node = $dou3_A6
|
||
var for_control_result: Dictionary = {
|
||
'control_is_over': unit_prd_n.flag_control_is_over,
|
||
'result_dic': unit_prd_n.control_results,
|
||
'power_dic': unit_prd_n.power_result,
|
||
'block_kasseta_y5_config': unit_prd_n.block_kasseta_y5_config,
|
||
'block_ip_config': unit_prd_n.block_ip_config,
|
||
'temperature_um' : unit_prd_n.temperature_um,
|
||
'nodes_y5': nodes_y5,
|
||
'node_ip_power_arr': node_ip_power_arr,
|
||
'fs_nodes': fs_nodes,
|
||
'power_amplifier': power_amplifier_arr_node,
|
||
'default_reset_array_node': default_reset_array_node,
|
||
'POWER_THRESHOLD': unit_prd_n.constants.POWER_THRESHOLD,
|
||
'name_prd': unit_prd_n.self_name,
|
||
'module_fs_2': module_fs_2,
|
||
'dou_2': dou_2,
|
||
'module_fs_3': module_fs_3,
|
||
'dou_3': dou_3,
|
||
}
|
||
on_control_result(for_control_result)
|
||
|
||
|
||
static func on_control_result(for_result_dic: Dictionary) -> void:
|
||
temperature_fill(for_result_dic.power_amplifier, for_result_dic.temperature_um)
|
||
|
||
var block_kasseta_y5_prd_config_n: Dictionary = for_result_dic.block_kasseta_y5_config
|
||
var nodes_y5: Array = for_result_dic.nodes_y5
|
||
for node_y5 in nodes_y5:
|
||
var meta_y5 = node_y5.get_meta('y5')
|
||
if block_kasseta_y5_prd_config_n.has(meta_y5):
|
||
if not block_kasseta_y5_prd_config_n['yau07']:
|
||
node_y5.state = STATE_VAL.ERROR if meta_y5 == 'yau07' else STATE_VAL.NONE
|
||
break
|
||
node_y5.state = STATE_VAL.GOOD if block_kasseta_y5_prd_config_n[meta_y5] else STATE_VAL.ERROR
|
||
|
||
var block_ip_config_n: Dictionary = for_result_dic.block_ip_config
|
||
for power_supply in for_result_dic.node_ip_power_arr:
|
||
var meta_ip = power_supply.get_meta('ip')
|
||
if block_ip_config_n.has(meta_ip) and block_kasseta_y5_prd_config_n.ug:
|
||
power_supply.state = STATE_VAL.GOOD if block_ip_config_n[meta_ip][1] else STATE_VAL.ERROR
|
||
|
||
if not for_result_dic.control_is_over:
|
||
set_default_state(for_result_dic.default_reset_array_node, for_result_dic.power_amplifier)
|
||
return
|
||
var result_dic: Dictionary = for_result_dic.result_dic
|
||
for f in for_result_dic.fs_nodes:
|
||
var fs_meta: String = f.get_meta('fs')
|
||
if result_dic.has(fs_meta):
|
||
f.state = result_dic[fs_meta]
|
||
|
||
if result_dic.fs_2 == 1 and block_kasseta_y5_prd_config_n['yau07']:
|
||
for_result_dic.module_fs_2.state = STATE_VAL.GOOD if result_dic.dkm_2 else STATE_VAL.ERROR
|
||
for_result_dic.dou_2.state = STATE_VAL.GOOD if result_dic.dou_2 else STATE_VAL.ERROR
|
||
|
||
if result_dic.fs_3 == 1 and block_kasseta_y5_prd_config_n['yau07']:
|
||
for_result_dic.module_fs_3.state = STATE_VAL.GOOD if result_dic.dkm_3 else STATE_VAL.ERROR
|
||
for_result_dic.dou_3.state = STATE_VAL.GOOD if result_dic.dou_3 else STATE_VAL.ERROR
|
||
|
||
if block_kasseta_y5_prd_config_n['yau07']:
|
||
power_fill(for_result_dic.power_dic, for_result_dic.result_dic, for_result_dic.power_amplifier, for_result_dic.POWER_THRESHOLD)
|
||
var result: bool = true
|
||
for device in result_dic.values():
|
||
if not device:
|
||
result = false
|
||
|
||
log.message(Logger.INFO, 'Прибор ПРД-%s %s' % [for_result_dic.name_prd, ['неисправен', 'исправен'][int(result)]])
|
||
|
||
|
||
func find_labels(node1: Node):
|
||
if node1 is Label:
|
||
if node1.name in ["lbl_rname", "rname"]:
|
||
if not node1.has_meta("tooltip_set"):
|
||
ctrl_pos += 1
|
||
var box_number = ceili(float(ctrl_pos) / 10.0)
|
||
var position_number = ctrl_pos % 10
|
||
if position_number == 0:
|
||
position_number = 10
|
||
node1.tooltip_text = "Ящик - %d, Позиция - %d" % [box_number, position_number]
|
||
node1.mouse_filter = Control.MOUSE_FILTER_STOP
|
||
node1.set_meta("tooltip_set", true)
|
||
for child in node1.get_children():
|
||
find_labels(child)
|