diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/autoload.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/autoload.mjs index dcdaedb..085a5c5 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/autoload.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/autoload.mjs @@ -17,11 +17,11 @@ */ // Loading modules in order -import * as Objects from "./objects.mjs" -import * as ExprParser from "./lib/expr-eval/integration.mjs" +import * as Objects from "./module/objects.mjs" +import * as ExprParser from "./module/expreval.mjs" import * as ObjsAutoload from "./objs/autoload.mjs" -import * as Latex from "./math/latex.mjs" -import * as HistoryCommon from "./history/common.mjs" -import * as CanvasAPI from "./canvas.mjs" -import * as IOAPI from "./io.mjs" -import * as PreferencesAPI from "./preferences.mjs" +import * as Latex from "./module/latex.mjs" +import * as History from "./module/history.mjs" +import * as CanvasAPI from "./module/canvas.mjs" +import * as IOAPI from "./module/io.mjs" +import * as PreferencesAPI from "./module/preferences.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs index 12a8793..067da0c 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.mjs @@ -17,7 +17,7 @@ */ import EditedProperty from "editproperty.mjs" -import Objects from "../objects.mjs" +import Objects from "../module/objects.mjs" export default class ColorChanged extends EditedProperty { // Action used everytime when an object's color is changed diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.mjs index db2d5dc..41d28ce 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.mjs @@ -16,34 +16,8 @@ * along with this program. If not, see . */ -import { Module } from "../modules.mjs" -import Latex from "../math/latex.mjs" - - -class HistoryCommonAPI extends Module { - constructor() { - super('History', [ - Modules.Latex - ]) - // History QML object - this.history = null; - this.themeTextColor = "#ff0000"; - this.imageDepth = 2; - this.fontSize = 14; - } - - undo() { this.history.undo() } - redo() { this.history.redo() } - clear() { this.history.clear() } - addToHistory(action) { this.history.addToHistory(action) } - unserialize(...data) { this.history.unserialize(...data) } - serialize() { return this.history.serialize() } -} - -/** @type {HistoryCommonAPI} */ -Modules.History = Modules.History || new HistoryCommonAPI() - -export const API = Modules.History +import History from "../module/history.mjs" +import Latex from "../module/latex.mjs" export class Action { /** @@ -102,7 +76,7 @@ export class Action { * @returns {string} */ getIconRichText(type) { - return `` + return `` } /** @@ -115,11 +89,11 @@ export class Action { if(!Latex.enabled) throw new Error("Cannot render an item as LaTeX when LaTeX is disabled.") return new Promise(resolve => { - let imgDepth = Modules.History.imageDepth + let imgDepth = History.imageDepth Latex.requestAsyncRender( latexString, - imgDepth * (Modules.History.fontSize + 2), - Modules.History.themeTextColor + imgDepth * (History.fontSize + 2), + History.themeTextColor ).then((imgData) => { const { source, width, height } = imgData resolve(``) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs index b2c7f2d..bd3dafd 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.mjs @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import Objects from "../objects.mjs" +import Objects from "../module/objects.mjs" import { Action } from "common.mjs" export default class CreateNewObject extends Action { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs index 7fa855d..c348c41 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.mjs @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import Objects from "../objects.mjs" +import Objects from "../module/objects.mjs" import CreateNewObject from "create.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs index 1280e54..febed9a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.mjs @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import * as MathLib from "../mathlib.mjs" import { Action } from "common.mjs" import { DrawableObject } from "../objs/common.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs index 13417da..a852923 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.mjs @@ -17,7 +17,7 @@ */ import EditedProperty from "editproperty.mjs" -import Objects from "../objects.mjs" +import Objects from "../module/objects.mjs" export default class NameChanged extends EditedProperty { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs index b071cc7..14b5bac 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.mjs @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import * as MathLib from "../mathlib.mjs" import { escapeHTML } from "../utils.mjs" import { Action } from "common.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs index ebcb4fa..c04e0a4 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.mjs @@ -17,7 +17,7 @@ */ import EditedProperty from "editproperty.mjs" -import Objects from "../objects.mjs" +import Objects from "../module/objects.mjs" export default class EditedVisibility extends EditedProperty { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/expression.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/expression.mjs index 3a0ebb4..8a7bf77 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/expression.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/expression.mjs @@ -17,21 +17,19 @@ */ -import Latex from "latex.mjs" import * as Utils from "../utils.mjs" +import Latex from "../module/latex.mjs" +import ExprParser from "../module/expreval.mjs" +import Objects from "../module/objects.mjs" /** * Represents any kind of x-based or non variable based expression. */ export class Expression { constructor(expr) { - if(!Modules.ExprParser) - throw new Error('Expression parser not initialized.') - if(!Modules.Objects) - throw new Error('Objects API not initialized.') if(typeof expr === "string") { this.expr = Utils.exponentsToExpression(expr) - this.calc = Modules.ExprParser.parse(this.expr).simplify() + this.calc = ExprParser.parse(this.expr).simplify() } else { // Passed an expression here directly. this.calc = expr.simplify() @@ -40,7 +38,7 @@ export class Expression { this.cached = this.isConstant() this.cachedValue = null if(this.cached && this.allRequirementsFullfilled()) - this.cachedValue = this.calc.evaluate(Modules.Objects.currentObjectsByName) + this.cachedValue = this.calc.evaluate(Objects.currentObjectsByName) this.latexMarkup = Latex.expression(this.calc.tokens) } @@ -54,26 +52,26 @@ export class Expression { } allRequirementsFullfilled() { - return this.requiredObjects().every(objName => objName in Modules.Objects.currentObjectsByName) + return this.requiredObjects().every(objName => objName in Objects.currentObjectsByName) } undefinedVariables() { - return this.requiredObjects().filter(objName => !(objName in Modules.Objects.currentObjectsByName)) + return this.requiredObjects().filter(objName => !(objName in Objects.currentObjectsByName)) } recache() { if(this.cached) - this.cachedValue = this.calc.evaluate(Modules.Objects.currentObjectsByName) + this.cachedValue = this.calc.evaluate(Objects.currentObjectsByName) } execute(x = 1) { if(this.cached) { if(this.cachedValue == null) - this.cachedValue = this.calc.evaluate(Modules.Objects.currentObjectsByName) + this.cachedValue = this.calc.evaluate(Objects.currentObjectsByName) return this.cachedValue } - Modules.ExprParser.currentVars = Object.assign({'x': x}, Modules.Objects.currentObjectsByName) - return this.calc.evaluate(Modules.ExprParser.currentVars) + ExprParser.currentVars = Object.assign({'x': x}, Objects.currentObjectsByName) + return this.calc.evaluate(ExprParser.currentVars) } simplify(x) { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.mjs index 677d68e..d524e44 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/sequence.mjs @@ -18,7 +18,9 @@ import * as Expr from "expression.mjs" import * as Utils from "../utils.mjs" -import Latex from "../math/latex.mjs" +import Latex from "../module/latex.mjs" +import Objects from "../module/objects.mjs" +import ExprParser from "../module/expreval.mjs" /** * Represents mathematical object for sequences. @@ -33,7 +35,7 @@ export class Sequence extends Expr.Expression { this.latexValues = Object.assign({}, baseValues) for(let n in this.calcValues) if(['string', 'number'].includes(typeof this.calcValues[n])) { - let parsed = Modules.ExprParser.parse(this.calcValues[n].toString()).simplify() + let parsed = ExprParser.parse(this.calcValues[n].toString()).simplify() this.latexValues[n] = Latex.expression(parsed.tokens) this.calcValues[n] = parsed.evaluate() } @@ -59,17 +61,17 @@ export class Sequence extends Expr.Expression { cache(n = 1) { let str = Utils.simplifyExpression(this.calc.substitute('n', n-this.valuePlus).toString()) - let expr = Modules.ExprParser.parse(str).simplify() + let expr = ExprParser.parse(str).simplify() // Cache values required for this one. if(!this.calcValues[n-this.valuePlus] && n-this.valuePlus > 0) this.cache(n-this.valuePlus) // Setting current variables - Modules.ExprParser.currentVars = Object.assign( + ExprParser.currentVars = Object.assign( {'n': n-this.valuePlus}, // Just in case, add n (for custom functions) - Modules.Objects.currentObjectsByName, + Objects.currentObjectsByName, {[this.name]: this.calcValues} ) - this.calcValues[n] = expr.evaluate(Modules.ExprParser.currentVars) + this.calcValues[n] = expr.evaluate(ExprParser.currentVars) } toString(forceSign=false) { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/canvas.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/canvas.mjs similarity index 97% rename from LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/canvas.mjs rename to LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/canvas.mjs index d214be3..cd86c6e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/canvas.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/canvas.mjs @@ -16,10 +16,12 @@ * along with this program. If not, see . */ -import { Module } from "./modules.mjs" -import { textsup } from "./utils.mjs" -import { Expression } from "./mathlib.mjs" -import Latex from "./math/latex.mjs" +import { Module } from "./common.mjs" +import { textsup } from "../utils.mjs" +import { Expression } from "../mathlib.mjs" +import Latex from "./latex.mjs" +import Objects from "./objects.mjs" +import History from "./history.mjs" class CanvasAPI extends Module { @@ -168,8 +170,8 @@ class CanvasAPI extends Module { this._drawAxes() this._drawLabels() this._ctx.lineWidth = this.linewidth - for(let objType in Modules.Objects.currentObjects) { - for(let obj of Modules.Objects.currentObjects[objType]){ + for(let objType in Objects.currentObjects) { + for(let obj of Objects.currentObjects[objType]){ this._ctx.strokeStyle = obj.color this._ctx.fillStyle = obj.color if(obj.visible) @@ -180,7 +182,7 @@ class CanvasAPI extends Module { console.error(e) console.log(e.stack) this._drawingErrorDialog.showDialog(objType, obj.name, e.message) - Modules.History.undo() + History.undo() } } } @@ -188,7 +190,7 @@ class CanvasAPI extends Module { } /** - * Calculates informations for drawing gradations for axes. + * Calculates information for drawing gradations for axes. * @private */ _computeAxes() { @@ -538,4 +540,4 @@ class CanvasAPI extends Module { /** @type {CanvasAPI} */ Modules.Canvas = Modules.Canvas || new CanvasAPI() -export const API = Modules.Canvas +export default Modules.Canvas diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/modules.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/common.mjs similarity index 100% rename from LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/modules.mjs rename to LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/common.mjs diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/lib/expr-eval/integration.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/expreval.mjs similarity index 97% rename from LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/lib/expr-eval/integration.mjs rename to LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/expreval.mjs index 244194f..9ad06d5 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/lib/expr-eval/integration.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/expreval.mjs @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import { Module } from "../../modules.mjs" -import { Parser } from "./parser.mjs" +import { Module } from "./common.mjs" +import { Parser } from "../lib/expr-eval/parser.mjs" const evalVariables = { // Variables not provided by expr-eval.js, needs to be provided manually @@ -112,5 +112,5 @@ export class ExprParserAPI extends Module { /** @type {ExprParserAPI} */ Modules.ExprParser = Modules.ExprParser || new ExprParserAPI() - +export default Modules.ExprParser diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/history.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/history.mjs new file mode 100644 index 0000000..27eedcb --- /dev/null +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/history.mjs @@ -0,0 +1,46 @@ +/** + * 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 . + */ + +import { Module } from "./common.mjs" +import Latex from "./latex.mjs" + + +class HistoryAPI extends Module { + constructor() { + super('History', [ + Modules.Latex + ]) + // History QML object + this.history = null; + this.themeTextColor = "#ff0000"; + this.imageDepth = 2; + this.fontSize = 14; + } + + undo() { this.history.undo() } + redo() { this.history.redo() } + clear() { this.history.clear() } + addToHistory(action) { this.history.addToHistory(action) } + unserialize(...data) { this.history.unserialize(...data) } + serialize() { return this.history.serialize() } +} + +/** @type {HistoryAPI} */ +Modules.History = Modules.History || new HistoryAPI() + +export default Modules.History \ No newline at end of file diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/io.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/io.mjs similarity index 60% rename from LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/io.mjs rename to LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/io.mjs index 4bc76b5..bc9a1db 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/io.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/io.mjs @@ -16,12 +16,15 @@ * along with this program. If not, see . */ -import {Module} from "./modules.mjs" +import { Module } from "./common.mjs" +import Objects from "./objects.mjs" +import History from "./history.mjs" +import Canvas from "./canvas.mjs" class IOAPI extends Module { constructor() { - super('IO', [ + super("IO", [ Modules.Objects, Modules.History ]) @@ -50,39 +53,39 @@ class IOAPI extends Module { */ saveDiagram(filename) { // Add extension if necessary - if(['lpf'].indexOf(filename.split('.')[filename.split('.').length-1]) === -1) - filename += '.lpf' + if(["lpf"].indexOf(filename.split(".")[filename.split(".").length - 1]) === -1) + filename += ".lpf" this.saveFilename = filename let objs = {} - for(let objType in Modules.Objects.currentObjects){ + for(let objType in Objects.currentObjects) { objs[objType] = [] - for(let obj of Modules.Objects.currentObjects[objType]) { + for(let obj of Objects.currentObjects[objType]) { objs[objType].push(obj.export()) } } let settings = { - "xzoom": this.settings.xzoom, - "yzoom": this.settings.yzoom, - "xmin": this.settings.xmin, - "ymax": this.settings.ymax, - "xaxisstep": this.settings.xaxisstep, - "yaxisstep": this.settings.yaxisstep, - "xaxislabel": this.settings.xlabel, - "yaxislabel": this.settings.ylabel, - "logscalex": this.settings.logscalex, - "linewidth": this.settings.linewidth, - "showxgrad": this.settings.showxgrad, - "showygrad": this.settings.showygrad, - "textsize": this.settings.textsize, - "history": Modules.History.serialize(), - "width": this.rootElement.width, - "height": this.rootElement.height, - "objects": objs, - "type": "logplotv1" + "xzoom": this.settings.xzoom, + "yzoom": this.settings.yzoom, + "xmin": this.settings.xmin, + "ymax": this.settings.ymax, + "xaxisstep": this.settings.xaxisstep, + "yaxisstep": this.settings.yaxisstep, + "xaxislabel": this.settings.xlabel, + "yaxislabel": this.settings.ylabel, + "logscalex": this.settings.logscalex, + "linewidth": this.settings.linewidth, + "showxgrad": this.settings.showxgrad, + "showygrad": this.settings.showygrad, + "textsize": this.settings.textsize, + "history": History.serialize(), + "width": this.rootElement.width, + "height": this.rootElement.height, + "objects": objs, + "type": "logplotv1" } Helper.write(filename, JSON.stringify(settings)) - this.alert.show(qsTranslate('io', "Saved plot to '%1'.").arg(filename.split("/").pop())) - Modules.History.history.saved = true + this.alert.show(qsTranslate("io", "Saved plot to '%1'.").arg(filename.split("/").pop())) + History.history.saved = true } /** @@ -91,16 +94,16 @@ class IOAPI extends Module { */ loadDiagram(filename) { let basename = filename.split("/").pop() - this.alert.show(qsTranslate('io', "Loading file '%1'.").arg(basename)) + this.alert.show(qsTranslate("io", "Loading file '%1'.").arg(basename)) let data = JSON.parse(Helper.load(filename)) - let error = ""; + let error = "" if(Object.keys(data).includes("type") && data["type"] === "logplotv1") { - Modules.History.clear() + History.clear() // Importing settings this.settings.saveFilename = filename this.settings.xzoom = parseFloat(data["xzoom"]) || 100 this.settings.yzoom = parseFloat(data["yzoom"]) || 10 - this.settings.xmin = parseFloat(data["xmin"]) || 5/10 + this.settings.xmin = parseFloat(data["xmin"]) || 5 / 10 this.settings.ymax = parseFloat(data["ymax"]) || 24 this.settings.xaxisstep = data["xaxisstep"] || "4" this.settings.yaxisstep = data["yaxisstep"] || "4" @@ -119,51 +122,53 @@ class IOAPI extends Module { this.rootElement.width = parseFloat(data["width"]) || 1000 // Importing objects - Modules.Objects.currentObjects = {} - for(let key of Object.keys(Modules.Objects.currentObjectsByName)) { - delete Modules.Objects.currentObjectsByName[key]; + Objects.currentObjects = {} + for(let key of Object.keys(Objects.currentObjectsByName)) { + delete Objects.currentObjectsByName[key] // Required to keep the same reference for the copy of the object used in expression variable detection. // Another way would be to change the reference as well, but I feel like the code would be less clean. } - for(let objType in data['objects']) { - if(Object.keys(Modules.Objects.types).indexOf(objType) > -1) { - Modules.Objects.currentObjects[objType] = [] - for(let objData of data['objects'][objType]) { + for(let objType in data["objects"]) { + if(Object.keys(Objects.types).indexOf(objType) > -1) { + Objects.currentObjects[objType] = [] + for(let objData of data["objects"][objType]) { /** @type {DrawableObject} */ - let obj = Modules.Objects.types[objType].import(...objData) - Modules.Objects.currentObjects[objType].push(obj) - Modules.Objects.currentObjectsByName[obj.name] = obj + let obj = Objects.types[objType].import(...objData) + Objects.currentObjects[objType].push(obj) + Objects.currentObjectsByName[obj.name] = obj } } else { - error += qsTranslate('io', "Unknown object type: %1.").arg(objType) + "\n"; + error += qsTranslate("io", "Unknown object type: %1.").arg(objType) + "\n" } } // Updating object dependencies. - for(let objName in Modules.Objects.currentObjectsByName) - Modules.Objects.currentObjectsByName[objName].update() + for(let objName in Objects.currentObjectsByName) + Objects.currentObjectsByName[objName].update() // Importing history if("history" in data) - Modules.History.unserialize(...data["history"]) + History.unserialize(...data["history"]) // Refreshing sidebar this.rootElement.updateObjectsLists() } else { - error = qsTranslate('io', "Invalid file provided.") + error = qsTranslate("io", "Invalid file provided.") } if(error !== "") { console.log(error) - this.alert.show(qsTranslate('io', "Could not save file: ") + error) + this.alert.show(qsTranslate("io", "Could not save file: ") + error) // TODO: Error handling return } - Modules.Canvas.redraw() - this.alert.show(qsTranslate('io', "Loaded file '%1'.").arg(basename)) - Modules.History.history.saved = true + Canvas.redraw() + this.alert.show(qsTranslate("io", "Loaded file '%1'.").arg(basename)) + History.history.saved = true } } /** @type {IOAPI} */ Modules.IO = Modules.IO || new IOAPI() + +export default Modules.IO \ No newline at end of file diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/latex.mjs similarity index 99% rename from LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.mjs rename to LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/latex.mjs index ad4c1f2..32f048b 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/latex.mjs @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import { Module } from "../modules.mjs" +import { Module } from "./common.mjs" import * as Instruction from "../lib/expr-eval/instruction.mjs" import { escapeValue } from "../lib/expr-eval/expression.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/objects.mjs similarity index 98% rename from LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.mjs rename to LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/objects.mjs index ef45429..5a63386 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objects.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/objects.mjs @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -import { Module } from './modules.mjs' -import { textsub } from './utils.mjs' +import { Module } from './common.mjs' +import { textsub } from '../utils.mjs' class ObjectsAPI extends Module { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/preferences.mjs similarity index 87% rename from LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences.mjs rename to LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/preferences.mjs index 40ac532..e76596e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/module/preferences.mjs @@ -15,10 +15,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -import {Module} from "modules.mjs" -import General from "preferences/general.mjs" -import Editor from "preferences/expression.mjs" -import DefaultGraph from "preferences/default.mjs" +import {Module} from "./common.mjs" +import General from "../preferences/general.mjs" +import Editor from "../preferences/expression.mjs" +import DefaultGraph from "../preferences/default.mjs" class PreferencesAPI extends Module { constructor() { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/autoload.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/autoload.mjs index cf0df63..a7351b5 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/autoload.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/autoload.mjs @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -import Objects from "../objects.mjs" +import Objects from "../module/objects.mjs" import { DrawableObject } from "common.mjs" import Point from "point.mjs" import Text from "text.mjs" @@ -43,7 +43,7 @@ function registerObject(obj) { } } -if(Object.keys(Modules.Objects.types).length === 0) { +if(Object.keys(Objects.types).length === 0) { registerObject(Point) registerObject(Text) registerObject(Function) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs index c01bcae..05e1150 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitude.mjs @@ -17,17 +17,15 @@ */ import { parseDomain, executeExpression, Expression, EmptySet, Domain } from "../mathlib.mjs" +import { CreateNewObject } from "../historylib.mjs" import * as P from "../parameters.mjs" -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" +import History from "../module/history.mjs" import { ExecutableObject } from "common.mjs" import Function from "function.mjs" -import { API as HistoryAPI } from "../history/common.mjs" -import { CreateNewObject } from "../historylib.mjs" - - export default class BodeMagnitude extends ExecutableObject { static type(){return 'Gain Bode'} static displayType(){return qsTranslate("bodemagnitude", 'Bode Magnitude')} @@ -52,7 +50,7 @@ export default class BodeMagnitude extends ExecutableObject { if(om_0 == null) { // Create new point om_0 = Objects.createNewRegisteredObject('Point', [Objects.getNewName('ω'), true, this.color, 'name']) - HistoryAPI.addToHistory(new CreateNewObject(om_0.name, 'Point', om_0.export())) + History.addToHistory(new CreateNewObject(om_0.name, 'Point', om_0.export())) om_0.update() labelPosition = 'below' } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs index 82bf6b6..4531bee 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodemagnitudesum.mjs @@ -18,8 +18,8 @@ import { Range, Expression, Domain } from "../mathlib.mjs" import * as P from "../parameters.mjs" -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import { ExecutableObject } from "common.mjs" import Function from "function.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs index 23119ef..cce63fa 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephase.mjs @@ -17,11 +17,11 @@ */ import { executeExpression, Expression } from "../mathlib.mjs" -import * as P from "../parameters.mjs" -import Objects from "../objects.mjs" -import { API as HistoryAPI } from "../history/common.mjs" import { CreateNewObject } from "../historylib.mjs" -import Latex from "../math/latex.mjs" +import * as P from "../parameters.mjs" +import Objects from "../module/objects.mjs" +import History from "../module/history.mjs" +import Latex from "../module/latex.mjs" import { ExecutableObject } from "common.mjs" @@ -52,7 +52,7 @@ export default class BodePhase extends ExecutableObject { // Create new point om_0 = Objects.createNewRegisteredObject('Point', [Objects.getNewName('ω'), this.color, 'name']) om_0.labelPosition = this.phase.execute() >= 0 ? 'above' : 'below' - HistoryAPI.history.addToHistory(new CreateNewObject(om_0.name, 'Point', om_0.export())) + History.history.addToHistory(new CreateNewObject(om_0.name, 'Point', om_0.export())) labelPosition = 'below' } om_0.requiredBy.push(this) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs index 1f1a0fa..d55a29c 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/bodephasesum.mjs @@ -18,8 +18,8 @@ import { executeExpression, Expression } from "../mathlib.mjs" import * as P from "../parameters.mjs" -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import { ExecutableObject } from "common.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.mjs index b27cbf3..9b13fbd 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.mjs @@ -17,8 +17,8 @@ */ import { getRandomColor, textsub } from "../utils.mjs" -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import {ensureTypeSafety, serializesByPropertyType} from "../parameters.mjs" // This file contains the default data to be imported from all other objects diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs index e0fe698..1ad9a7e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/distribution.mjs @@ -17,8 +17,8 @@ */ import * as P from "../parameters.mjs" -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import { ExecutableObject } from "common.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs index eb3f081..31afc37 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/function.mjs @@ -17,11 +17,11 @@ */ import { textsub } from "../utils.mjs" -import Objects from "../objects.mjs" +import Objects from "../module/objects.mjs" import { ExecutableObject } from "common.mjs" import { parseDomain, Expression, SpecialDomain } from "../mathlib.mjs" import * as P from "../parameters.mjs" -import Latex from "../math/latex.mjs" +import Latex from "../module/latex.mjs" export default class Function extends ExecutableObject { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.mjs index 503026e..7264894 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/point.mjs @@ -18,8 +18,8 @@ import { Expression } from "../mathlib.mjs" import * as P from "../parameters.mjs" -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import { DrawableObject } from "common.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs index b05a66e..5d431af 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/sequence.mjs @@ -18,8 +18,8 @@ import { Sequence as MathSequence, Domain } from "../mathlib.mjs" import * as P from "../parameters.mjs" -import Latex from "../math/latex.mjs" -import Objects from "../objects.mjs" +import Latex from "../module/latex.mjs" +import Objects from "../module/objects.mjs" import { ExecutableObject } from "common.mjs" import Function from "function.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs index 3ad1e82..a819d7a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/text.mjs @@ -18,8 +18,8 @@ import { Expression } from "../mathlib.mjs" import * as P from "../parameters.mjs" -import Objects from "../objects.mjs" -import Latex from "../math/latex.mjs" +import Objects from "../module/objects.mjs" +import Latex from "../module/latex.mjs" import { DrawableObject } from "common.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs index f377a74..63c85d3 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.mjs @@ -18,8 +18,8 @@ import { Expression } from "../mathlib.mjs" import * as P from "../parameters.mjs" -import Latex from "../math/latex.mjs" -import Objects from "../objects.mjs" +import Latex from "../module/latex.mjs" +import Objects from "../module/objects.mjs" import { DrawableObject } from "common.mjs" diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs index f59c322..6cd9e04 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/parameters.mjs @@ -16,6 +16,7 @@ * along with this program. If not, see . */ import {parseDomain, Expression as Expr, Domain} from "./mathlib.mjs" +import Objects from "./module/objects.mjs" const NONE = class Empty {} @@ -129,8 +130,8 @@ export class ObjectType extends PropertyType { parse(name) { let result = NONE - if(typeof name == 'string' && name in Modules.Objects.currentObjectsByName) { - let obj = Modules.Objects.currentObjectsByName[name] + if(typeof name == 'string' && name in Objects.currentObjectsByName) { + let obj = Objects.currentObjectsByName[name] if (obj.type === this.objType || (this.objType === 'ExecutableObject' && obj.execute)) { result = obj } else { @@ -174,15 +175,15 @@ export class List extends PropertyType { parse(value) { let result = NONE if(typeof value == 'object' && value.__proto__ === Array) { - let list = [] + let valid = 0 for(let v of value) { if (this.format.test(v)) { v = stringValuesValidators[this.valueType][0](v) if(stringValuesValidators[this.valueType][1](v)) - list.append(v) + valid++ } } - if(list.length === value.length) + if(valid === value.length) // Ensure every value is valid. result = value } return result diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/general.mjs b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/general.mjs index eb47e4a..2c5ef17 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/general.mjs +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/preferences/general.mjs @@ -17,6 +17,8 @@ */ 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"), @@ -38,8 +40,8 @@ class EnableLatex extends BoolSetting { set(value) { if(!value || Latex.checkLatexInstallation()) { super.set(value) - Modules.Latex.enabled = value - Modules.Canvas.requestPaint() + LatexAPI.enabled = value + Canvas.requestPaint() } } }