Reorganizing paths
This commit is contained in:
parent
e9d204daab
commit
34cb856dd4
249 changed files with 118 additions and 294 deletions
136
common/src/preferences/common.mjs
Normal file
136
common/src/preferences/common.mjs
Normal file
|
@ -0,0 +1,136 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 Ad5001
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Expression } from "../math/index.mjs"
|
||||
|
||||
class Setting {
|
||||
constructor(type, name, nameInConfig, icon) {
|
||||
this.type = type
|
||||
this.name = name
|
||||
this.nameInConfig = nameInConfig
|
||||
this.icon = icon
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the setting.
|
||||
* @returns {string|boolean|number}
|
||||
*/
|
||||
value() {
|
||||
throw new TypeError(`value of ${this.constructor} not implemented.`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the setting
|
||||
* @param {string|boolean|number|Expression} value
|
||||
*/
|
||||
set(value) {
|
||||
throw new TypeError(`value of ${this.constructor} not implemented.`)
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `Setting<${this.type} ${this.name}>`
|
||||
}
|
||||
}
|
||||
|
||||
export class BoolSetting extends Setting {
|
||||
constructor(name, nameInConfig, icon) {
|
||||
super("bool", name, nameInConfig, icon)
|
||||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSettingBool(this.nameInConfig)
|
||||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSettingBool(this.nameInConfig, value)
|
||||
}
|
||||
}
|
||||
|
||||
export class NumberSetting extends Setting {
|
||||
constructor(name, nameInConfig, icon, min = -Infinity, max = +Infinity) {
|
||||
super("number", name, nameInConfig, icon)
|
||||
this.min = typeof min == "number" ? () => min : min
|
||||
this.max = typeof max == "number" ? () => max : max
|
||||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSettingInt(this.nameInConfig)
|
||||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSettingInt(this.nameInConfig, value)
|
||||
}
|
||||
}
|
||||
|
||||
export class EnumIntSetting extends Setting {
|
||||
constructor(name, nameInConfig, icon, values = []) {
|
||||
super("enum", name, nameInConfig, icon)
|
||||
this.values = values
|
||||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSettingInt(this.nameInConfig)
|
||||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSettingInt(this.nameInConfig, value)
|
||||
}
|
||||
}
|
||||
|
||||
export class ExpressionSetting extends Setting {
|
||||
constructor(name, nameInConfig, icon, variables = []) {
|
||||
super("expression", name, nameInConfig, icon)
|
||||
this.variables = variables
|
||||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSetting(this.nameInConfig)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Expression} value
|
||||
*/
|
||||
set(value) {
|
||||
let vars = value.variables()
|
||||
if(vars.length === this.variables.length && vars.every(x => this.variables.includes(x)))
|
||||
Helper.setSetting(this.nameInConfig, value)
|
||||
else {
|
||||
let undefinedVars = vars.filter(x => !this.variables.includes(x))
|
||||
let allowed = ""
|
||||
if(this.variables.length > 0)
|
||||
allowed = `Allowed variables: ${this.variables.join(", ")}.`
|
||||
throw new TypeError(`Cannot use variable(s) ${undefinedVars.join(", or ")} to define ${this.displayName}. ${allowed}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class StringSetting extends Setting {
|
||||
constructor(name, nameInConfig, icon, defaultValues = []) {
|
||||
super("string", name, nameInConfig, icon)
|
||||
this.defaultValues = defaultValues
|
||||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSetting(this.nameInConfig)
|
||||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSetting(this.nameInConfig, value)
|
||||
}
|
||||
}
|
120
common/src/preferences/default.mjs
Normal file
120
common/src/preferences/default.mjs
Normal file
|
@ -0,0 +1,120 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 Ad5001
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { BoolSetting, ExpressionSetting, NumberSetting, StringSetting } from "./common.mjs"
|
||||
|
||||
|
||||
const XZOOM = new NumberSetting(
|
||||
qsTranslate("Settings", "X Zoom"),
|
||||
"default_graph.xzoom",
|
||||
"xzoom",
|
||||
0.1
|
||||
)
|
||||
|
||||
const YZOOM = new NumberSetting(
|
||||
qsTranslate("Settings", "Y Zoom"),
|
||||
"default_graph.xzoom",
|
||||
"yzoom",
|
||||
0.1
|
||||
)
|
||||
|
||||
const XMIN = new NumberSetting(
|
||||
qsTranslate("Settings", "Min X"),
|
||||
"default_graph.xmin",
|
||||
"xmin",
|
||||
() => Helper.getSettingBool("default_graph.logscalex") ? 1e-100 : -Infinity
|
||||
)
|
||||
|
||||
const YMAX = new NumberSetting(
|
||||
qsTranslate("Settings", "Max Y"),
|
||||
"default_graph.ymax",
|
||||
"ymax"
|
||||
)
|
||||
|
||||
const XAXISSTEP = new ExpressionSetting(
|
||||
qsTranslate("Settings", "X Axis Step"),
|
||||
"default_graph.xaxisstep",
|
||||
"xaxisstep"
|
||||
)
|
||||
|
||||
const YAXISSTEP = new ExpressionSetting(
|
||||
qsTranslate("Settings", "Y Axis Step"),
|
||||
"default_graph.yaxisstep",
|
||||
"yaxisstep"
|
||||
)
|
||||
|
||||
const LINE_WIDTH = new NumberSetting(
|
||||
qsTranslate("Settings", "Line width"),
|
||||
"default_graph.linewidth",
|
||||
"linewidth",
|
||||
1
|
||||
)
|
||||
|
||||
const TEXT_SIZE = new NumberSetting(
|
||||
qsTranslate("Settings", "Text size (px)"),
|
||||
"default_graph.textsize",
|
||||
"textsize"
|
||||
)
|
||||
|
||||
const X_LABEL = new StringSetting(
|
||||
qsTranslate("Settings", "X Label"),
|
||||
"default_graph.xlabel",
|
||||
"xlabel",
|
||||
["", "x", "ω (rad/s)"]
|
||||
)
|
||||
|
||||
const Y_LABEL = new StringSetting(
|
||||
qsTranslate("Settings", "Y Label"),
|
||||
"default_graph.ylabel",
|
||||
"xlabel",
|
||||
["", "y", "G (dB)", "φ (°)", "φ (deg)", "φ (rad)"]
|
||||
)
|
||||
|
||||
const LOG_SCALE_X = new BoolSetting(
|
||||
qsTranslate("Settings", "X Log scale"),
|
||||
"default_graph.logscalex",
|
||||
"logscalex"
|
||||
)
|
||||
|
||||
const SHOW_X_GRAD = new BoolSetting(
|
||||
qsTranslate("Settings", "Show X graduation"),
|
||||
"default_graph.showxgrad",
|
||||
"showxgrad"
|
||||
)
|
||||
|
||||
const SHOW_Y_GRAD = new BoolSetting(
|
||||
qsTranslate("Settings", "Show Y graduation"),
|
||||
"default_graph.showygrad",
|
||||
"showygrad"
|
||||
)
|
||||
|
||||
export default [
|
||||
XZOOM,
|
||||
YZOOM,
|
||||
XMIN,
|
||||
YMAX,
|
||||
XAXISSTEP,
|
||||
YAXISSTEP,
|
||||
LINE_WIDTH,
|
||||
TEXT_SIZE,
|
||||
X_LABEL,
|
||||
Y_LABEL,
|
||||
LOG_SCALE_X,
|
||||
SHOW_X_GRAD,
|
||||
SHOW_Y_GRAD
|
||||
]
|
51
common/src/preferences/expression.mjs
Normal file
51
common/src/preferences/expression.mjs
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 Ad5001
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { BoolSetting, EnumIntSetting } from "./common.mjs"
|
||||
|
||||
const AUTOCLOSE_FORMULA = new BoolSetting(
|
||||
qsTranslate("expression", "Automatically close parenthesises and brackets"),
|
||||
"expression_editor.autoclose",
|
||||
"text"
|
||||
)
|
||||
|
||||
const ENABLE_SYNTAX_HIGHLIGHTING = new BoolSetting(
|
||||
qsTranslate("expression", "Enable syntax highlighting"),
|
||||
"expression_editor.colorize",
|
||||
"appearance"
|
||||
)
|
||||
|
||||
const ENABLE_AUTOCOMPLETE = new BoolSetting(
|
||||
qsTranslate("expression", "Enable autocompletion"),
|
||||
"autocompletion.enabled",
|
||||
"label"
|
||||
)
|
||||
|
||||
const PICK_COLOR_SCHEME = new EnumIntSetting(
|
||||
qsTranslate("expression", "Color Scheme"),
|
||||
"expression_editor.color_scheme",
|
||||
"color",
|
||||
["Breeze Light", "Breeze Dark", "Solarized", "Github Light", "Github Dark", "Nord", "Monokai"]
|
||||
)
|
||||
|
||||
export default [
|
||||
AUTOCLOSE_FORMULA,
|
||||
ENABLE_AUTOCOMPLETE,
|
||||
ENABLE_SYNTAX_HIGHLIGHTING,
|
||||
PICK_COLOR_SCHEME
|
||||
]
|
53
common/src/preferences/general.mjs
Normal file
53
common/src/preferences/general.mjs
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 Ad5001
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { BoolSetting } from "./common.mjs"
|
||||
import Canvas from "../module/canvas.mjs"
|
||||
import LatexAPI from "../module/latex.mjs"
|
||||
|
||||
const CHECK_FOR_UPDATES = new BoolSetting(
|
||||
qsTranslate("general", "Check for updates on startup"),
|
||||
"check_for_updates",
|
||||
"update"
|
||||
)
|
||||
|
||||
const RESET_REDO_STACK = new BoolSetting(
|
||||
qsTranslate("general", "Reset redo stack automaticly"),
|
||||
"reset_redo_stack",
|
||||
"timeline"
|
||||
)
|
||||
|
||||
class EnableLatex extends BoolSetting {
|
||||
constructor() {
|
||||
super(qsTranslate("general", "Enable LaTeX rendering"), "enable_latex", "Expression")
|
||||
}
|
||||
|
||||
set(value) {
|
||||
if(!value || Latex.checkLatexInstallation()) {
|
||||
super.set(value)
|
||||
LatexAPI.enabled = value
|
||||
Canvas.requestPaint()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default [
|
||||
CHECK_FOR_UPDATES,
|
||||
RESET_REDO_STACK,
|
||||
new EnableLatex()
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue