diff --git a/.idea/PRD-TU-MP550.iml b/.idea/PRD-TU-MP550.iml index d0876a7..15e76cf 100644 --- a/.idea/PRD-TU-MP550.iml +++ b/.idea/PRD-TU-MP550.iml @@ -1,8 +1,7 @@ - + + - - \ No newline at end of file diff --git a/PRD_MP550.tscn b/PRD_MP550.tscn index 0b919ea..2cee148 100644 --- a/PRD_MP550.tscn +++ b/PRD_MP550.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=51 format=3 uid="uid://cvor2jm4xk3ha"] +[gd_scene load_steps=52 format=3 uid="uid://cvor2jm4xk3ha"] [ext_resource type="Script" path="res://scripts/PRD.gd" id="1_v273n"] [ext_resource type="Texture2D" uid="uid://cdxdluvyb5uei" path="res://table/on.png" id="2_dv7xx"] @@ -151,6 +151,9 @@ shader_parameter/color4 = Color(0, 0, 0, 0) shader_parameter/opacity = 0.218 shader_parameter/turn = 0.785 +[sub_resource type="Theme" id="Theme_qrfud"] +CheckBox/font_sizes/font_size = 14 + [node name="Node2D" type="Node2D"] script = ExtResource("1_v273n") @@ -202,7 +205,7 @@ mouse_default_cursor_shape = 2 theme_override_font_sizes/font_size = 14 theme_override_styles/pressed = SubResource("StyleBoxFlat_p247y") toggle_mode = true -text = "ЭМС Г" +text = "ЭМС-Г" [node name="select_fs" type="Button" parent="Background/side_panel"] layout_mode = 0 @@ -217,6 +220,7 @@ toggle_mode = true text = "Модуль ФС" [node name="save_config" type="Button" parent="Background/side_panel"] +layout_mode = 0 offset_top = 832.0 offset_right = 216.0 offset_bottom = 868.0 @@ -227,6 +231,7 @@ theme_override_styles/pressed = SubResource("StyleBoxFlat_p247y") text = "Сохранить" [node name="load_config" type="Button" parent="Background/side_panel"] +layout_mode = 0 offset_top = 872.0 offset_right = 216.0 offset_bottom = 908.0 @@ -234,7 +239,7 @@ focus_mode = 0 mouse_default_cursor_shape = 2 theme_override_font_sizes/font_size = 14 theme_override_styles/pressed = SubResource("StyleBoxFlat_p247y") -text = "Загрузить" +text = "Загрузить " [node name="Litera_3_5_7" type="ColorRect" parent="Background"] visible = false @@ -1130,6 +1135,15 @@ offset_right = 1102.0 offset_bottom = 226.0 text = "Темп" +[node name="save_other" type="CheckBox" parent="."] +offset_left = 2.0 +offset_top = 798.0 +offset_right = 216.0 +offset_bottom = 826.0 +theme = SubResource("Theme_qrfud") +text = "Сохранить все настройки" +alignment = 1 + [connection signal="pressed" from="Background/side_panel/select_prd" to="." method="_on_prd_select"] [connection signal="pressed" from="Background/side_panel/select_control" to="." method="_on_control_button"] [connection signal="pressed" from="Background/side_panel/select_ems_g" to="." method="_on_emsg_select"] diff --git a/ems_1 b/ems_1 new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/ems_1 @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/others-Н1 b/others-Н1 new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/others-Н1 @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/project.godot b/project.godot index 842c8be..6ab7c36 100644 --- a/project.godot +++ b/project.godot @@ -31,6 +31,10 @@ gdscript/warnings/unused_signal=0 window/size/viewport_width=1900 window/size/viewport_height=940 +[editor] + +run/main_run_args="-- testsave-path D://PRD-TU-MP550//testsave//" + [rendering] renderer/rendering_method="gl_compatibility" diff --git a/scripts/PRD.gd b/scripts/PRD.gd index e7067b1..8d718ea 100644 --- a/scripts/PRD.gd +++ b/scripts/PRD.gd @@ -10,9 +10,28 @@ var node_select2: Node var flag_yau_control: bool var CONTROL_TABLE: Array var isa_from_yau07b: Dictionary = {} +var JSOON = JSON.new() +var status_pribor = null +var save_path = "D://PRD-TU-MP550//save//" + +var need_port: Array = [ + 0x122, + 0x124, + 0x126, + 0x128, + 0x12A +] func _ready() -> void: + # Считывание аргументов с консоли (путь сохранения) + var args = OS.get_cmdline_user_args() + for i in range(args.size()): + if args[i] == "testsave-path" and i + 1 < args.size(): + save_path = args[i + 1] + break + print("путь сохранения: ", save_path) + # Таблица УКП_1 node_select1 = $TabContainer/PRD/body_grid/litera_2_4_6/table_ukp_1 draw_tabl(node_select1, Constants.ROWS_REGS_DATA, Constants.ROWS_REGS_DATA.size()) @@ -31,15 +50,20 @@ func _ready() -> void: var node_select_device = $TabContainer/PRD/select_dev draw_tabl(node_select_device, Constants.SELECT_DEVICE, Constants.SELECT_DEVICE.size()) var get_select_device = node_select_device.get_node2(1, 0) + get_select_device.connect('item_selected', Callable(self, 'on_device_selected')) # Заполнение адресов for i_addr in Constants.ADDRESSES.size(): get_select_device.add_item(Constants.ADDRESSES[i_addr][0]) - get_select_device.set_item_metadata(i_addr, Constants.ADDRESSES[i_addr].slice(1,7)) + get_select_device.set_item_metadata(i_addr, Constants.ADDRESSES[i_addr].slice(1, 7)) get_select_device.connect('item_selected', Callable(self, 'on_btn_select')) - node_select_device.get_node2(0,0).text = 'ПРИБОР' + node_select_device.get_node2(0, 0).text = 'ПРИБОР' node_select_device.set_columns_min_size([100, 100]) + if Constants.ADDRESSES.size() > 0: + get_select_device.select(0) + status_pribor = get_select_device.get_item_text(0).strip_edges().substr(4) + ## Заполненение списка направления луча for key in Constants.RAY_DICT: $TabContainer/PRD/body_grid/litera_2_4_6/yau_07b/Ray_set_1.add_item(key) @@ -57,6 +81,11 @@ func _ready() -> void: Network.connect('yau_read_isa', Callable(self, '_on_read_isa')) +func on_device_selected(selected_index: int) -> void: + var get_select_device = $TabContainer/PRD/select_dev.get_node2(1, 0) + status_pribor = get_select_device.get_item_text(selected_index).strip_edges().substr(4) + + func draw_control_panel_prd(mode) -> void: for node_path in Constants.NODE_MAP: var index = Constants.NODE_MAP[node_path] @@ -95,7 +124,6 @@ func _on_read_isa(unit_isa_ports: Dictionary) -> void: if len(Constants.EMS_G_PORT_DATA_HOLDER) == 32: emit_signal('read_ems_g_finish') $ISA.text = 'ISA: ' + str(len(Constants.EMS_G_PORT_DATA_HOLDER)) - if isa_data.has(Constants.BASE_PORTS.UG+6): $TabContainer/PRD/body_grid/litera_2_4_6/PSK/ray_1.material.set('shader_parameter/turn', 0.735 + 0.025 * (isa_data[0x106] & 0x7)) if isa_data.has(Constants.BASE_PORTS.UG+8): @@ -166,12 +194,81 @@ func _on_mfs_select() -> void: func _on_save_config(): - print('Тебе сюда') - + var file_dialog = FileDialog.new() + file_dialog.title = "Сохранить файл как" + file_dialog.set_size(Vector2(600, 400)) + file_dialog.mode = FileDialog.FILE_MODE_SAVE_FILE + file_dialog.current_dir = save_path + file_dialog.set_current_file("ЭМС-Г" + "-" + status_pribor) + file_dialog.connect("file_selected", Callable(self, "_save_selected_file")) + add_child(file_dialog) + file_dialog.popup_centered() + + +func _save_selected_file(file_path: String): + var data = Constants.EMS_G_PORT_DATA_HOLDER + var param_ems_g: Dictionary = {} + var other_data: Dictionary = {} + # Формируем словари + for item in data: + var regist: Dictionary = {} + regist[0x122] = item[0] + for key in item[1]: + if key in need_port: + regist[key] = item[1][key] + else: + other_data[key] = item[1] + param_ems_g[item[0]] = regist + var item_id = item[0] + # Переменные для сохранения + var ems_g_file = file_path + var ems_g_path = save_path + ems_g_file + var other_name = "others" + "-" + status_pribor + var other_path = save_path + other_name + var other_names = other_name + var other_counter = 1 + var dir = DirAccess.open(file_path.get_base_dir()) + # Сохранение данных ЭМС-Г + var file = FileAccess.open(ems_g_file, FileAccess.WRITE) + if file != null: + file.store_string(JSON.stringify(param_ems_g)) + file.close() + # Сохранение данных других + var save_other = $save_other.is_pressed() + if save_other: + while dir.file_exists(other_names): + other_names = other_name + "_" + str(other_counter) + other_path = save_path + other_names + other_counter += 1 + var other_file = FileAccess.open(other_path, FileAccess.WRITE) + if other_file != null: + other_file.store_string(JSON.stringify(other_data)) + other_file.close() + + +func _on_file_selected(file_path: String): + var file = FileAccess.open(file_path, FileAccess.READ) + # Проверка на открытие/чтение файла + if file != OK: + return + var file_content = file.get_as_text() + file.close() + var json = JSON.new() + var data = json.parse(file_content) + # Проверка на разбор содержимого файла + if data.error != OK: + return + Constants.EMS_G_PORT_DATA_HOLDER = data.result + func _on_load_config(): - print('тебе сюда') - + var file_dialog = FileDialog.new() + file_dialog.set_title("Выберите файл") + file_dialog.set_size(Vector2(600, 400)) + file_dialog.current_dir = save_path + file_dialog.access = FileDialog.ACCESS_FILESYSTEM + add_child(file_dialog) + file_dialog.popup_centered() func set_tab_and_buttons(tab_index: int, button_name: String) -> void: @@ -190,7 +287,7 @@ func on_btn_select(intem_from_sector: int) -> void: Network.on_command_change_device(meta) flag_mode = meta[2] draw_control_panel_prd(flag_mode) - + status_pribor = get_select_device.get_item_text(intem_from_sector).strip_edges().substr(4) func fill_item(node: Node, i_column: int, i_row: int, arr: Dictionary, select: int = 0) -> void: var optionbutton = node.get_node2(i_column, i_row) as OptionButton diff --git a/scripts/ems_g.gd b/scripts/ems_g.gd index e4bdd0b..eb23f74 100644 --- a/scripts/ems_g.gd +++ b/scripts/ems_g.gd @@ -9,11 +9,11 @@ func _on_read_ems_g(): Constants.EMS_G_PORT_DATA_HOLDER.clear() for i_input in 16: Network.write_port_isa(Constants.BASE_PORTS.EMS_G+2, 1+i_input) - Network.read_port_isa([Constants.BASE_PORTS.EMS_G+0xA]) + Network.read_port_isa([Constants.BASE_PORTS.EMS_G+2, Constants.BASE_PORTS.EMS_G+4, Constants.BASE_PORTS.EMS_G+6, Constants.BASE_PORTS.EMS_G+8,Constants.BASE_PORTS.EMS_G+0xA]) for i_output in range(46, 62): Network.write_port_isa(Constants.BASE_PORTS.EMS_G+2, 1+i_output) - Network.read_port_isa([Constants.BASE_PORTS.EMS_G+4, Constants.BASE_PORTS.EMS_G+8]) + Network.read_port_isa([Constants.BASE_PORTS.EMS_G+2, Constants.BASE_PORTS.EMS_G+4, Constants.BASE_PORTS.EMS_G+6, Constants.BASE_PORTS.EMS_G+8,Constants.BASE_PORTS.EMS_G+0xA]) func _on_sync():