You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
5.5 KiB
204 lines
5.5 KiB
function createEnd() {
|
|
|
|
//find X and Y
|
|
|
|
var X = stage.width() - stage.width() /100 * 10;
|
|
console.log(X);
|
|
var Y = stage.height() / 3;
|
|
|
|
var imageObj2 = new Image();
|
|
imageObj2.onload = function () {
|
|
var end = new Konva.Image({
|
|
x: X,
|
|
y: Y,
|
|
image: imageObj2,
|
|
width: 50,
|
|
height: 50,
|
|
id: "end",
|
|
});
|
|
layer.add(end);
|
|
layer.batchDraw();
|
|
};
|
|
end = {
|
|
name: "end",
|
|
x: X,
|
|
y: Y,
|
|
type: "end",
|
|
position: 1,
|
|
let:1,
|
|
}
|
|
imageObj2.src = pathImg + imageEnd;
|
|
}
|
|
|
|
function createSwitch(id, x, y) {
|
|
switchs.push(id);
|
|
var num = lineCount.length;
|
|
lineCount.push(1);
|
|
var rect1 = new Konva.Rect({
|
|
x: x,
|
|
y: y,
|
|
width: SwitchWidth,
|
|
height: SwitchHeight,
|
|
stroke: colorSwitchBorder,
|
|
fill: colorSwitchInnactiveBackground,
|
|
strokeWidth: 4,
|
|
id: id,
|
|
id3: null,
|
|
});
|
|
layer.add(rect1);
|
|
}
|
|
|
|
function createLine(points, id) {
|
|
let startX = points[0], startY = points[1], endX = points[2], endY = points[3];
|
|
let distance20 = (endX - startX)/100*pourcentageBreak;
|
|
let newPoints = [startX, startY,startX + distance20, startY,endX - distance20,endY,endX,endY];
|
|
let line = new Konva.Line({
|
|
points: newPoints,
|
|
stroke: colorLineInnactive,
|
|
strokeWidth: lineStroke,
|
|
id: id,
|
|
});
|
|
layer.add(line);
|
|
}
|
|
|
|
|
|
function createLink(entre, sortie) {
|
|
//entre est une porte logique
|
|
lineId = lineCount.length;
|
|
lineCount.push(1);
|
|
switch (whatIsElement(entre)) {
|
|
case "switch":
|
|
switch (whatIsElement(sortie)) {
|
|
case "logique":
|
|
switch (giveLineId(sortie.name)) {
|
|
case "id1":
|
|
let switchMidX = entre.getX() + entre.getWidth();
|
|
let switchMidY = entre.getY() + entre.getHeight() / 2;
|
|
|
|
let logiqueMidX = sortie.x;
|
|
if(sortie.type === "inv"){
|
|
var logiqueMidY = sortie.y + (imageHeight / 2);
|
|
}else{
|
|
var logiqueMidY = sortie.y + (imageHeight / 3);
|
|
}
|
|
createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId);
|
|
setLine(sortie, "id1", "line" + lineId);
|
|
entre.id3 = "line" + lineId;
|
|
break;
|
|
case "id2":
|
|
createLine([entre.getX() + entre.getWidth(), entre.getY() + entre.getHeight() / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId);
|
|
setLine(sortie, "id2", "line" + lineId);
|
|
entre.id3 = "line" + lineId;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case "logique":
|
|
switch (whatIsElement(sortie)) {
|
|
case "logique":
|
|
switch (giveLineId(sortie.name)) {
|
|
case "id1":
|
|
let switchMidX = entre.x + imageWidth;
|
|
let switchMidY = entre.y + imageHeight / 2;
|
|
|
|
let logiqueMidX = sortie.x;
|
|
if(sortie.type === "inv"){
|
|
var logiqueMidY = sortie.y + (imageHeight / 2);
|
|
}else{
|
|
var logiqueMidY = sortie.y + (imageHeight / 3);
|
|
}
|
|
createLine([switchMidX, switchMidY, logiqueMidX, logiqueMidY], "line" + lineId);
|
|
setLine(sortie, "id1", "line" + lineId);
|
|
setLine(entre, "id3", "line" + lineId);
|
|
break;
|
|
case "id2":
|
|
createLine([entre.x + imageWidth, entre.y + imageHeight / 2, sortie.x, sortie.y + (imageHeight / 3) * 2], "line" + lineId);
|
|
setLine(sortie, "id2", "line" + lineId);
|
|
setLine(entre, "id3", "line" + lineId);
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
endLines.push(lineId);
|
|
createLine([entre.x + imageWidth, entre.y + imageHeight / 2, sortie.x, sortie.y + (imageHeight / end.position+1)*end.let], "line" + lineId);
|
|
setLine(entre, "id3", "line" + lineId);
|
|
end.let--;
|
|
break;
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
function createLogique(x, y, id, type) {
|
|
var imageObj = new Image();
|
|
imageObj.onload = function () {
|
|
var et = new Konva.Image({
|
|
x: x,
|
|
y: y,
|
|
image: imageObj,
|
|
width: imageWidth,
|
|
height: imageHeight,
|
|
id: id,
|
|
});
|
|
if (imageRotation != 0) {
|
|
et.rotation(imageRotation);
|
|
et.x(et.getX() + imageHeight);
|
|
}
|
|
layer.add(et);
|
|
layer.batchDraw();
|
|
};
|
|
switch(type){
|
|
case "et" :
|
|
imageObj.src = pathImg + imageLogiqueEt;
|
|
break;
|
|
case "ou":
|
|
imageObj.src = pathImg + imageLogiqueOu;
|
|
break;
|
|
case "etnon":
|
|
imageObj.src = pathImg + imageLogiqueEtNon;
|
|
break;
|
|
case "inv":
|
|
imageObj.src = pathImg + imageLogiqueInv;
|
|
break;
|
|
case "nonou":
|
|
imageObj.src = pathImg + imageLogiqueNonOu;
|
|
break;
|
|
}
|
|
|
|
imageObj.id = id;
|
|
|
|
|
|
|
|
var logique = {
|
|
name: id,
|
|
x: x,
|
|
y: y,
|
|
type: type,
|
|
id1: null,
|
|
id2: null,
|
|
id3: null,
|
|
}
|
|
logiques.push(logique);
|
|
}
|
|
|
|
function switchCreator(number){
|
|
let split = number + 1;
|
|
let space = (stage.height() - stage.height()/100*25) / split;
|
|
for(let i = 1; i < number+1 ; i++){
|
|
createSwitch("s"+i, 20, (i) * space);
|
|
}
|
|
}
|
|
|
|
function insertLogiqueColonne(nomLogique, TypeLogique, colonne){
|
|
var X = stage.width() / (colonneTot+1) * (colonne+1);
|
|
//calcul position Y
|
|
if(numberPerColonne[colonne] == 1){
|
|
var Y = stage.height() / 3;
|
|
}else{
|
|
let numberAlreadyAdded = liveColonneNumber[colonne].length+1;
|
|
let split = (stage.height() - stage.height()/100*25) / (numberPerColonne[colonne]+1);
|
|
var Y = split * numberAlreadyAdded;
|
|
}
|
|
createLogique(X, Y, nomLogique,TypeLogique);
|
|
liveColonneNumber[colonne].push(1);
|
|
} |