public bool link(Cell originCell, LayerType layerType) { if (layers[(int)layerType].isSet && originCell.layers[(int)layerType].isSet) { // lien Nord if (originCell.x == x && originCell.y - y == -1) { layers[(int)layerType].links[(int)CellLayer.Cardinals.N] = originCell; originCell.layers[(int)layerType].links[(int)CellLayer.Cardinals.S] = this; originCell.draw(); return true; // lien Sud } else if (originCell.x == x && originCell.y - y == 1) { layers[(int)layerType].links[(int)CellLayer.Cardinals.S] = originCell; originCell.layers[(int)layerType].links[(int)CellLayer.Cardinals.N] = this; originCell.draw(); return true; // lien Ouest } else if (originCell.y == y && originCell.x - x == -1) { layers[(int)layerType].links[(int)CellLayer.Cardinals.W] = originCell; originCell.layers[(int)layerType].links[(int)CellLayer.Cardinals.E] = this; originCell.draw(); return true; // lien Est } else if (originCell.y == y && originCell.x - x == 1) { layers[(int)layerType].links[(int)CellLayer.Cardinals.E] = originCell; originCell.layers[(int)layerType].links[(int)CellLayer.Cardinals.W] = this; originCell.draw(); return true; } } // creation portes PNP NPN switch (layerType) { // PNP case LayerType.SILICON_N: if (layers[(int)LayerType.SILICON_P].isSet) { // nord if (originCell.x == x && originCell.y - y == -1) { if (layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.E] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.W] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.S] == null) { layers[(int)LayerType.PNP].isSet = true; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.N] = originCell; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.W] = circuit.findCellByCoords(x - 1, y); layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.E] = circuit.findCellByCoords(x + 1, y); originCell.layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.S] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } else // sud if (originCell.x == x && originCell.y - y == 1) { if (layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.E] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.W] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.N] == null) { layers[(int)LayerType.PNP].isSet = true; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.S] = originCell; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.W] = circuit.findCellByCoords(x - 1, y); layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.E] = circuit.findCellByCoords(x + 1, y); originCell.layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.N] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } else // ouest if (originCell.y == y && originCell.x - x == -1) { if (layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.N] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.S] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.E] == null) { layers[(int)LayerType.PNP].isSet = true; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.W] = originCell; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.S] = circuit.findCellByCoords(x, y + 1); layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.N] = circuit.findCellByCoords(x, y - 1); originCell.layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.E] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } else // est if (originCell.y == y && originCell.x - x == 1) { if (layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.N] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.S] != null && layers[(int)LayerType.SILICON_P].links[(int)CellLayer.Cardinals.W] == null) { layers[(int)LayerType.PNP].isSet = true; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.E] = originCell; layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.S] = circuit.findCellByCoords(x, y + 1); layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.N] = circuit.findCellByCoords(x, y - 1); originCell.layers[(int)LayerType.PNP].links[(int)CellLayer.Cardinals.W] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } } break; // NPN case LayerType.SILICON_P: if (layers[(int)LayerType.SILICON_N].isSet) { // nord if (originCell.x == x && originCell.y - y == -1) { if (layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.E] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.W] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.S] == null) { layers[(int)LayerType.NPN].isSet = true; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.N] = originCell; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.W] = circuit.findCellByCoords(x - 1, y); layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.E] = circuit.findCellByCoords(x + 1, y); originCell.layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.S] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } else // sud if (originCell.x == x && originCell.y - y == 1) { if (layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.E] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.W] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.N] == null) { layers[(int)LayerType.NPN].isSet = true; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.S] = originCell; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.W] = circuit.findCellByCoords(x - 1, y); layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.E] = circuit.findCellByCoords(x + 1, y); originCell.layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.N] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } else // ouest if (originCell.y == y && originCell.x - x == -1) { if (layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.N] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.S] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.E] == null) { layers[(int)LayerType.NPN].isSet = true; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.W] = originCell; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.S] = circuit.findCellByCoords(x, y + 1); layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.N] = circuit.findCellByCoords(x, y - 1); originCell.layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.E] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } else // est if (originCell.y == y && originCell.x - x == 1) { if (layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.N] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.S] != null && layers[(int)LayerType.SILICON_N].links[(int)CellLayer.Cardinals.W] == null) { layers[(int)LayerType.NPN].isSet = true; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.E] = originCell; layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.S] = circuit.findCellByCoords(x, y + 1); layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.N] = circuit.findCellByCoords(x, y - 1); originCell.layers[(int)LayerType.NPN].links[(int)CellLayer.Cardinals.W] = this; layers[(int)LayerType.SILICON_N].isSet = false; layers[(int)LayerType.SILICON_P].isSet = false; draw(); originCell.draw(); } } } break; } return false; }