Skip to content

Commit

Permalink
# Stopcontact overgezet van Keys naar Props
Browse files Browse the repository at this point in the history
# Nieuwe functie getLegacyKey ingevoerd omdat voor zeer oude saves er errors ontstonden bij het assignen
  • Loading branch information
igoethal committed Jan 2, 2024
1 parent a9ddd4d commit 7bea673
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 111 deletions.
2 changes: 1 addition & 1 deletion builddate.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var CONF_builddate="20240102-150647"
var CONF_builddate="20240102-155011"
95 changes: 58 additions & 37 deletions eendraadschema.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ var Electro_Item = /** @class */ (function (_super) {
//Indien domotica gestuurde verbruiker, bool5 is de selector voor uitbreiding van de sturing met drukknop
//Indien stopcontact, geeft aan dat deze in een verdeelbord zit*/
};
Electro_Item.prototype.getLegacyKey = function (keyid) {
if ((typeof (this.keys) != 'undefined') && (this.keys.length > keyid)) {
return this.keys[keyid][2];
}
else {
return null;
}
};
Electro_Item.prototype.getParent = function () {
return _super.prototype.getParent.call(this);
};
Expand All @@ -432,7 +440,7 @@ var Electro_Item = /** @class */ (function (_super) {
return (this.getNumChildsWithKnownType() > 0);
};
Electro_Item.prototype.isVrijeTekstZonderKader = function (item) {
return ((item.getType() == "Vrije tekst") && (item.keys[16][2] == "Zonder kader"));
return ((item.getType() == "Vrije tekst") && (item.keys[16][2] == "zonder kader"));
};
Electro_Item.prototype.heeftVerbruikerAlsKind = function () {
var parent = this.getParent();
Expand Down Expand Up @@ -3163,36 +3171,49 @@ var Stopcontact = /** @class */ (function (_super) {
_this.resetKeys();
return _this;
}
Stopcontact.prototype.convertLegacyKeys = function (mykeys) {
this.props.type = this.getLegacyKey(0);
this.props.is_geaard = this.getLegacyKey(1);
this.props.is_kinderveilig = this.getLegacyKey(2);
this.props.aantal = this.getLegacyKey(4);
this.props.adres = this.getLegacyKey(15);
this.props.aantal_fases_indien_meerfasig = this.getLegacyKey(16);
this.props.heeft_ingebouwde_schakelaar = this.getLegacyKey(19);
this.props.is_halfwaterdicht = this.getLegacyKey(20);
this.props.is_meerfasig = this.getLegacyKey(21);
this.props.heeft_nul_indien_meerfasig = this.getLegacyKey(25);
this.props.in_verdeelbord = this.getLegacyKey(26);
};
Stopcontact.prototype.resetKeys = function () {
this.clearKeys();
this.keys[0][2] = "Stopcontact"; // This is rather a formality as we should already have this at this stage
this.keys[1][2] = true; // Per default geaard
this.keys[2][2] = true; // Per default kinderveilig
this.keys[4][2] = "1"; // Per default 1 Stopcontact
this.keys[15][2] = ""; // Set Adres/tekst to "" when the item is cleared
this.keys[16][2] = "3"; // Indien meerfasig is de default 3 fasen
this.keys[19][2] = false; // Per default niet met ingebouwde schakelaar
this.keys[20][2] = false; // Per default niet halfwaterdicht
this.keys[21][2] = false; // Per default niet meerfasig
this.keys[25][2] = false; // Indien meerfasig, per default niet met nul
this.keys[26][2] = false; // Per default niet in verdeelbord
this.props.type = "Stopcontact";
this.props.is_geaard = true;
this.props.is_kinderveilig = true;
this.props.aantal = "1";
this.props.adres = "";
this.props.aantal_fases_indien_meerfasig = "3";
this.props.heeft_ingebouwde_schakelaar = false;
this.props.is_halfwaterdicht = false;
this.props.is_meerfasig = false;
this.props.heeft_nul_indien_meerfasig = false;
this.props.in_verdeelbord = false;
};
Stopcontact.prototype.toHTML = function (mode) {
var output = this.toHTMLHeader(mode);
output += " Nr: " + this.stringToHTML(10, 5) + ", "
+ "Geaard: " + this.checkboxToHTML(1) + ", "
+ "Kinderveiligheid: " + this.checkboxToHTML(2) + " "
+ "Halfwaterdicht: " + this.checkboxToHTML(20) + ", "
+ "Meerfasig: " + this.checkboxToHTML(21) + ", ";
if (this.keys[21][2]) {
output += "Aantal fasen: " + this.selectToHTML(16, ["1", "2", "3"]) + ", "
+ "Met nul: " + this.checkboxToHTML(25) + ", ";
output += " Nr: " + this.stringPropToHTML('nr', 5) + ", "
+ "Geaard: " + this.checkboxPropToHTML('is_geaard') + ", "
+ "Kinderveiligheid: " + this.checkboxPropToHTML('is_kinderveilig') + " "
+ "Halfwaterdicht: " + this.checkboxPropToHTML('is_halfwaterdicht') + ", "
+ "Meerfasig: " + this.checkboxPropToHTML('is_meerfasig') + ", ";
if (this.props.is_meerfasig) {
output += "Aantal fasen: " + this.selectPropToHTML('aantal_fases_indien_meerfasig', ["1", "2", "3"]) + ", "
+ "Met nul: " + this.checkboxPropToHTML('heeft_nul_indien_meerfasig') + ", ";
}
;
output += "Ingebouwde schakelaar: " + this.checkboxToHTML(19) + ", "
+ "Aantal: " + this.selectToHTML(4, ["1", "2", "3", "4", "5", "6"]) + ", "
+ "In verdeelbord: " + this.checkboxToHTML(26)
+ ", Adres/tekst: " + this.stringToHTML(15, 5);
output += "Ingebouwde schakelaar: " + this.checkboxPropToHTML('heeft_ingebouwde_schakelaar') + ", "
+ "Aantal: " + this.selectPropToHTML('aantal', ["1", "2", "3", "4", "5", "6"]) + ", "
+ "In verdeelbord: " + this.checkboxPropToHTML('in_verdeelbord')
+ ", Adres/tekst: " + this.stringPropToHTML('adres', 5);
return (output);
};
Stopcontact.prototype.toSVG = function () {
Expand All @@ -3203,9 +3224,9 @@ var Stopcontact = /** @class */ (function (_super) {
mySVG.ydown = 25;
var startx = 1; // Punt waar we aan het tekenen zijn. Schuift gaandeweg op
// Teken lijnen voor meerfasig stopcontact
if (this.keys[21][2]) {
if (this.props.is_meerfasig) {
mySVG.data += '<line x1="1" y1="25" x2="35" y2="25" stroke="black" />';
switch (this.keys[16][2]) { //faselijnen
switch (this.props.aantal_fases_indien_meerfasig) { //faselijnen
case "1":
mySVG.data += '<line x1="21" y1="35" x2="27" y2="15" stroke="black" />';
break;
Expand All @@ -3222,15 +3243,15 @@ var Stopcontact = /** @class */ (function (_super) {
mySVG.data += '<line x1="21" y1="35" x2="27" y2="15" stroke="black" />';
break;
}
if (this.keys[25][2]) { //nullijn
if (this.props.heeft_nul_indien_meerfasig) { //nullijn
mySVG.data += '<line x1="39" y1="35" x2="45" y2="15" stroke="black" />'
+ '<circle cx="39" cy="35" r="2" fill="black" stroke="black" />';
}
startx += 34;
mySVG.xright += 34; //We schuiven alles 34 pixels op
}
// Teken ingebouwde schakelaar
if (this.keys[19][2]) {
if (this.props.heeft_ingebouwde_schakelaar) {
mySVG.data += '<line x1="' + (startx + 0) + '" y1="25" x2="' + (startx + 11) + '" y2="25" stroke="black" />'
+ '<line x1="' + (startx + 30) + '" y1="25" x2="' + (startx + 20) + '" y2="5" stroke="black" />'
+ '<line x1="' + (startx + 20) + '" y1="5" x2="' + (startx + 15) + '" y2="7.5" stroke="black" />'
Expand All @@ -3239,31 +3260,31 @@ var Stopcontact = /** @class */ (function (_super) {
mySVG.xright += 10; //We schuiven alles 10 pixels op
}
// Teken alle stopcontacten, inclusief aarding en kinderveiligheid indien van toepassing
for (var i = 0; i < this.keys[4][2]; ++i) {
for (var i = 0; i < this.props.aantal; ++i) {
mySVG.data += '<use xlink:href="#stopcontact" x="' + startx + '" y="25"></use>';
if (this.keys[1][2])
if (this.props.is_geaard)
mySVG.data += '<use xlink:href="#stopcontact_aarding" x="' + startx + '" y="25"></use>';
if (this.keys[2][2])
if (this.props.is_kinderveilig)
mySVG.data += '<use xlink:href="#stopcontact_kinderveilig" x="' + startx + '" y="25"></use>';
startx += 20;
mySVG.xright += 20;
}
// Teken kader indien in verdeelbord
if (this.keys[26][2]) {
mySVG.data += '<rect x="' + (mySVG.xright - this.keys[4][2] * 20 - 3 - (this.keys[19][2]) * 12) + '" y="3" width="' + (this.keys[4][2] * 20 + 6 + (this.keys[19][2]) * 12) + '" height="44" fill="none" style="stroke:black" />';
if (this.props.in_verdeelbord) {
mySVG.data += '<rect x="' + (mySVG.xright - this.props.aantal * 20 - 3 - (this.props.heeft_ingebouwde_schakelaar) * 12) + '" y="3" width="' + (this.props.aantal * 20 + 6 + (this.props.heeft_ingebouwde_schakelaar) * 12) + '" height="44" fill="none" style="stroke:black" />';
+'<line x1="' + (17 + (mySVG.xright - 20 + 3)) + '" y1="3" x2="' + (17 + (mySVG.xright - 20 + 3)) + '" y2="47" fill="none" style="stroke:black" />';
}
;
// Teken halfwaterdicht indien van toepassing
if (this.keys[20][2])
mySVG.data += '<rect x="' + (22 + (this.keys[19][2]) * 10 + (this.keys[21][2]) * 34) + '" y="0" width="6" height="8" style="fill:rgb(255,255,255)" /><text x="' + (25 + (this.keys[19][2]) * 10 + (this.keys[21][2]) * 34) + '" y="8" style="text-anchor:middle" font-family="Arial, Helvetica, sans-serif" font-size="10">h</text>';
if (this.props.is_halfwaterdicht)
mySVG.data += '<rect x="' + (22 + (this.props.heeft_ingebouwde_schakelaar) * 10 + (this.props.is_meerfasig) * 34) + '" y="0" width="6" height="8" style="fill:rgb(255,255,255)" /><text x="' + (25 + (this.props.heeft_ingebouwde_schakelaar) * 10 + (this.props.is_meerfasig) * 34) + '" y="8" style="text-anchor:middle" font-family="Arial, Helvetica, sans-serif" font-size="10">h</text>';
// Indien het stopcontact een kind heeft, teken een streepje rechts
if (this.heeftVerbruikerAlsKind()) {
mySVG.data += '<line x1="' + startx + '" y1="25" x2="' + (startx + 21) + '" y2="25" stroke="black" />';
}
;
// Adres helemaal onderaan plaatsen
mySVG.data += this.addAddress(mySVG, 60, 15);
mySVG.data += this.addPropAddress(mySVG, 60, 15);
mySVG.data += "\n";
return (mySVG);
};
Expand Down Expand Up @@ -5433,7 +5454,7 @@ function import_to_structure(mystring, redraw) {
if (version < 2) { // Versies < 2 gebruikten enkel keys en geen props dus de code hieronder met keys zal altijd werken
for (var i = 0; i < mystructure.length; i++) {
// Breedte van Vrije tekst velden zonder kader met 30 verhogen sinds 16/12/2023
if ((structure.data[i].keys[0][2] === "Vrije tekst") && (structure.data[i].keys[16][2] != "verbruiker")) {
if ((structure.data[i].getType() === "Vrije tekst") && (structure.data[i].keys[16][2] != "verbruiker")) {
if (Number(structure.data[i].keys[22][2]) > 0)
structure.data[i].keys[22][2] = String(Number(structure.data[i].keys[22][2]) + 30);
else
Expand Down
10 changes: 9 additions & 1 deletion src/List_Item/Electro_Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ class Electro_Item extends List_Item {
//Indien stopcontact, geeft aan dat deze in een verdeelbord zit*/
}

getLegacyKey(keyid: number) {
if ( (typeof(this.keys) != 'undefined') && (this.keys.length>keyid) ) {
return this.keys[keyid][2];
} else {
return null;
}
}

getParent(): Electro_Item { // Function that returns an Electro_Item and not a List_Item
return(super.getParent() as Electro_Item);
}
Expand All @@ -111,7 +119,7 @@ class Electro_Item extends List_Item {
}

isVrijeTekstZonderKader(item: Electro_Item) : boolean {
return ((item.getType() == "Vrije tekst") && (item.keys[16][2] == "Zonder kader"));
return ((item.getType() == "Vrije tekst") && (item.keys[16][2] == "zonder kader"));
}

heeftVerbruikerAlsKind() : boolean {
Expand Down
Loading

0 comments on commit 7bea673

Please sign in to comment.