Skip to content

Commit

Permalink
# Aparte class voor Splitsing
Browse files Browse the repository at this point in the history
# Aparte class voor Bord en deze class houdt nu ook rekening met de lengte van de naam van het bord
# Kleine correctie bij de lengteberekening van de tekst in het Domotica symbool
  • Loading branch information
igoethal committed Dec 22, 2023
1 parent a3dd923 commit 2ef224e
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 242 deletions.
2 changes: 1 addition & 1 deletion builddate.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var CONF_builddate="20231222-080521"
var CONF_builddate="20231222-122151"
189 changes: 108 additions & 81 deletions eendraadschema.js

Large diffs are not rendered by default.

73 changes: 5 additions & 68 deletions src/Hierarchical_List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class Hierarchical_List {
case 'Batterij': tempval = new Batterij(structure); break;
case 'Bel': tempval = new Bel(structure); break;
case 'Boiler': tempval = new Boiler(structure); break;
case 'Bord': tempval = new Bord(structure); break;
case 'Diepvriezer': tempval = new Diepvriezer(structure); break;
case 'Domotica': tempval = new Domotica(structure); break;
case 'Droogkast': tempval = new Droogkast(structure); break;
Expand All @@ -191,6 +192,7 @@ class Hierarchical_List {
case 'Omvormer': tempval = new Omvormer(structure); break;
case 'Overspanningsbeveiliging': tempval = new Overspanningsbeveiliging(structure); break;
case 'Schakelaars': tempval = new Schakelaars(structure); break;
case 'Splitsing': tempval = new Splitsing(structure); break;
case 'Stoomoven': tempval = new Stoomoven(structure); break;
case 'Stopcontact': tempval = new Stopcontact(structure); break;
case 'Transformator': tempval = new Transformator(structure); break;
Expand Down Expand Up @@ -552,78 +554,13 @@ class Hierarchical_List {
for (var i = 0; i<this.length; i++) {
if (this.active[i] && ( (this.data[i].parent == myParent) || ( (includeparent==true) && (this.id[i] == myParent) ) ) ) {
switch (this.data[i].getKey("type")) {

case "Bord":
//get image of the entire bord
inSVG[elementCounter] = this.toSVG(this.id[i],"horizontal");
inSVG[elementCounter].xright += 10;
if (this.data[i].getKey("geaard")) {
if (inSVG[elementCounter].xleft <=100) {
var toShift = 100-inSVG[elementCounter].xleft;
inSVG[elementCounter].xleft = 100;
inSVG[elementCounter].xright -= toShift;
}
} else {
if (inSVG[elementCounter].xleft <=30) {
var toShift = 30-inSVG[elementCounter].xleft;
inSVG[elementCounter].xleft = 30;
inSVG[elementCounter].xright -= toShift;
}
}
if (inSVG[elementCounter].xright <=10) inSVG[elementCounter].xright = 10;

//Ensure there is enough space to draw the bottom line
inSVG[elementCounter].ydown = Math.max(inSVG[elementCounter].ydown,1);

//Draw the bottom line
inSVG[elementCounter].data = inSVG[elementCounter].data +
'<line x1="4" x2="' + (inSVG[elementCounter].xleft + inSVG[elementCounter].xright-6) +
'" y1="' + inSVG[elementCounter].yup + '" y2="' + inSVG[elementCounter].yup + '" stroke="black" stroke-width="3" />'

//Add name of the board
if (this.data[i].getKey("naam") !== "") {
inSVG[elementCounter].data += '<text x="' + (0) + '" y="' + (inSVG[elementCounter].yup + 13) + '" ' +
'style="text-anchor:start" font-family="Arial, Helvetica, sans-serif" font-weight="bold" font-size="10">&lt;' +
htmlspecialchars(this.data[i].getKey("naam"))+'&gt;</text>';
};

//Add an image of the grounding
if (this.data[i].getKey("geaard")) {
inSVG[elementCounter].data += '<line x1="40" y1="' + (inSVG[elementCounter].yup + 0) + '" x2="40" y2="' + (inSVG[elementCounter].yup + 10) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="40" y1="' + (inSVG[elementCounter].yup + 15) + '" x2="40" y2="' + (inSVG[elementCounter].yup + 25) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="40" y1="' + (inSVG[elementCounter].yup + 30) + '" x2="40" y2="' + (inSVG[elementCounter].yup + 40) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="35" y1="' + (inSVG[elementCounter].yup + 10) + '" x2="45" y2="' + (inSVG[elementCounter].yup + 10) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="35" y1="' + (inSVG[elementCounter].yup + 15) + '" x2="45" y2="' + (inSVG[elementCounter].yup + 15) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="35" y1="' + (inSVG[elementCounter].yup + 25) + '" x2="45" y2="' + (inSVG[elementCounter].yup + 25) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="35" y1="' + (inSVG[elementCounter].yup + 30) + '" x2="45" y2="' + (inSVG[elementCounter].yup + 30) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="30" y1="' + (inSVG[elementCounter].yup + 40) + '" x2="50" y2="' + (inSVG[elementCounter].yup + 40) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="32.5" y1="' + (inSVG[elementCounter].yup + 43) + '" x2="47.5" y2="' + (inSVG[elementCounter].yup + 43) + '" stroke="black" />';
inSVG[elementCounter].data += '<line x1="35" y1="' + (inSVG[elementCounter].yup + 46) + '" x2="45" y2="' + (inSVG[elementCounter].yup + 46) + '" stroke="black" />';
};
inSVG[elementCounter] = this.data[i].toSVG();
break;

case "Splitsing":
//Algoritme werkt gelijkaardig aan een "Bord", eerst maken we een tekening van het geheel
inSVG[elementCounter] = this.toSVG(this.id[i],"horizontal");

switch ((this.data[this.getOrdinalById(myParent)]).getKey("type")) {
case "Aansluiting":
case "Kring": //in-line with kring or aansluiting
inSVG[elementCounter].data = inSVG[elementCounter].data +
'<line x1="' + (inSVG[elementCounter].xleft) + '" x2="' + (inSVG[elementCounter].xleft + inSVG[elementCounter].xrightmin) +
'" y1="' + inSVG[elementCounter].yup + '" y2="' + inSVG[elementCounter].yup + '" stroke="black" />'
break;
default:
if ((inSVG[elementCounter].xright + inSVG[elementCounter].xleft) <=0) inSVG[elementCounter].xrightmin = 15; // ensure we see there is a "splitsing"
if (inSVG[elementCounter].yup < 25) inSVG[elementCounter].yup = 25;
if (inSVG[elementCounter].ydown < 25) inSVG[elementCounter].ydown = 25;
inSVG[elementCounter].data = inSVG[elementCounter].data +
'<line x1="' + (1) + '" x2="' + (inSVG[elementCounter].xleft + inSVG[elementCounter].xrightmin) +
'" y1="' + inSVG[elementCounter].yup + '" y2="' + inSVG[elementCounter].yup + '" stroke="black" />'
var toShift = inSVG[elementCounter].xleft;
inSVG[elementCounter].xleft -= toShift - 1; //we leave one pixel for the bold kring-line at the left
inSVG[elementCounter].xright += toShift;
break;
}
inSVG[elementCounter] = this.data[i].toSVG();
break;

case "Domotica":
Expand Down
72 changes: 72 additions & 0 deletions src/List_Item/Bord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class Bord extends Electro_Item {

constructor(mylist: Hierarchical_List) { super(mylist); }

resetKeys() {
this.clearKeys();
this.keys[0][2] = "Bord"; // This is rather a formality as we should already have this at this stage
this.keys[1][2] = true; // Per default geaard
this.keys[15][2] = ""; // Set Adres/tekst to "" when the item is cleared
}

toHTML(mode: string, Parent?: List_Item) {
let output = this.toHTMLHeader(mode, Parent);

output += "&nbsp;Naam: " + this.stringToHTML(10,5) + ", "
+ "Geaard: " + this.checkboxToHTML(1);

return(output);
}

toSVG() {
let mySVG:SVGelement; // = new SVGelement();

// Maak een tekening van alle kinderen
mySVG = this.sourcelist.toSVG(this.id,"horizontal");

// Voorzie 10 extra pixels rechts na de allerlaatste kring
mySVG.xright += 10;

// Schuif het geheel voldoende naar links om plaats te hebben voor label en eventuele aarding

let mintextsize = Math.max(30, svgTextWidth('&lt'+htmlspecialchars(this.keys[10][2])+'&gt',10,'font-weight="bold"') + 13);
let minxleft = mintextsize + (this.keys[1][2] ? 70 : 0); //Indien geaard hebben we 70 meer nodig

if (mySVG.xleft <= minxleft) { // Minstens 100 pixels indien aarding
mySVG.xright = mySVG.xleft + mySVG.xright - minxleft;
mySVG.xleft = minxleft;
}

// Indien door het schuiven er niets rechts over blijft, voorzie minstens 10 pixels
if (mySVG.xright <=10) mySVG.xright = 10;

// Voorzie voldoende plaats voor de lijn onderaan
mySVG.ydown = Math.max(mySVG.ydown,1);

// Teken de lijn onderaan
mySVG.data += '<line x1="4" x2="' + (mySVG.xleft + mySVG.xright - 6) +
'" y1="' + mySVG.yup + '" y2="' + mySVG.yup + '" stroke="black" stroke-width="3" />'

// Voeg naam van het bord toe
if (this.keys[10][2] !== "")
mySVG.data += '<text x="' + (5) + '" y="' + (mySVG.yup + 13) + '" '
+ 'style="text-anchor:start" font-family="Arial, Helvetica, sans-serif" font-weight="bold" font-size="10">&lt;'
+ htmlspecialchars(this.keys[10][2])+'&gt;</text>';

// Teken aarding onderaan
if (this.keys[1][2])
mySVG.data += '<line x1="' + (mintextsize + 10) + '" y1="' + (mySVG.yup + 0) + '" x2="' + (mintextsize + 10) + '" y2="' + (mySVG.yup + 10) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 10) + '" y1="' + (mySVG.yup + 15) + '" x2="' + (mintextsize + 10) + '" y2="' + (mySVG.yup + 25) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 10) + '" y1="' + (mySVG.yup + 30) + '" x2="' + (mintextsize + 10) + '" y2="' + (mySVG.yup + 40) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 5) + '" y1="' + (mySVG.yup + 10) + '" x2="' + (mintextsize + 15) + '" y2="' + (mySVG.yup + 10) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 5) + '" y1="' + (mySVG.yup + 15) + '" x2="' + (mintextsize + 15) + '" y2="' + (mySVG.yup + 15) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 5) + '" y1="' + (mySVG.yup + 25) + '" x2="' + (mintextsize + 15) + '" y2="' + (mySVG.yup + 25) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 5) + '" y1="' + (mySVG.yup + 30) + '" x2="' + (mintextsize + 15) + '" y2="' + (mySVG.yup + 30) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 0) + '" y1="' + (mySVG.yup + 40) + '" x2="' + (mintextsize + 20) + '" y2="' + (mySVG.yup + 40) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 2.5) + '" y1="' + (mySVG.yup + 43) + '" x2="' + (mintextsize + 17.5) + '" y2="' + (mySVG.yup + 43) + '" stroke="black" />'
+ '<line x1="' + (mintextsize + 5) + '" y1="' + (mySVG.yup + 46) + '" x2="' + (mintextsize + 15) + '" y2="' + (mySVG.yup + 46) + '" stroke="black" />';

return(mySVG);
}

}
2 changes: 1 addition & 1 deletion src/List_Item/Domotica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Domotica extends Electro_Item {

// We voorzien altijd minimaal een kader van 80 en zeker genoeg voor de tekst in het Domotica-symbool
let minwidth = 80;
for (let str of strlines) minwidth = Math.max(minwidth, svgTextWidth(str,10,'font-weight="bold"') + 15); //15 padding
for (let str of strlines) minwidth = Math.max(minwidth, svgTextWidth(htmlspecialchars(str),10,'font-weight="bold"') + 15); //15 padding
minwidth += 20; //Ruimte voor leiding links
if ((mySVG.xright + mySVG.xleft) <=minwidth) mySVG.xright = (minwidth - mySVG.xleft);

Expand Down
10 changes: 0 additions & 10 deletions src/List_Item/Electro_Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,6 @@ class Electro_Item extends List_Item {
output += ", Kabeltype v&oacute;&oacute;r teller: " + this.stringToHTML(24,10);
output += ", Adres/tekst: " + this.stringToHTML(15,5);
break;
case "Bord":
output += "&nbsp;Naam: " + this.stringToHTML(10,5) + ", ";
output += "Geaard: " + this.checkboxToHTML(1);
break;
case "Domotica":
output += "&nbsp;Nr: " + this.stringToHTML(10,5);
output += ", Tekst: " + this.stringToHTML(15,10);
break;
case "Domotica gestuurde verbruiker":
output += "&nbsp;Nr: " + this.stringToHTML(10,5);
output += ", Draadloos: " + this.checkboxToHTML(19);
Expand All @@ -486,8 +478,6 @@ class Electro_Item extends List_Item {
output += ", Externe sturing: " + this.selectToHTML(5,["drukknop","schakelaar"]);
}
output += ", Adres/tekst: " + this.stringToHTML(15,5);
case "Splitsing":
break;
case "Vrije ruimte":
output += "&nbsp;Breedte: " + this.stringToHTML(22,3);
break;
Expand Down
47 changes: 47 additions & 0 deletions src/List_Item/Splitsing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class Splitsing extends Electro_Item {

constructor(mylist: Hierarchical_List) { super(mylist); }

resetKeys() {
this.clearKeys();
this.keys[0][2] = "Splitsing"; // This is rather a formality as we should already have this at this stage
this.keys[15][2] = ""; // Set Adres/tekst to "" when the item is cleared
}

toHTML(mode: string, Parent?: List_Item) {
let output = this.toHTMLHeader(mode, Parent);

return(output);
}

toSVG() {
let mySVG:SVGelement; // = new SVGelement();

// Maak een tekening van alle kinderen
mySVG = this.sourcelist.toSVG(this.id,"horizontal");

let parent = this.getParent();

// Teken de lijn onderaan
if ( (parent.keys[0][2] == "Aansluiting") || (parent.keys[0][2] == "Kring") ) {
mySVG.data += '<line x1="' + (mySVG.xleft) + '" x2="' + (mySVG.xleft + mySVG.xrightmin)
+ '" y1="' + mySVG.yup + '" y2="' + mySVG.yup + '" stroke="black" />'

} else {

if ( (mySVG.xleft + mySVG.xright) <=0 ) mySVG.xrightmin = 15; // We teken altijd minstens een lijntje van 15 pixels om duidelijk te maken dat er een splitsing is

if (mySVG.yup < 25) mySVG.yup = 25;
if (mySVG.ydown < 25) mySVG.ydown = 25;

mySVG.data += '<line x1="' + (1) + '" x2="' + (mySVG.xleft + mySVG.xrightmin)
+ '" y1="' + mySVG.yup + '" y2="' + mySVG.yup + '" stroke="black" />'

mySVG.xright = mySVG.xright + mySVG.xleft;
mySVG.xleft = 1; //we leave one pixel for the bold kring-line at the left
}

return(mySVG);
}

}
Loading

0 comments on commit 2ef224e

Please sign in to comment.