Skip to content

Commit 9b039d2

Browse files
committed
Code toegevoegd om meerdere schakelaars uit te pakken naar individuele schakelaars. Dit zal nodig zijn om dit soort schakelaar-schakelingen correct op het situatieschema te kunnen aanbrengen.
1 parent 5d16265 commit 9b039d2

File tree

5 files changed

+232
-2
lines changed

5 files changed

+232
-2
lines changed

builddate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
var CONF_builddate="20250119-144827"
1+
var CONF_builddate="20250119-200745"

eendraadschema.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,6 +3831,15 @@ var Electro_Item = /** @class */ (function (_super) {
38313831
output += this.selectPropToHTML('type', consumerArray);
38323832
return (output);
38333833
};
3834+
// -- Displays the Expand button for the Electro_item, in case the item is expandable --
3835+
Electro_Item.prototype.toHTMLFooter = function () {
3836+
if (this.isExpandable()) {
3837+
return (" <button title=\"Meerdere schakelaars omzetten in indivuele schakelaars\" style=\"background-color:lightblue;\" onclick=\"HLExpand(".concat(this.id, ")\">Uitpakken</button>"));
3838+
}
3839+
else {
3840+
return ("");
3841+
}
3842+
};
38343843
// -- This one will get called if the type of the Electro_Item has not yet been chosen --
38353844
Electro_Item.prototype.toHTML = function (mode) { return (this.toHTMLHeader(mode)); }; // Implemented in the derived classes
38363845
// -- Get the number of the Electro_Item, if it is not defined, ask the parent
@@ -3904,6 +3913,21 @@ var Electro_Item = /** @class */ (function (_super) {
39043913
//this.updateSituationPlanElement(myElement); //Lijkt niet nodig aangezien dit zoiezo gebeurt in getScaledSVG bij iedere update
39053914
return (myElement);
39063915
};
3916+
/**
3917+
* Functie geeft aan of een Electro_Item nog verder kan uitgesplitst worden in kleinere Items.
3918+
* Deze is vooral nuttig voor het situatieschema om groepen van schakelaars of een lichtcircuit te herkennen.
3919+
*/
3920+
Electro_Item.prototype.isExpandable = function () {
3921+
return false;
3922+
};
3923+
/**
3924+
* Deze functie splitst een Electro_Item verder uit in kleinere Items. Dit is uiteraard enkel mogelijk indien isExpandable() true geeft.
3925+
* De aanpassing wordt direct op de sourcelist uitgevoerd.
3926+
*/
3927+
Electro_Item.prototype.expand = function () {
3928+
if (!this.isExpandable())
3929+
return;
3930+
};
39073931
/**
39083932
* Geeft de boundary's terug van het element in het situatieplan. Deze boundary's worden gebruikt om het element te positioneren en te clippen.
39093933
*
@@ -4349,6 +4373,7 @@ var Schakelaars = /** @class */ (function (_super) {
43494373
break;
43504374
}
43514375
output += ", Adres/tekst: " + this.stringPropToHTML('adres', 5);
4376+
output += this.toHTMLFooter();
43524377
return (output);
43534378
};
43544379
Schakelaars.prototype.bouwSchakelaarKeten = function (tekenKeten) {
@@ -4428,6 +4453,82 @@ var Schakelaars = /** @class */ (function (_super) {
44284453
break;
44294454
}
44304455
};
4456+
Schakelaars.prototype.isExpandable = function () {
4457+
switch (this.props.type_schakelaar) {
4458+
case "enkelpolig":
4459+
case "dubbelpolig":
4460+
return (Number(this.props.aantal_schakelaars) > 1);
4461+
default:
4462+
return (false);
4463+
}
4464+
};
4465+
Schakelaars.prototype.expand = function () {
4466+
switch (this.props.type_schakelaar) {
4467+
case "enkelpolig":
4468+
if (Number(this.props.aantal_schakelaars) > 1) { // Er zijn er altijd 2 als er niet 1 is
4469+
var adresGoesHere = Math.floor(this.props.aantal_schakelaars / 2);
4470+
var schakelaar1 = new Schakelaars(this.sourcelist);
4471+
Object.assign(schakelaar1.props, this.props);
4472+
schakelaar1.props.aantal_schakelaars = 1;
4473+
schakelaar1.props.type_schakelaar = "wissel_enkel";
4474+
schakelaar1.props.adres = "";
4475+
this.sourcelist.insertItemBeforeId(schakelaar1, this.id);
4476+
var lastschakelaar = schakelaar1;
4477+
for (var i = 0; i < Number(this.props.aantal_schakelaars) - 2; ++i) {
4478+
var schakelaar = new Schakelaars(this.sourcelist);
4479+
Object.assign(schakelaar.props, this.props);
4480+
schakelaar.props.aantal_schakelaars = 1;
4481+
schakelaar.props.type_schakelaar = "kruis_enkel";
4482+
if (adresGoesHere == i + 1) {
4483+
schakelaar.props.adres = this.props.adres;
4484+
}
4485+
else {
4486+
schakelaar.props.adres = "";
4487+
}
4488+
if (this.getParent().props.type === "Meerdere verbruikers") {
4489+
this.sourcelist.insertItemBeforeId(schakelaar, this.id);
4490+
}
4491+
else {
4492+
this.sourcelist.insertChildAfterId(schakelaar, lastschakelaar.id);
4493+
lastschakelaar = schakelaar;
4494+
}
4495+
}
4496+
if (adresGoesHere == Number(this.props.aantal_schakelaars) - 1) {
4497+
this.props.adres = this.props.adres;
4498+
}
4499+
else {
4500+
this.props.adres = "";
4501+
}
4502+
this.props.aantal_schakelaars = 1;
4503+
this.props.type_schakelaar = "wissel_enkel";
4504+
if (this.getParent().props.type === "Meerdere verbruikers") {
4505+
this.parent = this.getParent().id;
4506+
}
4507+
else {
4508+
this.parent = lastschakelaar.id;
4509+
}
4510+
}
4511+
break;
4512+
case "dubbelpolig":
4513+
if (Number(this.props.aantal_schakelaars) > 1) { // Er zijn er altijd 2 als er niet 1 is
4514+
var schakelaar1 = new Schakelaars(this.sourcelist);
4515+
Object.assign(schakelaar1.props, this.props);
4516+
schakelaar1.props.aantal_schakelaars = 1;
4517+
schakelaar1.props.type_schakelaar = "wissel_dubbel";
4518+
schakelaar1.props.adres = "";
4519+
this.sourcelist.insertItemBeforeId(schakelaar1, this.id);
4520+
this.props.aantal_schakelaars = 1;
4521+
this.props.type_schakelaar = "wissel_dubbel";
4522+
if (this.getParent().props.type == "Meerdere verbruikers") {
4523+
this.parent = this.getParent().id;
4524+
}
4525+
else {
4526+
this.parent = schakelaar1.id;
4527+
}
4528+
}
4529+
break;
4530+
}
4531+
};
44314532
Schakelaars.prototype.toSVG = function (sitplan, mirrortext) {
44324533
var _a;
44334534
if (sitplan === void 0) { sitplan = false; }
@@ -9255,6 +9356,15 @@ function HL_editmode() {
92559356
structure.mode = document.getElementById("edit_mode").value;
92569357
HLRedrawTreeHTML();
92579358
}
9359+
function HLExpand(my_id) {
9360+
var element = structure.getElectroItemById(my_id);
9361+
if (element !== null) {
9362+
element.expand();
9363+
}
9364+
structure.reSort();
9365+
undostruct.store();
9366+
HLRedrawTree();
9367+
}
92589368
function HL_changeparent(my_id) {
92599369
// See what the new parentid is
92609370
var str_newparentid = document.getElementById("id_parent_change_" + my_id).value;

src/List_Item/Electro_Item.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ class Electro_Item extends List_Item {
177177
return(output);
178178
}
179179

180+
// -- Displays the Expand button for the Electro_item, in case the item is expandable --
181+
182+
toHTMLFooter() {
183+
if (this.isExpandable()) {
184+
return(` <button title="Meerdere schakelaars omzetten in indivuele schakelaars" style="background-color:lightblue;" onclick="HLExpand(${this.id})">Uitpakken</button>`);
185+
} else {
186+
return("");
187+
}
188+
}
189+
180190
// -- This one will get called if the type of the Electro_Item has not yet been chosen --
181191

182192
toHTML(mode: string) { return(this.toHTMLHeader(mode)); } // Implemented in the derived classes
@@ -250,6 +260,23 @@ class Electro_Item extends List_Item {
250260
return(myElement);
251261
}
252262

263+
264+
/**
265+
* Functie geeft aan of een Electro_Item nog verder kan uitgesplitst worden in kleinere Items.
266+
* Deze is vooral nuttig voor het situatieschema om groepen van schakelaars of een lichtcircuit te herkennen.
267+
*/
268+
isExpandable() {
269+
return false;
270+
}
271+
272+
/**
273+
* Deze functie splitst een Electro_Item verder uit in kleinere Items. Dit is uiteraard enkel mogelijk indien isExpandable() true geeft.
274+
* De aanpassing wordt direct op de sourcelist uitgevoerd.
275+
*/
276+
expand() {
277+
if (!this.isExpandable()) return;
278+
}
279+
253280
/**
254281
* Geeft de boundary's terug van het element in het situatieplan. Deze boundary's worden gebruikt om het element te positioneren en te clippen.
255282
*

src/List_Item/Schakelaars/Schakelaars.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class Schakelaars extends Electro_Item {
8181
}
8282

8383
output += ", Adres/tekst: " + this.stringPropToHTML('adres',5);
84+
85+
output += this.toHTMLFooter();
86+
8487
return(output);
8588
}
8689

@@ -124,6 +127,86 @@ class Schakelaars extends Electro_Item {
124127
}
125128
}
126129

130+
isExpandable() {
131+
switch (this.props.type_schakelaar) {
132+
case "enkelpolig": case "dubbelpolig":
133+
return (Number(this.props.aantal_schakelaars) > 1);
134+
default:
135+
return (false);
136+
}
137+
}
138+
139+
expand() {
140+
switch (this.props.type_schakelaar) {
141+
case "enkelpolig":
142+
if (Number(this.props.aantal_schakelaars) > 1) { // Er zijn er altijd 2 als er niet 1 is
143+
144+
let adresGoesHere = Math.floor(this.props.aantal_schakelaars/2);
145+
146+
let schakelaar1 = new Schakelaars(this.sourcelist);
147+
Object.assign(schakelaar1.props, this.props);
148+
schakelaar1.props.aantal_schakelaars = 1;
149+
schakelaar1.props.type_schakelaar = "wissel_enkel";
150+
schakelaar1.props.adres = "";
151+
this.sourcelist.insertItemBeforeId(schakelaar1,this.id);
152+
let lastschakelaar = schakelaar1;
153+
154+
for (let i=0; i<Number(this.props.aantal_schakelaars)-2; ++i) {
155+
let schakelaar = new Schakelaars(this.sourcelist);
156+
Object.assign(schakelaar.props, this.props);
157+
schakelaar.props.aantal_schakelaars = 1;
158+
schakelaar.props.type_schakelaar = "kruis_enkel";
159+
if (adresGoesHere == i+1) {
160+
schakelaar.props.adres = this.props.adres;
161+
} else {
162+
schakelaar.props.adres = "";
163+
}
164+
if (this.getParent().props.type === "Meerdere verbruikers") {
165+
this.sourcelist.insertItemBeforeId(schakelaar,this.id);
166+
} else {
167+
this.sourcelist.insertChildAfterId(schakelaar,lastschakelaar.id);
168+
lastschakelaar = schakelaar;
169+
}
170+
}
171+
172+
if (adresGoesHere == Number(this.props.aantal_schakelaars)-1) {
173+
this.props.adres = this.props.adres;
174+
} else {
175+
this.props.adres = "";
176+
}
177+
this.props.aantal_schakelaars = 1;
178+
this.props.type_schakelaar = "wissel_enkel"
179+
180+
if (this.getParent().props.type === "Meerdere verbruikers") {
181+
this.parent = this.getParent().id;
182+
} else {
183+
this.parent = lastschakelaar.id;
184+
}
185+
}
186+
break;
187+
188+
case "dubbelpolig":
189+
if (Number(this.props.aantal_schakelaars) > 1) { // Er zijn er altijd 2 als er niet 1 is
190+
191+
let schakelaar1 = new Schakelaars(this.sourcelist);
192+
Object.assign(schakelaar1.props, this.props);
193+
schakelaar1.props.aantal_schakelaars = 1;
194+
schakelaar1.props.type_schakelaar = "wissel_dubbel";
195+
schakelaar1.props.adres = "";
196+
this.sourcelist.insertItemBeforeId(schakelaar1,this.id);
197+
198+
this.props.aantal_schakelaars = 1;
199+
this.props.type_schakelaar = "wissel_dubbel"
200+
if (this.getParent().props.type == "Meerdere verbruikers") {
201+
this.parent = this.getParent().id;
202+
} else {
203+
this.parent = schakelaar1.id;
204+
}
205+
}
206+
break;
207+
}
208+
}
209+
127210
toSVG(sitplan = false, mirrortext = false) {
128211
let mySVG:SVGelement = new SVGelement();
129212
let tekenKeten: Array<Schakelaar> = [];

src/main.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ function HL_editmode() {
7373
HLRedrawTreeHTML();
7474
}
7575

76+
function HLExpand(my_id: number ) {
77+
let element: Electro_Item = structure.getElectroItemById(my_id) as Electro_Item;
78+
if (element !== null) {
79+
element.expand();
80+
}
81+
82+
structure.reSort();
83+
undostruct.store();
84+
HLRedrawTree();
85+
}
86+
7687
function HL_changeparent(my_id: number) {
7788
// See what the new parentid is
7889
let str_newparentid = (document.getElementById("id_parent_change_"+my_id) as HTMLInputElement).value;
@@ -94,7 +105,6 @@ function HL_changeparent(my_id: number) {
94105

95106
structure.reSort();
96107
undostruct.store();
97-
98108
HLRedrawTree();
99109
}
100110

0 commit comments

Comments
 (0)