2022-01-31 19:17:24 +00:00
|
|
|
/**
|
2022-03-05 16:49:35 +00:00
|
|
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
2022-01-31 19:17:24 +00:00
|
|
|
* Copyright (C) 2022 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
.pragma library
|
|
|
|
|
|
|
|
.import "../objects.js" as Objects
|
2022-10-19 15:29:35 +00:00
|
|
|
.import "../math/latex.js" as Latex
|
2022-01-31 19:17:24 +00:00
|
|
|
.import "../mathlib.js" as MathLib
|
|
|
|
.import "../objs/common.js" as Common
|
|
|
|
.import "common.js" as C
|
|
|
|
|
|
|
|
class EditedProperty extends C.Action {
|
|
|
|
// Action used everytime an object's property has been changed
|
|
|
|
type(){return 'EditedProperty'}
|
|
|
|
|
|
|
|
icon(){return 'modify'}
|
|
|
|
|
2022-01-31 22:07:00 +00:00
|
|
|
color(darkVer=false){
|
|
|
|
return darkVer ? 'darkslateblue' : 'cyan';
|
|
|
|
}
|
2022-01-31 19:17:24 +00:00
|
|
|
|
|
|
|
constructor(targetName = "", targetType = "Point", targetProperty = "visible", previousValue = false, newValue = true, valueIsExpressionNeedingImport = false) {
|
|
|
|
super(targetName, targetType)
|
|
|
|
this.targetProperty = targetProperty
|
|
|
|
this.targetPropertyReadable = qsTranslate("prop", this.targetProperty)
|
|
|
|
this.previousValue = previousValue
|
|
|
|
this.newValue = newValue
|
|
|
|
this.propertyType = Objects.types[targetType].properties()[targetProperty]
|
|
|
|
if(valueIsExpressionNeedingImport) {
|
|
|
|
if(this.propertyType == "Expression") {
|
|
|
|
this.previousValue = new MathLib.Expression(this.previousValue);
|
|
|
|
this.newValue = new MathLib.Expression(this.newValue);
|
|
|
|
} else if(this.propertyType == "Domain") {
|
|
|
|
this.previousValue = MathLib.parseDomain(this.previousValue);
|
|
|
|
this.newValue = MathLib.parseDomain(this.newValue);
|
|
|
|
} else {
|
|
|
|
// Objects
|
2022-10-17 18:25:29 +00:00
|
|
|
this.previousValue = Objects.currentObjectsByName[this.previousValue] // Objects.getObjectByName(this.previousValue);
|
|
|
|
this.newValue = Objects.currentObjectsByName[this.newValue] // Objects.getObjectByName(this.newValue);
|
2022-01-31 19:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-31 22:07:00 +00:00
|
|
|
this.setReadableValues()
|
2022-01-31 19:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
undo() {
|
2022-10-17 18:25:29 +00:00
|
|
|
Objects.currentObjectsByName[this.targetName][this.targetProperty] = this.previousValue
|
2022-10-17 22:45:53 +00:00
|
|
|
Objects.currentObjectsByName[this.targetName].update()
|
2022-01-31 19:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
redo() {
|
2022-10-17 18:25:29 +00:00
|
|
|
Objects.currentObjectsByName[this.targetName][this.targetProperty] = this.newValue
|
2022-10-17 22:45:53 +00:00
|
|
|
Objects.currentObjectsByName[this.targetName].update()
|
2022-01-31 19:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export() {
|
|
|
|
if(this.previousValue instanceof MathLib.Expression) {
|
|
|
|
return [this.targetName, this.targetType, this.targetProperty, this.previousValue.toEditableString(), this.newValue.toEditableString(), true]
|
|
|
|
} else if(this.previousValue instanceof Common.DrawableObject) {
|
|
|
|
return [this.targetName, this.targetType, this.targetProperty, this.previousValue.name, this.newValue.name, true]
|
|
|
|
} else {
|
|
|
|
return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-31 22:07:00 +00:00
|
|
|
setReadableValues() {
|
2022-10-19 15:29:35 +00:00
|
|
|
this.prevString = "";
|
|
|
|
this.nextString = "";
|
2022-01-31 19:17:24 +00:00
|
|
|
if(this.propertyType instanceof Object) {
|
|
|
|
switch(this.propertyType.type) {
|
|
|
|
case "Enum":
|
2022-10-19 15:29:35 +00:00
|
|
|
this.prevString = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.previousValue)]
|
|
|
|
this.nextString = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.newValue)]
|
2022-01-31 19:17:24 +00:00
|
|
|
break;
|
|
|
|
case "ObjectType":
|
2022-10-19 15:29:35 +00:00
|
|
|
this.prevString = this.previousValue == null ? "null" : this.previousValue.name
|
|
|
|
this.nextString = this.newValue == null ? "null" : this.newValue.name
|
2022-01-31 19:17:24 +00:00
|
|
|
break;
|
|
|
|
case "List":
|
2022-10-19 15:29:35 +00:00
|
|
|
this.prevString = this.previousValue.join(",")
|
|
|
|
this.nextString = this.newValue.name.join(",")
|
2022-01-31 19:17:24 +00:00
|
|
|
break;
|
|
|
|
case "Dict":
|
2022-10-19 15:29:35 +00:00
|
|
|
this.prevString = JSON.stringify(this.previousValue)
|
|
|
|
this.nextString = JSON.stringify(this.newValue)
|
2022-01-31 19:17:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2022-10-19 15:29:35 +00:00
|
|
|
this.prevString = this.previousValue == null ? "null" : this.previousValue.toString()
|
|
|
|
this.nextString = this.newValue == null ? "null" : this.newValue.toString()
|
|
|
|
}
|
|
|
|
// HTML
|
|
|
|
this.prevHTML = '<tt style="background: rgba(128,128,128,0.1);"> '+this.prevString+' </tt>'
|
|
|
|
this.nextHTML = '<tt style="background: rgba(128,128,128,0.1);"> '+this.nextString+' </tt>'
|
|
|
|
if(Latex.enabled && this.propertyType == "Expression") {
|
|
|
|
this.prevHTML= this.renderLatexAsHtml(this.previousValue.latexMarkup)
|
|
|
|
this.nextHTML= this.renderLatexAsHtml(this.newValue.latexMarkup)
|
2022-01-31 19:17:24 +00:00
|
|
|
}
|
2022-01-31 22:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getReadableString() {
|
2022-01-31 19:17:24 +00:00
|
|
|
return qsTr('%1 of %2 %3 changed from "%4" to "%5".')
|
|
|
|
.arg(this.targetPropertyReadable)
|
|
|
|
.arg(Objects.types[this.targetType].displayType())
|
2022-10-19 15:29:35 +00:00
|
|
|
.arg(this.targetName).arg(this.prevString).arg(this.nextString)
|
2022-01-31 22:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getHTMLString() {
|
|
|
|
return qsTr('%1 of %2 changed from %3 to %4.')
|
|
|
|
.arg(this.targetPropertyReadable)
|
|
|
|
.arg('<b style="font-size: 15px;"> ' + this.targetName + ' </b>')
|
2022-10-19 15:29:35 +00:00
|
|
|
.arg(this.prevHTML)
|
|
|
|
.arg(this.nextHTML)
|
2022-01-31 19:17:24 +00:00
|
|
|
}
|
|
|
|
}
|