Compare commits
No commits in common. "1a433eba27f3105023bbae139a0cd240aa94e21a" and "3dc69cc9ba44e2251426b9d5e53b79302d2f0f5f" have entirely different histories.
1a433eba27
...
3dc69cc9ba
21 changed files with 99 additions and 178 deletions
|
@ -249,24 +249,18 @@ ApplicationWindow {
|
|||
|
||||
// Importing objects
|
||||
Objects.currentObjects = {}
|
||||
Objects.currentObjectsByName = {}
|
||||
for(let objType in data['objects']) {
|
||||
for(var objType in data['objects']) {
|
||||
if(Object.keys(Objects.types).indexOf(objType) > -1) {
|
||||
Objects.currentObjects[objType] = []
|
||||
for(let objData of data['objects'][objType]) {
|
||||
let obj = new Objects.types[objType](...objData)
|
||||
for(var objData of data['objects'][objType]) {
|
||||
var obj = new Objects.types[objType](...objData)
|
||||
Objects.currentObjects[objType].push(obj)
|
||||
Objects.currentObjectsByName[obj.name] = obj
|
||||
}
|
||||
} else {
|
||||
error += qsTr("Unknown object type: %1.").arg(objType) + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Updating object dependencies.
|
||||
for(let objName in Objects.currentObjectsByName)
|
||||
Objects.currentObjectsByName[objName].update()
|
||||
|
||||
// Importing history
|
||||
if("history" in data)
|
||||
history.unserialize(...data["history"])
|
||||
|
|
|
@ -74,36 +74,26 @@ D.Dialog {
|
|||
width: objEditor.width - 20
|
||||
spacing: 10
|
||||
|
||||
D.MessageDialog {
|
||||
id: invalidNameDialog
|
||||
title: qsTr("LogarithmPlotter - Invalid object name")
|
||||
text: ""
|
||||
function showDialog(objectName) {
|
||||
text = qsTr("An object with the name '%1' already exists.").arg(objectName)
|
||||
open()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: nameProperty
|
||||
height: 30
|
||||
label: qsTr("Name")
|
||||
icon: "common/label.svg"
|
||||
min: 1
|
||||
width: dlgProperties.width
|
||||
value: objEditor.obj.name
|
||||
onChanged: function(newValue) {
|
||||
let newName = Utils.parseName(newValue)
|
||||
var newName = Utils.parseName(newValue)
|
||||
if(newName != '' && objEditor.obj.name != newName) {
|
||||
if(newName in Objects.currentObjectsByName) {
|
||||
invalidNameDialog.showDialog(newName)
|
||||
} else {
|
||||
history.addToHistory(new HistoryLib.NameChanged(
|
||||
objEditor.obj.name, objEditor.objType, newName
|
||||
))
|
||||
Objects.renameObject(obj.name, newName)
|
||||
objEditor.obj = Objects.currentObjects[objEditor.objType][objEditor.objIndex]
|
||||
objectListList.update()
|
||||
if(Objects.getObjectByName(newName) != null) {
|
||||
newName = ObjectsCommons.getNewName(newName)
|
||||
}
|
||||
history.addToHistory(new HistoryLib.NameChanged(
|
||||
objEditor.obj.name, objEditor.objType, newName
|
||||
))
|
||||
Objects.currentObjects[objEditor.objType][objEditor.objIndex].name = newName
|
||||
objEditor.obj = Objects.currentObjects[objEditor.objType][objEditor.objIndex]
|
||||
objectListList.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +213,7 @@ D.Dialog {
|
|||
[]) :
|
||||
modelData[1].values)
|
||||
: []
|
||||
// Translated version of the model.
|
||||
// Translated verison of the model.
|
||||
model: selectObjMode ? baseModel : modelData[1].translatedValues
|
||||
visible: paramTypeIn(modelData[1], ['ObjectType', 'Enum'])
|
||||
currentIndex: baseModel.indexOf(selectObjMode ? objEditor.obj[modelData[0]].name : objEditor.obj[modelData[0]])
|
||||
|
@ -232,7 +222,7 @@ D.Dialog {
|
|||
if(selectObjMode) {
|
||||
// This is only done when what we're selecting are Objects.
|
||||
// Setting object property.
|
||||
var selectedObj = Objects.currentObjectsByName[baseModel[newIndex]]
|
||||
var selectedObj = Objects.getObjectByName(baseModel[newIndex], modelData[1].objType)
|
||||
if(newIndex != 0) {
|
||||
// Make sure we don't set the object to null.
|
||||
if(selectedObj == null) {
|
||||
|
|
|
@ -193,7 +193,8 @@ ScrollView {
|
|||
history.addToHistory(new HistoryLib.DeleteObject(
|
||||
obj.name, objType, obj.export()
|
||||
))
|
||||
Objects.deleteObject(obj.name)
|
||||
Objects.currentObjects[objType][index].delete()
|
||||
Objects.currentObjects[objType].splice(index, 1)
|
||||
objectListList.update()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ Item {
|
|||
'Expression': () => new MathLib.Expression(newValue),
|
||||
'number': () => parseFloat(newValue)
|
||||
}[Objects.types[objType].properties()[propertyX]]()
|
||||
let obj = Objects.currentObjectsByName[objName] // getObjectByName(objName, objType)
|
||||
let obj = Objects.getObjectByName(objName, objType)
|
||||
history.addToHistory(new HistoryLib.EditedProperty(
|
||||
objName, objType, propertyX, obj[propertyX], newValue
|
||||
))
|
||||
|
@ -112,7 +112,7 @@ Item {
|
|||
'Expression': () => new MathLib.Expression(newValue),
|
||||
'number': () => parseFloat(newValue)
|
||||
}[Objects.types[objType].properties()[propertyY]]()
|
||||
let obj = Objects.currentObjectsByName[objName] // Objects.getObjectByName(objName, objType)
|
||||
let obj = Objects.getObjectByName(objName, objType)
|
||||
history.addToHistory(new HistoryLib.EditedProperty(
|
||||
objName, objType, propertyY, obj[propertyY], newValue
|
||||
))
|
||||
|
|
|
@ -194,7 +194,6 @@ function evaluate(tokens, expr, values) {
|
|||
nstack.push(f(resolveExpression(n1, values), resolveExpression(n2, values), resolveExpression(n3, values)));
|
||||
}
|
||||
} else if (type === IVAR) {
|
||||
// Check for variable value
|
||||
if (item.value in expr.functions) {
|
||||
nstack.push(expr.functions[item.value]);
|
||||
} else if (item.value in expr.unaryOps && expr.parser.isOperatorEnabled(item.value)) {
|
||||
|
@ -220,11 +219,8 @@ function evaluate(tokens, expr, values) {
|
|||
f = nstack.pop();
|
||||
if (f.apply && f.call) {
|
||||
nstack.push(f.apply(undefined, args));
|
||||
} else if(f.execute) {
|
||||
// Objects & expressions execution
|
||||
nstack.push(f.execute.apply(f, args));
|
||||
} else {
|
||||
throw new Error(f + ' cannot be executed');
|
||||
throw new Error(f + ' is not a function');
|
||||
}
|
||||
} else if (type === IFUNDEF) {
|
||||
// Create closure to keep references to arguments and expression
|
||||
|
|
|
@ -36,11 +36,9 @@ class CreateNewObject extends C.Action {
|
|||
|
||||
|
||||
undo() {
|
||||
Objects.deleteObject(this.targetName)
|
||||
//let targetIndex = Objects.getObjectsName(this.targetType).indexOf(this.targetName)
|
||||
//delete Objects.currentObjectsByName[this.targetName]
|
||||
//Objects.currentObjects[this.targetType][targetIndex].delete()
|
||||
//Objects.currentObjects[this.targetType].splice(targetIndex, 1)
|
||||
var targetIndex = Objects.getObjectsName(this.targetType).indexOf(this.targetName)
|
||||
Objects.currentObjects[this.targetType][targetIndex].delete()
|
||||
Objects.currentObjects[this.targetType].splice(targetIndex, 1)
|
||||
}
|
||||
|
||||
redo() {
|
||||
|
|
|
@ -49,21 +49,19 @@ class EditedProperty extends C.Action {
|
|||
this.newValue = MathLib.parseDomain(this.newValue);
|
||||
} else {
|
||||
// Objects
|
||||
this.previousValue = Objects.currentObjectsByName[this.previousValue] // Objects.getObjectByName(this.previousValue);
|
||||
this.newValue = Objects.currentObjectsByName[this.newValue] // Objects.getObjectByName(this.newValue);
|
||||
this.previousValue = Objects.getObjectByName(this.previousValue);
|
||||
this.newValue = Objects.getObjectByName(this.newValue);
|
||||
}
|
||||
}
|
||||
this.setReadableValues()
|
||||
}
|
||||
|
||||
undo() {
|
||||
Objects.currentObjectsByName[this.targetName][this.targetProperty] = this.previousValue
|
||||
Objects.currentObjectsByName[this.targetName].update()
|
||||
Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.previousValue
|
||||
}
|
||||
|
||||
redo() {
|
||||
Objects.currentObjectsByName[this.targetName][this.targetProperty] = this.newValue
|
||||
Objects.currentObjectsByName[this.targetName].update()
|
||||
Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.newValue
|
||||
}
|
||||
|
||||
export() {
|
||||
|
|
|
@ -40,15 +40,11 @@ class NameChanged extends EP.EditedProperty {
|
|||
}
|
||||
|
||||
undo() {
|
||||
Objects.renameObject(this.newValue, this.previousValue)
|
||||
Objects.getObjectByName(this.newValue, this.targetType)['name'] = this.previousValue
|
||||
}
|
||||
|
||||
redo() {
|
||||
Objects.renameObject(this.previousValue, this.newValue)
|
||||
//let obj = Objects.currentObjectsByName[this.previousValue]
|
||||
//obj.name = this.newValue
|
||||
//Objects.currentObjectsByName[this.newValue] = obj
|
||||
//delete Objects.currentObjectsByName[this.previousValue]
|
||||
Objects.getObjectByName(this.previousValue, this.targetType)['name'] = this.newValue
|
||||
}
|
||||
|
||||
getReadableString() {
|
||||
|
|
|
@ -22,9 +22,7 @@
|
|||
.import "../utils.js" as Utils
|
||||
.import "latex.js" as Latex
|
||||
|
||||
const DERIVATION_PRECISION = 0.1
|
||||
|
||||
var evalVariables = { // Variables not provided by expr-eval.js, needs to be provided manually
|
||||
var evalVariables = { // Variables not provided by expr-eval.js, needs to be provided manualy
|
||||
"pi": Math.PI,
|
||||
"π": Math.PI,
|
||||
"inf": Infinity,
|
||||
|
@ -35,21 +33,18 @@ var evalVariables = { // Variables not provided by expr-eval.js, needs to be pro
|
|||
}
|
||||
|
||||
var currentVars = {}
|
||||
var currentObjectsByName = {} // Mirror of currentObjectsByName in objects.js
|
||||
|
||||
const parser = new ExprEval.Parser()
|
||||
|
||||
parser.consts = Object.assign({}, parser.consts, evalVariables)
|
||||
|
||||
// Function definition
|
||||
parser.functions.integral = function(a, b, f, variable) {
|
||||
// https://en.wikipedia.org/wiki/Simpson%27s_rule
|
||||
// Simpler, faster than tokenizing the expression
|
||||
f = parser.parse(f).toJSFunction(variable, currentVars)
|
||||
return (b-a)/6*(f(a)+4*f((a+b)/2)+f(b))
|
||||
}
|
||||
|
||||
const DERIVATION_PRECISION = 0.1
|
||||
|
||||
parser.functions.derivative = function(f, variable, x) {
|
||||
f = parser.parse(f).toJSFunction(variable, currentVars)
|
||||
return (f(x+DERIVATION_PRECISION/2)-f(x-DERIVATION_PRECISION/2))/DERIVATION_PRECISION
|
||||
}
|
||||
|
||||
|
|
|
@ -30,42 +30,23 @@ class Expression {
|
|||
this.expr = expr
|
||||
this.calc = C.parser.parse(expr).simplify()
|
||||
this.cached = this.isConstant()
|
||||
this.cachedValue = this.cached && this.allRequirementsFullfilled() ? this.calc.evaluate(C.currentObjectsByName) : null
|
||||
this.cachedValue = this.cached ? this.calc.evaluate(C.evalVariables) : null
|
||||
this.latexMarkup = Latex.expression(this.calc.tokens)
|
||||
}
|
||||
|
||||
isConstant() {
|
||||
let vars = this.calc.variables()
|
||||
return !vars.includes("x") && !vars.includes("n")
|
||||
}
|
||||
|
||||
requiredObjects() {
|
||||
return this.calc.variables().filter(objName => objName != "x" && objName != "n")
|
||||
}
|
||||
|
||||
allRequirementsFullfilled() {
|
||||
return this.requiredObjects().every(objName => objName in C.currentObjectsByName)
|
||||
}
|
||||
|
||||
recache() {
|
||||
if(this.cached)
|
||||
this.cachedValue = this.calc.evaluate(C.currentObjectsByName)
|
||||
return !this.expr.includes("x") && !this.expr.includes("n")
|
||||
}
|
||||
|
||||
execute(x = 1) {
|
||||
if(this.cached) {
|
||||
if(this.cachedValue == null)
|
||||
this.cachedValue = this.calc.evaluate(C.currentObjectsByName)
|
||||
return this.cachedValue
|
||||
}
|
||||
C.currentVars = Object.assign({'x': x}, C.currentObjectsByName)
|
||||
//console.log("Executing", this.expr, "with", JSON.stringify(C.currentVars))
|
||||
if(this.cached) return this.cachedValue
|
||||
C.currentVars = Object.assign({'x': x}, C.evalVariables)
|
||||
return this.calc.evaluate(C.currentVars)
|
||||
}
|
||||
|
||||
simplify(x) {
|
||||
var expr = this.calc.substitute('x', x).simplify()
|
||||
if(expr.evaluate() == 0) return '0'
|
||||
if(expr.evaluate(C.evalVariables) == 0) return '0'
|
||||
var str = Utils.makeExpressionReadable(expr.toString());
|
||||
if(str != undefined && str.match(/^\d*\.\d+$/)) {
|
||||
if(str.split('.')[1].split('0').length > 7) {
|
||||
|
@ -85,7 +66,7 @@ class Expression {
|
|||
}
|
||||
|
||||
toString(forceSign=false) {
|
||||
let str = Utils.makeExpressionReadable(this.calc.toString())
|
||||
var str = Utils.makeExpressionReadable(this.calc.toString())
|
||||
if(str[0] != '-' && forceSign) str = '+' + str
|
||||
return str
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class Sequence extends Expr.Expression {
|
|||
if(['string', 'number'].includes(typeof this.calcValues[n])) {
|
||||
let parsed = C.parser.parse(this.calcValues[n].toString()).simplify()
|
||||
this.latexValues[n] = Latex.expression(parsed.tokens)
|
||||
this.calcValues[n] = parsed.evaluate()
|
||||
this.calcValues[n] = parsed.evaluate(C.evalVariables)
|
||||
}
|
||||
this.valuePlus = parseInt(valuePlus)
|
||||
}
|
||||
|
@ -65,10 +65,9 @@ class Sequence extends Expr.Expression {
|
|||
cache(n = 1) {
|
||||
var str = Utils.simplifyExpression(this.calc.substitute('n', n-this.valuePlus).toString())
|
||||
var expr = C.parser.parse(str).simplify()
|
||||
C.currentVars = Object.assign(
|
||||
{'n': n-this.valuePlus, [this.name]: this.calcValues}, // Just in case, add n (for custom functions)
|
||||
C.currentObjectsByName
|
||||
)
|
||||
var l = {'n': n-this.valuePlus} // Just in case, add n (for custom functions)
|
||||
l[this.name] = this.calcValues
|
||||
C.currentVars = Object.assign(l, C.evalVariables)
|
||||
this.calcValues[n] = expr.evaluate(C.currentVars)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,44 +19,36 @@
|
|||
.pragma library
|
||||
|
||||
.import "utils.js" as Utils
|
||||
.import "math/common.js" as MathCommons
|
||||
.import "mathlib.js" as MathLib
|
||||
.import "parameters.js" as P
|
||||
|
||||
var types = {}
|
||||
|
||||
var currentObjects = {}
|
||||
var currentObjectsByName = {}
|
||||
MathCommons.currentObjectsByName = currentObjectsByName // Required for using objects in variables.
|
||||
|
||||
function renameObject(oldName, newName) {
|
||||
/**
|
||||
* Renames an object from its old name to the new one.
|
||||
* @param {string} oldName - Current name of the object.
|
||||
* @param {string} newName - Name to rename the object to.
|
||||
*/
|
||||
let obj = currentObjectsByName[oldName]
|
||||
delete currentObjectsByName[oldName]
|
||||
currentObjectsByName[newName] = obj
|
||||
obj.name = newName
|
||||
}
|
||||
|
||||
function deleteObject(objName) {
|
||||
/**
|
||||
* Deletes an object by its given name.
|
||||
* @param {string} objName - Current name of the object.
|
||||
*/
|
||||
let obj = currentObjectsByName[objName]
|
||||
delete currentObjectsByName[objName]
|
||||
currentObjects[obj.type].splice(currentObjects[obj.type].indexOf(obj),1)
|
||||
obj.delete()
|
||||
function getObjectByName(objName, objType = null) {
|
||||
var objectTypes = Object.keys(currentObjects)
|
||||
if(typeof objType == 'string' && objType != "") {
|
||||
if(objType == "ExecutableObject") {
|
||||
objectTypes = getExecutableTypes()
|
||||
} else if(currentObjects[objType] != undefined) {
|
||||
objectTypes = [objType]
|
||||
}
|
||||
}
|
||||
if(Array.isArray(objType)) objectTypes = objType
|
||||
var retObj = null
|
||||
if(objName != "" && objName != null) {
|
||||
objectTypes.forEach(function(objType){
|
||||
if(currentObjects[objType] == undefined) return null
|
||||
currentObjects[objType].forEach(function(obj){
|
||||
if(obj.name == objName) retObj = obj
|
||||
})
|
||||
})
|
||||
}
|
||||
return retObj
|
||||
}
|
||||
|
||||
function getObjectsName(objType) {
|
||||
/**
|
||||
* Gets a list of all names of a certain object type.
|
||||
* @param {string} objType - Type of the object to query. Can be ExecutableObject for all ExecutableObjects.
|
||||
* @return {array} List of names of the objects.
|
||||
*/
|
||||
if(objType == "ExecutableObject") {
|
||||
var types = getExecutableTypes()
|
||||
var elementNames = ['']
|
||||
|
@ -70,26 +62,15 @@ function getObjectsName(objType) {
|
|||
}
|
||||
|
||||
function getExecutableTypes() {
|
||||
/**
|
||||
* Returns a list of all object types which are executable objects.
|
||||
* @return {array} List of all object types which are executable objects.
|
||||
*/
|
||||
return Object.keys(currentObjects).filter(objType => types[objType].executable())
|
||||
}
|
||||
|
||||
function createNewRegisteredObject(objType, args=[]) {
|
||||
/**
|
||||
* Creates and register an object in the database.
|
||||
* @param {string} objType - Type of the object to create.
|
||||
* @param {string} args - List of arguments for the objects (can be empty).
|
||||
* @return {[objType]} Newly created object.
|
||||
*/
|
||||
if(Object.keys(types).indexOf(objType) == -1) return null // Object type does not exist.
|
||||
var newobj = new types[objType](...args)
|
||||
if(Object.keys(currentObjects).indexOf(objType) == -1) {
|
||||
currentObjects[objType] = []
|
||||
}
|
||||
currentObjects[objType].push(newobj)
|
||||
currentObjectsByName[newobj.name] = newobj
|
||||
return newobj
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
.import "../utils.js" as Utils
|
||||
.import "../objects.js" as Objects
|
||||
.import "../math/latex.js" as Latex
|
||||
.import "../parameters.js" as P
|
||||
.import "../math/common.js" as C
|
||||
|
||||
// This file contains the default data to be imported from all other objects
|
||||
|
||||
|
@ -42,7 +40,7 @@ function getNewName(allowedLetters) {
|
|||
var num = Math.floor((newid - (newid % allowedLetters.length)) / allowedLetters.length)
|
||||
ret = letter + (num > 0 ? Utils.textsub(num-1) : '')
|
||||
newid += 1
|
||||
} while(ret in Objects.currentObjectsByName)
|
||||
} while(Objects.getObjectByName(ret) != null)
|
||||
return ret
|
||||
}
|
||||
|
||||
|
@ -118,7 +116,6 @@ class DrawableObject {
|
|||
this.color = color
|
||||
this.labelContent = labelContent // "null", "name", "name + value"
|
||||
this.requiredBy = []
|
||||
this.requires = []
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,40 +187,18 @@ class DrawableObject {
|
|||
* Callback method when one of the properties of the object is updated.
|
||||
*/
|
||||
update() {
|
||||
// Refreshing dependencies.
|
||||
for(let obj of this.requires)
|
||||
obj.requiredBy = obj.requiredBy.filter(dep => dep != this)
|
||||
// Checking objects this one depends on
|
||||
this.requires = []
|
||||
let properties = this.constructor.properties()
|
||||
for(let property in properties)
|
||||
if(properties[property] == 'Expression' && this[property] != null) {
|
||||
// Expressions with dependencies
|
||||
for(let objName of this[property].requiredObjects()) {
|
||||
this.requires.push(C.currentObjectsByName[objName])
|
||||
C.currentObjectsByName[objName].requiredBy.push(this)
|
||||
}
|
||||
if(this[property].cached && this[property].requiredObjects().length > 0)
|
||||
// Recalculate
|
||||
this[property].recache()
|
||||
|
||||
} else if(typeof properties[property] == 'object' && 'type' in properties[property] && properties[property] == 'ObjectType' && this[property] != null) {
|
||||
// Object dependency
|
||||
this.requires.push(this[property])
|
||||
this[property].requiredBy.push(this)
|
||||
}
|
||||
|
||||
// Updating objects dependent on this one
|
||||
for(let req of this.requiredBy)
|
||||
for(var req of this.requiredBy) {
|
||||
req.update()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback method when the object is about to get deleted.
|
||||
*/
|
||||
delete() {
|
||||
for(let toRemove of this.requiredBy) {
|
||||
Objects.deleteObject(toRemove.name)
|
||||
for(var toRemove of this.requiredBy) {
|
||||
toRemove.delete()
|
||||
Objects.currentObjects[toRemove.type] = Objects.currentObjects[toRemove.type].filter(obj => obj.name != toRemove.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,7 +261,7 @@ class DrawableObject {
|
|||
}
|
||||
|
||||
/**
|
||||
* Automatically draw text (by default the label of the object on the \c canvas with
|
||||
* Automaticly draw text (by default the label of the object on the \c canvas with
|
||||
* the 2D context \c ctx depending on user settings.
|
||||
* This method takes into account both the \c posX and \c posY of where the label
|
||||
* should be displayed, including the \c labelPosition relative to it.
|
||||
|
|
|
@ -49,7 +49,7 @@ class GainBode extends Common.ExecutableObject {
|
|||
this.type = 'Gain Bode'
|
||||
if(typeof om_0 == "string") {
|
||||
// Point name or create one
|
||||
om_0 = Objects.currentObjectsByName[om_0]
|
||||
om_0 = Objects.getObjectByName(om_0, 'Point')
|
||||
if(om_0 == null) {
|
||||
// Create new point
|
||||
om_0 = Objects.createNewRegisteredObject('Point')
|
||||
|
|
|
@ -48,7 +48,7 @@ class PhaseBode extends Common.ExecutableObject {
|
|||
this.phase = phase
|
||||
if(typeof om_0 == "string") {
|
||||
// Point name or create one
|
||||
om_0 = Objects.currentObjectsByName[om_0]
|
||||
om_0 = Objects.getObjectByName(om_0, 'Point')
|
||||
if(om_0 == null) {
|
||||
// Create new point
|
||||
om_0 = Objects.createNewRegisteredObject('Point')
|
||||
|
|
|
@ -27,6 +27,14 @@ class RepartitionFunction extends Common.ExecutableObject {
|
|||
static type(){return 'Repartition'}
|
||||
static displayType(){return qsTr('Repartition')}
|
||||
static displayTypeMultiple(){return qsTr('Repartition functions')}
|
||||
/*static properties() {return {
|
||||
'beginIncluded': 'boolean',
|
||||
'drawLineEnds': 'boolean',
|
||||
'comment1': 'Note: Specify the properties for each potential result.',
|
||||
'probabilities': new P.Dictionary('string', 'float', /^-?[\d.,]+$/, /^-?[\d\.,]+$/, 'P({name} = ', ') = '),
|
||||
'labelPosition': new P.Enum('above', 'below', 'left', 'right', 'above-left', 'above-right', 'below-left', 'below-right'),
|
||||
'labelX': 'number'
|
||||
}}*/
|
||||
static properties() {return {
|
||||
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
|
||||
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
|
||||
|
|
|
@ -30,6 +30,10 @@ class SommePhasesBode extends Common.ExecutableObject {
|
|||
static displayType(){return qsTr('Bode Phases Sum')}
|
||||
static displayTypeMultiple(){return qsTr('Bode Phases Sum')}
|
||||
static createable() {return false}
|
||||
/*static properties() {return {
|
||||
'labelPosition': new P.Enum('above', 'below', 'left', 'right', 'above-left', 'above-right', 'below-left', 'below-right'),
|
||||
'labelX': 'number'
|
||||
}}*/
|
||||
static properties() {return {
|
||||
[QT_TRANSLATE_NOOP('prop','labelPosition')]: P.Enum.Position,
|
||||
[QT_TRANSLATE_NOOP('prop','labelX')]: 'number',
|
||||
|
|
|
@ -29,6 +29,12 @@ class Text extends Common.DrawableObject {
|
|||
static type(){return 'Text'}
|
||||
static displayType(){return qsTr('Text')}
|
||||
static displayTypeMultiple(){return qsTr('Texts')}
|
||||
/*static properties() {return {
|
||||
'x': 'Expression',
|
||||
'y': 'Expression',
|
||||
'labelPosition': new P.Enum('center', 'above', 'below', 'left', 'right', 'above-left', 'above-right', 'below-left', 'below-right'),
|
||||
'text': 'string',
|
||||
}}*/
|
||||
static properties() {return {
|
||||
[QT_TRANSLATE_NOOP('prop','x')]: 'Expression',
|
||||
[QT_TRANSLATE_NOOP('prop','y')]: 'Expression',
|
||||
|
|
|
@ -56,7 +56,7 @@ class XCursor extends Common.DrawableObject {
|
|||
this.x = x
|
||||
this.targetElement = targetElement
|
||||
if(typeof targetElement == "string") {
|
||||
this.targetElement = Objects.currentObjectsByName[targetElement]
|
||||
this.targetElement = Objects.getObjectByName(targetElement, elementTypes)
|
||||
}
|
||||
this.labelPosition = labelPosition
|
||||
this.displayStyle = displayStyle
|
||||
|
|
|
@ -129,11 +129,11 @@ function simplifyExpression(str) {
|
|||
var replacements = [
|
||||
// Operations not done by parser.
|
||||
[// Decomposition way 2
|
||||
/(^|[+-] |\()([-.\d\w]+) ([*/]) \((([-.\d\w] [*/] )?[-\d\w.]+) ([+\-]) (([-.\d\w] [*/] )?[\d\w.+]+)\)($| [+-]|\))/g,
|
||||
/(^.?|[+-] |\()([-.\d\w]+) ([*/]) \((([-.\d\w] [*/] )?[-\d\w.]+) ([+\-]) (([-.\d\w] [*/] )?[\d\w.+]+)\)(.?$| [+-]|\))/g,
|
||||
"$1$2 $3 $4 $6 $2 $3 $7$9"
|
||||
],
|
||||
[ // Decomposition way 2
|
||||
/(^|[+-] |\()\((([-.\d\w] [*/] )?[-\d\w.]+) ([+\-]) (([-.\d\w] [*/] )?[\d\w.+]+)\) ([*/]) ([-.\d\w]+)($| [+-]|\))/g,
|
||||
/(^.?|[+-] |\()\((([-.\d\w] [*/] )?[-\d\w.]+) ([+\-]) (([-.\d\w] [*/] )?[\d\w.+]+)\) ([*/]) ([-.\d\w]+)(.?$| [+-]|\))/g,
|
||||
"$1$2 $7 $8 $4 $5 $7 $8$9"
|
||||
],
|
||||
[ // Factorisation of π elements.
|
||||
|
@ -159,19 +159,19 @@ function simplifyExpression(str) {
|
|||
}
|
||||
],
|
||||
[ // Removing parenthesis when content is only added from both sides.
|
||||
/(^|[+-] |\()\(([^)(]+)\)($| [+-]|\))/g,
|
||||
/(^.?|[+-] |\()\(([^)(]+)\)(.?$| [+-]|\))/g,
|
||||
function(match, b4, middle, after) {return `${b4}${middle}${after}`}
|
||||
],
|
||||
[ // Removing parenthesis when content is only multiplied.
|
||||
/(^|[*\/] |\()\(([^)(+-]+)\)($| [*\/+-]|\))/g,
|
||||
/(^.?|[*\/] |\()\(([^)(+-]+)\)(.?$| [*\/+-]|\))/g,
|
||||
function(match, b4, middle, after) {return `${b4}${middle}${after}`}
|
||||
],
|
||||
[ // Removing parenthesis when content is only multiplied.
|
||||
/(^|[*\/-+] |\()\(([^)(+-]+)\)($| [*\/]|\))/g,
|
||||
/(^.?|[*\/-+] |\()\(([^)(+-]+)\)(.?$| [*\/]|\))/g,
|
||||
function(match, b4, middle, after) {return `${b4}${middle}${after}`}
|
||||
],
|
||||
[// Simplification additions/substractions.
|
||||
/(^|[^*\/] |\()([-.\d]+) (\+|\-) (\([^)(]+\)|[^)(]+) (\+|\-) ([-.\d]+)($| [^*\/]|\))/g,
|
||||
/(^.?|[^*\/] |\()([-.\d]+) (\+|\-) (\([^)(]+\)|[^)(]+) (\+|\-) ([-.\d]+)(.?$| [^*\/]|\))/g,
|
||||
function(match, b4, n1, op1, middle, op2, n2, after) {
|
||||
var total
|
||||
if(op2 == '+') {
|
||||
|
@ -258,7 +258,7 @@ function makeExpressionReadable(str) {
|
|||
[/\[([^\[\]]+)\]/g, function(match, p1) { return textsub(p1) }],
|
||||
[/(\d|\))×/g, '$1'],
|
||||
//[/×(\d|\()/g, '$1'],
|
||||
[/[^a-z]\(([^)(+.\/-]+)\)/g, "$1"],
|
||||
[/\(([^)(+.\/-]+)\)/g, "$1"],
|
||||
[/integral\((.+),\s?(.+),\s?("|')(.+)("|'),\s?("|')(.+)("|')\)/g, function(match, a, b, p1, body, p2, p3, by, p4) {
|
||||
if(a.length < b.length) {
|
||||
return `∫${textsub(a)}${textsup(b)} ${body} d${by}`
|
||||
|
|
|
@ -149,7 +149,6 @@ class Helper(QObject):
|
|||
@Slot()
|
||||
def fetchChangelog(self):
|
||||
changelog_cache_path = path.join(path.dirname(path.realpath(__file__)), "CHANGELOG.md")
|
||||
print(changelog_cache_path)
|
||||
if path.exists(changelog_cache_path):
|
||||
# We have a cached version of the changelog, for env that don't have access to the internet.
|
||||
f = open(changelog_cache_path);
|
||||
|
|
Loading…
Reference in a new issue