diff options
author | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-07-17 16:26:49 -0500 |
---|---|---|
committer | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-07-17 16:26:49 -0500 |
commit | a5f088ae43c285bc3708303bdcc99bd8936477d2 (patch) | |
tree | 8d3ac45478468fe772618aa6d44c4879152738b5 /docs | |
parent | cc79db65bc347c50267d0a719278ef1d90cf6b1a (diff) | |
parent | b76c06eb393c7c6d9a3ece66efec1fd20311b7e8 (diff) |
Merge branch 'release-0.4.0' into stable
Diffstat (limited to 'docs')
-rw-r--r-- | docs/design.org | 75 | ||||
-rw-r--r-- | docs/design.pdf | bin | 242954 -> 346620 bytes | |||
-rw-r--r-- | docs/design.tex | 145 | ||||
-rw-r--r-- | docs/diagrams/convert-expressions.plantuml.png | bin | 0 -> 36460 bytes | |||
-rw-r--r-- | docs/diagrams/convert-expressions.plantuml.txt | 22 | ||||
-rw-r--r-- | docs/diagrams/convert-units.plantuml.png | bin | 0 -> 28368 bytes | |||
-rw-r--r-- | docs/diagrams/convert-units.plantuml.txt | 19 | ||||
-rw-r--r-- | docs/diagrams/overview-diagram.plantuml.png | bin | 0 -> 11363 bytes | |||
-rw-r--r-- | docs/diagrams/overview-diagram.plantuml.txt | 20 | ||||
-rw-r--r-- | docs/manual.org | 13 | ||||
-rw-r--r-- | docs/manual.pdf | bin | 172013 -> 170946 bytes | |||
-rw-r--r-- | docs/manual.tex | 44 |
12 files changed, 288 insertions, 50 deletions
diff --git a/docs/design.org b/docs/design.org index be345f2..0e3a477 100644 --- a/docs/design.org +++ b/docs/design.org @@ -1,20 +1,53 @@ #+TITLE: 7Units Design Document -#+SUBTITLE: For version 0.3.1 -#+DATE: 2021 August 26 +#+SUBTITLE: For version 0.4.0 +#+DATE: 2022 July 8 #+LaTeX_HEADER: \usepackage[a4paper, lmargin=25mm, rmargin=25mm, tmargin=25mm, bmargin=25mm]{geometry} #+LaTeX_HEADER: \usepackage{xurl} #+LaTeX: \newpage * Introduction 7Units is a program that can convert between units. This document details the internal design of 7Units, intended to be used by current and future developers. - - The frontend code is currently subject to change, so it is not included in the current version of this document. +* System Overview + #+CAPTION: A big-picture diagram of 7Units, containing all of the major classes. + #+attr_latex: :height 144px + [[./diagrams/overview-diagram.plantuml.png]] +** Packages of 7Units + 7Units splits its code into three main packages: + - ~sevenUnits.unit~ :: The [[*Unit System Design][unit system]] + - ~sevenUnits.utils~ :: Extra classes that aid the unit system. + - ~sevenUnitsGUI~ :: The [[*Front-End Design][front end]] code + ~sevenUnits.unit~ depends on ~sevenUnits.utils~, while ~sevenUnitsGUI~ depends on both ~sevenUnits~ packages. There is only one class that isn't in any of these packages, ~sevenUnits.VersionInfo~. +** Major Classes of 7Units + - [[*Unit Classes][sevenUnits.unit.Unit]] :: The class representing a unit + - [[*The Unit Database][sevenUnits.unit.UnitDatabase]] :: A class that stores collections of units, prefixes and dimensions. + - [[*The View][sevenUnitsGUI.View]] :: The class that handles interaction between the user and the program. + - [[*The Presenter][sevenUnitsGUI.Presenter]] :: The class that handles communication between the ~View~ and the unit system. +#+LaTeX: \newpage +** Process of Unit Conversion + #+CAPTION: The process of converting units + [[./diagrams/convert-units.plantuml.png]] + 1. The ~View~ triggers a unit conversion method from the ~Presenter~. + 2. The ~Presenter~ gets raw input data from the ~View~'s public methods (from unit, to unit, from value). + 3. The ~Presenter~ uses the ~UnitDatabase~'s methods to convert the raw data from the ~View~ into actual units. + 4. The ~Presenter~ performs the unit conversion using the provided unit objects. + 5. The ~Presenter~ calls the ~View~'s methods to show the result of the conversion. +#+LaTeX: \newpage +** Process of Expression Conversion + The process of expression conversion is similar to that of unit conversion. + #+CAPTION: The process of converting expressions + [[./diagrams/convert-expressions.plantuml.png]] + 1. The ~View~ triggers a unit conversion method from the ~Presenter~. + 2. The ~Presenter~ gets raw input data from the ~View~'s public methods (unit conversion: from unit, to unit, from value; expression conversion: input expression, output expression). + 3. The ~Presenter~ uses the ~UnitDatabase~'s methods to parse the expressions, converting the input into a ~LinearUnitValue~ and the output into a ~Unit~. + 4. The ~Presenter~ converts the provided value into the provided unit. + 5. The ~Presenter~ calls the ~View~'s methods to show the result of the conversion. +#+LaTeX: \newpage * Unit System Design Any code related to the backend unit system is stored in the ~sevenUnits.unit~ package. Here is a class diagram of the system. Unimportant methods, methods inherited from Object, getters and setters have been omitted. - [[./diagrams/units-class-diagram.plantuml.png]] #+CAPTION: Class diagram of sevenUnits.unit + [[./diagrams/units-class-diagram.plantuml.png]] #+LaTeX: \newpage ** Dimensions Dimensions represent what a unit is measuring, such as length, time, or energy. Dimensions are represented as an [[*ObjectProduct][ObjectProduct]]<BaseDimension>, where ~BaseDimension~ is a very simple class (its only properties are a name and a symbol) which represents the dimension of a base unit; these base dimensions can be multiplied to create all other Dimensions. @@ -56,6 +89,38 @@ Dimension files are similar, only for dimensions instead of units and prefixes. #+LaTeX: \newpage +* Front-End Design + The front-end of 7Units is based on an MVP model. There are two major frontend classes, the *View* and the *Presenter*. +** The View + The ~View~ is the part of the frontend code that directly interacts with the user. It handles input and output, but does not do any processing. Processing is handled by the presenter and the backend code. + + The ~View~ is an interface, not a single class, so that I can easily create multiple views without having to rewrite any processing code. This allows me to easily prototype changes to the GUI without messing with existing code. + + In addition, I have decided to move some functions of the ~View~ into two subinterfaces, ~UnitConversionView~ and ~ExpressionConversionView~. This is because 7Units supports two kinds of unit conversion: unit conversion (select two compatible units, specify a value then convert) and expression conversion (enter two expressions and convert the first to a multiple of the second). Putting these functions into subinterfaces allows a ~View~ to do one type of conversion without forcing it to support the other. + + There are currently two implementations of the ~View~: + - TabbedView :: A Swing GUI implementation that uses tabs to separate the two types of conversion. The default GUI used by 7Units. + - ViewBot :: A simulated view that allows programs to set the output of its public methods (i.e. every getter in ~View~ has a setter in ~ViewBot~). Intended for testing, and is already used by ~PresenterTest~. + Both of these ~View~ implementations implement ~UnitConversionView~ and ~ExpressionConversionView~. +** The Presenter + The ~Presenter~ is an intermediary between the ~View~ and the backend code. It accepts the user's input and passes it to the backend, then accepts the backend's output and passes it to the frontend for user viewing. Its main functions do not have arguments or return values; instead it takes input from and provides output to the ~View~ via its public methods. +*** Rules + The ~Presenter~ has a set of function-object rules that determine some of its behaviours. Each corresponds to a setting in the ~View~, but they can be set to other values via the ~Presenter~'s setters (although nonstandard rules cannot be saved and loaded): + - numberDisplayRule :: A function that determines how numbers are displayed. This controls the rounding rules. + - prefixRepetitionRule :: A function that determines which combinations of prefixes are valid in unit expressions. This controls the unit prefix rules. + - searchRule :: A function that determines which prefixes are shown in the unit lists in unit conversion (which prefixed units are searchable). + + These rules have been made this way to enable an incredible level of customization of these behaviours. Because any function object with the correct arguments and return type is accepted, these rules (especially the number display rule) can do much more than the default behaviours. +** Utility Classes + The frontend has many miscellaneous utility classes. Many of them are package-private. Here is a list of them, with a brief description of what they do and where they are used: + - DefaultPrefixRepetitionRule :: An enum containing the available rules determining when you can repeat prefixes. Used by the ~TabbedView~ for selecting the rule and by the ~Presenter~ for loading it from a file. + - DelegateListModel :: A ~javax.swing.ListModel~ implementation that delegates all of its methods to a ~List~. Implements ~List~ by also delegating to the underlying list. Used by the ~SearchBoxList~ to create an easily mutable ~ListModel~. + - FilterComparator :: A ~Comparator~ that sorts objects according to whether or not they match a filter. Used by the ~SearchBoxList~ for item sorting. + - GridBagBuilder :: A convenience class for generating ~GridBagConstraints~ objects for Swing's ~GridBagLayout~. Used by ~TabbedView~ for constructing the GUI. + - SearchBoxList :: A Swing component that combines a text field and a ~JList~ to create a searchable list. Used by the ~TabbedView~'s unit conversion mode. + - StandardDisplayRules :: A static utility class that allows you to generate display/rounding rules. Used by ~TabbedView~ for generating these rules and ~Presenter~ for loading them from a file. + - UnitConversionRecord :: A record-like object that contains the results of a unit or expression conversion. Used by ~UnitConversionView~ and ~ExpressionConversionView~ for accepting the results to be displayed. +#+LaTeX: \newpage * Utility Classes 7Units has a few general "utility" classes. They aren't directly related to units, but are used in the units system. ** ObjectProduct diff --git a/docs/design.pdf b/docs/design.pdf Binary files differindex fd1f2f1..936928a 100644 --- a/docs/design.pdf +++ b/docs/design.pdf diff --git a/docs/design.tex b/docs/design.tex index 178a1c8..35d2004 100644 --- a/docs/design.tex +++ b/docs/design.tex @@ -1,4 +1,4 @@ -% Created 2021-08-26 Thu 11:25 +% Created 2022-07-17 Sun 16:22 % Intended LaTeX compiler: pdflatex \documentclass[11pt]{article} \usepackage[utf8]{inputenc} @@ -16,9 +16,9 @@ \usepackage{hyperref} \usepackage[a4paper, lmargin=25mm, rmargin=25mm, tmargin=25mm, bmargin=25mm]{geometry} \usepackage{xurl} -\date{2021 August 26} +\date{2022 July 8} \title{7Units Design Document\\\medskip -\large For version 0.3.1} +\large For version 0.4.0} \hypersetup{ pdfauthor={}, pdftitle={7Units Design Document}, @@ -34,25 +34,81 @@ \newpage \section{Introduction} -\label{sec:orgc81fddd} +\label{sec:orgb154108} 7Units is a program that can convert between units. This document details the internal design of 7Units, intended to be used by current and future developers. - -The frontend code is currently subject to change, so it is not included in the current version of this document. +\section{System Overview} +\label{sec:org064d7bc} +\begin{figure}[htbp] +\centering +\includegraphics[height=144px]{./diagrams/overview-diagram.plantuml.png} +\caption{A big-picture diagram of 7Units, containing all of the major classes.} +\end{figure} +\subsection{Packages of 7Units} +\label{sec:org8a6985b} +7Units splits its code into three main packages: +\begin{description} +\item[{\texttt{sevenUnits.unit}}] The \hyperref[sec:org76c2c26]{unit system} +\item[{\texttt{sevenUnits.utils}}] Extra classes that aid the unit system. +\item[{\texttt{sevenUnitsGUI}}] The \hyperref[sec:orgbb1d346]{front end} code +\end{description} +\texttt{sevenUnits.unit} depends on \texttt{sevenUnits.utils}, while \texttt{sevenUnitsGUI} depends on both \texttt{sevenUnits} packages. There is only one class that isn't in any of these packages, \texttt{sevenUnits.VersionInfo}. +\subsection{Major Classes of 7Units} +\label{sec:org031cf3b} +\begin{description} +\item[{\hyperref[sec:org195924f]{sevenUnits.unit.Unit}}] The class representing a unit +\item[{\hyperref[sec:org1a286b2]{sevenUnits.unit.UnitDatabase}}] A class that stores collections of units, prefixes and dimensions. +\item[{\hyperref[sec:orgae93ac0]{sevenUnitsGUI.View}}] The class that handles interaction between the user and the program. +\item[{\hyperref[sec:org76432e4]{sevenUnitsGUI.Presenter}}] The class that handles communication between the \texttt{View} and the unit system. +\end{description} +\newpage +\subsection{Process of Unit Conversion} +\label{sec:org0699189} +\begin{figure}[htbp] +\centering +\includegraphics[width=.9\linewidth]{./diagrams/convert-units.plantuml.png} +\caption{The process of converting units} +\end{figure} +\begin{enumerate} +\item The \texttt{View} triggers a unit conversion method from the \texttt{Presenter}. +\item The \texttt{Presenter} gets raw input data from the \texttt{View}'s public methods (from unit, to unit, from value). +\item The \texttt{Presenter} uses the \texttt{UnitDatabase}'s methods to convert the raw data from the \texttt{View} into actual units. +\item The \texttt{Presenter} performs the unit conversion using the provided unit objects. +\item The \texttt{Presenter} calls the \texttt{View}'s methods to show the result of the conversion. +\end{enumerate} +\newpage +\subsection{Process of Expression Conversion} +\label{sec:orgbdb2960} +The process of expression conversion is similar to that of unit conversion. +\begin{figure}[htbp] +\centering +\includegraphics[width=.9\linewidth]{./diagrams/convert-expressions.plantuml.png} +\caption{The process of converting expressions} +\end{figure} +\begin{enumerate} +\item The \texttt{View} triggers a unit conversion method from the \texttt{Presenter}. +\item The \texttt{Presenter} gets raw input data from the \texttt{View}'s public methods (unit conversion: from unit, to unit, from value; expression conversion: input expression, output expression). +\item The \texttt{Presenter} uses the \texttt{UnitDatabase}'s methods to parse the expressions, converting the input into a \texttt{LinearUnitValue} and the output into a \texttt{Unit}. +\item The \texttt{Presenter} converts the provided value into the provided unit. +\item The \texttt{Presenter} calls the \texttt{View}'s methods to show the result of the conversion. +\end{enumerate} +\newpage \section{Unit System Design} -\label{sec:org9d0655d} +\label{sec:org76c2c26} Any code related to the backend unit system is stored in the \texttt{sevenUnits.unit} package. Here is a class diagram of the system. Unimportant methods, methods inherited from Object, getters and setters have been omitted. -\begin{center} +\begin{figure}[htbp] +\centering \includegraphics[width=.9\linewidth]{./diagrams/units-class-diagram.plantuml.png} -\end{center} +\caption{Class diagram of sevenUnits.unit} +\end{figure} \newpage \subsection{Dimensions} -\label{sec:org1e98dda} -Dimensions represent what a unit is measuring, such as length, time, or energy. Dimensions are represented as an \hyperref[sec:orgc7c5740]{ObjectProduct}<BaseDimension>, where \texttt{BaseDimension} is a very simple class (its only properties are a name and a symbol) which represents the dimension of a base unit; these base dimensions can be multiplied to create all other Dimensions. +\label{sec:orgc8f3222} +Dimensions represent what a unit is measuring, such as length, time, or energy. Dimensions are represented as an \hyperref[sec:org07580ff]{ObjectProduct}<BaseDimension>, where \texttt{BaseDimension} is a very simple class (its only properties are a name and a symbol) which represents the dimension of a base unit; these base dimensions can be multiplied to create all other Dimensions. \subsection{Unit Classes} -\label{sec:orgd5ff0fb} -Units are internally represented by the abstract class \texttt{Unit}. All units have an \hyperref[sec:orgc7c5740]{ObjectProduct}<BaseUnit> (referred to as the base) that they are based on, a dimension (ObjectProduct<BaseDimension>), one or more names and a symbol (these last two bits of data are contained in the \texttt{NameSymbol} class). The dimension is calculated from the base unit when needed; the variable is just a cache. It has two constructors: a package-private one used to make \texttt{BaseUnit} instances, and a protected one used to make general units (for other subclasses of \texttt{Unit}). All unit classes are immutable. +\label{sec:org195924f} +Units are internally represented by the abstract class \texttt{Unit}. All units have an \hyperref[sec:org07580ff]{ObjectProduct}<BaseUnit> (referred to as the base) that they are based on, a dimension (ObjectProduct<BaseDimension>), one or more names and a symbol (these last two bits of data are contained in the \texttt{NameSymbol} class). The dimension is calculated from the base unit when needed; the variable is just a cache. It has two constructors: a package-private one used to make \texttt{BaseUnit} instances, and a protected one used to make general units (for other subclasses of \texttt{Unit}). All unit classes are immutable. Units also have two conversion functions - one which converts from a value expressed in this unit to its base unit, and another which converts from a value expressed in the base unit to this unit. In \texttt{Unit}, they are defined as two abstract methods. This allows you to convert from any unit to any other (as long as they have the same base, i.e. you aren't converting metres to pounds). To convert from A to B, first convert from A to its base, then convert from the base to B. @@ -77,36 +133,79 @@ There are a few more classes which play small roles in the unit system: \item[{USCustomary}] A static utility class with instances of common units in the US Customary system (not to be confused with the British Imperial system; it has the same unit names but the values of a few units are different). \end{description} \subsection{Prefixes} -\label{sec:org1aaa92c} +\label{sec:org1504786} A \texttt{UnitPrefix} is a simple object that can multiply a \texttt{LinearUnit} by a value. It can calculate a new name for the unit by combining its name and the unit's name (symbols are done similarly). It can do multiplication, division and exponentation with a number, as well as multiplication and division with another prefix; all of these work by changing the prefix's multiplier. \subsection{The Unit Database} -\label{sec:org7c6cf6d} +\label{sec:org1a286b2} The \texttt{UnitDatabase} class stores all of the unit, prefix and dimension data used by this program. It is not a representation of an actual database, just a class that stores lots of data. Units are stored using a custom \texttt{Map} implementation (\texttt{PrefixedUnitMap}) which maps unit names to units. It is backed by two maps: one for units (without prefixes) and one for prefixes. It is programmed to include prefixes (so if units includes "metre" and prefixes includes "kilo", this map will include "kilometre", mapping it to a unit representing a kilometre). It is immutable, but you can modify the underlying maps, which is reflected in the \texttt{PrefixedUnitMap}. Other than that, it is a normal map implementation. Prefixes and dimensions are stored in normal maps. \subsubsection{Parsing Expressions} -\label{sec:org8392990} -Each \texttt{UnitDatabase} instance has four \hyperref[sec:orgb091347]{ExpressionParser} instances associated with it, for four types of expressions: unit, unit value, prefix and dimension. They are mostly similar, with operators corresponding to each operation of the corresponding class (\texttt{LinearUnit}, \texttt{LinearUnitValue}, \texttt{UnitPrefix}, \texttt{ObjectProduct<BaseDimension>}). Unit and unit value expressions use linear units; nonlinear units can be used with a special syntax (like "degC(20)") and are immediately converted to a linear unit representing their base (Kelvin in this case) before operating. +\label{sec:org3608cd5} +Each \texttt{UnitDatabase} instance has four \hyperref[sec:orgb075c07]{ExpressionParser} instances associated with it, for four types of expressions: unit, unit value, prefix and dimension. They are mostly similar, with operators corresponding to each operation of the corresponding class (\texttt{LinearUnit}, \texttt{LinearUnitValue}, \texttt{UnitPrefix}, \texttt{ObjectProduct<BaseDimension>}). Unit and unit value expressions use linear units; nonlinear units can be used with a special syntax (like "degC(20)") and are immediately converted to a linear unit representing their base (Kelvin in this case) before operating. \subsubsection{Parsing Files} -\label{sec:orgd4ad341} +\label{sec:org262b0a7} There are two types of data files: unit and dimension. Unit files contain data about units and prefixes. Each line contains the name of a unit or prefix (prefixes end in a dash, units don't) followed by an expression which defines it, separated by one or more space characters (this behaviour is defined by the static regular expression \texttt{NAME\_EXPRESSION}). Unit files are parsed line by line, each line being run through the \texttt{addUnitOrPrefixFromLine} method, which splits a line into name and expression, determines whether it's a unit or a prefix, and parses the expression. Because all units are defined by others, base units need to be defined with a special expression "!"; \textbf{these units should be added to the database before parsing the file}. Dimension files are similar, only for dimensions instead of units and prefixes. \newpage +\section{Front-End Design} +\label{sec:orgbb1d346} +The front-end of 7Units is based on an MVP model. There are two major frontend classes, the \textbf{View} and the \textbf{Presenter}. +\subsection{The View} +\label{sec:orgae93ac0} +The \texttt{View} is the part of the frontend code that directly interacts with the user. It handles input and output, but does not do any processing. Processing is handled by the presenter and the backend code. + +The \texttt{View} is an interface, not a single class, so that I can easily create multiple views without having to rewrite any processing code. This allows me to easily prototype changes to the GUI without messing with existing code. + +In addition, I have decided to move some functions of the \texttt{View} into two subinterfaces, \texttt{UnitConversionView} and \texttt{ExpressionConversionView}. This is because 7Units supports two kinds of unit conversion: unit conversion (select two compatible units, specify a value then convert) and expression conversion (enter two expressions and convert the first to a multiple of the second). Putting these functions into subinterfaces allows a \texttt{View} to do one type of conversion without forcing it to support the other. + +There are currently two implementations of the \texttt{View}: +\begin{description} +\item[{TabbedView}] A Swing GUI implementation that uses tabs to separate the two types of conversion. The default GUI used by 7Units. +\item[{ViewBot}] A simulated view that allows programs to set the output of its public methods (i.e. every getter in \texttt{View} has a setter in \texttt{ViewBot}). Intended for testing, and is already used by \texttt{PresenterTest}. +\end{description} +Both of these \texttt{View} implementations implement \texttt{UnitConversionView} and \texttt{ExpressionConversionView}. +\subsection{The Presenter} +\label{sec:org76432e4} +The \texttt{Presenter} is an intermediary between the \texttt{View} and the backend code. It accepts the user's input and passes it to the backend, then accepts the backend's output and passes it to the frontend for user viewing. Its main functions do not have arguments or return values; instead it takes input from and provides output to the \texttt{View} via its public methods. +\subsubsection{Rules} +\label{sec:org5218ce5} +The \texttt{Presenter} has a set of function-object rules that determine some of its behaviours. Each corresponds to a setting in the \texttt{View}, but they can be set to other values via the \texttt{Presenter}'s setters (although nonstandard rules cannot be saved and loaded): +\begin{description} +\item[{numberDisplayRule}] A function that determines how numbers are displayed. This controls the rounding rules. +\item[{prefixRepetitionRule}] A function that determines which combinations of prefixes are valid in unit expressions. This controls the unit prefix rules. +\item[{searchRule}] A function that determines which prefixes are shown in the unit lists in unit conversion (which prefixed units are searchable). +\end{description} + +These rules have been made this way to enable an incredible level of customization of these behaviours. Because any function object with the correct arguments and return type is accepted, these rules (especially the number display rule) can do much more than the default behaviours. +\subsection{Utility Classes} +\label{sec:org0cfabd2} +The frontend has many miscellaneous utility classes. Many of them are package-private. Here is a list of them, with a brief description of what they do and where they are used: +\begin{description} +\item[{DefaultPrefixRepetitionRule}] An enum containing the available rules determining when you can repeat prefixes. Used by the \texttt{TabbedView} for selecting the rule and by the \texttt{Presenter} for loading it from a file. +\item[{DelegateListModel}] A \texttt{javax.swing.ListModel} implementation that delegates all of its methods to a \texttt{List}. Implements \texttt{List} by also delegating to the underlying list. Used by the \texttt{SearchBoxList} to create an easily mutable \texttt{ListModel}. +\item[{FilterComparator}] A \texttt{Comparator} that sorts objects according to whether or not they match a filter. Used by the \texttt{SearchBoxList} for item sorting. +\item[{GridBagBuilder}] A convenience class for generating \texttt{GridBagConstraints} objects for Swing's \texttt{GridBagLayout}. Used by \texttt{TabbedView} for constructing the GUI. +\item[{SearchBoxList}] A Swing component that combines a text field and a \texttt{JList} to create a searchable list. Used by the \texttt{TabbedView}'s unit conversion mode. +\item[{StandardDisplayRules}] A static utility class that allows you to generate display/rounding rules. Used by \texttt{TabbedView} for generating these rules and \texttt{Presenter} for loading them from a file. +\item[{UnitConversionRecord}] A record-like object that contains the results of a unit or expression conversion. Used by \texttt{UnitConversionView} and \texttt{ExpressionConversionView} for accepting the results to be displayed. +\end{description} +\newpage \section{Utility Classes} -\label{sec:org251cb6a} +\label{sec:org59e5f0c} 7Units has a few general "utility" classes. They aren't directly related to units, but are used in the units system. \subsection{ObjectProduct} -\label{sec:orgc7c5740} +\label{sec:org07580ff} An \texttt{ObjectProduct} represents a "product" of elements of some type. The units system uses them to represent coherent units as a product of base units, and dimensions as a product of base dimensions. Internally, it is represented using a map mapping objects to their exponents in the product. For example, the unit "kg m\textsuperscript{2} / s\textsuperscript{2}" (i.e. a Joule) would be represented with a map like \texttt{[kg: 1, m: 2, s: -2]}. \subsection{ExpressionParser} -\label{sec:orgb091347} +\label{sec:orgb075c07} The \texttt{ExpressionParser} class is used to parse the unit, prefix and dimension expressions that are used throughout 7Units. An expression is something like "(2 m + 30 J / N) * 8 s)". Each instance represents a type of expression, containing a way to obtain values (such as numbers or units) from the text and operations that can be done on these values (such as addition, subtraction or multiplication). Each operation also has a priority, which controls the order of operations (i.e. multiplication gets a higher priority than addition). \texttt{ExpressionParser} has a parameterized type \texttt{T}, which represents the type of the value used in the expression. The expression parser currently only supports one type of value per expression; in the expressions used by 7Units numbers are treated as a kind of unit or prefix. Operators are represented by internal types; the system distinguishes between unary operators (those that take a single value, like negation) and binary operators (those that take 2 values, like +, -, * or /). @@ -123,13 +222,13 @@ Expressions are parsed in 2 steps: After evaluating the last token, there should be one value left in the stack - the answer. If there isn't, the original expression was malformed. \end{enumerate} \subsection{Math Classes} -\label{sec:orgb4a476a} +\label{sec:org1e73788} There are two simple math classes in 7Units: \begin{description} \item[{\texttt{UncertainDouble}}] Like a \texttt{double}, but with an uncertainty (e.g. \(2.0 \pm 0.4\)). The operations are like those of the regular Double, only they also calculate the uncertainty of the final value. They also have "exact" versions to help interoperation between \texttt{double} and \texttt{UncertainDouble}. It is used by the converter's Scientific Precision setting. \item[{\texttt{DecimalComparison}}] A static utility class that contains a few alternate equals() methods for \texttt{double} and \texttt{UncertainDouble}. These methods allow a slight (configurable) difference between values to still be considered equal, to fight roundoff error. \end{description} \subsection{Collection Classes} -\label{sec:org4a3e6a1} +\label{sec:org02e007a} The \texttt{ConditionalExistenceCollections} class contains wrapper implementations of \texttt{Collection}, \texttt{Iterator}, \texttt{Map} and \texttt{Set}. These implementations ignore elements that do not pass a certain condition - if an element fails the condition, \texttt{contains} will return false, the iterator will skip past it, it won't be counted in \texttt{size}, etc. even if it exists in the original collection. Effectively, any element of the original collection that fails the test does not exist. \end{document} diff --git a/docs/diagrams/convert-expressions.plantuml.png b/docs/diagrams/convert-expressions.plantuml.png Binary files differnew file mode 100644 index 0000000..f3e9096 --- /dev/null +++ b/docs/diagrams/convert-expressions.plantuml.png diff --git a/docs/diagrams/convert-expressions.plantuml.txt b/docs/diagrams/convert-expressions.plantuml.txt new file mode 100644 index 0000000..08de283 --- /dev/null +++ b/docs/diagrams/convert-expressions.plantuml.txt @@ -0,0 +1,22 @@ +@startuml + +actor User +participant View +participant Presenter +database UnitDatabase +participant ExpressionParser +participant Unit + +User -> View : Set input & output expressions +View -> Presenter : Call convertExpressions() +View <-- Presenter : Get user input +Presenter -> UnitDatabase : Send raw user input +UnitDatabase -> ExpressionParser : Send inputted expressions +UnitDatabase <-- ExpressionParser : Return parsed expressions +Presenter <-- UnitDatabase : Return unit/value objects +Presenter -> Unit : Convert provided units +Presenter <-- Unit : Return converted value +View <-- Presenter : Return converted units +User <-- View : Show conversion output + +@enduml diff --git a/docs/diagrams/convert-units.plantuml.png b/docs/diagrams/convert-units.plantuml.png Binary files differnew file mode 100644 index 0000000..318e8c9 --- /dev/null +++ b/docs/diagrams/convert-units.plantuml.png diff --git a/docs/diagrams/convert-units.plantuml.txt b/docs/diagrams/convert-units.plantuml.txt new file mode 100644 index 0000000..564a766 --- /dev/null +++ b/docs/diagrams/convert-units.plantuml.txt @@ -0,0 +1,19 @@ +@startuml + +actor User +participant View +participant Presenter +database UnitDatabase +participant Unit + +User -> View : Choose units & input value +View -> Presenter : Call convertUnits() +View <-- Presenter : Get user input +Presenter -> UnitDatabase : Send raw user input +Presenter <-- UnitDatabase : Return unit objects +Presenter -> Unit : Convert provided units +Presenter <-- Unit : Return converted value +View <-- Presenter : Return converted units +User <-- View : Show conversion output + +@enduml diff --git a/docs/diagrams/overview-diagram.plantuml.png b/docs/diagrams/overview-diagram.plantuml.png Binary files differnew file mode 100644 index 0000000..096a65c --- /dev/null +++ b/docs/diagrams/overview-diagram.plantuml.png diff --git a/docs/diagrams/overview-diagram.plantuml.txt b/docs/diagrams/overview-diagram.plantuml.txt new file mode 100644 index 0000000..aeedbc5 --- /dev/null +++ b/docs/diagrams/overview-diagram.plantuml.txt @@ -0,0 +1,20 @@ +@startuml + +package sevenUnitsGUI { + interface View {} + class Presenter {} + + Presenter "1" o-- View + View "0-1" o-- Presenter +} + +package sevenUnits.unit { + class Unit {} + class UnitDatabase {} + + UnitDatabase *-- Unit +} + +Presenter "1" o- UnitDatabase + +@enduml diff --git a/docs/manual.org b/docs/manual.org index 086ae5d..47302d3 100644 --- a/docs/manual.org +++ b/docs/manual.org @@ -1,6 +1,6 @@ #+TITLE: 7Units User Manual -#+SUBTITLE: For Version 0.3.1 -#+DATE: 2021 July 6 +#+SUBTITLE: For Version 0.4.0 +#+DATE: 2022 July 8 #+LaTeX_HEADER: \usepackage[a4paper, lmargin=25mm, rmargin=25mm, tmargin=25mm, bmargin=25mm]{geometry} #+LaTeX: \newpage @@ -9,7 +9,7 @@ * System Requirements - Works on all major operating systems \\ *NOTE:* All screenshots in this document were taken on Windows 10. If you use a different operating system, the program will probably look different than what is shown. - - Java version 11-15 required + - Java version 11+ required # installation instructions go here - wait until git repository is fixed/set up #+LaTeX: \newpage * How to Use 7Units @@ -47,7 +47,7 @@ [[../screenshots/sample-conversion-results-expression-converter.png]] * 7Units Settings All settings can be accessed in the tab with the gear icon. - #+CAPTION: The settings menu, as of version 0.3.0 + #+CAPTION: The settings menu, as of version 0.4.0 #+ATTR_LaTeX: :height 250px [[../screenshots/main-interface-settings.png]] ** Rounding Settings @@ -65,6 +65,11 @@ - any number of yocto or yotta - they must be in this order - all prefixes must be of the same sign (either all magnifying or all reducing) +** Search Settings + These settings control which prefixes are shown in the "Convert Units" tab. Only coherent SI units (e.g. metre, second, newton, joule) will get prefixes. Some prefixed units are created in the unitfile, and will stay regardless of this setting (though they can be removed from the unitfile). + - Never Include Prefixed Units :: Prefixed units will only be shown if they are explicitly added to the unitfile. + - Include Common Prefixes :: Every coherent unit will have its kilo- and milli- versions included in the list. + - Include All Single Prefixes :: Every coherent unit will have every prefixed version of it included in the list. ** Miscellaneous Settings - Convert One Way Only :: In the simple conversion tab, only imperial/customary units will be shown on the left, and only metric units[fn:1] will be shown on the right. Units listed in the exceptions file (~src/main/resources/metric_exceptions.txt~) will be shown on both sides. This is a way to reduce the number of options you must search through if you only convert one way. The expressions tab is unaffected. - Show Duplicates in "Convert Units" :: If unchecked, any unit that has multiple names will only have one included in the Convert Units lists. The selected name will be the longest; if there are multiple longest names one is selected arbitrarily. You will still be able to use these alternate names in the expressions tab. diff --git a/docs/manual.pdf b/docs/manual.pdf Binary files differindex e6cbb5d..76ec078 100644 --- a/docs/manual.pdf +++ b/docs/manual.pdf diff --git a/docs/manual.tex b/docs/manual.tex index 25a5cf7..e82dac5 100644 --- a/docs/manual.tex +++ b/docs/manual.tex @@ -1,4 +1,4 @@ -% Created 2021-07-06 Tue 15:22 +% Created 2022-07-17 Sun 16:22 % Intended LaTeX compiler: pdflatex \documentclass[11pt]{article} \usepackage[utf8]{inputenc} @@ -15,9 +15,9 @@ \usepackage{capt-of} \usepackage{hyperref} \usepackage[a4paper, lmargin=25mm, rmargin=25mm, tmargin=25mm, bmargin=25mm]{geometry} -\date{2021 July 6} +\date{2022 July 8} \title{7Units User Manual\\\medskip -\large For Version 0.3.1} +\large For Version 0.4.0} \hypersetup{ pdfauthor={}, pdftitle={7Units User Manual}, @@ -32,21 +32,21 @@ \newpage \section{Introduction and Purpose} -\label{sec:org9bdf09d} +\label{sec:org24a029b} 7Units is a program that can be used to convert units. This document outlines how to use the program. \section{System Requirements} -\label{sec:org6fc29c1} +\label{sec:orgab28d01} \begin{itemize} \item Works on all major operating systems \\ \textbf{NOTE:} All screenshots in this document were taken on Windows 10. If you use a different operating system, the program will probably look different than what is shown. -\item Java version 11-15 required +\item Java version 11+ required \end{itemize} \newpage \section{How to Use 7Units} -\label{sec:org12dfe6f} +\label{sec:org23427ab} \subsection{Simple Unit Conversion} -\label{sec:org49a020a} +\label{sec:org91a1ab6} \begin{enumerate} \item Select the "Convert Units" tab if it is not already selected. You should see a screen like in figure \ref{main-interface-dimension}: \begin{figure}[htbp] @@ -71,7 +71,7 @@ \end{figure} \end{enumerate} \subsection{Complex Unit Conversion} -\label{sec:org5433cd5} +\label{sec:orgf8fd5b1} \begin{enumerate} \item Select the "Convert Unit Expressions" if it is not already selected. You should see a screen like in figure \ref{main-interface-expression}: \begin{figure}[htbp] @@ -79,7 +79,7 @@ \includegraphics[height=250px]{../screenshots/main-interface-expression-converter.png} \caption{\label{main-interface-expression}Taken in version 0.3.0} \end{figure} -\item Enter a \hyperref[sec:org05dd82b]{unit expression} in the From box. This can be something like "\texttt{7 km}" or "\texttt{6 ft - 2 in}" or "\texttt{3 kg m + 9 lb ft + (35 mm)\textasciicircum{}2 * (85 oz) / (20 in)}". +\item Enter a \hyperref[sec:org7ac3fe5]{unit expression} in the From box. This can be something like "\texttt{7 km}" or "\texttt{6 ft - 2 in}" or "\texttt{3 kg m + 9 lb ft + (35 mm)\textasciicircum{}2 * (85 oz) / (20 in)}". \item Enter a unit name (or another unit expression) in the To box. \item Press the Convert button. This will calculate the value of the first expression, and convert it to a multiple of the second unit (or expression). \begin{figure}[htbp] @@ -89,15 +89,15 @@ \end{figure} \end{enumerate} \section{7Units Settings} -\label{sec:org59fb50d} +\label{sec:org72dc17b} All settings can be accessed in the tab with the gear icon. \begin{figure}[htbp] \centering \includegraphics[height=250px]{../screenshots/main-interface-settings.png} -\caption{The settings menu, as of version 0.3.0} +\caption{The settings menu, as of version 0.4.0} \end{figure} \subsection{Rounding Settings} -\label{sec:org328f0e1} +\label{sec:org690a0a5} These settings control how the output of a unit conversion is rounded. \begin{description} \item[{Fixed Precision}] Round to a fixed number of \href{https://en.wikipedia.org/wiki/Significant\_figures}{significant digits}. The number of significant digits is controlled by the precision slider below. @@ -105,7 +105,7 @@ These settings control how the output of a unit conversion is rounded. \item[{Scientific Precision}] Intelligent rounding which uses the precision of the input value(s) to determine the output precision. Not affected by the precision slider. \end{description} \subsection{Prefix Repetition Settings} -\label{sec:org859bd80} +\label{sec:orgef19465} These settings control when you are allowed to repeat unit prefixes (e.g. kilokilometre) \begin{description} \item[{No Repetition}] Units may only have one prefix. @@ -119,16 +119,24 @@ These settings control when you are allowed to repeat unit prefixes (e.g. kiloki \item all prefixes must be of the same sign (either all magnifying or all reducing) \end{itemize} \end{description} +\subsection{Search Settings} +\label{sec:org038add7} +These settings control which prefixes are shown in the "Convert Units" tab. Only coherent SI units (e.g. metre, second, newton, joule) will get prefixes. Some prefixed units are created in the unitfile, and will stay regardless of this setting (though they can be removed from the unitfile). +\begin{description} +\item[{Never Include Prefixed Units}] Prefixed units will only be shown if they are explicitly added to the unitfile. +\item[{Include Common Prefixes}] Every coherent unit will have its kilo- and milli- versions included in the list. +\item[{Include All Single Prefixes}] Every coherent unit will have every prefixed version of it included in the list. +\end{description} \subsection{Miscellaneous Settings} -\label{sec:org7345e44} +\label{sec:orgbd23cc6} \begin{description} \item[{Convert One Way Only}] In the simple conversion tab, only imperial/customary units will be shown on the left, and only metric units\footnote{7Units's definition of "metric" is stricter than the SI, but all of the common units that are commonly considered metric but not included in 7Units's definition are included in the exceptions file.} will be shown on the right. Units listed in the exceptions file (\texttt{src/main/resources/metric\_exceptions.txt}) will be shown on both sides. This is a way to reduce the number of options you must search through if you only convert one way. The expressions tab is unaffected. \item[{Show Duplicates in "Convert Units"}] If unchecked, any unit that has multiple names will only have one included in the Convert Units lists. The selected name will be the longest; if there are multiple longest names one is selected arbitrarily. You will still be able to use these alternate names in the expressions tab. \end{description} \section{Appendices} -\label{sec:orgee83bb3} +\label{sec:org4ceffe9} \subsection{Unit Expressions} -\label{sec:org05dd82b} +\label{sec:org7ac3fe5} A unit expression is simply a math expression where the values being operated on are units or numbers. The operations that can be used are (in order of precedence): \begin{itemize} \item Exponentiation (\^{}); the exponent must be an integer. Both units and numbers can be raised to an exponent @@ -138,6 +146,6 @@ A unit expression is simply a math expression where the values being operated on Brackets can be used to manipulate the order of operations, and nonlinear units like Celsius and Fahrenheit cannot be used in expressions. You can use a value in a nonlinear unit by putting brackets after it - for example, degC(12) represents the value 12 \textdegree{} C \subsection{Other Expressions} -\label{sec:org8014464} +\label{sec:orga66137e} There are also a simplified version of expressions for prefixes and dimensions. Only multiplication, division and exponentation are supported. Currently, exponentation is not supported for dimensions, but that may be fixed in the future. \end{document} |