Merge pull request #10 from andrasfuchs/rules-file-handling

Rules file handling
This commit is contained in:
Michael Hoffer 2020-02-29 20:08:25 +01:00 committed by GitHub
commit 492c37848b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 24 deletions

View File

@ -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.
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.

View File

@ -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)

View File

@ -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);
}
@ -292,19 +291,9 @@ public class DesignFile
{
result = false;
}
try
{
if (input_stream != null)
{
input_stream.close();
}
rules_file.delete();
} catch (java.io.IOException e)
{
result = false;
}
} catch (java.io.FileNotFoundException e)
{
FRLogger.error("File '"+rules_file_name+"' was not found.", null);
result = false;
}
}

View File

@ -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();

View File

@ -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]);