From a7ef06333a8a165ac4af009eef40e51d76f38021 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Mon, 25 Apr 2016 11:20:07 +1200 Subject: [PATCH 01/16] Started working on adding the ability for NinjaCalc to save state between application sessions (#115). --- .idea/workspace.xml | 380 +++++++++++------- src/Core/CalcVar/CalcVarBase.java | 2 +- src/Core/CalcVar/CalcVarComboBox.java | 2 +- src/Core/CalcVar/CalcVarNumerical.java | 4 +- src/Core/Calculator.java | 12 +- src/Main.java | 116 +++++- src/MainWindow/MainWindowController.java | 121 ++++-- .../MetricPrefixes/MetricPrefixes.java | 19 +- src/Utility/Rounding.java | 10 +- src/Utility/StandardResistanceFinder.java | 4 +- 10 files changed, 449 insertions(+), 221 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index dcb248fe..db626bd2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,7 +7,15 @@ - + + + + + + + + + @@ -67,100 +75,94 @@ - - + + - - + + - - + + - - - + + + + + + - - - - - - - - - + + + + + + - - - - - + + - - + + - - + + - - + + - - - - - - - - - + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -169,8 +171,8 @@ - - + + @@ -206,9 +208,6 @@ @@ -358,6 +360,64 @@ - + @@ -903,8 +963,8 @@ - - + + @@ -940,7 +1000,7 @@ - + @@ -950,7 +1010,7 @@ - + @@ -996,8 +1056,14 @@ - @@ -1164,27 +1229,11 @@ - + - - - - - - - - - - - - - - - - @@ -1207,14 +1256,6 @@ - - - - - - - - @@ -1277,14 +1318,6 @@ - - - - - - - - @@ -1336,14 +1369,6 @@ - - - - - - - - @@ -1352,22 +1377,6 @@ - - - - - - - - - - - - - - - - @@ -1395,22 +1404,6 @@ - - - - - - - - - - - - - - - - @@ -1427,35 +1420,118 @@ - + - - + + - - + + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Core/CalcVar/CalcVarBase.java b/src/Core/CalcVar/CalcVarBase.java index b45169dd..9cd9ad7c 100644 --- a/src/Core/CalcVar/CalcVarBase.java +++ b/src/Core/CalcVar/CalcVarBase.java @@ -185,7 +185,7 @@ public void forceDependantOutputsToRecalculate() { * calculator variable changes. */ protected void forceVariablesWithDependantValidatorsToRevalidate() { - System.out.println("CalcVarBase.forceVariablesWithDependantValidatorsToRevalidate() called for " + this.name + "."); + //System.out.println("CalcVarBase.forceVariablesWithDependantValidatorsToRevalidate() called for " + this.name + "."); for(CalcVarBase calcVar : this.varsWithDependantValidators) { calcVar.validate(); diff --git a/src/Core/CalcVar/CalcVarComboBox.java b/src/Core/CalcVar/CalcVarComboBox.java index 7407cb18..f00b3e77 100644 --- a/src/Core/CalcVar/CalcVarComboBox.java +++ b/src/Core/CalcVar/CalcVarComboBox.java @@ -173,7 +173,7 @@ private void comboBoxSelectionChanged() { //ComboBox units = (ComboBox)sender; this.setRawVal((String) this.comboBox.getSelectionModel().getSelectedItem()); - System.out.println("Selected unit is now \"" + this.getRawVal() + "\"."); + //System.out.println("Selected unit is now \"" + this.getRawVal() + "\"."); this.forceDependantOutputsToRecalculate(); } diff --git a/src/Core/CalcVar/CalcVarNumerical.java b/src/Core/CalcVar/CalcVarNumerical.java index 1e6fde14..48175d2a 100644 --- a/src/Core/CalcVar/CalcVarNumerical.java +++ b/src/Core/CalcVar/CalcVarNumerical.java @@ -27,7 +27,7 @@ * * @author gbmhunter (www.mbedded.ninja) * @since 2015-11-02 - * @last-modified 2016-04-18 + * @last-modified 2016-04-25 */ public class CalcVarNumerical extends CalcVarBase { @@ -721,7 +721,7 @@ else if(this.getDirection() == CalcVarDirections.Output) { */ private void updateDispValFromRawVal() { - System.out.println("updateDispValFromRawVal() called for variable \"" + this.name + "\". this.rawVal = " + this.rawVal); + //System.out.println("updateDispValFromRawVal() called for variable \"" + this.name + "\". this.rawVal = " + this.rawVal); // Special treatment if raw value is NaN if(Double.isNaN(this.rawVal)) { diff --git a/src/Core/Calculator.java b/src/Core/Calculator.java index 62ee6fd4..0fc3840c 100644 --- a/src/Core/Calculator.java +++ b/src/Core/Calculator.java @@ -11,10 +11,10 @@ /** * Base calculator class. Designed to be inherited by actual calculator implementations, which then define their own variables. * - * @author gbmhunter (www.mbedded.ninja) - * @last-modified 2016-04-13 - * @since 2015-11-02 - */ + * @author gbmhunter (www.mbedded.ninja) + * @since 2015-11-02 + * @last-modified 2016-04-25 + */ public abstract class Calculator { /** @@ -170,7 +170,7 @@ protected void findDependenciesAndDependants() { protected void findAllValidatorDependants() { - System.out.println("Calculator.findAllValidatorDependants() called."); + //System.out.println("Calculator.findAllValidatorDependants() called."); // Iterate over every variable in this calculator for (CalcVarBase calcVar : this.calcVars) { @@ -180,7 +180,7 @@ protected void findAllValidatorDependants() { // Iterate through each calculator variable which is a dependency for this validator, // and signal that this validator is dependent on the calculator variable for (CalcVarBase calcVarDependency : validator.dependencies) { - System.out.println("Adding " + calcVar.name + " to " + calcVarDependency.name + "'s list of vars with dependant validators."); + //System.out.println("Adding " + calcVar.name + " to " + calcVarDependency.name + "'s list of vars with dependant validators."); calcVarDependency.varsWithDependantValidators.add(calcVar); } } diff --git a/src/Main.java b/src/Main.java index 8ecef90a..2c250c27 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,25 +1,56 @@ // SYSTEM IMPORTS +import Core.Calculator; import javafx.application.Application; +import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.SceneAntialiasing; +import javafx.scene.control.Alert; import javafx.stage.Stage; // USER IMPORTS import MainWindow.MainWindowController; +import javafx.stage.WindowEvent; + +import java.io.*; +import java.util.ArrayList; /** * Entry class for NinjaCalc application. * * @author gbmhunter (www.mbedded.ninja) * @since 2015-11-02 - * @last-modified 2016-04-19 + * @last-modified 2016-04-25 */ public class Main extends Application { + //===============================================================================================// + //========================================== CONSTANTS ==========================================// + //===============================================================================================// + + public static final String appStateFileName = "NinjaCalcState.data"; + + //===============================================================================================// + //============================================ FIELDS ===========================================// + //===============================================================================================// + + MainWindowController controller; + + //===============================================================================================// + //======================================== CONSTRUCTORS =========================================// + //===============================================================================================// + + //===============================================================================================// + //======================================= GENERAL METHODS =======================================// + //===============================================================================================// + + public static void main(String[] args) { + launch(args); + } + @Override public void start(Stage primaryStage) throws Exception{ @@ -30,7 +61,7 @@ public void start(Stage primaryStage) throws Exception{ root.getStylesheets().add("/Core/StyleSheets/default.css"); // Get a handle of the controller (backend) for the MainWindowView.fxml file - MainWindowController controller = loader.getController(); + controller = loader.getController(); //===============================================================================================// //======================================= REGISTER CALCULATORS ==================================// @@ -39,7 +70,7 @@ public void start(Stage primaryStage) throws Exception{ // Any of the following can be commented out to remove the calculator(s) from the app //======== SCIENTIFIC =========// - //controller.addCalculatorTemplate(new Calculators.Scientific.ScientificCalcModel()); + controller.addCalculatorTemplate(new Calculators.Scientific.ScientificCalcModel()); //===============================================================================================// //========================================== ELECTRONICS ========================================// @@ -81,15 +112,90 @@ public void start(Stage primaryStage) throws Exception{ primaryStage.setMaximized(true); + // Install event handler for when the app is closed + primaryStage.setOnCloseRequest((windowEvent) -> { + this.saveCalculatorState(); + } + ); + + // Load saved calculator state (if any) + loadCalculatorState(); + // Show the NinjaCalc app primaryStage.show(); } + private void saveCalculatorState() { - public static void main(String[] args) { - launch(args); + try { + // Write to disk with FileOutputStream + FileOutputStream f_out = new + FileOutputStream(appStateFileName); + + // Write object with ObjectOutputStream + ObjectOutputStream obj_out = new + ObjectOutputStream(f_out); + + // Write object out to disk + obj_out.writeObject(controller.getOpenCalculators()); + + obj_out.close(); + + f_out.close(); + } catch (FileNotFoundException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("FileNotFoundException"); + //alert.setHeaderText("Look, an Information Dialog"); + alert.setContentText("File was not found when trying to save the app state."); + + alert.showAndWait(); + } catch (IOException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("IOException"); + //alert.setHeaderText("Look, an Information Dialog"); + alert.setContentText("An IOException occurred while trying to save the app state."); + alert.showAndWait(); + } + } + + private void loadCalculatorState() { + + System.out.println("Main.loadCalculatorState() called."); + + try { + FileInputStream fileIS = new FileInputStream(appStateFileName); + + ObjectInputStream objectIS = new ObjectInputStream(fileIS); + + //Object obj = objectIS.readObject(); + + ArrayList calculators = (ArrayList)objectIS.readObject(); + + // Finally, call the controller, passing it the calculators we want + // to be open + controller.setOpenCalculators(calculators); + + } catch (FileNotFoundException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("ERROR"); + alert.setHeaderText("FileNotFoundException"); + alert.setContentText("File was not found when trying to read the app state."); + alert.showAndWait(); + } catch (IOException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("ERROR"); + alert.setHeaderText("IOException"); + alert.setContentText("An IOException occurred while trying to read the app state."); + alert.showAndWait(); + } catch (ClassNotFoundException e) { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle("ERROR"); + alert.setHeaderText("ClassNotFoundException"); + alert.setContentText("An ClassNotFoundException occurred while trying to read the app state."); + alert.showAndWait(); + } } diff --git a/src/MainWindow/MainWindowController.java b/src/MainWindow/MainWindowController.java index 5de93555..d8cf8871 100644 --- a/src/MainWindow/MainWindowController.java +++ b/src/MainWindow/MainWindowController.java @@ -28,9 +28,9 @@ public CalculatorAndGridElementPair(Calculator calculator, CalculatorGridElement /** * The controller for the main window. * - * @author gbmhunter + * @author gbmhunter (www.mbedded.ninja) + * @last-modified 2016-04-25 * @since 2015-11-02 - * @last-modified 2016-02-14 */ public class MainWindowController implements Initializable { @@ -57,16 +57,50 @@ public class MainWindowController implements Initializable { private ArrayList calculatorTemplates; + private ArrayList openCalculators; + //===============================================================================================// //======================================== CONSTRUCTORS =========================================// //===============================================================================================// public MainWindowController() { + this.calculatorTemplates = new ArrayList(); + this.openCalculators = new ArrayList<>(); } + //===============================================================================================// + //====================================== GETTERS/SETTERS ========================================// + //===============================================================================================// + + public ArrayList getOpenCalculators() { + return openCalculators; + } + + public void setOpenCalculators(ArrayList openCalculators) { + System.out.println("MainWindowController.setOpenCalculators() called."); + this.openCalculators = openCalculators; + + // We also need to update the grid display at this point + + // First, remove all current tabs, this will DELETE them!!! + this.tabPaneCalculatorInstances.getTabs().removeAll(); + + // Now add the given calculators to the tabs one-by-one + for(Calculator calculator : openCalculators) { + addCalculatorToNewTab(calculator); + } + + } + + + //===============================================================================================// + //======================================= GENERAL METHODS =======================================// + //===============================================================================================// + /** * Used to add listeners to the main window where needed (UI objects have been injected at this point). + * * @param location * @param resources */ @@ -76,7 +110,7 @@ public void initialize(java.net.URL location, java.util.ResourceBundle resources //System.out.println("Selected tab index = \"" + String.valueOf(this.tabPaneCalculatorInstances.getSelectionModel().getSelectedIndex()) + "\"."); // Check to see if there are any tabs left open - if(this.tabPaneCalculatorInstances.getSelectionModel().getSelectedIndex() == -1) { + if (this.tabPaneCalculatorInstances.getSelectionModel().getSelectedIndex() == -1) { // Last tab has been closed, hide the tab pane and // show the "Do you wish to open a calculator" pane this.noCalculatorIsOpenPane.setVisible(true); @@ -91,7 +125,7 @@ public void initialize(java.net.URL location, java.util.ResourceBundle resources }); this.searchTextField.textProperty().addListener((observable, oldValue, newValue) -> { - System.out.println("searchTextField.textProperty listener called with newValue = " + newValue + "."); + //System.out.println("searchTextField.textProperty listener called with newValue = " + newValue + "."); this.filterCalculatorSelectionGrid(newValue); }); @@ -102,24 +136,24 @@ public void initialize(java.net.URL location, java.util.ResourceBundle resources /*** * Filters the calculator templates visible in the selection grid by the provided search text * (which comes the the search TextField). + * * @param searchText */ public void filterCalculatorSelectionGrid(String searchText) { // Iterate over all the registered calculator templates - for(CalculatorAndGridElementPair calculatorAndGridElementPair : this.calculatorTemplates) { - + for (CalculatorAndGridElementPair calculatorAndGridElementPair : this.calculatorTemplates) { - if(this.doesCalculatorMatchSearchText(calculatorAndGridElementPair.calculator, searchText)) { - System.out.println("Calculator \"" + calculatorAndGridElementPair.calculator.name + "\" included by search text."); + if (this.doesCalculatorMatchSearchText(calculatorAndGridElementPair.calculator, searchText)) { + //System.out.println("Calculator \"" + calculatorAndGridElementPair.calculator.name + "\" included by search text."); - if(!calculatorGridTilePane.getChildren().contains(calculatorAndGridElementPair.gridElement)) + if (!calculatorGridTilePane.getChildren().contains(calculatorAndGridElementPair.gridElement)) calculatorGridTilePane.getChildren().add(calculatorAndGridElementPair.gridElement); } else { - System.out.println("Calculator \"" + calculatorAndGridElementPair.calculator.name + "\" excluded by search text."); - if(calculatorGridTilePane.getChildren().contains(calculatorAndGridElementPair.gridElement)) + //System.out.println("Calculator \"" + calculatorAndGridElementPair.calculator.name + "\" excluded by search text."); + if (calculatorGridTilePane.getChildren().contains(calculatorAndGridElementPair.gridElement)) calculatorGridTilePane.getChildren().remove(calculatorAndGridElementPair.gridElement); } } @@ -128,9 +162,10 @@ public void filterCalculatorSelectionGrid(String searchText) { /** * Searches through the relevant String fields of the provided calculator to see if the calculator is a suitable * match for the provided search text. - * @param calculator The calculator that will be searched through. - * @param searchText The search text to use on the calculator. - * @return True if the calculator is a suitable match for the search text, otherwise false. + * + * @param calculator The calculator that will be searched through. + * @param searchText The search text to use on the calculator. + * @return True if the calculator is a suitable match for the search text, otherwise false. */ public boolean doesCalculatorMatchSearchText(Calculator calculator, String searchText) { @@ -138,16 +173,16 @@ public boolean doesCalculatorMatchSearchText(Calculator calculator, String searc return true;*/ // Search name - if(Pattern.compile(Pattern.quote(searchText), Pattern.CASE_INSENSITIVE).matcher(calculator.name).find()) + if (Pattern.compile(Pattern.quote(searchText), Pattern.CASE_INSENSITIVE).matcher(calculator.name).find()) return true; // Search description - if(Pattern.compile(Pattern.quote(searchText), Pattern.CASE_INSENSITIVE).matcher(calculator.description).find()) + if (Pattern.compile(Pattern.quote(searchText), Pattern.CASE_INSENSITIVE).matcher(calculator.description).find()) return true; // Search through tags - for(String tag : calculator.tags) { - if(Pattern.compile(Pattern.quote(searchText), Pattern.CASE_INSENSITIVE).matcher(tag).find()) + for (String tag : calculator.tags) { + if (Pattern.compile(Pattern.quote(searchText), Pattern.CASE_INSENSITIVE).matcher(tag).find()) return true; } @@ -185,7 +220,8 @@ public void handleCalcSelectionMouseClicked(MouseEvent event) { /*** * Adds a calculator to the list of calculator templates the user can select from in the calculator selection grid. * This must be called once for each calculator that is to be shown to the user when the app starts up. - * @param calculator The calculator you wish to add to the apps list of calculator templates. + * + * @param calculator The calculator you wish to add to the apps list of calculator templates. */ public void addCalculatorTemplate(Calculator calculator) { //System.out.println("addCalculatorTemplate() called."); @@ -215,16 +251,16 @@ public void openCalculatorButtonPressed(String calculatorName) { Calculator foundCalculator = null; // Search for calculator in list of calculator templates - for(CalculatorAndGridElementPair calculatorAndGridElementPair : this.calculatorTemplates) { - if(calculatorAndGridElementPair.calculator.name == calculatorName) { + for (CalculatorAndGridElementPair calculatorAndGridElementPair : this.calculatorTemplates) { + if (calculatorAndGridElementPair.calculator.name == calculatorName) { foundCalculator = calculatorAndGridElementPair.calculator; } } - if(foundCalculator == null) + if (foundCalculator == null) throw new IllegalArgumentException("The provided calculator name \"" + calculatorName + "\" was not found in the list of calculator templates."); - System.out.println("Opening new calculator instance..."); + //System.out.println("Opening new calculator instance..."); // Make calculator tabs visible //this.gridPaneCalculatorTabsContainer.setVisible(true); @@ -235,27 +271,36 @@ public void openCalculatorButtonPressed(String calculatorName) { // Hide the "No calculator is open" pane //this.noCalculatorIsOpenPane.setVisible(false); - // Add new tab to tab pane - Tab newTab = new Tab(); - newTab.setText(foundCalculator.name); - - try { - // Create a new instance of this calculator Calculator newInstance = foundCalculator.getClass().newInstance(); - newTab.setContent(newInstance.view); - this.tabPaneCalculatorInstances.getTabs().add(newTab); - // Set this newly created tab to be the active one - // NOTE: If this is the first tab to be created, this also causes a listener to be called which shows the tab - // pane and hides the "Do wish to open a new calculator?" pane - this.tabPaneCalculatorInstances.getSelectionModel().selectLast(); - } catch (InstantiationException x) { + addCalculatorToNewTab(newInstance); + } catch (InstantiationException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } - } + public void addCalculatorToNewTab(Calculator calculator) { -} + // Add new tab to tab pane + Tab newTab = new Tab(); + newTab.setText(calculator.name); + + // Create a new instance of this calculator + + newTab.setContent(calculator.view); + this.tabPaneCalculatorInstances.getTabs().add(newTab); + + // Lets keep a record of all the calculators which are open + // (note that this is independent of the tabs, and we have to make sure to + // remove the record when the tab is closed) + this.openCalculators.add(calculator); + + // Set this newly created tab to be the active one + // NOTE: If this is the first tab to be created, this also causes a listener to be called which shows the tab + // pane and hides the "Do wish to open a new calculator?" pane + this.tabPaneCalculatorInstances.getSelectionModel().selectLast(); + + } +} \ No newline at end of file diff --git a/src/Utility/MetricPrefixes/MetricPrefixes.java b/src/Utility/MetricPrefixes/MetricPrefixes.java index b739634a..21cad64e 100644 --- a/src/Utility/MetricPrefixes/MetricPrefixes.java +++ b/src/Utility/MetricPrefixes/MetricPrefixes.java @@ -57,7 +57,7 @@ public double getMultiplier() { private static final Pattern REGEX; static { - System.out.println("MetricPrefixes::static() called."); + //System.out.println("MetricPrefixes::static() called."); final StringBuffer buffer = new StringBuffer(); buffer.append("^([+-]?[1-9]\\d*\\.?\\d*|[+-]?0?\\.\\d+)(?:(["); @@ -76,11 +76,11 @@ public double getMultiplier() { */ public static Double toDouble(final String value) { - System.out.println("MetricPrefixes::toDouble() called with value = " + value); + //System.out.println("MetricPrefixes::toDouble() called with value = " + value); final Matcher m = REGEX.matcher(value); if (!m.matches()) { - System.out.println("MetricPrefixes::toDouble() is going to return null!"); + //System.out.println("MetricPrefixes::toDouble() is going to return null!"); return null; } @@ -90,7 +90,7 @@ public static Double toDouble(final String value) { if (m.group(2) == null) return result; // Units - System.out.println("Finding character..."); + //System.out.println("Finding character..."); try { // Retrieve the metric prefix character @@ -100,16 +100,17 @@ public static Double toDouble(final String value) { if (e.getSymbol() == c) { // Found valid prefix!!! Double returnValue = result * e.getMultiplier(); - System.out.println("Returning the number " + returnValue); + //System.out.println("Returning the number " + returnValue); return returnValue; } } } catch (StringIndexOutOfBoundsException e) { - System.out.println("StringIndexOutOfBoundsException occurred! Assuming no metric prefix was present, and returning result..."); + // This exception happens during normal execution! + //System.out.println("StringIndexOutOfBoundsException occurred! Assuming no metric prefix was present, and returning result..."); return result; } - System.out.println("MetricPrefixes::toDouble() is going to return null!"); + //System.out.println("MetricPrefixes::toDouble() is going to return null!"); return null; } @@ -153,7 +154,7 @@ public static String toEng( final double value, final MetricPrefixes notation ) { - System.out.println("toEng() called with value = " + value + ", notation = " + notation.toString()); + //System.out.println("toEng() called with value = " + value + ", notation = " + notation.toString()); if (notation == null || notation == unit) return doubleToString(value); @@ -176,7 +177,7 @@ public static String toEng( final RoundingMethods roundingMethod, final Integer roundTo ) { - System.out.println("toEng() called with value = " + value + ", notation = " + notation.toString() + ", roundingMethod = " + roundingMethod.toString() + ", roundTo = " + roundTo); + //System.out.println("toEng() called with value = " + value + ", notation = " + notation.toString() + ", roundingMethod = " + roundingMethod.toString() + ", roundTo = " + roundTo); /*if (notation == null || notation == unit) return doubleToString(value);*/ diff --git a/src/Utility/Rounding.java b/src/Utility/Rounding.java index f0c20ea4..9c30c3a6 100644 --- a/src/Utility/Rounding.java +++ b/src/Utility/Rounding.java @@ -6,9 +6,9 @@ /** * Static class to help with the rounding of calculator variables, especially * with significant figure-based rounding. - * @author gbmhunter - * @since 2015-11-02 - * @last-modified 2016-03-26 + * @author gbmhunter + * @since 2015-11-02 + * @last-modified 2016-04-25 */ public class Rounding { @@ -35,12 +35,12 @@ public static double RoundToSignificantDigits(double numberToRound, int digits) public static BigDecimal ToSignificantDigits(BigDecimal value, int digits) { - System.out.println("ToSignificantDigits(), BigDecimal overload called."); + //System.out.println("ToSignificantDigits(), BigDecimal overload called."); int newScale = digits - value.precision()+value.scale(); BigDecimal bd2 = value.setScale(newScale, RoundingMode.HALF_UP); - System.out.println("Rounded number = " + bd2); + //System.out.println("Rounded number = " + bd2); return bd2; } diff --git a/src/Utility/StandardResistanceFinder.java b/src/Utility/StandardResistanceFinder.java index 0dec348b..793d53d3 100644 --- a/src/Utility/StandardResistanceFinder.java +++ b/src/Utility/StandardResistanceFinder.java @@ -40,7 +40,7 @@ public enum eSeriesOptions { */ static { - System.out.println("Building resistor E-series arrays."); + //System.out.println("Building resistor E-series arrays."); e24 = new ArrayList(Arrays.asList(100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300, 330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, 910, 1000)); @@ -98,7 +98,7 @@ public enum eSeriesOptions { */ public static double Find(double desiredResistance, eSeriesOptions eSeries) { - System.out.println("StandardResistanceFinder::Find() called with desiredResistance = " + desiredResistance + "and eSeries = " + eSeries.toString()); + //System.out.println("StandardResistanceFinder::Find() called with desiredResistance = " + desiredResistance + "and eSeries = " + eSeries.toString()); // Check for special case where desired resistance is 0. Strictly speaking, this does not belong // in any E-series, but 0R links are common place so we will return 0.0 anyway. From a0727b42ecb2c5660f675e524231f9575f652981 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Mon, 25 Apr 2016 11:49:49 +1200 Subject: [PATCH 02/16] Tidied up save/load app state code (#115). --- .idea/workspace.xml | 26 ++++++++++++-------------- src/Main.java | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index db626bd2..04333826 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,15 +7,7 @@ - - - - - - - - @@ -78,8 +70,8 @@ - - + + @@ -1058,12 +1050,18 @@ file://$PROJECT_DIR$/src/Main.java - 164 + 165 + + file://$PROJECT_DIR$/src/Main.java + 135 + + - - - + + diff --git a/src/Main.java b/src/Main.java index 2c250c27..56915ef1 100644 --- a/src/Main.java +++ b/src/Main.java @@ -112,14 +112,16 @@ public void start(Stage primaryStage) throws Exception{ primaryStage.setMaximized(true); + //====== SAVING/LOADING APP STATE =====// + // Install event handler for when the app is closed primaryStage.setOnCloseRequest((windowEvent) -> { - this.saveCalculatorState(); + //this.saveCalculatorState(); } ); // Load saved calculator state (if any) - loadCalculatorState(); + //loadCalculatorState(); // Show the NinjaCalc app primaryStage.show(); @@ -131,19 +133,18 @@ private void saveCalculatorState() { try { // Write to disk with FileOutputStream - FileOutputStream f_out = new + FileOutputStream fileOS = new FileOutputStream(appStateFileName); // Write object with ObjectOutputStream - ObjectOutputStream obj_out = new - ObjectOutputStream(f_out); + ObjectOutputStream objOS = new + ObjectOutputStream(fileOS); // Write object out to disk - obj_out.writeObject(controller.getOpenCalculators()); - - obj_out.close(); + objOS.writeObject(controller.getOpenCalculators()); - f_out.close(); + objOS.close(); + fileOS.close(); } catch (FileNotFoundException e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("FileNotFoundException"); From 090af9f55742c83218ec1c116520a3f2c701fa45 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Wed, 27 Apr 2016 20:38:12 +1200 Subject: [PATCH 03/16] Disabled metric prefixes for IPC-2152 calculator variables, closes #118. --- .idea/workspace.xml | 610 +++++++++++------- changelog.md | 5 + .../Basic/OhmsLaw/OhmsLawCalcModel.java | 83 +-- .../TrackCurrentIpc2152CalcModel.java | 331 +--------- src/Core/CalcVar/CalcVarBase.java | 3 +- src/Core/CalcVar/CalcVarNumerical.java | 11 +- src/Core/Calculator.java | 3 +- 7 files changed, 398 insertions(+), 648 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 04333826..228df82c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,7 +7,13 @@ - + + + + + + + @@ -67,94 +73,184 @@ - + - - + + - - + + - - - - - - + + + - - + + - - - + + + + + + - - - - - - + + + + + + + + + - - + + - - - + + + + + - - + + - - - + + + + + + + + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + @@ -163,8 +259,8 @@ - - + + @@ -230,9 +326,7 @@ @@ -298,10 +394,6 @@ - - - - @@ -348,7 +440,7 @@ @@ -366,7 +458,11 @@ + + + + @@ -981,7 +1057,7 @@ - + @@ -997,7 +1073,6 @@ - @@ -1014,6 +1089,7 @@ + @@ -1050,18 +1126,18 @@ file://$PROJECT_DIR$/src/Main.java - 165 + 155 - - file://$PROJECT_DIR$/src/Main.java - 135 + file://$PROJECT_DIR$/src/Core/CalcVar/CalcVarNumerical.java + 753 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1116,12 +1164,6 @@ - - - - - - @@ -1132,7 +1174,6 @@ - @@ -1140,7 +1181,6 @@ - @@ -1148,18 +1188,10 @@ - - - - - - - - - + @@ -1171,19 +1203,11 @@ - - - - - - - - + - @@ -1202,7 +1226,6 @@ - @@ -1210,7 +1233,6 @@ - @@ -1218,7 +1240,6 @@ - @@ -1239,7 +1260,6 @@ - @@ -1250,7 +1270,6 @@ - @@ -1261,7 +1280,6 @@ - @@ -1272,7 +1290,6 @@ - @@ -1324,14 +1341,6 @@ - - - - - - - - @@ -1340,38 +1349,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - @@ -1379,7 +1362,6 @@ - @@ -1387,7 +1369,6 @@ - @@ -1398,7 +1379,6 @@ - @@ -1423,7 +1403,6 @@ - @@ -1431,106 +1410,243 @@ + + + + + + + - - - - - - - - + + + + + - - - + + + + + - + - - - + + - + - - + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - - + + + + + - + - - + + - + - - + + - + - - + + - + - - + + - - + + - - - - - + + + + + + + + + + + + + diff --git a/changelog.md b/changelog.md index bd3b541c..f5c3c531 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +vX.X.X +------ + +- Disabled metric prefixes for IPC-2152 calculator variables, closes #118. + v1.2.0 ------ diff --git a/src/Calculators/Electronics/Basic/OhmsLaw/OhmsLawCalcModel.java b/src/Calculators/Electronics/Basic/OhmsLaw/OhmsLawCalcModel.java index b682e7e4..e2fd08ff 100644 --- a/src/Calculators/Electronics/Basic/OhmsLaw/OhmsLawCalcModel.java +++ b/src/Calculators/Electronics/Basic/OhmsLaw/OhmsLawCalcModel.java @@ -5,6 +5,7 @@ import Core.CalcVar.CalcVarDirections; import Core.CalcVar.CalcVarNumerical; +import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -17,6 +18,7 @@ import javafx.scene.web.WebView; import java.io.IOException; +import java.io.Serializable; import java.net.URL; /** @@ -117,38 +119,14 @@ public OhmsLawCalcModel() { } ); + //===============================================================================================// //========================================= VOLTAGE (i/o) =======================================// //===============================================================================================// - /*this.voltage = new CalcVarNumerical( - "voltage", - voltageValueTextField, - null, - () -> { - Double current = this.current.getRawVal(); - Double resistance = this.resistance.getRawVal(); - return current * resistance; - }, - new NumberUnitMultiplier[]{ - //new NumberUnitMultiplier("mV", 1e-3), - new NumberUnitMultiplier("V", 1e0, NumberPreference.DEFAULT), - //new NumberUnitMultiplier("kV", 1e3), - }, - 4, - () -> { - if (voltageRadioButton.isSelected()) - return CalcVarDirections.Output; - else return CalcVarDirections.Input; - }, - null, - "The voltage across the resistor." // Help text - ); - this.voltage.setIsEngineeringNotationEnabled(true);*/ - this.voltage.setName("voltage"); this.voltage.setValueTextField(this.voltageValueTextField); - this.voltage.setEquationFunction(() -> { + this.voltage.setEquationFunction((IEquationFunction & Serializable)() -> { // Read dependency variables Double current = this.current.getRawVal(); Double resistance = this.resistance.getRawVal(); @@ -176,32 +154,6 @@ public OhmsLawCalcModel() { //============================================ CURRENT ==========================================// //===============================================================================================// - - /*this.current = new CalcVarNumerical( - "current", - currentValueTextField, - null, - () -> { - Double voltage = this.voltage.getRawVal(); - Double resistance = this.resistance.getRawVal(); - return voltage / resistance; - }, - new NumberUnitMultiplier[]{ - //new NumberUnitMultiplier("pA", 1e-12), - //new NumberUnitMultiplier("nA", 1e-9), - //new NumberUnitMultiplier("uA", 1e-6), - //new NumberUnitMultiplier("mA", 1e-3), - new NumberUnitMultiplier("A", 1e0, NumberPreference.DEFAULT), - }, - 4, - () -> { - if (currentRadioButton.isSelected()) return CalcVarDirections.Output; - else return CalcVarDirections.Input; - }, - null, - "The current going through the resistor" // Help text - );*/ - this.current.setName("current"); this.current.setValueTextField(this.currentValueTextField); this.current.setEquationFunction(() -> { @@ -228,36 +180,11 @@ public OhmsLawCalcModel() { this.calcVars.add(this.current); + //===============================================================================================// //========================================== RESISTANCE =========================================// //===============================================================================================// - - /*this.resistance = new CalcVarNumerical( - "resistance", - resistanceValueTextField, - null, - () -> { - Double voltage = this.voltage.getRawVal(); - Double current = this.current.getRawVal(); - return voltage / current; - }, - new NumberUnitMultiplier[]{ - //new NumberUnitMultiplier("mΩ", 1e-3), - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - //new NumberUnitMultiplier("kΩ", 1e3), - //new NumberUnitMultiplier("MΩ", 1e6), - //new NumberUnitMultiplier("GΩ", 1e9), - }, - 4, - () -> { - if (resistanceRadioButton.isSelected()) return CalcVarDirections.Output; - else return CalcVarDirections.Input; - }, - null, - "The resistance of the resistor (or other circuit component)." // Help text - );*/ - this.resistance.setName("resistance"); this.resistance.setValueTextField(this.resistanceValueTextField); this.resistance.setEquationFunction(() -> { diff --git a/src/Calculators/Electronics/Pcb/TrackCurrentIpc2152/TrackCurrentIpc2152CalcModel.java b/src/Calculators/Electronics/Pcb/TrackCurrentIpc2152/TrackCurrentIpc2152CalcModel.java index 9185208f..bbadbdf9 100644 --- a/src/Calculators/Electronics/Pcb/TrackCurrentIpc2152/TrackCurrentIpc2152CalcModel.java +++ b/src/Calculators/Electronics/Pcb/TrackCurrentIpc2152/TrackCurrentIpc2152CalcModel.java @@ -267,20 +267,6 @@ public TrackCurrentIpc2152CalcModel() { //===================================== TRACE CURRENT (input) ===================================// //===============================================================================================// - /*this.trackCurrent = new CalcVarNumericalInput( - "traceCurrent", // Debug name - trackCurrentValue, // Textbox for value (UI object) - trackCurrentUnits, // Combobox for units (UI object) - new NumberUnitMultiplier[]{ // units - new NumberUnitMultiplier("uA", 1e-6), - new NumberUnitMultiplier("mA", 1e-3), - new NumberUnitMultiplier("A", 1e0, NumberPreference.DEFAULT), - }, - 4, // Num. digits to round to - null, // Default value - "The current you want the PCB track to be able to handle." // Help info - );*/ - this.trackCurrent.setName("trackCurrent"); this.trackCurrent.setValueTextField(this.trackCurrentValue); this.trackCurrent.setUnitsComboBox(this.trackCurrentUnits); @@ -291,7 +277,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.trackCurrent.setNumDigitsToRound(4); this.trackCurrent.setHelpText("The current you want the PCB track to be able to handle."); - this.trackCurrent.setIsEngineeringNotationEnabled(true); + this.trackCurrent.setIsEngineeringNotationEnabled(false); //====================== VALIDATORS ===================// this.trackCurrent.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -315,18 +301,6 @@ public TrackCurrentIpc2152CalcModel() { //====================================== TEMP RISE (input) ======================================// //===============================================================================================// - /*this.tempRise = new CalcVarNumericalInput( - "tempRise", // Debug name - tempRiseValue, // Textbox for value (UI object) - tempRiseUnits, // Combobox for units (UI object) - new NumberUnitMultiplier[]{ // units - new NumberUnitMultiplier("°c", 1e0, NumberPreference.DEFAULT), - }, - 4, // Num. digits to round to - null, // Default value - "The maximum desired temperature rise due to the current flowing through the track. 20-40°c is a common value for this." // Help info - );*/ - this.tempRise.setName("tempRise"); this.tempRise.setValueTextField(this.tempRiseValue); this.tempRise.setUnitsComboBox(this.tempRiseUnits); @@ -335,7 +309,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.tempRise.setNumDigitsToRound(4); this.tempRise.setHelpText("The maximum desired temperature rise due to the current flowing through the track. 20-40°c is a common value for this."); - this.tempRise.setIsEngineeringNotationEnabled(true); + this.tempRise.setIsEngineeringNotationEnabled(false); //====================== VALIDATORS ===================// this.tempRise.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -359,37 +333,6 @@ public TrackCurrentIpc2152CalcModel() { //============================ UN-ADJUSTED TRACK CROSS-SECTIONAL AREA (output) ==================// //===============================================================================================// - /*this.unadjustedTrackCrossSectionalArea = new CalcVarNumericalOutput( - "unadjustedTrackCrossSectionalArea", - unadjustedTrackCrossSectionalAreaValue, - unadjustedTrackCrossSectionalAreaUnits, - () -> { - - // Read in variables - Double trackCurrent = this.trackCurrent.getRawVal(); - Double tempRise = this.tempRise.getRawVal(); - - // Lets calculate the two co-efficients for the fixed-temp trend line - Double universalChartTrendLineCoefA = UNIVERSAL_CHART_TREND_LINE_COEF_AA * Math.pow(tempRise, UNIVERSAL_CHART_TREND_LINE_COEF_AB); - Double universalChartTrendLineCoefB = UNIVERSAL_CHART_TREND_LINE_COEF_BA * Math.pow(tempRise, UNIVERSAL_CHART_TREND_LINE_COEF_BB); - - // Now we know the two co-efficients, we can use the trend line eq. y=Ax^B to find the unadjusted cross-sectional area - Double unadjustedTrackCrosssectionalAreaMils2 = Math.pow(trackCurrent / universalChartTrendLineCoefA, 1 / universalChartTrendLineCoefB); - - //console.log("unadjustedTrackCrosssectionalAreaMils2 = '" + unadjustedTrackCrosssectionalAreaMils2 + "'."); - - // Convert mils^2 to m^2 (store variable values in SI units) - Double unadjustedTrackCrosssectionalAreaM2 = unadjustedTrackCrosssectionalAreaMils2 * (1 / (NUM_MILS_PER_MM * NUM_MILS_PER_MM * 1e6)); - - return unadjustedTrackCrosssectionalAreaM2; - - }, - new NumberUnitMultiplier[]{ - - }, - 4, - "The unadjusted cross-sectional area. This gets multiplied by the many modifiers to give an adjusted cross-sectional area.");*/ - this.unadjustedTrackCrossSectionalArea.setName("unadjustedTrackCrossSectionalArea"); this.unadjustedTrackCrossSectionalArea.setValueTextField(this.unadjustedTrackCrossSectionalAreaValue); this.unadjustedTrackCrossSectionalArea.setUnitsComboBox(this.unadjustedTrackCrossSectionalAreaUnits); @@ -419,7 +362,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.unadjustedTrackCrossSectionalArea.setNumDigitsToRound(4); this.unadjustedTrackCrossSectionalArea.setHelpText("The unadjusted cross-sectional area. This gets multiplied by the many modifiers to give an adjusted cross-sectional area."); - this.unadjustedTrackCrossSectionalArea.setIsEngineeringNotationEnabled(true); + this.unadjustedTrackCrossSectionalArea.setIsEngineeringNotationEnabled(false); //====================== VALIDATORS ===================// this.unadjustedTrackCrossSectionalArea.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -432,21 +375,6 @@ public TrackCurrentIpc2152CalcModel() { //================================== TRACK THICKNESS (input) ====================================// //===============================================================================================// - /*this.trackThickness = new CalcVarNumericalInput( - "trackThickness", - trackThicknessValue, - trackThicknessUnits, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("um", 1e-6, NumberPreference.DEFAULT), - new NumberUnitMultiplier("mm", 1e-3), - new NumberUnitMultiplier("oz", UnitConversionConstants.COPPER_THICKNESS_M_PER_OZ), - new NumberUnitMultiplier("mils", UnitConversionConstants.METERS_PER_MILS), - }, - 4, - null, - "The thickness (height) of the track. This is equal to the thickness of the copper layer the track is on. This is also called the copper weight. Common values are 16um (0.5oz) or 32um (1oz)." // Help text - );*/ - this.trackThickness.setName("trackThickness"); this.trackThickness.setValueTextField(this.trackThicknessValue); this.trackThickness.setUnitsComboBox(this.trackThicknessUnits); @@ -458,7 +386,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.trackThickness.setNumDigitsToRound(4); this.trackThickness.setHelpText("The thickness (height) of the track. This is equal to the thickness of the copper layer the track is on. This is also called the copper weight. Common values are 16um (0.5oz) or 32um (1oz)."); - this.trackThickness.setIsEngineeringNotationEnabled(true); + this.trackThickness.setIsEngineeringNotationEnabled(false); //====================== VALIDATORS ===================// this.trackThickness.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -482,64 +410,6 @@ public TrackCurrentIpc2152CalcModel() { //=================================== TRACK THICKNESS MODIFIER (output) =========================// //===============================================================================================// - /*this.trackThicknessModifier = new CalcVarNumericalOutput( - "trackThicknessModifier", - trackThicknessModifierValue, - trackThicknessModifierUnits, - () -> { - - // Read in variables - Double trackCurrentA = this.trackCurrent.getRawVal(); - Double trackThicknessM = this.trackThickness.getRawVal(); - - // Convert to "oz" units, as this is what is used in IPC-2152 graphs - Double trackThicknessOz = trackThicknessM*(1/UnitConversionConstants.COPPER_THICKNESS_M_PER_OZ); - //console.log("trackThicknessOz = " + trackThicknessOz); - - // Lets calculate the two co-efficients for the fixed-temp trend line - double[] trackThicknessTrendLineCoefA = new double[TRACK_THICKNESS_TREND_LINE_COEF_COEF_A.length]; - - //console.log("test = " + TRACK_THICKNESS_TREND_LINE_COEF_COEF_A[0].length); - - - // Outer loop calculates all co-efficients - for(Integer i = 0; i < TRACK_THICKNESS_TREND_LINE_COEF_COEF_A.length; i++) - { - // Initialise array element with 0 - trackThicknessTrendLineCoefA[i] = 0; - - //console.log("i = " + i); - //console.log("test = " + TRACK_THICKNESS_TREND_LINE_COEF_COEF_A[i].length); - - // Inner loop calculates a single co-efficient - for(Integer j = 0; j < TRACK_THICKNESS_TREND_LINE_COEF_COEF_A[0].length; j++) - { - //TRACK_THICKNESS_TREND_LINE_COEF_COEF_A[0,0] = 2; - //console.log("sum = " + TRACK_THICKNESS_TREND_LINE_COEF_COEF_A[0,0]); - trackThicknessTrendLineCoefA[i] += TRACK_THICKNESS_TREND_LINE_COEF_COEF_A[i][j]*Math.pow(trackThicknessOz, j); - } - - //console.log("trackThicknessTrendLineCoefA[" + i + "] = '" + trackThicknessTrendLineCoefA[i] + "'."); - } - - // Now we have calculate the 5th degree polynomial co-efficients, we can finally calc the thickness modifier - double trackThicknessModifierMulti = 0; - - for(Integer i = 0; i < trackThicknessTrendLineCoefA.length; i++) - { - trackThicknessModifierMulti += trackThicknessTrendLineCoefA[i]*Math.pow(trackCurrentA, i); - } - - return trackThicknessModifierMulti; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("no unit", 1.0, NumberPreference.DEFAULT), - }, - 4, - "The modifier to adjust the cross-sectional area with based on the track thickness." // Help text - );*/ - this.trackThicknessModifier.setName("trackThicknessModifier"); this.trackThicknessModifier.setValueTextField(this.trackThicknessModifierValue); this.trackThicknessModifier.setUnitsComboBox(this.trackThicknessModifierUnits); @@ -590,7 +460,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.trackThicknessModifier.setNumDigitsToRound(4); this.trackThicknessModifier.setHelpText("The modifier to adjust the cross-sectional area with based on the track thickness."); - this.trackThicknessModifier.setIsEngineeringNotationEnabled(true); + this.trackThicknessModifier.setIsEngineeringNotationEnabled(false); //====================== VALIDATORS ===================// this.trackThicknessModifier.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -602,20 +472,6 @@ public TrackCurrentIpc2152CalcModel() { //================================== BOARD THICKNESS (input) ====================================// //===============================================================================================// - /*this.boardThickness = new CalcVarNumericalInput( - "boardThickness", - boardThicknessValue, - boardThicknessUnits, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("um", 1e-6), - new NumberUnitMultiplier("mm", 1e-3, NumberPreference.DEFAULT), - new NumberUnitMultiplier("mils", UnitConversionConstants.METERS_PER_MILS), - }, - 4, - null, - "The total thickness of the PCB that the track is on. A standard PCB thickness is 1.6mm." // Help text - );*/ - this.boardThickness.setName("boardThickness"); this.boardThickness.setValueTextField(this.boardThicknessValue); this.boardThickness.setUnitsComboBox(this.boardThicknessUnits); @@ -626,7 +482,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.boardThickness.setNumDigitsToRound(4); this.boardThickness.setHelpText("The total thickness of the PCB that the track is on. A standard PCB thickness is 1.6mm."); - this.boardThickness.setIsEngineeringNotationEnabled(true); + this.boardThickness.setIsEngineeringNotationEnabled(false); //========== VALIDATORS ==========// this.boardThickness.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -650,31 +506,6 @@ public TrackCurrentIpc2152CalcModel() { //=================================== BOARD THICKNESS MODIFIER (output) =========================// //===============================================================================================// - /*this.boardThicknessModifier = new CalcVarNumericalOutput( - "boardThicknessModifier", - boardThicknessModifierValue, - boardThicknessModifierUnits, - () -> { - - // Read in variables - Double boardThicknessM = this.boardThickness.getRawVal(); - - // Convert to "mils" units, as this is what is used in IPC-2152 graphs - double boardThicknessMils = boardThicknessM * (1 / UNIT_CONVERSION_M_PER_MIL); - - double boardThicknessModifierMulti = BOARD_THICKNESS_TREND_LINE_COEF_A * - Math.pow(boardThicknessMils, BOARD_THICKNESS_TREND_LINE_COEF_B); - - return boardThicknessModifierMulti; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("no unit", 1.0, NumberPreference.DEFAULT), - }, - 4, - "The modifier to adjust the cross-sectional area with based on the board thickness." // Help text - );*/ - this.boardThicknessModifier.setName("boardThicknessModifier"); this.boardThicknessModifier.setValueTextField(this.boardThicknessModifierValue); this.boardThicknessModifier.setUnitsComboBox(this.boardThicknessModifierUnits); @@ -695,7 +526,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.boardThicknessModifier.setNumDigitsToRound(4); this.boardThicknessModifier.setHelpText("The modifier to adjust the cross-sectional area with based on the board thickness."); - this.boardThicknessModifier.setIsEngineeringNotationEnabled(true); + this.boardThicknessModifier.setIsEngineeringNotationEnabled(false); //========== VALIDATORS ==========// this.boardThicknessModifier.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -724,20 +555,6 @@ public TrackCurrentIpc2152CalcModel() { //================================== PLANE PROXIMITY (input) ====================================// //===============================================================================================// - /*this.planeProximity = new CalcVarNumericalInput( - "planeProximity", - planeProximityValue, - planeProximityUnits, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("um", 1e-6), - new NumberUnitMultiplier("mm", 1e-3, NumberPreference.DEFAULT), - new NumberUnitMultiplier("mils", UnitConversionConstants.METERS_PER_MILS), - }, - 4, - null, - "The distance from the current-carrying track to the closest copper plane. If it is a 2-layer 1.6mm PCB, with the current-carrying track on one side and ground on the other side, then the plane proximity would be 1.6mm. For 4 or more layer boards, this value is likely to be much less." // Help text - );*/ - this.planeProximity.setName("planeProximity"); this.planeProximity.setValueTextField(this.planeProximityValue); this.planeProximity.setUnitsComboBox(this.planeProximityUnits); @@ -748,7 +565,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.planeProximity.setNumDigitsToRound(4); this.planeProximity.setHelpText("The distance from the current-carrying track to the closest copper plane. If it is a 2-layer 1.6mm PCB, with the current-carrying track on one side and ground on the other side, then the plane proximity would be 1.6mm. For 4 or more layer boards, this value is likely to be much less."); - this.planeProximity.setIsEngineeringNotationEnabled(true); + this.planeProximity.setIsEngineeringNotationEnabled(false); //========== VALIDATORS ==========// this.planeProximity.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -780,40 +597,6 @@ public TrackCurrentIpc2152CalcModel() { //=================================== PLANE PROXIMITY MODIFIER (output) =========================// //===============================================================================================// - /*this.planeProximityModifier = new CalcVarNumericalOutput( - "planeProximityModifier", - planeProximityModifierValue, - planeProximityModifierUnits, - () -> { - - // Read in variables - String isPlanePresent = this.isPlanePresent.getRawVal(); - double planeProximityM = this.planeProximity.getRawVal(); - - if (isPlanePresent == "False") { - // Lets not modify the cross-sectional area by anything if no plane is present - // (multiply by 1) - return 1.0; - } - - // Plane must be present at this point - - // Convert to "mils" units, as this is what is used in IPC-2152 graphs - double planeProximityMils = planeProximityM * (1 / UNIT_CONVERSION_M_PER_MIL); - - double planeProximityModifierMulti = PLANE_PROXIMITY_TREND_LINE_COEF_M * planeProximityMils + - PLANE_PROXIMITY_TREND_LINE_COEF_C; - - return planeProximityModifierMulti; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("no unit", 1.0, NumberPreference.DEFAULT), - }, - 4, - "The modifier to adjust the cross-sectional area with based on the proximity of a plane to the current-carrying track." // Help text - );*/ - this.planeProximityModifier.setName("planeProximityModifier"); this.planeProximityModifier.setValueTextField(this.planeProximityModifierValue); this.planeProximityModifier.setUnitsComboBox(this.planeProximityModifierUnits); @@ -843,7 +626,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.planeProximityModifier.setNumDigitsToRound(4); this.planeProximityModifier.setHelpText("The modifier to adjust the cross-sectional area with based on the proximity of a plane to the current-carrying track."); - this.planeProximityModifier.setIsEngineeringNotationEnabled(true); + this.planeProximityModifier.setIsEngineeringNotationEnabled(false); // Add validators this.planeProximityModifier.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -855,19 +638,6 @@ public TrackCurrentIpc2152CalcModel() { //================================= THERMAL CONDUCTIVITY (input) ================================// //===============================================================================================// - /*this.thermalConductivity = new CalcVarNumericalInput( - "boardThickness", - thermalConductivityValue, - thermalConductivityUnits, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("W/(m*K)", 1), - new NumberUnitMultiplier("BTU/(hour*ft*F)", UNIT_CONVERSION_THERMAL_CONDUCTIVITY_WATT_nMETER_nKELVIN_PER_BTU_nHOUR_nFT_nDEGF) - }, - 4, - 0.20, - "The thermal conductivity of the PCB. This is normally hard to determine, but for most FR4 PCBs this is around 0.20Wm-1K-1." // Help text - );*/ - this.thermalConductivity.setName("thermalConductivity"); this.thermalConductivity.setValueTextField(this.thermalConductivityValue); this.thermalConductivity.setUnitsComboBox(this.thermalConductivityUnits); @@ -878,7 +648,7 @@ public TrackCurrentIpc2152CalcModel() { this.thermalConductivity.setNumDigitsToRound(4); this.thermalConductivity.setDefaultRawValue(0.20); this.thermalConductivity.setHelpText("The thermal conductivity of the PCB. This is normally hard to determine, but for most FR4 PCBs this is around 0.20Wm-1K-1."); - this.thermalConductivity.setIsEngineeringNotationEnabled(true); + this.thermalConductivity.setIsEngineeringNotationEnabled(false); //========== VALIDATORS ==========// this.thermalConductivity.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -902,32 +672,6 @@ public TrackCurrentIpc2152CalcModel() { //================================ THERMAL CONDUCTIVITY MODIFIER (output) =======================// //===============================================================================================// - /*this.thermalConductivityModifier = new CalcVarNumericalOutput( - "thermalConductivityModifier", - thermalConductivityModifierValue, - thermalConductivityModifierUnits, - () -> { - - // Read in variables - double thermalConductivityWattnMeternDegC = this.thermalConductivity.getRawVal(); - - // Convert to BTU/(ft*hour*F), as this is what the IPC-2152 graph used - double thermalConductivityBtunFtnHournDegF = thermalConductivityWattnMeternDegC * - (1 / UNIT_CONVERSION_THERMAL_CONDUCTIVITY_WATT_nMETER_nKELVIN_PER_BTU_nHOUR_nFT_nDEGF); - - double thermalConductivityModifierMulti = THERMAL_CONDUCTIVITY_TREND_LINE_COEF_M * - thermalConductivityBtunFtnHournDegF + THERMAL_CONDUCTIVITY_TREND_LINE_COEF_C; - - return thermalConductivityModifierMulti; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("no unit", 1.0, NumberPreference.DEFAULT), - }, - 4, - "The modifier to adjust the cross-sectional area with based on the thermal conductivity of the PCB." // Help text - );*/ - this.thermalConductivityModifier.setName("thermalConductivityModifier"); this.thermalConductivityModifier.setValueTextField(this.thermalConductivityModifierValue); this.thermalConductivityModifier.setUnitsComboBox(this.thermalConductivityModifierUnits); @@ -949,7 +693,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.thermalConductivityModifier.setNumDigitsToRound(4); this.thermalConductivityModifier.setHelpText("The modifier to adjust the cross-sectional area with based on the thermal conductivity of the PCB."); - this.thermalConductivityModifier.setIsEngineeringNotationEnabled(true); + this.thermalConductivityModifier.setIsEngineeringNotationEnabled(false); // Add validators this.thermalConductivityModifier.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -961,37 +705,6 @@ public TrackCurrentIpc2152CalcModel() { //================================= ADJUSTED CROSS-SECTIONAL AREA (output) ======================// //===============================================================================================// - /*this.adjustedTrackCrossSectionalArea = new CalcVarNumericalOutput( - "adjustedTrackCrossSectionalArea", - adjustedTrackCrossSectionalAreaValue, - adjustedTrackCrossSectionalAreaUnits, - () -> { - - double unadjustedTrackCrossSectionalArea = this.unadjustedTrackCrossSectionalArea.getRawVal(); - double trackThicknessModifier = this.trackThicknessModifier.getRawVal(); - double boardThicknessModifier = this.boardThicknessModifier.getRawVal(); - double planeProximityModifier = this.planeProximityModifier.getRawVal(); - double thermalConductivityModifier = this.thermalConductivityModifier.getRawVal(); - - double adjustedTrackCrosssectionalAreaM2 = - unadjustedTrackCrossSectionalArea * - trackThicknessModifier * - boardThicknessModifier * - planeProximityModifier * - thermalConductivityModifier; - - return adjustedTrackCrosssectionalAreaM2; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("um²", 1e-12, NumberPreference.DEFAULT), - new NumberUnitMultiplier("mils²", UNIT_CONVERSION_M2_PER_MIL2), - new NumberUnitMultiplier("mm²", 1e-6), - }, - 4, - "The adjusted cross-sectional area, which is equal to the unadjusted cross-section area multiplied by all of the modifiers." // Help text - );*/ - this.adjustedTrackCrossSectionalArea.setName("adjustedTrackCrossSectionalArea"); this.adjustedTrackCrossSectionalArea.setValueTextField(this.adjustedTrackCrossSectionalAreaValue); this.adjustedTrackCrossSectionalArea.setUnitsComboBox(this.adjustedTrackCrossSectionalAreaUnits); @@ -1019,7 +732,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.adjustedTrackCrossSectionalArea.setNumDigitsToRound(4); this.adjustedTrackCrossSectionalArea.setHelpText("The adjusted cross-sectional area, which is equal to the unadjusted cross-section area multiplied by all of the modifiers."); - this.adjustedTrackCrossSectionalArea.setIsEngineeringNotationEnabled(true); + this.adjustedTrackCrossSectionalArea.setIsEngineeringNotationEnabled(false); // Add validators this.adjustedTrackCrossSectionalArea.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); @@ -1032,24 +745,6 @@ public TrackCurrentIpc2152CalcModel() { //==================================== MIN. TRACK WIDTH (output) ================================// //===============================================================================================// - /*this.currentLimit = new CalcVarNumericalOutput( - "currentLimit", - minTrackWidthValue, - minTrackWidthUnits, - () -> { - double minimumTrackWidthM = this.adjustedTrackCrossSectionalArea.getRawVal() / this.trackThickness.getRawVal(); - - return minimumTrackWidthM; - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("um", 1e-6), - new NumberUnitMultiplier("mm", 1e-3, NumberPreference.DEFAULT), - new NumberUnitMultiplier("mils", UnitConversionConstants.METERS_PER_MILS), - }, - 4, - "The minimum track width needed to carry the specified current without exceeding the given temperature rise." // Help text - );*/ - this.minTrackWidth.setName("currentLimit"); this.minTrackWidth.setValueTextField(this.minTrackWidthValue); this.minTrackWidth.setUnitsComboBox(this.minTrackWidthUnits); @@ -1066,7 +761,7 @@ public TrackCurrentIpc2152CalcModel() { }); this.minTrackWidth.setNumDigitsToRound(4); this.minTrackWidth.setHelpText("The minimum track width needed to carry the specified current without exceeding the given temperature rise."); - this.minTrackWidth.setIsEngineeringNotationEnabled(true); + this.minTrackWidth.setIsEngineeringNotationEnabled(false); // Add validators this.minTrackWidth.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); diff --git a/src/Core/CalcVar/CalcVarBase.java b/src/Core/CalcVar/CalcVarBase.java index 9cd9ad7c..905be11a 100644 --- a/src/Core/CalcVar/CalcVarBase.java +++ b/src/Core/CalcVar/CalcVarBase.java @@ -2,6 +2,7 @@ import Core.*; +import java.io.Serializable; import java.util.*; /** @@ -11,7 +12,7 @@ * @since 2015-11-02 * @last-modified 2016-04-23 */ -public abstract class CalcVarBase { +public abstract class CalcVarBase implements Serializable { /** * The name of the calculator variable. Used when debugging. diff --git a/src/Core/CalcVar/CalcVarNumerical.java b/src/Core/CalcVar/CalcVarNumerical.java index 48175d2a..15731153 100644 --- a/src/Core/CalcVar/CalcVarNumerical.java +++ b/src/Core/CalcVar/CalcVarNumerical.java @@ -724,9 +724,10 @@ private void updateDispValFromRawVal() { //System.out.println("updateDispValFromRawVal() called for variable \"" + this.name + "\". this.rawVal = " + this.rawVal); // Special treatment if raw value is NaN - if(Double.isNaN(this.rawVal)) { + if(Double.isNaN(this.rawVal) || Double.isInfinite(this.rawVal)) { //this.dispValAsNumber = Double.NaN; - this.dispValAsString = String.valueOf(Double.NaN); + //this.dispValAsString = String.valueOf(Double.NaN); + this.dispValAsString = String.valueOf(this.rawVal); this.valueTextField.setText(this.dispValAsString); return; } @@ -747,7 +748,11 @@ private void updateDispValFromRawVal() { // Round to specific number of significant figures, but don't use the metrix prefixes library // to that //this.dispValAsString = String.valueOf(unroundedDispVal); - this.dispValAsString = String.valueOf(Rounding.ToSignificantDigits(new BigDecimal(unroundedDispVal), this.numDigitsToRound)); + try { + this.dispValAsString = String.valueOf(Rounding.ToSignificantDigits(new BigDecimal(unroundedDispVal), this.numDigitsToRound)); + } catch (NumberFormatException e) { + throw new RuntimeException("Could not convert the number to a BigDecimal."); + } } } else if(this.roundingType == RoundingTypes.DECIMAL_PLACES) { // Rounding to fixed number of decimal places diff --git a/src/Core/Calculator.java b/src/Core/Calculator.java index 0fc3840c..433437b3 100644 --- a/src/Core/Calculator.java +++ b/src/Core/Calculator.java @@ -5,6 +5,7 @@ import Core.CalcVar.CalcVarNumerical; import javafx.scene.layout.*; +import java.io.Serializable; import java.net.URL; import java.util.ArrayList; @@ -15,7 +16,7 @@ * @since 2015-11-02 * @last-modified 2016-04-25 */ -public abstract class Calculator { +public abstract class Calculator implements Serializable { /** * The name of the calculator. This is shown in the "choose calculator" grid. From 0b50826807044494cfe09a7b6a2191ff3919889b Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Wed, 27 Apr 2016 21:24:54 +1200 Subject: [PATCH 04/16] Fixed info section of "Via Current" calculator, closes #112. --- .idea/workspace.xml | 215 ++++++++---------- changelog.md | 1 + .../ViaCurrentIpc2221ACalcModel.java | 6 +- .../Pcb/ViaCurrentIpc2221A/info.html | 68 +++--- src/Core/CalcVar/CalcVarNumerical.java | 8 +- 5 files changed, 133 insertions(+), 165 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 228df82c..2cde00d7 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -9,11 +9,9 @@ - - - + + - @@ -83,25 +81,26 @@ - - + + - - - + + + + + + + - - + + - - - - - - + + + @@ -110,8 +109,8 @@ - - + + @@ -131,70 +130,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -296,7 +231,6 @@ @@ -491,6 +426,10 @@ - - - - - - - @@ -1290,6 +1238,7 @@ + @@ -1351,13 +1300,6 @@ - - - - - - - @@ -1379,13 +1321,6 @@ - - - - - - - @@ -1599,6 +1534,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1607,29 +1569,30 @@ - + - - + + - + - - + + - + - - + + - - + + + @@ -1637,8 +1600,8 @@ - - + + diff --git a/changelog.md b/changelog.md index f5c3c531..9efcfc5d 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ vX.X.X ------ - Disabled metric prefixes for IPC-2152 calculator variables, closes #118. +- Fixed info section of "Via Current" calculator, closes #112. v1.2.0 ------ diff --git a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java index f074f694..f6d69cc5 100644 --- a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java +++ b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java @@ -28,7 +28,7 @@ public class ViaCurrentIpc2221ACalcModel extends Calculator { //=========================================== CONSTANTS ========================================// //===============================================================================================// - public static final Double thermalResistivity_MKpWatt = 2.489e-3; + public static final Double specificThermalResistivity_KMpWatt = 2.489e-3; public static final Double ipc2221ACoefficientK = 0.048; public static final Double ipc2221ACoefficientb = 0.44; public static final Double ipc2221ACoefficientc = 0.725; @@ -320,7 +320,7 @@ public ViaCurrentIpc2221ACalcModel() { Double viaLength_M = this.viaLength_M.getRawVal(); Double viaCrossSectionalArea_M2 = this.viaCrossSectionalArea_M2.getRawVal(); - return (this.thermalResistivity_MKpWatt*viaLength_M)/viaCrossSectionalArea_M2; + return (this.specificThermalResistivity_KMpWatt *viaLength_M)/viaCrossSectionalArea_M2; }); this.thermalResistance_DegCpWatt.setUnits(new NumberUnitMultiplier[]{ @@ -340,6 +340,8 @@ public ViaCurrentIpc2221ACalcModel() { //====================================== CURRENT LIMIT (output) =================================// //===============================================================================================// + // Note that this does not take into account the via length or the via resistivity. + this.currentLimit.setName("currentLimit"); this.currentLimit.setValueTextField(this.currentLimitValue); this.currentLimit.setUnitsComboBox(this.currentLimitUnits); diff --git a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html index 404c9a22..1b9ec65c 100644 --- a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html +++ b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html @@ -10,37 +10,43 @@ -

This calculator can find the minimum PCB track width (external or internal layer) given the track current, the - allowed temperature rise, and copper layer thickness.

- -

Calculated in accordance with the equations in IPC-2221A Section 6.2 (formerly IPC-D-275, the equation has not - changed between these two standards amd you can get similar values by curve-fitting to the graphs provided in - IPC-D-275, drawn in 1954, woah!

- -

$$ I = k\Delta T^b A^c $$

- -

where:
- \( k \) = 0.048 for external traces, 0.024 for internal tracks
- \( \Delta T \) = the change in temperature (temperature rise) in \( ^{\circ}C \)
- \( b \) = 0.44
- \( A \) = cross-sectional area in \( mils^2 \)
- \( c \) = 0.725
-

- -

The standard only covers values where the current is 0-35A, track width is 0-10.16mm, temperature rise is from - 10-100C, and the copper from 0.5-3oz. Values outside this range are extrapolated (and there more error-prone) and - will turn orange.

- -

This also assumes the track is sufficiently long enough the the end-points do not have a significant effect on the - heatsinking. For example, this calcultor should not be used for calculating the width of thermal-relief style - connections from a copper pour to a via, in where the track is very short (0.2-1.0mm). It also assumes there are no - vias along the length of the track.

- -

The current in assumed to be constant (DC). However, you can use the RMS value for a pulsed current as long as the - pulses are fast enough.

- -

The temperature of the PCB material should NEVER exceed the relative thermal index (RTI) of the material. This is - defined in UL746B as the temperature at which 50% of the materials properties are retained after 100,000 hours.

+

Use this calculator to find the maximum current that a PCB via can handle (a.k.a. as it's ampacity). This calculator uses equations formed from the data presented in the IPC-2221A standard. This equation takes into account the via diameter, via plating thickness and permissible temperature rise.

+ +

The equation used to calculate the maximum via current is:

+ +

$$ I = \Delta T^b \cdot A^c $$

+

+ where:
+ \( I \) = the max. current allowed through the via, in Amps.
+ \( \Delta T \) = the maximum permissible temperature rise of the via above ambient, in \(^{\circ}C\). \(20\) to \(40^{\circ}C\) is a common value for this.
+ \( b \) = A co-efficient from the IPC-2221A standard.
+ \( A \) = the cross-sectional area of the via (the area of the via as looking top down onto it), in \(mills^2\) (imperial).
+ \( c \) = A co-efficient from the IPC-2221A standard. +

+ +

This calculator, when given the via length and plated copper resistivity (default value provided, only change if necessary), will also find approximate values for the electrical and thermal resistance of the via.

+ +

The via's resistance is calculated with the equation:

+ +

$$ R = \frac{\rho l}{A} $$

+

+ where:
+ \( R \) is the resistance of the via, as measured from it's top surface to it's bottom surface, in \(\Omega\).
+ \( \rho \) is the resistivity of plated copper, in \( \Omega \cdot m \). A default value of \(19e^{-9}\Omega m\) is provided for this variable.
+ \( l \) is the length of the via (a.k.a. it's height), in \(m\).
+ \( A \) is the cross-sectional area of the via (the area of the via as looking top down onto it), in \(m^2\). +

+ +

The thermal resistance is calculated with the equation:

+ +

$$ R_{\theta} = \frac{R_{plated-copper} \cdot l}{A} $$

+

+ where:
+ \( R_{\theta} \) is the thermal resistance of the via, in \(K/W\).
+ \( R_{plated-copper} \) is the specific thermal resistivity of plated copper, in \( K \cdot m / W \). A default value of \(2.489e^{-3}Km/W \) is provided for this variable.
+ \( l \) is the length of the via (a.k.a. it's height), in \(m\).
+ \( A \) is the cross-sectional area of the via (the area of the via as looking top down onto it), in \(m^2\). +

Remember this calculator does not take into account other nearby heat sources.

diff --git a/src/Core/CalcVar/CalcVarNumerical.java b/src/Core/CalcVar/CalcVarNumerical.java index 15731153..089f2b24 100644 --- a/src/Core/CalcVar/CalcVarNumerical.java +++ b/src/Core/CalcVar/CalcVarNumerical.java @@ -747,12 +747,8 @@ private void updateDispValFromRawVal() { } else { // Round to specific number of significant figures, but don't use the metrix prefixes library // to that - //this.dispValAsString = String.valueOf(unroundedDispVal); - try { - this.dispValAsString = String.valueOf(Rounding.ToSignificantDigits(new BigDecimal(unroundedDispVal), this.numDigitsToRound)); - } catch (NumberFormatException e) { - throw new RuntimeException("Could not convert the number to a BigDecimal."); - } + this.dispValAsString = String.valueOf(Rounding.ToSignificantDigits(new BigDecimal(unroundedDispVal), this.numDigitsToRound)); + } } else if(this.roundingType == RoundingTypes.DECIMAL_PLACES) { // Rounding to fixed number of decimal places From 47637890d95b0ac9b85dcc76b800736cd7ccf602 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Wed, 27 Apr 2016 21:46:30 +1200 Subject: [PATCH 05/16] Added specific thermal conductivity as a adjustable variable in the via current calculator. --- .idea/workspace.xml | 97 +++++++++++-------- .../ViaCurrentIpc2221ACalcModel.java | 55 ++++++++--- .../ViaCurrentIpc2221ACalcView.fxml | 30 +++--- .../Pcb/ViaCurrentIpc2221A/info.html | 4 +- 4 files changed, 117 insertions(+), 69 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2cde00d7..caedbc07 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,11 +7,9 @@
- - + - @@ -81,11 +79,11 @@ - + - - + + @@ -95,17 +93,30 @@ + + + + + + + + + + + + + - - + + - + @@ -263,7 +274,6 @@ @@ -1034,6 +1045,7 @@ + @@ -1050,7 +1062,6 @@ - @@ -1314,17 +1325,6 @@ - - - - - - - - - - - @@ -1577,26 +1577,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -1613,6 +1593,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java index f6d69cc5..10e8c110 100644 --- a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java +++ b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcModel.java @@ -28,7 +28,6 @@ public class ViaCurrentIpc2221ACalcModel extends Calculator { //=========================================== CONSTANTS ========================================// //===============================================================================================// - public static final Double specificThermalResistivity_KMpWatt = 2.489e-3; public static final Double ipc2221ACoefficientK = 0.048; public static final Double ipc2221ACoefficientb = 0.44; public static final Double ipc2221ACoefficientc = 0.725; @@ -67,6 +66,11 @@ public class ViaCurrentIpc2221ACalcModel extends Calculator { @FXML private ComboBox platedCopperResistivityUnits; + @FXML + private TextField specificThermalConductivityValue; + @FXML + private ComboBox specificThermalConductivityUnits; + @FXML private TextField viaCrossSectionalAreaValue; @FXML @@ -91,17 +95,19 @@ public class ViaCurrentIpc2221ACalcModel extends Calculator { //====================================== CALCULATOR VARIABLES ===================================// //===============================================================================================// - public CalcVarNumericalInput finishedHoleDiameter_M = new CalcVarNumericalInput(); - public CalcVarNumericalInput platingThickness_M = new CalcVarNumericalInput(); - public CalcVarNumericalInput viaLength_M = new CalcVarNumericalInput(); + // CALCULATOR VARIABLES IN DIAGRAM + public final CalcVarNumericalInput finishedHoleDiameter_M = new CalcVarNumericalInput(); + public final CalcVarNumericalInput platingThickness_M = new CalcVarNumericalInput(); + public final CalcVarNumericalInput viaLength_M = new CalcVarNumericalInput(); // CALCULATOR VARIABLES IN GRIDPANE - public CalcVarNumericalInput temperatureRise_DegC = new CalcVarNumericalInput(); - public CalcVarNumericalInput platedCopperResistivity_OhmMeter = new CalcVarNumericalInput(); - public CalcVarNumericalOutput viaCrossSectionalArea_M2 = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput viaResistance_Ohms = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput thermalResistance_DegCpWatt = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput currentLimit = new CalcVarNumericalOutput(); + public final CalcVarNumericalInput temperatureRise_DegC = new CalcVarNumericalInput(); + public final CalcVarNumericalInput platedCopperResistivity_OhmMeter = new CalcVarNumericalInput(); + public final CalcVarNumericalInput specificThermalConductivity_WpKm = new CalcVarNumericalInput(); + public final CalcVarNumericalOutput viaCrossSectionalArea_M2 = new CalcVarNumericalOutput(); + public final CalcVarNumericalOutput viaResistance_Ohms = new CalcVarNumericalOutput(); + public final CalcVarNumericalOutput thermalResistance_DegCpWatt = new CalcVarNumericalOutput(); + public final CalcVarNumericalOutput currentLimit = new CalcVarNumericalOutput(); //===============================================================================================// //========================================== CONSTRUCTORS =======================================// @@ -206,7 +212,7 @@ public ViaCurrentIpc2221ACalcModel() { //===============================================================================================// - //================================ TEMPERATURE RISE (input) ============================// + //==================================== TEMPERATURE RISE (input) =================================// //===============================================================================================// this.temperatureRise_DegC.setName("temperatureRise_DegC"); @@ -250,6 +256,30 @@ public ViaCurrentIpc2221ACalcModel() { this.calcVars.add(this.platedCopperResistivity_OhmMeter); + + //===============================================================================================// + //============================== SPECIFIC THERMAL CONDUCTIVITY (input) ==========================// + //===============================================================================================// + + this.specificThermalConductivity_WpKm.setName("specificThermalConductivity_WpKm"); + this.specificThermalConductivity_WpKm.setValueTextField(this.specificThermalConductivityValue); + this.specificThermalConductivity_WpKm.setUnitsComboBox(this.specificThermalConductivityUnits); + this.specificThermalConductivity_WpKm.setUnits(new NumberUnit[]{ + new NumberUnitMultiplier("W/K⋅m", 1e0), + }); + this.specificThermalConductivity_WpKm.setHelpText("The specific thermal conductivity, k, of the plated copper which the via is made from."); + this.specificThermalConductivity_WpKm.setIsEngineeringNotationEnabled(false); + + // Plated copper has a specific thermal conductivity of about 401.8W/K.m + // (a specific thermal resistivity of 2.489e-3Km/W) + this.specificThermalConductivity_WpKm.setDefaultRawValue(401.8); + + //===== VALIDATORS =====// + this.specificThermalConductivity_WpKm.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + this.specificThermalConductivity_WpKm.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + this.calcVars.add(this.specificThermalConductivity_WpKm); + //===============================================================================================// //================================ VIA CROSS-SECTIONAL AREA (output) ============================// @@ -318,9 +348,10 @@ public ViaCurrentIpc2221ACalcModel() { this.thermalResistance_DegCpWatt.setEquationFunction(() -> { // Read dependencies Double viaLength_M = this.viaLength_M.getRawVal(); + Double specificThermalConductivity_WpKm = this.specificThermalConductivity_WpKm.getRawVal(); Double viaCrossSectionalArea_M2 = this.viaCrossSectionalArea_M2.getRawVal(); - return (this.specificThermalResistivity_KMpWatt *viaLength_M)/viaCrossSectionalArea_M2; + return viaLength_M/(specificThermalConductivity_WpKm * viaCrossSectionalArea_M2); }); this.thermalResistance_DegCpWatt.setUnits(new NumberUnitMultiplier[]{ diff --git a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcView.fxml b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcView.fxml index 17b71b53..a390cb8f 100644 --- a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcView.fxml +++ b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/ViaCurrentIpc2221ACalcView.fxml @@ -88,30 +88,36 @@ - + + + + + + GridPane.rowIndex="3" GridPane.columnIndex="1" /> + GridPane.rowIndex="3" GridPane.columnIndex="2"/> - + + GridPane.rowIndex="4" GridPane.columnIndex="1" /> + GridPane.rowIndex="4" GridPane.columnIndex="2"/> - + + GridPane.rowIndex="5" GridPane.columnIndex="1" /> + GridPane.rowIndex="5" GridPane.columnIndex="2"/> - - Current Limit + - diff --git a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html index 1b9ec65c..f865c521 100644 --- a/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html +++ b/src/Calculators/Electronics/Pcb/ViaCurrentIpc2221A/info.html @@ -39,12 +39,12 @@

The thermal resistance is calculated with the equation:

-

$$ R_{\theta} = \frac{R_{plated-copper} \cdot l}{A} $$

+

$$ R_{\theta} = \frac{l}{k \cdot A} $$

where:
\( R_{\theta} \) is the thermal resistance of the via, in \(K/W\).
- \( R_{plated-copper} \) is the specific thermal resistivity of plated copper, in \( K \cdot m / W \). A default value of \(2.489e^{-3}Km/W \) is provided for this variable.
\( l \) is the length of the via (a.k.a. it's height), in \(m\).
+ \( k \) is the specific thermal conductivity of plated copper, in \( W/Km \). A default value of \(401.8W/K \cdot m \) is provided for this variable.
\( A \) is the cross-sectional area of the via (the area of the via as looking top down onto it), in \(m^2\).

From 2ca8d2645e7ad4e809e0464a32f13232f3fb8dd2 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sun, 1 May 2016 10:06:17 +1200 Subject: [PATCH 06/16] Removed unneeded comments. --- .idea/workspace.xml | 404 ++++-------------- .../StandardResistanceFinderModel.java | 326 +------------- 2 files changed, 82 insertions(+), 648 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index caedbc07..b232e250 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,9 +7,8 @@ - - - + + @@ -69,35 +68,11 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -106,107 +81,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + @@ -269,7 +148,6 @@ @@ -340,6 +219,11 @@ + + + + + @@ -434,11 +318,11 @@ @@ -464,43 +348,12 @@ - - - - - @@ -1034,23 +887,19 @@ - - - - @@ -1058,10 +907,14 @@ + + + + @@ -1119,13 +972,6 @@ - - - - - - - @@ -1174,7 +1020,6 @@ - @@ -1212,16 +1057,6 @@ - - - - - - - - - - @@ -1273,7 +1108,6 @@ - @@ -1281,15 +1115,6 @@ - - - - - - - - - @@ -1297,7 +1122,6 @@ - @@ -1305,7 +1129,6 @@ - @@ -1334,6 +1157,11 @@ + + + + + @@ -1342,25 +1170,11 @@ - - - - - - - - - - - - - - @@ -1390,10 +1204,6 @@ - - - - @@ -1401,9 +1211,6 @@ - - - @@ -1411,12 +1218,6 @@ - - - - - - @@ -1424,46 +1225,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1471,48 +1232,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1536,7 +1256,7 @@ - + @@ -1557,13 +1277,12 @@ - - + @@ -1573,11 +1292,15 @@ - + + + + + @@ -1587,17 +1310,14 @@ - - - - - - + - + + + @@ -1606,7 +1326,7 @@ - + @@ -1614,8 +1334,8 @@ - - + + @@ -1624,6 +1344,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java index d3adc12e..2f5f1e8b 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java @@ -41,7 +41,7 @@ * * @author gbmhunter (www.mbedded.ninja) * @since 2013-09-17 - * @last-modified 2016-04-23 + * @last-modified 2016-05-01 */ public class StandardResistanceFinderModel extends Calculator { @@ -169,18 +169,6 @@ public void handleEvent(Event evt) //================================== DESIRED RESISTANCE (input) =================================// //===============================================================================================// - /*this.desiredResistance = new CalcVarNumericalInput( - "desiredResistance", // Debug name - this.desiredResistanceValue, // Textbox for value (UI object) - null, // No units for this variable - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }, - 4, // Num. digits to round to - null, // Default value - "The resistance you actually want. The closest value to this resistance will be found in each resistor series." // Help info - );*/ - this.desiredResistance.setName("desiredResistance"); this.desiredResistance.setValueTextField(this.desiredResistanceValue); this.desiredResistance.setUnits(new NumberUnitMultiplier[]{ @@ -205,31 +193,6 @@ public void handleEvent(Event evt) //======================================= E6 RESISTANCE (output) ================================// //===============================================================================================// - /*this.e6Resistance = new CalcVarNumericalOutput( - "e6Resistance", - this.e6ResistanceValue, // Textbox - null, // No units for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E6); - - return actualResistance; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The closest resistance in the E6 series to your desired resistance." - );*/ - this.e6Resistance.setName("e6Resistance"); this.e6Resistance.setValueTextField(this.e6ResistanceValue); this.e6Resistance.setEquationFunction(() -> { @@ -261,33 +224,6 @@ public void handleEvent(Event evt) //================================= E6 PERCENTAGE DIFFERENCE (output) ===========================// //===============================================================================================// - /*this.e6Error = new CalcVarNumericalOutput( - "e6Resistance", // Debug name - this.e6ErrorValue, // Textbox for variable value - null, // No units combobox for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e6Resistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; - - return percentageDiff; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The percentage difference between the closest E6 series resistance and your desired resistance." // Tooltip help text - );*/ - this.e6Error.setName("e6Error"); this.e6Error.setValueTextField(this.e6ErrorValue); this.e6Error.setEquationFunction(() -> { @@ -320,31 +256,6 @@ public void handleEvent(Event evt) //======================================= E12 RESISTANCE (output) ================================// //===============================================================================================// - /*this.e12Resistance = new CalcVarNumericalOutput( - "e12Resistance", - this.e12ResistanceValue, // Textbox - null, // No units for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E12); - - return actualResistance; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The closest resistance in the E12 series to your desired resistance." // Tooltip help text - );*/ - this.e12Resistance.setName("e12Resistance"); this.e12Resistance.setValueTextField(this.e12ResistanceValue); this.e12Resistance.setEquationFunction(() -> { @@ -376,33 +287,6 @@ public void handleEvent(Event evt) //====================================== E12 ERROR (output) =====================================// //===============================================================================================// - /*this.e12Error = new CalcVarNumericalOutput( - "e12Error", // Debug name - this.e12ErrorValue, // Textbox for variable value - null, // No units combobox for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e12Resistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; - - return percentageDiff; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The percentage difference between the closest E12 series resistance and your desired resistance." // Tooltip help text - );*/ - this.e12Error.setName("e12Error"); this.e12Error.setValueTextField(this.e12ErrorValue); this.e12Error.setEquationFunction(() -> { @@ -435,31 +319,6 @@ public void handleEvent(Event evt) //======================================= E24 RESISTANCE (output) ================================// //===============================================================================================// - /*this.e24Resistance = new CalcVarNumericalOutput( - "e24Resistance", - this.e24ResistanceValue, // Textbox - null, // No units for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E24); - - return actualResistance; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The closest resistance in the E24 series to your desired resistance." // Tooltip help text - );*/ - this.e24Resistance.setName("e24Resistance"); this.e24Resistance.setValueTextField(this.e24ResistanceValue); this.e24Resistance.setEquationFunction(() -> { @@ -491,33 +350,6 @@ public void handleEvent(Event evt) //================================= E24 PERCENTAGE DIFFERENCE (output) ==========================// //===============================================================================================// - /*this.e24Error = new CalcVarNumericalOutput( - "e24Error", // Debug name - this.e24ErrorValue, // Textbox for variable value - null, // No units combobox for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e24Resistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; - - return percentageDiff; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The percentage difference between the closest E24 series resistance and your desired resistance." // Tooltip help text - );*/ - this.e24Error.setName("e24Error"); this.e24Error.setValueTextField(this.e24ErrorValue); this.e24Error.setEquationFunction(() -> { @@ -550,31 +382,6 @@ public void handleEvent(Event evt) //======================================= E48 RESISTANCE (output) ================================// //===============================================================================================// - /*this.e48Resistance = new CalcVarNumericalOutput( - "e48Resistance", - this.e48ResistanceValue, // Textbox - null, // No units for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E48); - - return actualResistance; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The closest resistance in the E48 series to your desired resistance." // Tooltip help text - );*/ - this.e48Resistance.setName("e48Resistance"); this.e48Resistance.setValueTextField(this.e48ResistanceValue); this.e48Resistance.setEquationFunction(() -> { @@ -606,33 +413,6 @@ public void handleEvent(Event evt) //======================================= E48 ERROR (output) ===================================// //===============================================================================================// - /*this.e48Error = new CalcVarNumericalOutput( - "e48Error", // Debug name - this.e48ErrorValue, // Textbox for variable value - null, // No units combobox for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e48Resistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; - - return percentageDiff; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The percentage difference between the closest E48 series resistance and your desired resistance." // Tooltip help text - );*/ - this.e48Error.setName("e48Error"); this.e48Error.setValueTextField(this.e48ErrorValue); this.e48Error.setEquationFunction(() -> { @@ -665,31 +445,6 @@ public void handleEvent(Event evt) //======================================= E96 RESISTANCE (output) ===============================// //===============================================================================================// - /*this.e96Resistance = new CalcVarNumericalOutput( - "e96Resistance", - this.e96ResistanceValue, // Textbox - null, // No units for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E96); - - return actualResistance; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The closest resistance in the E96 series to your desired resistance." // Tooltip help text - );*/ - this.e96Resistance.setName("e96Resistance"); this.e96Resistance.setValueTextField(this.e96ResistanceValue); this.e96Resistance.setEquationFunction(() -> { @@ -721,33 +476,6 @@ public void handleEvent(Event evt) //================================= E96 PERCENTAGE DIFFERENCE (output) ==========================// //===============================================================================================// - /*this.e96Error = new CalcVarNumericalOutput( - "e96Error", // Debug name - this.e96ErrorValue, // Textbox for variable value - null, // No units combobox for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e96Resistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; - - return percentageDiff; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The percentage difference between the closest E96 series resistance and your desired resistance." // Tooltip help text - );*/ - this.e96Error.setName("e96Error"); this.e96Error.setValueTextField(this.e96ErrorValue); this.e96Error.setEquationFunction(() -> { @@ -780,31 +508,6 @@ public void handleEvent(Event evt) //===================================== E192 RESISTANCE (output) ================================// //===============================================================================================// - /*this.e192Resistance = new CalcVarNumericalOutput( - "e192Resistance", - this.e192ResistanceValue, // Textbox - null, // No units for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E192); - - return actualResistance; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The closest resistance in the E192 series to your desired resistance." // Tooltip help text - );*/ - this.e192Resistance.setName("e192Resistance"); this.e192Resistance.setValueTextField(this.e192ResistanceValue); this.e192Resistance.setEquationFunction(() -> { @@ -836,33 +539,6 @@ public void handleEvent(Event evt) //================================= E192 PERCENTAGE DIFFERENCE (output) ==========================// //===============================================================================================// - /*this.e192Error = new CalcVarNumericalOutput( - "e192Error", // Debug name - this.e192ErrorValue, // Textbox for variable value - null, // No units combobox for this variable - () -> { - - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e192Resistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; - - return percentageDiff; - - }, - new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }, - 4, - "The percentage difference between the closest E192 series resistance and your desired resistance." // Tooltip help text - );*/ - this.e192Error.setName("e192Error"); this.e192Error.setValueTextField(this.e192ErrorValue); this.e192Error.setEquationFunction(() -> { From 7d0fa52818c89cc3e6de0e6678562818f594b528 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sun, 1 May 2016 11:23:41 +1200 Subject: [PATCH 07/16] Changing the way that the standard resistance finder works, now using an array-style build. --- .idea/workspace.xml | 42 +-- .../StandardResistanceFinderModel.java | 269 +++++++++++------- .../StandardResistanceFinderView.fxml | 8 +- 3 files changed, 197 insertions(+), 122 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b232e250..2f6eeb3d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,8 +7,8 @@ - + @@ -71,8 +71,8 @@ - - + + @@ -84,9 +84,11 @@ - - - + + + + + @@ -121,7 +123,6 @@ @@ -882,16 +884,18 @@ - + + + @@ -900,6 +904,7 @@ + @@ -907,11 +912,8 @@ - - - @@ -1337,9 +1339,9 @@ - - - + + + @@ -1365,8 +1367,8 @@ - - + + @@ -1376,9 +1378,11 @@ - - - + + + + + diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java index 2f5f1e8b..ba9f333d 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java @@ -11,7 +11,10 @@ import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.scene.control.*; +import javafx.scene.control.Label; import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javafx.concurrent.Worker.State; @@ -28,6 +31,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.ArrayList; // USER INCLUDES @@ -36,12 +40,12 @@ /** * Calculator for finding a E-series resistance (standard resistance, preferred value) which is closest to the user's * desired resistance. - * + *

* Lists closest resistance and percentage error in each EIA E series from E6 to E192. * - * @author gbmhunter (www.mbedded.ninja) - * @since 2013-09-17 - * @last-modified 2016-05-01 + * @author gbmhunter (www.mbedded.ninja) + * @last-modified 2016-05-01 + * @since 2013-09-17 */ public class StandardResistanceFinderModel extends Calculator { @@ -49,22 +53,39 @@ public class StandardResistanceFinderModel extends Calculator { //========================================= FXML Bindings =======================================// //===============================================================================================// - @FXML private WebView infoWebView; - - @FXML private TextField desiredResistanceValue; - - @FXML private TextField e6ResistanceValue; - @FXML private TextField e6ErrorValue; - @FXML private TextField e12ResistanceValue; - @FXML private TextField e12ErrorValue; - @FXML private TextField e24ResistanceValue; - @FXML private TextField e24ErrorValue; - @FXML private TextField e48ResistanceValue; - @FXML private TextField e48ErrorValue; - @FXML private TextField e96ResistanceValue; - @FXML private TextField e96ErrorValue; - @FXML private TextField e192ResistanceValue; - @FXML private TextField e192ErrorValue; + @FXML + private WebView infoWebView; + + @FXML + private TextField desiredResistanceValue; + + @FXML + private TextField e6ResistanceValue; + @FXML + private TextField e6ErrorValue; + @FXML + private TextField e12ResistanceValue; + @FXML + private TextField e12ErrorValue; + @FXML + private TextField e24ResistanceValue; + @FXML + private TextField e24ErrorValue; + @FXML + private TextField e48ResistanceValue; + @FXML + private TextField e48ErrorValue; + @FXML + private TextField e96ResistanceValue; + @FXML + private TextField e96ErrorValue; + @FXML + private TextField e192ResistanceValue; + @FXML + private TextField e192ErrorValue; + + @FXML + private GridPane variableGridPane; //===============================================================================================// //====================================== CALCULATOR VARIABLES ===================================// @@ -84,15 +105,27 @@ public class StandardResistanceFinderModel extends Calculator { public CalcVarNumericalOutput e192Resistance = new CalcVarNumericalOutput(); public CalcVarNumericalOutput e192Error = new CalcVarNumericalOutput(); + private class GridPaneRow { + String resistanceSeries; + CalcVarNumericalOutput closestResistance; + CalcVarNumericalOutput closesResistanceError; + CalcVarNumericalOutput closestHigherResistance; + CalcVarNumericalOutput closestHigherResistanceError; + CalcVarNumericalOutput closestLowerResistance; + CalcVarNumericalOutput closestLowerResistanceError; + } + + public ArrayList gridPaneRows = new ArrayList<>(); + //===============================================================================================// //=========================================== CONSTRUCTOR =======================================// //===============================================================================================// public StandardResistanceFinderModel() { - super( "Standard Resistance Finder", + super("Standard Resistance Finder", "Find the closest E-series (e.g. E12, E96) resistor (preferred value) to your desired resistance.", - new String[]{ "Electronics", "Basic" }, + new String[]{"Electronics", "Basic"}, new String[]{"ohm", "resistor", "resistance", "e", "series", "standard", "preferred", "values", "e6", "e12", "e24", "e48", "e96", "e128"}); super.setIconImagePath(getClass().getResource("grid-icon.png")); @@ -118,7 +151,7 @@ public StandardResistanceFinderModel() { //===============================================================================================// WebEngine engine = this.infoWebView.getEngine(); - final String htmlFile= "info.html"; + final String htmlFile = "info.html"; URL url = getClass().getResource(htmlFile); engine.getLoadWorker().stateProperty().addListener( @@ -128,15 +161,12 @@ public void changed(ObservableValue ov, State oldState, State newState) { //stage.setTitle(engine.getLocation()); NodeList nodeList = engine.getDocument().getElementsByTagName("a"); - for (int i = 0; i < nodeList.getLength(); i++) - { - Node node= nodeList.item(i); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); EventTarget eventTarget = (EventTarget) node; - eventTarget.addEventListener("click", new EventListener() - { + eventTarget.addEventListener("click", new EventListener() { @Override - public void handleEvent(Event evt) - { + public void handleEvent(Event evt) { EventTarget target = evt.getCurrentTarget(); HTMLAnchorElement anchorElement = (HTMLAnchorElement) target; String href = anchorElement.getHref(); @@ -183,74 +213,78 @@ public void handleEvent(Event evt) this.desiredResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); this.desiredResistance.addValidator( new Validator(() -> { - return ((this.desiredResistance.getRawVal() < 1.0 || this.desiredResistance.getRawVal() >10.0e6) ? CalcValidationLevels.Warning : CalcValidationLevels.Ok); + return ((this.desiredResistance.getRawVal() < 1.0 || this.desiredResistance.getRawVal() > 10.0e6) ? CalcValidationLevels.Warning : CalcValidationLevels.Ok); }, - "The desired resistance is outside the \"normal\" purchasable resistance range of 1Ω to 10MΩ. Some or all of the standard E-series may not have a resistor available with the desired resistance.")); + "The desired resistance is outside the \"normal\" purchasable resistance range of 1Ω to 10MΩ. Some or all of the standard E-series may not have a resistor available with the desired resistance.")); this.calcVars.add(this.desiredResistance); - //===============================================================================================// - //======================================= E6 RESISTANCE (output) ================================// - //===============================================================================================// - this.e6Resistance.setName("e6Resistance"); - this.e6Resistance.setValueTextField(this.e6ResistanceValue); - this.e6Resistance.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E6); - return actualResistance; - }); - this.e6Resistance.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - this.e6Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); - this.e6Resistance.setHelpText("The closest resistance in the E6 series to your desired resistance."); - this.e6Resistance.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e6Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - this.e6Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + //===============================================================================================// + //======================================= E6 RESISTANCE (output) ================================// + //===============================================================================================// - this.calcVars.add(this.e6Resistance); +// this.e6Resistance.setName("e6Resistance"); +// this.e6Resistance.setValueTextField(this.e6ResistanceValue); +// this.e6Resistance.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E6); +// +// return actualResistance; +// }); +// this.e6Resistance.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), +// }); +// this.e6Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); +// this.e6Resistance.setHelpText("The closest resistance in the E6 series to your desired resistance."); +// this.e6Resistance.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e6Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// this.e6Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e6Resistance); //===============================================================================================// //================================= E6 PERCENTAGE DIFFERENCE (output) ===========================// //===============================================================================================// - this.e6Error.setName("e6Error"); - this.e6Error.setValueTextField(this.e6ErrorValue); - this.e6Error.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e6Resistance.getRawVal(); - - if(Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; - - return percentageDiff; - }); - this.e6Error.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }); - this.e6Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); - this.e6Error.setHelpText("The percentage difference between the closest E6 series resistance and your desired resistance."); - this.e6Error.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e6Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - - this.calcVars.add(this.e6Error); +// this.e6Error.setName("e6Error"); +// this.e6Error.setValueTextField(this.e6ErrorValue); +// this.e6Error.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// Double closestStandardResistance = this.e6Resistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// // Calculate percentage difference +// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; +// +// return percentageDiff; +// }); +// this.e6Error.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), +// }); +// this.e6Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); +// this.e6Error.setHelpText("The percentage difference between the closest E6 series resistance and your desired resistance."); +// this.e6Error.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e6Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e6Error); //===============================================================================================// //======================================= E12 RESISTANCE (output) ================================// @@ -262,7 +296,7 @@ public void handleEvent(Event evt) // Read in variables Double desiredResistance = this.desiredResistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } @@ -294,12 +328,12 @@ public void handleEvent(Event evt) Double desiredResistance = this.desiredResistance.getRawVal(); Double closestStandardResistance = this.e12Resistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; + double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; return percentageDiff; }); @@ -325,7 +359,7 @@ public void handleEvent(Event evt) // Read in variables Double desiredResistance = this.desiredResistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } @@ -357,12 +391,12 @@ public void handleEvent(Event evt) Double desiredResistance = this.desiredResistance.getRawVal(); Double closestStandardResistance = this.e24Resistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; + double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; return percentageDiff; }); @@ -388,7 +422,7 @@ public void handleEvent(Event evt) // Read in variables Double desiredResistance = this.desiredResistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } @@ -420,12 +454,12 @@ public void handleEvent(Event evt) Double desiredResistance = this.desiredResistance.getRawVal(); Double closestStandardResistance = this.e48Resistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; + double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; return percentageDiff; }); @@ -451,7 +485,7 @@ public void handleEvent(Event evt) // Read in variables Double desiredResistance = this.desiredResistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } @@ -483,12 +517,12 @@ public void handleEvent(Event evt) Double desiredResistance = this.desiredResistance.getRawVal(); Double closestStandardResistance = this.e96Resistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; + double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; return percentageDiff; }); @@ -514,7 +548,7 @@ public void handleEvent(Event evt) // Read in variables Double desiredResistance = this.desiredResistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } @@ -546,12 +580,12 @@ public void handleEvent(Event evt) Double desiredResistance = this.desiredResistance.getRawVal(); Double closestStandardResistance = this.e192Resistance.getRawVal(); - if(Double.isNaN(desiredResistance)) { + if (Double.isNaN(desiredResistance)) { return Double.NaN; } // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance)/desiredResistance)*100.0; + double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; return percentageDiff; }); @@ -567,6 +601,18 @@ public void handleEvent(Event evt) this.calcVars.add(this.e192Error); + //===============================================================================================// + //========================================== ARRAY METHOD =======================================// + //===============================================================================================// + + GridPaneRow e6 = new GridPaneRow(); + e6.resistanceSeries = "E6"; + e6.closestResistance = this.e6Resistance; + e6.closesResistanceError = this.e6Error; + gridPaneRows.add(e6); + + addGridPaneRowsToUi(gridPaneRows); + //===============================================================================================// //============================================== FINAL ==========================================// //===============================================================================================// @@ -578,5 +624,30 @@ public void handleEvent(Event evt) } + private void addGridPaneRowsToUi(ArrayList gridPaneRowList) { + for(int x = 0; x < gridPaneRowList.size(); x++) { + // Create label + Label resistanceSeriesLabel = new Label(gridPaneRowList.get(x).resistanceSeries); + this.variableGridPane.add(resistanceSeriesLabel, 0, x + 1); + + // "Closest Resistance" TextField + TextField closestResistanceTextField = new TextField(); + this.variableGridPane.add(closestResistanceTextField, 1, x + 1); + + // Ohm symbol + Label ohmSymbol = new Label("Ω"); + this.variableGridPane.add(ohmSymbol, 2, x + 1); + + // "Closest Resistance" TextField + TextField closestResistanceErrorTextField = new TextField(); + this.variableGridPane.add(closestResistanceErrorTextField, 3, x + 1); + + // Ohm symbol + Label percentSymbol = new Label("%"); + this.variableGridPane.add(percentSymbol, 4, x + 1); + + } + } + } diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml index d6433985..e19c3d8b 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml @@ -41,7 +41,7 @@ - + @@ -57,9 +57,9 @@ - - - + + + From 61cf2538405b30c314e2ce13a1e728841754f3f1 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sat, 14 May 2016 16:57:01 +1200 Subject: [PATCH 08/16] Created a class to manage each row in the "Standard Resistance Finder" calculator table. --- .idea/workspace.xml | 172 ++-- .../ESeriesResistanceRow.java | 137 ++++ .../StandardResistanceFinderModel.java | 749 ++++++++++-------- .../StandardResistanceFinderView.fxml | 64 +- 4 files changed, 676 insertions(+), 446 deletions(-) create mode 100644 src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2f6eeb3d..a6ee4c46 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,6 +7,7 @@ + @@ -70,29 +71,61 @@ + + + - - + + - - - - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -123,8 +156,6 @@ @@ -221,7 +254,6 @@ - @@ -356,6 +388,7 @@ + @@ -884,7 +917,7 @@ - + @@ -895,11 +928,12 @@ - + + @@ -909,7 +943,6 @@ - @@ -945,12 +978,6 @@ - - - - - - - - - - @@ -1086,7 +1103,6 @@ - @@ -1159,11 +1175,6 @@ - - - - - @@ -1172,6 +1183,11 @@ + + + + + @@ -1194,14 +1210,6 @@ - - - - - - - - @@ -1234,7 +1242,6 @@ - @@ -1242,7 +1249,6 @@ - @@ -1250,9 +1256,6 @@ - - - @@ -1264,17 +1267,6 @@ - - - - - - - - - - - @@ -1298,28 +1290,24 @@ - - - - - - + + + + + - - - @@ -1330,7 +1318,6 @@ - @@ -1338,11 +1325,6 @@ - - - - - @@ -1353,7 +1335,6 @@ - @@ -1361,27 +1342,52 @@ - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java new file mode 100644 index 00000000..b7219888 --- /dev/null +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java @@ -0,0 +1,137 @@ +package Calculators.Electronics.Basic.StandardResistanceFinder; + +import Core.*; +import Core.CalcVar.CalcVarBase; +import Core.CalcVar.CalcVarNumerical; +import Core.CalcVar.CalcVarNumericalInput; +import Core.CalcVar.CalcVarNumericalOutput; +import Utility.StandardResistanceFinder; +import javafx.geometry.Pos; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; + +import java.util.ArrayList; + +/** + * Represents a row in the standard resistance finder table. + * + * @author gbmhunter (www.mbedded.ninja) + * @last-modified 2016-05-14 + * @since 2016-05-14 + */ +public class ESeriesResistanceRow { + + String name; + StandardResistanceFinder.eSeriesOptions eSeries; + + CalcVarNumericalOutput closestResistance; + CalcVarNumericalOutput closestResistanceErrorCalcVar; + + CalcVarNumericalOutput closestHigherResistance; + CalcVarNumericalOutput closestLowerResistance; + + ESeriesResistanceRow( + String name, + StandardResistanceFinder.eSeriesOptions eSeries, + CalcVarNumericalInput desiredResistance, + GridPane variableGridPane, + Integer rowToAddTo, + ArrayList calcVars, + CalcVarNumerical.RoundingTypes roundingType, + Integer numberToRoundTo) { + + this.name = name; + this.eSeries = eSeries; + + // Create label + Label resistanceSeriesLabel = new Label(eSeries.name()); + variableGridPane.add(resistanceSeriesLabel, 0, rowToAddTo); + + //=============== CLOSEST RESISTANCE ============// + + // "Closest Resistance" TextField + TextField closestResistanceTextField = new TextField(); + closestResistanceTextField.setAlignment(Pos.CENTER_RIGHT); + variableGridPane.add(closestResistanceTextField, 1, rowToAddTo); + + // Calculator variable + closestResistance = new CalcVarNumericalOutput(); + closestResistance.setName("closestResistance"); + closestResistance.setValueTextField(closestResistanceTextField); + closestResistance.setEquationFunction(() -> { + // Read in variables + Double desiredResistanceValue = desiredResistance.getRawVal(); + + if (Double.isNaN(desiredResistanceValue)) { + return Double.NaN; + } + + double actualResistance = StandardResistanceFinder.Find(desiredResistanceValue, eSeries); + + return actualResistance; + }); + closestResistance.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), + }); + closestResistance.setRounding(roundingType, numberToRoundTo); + closestResistance.setHelpText("The closest resistance in the E6 series to your desired resistance."); + closestResistance.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + closestResistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + calcVars.add(closestResistance); + + // Ohm symbol + Label ohmSymbol = new Label("Ω"); + variableGridPane.add(ohmSymbol, 2, rowToAddTo); + + //=============== CLOSEST RESISTANCE ERROR ============// + + // "Closest Resistance" TextField + TextField closestResistanceErrorTextField = new TextField(); + closestResistanceErrorTextField.setAlignment(Pos.CENTER_RIGHT); + variableGridPane.add(closestResistanceErrorTextField, 3, rowToAddTo); + + // Calculator variable + closestResistanceErrorCalcVar = new CalcVarNumericalOutput(); + closestResistanceErrorCalcVar.setName("e6Error"); + closestResistanceErrorCalcVar.setValueTextField(closestResistanceErrorTextField); + closestResistanceErrorCalcVar.setEquationFunction(() -> { + // Read in variables + Double desiredResistanceValue = desiredResistance.getRawVal(); + Double closestStandardResistanceValue = closestResistance.getRawVal(); + + if (Double.isNaN(desiredResistanceValue)) { + return Double.NaN; + } + + // Calculate percentage difference + double percentageDiff = (Math.abs(closestStandardResistanceValue - desiredResistanceValue) / desiredResistanceValue) * 100.0; + + return percentageDiff; + }); + closestResistanceErrorCalcVar.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), + }); + closestResistanceErrorCalcVar.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); + closestResistanceErrorCalcVar.setHelpText("The percentage difference between the closest E6 series resistance and your desired resistance."); + closestResistanceErrorCalcVar.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + closestResistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + calcVars.add(closestResistanceErrorCalcVar); + + // Percentage symbol + Label percentSymbol = new Label("%"); + variableGridPane.add(percentSymbol, 4, rowToAddTo); + + + } + + +} diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java index ba9f333d..4807db25 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java @@ -11,7 +11,6 @@ import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; -import javafx.scene.control.*; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; @@ -40,12 +39,12 @@ /** * Calculator for finding a E-series resistance (standard resistance, preferred value) which is closest to the user's * desired resistance. - *

+ * * Lists closest resistance and percentage error in each EIA E series from E6 to E192. * - * @author gbmhunter (www.mbedded.ninja) - * @last-modified 2016-05-01 - * @since 2013-09-17 + * @author gbmhunter (www.mbedded.ninja) + * @last-modified 2016-05-01 + * @since 2013-09-17 */ public class StandardResistanceFinderModel extends Calculator { @@ -220,9 +219,6 @@ public void handleEvent(Event evt) { this.calcVars.add(this.desiredResistance); - - - //===============================================================================================// //======================================= E6 RESISTANCE (output) ================================// //===============================================================================================// @@ -286,332 +282,389 @@ public void handleEvent(Event evt) { // // this.calcVars.add(this.e6Error); - //===============================================================================================// - //======================================= E12 RESISTANCE (output) ================================// - //===============================================================================================// - - this.e12Resistance.setName("e12Resistance"); - this.e12Resistance.setValueTextField(this.e12ResistanceValue); - this.e12Resistance.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E12); - - return actualResistance; - }); - this.e12Resistance.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - this.e12Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); - this.e12Resistance.setHelpText("The closest resistance in the E12 series to your desired resistance."); - this.e12Resistance.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e12Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - this.e12Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - - this.calcVars.add(this.e12Resistance); - - //===============================================================================================// - //====================================== E12 ERROR (output) =====================================// - //===============================================================================================// - - this.e12Error.setName("e12Error"); - this.e12Error.setValueTextField(this.e12ErrorValue); - this.e12Error.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e12Resistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; - - return percentageDiff; - }); - this.e12Error.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }); - this.e12Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); - this.e12Error.setHelpText("The percentage difference between the closest E12 series resistance and your desired resistance."); - this.e12Error.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e12Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - - this.calcVars.add(this.e12Error); - - //===============================================================================================// - //======================================= E24 RESISTANCE (output) ================================// - //===============================================================================================// - - this.e24Resistance.setName("e24Resistance"); - this.e24Resistance.setValueTextField(this.e24ResistanceValue); - this.e24Resistance.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E24); - - return actualResistance; - }); - this.e24Resistance.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - this.e24Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); - this.e24Resistance.setHelpText("The closest resistance in the E24 series to your desired resistance."); - this.e24Resistance.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e24Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - this.e24Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - - this.calcVars.add(this.e24Resistance); - - //===============================================================================================// - //================================= E24 PERCENTAGE DIFFERENCE (output) ==========================// - //===============================================================================================// - - this.e24Error.setName("e24Error"); - this.e24Error.setValueTextField(this.e24ErrorValue); - this.e24Error.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e24Resistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; - - return percentageDiff; - }); - this.e24Error.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }); - this.e24Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); - this.e24Error.setHelpText("The percentage difference between the closest E24 series resistance and your desired resistance."); - this.e24Error.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e24Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - - this.calcVars.add(this.e24Error); - - //===============================================================================================// - //======================================= E48 RESISTANCE (output) ================================// - //===============================================================================================// - - this.e48Resistance.setName("e48Resistance"); - this.e48Resistance.setValueTextField(this.e48ResistanceValue); - this.e48Resistance.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E48); - - return actualResistance; - }); - this.e48Resistance.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - this.e48Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); - this.e48Resistance.setHelpText("The closest resistance in the E48 series to your desired resistance."); - this.e48Resistance.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e48Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - this.e48Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - - this.calcVars.add(this.e48Resistance); - - //===============================================================================================// - //======================================= E48 ERROR (output) ===================================// - //===============================================================================================// - - this.e48Error.setName("e48Error"); - this.e48Error.setValueTextField(this.e48ErrorValue); - this.e48Error.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e48Resistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; - - return percentageDiff; - }); - this.e48Error.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }); - this.e48Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); - this.e48Error.setHelpText("The percentage difference between the closest E48 series resistance and your desired resistance."); - this.e48Error.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e48Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - - this.calcVars.add(this.e48Error); - - //===============================================================================================// - //======================================= E96 RESISTANCE (output) ===============================// - //===============================================================================================// - - this.e96Resistance.setName("e96Resistance"); - this.e96Resistance.setValueTextField(this.e96ResistanceValue); - this.e96Resistance.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E96); - - return actualResistance; - }); - this.e96Resistance.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - this.e96Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); - this.e96Resistance.setHelpText("The closest resistance in the E96 series to your desired resistance."); - this.e96Resistance.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e96Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - this.e96Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - - this.calcVars.add(this.e96Resistance); - - //===============================================================================================// - //================================= E96 PERCENTAGE DIFFERENCE (output) ==========================// - //===============================================================================================// - - this.e96Error.setName("e96Error"); - this.e96Error.setValueTextField(this.e96ErrorValue); - this.e96Error.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e96Resistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; - - return percentageDiff; - }); - this.e96Error.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }); - this.e96Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); - this.e96Error.setHelpText("The percentage difference between the closest E96 series resistance and your desired resistance."); - this.e96Error.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e96Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - - this.calcVars.add(this.e96Error); - - //===============================================================================================// - //===================================== E192 RESISTANCE (output) ================================// - //===============================================================================================// - - this.e192Resistance.setName("e192Resistance"); - this.e192Resistance.setValueTextField(this.e192ResistanceValue); - this.e192Resistance.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E192); - - return actualResistance; - }); - this.e192Resistance.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - this.e192Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); - this.e192Resistance.setHelpText("The closest resistance in the E192 series to your desired resistance."); - this.e192Resistance.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e192Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - this.e192Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - - this.calcVars.add(this.e192Resistance); - - //===============================================================================================// - //================================= E192 PERCENTAGE DIFFERENCE (output) ==========================// - //===============================================================================================// - - this.e192Error.setName("e192Error"); - this.e192Error.setValueTextField(this.e192ErrorValue); - this.e192Error.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - Double closestStandardResistance = this.e192Resistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - // Calculate percentage difference - double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; - - return percentageDiff; - }); - this.e192Error.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), - }); - this.e192Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); - this.e192Error.setHelpText("The percentage difference between the closest E192 series resistance and your desired resistance."); - this.e192Error.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.e192Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - - this.calcVars.add(this.e192Error); +// //===============================================================================================// +// //======================================= E12 RESISTANCE (output) ================================// +// //===============================================================================================// +// +// this.e12Resistance.setName("e12Resistance"); +// this.e12Resistance.setValueTextField(this.e12ResistanceValue); +// this.e12Resistance.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E12); +// +// return actualResistance; +// }); +// this.e12Resistance.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), +// }); +// this.e12Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); +// this.e12Resistance.setHelpText("The closest resistance in the E12 series to your desired resistance."); +// this.e12Resistance.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e12Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// this.e12Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e12Resistance); +// +// //===============================================================================================// +// //====================================== E12 ERROR (output) =====================================// +// //===============================================================================================// +// +// this.e12Error.setName("e12Error"); +// this.e12Error.setValueTextField(this.e12ErrorValue); +// this.e12Error.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// Double closestStandardResistance = this.e12Resistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// // Calculate percentage difference +// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; +// +// return percentageDiff; +// }); +// this.e12Error.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), +// }); +// this.e12Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); +// this.e12Error.setHelpText("The percentage difference between the closest E12 series resistance and your desired resistance."); +// this.e12Error.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e12Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e12Error); +// +// //===============================================================================================// +// //======================================= E24 RESISTANCE (output) ================================// +// //===============================================================================================// +// +// this.e24Resistance.setName("e24Resistance"); +// this.e24Resistance.setValueTextField(this.e24ResistanceValue); +// this.e24Resistance.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E24); +// +// return actualResistance; +// }); +// this.e24Resistance.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), +// }); +// this.e24Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); +// this.e24Resistance.setHelpText("The closest resistance in the E24 series to your desired resistance."); +// this.e24Resistance.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e24Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// this.e24Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e24Resistance); +// +// //===============================================================================================// +// //================================= E24 PERCENTAGE DIFFERENCE (output) ==========================// +// //===============================================================================================// +// +// this.e24Error.setName("e24Error"); +// this.e24Error.setValueTextField(this.e24ErrorValue); +// this.e24Error.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// Double closestStandardResistance = this.e24Resistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// // Calculate percentage difference +// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; +// +// return percentageDiff; +// }); +// this.e24Error.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), +// }); +// this.e24Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); +// this.e24Error.setHelpText("The percentage difference between the closest E24 series resistance and your desired resistance."); +// this.e24Error.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e24Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e24Error); +// +// //===============================================================================================// +// //======================================= E48 RESISTANCE (output) ================================// +// //===============================================================================================// +// +// this.e48Resistance.setName("e48Resistance"); +// this.e48Resistance.setValueTextField(this.e48ResistanceValue); +// this.e48Resistance.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E48); +// +// return actualResistance; +// }); +// this.e48Resistance.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), +// }); +// this.e48Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); +// this.e48Resistance.setHelpText("The closest resistance in the E48 series to your desired resistance."); +// this.e48Resistance.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e48Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// this.e48Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e48Resistance); +// +// //===============================================================================================// +// //======================================= E48 ERROR (output) ===================================// +// //===============================================================================================// +// +// this.e48Error.setName("e48Error"); +// this.e48Error.setValueTextField(this.e48ErrorValue); +// this.e48Error.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// Double closestStandardResistance = this.e48Resistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// // Calculate percentage difference +// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; +// +// return percentageDiff; +// }); +// this.e48Error.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), +// }); +// this.e48Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); +// this.e48Error.setHelpText("The percentage difference between the closest E48 series resistance and your desired resistance."); +// this.e48Error.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e48Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e48Error); +// +// //===============================================================================================// +// //======================================= E96 RESISTANCE (output) ===============================// +// //===============================================================================================// +// +// this.e96Resistance.setName("e96Resistance"); +// this.e96Resistance.setValueTextField(this.e96ResistanceValue); +// this.e96Resistance.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E96); +// +// return actualResistance; +// }); +// this.e96Resistance.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), +// }); +// this.e96Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); +// this.e96Resistance.setHelpText("The closest resistance in the E96 series to your desired resistance."); +// this.e96Resistance.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e96Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// this.e96Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e96Resistance); +// +// //===============================================================================================// +// //================================= E96 PERCENTAGE DIFFERENCE (output) ==========================// +// //===============================================================================================// +// +// this.e96Error.setName("e96Error"); +// this.e96Error.setValueTextField(this.e96ErrorValue); +// this.e96Error.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// Double closestStandardResistance = this.e96Resistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// // Calculate percentage difference +// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; +// +// return percentageDiff; +// }); +// this.e96Error.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), +// }); +// this.e96Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); +// this.e96Error.setHelpText("The percentage difference between the closest E96 series resistance and your desired resistance."); +// this.e96Error.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e96Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e96Error); +// +// //===============================================================================================// +// //===================================== E192 RESISTANCE (output) ================================// +// //===============================================================================================// +// +// this.e192Resistance.setName("e192Resistance"); +// this.e192Resistance.setValueTextField(this.e192ResistanceValue); +// this.e192Resistance.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E192); +// +// return actualResistance; +// }); +// this.e192Resistance.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), +// }); +// this.e192Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); +// this.e192Resistance.setHelpText("The closest resistance in the E192 series to your desired resistance."); +// this.e192Resistance.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e192Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// this.e192Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e192Resistance); +// +// //===============================================================================================// +// //================================= E192 PERCENTAGE DIFFERENCE (output) ==========================// +// //===============================================================================================// +// +// this.e192Error.setName("e192Error"); +// this.e192Error.setValueTextField(this.e192ErrorValue); +// this.e192Error.setEquationFunction(() -> { +// // Read in variables +// Double desiredResistance = this.desiredResistance.getRawVal(); +// Double closestStandardResistance = this.e192Resistance.getRawVal(); +// +// if (Double.isNaN(desiredResistance)) { +// return Double.NaN; +// } +// +// // Calculate percentage difference +// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; +// +// return percentageDiff; +// }); +// this.e192Error.setUnits(new NumberUnitMultiplier[]{ +// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), +// }); +// this.e192Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); +// this.e192Error.setHelpText("The percentage difference between the closest E192 series resistance and your desired resistance."); +// this.e192Error.setIsEngineeringNotationEnabled(true); +// +// //========== VALIDATORS ===========// +// this.e192Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); +// +// this.calcVars.add(this.e192Error); //===============================================================================================// //========================================== ARRAY METHOD =======================================// //===============================================================================================// - GridPaneRow e6 = new GridPaneRow(); - e6.resistanceSeries = "E6"; - e6.closestResistance = this.e6Resistance; - e6.closesResistanceError = this.e6Error; - gridPaneRows.add(e6); - - addGridPaneRowsToUi(gridPaneRows); + // This variable keeps track of what row we are up to when inserting E-series resistances + Integer gridRowCount = 0; + // First row is a header + gridRowCount++; + + ESeriesResistanceRow e6ResistanceRow = new ESeriesResistanceRow( + "E6", + StandardResistanceFinder.eSeriesOptions.E6, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 2); + + ESeriesResistanceRow e12ResistanceRow = new ESeriesResistanceRow( + "E12", + StandardResistanceFinder.eSeriesOptions.E12, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 2); + + ESeriesResistanceRow e24ResistanceRow = new ESeriesResistanceRow( + "E24", + StandardResistanceFinder.eSeriesOptions.E24, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 2); + + ESeriesResistanceRow e48ResistanceRow = new ESeriesResistanceRow( + "E48", + StandardResistanceFinder.eSeriesOptions.E48, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 3); + + ESeriesResistanceRow e96ResistanceRow = new ESeriesResistanceRow( + "E96", + StandardResistanceFinder.eSeriesOptions.E96, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 3); + + ESeriesResistanceRow e192ResistanceRow = new ESeriesResistanceRow( + "E192", + StandardResistanceFinder.eSeriesOptions.E192, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 3); //===============================================================================================// //============================================== FINAL ==========================================// @@ -624,20 +677,54 @@ public void handleEvent(Event evt) { } - private void addGridPaneRowsToUi(ArrayList gridPaneRowList) { +/* + private void buildCalculator(ArrayList gridPaneRowList) { for(int x = 0; x < gridPaneRowList.size(); x++) { // Create label Label resistanceSeriesLabel = new Label(gridPaneRowList.get(x).resistanceSeries); this.variableGridPane.add(resistanceSeriesLabel, 0, x + 1); + //=============== CLOSEST RESISTANCE ============// + // "Closest Resistance" TextField TextField closestResistanceTextField = new TextField(); this.variableGridPane.add(closestResistanceTextField, 1, x + 1); + // Calculator variable + CalcVarNumericalOutput closestResistanceCalcVar = new CalcVarNumericalOutput(); + closestResistanceCalcVar.setName("closestResistance"); + closestResistanceCalcVar.setValueTextField(closestResistanceTextField); + closestResistanceCalcVar.setEquationFunction(() -> { + // Read in variables + Double desiredResistance = this.desiredResistance.getRawVal(); + + if (Double.isNaN(desiredResistance)) { + return Double.NaN; + } + + double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E6); + + return actualResistance; + }); + closestResistanceCalcVar.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), + }); + closestResistanceCalcVar.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); + closestResistanceCalcVar.setHelpText("The closest resistance in the E6 series to your desired resistance."); + closestResistanceCalcVar.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + closestResistanceCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestResistanceCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + this.calcVars.add(closestResistanceCalcVar); + // Ohm symbol Label ohmSymbol = new Label("Ω"); this.variableGridPane.add(ohmSymbol, 2, x + 1); + //=============== CLOSEST RESISTANCE ERROR ============// + // "Closest Resistance" TextField TextField closestResistanceErrorTextField = new TextField(); this.variableGridPane.add(closestResistanceErrorTextField, 3, x + 1); @@ -647,7 +734,7 @@ private void addGridPaneRowsToUi(ArrayList gridPaneRowList) { this.variableGridPane.add(percentSymbol, 4, x + 1); } - } + }*/ } diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml index e19c3d8b..ae4e68c9 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml @@ -60,38 +60,38 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From c8a4dacc3acb33255f7702546e973631bbae8343 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sat, 14 May 2016 18:49:11 +1200 Subject: [PATCH 09/16] Added the ability to find the closest higher or closest lower resistance to the standard resistance finder class. --- .idea/workspace.xml | 303 +++++++++++------- .../ESeriesResistanceRow.java | 60 +++- src/Utility/StandardResistanceFinder.java | 140 +++++--- .../StandardResistanceFinderModelTest.java | 26 +- test/Utility/MetrixPrefixesTests.java | 6 +- test/Utility/RoundingTests.java | 6 +- .../StandardResistanceFinderTests.java | 42 +++ 7 files changed, 403 insertions(+), 180 deletions(-) create mode 100644 test/Utility/StandardResistanceFinderTests.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a6ee4c46..d7651874 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,9 +7,11 @@ - - - + + + + + @@ -22,6 +24,11 @@ + + + Utility.* + + @@ -69,46 +76,53 @@ - - - - - + + - - + + - - + + - - - - - + + + - - + + - - + + + + + + + + + + + + + + - - + + @@ -156,10 +170,6 @@ @@ -276,6 +290,52 @@ - + @@ -468,19 +532,19 @@ - + - - + - - + - - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -929,11 +993,13 @@ + + @@ -949,7 +1015,6 @@ - @@ -985,7 +1050,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1364,30 +1403,64 @@ + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java index b7219888..0effa32d 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java @@ -41,19 +41,22 @@ public class ESeriesResistanceRow { CalcVarNumerical.RoundingTypes roundingType, Integer numberToRoundTo) { + // Keeps track of what column of the grid pane we are currently inserting at + Integer currColumnCount = 0; + this.name = name; this.eSeries = eSeries; // Create label Label resistanceSeriesLabel = new Label(eSeries.name()); - variableGridPane.add(resistanceSeriesLabel, 0, rowToAddTo); + variableGridPane.add(resistanceSeriesLabel, currColumnCount++, rowToAddTo); //=============== CLOSEST RESISTANCE ============// // "Closest Resistance" TextField TextField closestResistanceTextField = new TextField(); closestResistanceTextField.setAlignment(Pos.CENTER_RIGHT); - variableGridPane.add(closestResistanceTextField, 1, rowToAddTo); + variableGridPane.add(closestResistanceTextField, currColumnCount++, rowToAddTo); // Calculator variable closestResistance = new CalcVarNumericalOutput(); @@ -75,7 +78,7 @@ public class ESeriesResistanceRow { new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), }); closestResistance.setRounding(roundingType, numberToRoundTo); - closestResistance.setHelpText("The closest resistance in the E6 series to your desired resistance."); + closestResistance.setHelpText("The closest resistance in the " + name + " series to your desired resistance."); closestResistance.setIsEngineeringNotationEnabled(true); //========== VALIDATORS ===========// @@ -85,19 +88,18 @@ public class ESeriesResistanceRow { calcVars.add(closestResistance); // Ohm symbol - Label ohmSymbol = new Label("Ω"); - variableGridPane.add(ohmSymbol, 2, rowToAddTo); + variableGridPane.add(new Label("Ω"), currColumnCount++, rowToAddTo); //=============== CLOSEST RESISTANCE ERROR ============// // "Closest Resistance" TextField TextField closestResistanceErrorTextField = new TextField(); closestResistanceErrorTextField.setAlignment(Pos.CENTER_RIGHT); - variableGridPane.add(closestResistanceErrorTextField, 3, rowToAddTo); + variableGridPane.add(closestResistanceErrorTextField, currColumnCount++, rowToAddTo); // Calculator variable closestResistanceErrorCalcVar = new CalcVarNumericalOutput(); - closestResistanceErrorCalcVar.setName("e6Error"); + closestResistanceErrorCalcVar.setName("seriesError"); closestResistanceErrorCalcVar.setValueTextField(closestResistanceErrorTextField); closestResistanceErrorCalcVar.setEquationFunction(() -> { // Read in variables @@ -117,7 +119,7 @@ public class ESeriesResistanceRow { new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), }); closestResistanceErrorCalcVar.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); - closestResistanceErrorCalcVar.setHelpText("The percentage difference between the closest E6 series resistance and your desired resistance."); + closestResistanceErrorCalcVar.setHelpText("The percentage difference between the closest " + name + " series resistance and your desired resistance."); closestResistanceErrorCalcVar.setIsEngineeringNotationEnabled(true); //========== VALIDATORS ===========// @@ -127,8 +129,46 @@ public class ESeriesResistanceRow { calcVars.add(closestResistanceErrorCalcVar); // Percentage symbol - Label percentSymbol = new Label("%"); - variableGridPane.add(percentSymbol, 4, rowToAddTo); + variableGridPane.add(new Label("%"), currColumnCount++, rowToAddTo); + + //============================== CLOSEST HIGHER RESISTANCE ==============================// + + // "Closest Resistance" TextField + TextField closestHigherResistanceTextField = new TextField(); + closestHigherResistanceTextField.setAlignment(Pos.CENTER_RIGHT); + variableGridPane.add(closestHigherResistanceTextField, currColumnCount++, rowToAddTo); + + // Calculator variable + closestResistance = new CalcVarNumericalOutput(); + closestResistance.setName("closestHigherResistance"); + closestResistance.setValueTextField(closestHigherResistanceTextField); + closestResistance.setEquationFunction(() -> { + // Read in variables + Double desiredResistanceValue = desiredResistance.getRawVal(); + + if (Double.isNaN(desiredResistanceValue)) { + return Double.NaN; + } + + double actualResistance = StandardResistanceFinder.Find(desiredResistanceValue, eSeries); + + return actualResistance; + }); + closestResistance.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), + }); + closestResistance.setRounding(roundingType, numberToRoundTo); + closestResistance.setHelpText("The closest resistance in the " + name + " series to your desired resistance."); + closestResistance.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + closestResistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + calcVars.add(closestResistance); + + // Ohm symbol + variableGridPane.add(new Label("Ω"), currColumnCount++, rowToAddTo); } diff --git a/src/Utility/StandardResistanceFinder.java b/src/Utility/StandardResistanceFinder.java index 793d53d3..f40e86b9 100644 --- a/src/Utility/StandardResistanceFinder.java +++ b/src/Utility/StandardResistanceFinder.java @@ -1,6 +1,7 @@ package Utility; import java.math.BigDecimal; +import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Arrays; @@ -12,7 +13,7 @@ * * @author gbmhunter (www.mbedded.ninja) * @since 2016-02-15 - * @last-modified 2016-04-23 + * @last-modified 2016-05-14 */ public class StandardResistanceFinder { @@ -28,6 +29,15 @@ public enum eSeriesOptions { E192, } + /** + * The applicable search methods for the Find() method. + */ + public enum searchMethods { + CLOSEST, + CLOSEST_EQUAL_OR_HIGHER, + CLOSEST_EQUAL_OR_LOWER + } + private static ArrayList e6 = new ArrayList<>(); private static ArrayList e12 = new ArrayList<>(); private static ArrayList e24 = new ArrayList<>(); @@ -89,14 +99,18 @@ public enum eSeriesOptions { //e192 = BuildResArray(192); } + + + /** * Use to find the closest E-series resistance to your desired resistance. * * @param desiredResistance The desired resistance to search for. If this is 0.0, then method also returns 0.0. * @param eSeries The E-Series to use. - * @return The closest E-series resistance to desiredResistance. + * @param searchMethod The desired search method to use. + * @return The closest (or closest higher, closest lower) E-series resistance to desiredResistance. */ - public static double Find(double desiredResistance, eSeriesOptions eSeries) { + public static double Find(double desiredResistance, eSeriesOptions eSeries, searchMethods searchMethod) { //System.out.println("StandardResistanceFinder::Find() called with desiredResistance = " + desiredResistance + "and eSeries = " + eSeries.toString()); @@ -145,7 +159,8 @@ else if(eSeries == eSeriesOptions.E192) Integer order = FindOrder(desiredResistance) - 2; Double scaledDesRes = ScaleWrtOrder(desiredResistance, order); System.out.println("Scaled resistance = " + scaledDesRes); - Double closestScaledResistance = FindClosestMatch(scaledDesRes, selectedRange); + + Double closestScaledResistance = FindClosestMatch(scaledDesRes, selectedRange, searchMethod); System.out.println("Closest scaled (between 1-10) resistance = " + closestScaledResistance); BigDecimal closestScaledResistanceBD = new BigDecimal(closestScaledResistance); @@ -162,6 +177,19 @@ else if(eSeries == eSeriesOptions.E192) } + /** + * A simplification of the Find() method which can be used to find the closest E-series resistance to your desired resistance. + * The base Find() method allows the user to specify whether the found value has to be higher or lower than the desired resistance. + * + * @param desiredResistance The desired resistance to search for. If this is 0.0, then method also returns 0.0. + * @param eSeries The E-Series to use. + * @return The closest E-series resistance to desiredResistance. + */ + public static double Find(double desiredResistance, eSeriesOptions eSeries) { + return Find(desiredResistance, eSeries, searchMethods.CLOSEST); + } + + /** * Use to build an array of E-series values based on the number of elements provided. * @param numElements The number of elements PER DECADE you want to have. Typical values for this @@ -215,46 +243,86 @@ private static double ScaleWrtOrder(Double desRes, Integer order) /** * Finds the closest array entry (in terms of percentage difference) to the provided value. * For computational efficiency, this function assumes array values are sorted from smallest to highest - * @param val The value to look for in array. - * @param array The array of values to compare with val. + * @param val The value to look for in array. + * @param array The array of values to compare with val. + * @param searchMethod Places restrictions on what is a valid result. * @return The closest array entry (in terms of percentage difference). */ - private static double FindClosestMatch(Double val, ArrayList array) + private static double FindClosestMatch(Double val, ArrayList array, searchMethods searchMethod) { Integer i = 0; - // Iterate through array until we hit the first element which is bigger than the value we are - // trying to find. - // NOTE: Start of 2nd element of array! - i = 1; - while(true) - { - if(array.get(i) > val) break; + switch(searchMethod) { + case CLOSEST: + + // Iterate through array until we hit the first element which is bigger than the value we are + // trying to find. + // NOTE: Start of 2nd element of array! + i = 1; + while(true) + { + if(array.get(i) > val) break; + + if(i == array.size() - 1) break; + + i++; + } + + // At this point either: + // 1) We have stopped somewhere in the middle of the array. val will be higher than array[i-1] + // and lower than array[i]. We need to find which one is closer (based on percentage difference) + // 2) We have stopped either on the second or last element of the array. If it is the second, val will + // be closest to array[i-1], if it is the last, val will be closest to array[i]. + + System.out.println("Stopped when i = " + i); + System.out.println("Closest value 1 = " + array.get(i-1)); + System.out.println("Closest value 2 = " + array.get(i)); + + Double lowerPercDiff = ((val - array.get(i-1))/array.get(i-1))*100.0; + System.out.println("Percentage diff 1 = " + lowerPercDiff); + Double higherPercDiff = ((val - array.get(i))/array.get(i))*100.0; + System.out.println("Percentage diff 2 = " + higherPercDiff); + + if(Math.abs(lowerPercDiff) < Math.abs(higherPercDiff)) + return array.get(i-1); + else + return array.get(i); + + case CLOSEST_EQUAL_OR_LOWER: + + // First make sure there is a lower value in the array + if(array.get(0) > val) { + throw new InvalidParameterException("StandardResistanceFinder.Find() called with searchMethod = CLOSEST_EQUAL_OR_LOWER, but there way no value in the array lower than the provided value of " + val.toString()); + } + + i = 1; + while(i < array.size()) { + if(array.get(i) > val) { + // We have found the first value in the array which is bigger than the value, so the closest smaller value must of been the value before this + return array.get(i-1); + } + i++; + } + break; + + case CLOSEST_EQUAL_OR_HIGHER: + + i = 0; + while(i < array.size()) { + if(array.get(i) >= val) { + // We have found the first value in the array which is bigger than the value, so the closest smaller value must of been the value before this + return array.get(i); + } + i++; + } + + // Special case here where the first larger number is the first number of the next series + throw new InvalidParameterException("StandardResistanceFinder.Find() called with searchMethod = CLOSEST_EQUAL_OR_HIGHER, but there was no value in the array which was equal of higher than the provided value of " + val.toString()); - if(i == array.size() - 1) break; - - i++; } - // At this point either: - // 1) We have stopped somewhere in the middle of the array. val will be higher than array[i-1] - // and lower than array[i]. We need to find which one is closer (based on percentage difference) - // 2) We have stopped either on the second or last element of the array. If it is the second, val will - // be closest to array[i-1], if it is the last, val will be closest to array[i]. - - System.out.println("Stopped when i = " + i); - System.out.println("Closest value 1 = " + array.get(i-1)); - System.out.println("Closest value 2 = " + array.get(i)); - - Double lowerPercDiff = ((val - array.get(i-1))/array.get(i-1))*100.0; - System.out.println("Percentage diff 1 = " + lowerPercDiff); - Double higherPercDiff = ((val - array.get(i))/array.get(i))*100.0; - System.out.println("Percentage diff 2 = " + higherPercDiff); - - if(Math.abs(lowerPercDiff) < Math.abs(higherPercDiff)) - return array.get(i-1); - else - return array.get(i); + throw new RuntimeException("Code reached invalid place. Case must not of been handled correctly in switch statement."); + } } diff --git a/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java b/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java index ae0f08c0..39cbcc7f 100644 --- a/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java +++ b/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java @@ -19,18 +19,18 @@ public void start(Stage stage) { stage.show(); } - @Test - public void e12SeriesTest10k0() { - standardResistanceFinderModel.desiredResistance.setRawVal(10.1); - assertEquals("10", standardResistanceFinderModel.e12Resistance.getDispValAsString()); - assertEquals("0.99", standardResistanceFinderModel.e12Error.getDispValAsString()); - } - - @Test - public void e96SeriesTest246k() { - standardResistanceFinderModel.desiredResistance.setRawVal(246); - assertEquals("249", standardResistanceFinderModel.e96Resistance.getDispValAsString()); - assertEquals("1.22", standardResistanceFinderModel.e96Error.getDispValAsString()); - } +// @Test +// public void e12SeriesTest10k0() { +// standardResistanceFinderModel.desiredResistance.setRawVal(10.1); +// assertEquals("10", standardResistanceFinderModel.e12Resistance.getDispValAsString()); +// assertEquals("0.99", standardResistanceFinderModel.e12Error.getDispValAsString()); +// } +// +// @Test +// public void e96SeriesTest246k() { +// standardResistanceFinderModel.desiredResistance.setRawVal(246); +// assertEquals("249", standardResistanceFinderModel.e96Resistance.getDispValAsString()); +// assertEquals("1.22", standardResistanceFinderModel.e96Error.getDispValAsString()); +// } } \ No newline at end of file diff --git a/test/Utility/MetrixPrefixesTests.java b/test/Utility/MetrixPrefixesTests.java index a0c6c020..8f76c187 100644 --- a/test/Utility/MetrixPrefixesTests.java +++ b/test/Utility/MetrixPrefixesTests.java @@ -9,9 +9,9 @@ /** * Unit tests for the MetricPrefixes utility class. * - * @author Geoffrey Hunter - * @since 2015-03-25 - * @last-modified 2015-03-25 + * @author Geoffrey Hunter (www.mbedded.ninja) + * @since 2015-03-25 + * @last-modified 2016-05-14 */ public class MetrixPrefixesTests { diff --git a/test/Utility/RoundingTests.java b/test/Utility/RoundingTests.java index 27103fad..5af8f472 100644 --- a/test/Utility/RoundingTests.java +++ b/test/Utility/RoundingTests.java @@ -9,9 +9,9 @@ /** * Unit tests for the Rounding utility class. * - * @author Geoffrey Hunter - * @since 2015-03-26 - * @last-modified 2015-03-26 + * @author Geoffrey Hunter (mbedded.ninja) + * @since 2015-03-26 + * @last-modified 2016-05-14 */ public class RoundingTests { diff --git a/test/Utility/StandardResistanceFinderTests.java b/test/Utility/StandardResistanceFinderTests.java new file mode 100644 index 00000000..af9e89a6 --- /dev/null +++ b/test/Utility/StandardResistanceFinderTests.java @@ -0,0 +1,42 @@ +package Utility; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Unit tests for the StandardResistanceFinder utility class. + * + * @author Geoffrey Hunter (mbedded.ninja) + * @since 2016-05-14 + * @last-modified 2016-05-14 + */ +public class StandardResistanceFinderTests { + + @Test + public void e6ClosestValueTests() { + assertEquals(1.0, StandardResistanceFinder.Find(1.0, StandardResistanceFinder.eSeriesOptions.E6), 0.01); + assertEquals(10.0, StandardResistanceFinder.Find(11.0, StandardResistanceFinder.eSeriesOptions.E6), 0.01); + assertEquals(15.0, StandardResistanceFinder.Find(13.0, StandardResistanceFinder.eSeriesOptions.E6), 0.01); + assertEquals(680.0, StandardResistanceFinder.Find(800.0, StandardResistanceFinder.eSeriesOptions.E6), 0.01); + assertEquals(1000.0, StandardResistanceFinder.Find(900.0, StandardResistanceFinder.eSeriesOptions.E6), 0.01); + } + + @Test + public void e6ClosestLowerValueTests() { + assertEquals(1.0, StandardResistanceFinder.Find(1.4, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_LOWER), 0.01); + assertEquals(100.0, StandardResistanceFinder.Find(101.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_LOWER), 0.01); + assertEquals(100.0, StandardResistanceFinder.Find(149.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_LOWER), 0.01); + assertEquals(150.0, StandardResistanceFinder.Find(150.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_LOWER), 0.01); + assertEquals(150.0, StandardResistanceFinder.Find(219.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_LOWER), 0.01); + assertEquals(680.0, StandardResistanceFinder.Find(999.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_LOWER), 0.01); + } + + @Test + public void e6ClosestHigherValueTests() { + assertEquals(100.0, StandardResistanceFinder.Find(100.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_HIGHER), 0.01); + assertEquals(150.0, StandardResistanceFinder.Find(101.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_HIGHER), 0.01); + assertEquals(1000.0, StandardResistanceFinder.Find(900.0, StandardResistanceFinder.eSeriesOptions.E6, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_HIGHER), 0.01); + } + +} From 88b776353fd849f8ffeca6ca26d50687090ce3ff Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sat, 14 May 2016 19:34:21 +1200 Subject: [PATCH 10/16] Finished adding ability to display closest higher value and closest lower value on the standard resistor finder, closes #120. --- .idea/workspace.xml | 163 ++++++++--------- changelog.md | 1 + .../ESeriesResistanceRow.java | 168 +++++++++++++++--- .../StandardResistanceFinderView.fxml | 35 +++- 4 files changed, 251 insertions(+), 116 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d7651874..1ccb3d99 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,11 +7,9 @@ + - - - - + @@ -76,41 +74,37 @@ - - - - - - - + + + + - - - - - - + + - - - - - - + + + + + + + + + - + - - + + @@ -121,8 +115,8 @@ - - + + @@ -130,16 +124,6 @@ - - - - - - - - - - @@ -208,19 +192,19 @@ @@ -510,7 +494,7 @@ - + @@ -1328,21 +1312,6 @@ - - - - - - - - - - - - - - - @@ -1392,17 +1361,6 @@ - - - - - - - - - - - @@ -1413,16 +1371,6 @@ - - - - - - - - - - @@ -1431,14 +1379,6 @@ - - - - - - - - @@ -1449,22 +1389,67 @@ - + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/changelog.md b/changelog.md index 9efcfc5d..dda8b24f 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ vX.X.X - Disabled metric prefixes for IPC-2152 calculator variables, closes #118. - Fixed info section of "Via Current" calculator, closes #112. +- Added ability to display closest higher value and closest lower value on the standard resistor finder, closes #120. v1.2.0 ------ diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java index 0effa32d..7fa5e9af 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java @@ -28,8 +28,13 @@ public class ESeriesResistanceRow { CalcVarNumericalOutput closestResistance; CalcVarNumericalOutput closestResistanceErrorCalcVar; - CalcVarNumericalOutput closestHigherResistance; - CalcVarNumericalOutput closestLowerResistance; + CalcVarNumericalOutput closestEqualOrLowerResistanceCalcVar; + CalcVarNumericalOutput closestEqualOrLowerResistanceErrorCalcVar; + + CalcVarNumericalOutput closestEqualOrHigherResistanceCalcVar; + CalcVarNumericalOutput closestEqualOrHigherResistanceErrorCalcVar; + + CalcVarNumericalOutput closestEqualOrHigherResistance; ESeriesResistanceRow( String name, @@ -92,7 +97,7 @@ public class ESeriesResistanceRow { //=============== CLOSEST RESISTANCE ERROR ============// - // "Closest Resistance" TextField + // "Closest Resistance Error" TextField TextField closestResistanceErrorTextField = new TextField(); closestResistanceErrorTextField.setAlignment(Pos.CENTER_RIGHT); variableGridPane.add(closestResistanceErrorTextField, currColumnCount++, rowToAddTo); @@ -123,26 +128,26 @@ public class ESeriesResistanceRow { closestResistanceErrorCalcVar.setIsEngineeringNotationEnabled(true); //========== VALIDATORS ===========// - closestResistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - closestResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + closestResistanceErrorCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestResistanceErrorCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); calcVars.add(closestResistanceErrorCalcVar); // Percentage symbol variableGridPane.add(new Label("%"), currColumnCount++, rowToAddTo); - //============================== CLOSEST HIGHER RESISTANCE ==============================// + //============================== CLOSEST EQUAL OR LOWER RESISTANCE ==============================// // "Closest Resistance" TextField - TextField closestHigherResistanceTextField = new TextField(); - closestHigherResistanceTextField.setAlignment(Pos.CENTER_RIGHT); - variableGridPane.add(closestHigherResistanceTextField, currColumnCount++, rowToAddTo); + TextField closestEqualOrLowerResistanceTextField = new TextField(); + closestEqualOrLowerResistanceTextField.setAlignment(Pos.CENTER_RIGHT); + variableGridPane.add(closestEqualOrLowerResistanceTextField, currColumnCount++, rowToAddTo); // Calculator variable - closestResistance = new CalcVarNumericalOutput(); - closestResistance.setName("closestHigherResistance"); - closestResistance.setValueTextField(closestHigherResistanceTextField); - closestResistance.setEquationFunction(() -> { + closestEqualOrLowerResistanceCalcVar = new CalcVarNumericalOutput(); + closestEqualOrLowerResistanceCalcVar.setName("closestHigherResistance"); + closestEqualOrLowerResistanceCalcVar.setValueTextField(closestEqualOrLowerResistanceTextField); + closestEqualOrLowerResistanceCalcVar.setEquationFunction(() -> { // Read in variables Double desiredResistanceValue = desiredResistance.getRawVal(); @@ -150,27 +155,148 @@ public class ESeriesResistanceRow { return Double.NaN; } - double actualResistance = StandardResistanceFinder.Find(desiredResistanceValue, eSeries); + double actualResistance = StandardResistanceFinder.Find(desiredResistanceValue, eSeries, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_HIGHER); return actualResistance; }); - closestResistance.setUnits(new NumberUnitMultiplier[]{ + closestEqualOrLowerResistanceCalcVar.setUnits(new NumberUnitMultiplier[]{ new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), }); - closestResistance.setRounding(roundingType, numberToRoundTo); - closestResistance.setHelpText("The closest resistance in the " + name + " series to your desired resistance."); - closestResistance.setIsEngineeringNotationEnabled(true); + closestEqualOrLowerResistanceCalcVar.setRounding(roundingType, numberToRoundTo); + closestEqualOrLowerResistanceCalcVar.setHelpText("The closest equal or higher resistance in the " + name + " series to your desired resistance."); + closestEqualOrLowerResistanceCalcVar.setIsEngineeringNotationEnabled(true); //========== VALIDATORS ===========// - closestResistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - closestResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + closestEqualOrLowerResistanceCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestEqualOrLowerResistanceCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - calcVars.add(closestResistance); + calcVars.add(closestEqualOrLowerResistanceCalcVar); + + // Ohm symbol + variableGridPane.add(new Label("Ω"), currColumnCount++, rowToAddTo); + + //============================== CLOSEST EQUAL OR LOWER RESISTANCE ERROR ==============================// + + // "Closest Equal Or Lower Resistance Error" TextField + TextField closestEqualOrLowerResistanceErrorTextField = new TextField(); + closestEqualOrLowerResistanceErrorTextField.setAlignment(Pos.CENTER_RIGHT); + variableGridPane.add(closestEqualOrLowerResistanceErrorTextField, currColumnCount++, rowToAddTo); + + // Calculator variable + closestEqualOrLowerResistanceErrorCalcVar = new CalcVarNumericalOutput(); + closestEqualOrLowerResistanceErrorCalcVar.setName("equalOrLowerResistanceError"); + closestEqualOrLowerResistanceErrorCalcVar.setValueTextField(closestEqualOrLowerResistanceErrorTextField); + closestEqualOrLowerResistanceErrorCalcVar.setEquationFunction(() -> { + // Read in variables + Double desiredResistanceValue = desiredResistance.getRawVal(); + Double closestEqualOrLowerResistanceValue = closestEqualOrLowerResistanceCalcVar.getRawVal(); + + if (Double.isNaN(desiredResistanceValue)) { + return Double.NaN; + } + + // Calculate percentage difference + double percentageDiff = (Math.abs(closestEqualOrLowerResistanceValue - desiredResistanceValue) / desiredResistanceValue) * 100.0; + + return percentageDiff; + }); + closestEqualOrLowerResistanceErrorCalcVar.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), + }); + closestEqualOrLowerResistanceErrorCalcVar.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); + closestEqualOrLowerResistanceErrorCalcVar.setHelpText("The percentage difference between the closest equal or lower " + name + " series resistance and your desired resistance."); + closestEqualOrLowerResistanceErrorCalcVar.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + closestEqualOrLowerResistanceErrorCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestEqualOrLowerResistanceErrorCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + calcVars.add(closestEqualOrLowerResistanceErrorCalcVar); + + // Percentage symbol + variableGridPane.add(new Label("%"), currColumnCount++, rowToAddTo); + + //============================== CLOSEST EQUAL OR HIGHER RESISTANCE ==============================// + + // "Closest Resistance" TextField + TextField closestEqualOrHigherResistanceTextField = new TextField(); + closestEqualOrHigherResistanceTextField.setAlignment(Pos.CENTER_RIGHT); + variableGridPane.add(closestEqualOrHigherResistanceTextField, currColumnCount++, rowToAddTo); + + // Calculator variable + closestEqualOrHigherResistanceCalcVar = new CalcVarNumericalOutput(); + closestEqualOrHigherResistanceCalcVar.setName("closestHigherResistance"); + closestEqualOrHigherResistanceCalcVar.setValueTextField(closestEqualOrHigherResistanceTextField); + closestEqualOrHigherResistanceCalcVar.setEquationFunction(() -> { + // Read in variables + Double desiredResistanceValue = desiredResistance.getRawVal(); + + if (Double.isNaN(desiredResistanceValue)) { + return Double.NaN; + } + + double actualResistance = StandardResistanceFinder.Find(desiredResistanceValue, eSeries, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_HIGHER); + + return actualResistance; + }); + closestEqualOrHigherResistanceCalcVar.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), + }); + closestEqualOrHigherResistanceCalcVar.setRounding(roundingType, numberToRoundTo); + closestEqualOrHigherResistanceCalcVar.setHelpText("The closest equal or higher resistance in the " + name + " series to your desired resistance."); + closestEqualOrHigherResistanceCalcVar.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + closestEqualOrHigherResistanceCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestEqualOrHigherResistanceCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + calcVars.add(closestEqualOrHigherResistanceCalcVar); // Ohm symbol variableGridPane.add(new Label("Ω"), currColumnCount++, rowToAddTo); + //============================== CLOSEST EQUAL OR HIGHER RESISTANCE ERROR ==============================// + + // "Closest Equal Or Lower Resistance Error" TextField + TextField closestEqualOrHigherResistanceErrorTextField = new TextField(); + closestEqualOrHigherResistanceErrorTextField.setAlignment(Pos.CENTER_RIGHT); + variableGridPane.add(closestEqualOrHigherResistanceErrorTextField, currColumnCount++, rowToAddTo); + // Calculator variable + closestEqualOrHigherResistanceErrorCalcVar = new CalcVarNumericalOutput(); + closestEqualOrHigherResistanceErrorCalcVar.setName("equalOrHigherResistanceError"); + closestEqualOrHigherResistanceErrorCalcVar.setValueTextField(closestEqualOrHigherResistanceErrorTextField); + closestEqualOrHigherResistanceErrorCalcVar.setEquationFunction(() -> { + // Read in variables + Double desiredResistanceValue = desiredResistance.getRawVal(); + Double closestEqualOrHigherResistanceValue = closestEqualOrHigherResistanceCalcVar.getRawVal(); + + if (Double.isNaN(desiredResistanceValue)) { + return Double.NaN; + } + + // Calculate percentage difference + double percentageDiff = (Math.abs(closestEqualOrHigherResistanceValue - desiredResistanceValue) / desiredResistanceValue) * 100.0; + + return percentageDiff; + }); + closestEqualOrHigherResistanceErrorCalcVar.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), + }); + closestEqualOrHigherResistanceErrorCalcVar.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); + closestEqualOrHigherResistanceErrorCalcVar.setHelpText("The percentage difference between the closest equal or higher " + name + " series resistance and your desired resistance."); + closestEqualOrHigherResistanceErrorCalcVar.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + closestEqualOrHigherResistanceErrorCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + closestEqualOrHigherResistanceErrorCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + + calcVars.add(closestEqualOrHigherResistanceErrorCalcVar); + + // Percentage symbol + variableGridPane.add(new Label("%"), currColumnCount++, rowToAddTo); + + } diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml index ae4e68c9..b87edc9a 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml @@ -18,6 +18,7 @@ + @@ -43,19 +44,41 @@ + + + + - - - - + + + + + + + + + + + + + + + - - + + + + + + + + + From 9528f43e60de66ad2f9094e66ddd993bebcaa686 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sat, 14 May 2016 21:35:07 +1200 Subject: [PATCH 11/16] Fixed bug where initial values for calculator variables were not "NaN" (see Standard Resistance Finder calculator for example), closes #117. --- .idea/workspace.xml | 545 ++++++++----- changelog.md | 1 + .../StandardResistanceFinderCalcModel.java | 302 +++++++ ... => StandardResistanceFinderCalcView.fxml} | 0 .../StandardResistanceFinderModel.java | 740 ------------------ src/Core/CalcVar/CalcVarNumerical.java | 176 +---- src/Main.java | 5 +- .../MetricPrefixes/MetricPrefixes.java | 17 +- .../MetricPrefixes/RoundingMethods.java | 4 +- .../StandardResistanceFinderModelTest.java | 21 +- .../MetrixPrefixesTests.java | 4 +- 11 files changed, 686 insertions(+), 1129 deletions(-) create mode 100644 src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcModel.java rename src/Calculators/Electronics/Basic/StandardResistanceFinder/{StandardResistanceFinderView.fxml => StandardResistanceFinderCalcView.fxml} (100%) delete mode 100644 src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java rename test/Utility/{ => MetricPrefixes}/MetrixPrefixesTests.java (95%) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1ccb3d99..8b149279 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,9 +7,16 @@ + + + + - - + + + + + @@ -74,14 +81,33 @@ - - - - + + + + + + + + + + + + + - - + + + + + + + + + + + + @@ -91,8 +117,8 @@ - - + + @@ -100,11 +126,11 @@ - - + + - - + + @@ -112,18 +138,66 @@ - - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -154,9 +228,6 @@ @@ -292,6 +366,28 @@ - - + + + + + - + - @@ -527,9 +650,9 @@ - + - @@ -554,8 +677,8 @@ - + - @@ -580,7 +703,7 @@ - + - - - - - - + + + + + - - - - - + + + + + @@ -930,11 +1053,11 @@ - - + + - - + + @@ -948,17 +1071,17 @@ - - + + - - + + - - + + - - + + @@ -976,7 +1099,7 @@ - + @@ -988,7 +1111,7 @@ - + @@ -1017,24 +1140,24 @@ file://$PROJECT_DIR$/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java - 32 + 29 - file://$PROJECT_DIR$/test/Utility/MetrixPrefixesTests.java - 59 + file://$PROJECT_DIR$/src/Main.java + 154 - - file://$PROJECT_DIR$/src/Main.java - 155 + file://$PROJECT_DIR$/test/Utility/MetricPrefixes/MetrixPrefixesTests.java + 61 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1149,6 +1223,7 @@ + @@ -1156,6 +1231,7 @@ + @@ -1170,6 +1246,7 @@ + @@ -1216,13 +1293,7 @@ - - - - - - - + @@ -1268,13 +1339,6 @@ - - - - - - - @@ -1282,14 +1346,6 @@ - - - - - - - - @@ -1316,6 +1372,9 @@ + + + @@ -1343,6 +1402,7 @@ + @@ -1350,86 +1410,181 @@ + - + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + - + - - + + + + + + + + + + + + - - + + - + - - + + - + - - + + - + - - + + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + - - + + @@ -1437,8 +1592,8 @@ - - + + diff --git a/changelog.md b/changelog.md index dda8b24f..d55694b0 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ vX.X.X - Disabled metric prefixes for IPC-2152 calculator variables, closes #118. - Fixed info section of "Via Current" calculator, closes #112. - Added ability to display closest higher value and closest lower value on the standard resistor finder, closes #120. +- Fixed bug where initial values for calculator variables were not "NaN" (see Standard Resistance Finder calculator for example), closes #117. v1.2.0 ------ diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcModel.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcModel.java new file mode 100644 index 00000000..b8cab38a --- /dev/null +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcModel.java @@ -0,0 +1,302 @@ + +package Calculators.Electronics.Basic.StandardResistanceFinder; + +// SYSTEM INCLUDES + +import Core.CalcVar.CalcVarNumerical; +import Core.CalcVar.CalcVarNumericalInput; +import Core.CalcVar.CalcVarNumericalOutput; +import Utility.StandardResistanceFinder; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.web.WebEngine; +import javafx.scene.web.WebView; +import javafx.concurrent.Worker.State; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.events.Event; +import org.w3c.dom.events.EventListener; +import org.w3c.dom.events.EventTarget; +import org.w3c.dom.html.HTMLAnchorElement; + +import java.awt.*; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; + +// USER INCLUDES + +import Core.*; + +/** + * Calculator for finding a E-series resistance (standard resistance, preferred value) which is closest to the user's + * desired resistance. + * + * Lists closest resistance and percentage error in each EIA E series from E6 to E192. + * + * @author gbmhunter (www.mbedded.ninja) + * @last-modified 2016-05-01 + * @since 2013-09-17 + */ +public class StandardResistanceFinderCalcModel extends Calculator { + + //===============================================================================================// + //========================================= FXML Bindings =======================================// + //===============================================================================================// + + @FXML + private WebView infoWebView; + + @FXML + private TextField desiredResistanceValue; + + @FXML + private TextField e6ResistanceValue; + @FXML + private TextField e6ErrorValue; + @FXML + private TextField e12ResistanceValue; + @FXML + private TextField e12ErrorValue; + @FXML + private TextField e24ResistanceValue; + @FXML + private TextField e24ErrorValue; + @FXML + private TextField e48ResistanceValue; + @FXML + private TextField e48ErrorValue; + @FXML + private TextField e96ResistanceValue; + @FXML + private TextField e96ErrorValue; + @FXML + private TextField e192ResistanceValue; + @FXML + private TextField e192ErrorValue; + + @FXML + private GridPane variableGridPane; + + //===============================================================================================// + //====================================== CALCULATOR VARIABLES ===================================// + //===============================================================================================// + + public CalcVarNumericalInput desiredResistance = new CalcVarNumericalInput(); + public CalcVarNumericalOutput e6Resistance = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e6Error = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e12Resistance = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e12Error = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e24Resistance = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e24Error = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e48Resistance = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e48Error = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e96Resistance = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e96Error = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e192Resistance = new CalcVarNumericalOutput(); + public CalcVarNumericalOutput e192Error = new CalcVarNumericalOutput(); + + private class GridPaneRow { + String resistanceSeries; + CalcVarNumericalOutput closestResistance; + CalcVarNumericalOutput closesResistanceError; + CalcVarNumericalOutput closestHigherResistance; + CalcVarNumericalOutput closestHigherResistanceError; + CalcVarNumericalOutput closestLowerResistance; + CalcVarNumericalOutput closestLowerResistanceError; + } + + public ArrayList gridPaneRows = new ArrayList<>(); + + //===============================================================================================// + //=========================================== CONSTRUCTOR =======================================// + //===============================================================================================// + + public StandardResistanceFinderCalcModel() { + + super("Standard Resistance Finder", + "Find the closest E-series (e.g. E12, E96) resistor (preferred value) to your desired resistance.", + new String[]{"Electronics", "Basic"}, + new String[]{"ohm", "resistor", "resistance", "e", "series", "standard", "preferred", "values", "e6", "e12", "e24", "e48", "e96", "e128"}); + + super.setIconImagePath(getClass().getResource("grid-icon.png")); + + //===============================================================================================// + //======================================== LOAD .FXML FILE ======================================// + //===============================================================================================// + + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("StandardResistanceFinderCalcView.fxml")); + //fxmlLoader.setRoot(this.view); + fxmlLoader.setController(this); + try { + // Create a UI node from the FXML file, and save it to the view variable. + // This will be used by the main window to create a new instance of this calculator when + // the "Open" button is clicked. + this.view = fxmlLoader.load(); + } catch (IOException exception) { + throw new RuntimeException(exception); + } + + //===============================================================================================// + //================================ LOAD WEB VIEW FOR INFO SECTION ===============================// + //===============================================================================================// + + WebEngine engine = this.infoWebView.getEngine(); + final String htmlFile = "info.html"; + URL url = getClass().getResource(htmlFile); + + engine.getLoadWorker().stateProperty().addListener( + new ChangeListener() { + public void changed(ObservableValue ov, State oldState, State newState) { + if (newState == State.SUCCEEDED) { + //stage.setTitle(engine.getLocation()); + + NodeList nodeList = engine.getDocument().getElementsByTagName("a"); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + EventTarget eventTarget = (EventTarget) node; + eventTarget.addEventListener("click", new EventListener() { + @Override + public void handleEvent(Event evt) { + EventTarget target = evt.getCurrentTarget(); + HTMLAnchorElement anchorElement = (HTMLAnchorElement) target; + String href = anchorElement.getHref(); + //handle opening URL outside JavaFX WebView + Desktop d = Desktop.getDesktop(); + + try { + URI uriToBrowseTo = new URI(href); + d.browse(uriToBrowseTo); + } catch (URISyntaxException e) { + System.err.println("URI had incorrect syntax."); + } catch (IOException e) { + System.err.println("An IOException occurred while trying to open link in system browser.."); + } + + System.out.println(href); + evt.preventDefault(); + } + }, false); + } + + + } + } + }); + + engine.load(url.toExternalForm()); + + //===============================================================================================// + //================================== DESIRED RESISTANCE (input) =================================// + //===============================================================================================// + + this.desiredResistance.setName("desiredResistance"); + this.desiredResistance.setValueTextField(this.desiredResistanceValue); + this.desiredResistance.setUnits(new NumberUnitMultiplier[]{ + new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), + }); + this.desiredResistance.setNumDigitsToRound(4); + this.desiredResistance.setHelpText("The resistance you actually want. The closest value to this resistance will be found in each resistor series."); + this.desiredResistance.setIsEngineeringNotationEnabled(true); + + //========== VALIDATORS ===========// + this.desiredResistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); + this.desiredResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + this.desiredResistance.addValidator( + new Validator(() -> { + return ((this.desiredResistance.getRawVal() < 1.0 || this.desiredResistance.getRawVal() > 10.0e6) ? CalcValidationLevels.Warning : CalcValidationLevels.Ok); + }, + "The desired resistance is outside the \"normal\" purchasable resistance range of 1Ω to 10MΩ. Some or all of the standard E-series may not have a resistor available with the desired resistance.")); + + this.calcVars.add(this.desiredResistance); + + + //===============================================================================================// + //======================================= E-SERIES RESISTANCES ==================================// + //===============================================================================================// + + // This variable keeps track of what row we are up to when inserting E-series resistances + Integer gridRowCount = 0; + // First row is a header + gridRowCount++; + + ESeriesResistanceRow e6ResistanceRow = new ESeriesResistanceRow( + "E6", + StandardResistanceFinder.eSeriesOptions.E6, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 2); + + ESeriesResistanceRow e12ResistanceRow = new ESeriesResistanceRow( + "E12", + StandardResistanceFinder.eSeriesOptions.E12, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 2); + + ESeriesResistanceRow e24ResistanceRow = new ESeriesResistanceRow( + "E24", + StandardResistanceFinder.eSeriesOptions.E24, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 2); + + ESeriesResistanceRow e48ResistanceRow = new ESeriesResistanceRow( + "E48", + StandardResistanceFinder.eSeriesOptions.E48, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 3); + + ESeriesResistanceRow e96ResistanceRow = new ESeriesResistanceRow( + "E96", + StandardResistanceFinder.eSeriesOptions.E96, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 3); + + ESeriesResistanceRow e192ResistanceRow = new ESeriesResistanceRow( + "E192", + StandardResistanceFinder.eSeriesOptions.E192, + desiredResistance, + variableGridPane, + gridRowCount++, + calcVars, + CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, + 3); + + //===============================================================================================// + //============================================== FINAL ==========================================// + //===============================================================================================// + + this.findDependenciesAndDependants(); + this.refreshDirectionsAndUpdateUI(); + this.recalculateAllOutputs(); + this.validateAllVariables(); + + } + +} + diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcView.fxml similarity index 100% rename from src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderView.fxml rename to src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcView.fxml diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java deleted file mode 100644 index 4807db25..00000000 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModel.java +++ /dev/null @@ -1,740 +0,0 @@ - -package Calculators.Electronics.Basic.StandardResistanceFinder; - -// SYSTEM INCLUDES - -import Core.CalcVar.CalcVarNumerical; -import Core.CalcVar.CalcVarNumericalInput; -import Core.CalcVar.CalcVarNumericalOutput; -import Utility.StandardResistanceFinder; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.scene.control.Label; -import javafx.scene.control.TextField; -import javafx.scene.layout.GridPane; -import javafx.scene.web.WebEngine; -import javafx.scene.web.WebView; -import javafx.concurrent.Worker.State; - -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; -import org.w3c.dom.html.HTMLAnchorElement; - -import java.awt.*; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; - -// USER INCLUDES - -import Core.*; - -/** - * Calculator for finding a E-series resistance (standard resistance, preferred value) which is closest to the user's - * desired resistance. - * - * Lists closest resistance and percentage error in each EIA E series from E6 to E192. - * - * @author gbmhunter (www.mbedded.ninja) - * @last-modified 2016-05-01 - * @since 2013-09-17 - */ -public class StandardResistanceFinderModel extends Calculator { - - //===============================================================================================// - //========================================= FXML Bindings =======================================// - //===============================================================================================// - - @FXML - private WebView infoWebView; - - @FXML - private TextField desiredResistanceValue; - - @FXML - private TextField e6ResistanceValue; - @FXML - private TextField e6ErrorValue; - @FXML - private TextField e12ResistanceValue; - @FXML - private TextField e12ErrorValue; - @FXML - private TextField e24ResistanceValue; - @FXML - private TextField e24ErrorValue; - @FXML - private TextField e48ResistanceValue; - @FXML - private TextField e48ErrorValue; - @FXML - private TextField e96ResistanceValue; - @FXML - private TextField e96ErrorValue; - @FXML - private TextField e192ResistanceValue; - @FXML - private TextField e192ErrorValue; - - @FXML - private GridPane variableGridPane; - - //===============================================================================================// - //====================================== CALCULATOR VARIABLES ===================================// - //===============================================================================================// - - public CalcVarNumericalInput desiredResistance = new CalcVarNumericalInput(); - public CalcVarNumericalOutput e6Resistance = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e6Error = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e12Resistance = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e12Error = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e24Resistance = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e24Error = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e48Resistance = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e48Error = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e96Resistance = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e96Error = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e192Resistance = new CalcVarNumericalOutput(); - public CalcVarNumericalOutput e192Error = new CalcVarNumericalOutput(); - - private class GridPaneRow { - String resistanceSeries; - CalcVarNumericalOutput closestResistance; - CalcVarNumericalOutput closesResistanceError; - CalcVarNumericalOutput closestHigherResistance; - CalcVarNumericalOutput closestHigherResistanceError; - CalcVarNumericalOutput closestLowerResistance; - CalcVarNumericalOutput closestLowerResistanceError; - } - - public ArrayList gridPaneRows = new ArrayList<>(); - - //===============================================================================================// - //=========================================== CONSTRUCTOR =======================================// - //===============================================================================================// - - public StandardResistanceFinderModel() { - - super("Standard Resistance Finder", - "Find the closest E-series (e.g. E12, E96) resistor (preferred value) to your desired resistance.", - new String[]{"Electronics", "Basic"}, - new String[]{"ohm", "resistor", "resistance", "e", "series", "standard", "preferred", "values", "e6", "e12", "e24", "e48", "e96", "e128"}); - - super.setIconImagePath(getClass().getResource("grid-icon.png")); - - //===============================================================================================// - //======================================== LOAD .FXML FILE ======================================// - //===============================================================================================// - - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("StandardResistanceFinderView.fxml")); - //fxmlLoader.setRoot(this.view); - fxmlLoader.setController(this); - try { - // Create a UI node from the FXML file, and save it to the view variable. - // This will be used by the main window to create a new instance of this calculator when - // the "Open" button is clicked. - this.view = fxmlLoader.load(); - } catch (IOException exception) { - throw new RuntimeException(exception); - } - - //===============================================================================================// - //================================ LOAD WEB VIEW FOR INFO SECTION ===============================// - //===============================================================================================// - - WebEngine engine = this.infoWebView.getEngine(); - final String htmlFile = "info.html"; - URL url = getClass().getResource(htmlFile); - - engine.getLoadWorker().stateProperty().addListener( - new ChangeListener() { - public void changed(ObservableValue ov, State oldState, State newState) { - if (newState == State.SUCCEEDED) { - //stage.setTitle(engine.getLocation()); - - NodeList nodeList = engine.getDocument().getElementsByTagName("a"); - for (int i = 0; i < nodeList.getLength(); i++) { - Node node = nodeList.item(i); - EventTarget eventTarget = (EventTarget) node; - eventTarget.addEventListener("click", new EventListener() { - @Override - public void handleEvent(Event evt) { - EventTarget target = evt.getCurrentTarget(); - HTMLAnchorElement anchorElement = (HTMLAnchorElement) target; - String href = anchorElement.getHref(); - //handle opening URL outside JavaFX WebView - Desktop d = Desktop.getDesktop(); - - try { - URI uriToBrowseTo = new URI(href); - d.browse(uriToBrowseTo); - } catch (URISyntaxException e) { - System.err.println("URI had incorrect syntax."); - } catch (IOException e) { - System.err.println("An IOException occurred while trying to open link in system browser.."); - } - - System.out.println(href); - evt.preventDefault(); - } - }, false); - } - - - } - } - }); - - engine.load(url.toExternalForm()); - - //===============================================================================================// - //================================== DESIRED RESISTANCE (input) =================================// - //===============================================================================================// - - this.desiredResistance.setName("desiredResistance"); - this.desiredResistance.setValueTextField(this.desiredResistanceValue); - this.desiredResistance.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - this.desiredResistance.setNumDigitsToRound(4); - this.desiredResistance.setHelpText("The resistance you actually want. The closest value to this resistance will be found in each resistor series."); - this.desiredResistance.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - this.desiredResistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - this.desiredResistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - this.desiredResistance.addValidator( - new Validator(() -> { - return ((this.desiredResistance.getRawVal() < 1.0 || this.desiredResistance.getRawVal() > 10.0e6) ? CalcValidationLevels.Warning : CalcValidationLevels.Ok); - }, - "The desired resistance is outside the \"normal\" purchasable resistance range of 1Ω to 10MΩ. Some or all of the standard E-series may not have a resistor available with the desired resistance.")); - - this.calcVars.add(this.desiredResistance); - - - //===============================================================================================// - //======================================= E6 RESISTANCE (output) ================================// - //===============================================================================================// - -// this.e6Resistance.setName("e6Resistance"); -// this.e6Resistance.setValueTextField(this.e6ResistanceValue); -// this.e6Resistance.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E6); -// -// return actualResistance; -// }); -// this.e6Resistance.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), -// }); -// this.e6Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); -// this.e6Resistance.setHelpText("The closest resistance in the E6 series to your desired resistance."); -// this.e6Resistance.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e6Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// this.e6Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e6Resistance); - - //===============================================================================================// - //================================= E6 PERCENTAGE DIFFERENCE (output) ===========================// - //===============================================================================================// - -// this.e6Error.setName("e6Error"); -// this.e6Error.setValueTextField(this.e6ErrorValue); -// this.e6Error.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// Double closestStandardResistance = this.e6Resistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// // Calculate percentage difference -// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; -// -// return percentageDiff; -// }); -// this.e6Error.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), -// }); -// this.e6Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); -// this.e6Error.setHelpText("The percentage difference between the closest E6 series resistance and your desired resistance."); -// this.e6Error.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e6Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e6Error); - -// //===============================================================================================// -// //======================================= E12 RESISTANCE (output) ================================// -// //===============================================================================================// -// -// this.e12Resistance.setName("e12Resistance"); -// this.e12Resistance.setValueTextField(this.e12ResistanceValue); -// this.e12Resistance.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E12); -// -// return actualResistance; -// }); -// this.e12Resistance.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), -// }); -// this.e12Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); -// this.e12Resistance.setHelpText("The closest resistance in the E12 series to your desired resistance."); -// this.e12Resistance.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e12Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// this.e12Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e12Resistance); -// -// //===============================================================================================// -// //====================================== E12 ERROR (output) =====================================// -// //===============================================================================================// -// -// this.e12Error.setName("e12Error"); -// this.e12Error.setValueTextField(this.e12ErrorValue); -// this.e12Error.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// Double closestStandardResistance = this.e12Resistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// // Calculate percentage difference -// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; -// -// return percentageDiff; -// }); -// this.e12Error.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), -// }); -// this.e12Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); -// this.e12Error.setHelpText("The percentage difference between the closest E12 series resistance and your desired resistance."); -// this.e12Error.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e12Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e12Error); -// -// //===============================================================================================// -// //======================================= E24 RESISTANCE (output) ================================// -// //===============================================================================================// -// -// this.e24Resistance.setName("e24Resistance"); -// this.e24Resistance.setValueTextField(this.e24ResistanceValue); -// this.e24Resistance.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E24); -// -// return actualResistance; -// }); -// this.e24Resistance.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), -// }); -// this.e24Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); -// this.e24Resistance.setHelpText("The closest resistance in the E24 series to your desired resistance."); -// this.e24Resistance.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e24Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// this.e24Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e24Resistance); -// -// //===============================================================================================// -// //================================= E24 PERCENTAGE DIFFERENCE (output) ==========================// -// //===============================================================================================// -// -// this.e24Error.setName("e24Error"); -// this.e24Error.setValueTextField(this.e24ErrorValue); -// this.e24Error.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// Double closestStandardResistance = this.e24Resistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// // Calculate percentage difference -// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; -// -// return percentageDiff; -// }); -// this.e24Error.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), -// }); -// this.e24Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); -// this.e24Error.setHelpText("The percentage difference between the closest E24 series resistance and your desired resistance."); -// this.e24Error.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e24Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e24Error); -// -// //===============================================================================================// -// //======================================= E48 RESISTANCE (output) ================================// -// //===============================================================================================// -// -// this.e48Resistance.setName("e48Resistance"); -// this.e48Resistance.setValueTextField(this.e48ResistanceValue); -// this.e48Resistance.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E48); -// -// return actualResistance; -// }); -// this.e48Resistance.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), -// }); -// this.e48Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); -// this.e48Resistance.setHelpText("The closest resistance in the E48 series to your desired resistance."); -// this.e48Resistance.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e48Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// this.e48Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e48Resistance); -// -// //===============================================================================================// -// //======================================= E48 ERROR (output) ===================================// -// //===============================================================================================// -// -// this.e48Error.setName("e48Error"); -// this.e48Error.setValueTextField(this.e48ErrorValue); -// this.e48Error.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// Double closestStandardResistance = this.e48Resistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// // Calculate percentage difference -// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; -// -// return percentageDiff; -// }); -// this.e48Error.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), -// }); -// this.e48Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); -// this.e48Error.setHelpText("The percentage difference between the closest E48 series resistance and your desired resistance."); -// this.e48Error.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e48Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e48Error); -// -// //===============================================================================================// -// //======================================= E96 RESISTANCE (output) ===============================// -// //===============================================================================================// -// -// this.e96Resistance.setName("e96Resistance"); -// this.e96Resistance.setValueTextField(this.e96ResistanceValue); -// this.e96Resistance.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E96); -// -// return actualResistance; -// }); -// this.e96Resistance.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), -// }); -// this.e96Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); -// this.e96Resistance.setHelpText("The closest resistance in the E96 series to your desired resistance."); -// this.e96Resistance.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e96Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// this.e96Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e96Resistance); -// -// //===============================================================================================// -// //================================= E96 PERCENTAGE DIFFERENCE (output) ==========================// -// //===============================================================================================// -// -// this.e96Error.setName("e96Error"); -// this.e96Error.setValueTextField(this.e96ErrorValue); -// this.e96Error.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// Double closestStandardResistance = this.e96Resistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// // Calculate percentage difference -// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; -// -// return percentageDiff; -// }); -// this.e96Error.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), -// }); -// this.e96Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); -// this.e96Error.setHelpText("The percentage difference between the closest E96 series resistance and your desired resistance."); -// this.e96Error.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e96Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e96Error); -// -// //===============================================================================================// -// //===================================== E192 RESISTANCE (output) ================================// -// //===============================================================================================// -// -// this.e192Resistance.setName("e192Resistance"); -// this.e192Resistance.setValueTextField(this.e192ResistanceValue); -// this.e192Resistance.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E192); -// -// return actualResistance; -// }); -// this.e192Resistance.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), -// }); -// this.e192Resistance.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 3); -// this.e192Resistance.setHelpText("The closest resistance in the E192 series to your desired resistance."); -// this.e192Resistance.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e192Resistance.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// this.e192Resistance.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e192Resistance); -// -// //===============================================================================================// -// //================================= E192 PERCENTAGE DIFFERENCE (output) ==========================// -// //===============================================================================================// -// -// this.e192Error.setName("e192Error"); -// this.e192Error.setValueTextField(this.e192ErrorValue); -// this.e192Error.setEquationFunction(() -> { -// // Read in variables -// Double desiredResistance = this.desiredResistance.getRawVal(); -// Double closestStandardResistance = this.e192Resistance.getRawVal(); -// -// if (Double.isNaN(desiredResistance)) { -// return Double.NaN; -// } -// -// // Calculate percentage difference -// double percentageDiff = (Math.abs(closestStandardResistance - desiredResistance) / desiredResistance) * 100.0; -// -// return percentageDiff; -// }); -// this.e192Error.setUnits(new NumberUnitMultiplier[]{ -// new NumberUnitMultiplier("%", 1e0, NumberPreference.DEFAULT), -// }); -// this.e192Error.setRounding(CalcVarNumerical.RoundingTypes.DECIMAL_PLACES, 2); -// this.e192Error.setHelpText("The percentage difference between the closest E192 series resistance and your desired resistance."); -// this.e192Error.setIsEngineeringNotationEnabled(true); -// -// //========== VALIDATORS ===========// -// this.e192Error.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); -// -// this.calcVars.add(this.e192Error); - - //===============================================================================================// - //========================================== ARRAY METHOD =======================================// - //===============================================================================================// - - // This variable keeps track of what row we are up to when inserting E-series resistances - Integer gridRowCount = 0; - // First row is a header - gridRowCount++; - - ESeriesResistanceRow e6ResistanceRow = new ESeriesResistanceRow( - "E6", - StandardResistanceFinder.eSeriesOptions.E6, - desiredResistance, - variableGridPane, - gridRowCount++, - calcVars, - CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, - 2); - - ESeriesResistanceRow e12ResistanceRow = new ESeriesResistanceRow( - "E12", - StandardResistanceFinder.eSeriesOptions.E12, - desiredResistance, - variableGridPane, - gridRowCount++, - calcVars, - CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, - 2); - - ESeriesResistanceRow e24ResistanceRow = new ESeriesResistanceRow( - "E24", - StandardResistanceFinder.eSeriesOptions.E24, - desiredResistance, - variableGridPane, - gridRowCount++, - calcVars, - CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, - 2); - - ESeriesResistanceRow e48ResistanceRow = new ESeriesResistanceRow( - "E48", - StandardResistanceFinder.eSeriesOptions.E48, - desiredResistance, - variableGridPane, - gridRowCount++, - calcVars, - CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, - 3); - - ESeriesResistanceRow e96ResistanceRow = new ESeriesResistanceRow( - "E96", - StandardResistanceFinder.eSeriesOptions.E96, - desiredResistance, - variableGridPane, - gridRowCount++, - calcVars, - CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, - 3); - - ESeriesResistanceRow e192ResistanceRow = new ESeriesResistanceRow( - "E192", - StandardResistanceFinder.eSeriesOptions.E192, - desiredResistance, - variableGridPane, - gridRowCount++, - calcVars, - CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, - 3); - - //===============================================================================================// - //============================================== FINAL ==========================================// - //===============================================================================================// - - this.findDependenciesAndDependants(); - this.refreshDirectionsAndUpdateUI(); - this.recalculateAllOutputs(); - this.validateAllVariables(); - - } - -/* - private void buildCalculator(ArrayList gridPaneRowList) { - for(int x = 0; x < gridPaneRowList.size(); x++) { - // Create label - Label resistanceSeriesLabel = new Label(gridPaneRowList.get(x).resistanceSeries); - this.variableGridPane.add(resistanceSeriesLabel, 0, x + 1); - - //=============== CLOSEST RESISTANCE ============// - - // "Closest Resistance" TextField - TextField closestResistanceTextField = new TextField(); - this.variableGridPane.add(closestResistanceTextField, 1, x + 1); - - // Calculator variable - CalcVarNumericalOutput closestResistanceCalcVar = new CalcVarNumericalOutput(); - closestResistanceCalcVar.setName("closestResistance"); - closestResistanceCalcVar.setValueTextField(closestResistanceTextField); - closestResistanceCalcVar.setEquationFunction(() -> { - // Read in variables - Double desiredResistance = this.desiredResistance.getRawVal(); - - if (Double.isNaN(desiredResistance)) { - return Double.NaN; - } - - double actualResistance = StandardResistanceFinder.Find(desiredResistance, StandardResistanceFinder.eSeriesOptions.E6); - - return actualResistance; - }); - closestResistanceCalcVar.setUnits(new NumberUnitMultiplier[]{ - new NumberUnitMultiplier("Ω", 1e0, NumberPreference.DEFAULT), - }); - closestResistanceCalcVar.setRounding(CalcVarNumerical.RoundingTypes.SIGNIFICANT_FIGURES, 2); - closestResistanceCalcVar.setHelpText("The closest resistance in the E6 series to your desired resistance."); - closestResistanceCalcVar.setIsEngineeringNotationEnabled(true); - - //========== VALIDATORS ===========// - closestResistanceCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - closestResistanceCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); - - this.calcVars.add(closestResistanceCalcVar); - - // Ohm symbol - Label ohmSymbol = new Label("Ω"); - this.variableGridPane.add(ohmSymbol, 2, x + 1); - - //=============== CLOSEST RESISTANCE ERROR ============// - - // "Closest Resistance" TextField - TextField closestResistanceErrorTextField = new TextField(); - this.variableGridPane.add(closestResistanceErrorTextField, 3, x + 1); - - // Ohm symbol - Label percentSymbol = new Label("%"); - this.variableGridPane.add(percentSymbol, 4, x + 1); - - } - }*/ - -} - diff --git a/src/Core/CalcVar/CalcVarNumerical.java b/src/Core/CalcVar/CalcVarNumerical.java index 089f2b24..91b8259b 100644 --- a/src/Core/CalcVar/CalcVarNumerical.java +++ b/src/Core/CalcVar/CalcVarNumerical.java @@ -155,179 +155,11 @@ public CalcVarNumerical() { this.valueTextField.setText(this.dispValAsString); }); - } - - /** - * Base constructor. Requires all possible arguments. - * @param name - * @param valueTextField The text field that displays this calculator variables value (UI element). - * @param unitsComboBox - * @param equation An expression tree of a function which calculates this variables value from the other variables. - * @param units An array of units for this calculator variable, to display in the units combobox. - * @param numDigitsToRound The number of significant figures you want the calculator variable rounded to, when it is an output. - * @param directionFunction - * @param defaultRawValue Default number for raw value to be set to. Can also be set to null, in which case the displayed text will be empty. - * @param helpText - */ - /*public CalcVarNumerical( - String name, - TextField valueTextField, - ComboBox unitsComboBox, - IEquationFunction equation, - NumberUnit[] units, - int numDigitsToRound, - IDirectionFunction directionFunction, - Double defaultRawValue, - String helpText) - { - - super(name, equation, directionFunction); - - //System.out.println("CalcVarNumerical constructor called."); - - //===============================================================================================// - //============================================== VALUE ==========================================// - //===============================================================================================// - - // Create text field listener - this.textListener = (observable, oldValue, newValue) -> { - this.valueTextFieldChanged(newValue); - }; - - // Make sure the provided text field is not null - if(valueTextField == null) - throw new IllegalArgumentException("Provided TextField for calculator variable \"" + name + "\" value was null. Is the @FXML binding name the same as the fx:id?"); - - this.valueTextField = valueTextField; - - // Attach this new listener to the text field - this.valueTextField.textProperty().addListener(textListener); - - // Engineering notation is disabled by default - this.isEngineeringNotationEnabled = false; - - //===============================================================================================// - //========================================== VALIDATORS =========================================// - //===============================================================================================// - - - // Initialise empty validators list - this.validators = new ArrayList(); - - // Initialise empty validation results list - this.validationResults = new ArrayList(); - - //===============================================================================================// - //====================================== UNITS AND UNITS COMBOBOX =====================================// - //===============================================================================================// - - // Save reference to the units combobox - this.unitsComboBox = unitsComboBox; - - // Initialise empty units list - this.units = FXCollections.observableArrayList(); - - // Internally save the units, and find the default unit at the same time - // Note we can't implictly convert from an array of NumberUnitMultiplier to a List - NumberUnit defaultUnit = null; - for(NumberUnit unit : units) { - this.units.add(unit); - if (unit.preference == NumberPreference.DEFAULT) { - defaultUnit = unit; - } - } - - // The combobox is allowed to be null, so only interact with it - // if combobox was provided - if(this.unitsComboBox != null) { - - // Bind the combo-box to the observable collection - this.unitsComboBox.setItems(this.units); - - //============ LET THE COMBOBOX KNOW HOW TO RENDER NUMBER UNITS ============// - - this.unitsComboBox.setCellFactory((combobox) -> { - - // Define rendering of the list of values in ComboBox drop down. - return new ListCell() { - @Override - protected void updateItem(NumberUnit item, boolean empty) { - super.updateItem(item, empty); - - if (item == null || empty) { - setText(null); - } else { - setText(item.name); - } - } - }; - }); - - // Define rendering of selected value shown in ComboBox. - this.unitsComboBox.setConverter(new StringConverter() { - @Override - public String toString(NumberUnit numberUnit) { - if (numberUnit == null) { - return null; - } else { - return numberUnit.name; - } - } - - @Override - public NumberUnit fromString(String numberUnitString) { - return null; // No conversion fromString needed. - } - }); - - // Connect up event handler for when combobox units change - this.unitsComboBox.setOnAction(this::unitsComboBoxSelectionChanged); - } // if(this.unitsComboBox != null) { + // Setting rawVal to NaN is important for getting the default state + // of the calculator correct + this.rawVal = Double.NaN; - - // Set current combobox selection to default unit - if (defaultUnit != null) { - this.setSelUnit(defaultUnit); - } - else { - this.setSelUnit(this.units.get(0)); - } - - //======================== ROUNDING =========================// - - // Set the default rounding type to use significant figures - this.roundingType = RoundingTypes.SIGNIFICANT_FIGURES; - this.numDigitsToRound = numDigitsToRound; - - // Assign the default raw value - if (defaultRawValue != null) { - this.rawVal = defaultRawValue; - //this.dispValAsString = String.valueOf( this.rawVal * this.selUnit.multiplier); - this.dispValAsString = String.valueOf(this.selUnit.convertFrom(this.rawVal)); - this.valueTextField.setText(this.dispValAsString); - } - else { - // Provided default value was null, so lets make - // the textbox empty - this.rawVal = Double.NaN; - //this.dispValAsNumber = Double.NaN; - this.valueTextField.setText(""); - } - - // Install event handlers - this.addRawValueChangedListener(calcVarBase -> { - // Update displayed value - //this.dispValAsNumber = this.rawVal * this.selUnit.multiplier; - //this.dispValAsString = String.valueOf(this.rawVal * this.selUnit.multiplier); - this.dispValAsString = String.valueOf(this.selUnit.convertFrom(this.rawVal)); - // Update textbox - this.valueTextField.setText(this.dispValAsString); - }); - - // Save the help text (displayed in the tooltip) - this.helpText = helpText; - - } // public CalcVarNumerical()*/ + } diff --git a/src/Main.java b/src/Main.java index 56915ef1..edb102f0 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,9 +1,9 @@ // SYSTEM IMPORTS +import Calculators.Electronics.Basic.StandardResistanceFinder.StandardResistanceFinderCalcModel; import Core.Calculator; import javafx.application.Application; -import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; @@ -13,7 +13,6 @@ // USER IMPORTS import MainWindow.MainWindowController; -import javafx.stage.WindowEvent; import java.io.*; import java.util.ArrayList; @@ -79,7 +78,7 @@ public void start(Stage primaryStage) throws Exception{ //========== BASIC ==========// controller.addCalculatorTemplate(new Calculators.Electronics.Basic.OhmsLaw.OhmsLawCalcModel()); controller.addCalculatorTemplate(new Calculators.Electronics.Basic.ResistorDivider.ResistorDividerCalcModel()); - controller.addCalculatorTemplate(new Calculators.Electronics.Basic.StandardResistanceFinder.StandardResistanceFinderModel()); + controller.addCalculatorTemplate(new StandardResistanceFinderCalcModel()); //========== FILTERS ==========// controller.addCalculatorTemplate(new Calculators.Electronics.Filters.LowPassRC.LowPassRCCalcModel()); diff --git a/src/Utility/MetricPrefixes/MetricPrefixes.java b/src/Utility/MetricPrefixes/MetricPrefixes.java index 21cad64e..52e4eeb5 100644 --- a/src/Utility/MetricPrefixes/MetricPrefixes.java +++ b/src/Utility/MetricPrefixes/MetricPrefixes.java @@ -9,9 +9,9 @@ /** * Utility class for converting numbers to strings with metric prefixes and back again. * - * @author gbmhunter - * @since 2016-03-26 - * @last-modified 2016-03-27 + * @author gbmhunter (www.mbedded.ninja) + * @since 2016-03-26 + * @last-modified 2016-05-14 */ public enum MetricPrefixes { yocto('y', 1e-24), @@ -129,6 +129,10 @@ private static String doubleToString(final double value) { public static String toSci( final double value ) { + + if(value == 0.0) + return "0.0"; + final long exponent = (long) Math.floor(Math.log10(Math.abs(value))); return doubleToString(value / Math.pow(10, exponent)) + 'E' + exponent; } @@ -266,9 +270,12 @@ public static String toEng( final int roundTo) { // Get the absolute value of the provided value - final double abs = Math.abs(value); + double abs = Math.abs(value); + + if(abs == 0.0) + return toSci(0.0); - // Search for the applicable multiplier + // Now that we know it is not exactly 0, search for the applicable multiplier double multiplier; for (final MetricPrefixes e : values()) { multiplier = e.getMultiplier(); diff --git a/src/Utility/MetricPrefixes/RoundingMethods.java b/src/Utility/MetricPrefixes/RoundingMethods.java index e8618722..4d24d753 100644 --- a/src/Utility/MetricPrefixes/RoundingMethods.java +++ b/src/Utility/MetricPrefixes/RoundingMethods.java @@ -1,7 +1,9 @@ package Utility.MetricPrefixes; /** - * Created by gbmhunter on 2016-03-27. + * @author gbmhunter (www.mbedded.ninja) + * @since 2016-03-26 + * @last-modified 2016-05-14 */ public enum RoundingMethods { DECIMAL_PLACES, diff --git a/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java b/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java index 39cbcc7f..173d59c1 100644 --- a/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java +++ b/test/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderModelTest.java @@ -2,35 +2,32 @@ import javafx.scene.Scene; import javafx.stage.Stage; -import org.junit.Test; import org.testfx.framework.junit.ApplicationTest; -import static org.junit.Assert.*; - public class StandardResistanceFinderModelTest extends ApplicationTest { - StandardResistanceFinderModel standardResistanceFinderModel; + StandardResistanceFinderCalcModel standardResistanceFinderCalcModel; @Override public void start(Stage stage) { - standardResistanceFinderModel = new StandardResistanceFinderModel(); - Scene scene = new Scene(standardResistanceFinderModel.view, 800, 600); + standardResistanceFinderCalcModel = new StandardResistanceFinderCalcModel(); + Scene scene = new Scene(standardResistanceFinderCalcModel.view, 800, 600); stage.setScene(scene); stage.show(); } // @Test // public void e12SeriesTest10k0() { -// standardResistanceFinderModel.desiredResistance.setRawVal(10.1); -// assertEquals("10", standardResistanceFinderModel.e12Resistance.getDispValAsString()); -// assertEquals("0.99", standardResistanceFinderModel.e12Error.getDispValAsString()); +// standardResistanceFinderCalcModel.desiredResistance.setRawVal(10.1); +// assertEquals("10", standardResistanceFinderCalcModel.e12Resistance.getDispValAsString()); +// assertEquals("0.99", standardResistanceFinderCalcModel.e12Error.getDispValAsString()); // } // // @Test // public void e96SeriesTest246k() { -// standardResistanceFinderModel.desiredResistance.setRawVal(246); -// assertEquals("249", standardResistanceFinderModel.e96Resistance.getDispValAsString()); -// assertEquals("1.22", standardResistanceFinderModel.e96Error.getDispValAsString()); +// standardResistanceFinderCalcModel.desiredResistance.setRawVal(246); +// assertEquals("249", standardResistanceFinderCalcModel.e96Resistance.getDispValAsString()); +// assertEquals("1.22", standardResistanceFinderCalcModel.e96Error.getDispValAsString()); // } } \ No newline at end of file diff --git a/test/Utility/MetrixPrefixesTests.java b/test/Utility/MetricPrefixes/MetrixPrefixesTests.java similarity index 95% rename from test/Utility/MetrixPrefixesTests.java rename to test/Utility/MetricPrefixes/MetrixPrefixesTests.java index 8f76c187..6b6d8df8 100644 --- a/test/Utility/MetrixPrefixesTests.java +++ b/test/Utility/MetricPrefixes/MetrixPrefixesTests.java @@ -1,4 +1,4 @@ -package Utility; +package Utility.MetricPrefixes; import Utility.MetricPrefixes.MetricPrefixes; import Utility.MetricPrefixes.RoundingMethods; @@ -59,6 +59,8 @@ public void roundingTests() { // Make sure no precision is lost numbers that have a large number of digits assertEquals("3.33", MetricPrefixes.toEng(10.0/3.0, RoundingMethods.DECIMAL_PLACES, 2)); + assertEquals("0.0", MetricPrefixes.toEng(0.0, RoundingMethods.SIGNIFICANT_FIGURES, 2)); + } //===========================================================================================// From 9ff37dba8a03004057e64252cbcb84c5f8a32a9e Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sat, 14 May 2016 22:06:18 +1200 Subject: [PATCH 12/16] Percentage error text field validators in the "Standard Resistance Calculator" now allow the number "0.0%". --- .idea/workspace.xml | 319 +++++------------- .../ESeriesResistanceRow.java | 8 +- src/Core/Validator.java | 22 +- 3 files changed, 107 insertions(+), 242 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8b149279..fbf86f4b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,16 +7,9 @@ - - - - - - - - - + + @@ -81,10 +74,23 @@ + + + + + + + + + + + + + - + @@ -113,12 +119,12 @@ - + - - + + @@ -129,8 +135,8 @@ - - + + @@ -138,6 +144,16 @@ + + + + + + + + + + @@ -171,33 +187,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -228,13 +217,11 @@ @@ -337,15 +326,13 @@ - - - - - - - - - - @@ -1430,17 +1267,6 @@ - - - - - - - - - - - @@ -1561,10 +1387,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -1573,7 +1431,7 @@ - + @@ -1581,30 +1439,17 @@ - + + + + - - + + - - - - - - - - - - - - - - - - diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java index 7fa5e9af..b2254b41 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/ESeriesResistanceRow.java @@ -129,7 +129,7 @@ public class ESeriesResistanceRow { //========== VALIDATORS ===========// closestResistanceErrorCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - closestResistanceErrorCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + closestResistanceErrorCalcVar.addValidator(Validator.IsGreaterOrEqualToZero(CalcValidationLevels.Error)); calcVars.add(closestResistanceErrorCalcVar); @@ -155,7 +155,7 @@ public class ESeriesResistanceRow { return Double.NaN; } - double actualResistance = StandardResistanceFinder.Find(desiredResistanceValue, eSeries, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_HIGHER); + double actualResistance = StandardResistanceFinder.Find(desiredResistanceValue, eSeries, StandardResistanceFinder.searchMethods.CLOSEST_EQUAL_OR_LOWER); return actualResistance; }); @@ -209,7 +209,7 @@ public class ESeriesResistanceRow { //========== VALIDATORS ===========// closestEqualOrLowerResistanceErrorCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - closestEqualOrLowerResistanceErrorCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + closestEqualOrLowerResistanceErrorCalcVar.addValidator(Validator.IsGreaterOrEqualToZero(CalcValidationLevels.Error)); calcVars.add(closestEqualOrLowerResistanceErrorCalcVar); @@ -289,7 +289,7 @@ public class ESeriesResistanceRow { //========== VALIDATORS ===========// closestEqualOrHigherResistanceErrorCalcVar.addValidator(Validator.IsNumber(CalcValidationLevels.Error)); - closestEqualOrHigherResistanceErrorCalcVar.addValidator(Validator.IsGreaterThanZero(CalcValidationLevels.Error)); + closestEqualOrHigherResistanceErrorCalcVar.addValidator(Validator.IsGreaterOrEqualToZero(CalcValidationLevels.Error)); calcVars.add(closestEqualOrHigherResistanceErrorCalcVar); diff --git a/src/Core/Validator.java b/src/Core/Validator.java index 367f135a..126ddaf5 100644 --- a/src/Core/Validator.java +++ b/src/Core/Validator.java @@ -11,7 +11,7 @@ * * @author gbmhunter (www.mbedded.ninja) * @since 2015-11-02 - * @last-modified 2016-04-13 + * @last-modified 2016-05-14 */ public class Validator { @@ -131,4 +131,24 @@ public static Validator IsGreaterThanZero(CalcValidationLevel desiredValidationR }, "Value must be positive and not equal to 0."); } + + /** + * Factory function. Returns a validator which will give the provided validation result if the calculator variable is + * not greater or equal to 0. If the number is greater than 0, it will return "CalcValidationResults.Ok". + * + * @param desiredValidationResult The desired validation result if the calculator variable value is not greater or equal to 0. + * @return A validator which will give the desired validation result if the calculator variable is not greater or equal to 0. + */ + public static Validator IsGreaterOrEqualToZero(CalcValidationLevel desiredValidationResult) { + return new Validator( + (value) -> { + if (value < 0) { + return desiredValidationResult; + } + else { + return CalcValidationLevels.Ok; + } + }, + "Value must be positive and not equal to 0."); + } } From 9972df307feeaf50231de05da364ad67076fcc42 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sun, 15 May 2016 14:40:09 +1200 Subject: [PATCH 13/16] Fixed bug where splash screen remained in background after app has started, closes #116. --- .idea/workspace.xml | 132 ++++++++++++++++++++++++-------------------- NinjaCalc.iml | 9 +++ changelog.md | 1 + src/Main.java | 8 ++- 4 files changed, 88 insertions(+), 62 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fbf86f4b..20274386 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -8,8 +8,9 @@ - - + + + @@ -74,14 +75,24 @@ - + - - + + + + + + + + + + + + @@ -90,7 +101,7 @@ - + @@ -119,12 +130,12 @@ - + - - + + @@ -177,16 +188,6 @@ - - - - - - - - - - @@ -246,7 +247,6 @@ @@ -326,14 +327,6 @@ @@ -1461,7 +1471,7 @@ @@ -1520,7 +1530,7 @@ diff --git a/NinjaCalc.iml b/NinjaCalc.iml index c3ae4022..e36cee10 100644 --- a/NinjaCalc.iml +++ b/NinjaCalc.iml @@ -12,5 +12,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/changelog.md b/changelog.md index d55694b0..52129994 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ vX.X.X - Fixed info section of "Via Current" calculator, closes #112. - Added ability to display closest higher value and closest lower value on the standard resistor finder, closes #120. - Fixed bug where initial values for calculator variables were not "NaN" (see Standard Resistance Finder calculator for example), closes #117. +- Fixed bug where splash screen remained in background after app has started, closes #116. v1.2.0 ------ diff --git a/src/Main.java b/src/Main.java index edb102f0..6feaf881 100644 --- a/src/Main.java +++ b/src/Main.java @@ -22,7 +22,7 @@ * * @author gbmhunter (www.mbedded.ninja) * @since 2015-11-02 - * @last-modified 2016-04-25 + * @last-modified 2016-05-15 */ public class Main extends Application { @@ -53,6 +53,12 @@ public static void main(String[] args) { @Override public void start(Stage primaryStage) throws Exception{ + // Hide the install4j splash screen, as this is not done automatically as + // no AWT window is shown (we are using javafx instead) + // /resource/i4juntime.jar has to be added to the classpath + // to be able to call this. install4j automatically bundles the runtime with the application + com.install4j.api.launcher.SplashScreen.hide(); + FXMLLoader loader = new FXMLLoader(getClass().getResource("/MainWindow/MainWindowView.fxml")); Parent root = loader.load(); From d8339d9530d74083fb186bfc9b20eef90ff7bd16 Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sun, 15 May 2016 16:30:10 +1200 Subject: [PATCH 14/16] Added more info about creating an installable package to the README. Header row text in the Standard Resistance Finder calculator table is now bold. --- .idea/workspace.xml | 130 +++++++++--------- README.md | 22 +-- .../StandardResistanceFinderCalcView.fxml | 59 ++------ 3 files changed, 91 insertions(+), 120 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 20274386..278bfcfc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,10 +7,8 @@ - - - - + + @@ -75,14 +73,14 @@ - + - - + + @@ -130,12 +128,25 @@ - + - - + + + + + + + + + + + + + + + @@ -178,16 +189,6 @@ - - - - - - - - - - @@ -240,7 +241,6 @@ @@ -942,7 +943,7 @@ - + @@ -1118,21 +1119,6 @@ - - - - - - - - - - - - - - - @@ -1405,6 +1391,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1430,36 +1456,12 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/README.md b/README.md index 35f55a1f..d5d1628b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ See the [project home page](http://mbedded-ninja.github.io/NinjaCalc/) for a lis 1. Download the latest installer-based release from [http://mbedded-ninja.github.io/NinjaCalc/](http://mbedded-ninja.github.io/NinjaCalc/). 2. Run the installer and play (or work, right?)! +3. NinjaCalc should automatically inform you if there is a new version available on start-up of the application. Installing a newer version of NinjaCalc should automatically overwrite the old one. @@ -73,22 +74,23 @@ Myself (gbmhunter) currently holds the license for this software, and so I am th The install4j script is located at `/NinjaCalc.install4j`. -1. Open the `/NinjaCalc.install4j` file in "install4j Multi-Platform Edition". -2. Update the "Version" field as appropriate. -3. Click the "Build Project" button. -4. Wait until build completes. install4j should have created installer files for each supported platform (currently Windows and Mac OS), as well as an updates.xml file, in the `install` directory. -5. Overwrite the old `updates.xml` file in the repos root directory with the one that install4j created in the `install` directory. -6. Upload the installable packages to GitHub as a new release (if appropriate). -7. Push the repository changes to the master branch (updates.xml is the most important file to be updated). -8. Update the download button links on the homepage in the `gh-pages` branch of the repo to point to the new release files. +1. After code changes are complete, make sure the NinjaCalc.jar artifact has been built from within IntelliJ (`Build->Build Artifacts->NinjaCalc:jar->Build`). +2. Open the `/NinjaCalc.install4j` file in "install4j Multi-Platform Edition". +3. Update the "Version" field as appropriate. +4. Click the "Build Project" button. +5. Wait until build completes. install4j should have created installer files for each supported platform (currently Windows and Mac OS), as well as an updates.xml file, in the `install` directory. +6. Overwrite the old `updates.xml` file in the repos root directory with the one that install4j created in the `install` directory. +7. Upload the installable packages to GitHub as a new release (if appropriate). +8. Commit and push the repository changes to the master branch (updates.xml is the most important file to be updated). The "Git Flow" plugin for SourceTree can make this step easy. +9. Update the download button links on the homepage in the `gh-pages` branch of the repo to point to the new release files. # Debugging A Deployed App (Locally) -You can get the `System.out` and `System.err` streams by running the NinjaCalc.jar file from the commandline. For example, in Windows you would type at the command-line: +You can get the `System.out` and `System.err` streams by running the `NinjaCalc.jar` file from the commandline. For example, in Windows you would type at the command-line: -`C:\Program Files (x86)\NinjaCal\java -jar NinjaCalc.jar` +`C:\Program Files (x86)\NinjaCalc\java -jar NinjaCalc.jar` # File Structure diff --git a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcView.fxml b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcView.fxml index b87edc9a..58e4d3b3 100644 --- a/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcView.fxml +++ b/src/Calculators/Electronics/Basic/StandardResistanceFinder/StandardResistanceFinderCalcView.fxml @@ -69,52 +69,19 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + From e0a5807db7f00857927271688da41df83d1de51d Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sun, 15 May 2016 16:32:47 +1200 Subject: [PATCH 15/16] Preparing files for v1.2.1 release. --- .idea/workspace.xml | 138 ++++++++++++++------------------------------ NinjaCalc.install4j | 2 +- README.md | 4 +- changelog.md | 2 +- 4 files changed, 46 insertions(+), 100 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 278bfcfc..11a27bcd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,8 +7,9 @@ + - + @@ -73,67 +74,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + @@ -145,8 +91,8 @@ - - + + @@ -267,9 +213,9 @@ @@ -943,7 +889,7 @@