From 5369156cc8d30e81d0f6c348fc9c74dbf929c331 Mon Sep 17 00:00:00 2001 From: Andras Fuchs Date: Thu, 13 Feb 2020 14:50:04 +0100 Subject: [PATCH 1/5] We load the rules file even is the design name doesn't match --- .../eu/mihosoft/freerouting/designforms/specctra/RulesFile.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/eu/mihosoft/freerouting/designforms/specctra/RulesFile.java b/src/main/java/eu/mihosoft/freerouting/designforms/specctra/RulesFile.java index 025aef8..a0380c6 100644 --- a/src/main/java/eu/mihosoft/freerouting/designforms/specctra/RulesFile.java +++ b/src/main/java/eu/mihosoft/freerouting/designforms/specctra/RulesFile.java @@ -94,7 +94,6 @@ public class RulesFile if (!(curr_token instanceof String) || !((String) curr_token).equals(p_design_name)) { FRLogger.warn("RulesFile.read: design_name not matching"); - return false; } } catch (java.io.IOException e) From 97c286513accf600a9451b2db0daab11cf509cfb Mon Sep 17 00:00:00 2001 From: Andras Fuchs Date: Thu, 13 Feb 2020 15:45:52 +0100 Subject: [PATCH 2/5] Added the "-dr" command line argument for design rules --- .../mihosoft/freerouting/gui/DesignFile.java | 11 +++++---- .../freerouting/gui/MainApplication.java | 24 +++++++++++++++---- .../freerouting/gui/StartupOptions.java | 5 ++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java index 51ce5aa..57c0672 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java @@ -270,21 +270,20 @@ public class DesignFile return true; } - public static boolean read_rules_file(String p_design_name, String p_parent_name, + public static boolean read_rules_file(String p_design_name, String p_parent_name, String rules_file_name, eu.mihosoft.freerouting.interactive.BoardHandling p_board_handling, boolean p_is_web_start, String p_confirm_message) { boolean result = true; - String rule_file_name = p_design_name + ".rules"; boolean dsn_file_generated_by_host = p_board_handling.get_routing_board().communication.specctra_parser_info.dsn_file_generated_by_host; { try { - java.io.File rules_file = new java.io.File(p_parent_name, rule_file_name); - FRLogger.info("Opening '"+rule_file_name+"'..."); + java.io.File rules_file = p_parent_name == null ? new java.io.File(rules_file_name) : new java.io.File(p_parent_name, rules_file_name); + FRLogger.info("Opening '"+rules_file_name+"'..."); java.io.InputStream input_stream = new java.io.FileInputStream(rules_file); - if (input_stream != null && dsn_file_generated_by_host && WindowMessage.confirm(p_confirm_message)) + if (input_stream != null && dsn_file_generated_by_host && (WindowMessage.confirm(p_confirm_message) || (p_confirm_message == null))) { result = RulesFile.read(input_stream, p_design_name, p_board_handling); } @@ -301,10 +300,12 @@ public class DesignFile rules_file.delete(); } catch (java.io.IOException e) { + FRLogger.error(e.getLocalizedMessage(), e); result = false; } } catch (java.io.FileNotFoundException e) { + FRLogger.error("File '"+rules_file_name+"' was not found.", e); result = false; } } diff --git a/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java b/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java index 804073c..ec284d3 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/MainApplication.java @@ -93,7 +93,8 @@ public class MainApplication extends javax.swing.JFrame final BoardFrame new_frame = create_board_frame(design_file, null, board_option, startupOptions.test_version_option, - startupOptions.current_locale); + startupOptions.current_locale, + startupOptions.design_rules_filename); welcome_window.dispose(); if (new_frame == null) { @@ -300,7 +301,7 @@ public class MainApplication extends javax.swing.JFrame WindowMessage welcome_window = WindowMessage.show(message); welcome_window.setTitle(message); BoardFrame new_frame = - create_board_frame(design_file, message_field, option, this.is_test_version, this.locale); + create_board_frame(design_file, message_field, option, this.is_test_version, this.locale, null); welcome_window.dispose(); if (new_frame == null) { @@ -329,7 +330,7 @@ public class MainApplication extends javax.swing.JFrame * Returns null, if an error occurred. */ static private BoardFrame create_board_frame(DesignFile p_design_file, javax.swing.JTextField p_message_field, - BoardFrame.Option p_option, boolean p_is_test_version, java.util.Locale p_locale) + BoardFrame.Option p_option, boolean p_is_test_version, java.util.Locale p_locale, String p_design_rules_file) { java.util.ResourceBundle resources = java.util.ResourceBundle.getBundle("eu.mihosoft.freerouting.gui.MainApplication", p_locale); @@ -366,8 +367,21 @@ public class MainApplication extends javax.swing.JFrame String file_name = p_design_file.get_name(); String[] name_parts = file_name.split("\\."); - String confirm_import_rules_message = resources.getString("confirm_import_rules"); - DesignFile.read_rules_file(name_parts[0], p_design_file.get_parent(), + + String design_name = name_parts[0]; + + String parent_folder_name = null; + String rules_file_name = null; + String confirm_import_rules_message = null; + if (p_design_rules_file == null) { + parent_folder_name = p_design_file.get_parent(); + rules_file_name = design_name + ".rules"; + confirm_import_rules_message = resources.getString("confirm_import_rules"); + } else { + rules_file_name = p_design_rules_file; + } + + DesignFile.read_rules_file(design_name, parent_folder_name, rules_file_name, new_frame.board_panel.board_handling, p_option == BoardFrame.Option.WEBSTART, confirm_import_rules_message); new_frame.refresh_windows(); diff --git a/src/main/java/eu/mihosoft/freerouting/gui/StartupOptions.java b/src/main/java/eu/mihosoft/freerouting/gui/StartupOptions.java index c3b00cf..aa19d78 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/StartupOptions.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/StartupOptions.java @@ -15,6 +15,7 @@ public class StartupOptions { boolean webstart_option = false; String design_input_filename = null; String design_output_filename = null; + String design_rules_filename = null; String design_input_directory_name = null; int max_passes = 99999; java.util.Locale current_locale = java.util.Locale.ENGLISH; @@ -50,6 +51,10 @@ public class StartupOptions { if (p_args.length > i + 1 && !p_args[i + 1].startsWith("-")) { design_output_filename = p_args[i + 1]; } + } else if (p_args[i].startsWith("-dr")) { + if (p_args.length > i + 1 && !p_args[i + 1].startsWith("-")) { + design_rules_filename = p_args[i + 1]; + } } else if (p_args[i].startsWith("-mp")) { if (p_args.length > i + 1 && !p_args[i + 1].startsWith("-")) { max_passes = Integer.decode(p_args[i + 1]); From dc3ca3c7a89226fbcc0979d38e79e47884824f10 Mon Sep 17 00:00:00 2001 From: Andras Fuchs Date: Thu, 13 Feb 2020 15:46:31 +0100 Subject: [PATCH 3/5] Removed the annoying .rules deletion --- .../java/eu/mihosoft/freerouting/gui/DesignFile.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java index 57c0672..e7ab71c 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java @@ -291,18 +291,6 @@ public class DesignFile { result = false; } - try - { - if (input_stream != null) - { - input_stream.close(); - } - rules_file.delete(); - } catch (java.io.IOException e) - { - FRLogger.error(e.getLocalizedMessage(), e); - result = false; - } } catch (java.io.FileNotFoundException e) { FRLogger.error("File '"+rules_file_name+"' was not found.", e); From 2c94b281dc6617cee917be112c88af4e8ed844a1 Mon Sep 17 00:00:00 2001 From: Andras Fuchs Date: Thu, 13 Feb 2020 15:51:43 +0100 Subject: [PATCH 4/5] Removed the exception detals from the .rules file not found case --- src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java index e7ab71c..6a8489a 100644 --- a/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java +++ b/src/main/java/eu/mihosoft/freerouting/gui/DesignFile.java @@ -293,7 +293,7 @@ public class DesignFile } } catch (java.io.FileNotFoundException e) { - FRLogger.error("File '"+rules_file_name+"' was not found.", e); + FRLogger.error("File '"+rules_file_name+"' was not found.", null); result = false; } } From 8194da23b912f8e44894c3ca93d641909b438d00 Mon Sep 17 00:00:00 2001 From: Andras Fuchs Date: Thu, 13 Feb 2020 19:44:52 +0100 Subject: [PATCH 5/5] Added the -dr argument information to the README --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 928bc88..dd4e5bc 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ The following command line arguments are supported by freerouter: * -de [design input file]: loads up a Specctra .dsn file at startup * -di [design input directory]: if the GUI is used, this sets the default folder for the open design dialogs +* -dr [design rules file]: reads the rules from a previously saved .rules file * -do [design output file]: saves a Specctra board (.dsn), a Specctra session file (.ses) or Eagle session script file (.scr) when the routing is finished * -mp [number of passes]: sets the upper limit of the number of passes that will be performed * -l [language]: "de" for German, otherwise it's English @@ -138,7 +139,7 @@ The following command line arguments are supported by freerouter: A complete command line looks something like this if your are using PowerShell on Windows: ` -& "c:\Program Files\Java\jdk-11.0.6\bin\java.exe" -jar freerouting-executable.jar -de MyBoard.dsn -do MyBoard.ses -mp 100 +& "c:\Program Files\Java\jdk-11.0.6\bin\java.exe" -jar freerouting-executable.jar -de MyBoard.dsn -do MyBoard.ses -mp 100 -dr MyBoard.rules ` -This would read the _MyBoard.dsn_ file, do the auto-routing for the maximum of 100 passes, and then save the result into the _MyBoard.ses_ file. \ No newline at end of file +This would read the _MyBoard.dsn_ file, do the auto-routing with the parameters defined in _MyBoard.rules_ for the maximum of 100 passes, and then save the result into the _MyBoard.ses_ file. \ No newline at end of file