master
pisouvigne 5 years ago
parent 7459fe550a
commit 7fa20c9b4e

@ -1,158 +1,158 @@
function createEnd(x, y) { function createEnd(x, y) {
var imageObj2 = new Image(); var imageObj2 = new Image();
imageObj2.onload = function () { imageObj2.onload = function () {
var end = new Konva.Image({ var end = new Konva.Image({
x: x, x: x,
y: y, y: y,
image: imageObj2, image: imageObj2,
width: 50, width: 50,
height: 50, height: 50,
id: "end", id: "end",
}); });
layer.add(end); layer.add(end);
layer.batchDraw(); layer.batchDraw();
}; };
imageObj2.src = pathImg + imageEnd; imageObj2.src = pathImg + imageEnd;
} }
function createSwitch(id, x, y) { function createSwitch(id, x, y) {
switchs.push(id); switchs.push(id);
var num = lineCount.length; var num = lineCount.length;
lineCount.push(1); lineCount.push(1);
var rect1 = new Konva.Rect({ var rect1 = new Konva.Rect({
x: x, x: x,
y: y, y: y,
width: 100, width: 100,
height: 50, height: 50,
stroke: colorSwitchBorder, stroke: colorSwitchBorder,
fill: colorSwitchInnactiveBackground, fill: colorSwitchInnactiveBackground,
strokeWidth: 4, strokeWidth: 4,
id: id, id: id,
id3: null, id3: null,
}); });
layer.add(rect1); layer.add(rect1);
} }
function createLine(points, id) { function createLine(points, id) {
let line = new Konva.Line({ let line = new Konva.Line({
points: points, points: points,
stroke: colorLineInnactive, stroke: colorLineInnactive,
strokeWidth: 3, strokeWidth: 3,
lineCap: 'round', lineCap: 'round',
lineJoin: 'round', lineJoin: 'round',
id: id, id: id,
}); });
layer.add(line); layer.add(line);
} }
function createLink(entre, sortie, lineId) { function createLink(entre, sortie, lineId) {
//entre est une porte logique //entre est une porte logique
switch (whatIsElement(entre)) { switch (whatIsElement(entre)) {
case "switch": case "switch":
switch (whatIsElement(sortie)) { switch (whatIsElement(sortie)) {
case "logique": case "logique":
switch (giveLineId(sortie.name)) { switch (giveLineId(sortie.name)) {
case "id1": case "id1":
let switchMidX = entre.getX() + entre.getWidth(); let switchMidX = entre.getX() + entre.getWidth();
let switchMidY = entre.getY() + entre.getHeight() / 2; let switchMidY = entre.getY() + entre.getHeight() / 2;
let logiqueMidX = sortie.x; let logiqueMidX = sortie.x;
let logiqueMidY = sortie.y + (imageHeight / 3); let logiqueMidY = sortie.y + (imageHeight / 3);
createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId); createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId);
setLine(sortie, "id1", "line" + lineId); setLine(sortie, "id1", "line" + lineId);
entre.id3 = "line" + lineId; entre.id3 = "line" + lineId;
break; break;
case "id2": case "id2":
createLine([entre.getX() + entre.getWidth(), entre.getY() + entre.getHeight() / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId); createLine([entre.getX() + entre.getWidth(), entre.getY() + entre.getHeight() / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId);
setLine(sortie, "id2", "line" + lineId); setLine(sortie, "id2", "line" + lineId);
entre.id3 = "line" + lineId; entre.id3 = "line" + lineId;
break; break;
} }
} }
break; break;
case "logique":
switch (whatIsElement(sortie)) {
case "logique": case "logique":
switch (whatIsElement(sortie)) { switch (giveLineId(sortie.name)) {
case "logique": case "id1":
switch (giveLineId(sortie.name)) { let switchMidX = entre.x + imageWidth;
case "id1": let switchMidY = entre.y + imageHeight / 2;
let switchMidX = entre.x + imageWidth;
let switchMidY = entre.y + imageHeight / 2; let logiqueMidX = sortie.x;
let logiqueMidY = sortie.y + (imageHeight / 3);
let logiqueMidX = sortie.x; createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId);
let logiqueMidY = sortie.y + (imageHeight / 3); setLine(sortie, "id1", "line" + lineId);
createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId); setLine(entre, "id3", "line" + lineId);
setLine(sortie, "id1", "line" + lineId); break;
setLine(entre, "id3", "line" + lineId); case "id2":
break; createLine([entre.x + imageWidth, entre.y + imageHeight / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId);
case "id2": setLine(sortie, "id2", "line" + lineId);
createLine([entre.x + imageWidth, entre.y + imageHeight / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId); setLine(entre, "id3", "line" + lineId);
setLine(sortie, "id2", "line" + lineId); break;
setLine(entre, "id3", "line" + lineId); }
break; }
} break;
} }
break;
}
} }
function createLogique(x, y, id, type) { function createLogique(x, y, id, type) {
switch (type) { switch (type) {
case "et": case "et":
var imageObj = new Image(); var imageObj = new Image();
imageObj.onload = function () { imageObj.onload = function () {
var et = new Konva.Image({ var et = new Konva.Image({
x: x, x: x,
y: y, y: y,
image: imageObj, image: imageObj,
width: imageWidth, width: imageWidth,
height: imageHeight, height: imageHeight,
id: id, id: id,
}); });
layer.add(et); layer.add(et);
layer.batchDraw(); layer.batchDraw();
}; };
imageObj.src = pathImg + imageLogiqueEt; imageObj.src = pathImg + imageLogiqueEt;
imageObj.id = id; imageObj.id = id;
break; break;
case "ou": case "ou":
var imageObj = new Image(); var imageObj = new Image();
imageObj.onload = function () { imageObj.onload = function () {
var et = new Konva.Image({ var et = new Konva.Image({
x: x, x: x,
y: y, y: y,
image: imageObj, image: imageObj,
width: imageWidth, width: imageWidth,
height: imageHeight, height: imageHeight,
id: id, id: id,
}); });
layer.add(et); layer.add(et);
layer.batchDraw(); layer.batchDraw();
}; };
imageObj.src = pathImg + imageLogiqueOu; imageObj.src = pathImg + imageLogiqueOu;
imageObj.id = id; imageObj.id = id;
break; break;
} }
var logique = { var logique = {
name: id, name: id,
x: x, x: x,
y: y, y: y,
type: type, type: type,
id1: null, id1: null,
id2: null, id2: null,
id3: null, id3: null,
} }
logiques.push(logique); logiques.push(logique);
} }

@ -8,6 +8,12 @@ function initAllSwitch(){
checkAllSortieLogique(); checkAllSortieLogique();
layer.draw(); layer.draw();
}); });
switche.on('mouseover', function () {
document.body.style.cursor = "pointer";
});
switche.on('mouseout', function () {
document.body.style.cursor = "default";
});
}); });
} }

Loading…
Cancel
Save