调整道岔生成逻辑

This commit is contained in:
zyy 2020-12-15 11:10:05 +08:00
parent e5a51e0d90
commit b85dcb41dc
3 changed files with 165 additions and 89 deletions

View File

@ -183,14 +183,22 @@ export function parser(data, skinCode, showConfig) {
if (sectionParent) { if (sectionParent) {
sectionParent['switch'] = mapDevice[elem.code]; sectionParent['switch'] = mapDevice[elem.code];
} }
let sectionCStar, sectionCEnd;
if (handleResetPoint(rnodeSection.points)) {
sectionCStar = rnodeSection.points[0];
sectionCEnd = rnodeSection.points[1];
} else {
sectionCStar = rnodeSection.points[1];
sectionCEnd = rnodeSection.points[0];
}
if (cnodeSection.points[0].x == lnodeSection.points[lnodeSection.points.length - 1].x && cnodeSection.points[0].y == lnodeSection.points[lnodeSection.points.length - 1].y) { if (cnodeSection.points[0].x == lnodeSection.points[lnodeSection.points.length - 1].x && cnodeSection.points[0].y == lnodeSection.points[lnodeSection.points.length - 1].y) {
mapDevice[elem.code].intersection = { mapDevice[elem.code].intersection = {
x: cnodeSection.points[0].x, x: cnodeSection.points[0].x,
y: cnodeSection.points[0].y y: cnodeSection.points[0].y
}; };
mapDevice[elem.code].skew = { mapDevice[elem.code].skew = {
x: rnodeSection.points[rnodeSection.points.length - 2].x, x: sectionCStar.x,
y: rnodeSection.points[rnodeSection.points.length - 2].y y: sectionCStar.y
}; };
} else if (cnodeSection.points[cnodeSection.points.length - 1].x == lnodeSection.points[0].x && cnodeSection.points[cnodeSection.points.length - 1].y == lnodeSection.points[0].y) { } else if (cnodeSection.points[cnodeSection.points.length - 1].x == lnodeSection.points[0].x && cnodeSection.points[cnodeSection.points.length - 1].y == lnodeSection.points[0].y) {
mapDevice[elem.code].intersection = { mapDevice[elem.code].intersection = {
@ -198,8 +206,8 @@ export function parser(data, skinCode, showConfig) {
y: cnodeSection.points[cnodeSection.points.length - 1].y y: cnodeSection.points[cnodeSection.points.length - 1].y
}; };
mapDevice[elem.code].skew = { mapDevice[elem.code].skew = {
x: rnodeSection.points[1].x, x: sectionCEnd.x,
y: rnodeSection.points[1].y y: sectionCEnd.y
}; };
} }
@ -254,6 +262,11 @@ export function parser(data, skinCode, showConfig) {
return mapDevice; return mapDevice;
} }
// 重置坐标点
function handleResetPoint(points) {
return (points[points.length - 1].x >= points[0].x) && (points[points.length - 1].y >= points[0].y);
}
// 同步绘制数据到原始数据 // 同步绘制数据到原始数据
export function updateForList(model, state, lstName) { export function updateForList(model, state, lstName) {
const list = state.map[lstName]; const list = state.map[lstName];

View File

@ -260,33 +260,33 @@ export default {
const end_x = endModel.points[0].x; const end_x = endModel.points[0].x;
const start_y = startModel.points[startModel.points.length - 1].y; const start_y = startModel.points[startModel.points.length - 1].y;
const end_y = endModel.points[0].y; const end_y = endModel.points[0].y;
if (end_x > start_x) { // if (end_x > start_x) {
if (this.createModel.leftSectionCode === this.createModel.rightSectionCode) { if (this.createModel.leftSectionCode === this.createModel.rightSectionCode) {
this.$messageBox('左关联区段不能和右关联区段相同'); this.$messageBox('左关联区段不能和右关联区段相同');
return; return;
}
if (start_x === end_x && start_y === end_y) {
this.$messageBox('左关联区段终点不能和右关联区段起点相同');
return;
}
model.points = [
{ x: start_x, y: start_y },
{ x: end_x, y: end_y }
];
const models = [];
model.leftSectionCode = this.createModel.leftSectionCode;
startModel.rightSectionCode = model.code;
endModel.leftSectionCode = model.code;
model.rightSectionCode = this.createModel.rightSectionCode;
models.push(model);
models.push(startModel);
models.push(endModel);
this.$emit('updateMapModel', models);
} else {
this.$messageBox('画图顺序应左往右绘制, 请求重新定义左右关联区段');
this.createModel.rightSectionCode = '';
this.createModel.leftSectionCode = '';
} }
if (start_x === end_x && start_y === end_y) {
this.$messageBox('左关联区段终点不能和右关联区段起点相同');
return;
}
model.points = [
{ x: start_x, y: start_y },
{ x: end_x, y: end_y }
];
const models = [];
model.leftSectionCode = this.createModel.leftSectionCode;
startModel.rightSectionCode = model.code;
endModel.leftSectionCode = model.code;
model.rightSectionCode = this.createModel.rightSectionCode;
models.push(model);
models.push(startModel);
models.push(endModel);
this.$emit('updateMapModel', models);
// } else {
// this.$messageBox(', ');
// this.createModel.rightSectionCode = '';
// this.createModel.leftSectionCode = '';
// }
}, },
// //
create() { create() {

View File

@ -23,15 +23,21 @@ export default {
methods:{ methods:{
create() { // create() { //
const createArr = []; // model const createArr = []; // model
const changeSectionList = this.changeSectionAttr(); const changeSectionList = this.changeSectionAttr(); //
changeSectionList.forEach(section => { changeSectionList.forEach(section => {
if (!section.rightSectionCode) { // if (section['typeModel'] && section['typeModel'] == 'start') { //
const list = this.findSectionA(section.points[section.points.length - 1].x, section.points[section.points.length - 1].y); const list = this.findSectionA(section.points[section.points.length - 1].x, section.points[section.points.length - 1].y, changeSectionList, section.code);
let sectionB = {}; let sectionB = {};
let sectionC = {}; let sectionC = {};
if (list.length >= 2) { if (list.length >= 2) {
list.forEach(item => { list.forEach(item => {
if ((item.points[1].y == section.points[section.points.length - 1].y) || (item.points[1].x == section.points[section.points.length - 1].x)) { // let sectionEnd;
if (this.handleResetPoint(item.points)) {
sectionEnd = item.points[item.points.length - 1];
} else {
sectionEnd = item.points[0];
}
if ((sectionEnd.y == section.points[section.points.length - 1].y) || (sectionEnd.x == section.points[section.points.length - 1].x)) { //
sectionB = item; sectionB = item;
} else { } else {
sectionC = item; sectionC = item;
@ -40,6 +46,18 @@ export default {
if (section.code && sectionB.code && sectionC.code) { if (section.code && sectionB.code && sectionC.code) {
const uname = 'W' + section.name.replace('T', ''); const uname = 'W' + section.name.replace('T', '');
const switchModel = getModel('Switch'); const switchModel = getModel('Switch');
let intersection;
if (this.handleResetPoint(section.points)) {
intersection = section.points[section.points.length - 1];
} else {
intersection = section.points[0];
}
let skew;
if (this.handleResetPoint(sectionC.points)) {
skew = sectionC.points[sectionC.points.length - 1];
} else {
skew = sectionC.points[0];
}
const data = { const data = {
code: getUID('W', [...this.switchList, ...createArr]), code: getUID('W', [...this.switchList, ...createArr]),
name: uname, name: uname,
@ -50,12 +68,12 @@ export default {
sectionCCode: sectionC.code, sectionCCode: sectionC.code,
turnTime: 3, turnTime: 3,
intersection: { intersection: {
x: section.points[section.points.length - 1].x, x: intersection.x,
y: section.points[section.points.length - 1].y y: intersection.y
}, },
skew: { skew: {
x: sectionC.points[1].x, x: skew.x,
y: sectionC.points[1].y y: skew.y
}, },
normalPosition: 1 // normalPosition: 1 //
}; };
@ -65,13 +83,19 @@ export default {
} }
} }
} }
if (!section.leftSectionCode) { // if (section['typeModel'] && section['typeModel'] == 'end') { //
const list = this.findSectionB(section.points[0].x, section.points[0].y); const list = this.findSectionB(section.points[0].x, section.points[0].y, changeSectionList, section.code);
let sectionB = {}; let sectionB = {};
let sectionC = {}; let sectionC = {};
if (list.length >= 2) { if (list.length >= 2) {
list.forEach(item => { list.forEach(item => {
if ((item.points[item.points.length - 2].y == section.points[0].y) || (item.points[item.points.length - 2].x == section.points[0].x)) { // let sectionStart;
if (this.handleResetPoint(item.points)) {
sectionStart = item.points[0];
} else {
sectionStart = item.points[item.points.length - 1];
}
if ((sectionStart.y == section.points[0].y) || (sectionStart.x == section.points[0].x)) { //
sectionB = item; sectionB = item;
} else { } else {
sectionC = item; sectionC = item;
@ -80,6 +104,18 @@ export default {
if (section.code && sectionB.code && sectionC.code) { if (section.code && sectionB.code && sectionC.code) {
const uname = 'W' + section.name.replace('T', ''); const uname = 'W' + section.name.replace('T', '');
const switchModel = getModel('Switch'); const switchModel = getModel('Switch');
let intersection;
if (this.handleResetPoint(section.points)) {
intersection = section.points[0];
} else {
intersection = section.points[section.points.length - 1];
}
let skew;
if (this.handleResetPoint(sectionC.points)) {
skew = sectionC.points[0];
} else {
skew = sectionC.points[sectionC.points.length - 1];
}
const data = { const data = {
code: getUID('W', [...this.switchList, ...createArr]), code: getUID('W', [...this.switchList, ...createArr]),
name: uname, name: uname,
@ -90,12 +126,12 @@ export default {
sectionCCode: sectionC.code, sectionCCode: sectionC.code,
turnTime: 3, turnTime: 3,
intersection: { intersection: {
x: section.points[0].x, x: intersection.x,
y: section.points[0].y y: intersection.y
}, },
skew: { skew: {
x: sectionC.points[sectionC.points.length - 2].x, x: skew.x,
y: sectionC.points[sectionC.points.length - 2].y y: skew.y
}, },
normalPosition: 1 // normalPosition: 1 //
}; };
@ -121,20 +157,36 @@ export default {
this.$message( this.$t('tip.cancelGeneration')); this.$message( this.$t('tip.cancelGeneration'));
}); });
}, },
findSectionA(pointX, pointY) { findSectionA(pointX, pointY, lists, code) {
const list = []; const list = [];
this.sectionList.forEach(item => { lists.forEach(item => {
if (item.points[0].x == pointX && item.points[0].y == pointY) { if (item.code != code) {
list.push(item); if (this.handleResetPoint(item.points)) {
if (item.points[0].x == pointX && item.points[0].y == pointY) {
list.push(item);
}
} else {
if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) {
list.push(item);
}
}
} }
}); });
return list; return list;
}, },
findSectionB(pointX, pointY) { findSectionB(pointX, pointY, lists, code) {
const list = []; const list = [];
this.sectionList.forEach(item => { lists.forEach(item => {
if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) { if (item.code != code) {
list.push(item); if (this.handleResetPoint(item.points)) {
if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) {
list.push(item);
}
} else {
if (item.points[0].x == pointX && item.points[0].y == pointY) {
list.push(item);
}
}
} }
}); });
return list; return list;
@ -154,6 +206,10 @@ export default {
} }
return rtn; return rtn;
}, },
//
handleResetPoint(points) {
return (points[points.length - 1].x >= points[0].x) && (points[points.length - 1].y >= points[0].y);
},
// //
changeSectionAttr() { changeSectionAttr() {
const changeSectionList = []; // const changeSectionList = []; //
@ -163,48 +219,55 @@ export default {
const oneSectionStar = section.points[0]; const oneSectionStar = section.points[0];
let countA = 0; let countA = 0;
let countB = 0; let countB = 0;
console.log(changeSectionList);
this.sectionList.forEach(elem => { this.sectionList.forEach(elem => {
if (elem.type == '01') { if (elem.type == '01' && section.code != elem.code) {
const twoSection = elem.points[0]; let twoSection, twoSectionEnd;
const twoSectionEnd = elem.points[elem.points.length - 1]; if (this.handleResetPoint(elem.points)) {
twoSection = elem.points[0];
twoSectionEnd = elem.points[elem.points.length - 1];
} else {
twoSection = elem.points[elem.points.length - 1];
twoSectionEnd = elem.points[0];
}
if (oneSection.x == twoSection.x && oneSection.y == twoSection.y) { if (oneSection.x == twoSection.x && oneSection.y == twoSection.y) {
countA++; countA++;
if (countA >= 2) { if (countA >= 2) {
if (!this.checkAddListA(oneSection, section.code)) { // // if (!this.checkAddListA(oneSection, section.code)) { //
const sectionModel = deepAssign({}, section); const sectionModel = deepAssign({}, section);
sectionModel.rightSectionCode = ''; sectionModel.rightSectionCode = '';
sectionModel.sepTypeRight = '00'; // sectionModel.sepTypeRight = '00'; //
sectionModel.type = '03'; sectionModel.type = '03';
const list = this.findSectionA(sectionModel.points[sectionModel.points.length - 1].x, sectionModel.points[sectionModel.points.length - 1].y); const list = this.findSectionA(sectionModel.points[sectionModel.points.length - 1].x, sectionModel.points[sectionModel.points.length - 1].y, this.sectionList, sectionModel.code);
list.forEach(elem => { list.forEach(elem => {
const sectionModelElem = deepAssign({}, elem); const sectionModelElem = deepAssign({}, elem);
sectionModelElem.leftSectionCode = ''; sectionModelElem.leftSectionCode = '';
sectionModelElem.sepTypeLeft = '00'; sectionModelElem.sepTypeLeft = '00';
sectionModelElem.type = '03'; sectionModelElem.type = '03';
changeSectionList.push(sectionModelElem); changeSectionList.push(sectionModelElem);
}); });
changeSectionList.push(sectionModel); sectionModel['typeModel'] = 'start';
} changeSectionList.push(sectionModel);
// }
} }
} else if (oneSectionStar.x == twoSectionEnd.x && oneSectionStar.y == twoSectionEnd.y) { } else if (oneSectionStar.x == twoSectionEnd.x && oneSectionStar.y == twoSectionEnd.y) {
countB++; countB++;
if (countB >= 2) { if (countB >= 2) {
if (!this.checkAddListB(oneSectionStar, section.code)) { // // if (!this.checkAddListB(oneSectionStar, section.code)) { //
const sectionModel = deepAssign({}, section); const sectionModel = deepAssign({}, section);
sectionModel.leftSectionCode = ''; sectionModel.leftSectionCode = '';
sectionModel.sepTypeLeft = '00'; sectionModel.sepTypeLeft = '00';
sectionModel.type = '03'; sectionModel.type = '03';
const list = this.findSectionB(sectionModel.points[0].x, sectionModel.points[0].y); const list = this.findSectionB(sectionModel.points[0].x, sectionModel.points[0].y, this.sectionList, sectionModel.code);
list.forEach(elem => { list.forEach(elem => {
const sectionModelElem = deepAssign({}, elem); const sectionModelElem = deepAssign({}, elem);
sectionModelElem.rightSectionCode = ''; sectionModelElem.rightSectionCode = '';
sectionModelElem.sepTypeRight = '00'; // sectionModelElem.sepTypeRight = '00'; //
sectionModelElem.type = '03'; sectionModelElem.type = '03';
changeSectionList.push(sectionModelElem); changeSectionList.push(sectionModelElem);
}); });
changeSectionList.push(sectionModel); sectionModel['typeModel'] = 'end';
} changeSectionList.push(sectionModel);
// }
} }
} }
} }
@ -213,7 +276,7 @@ export default {
}); });
return changeSectionList; return changeSectionList;
}, },
checkAddListA(points, code) { // list checkAddListA(points, code) { // list ()
let flag = false; let flag = false;
this.sectionList.forEach(section => { this.sectionList.forEach(section => {
section.points.forEach((point, index) => { section.points.forEach((point, index) => {
@ -227,7 +290,7 @@ export default {
}); });
return flag; return flag;
}, },
checkAddListB(points, code) { // list checkAddListB(points, code) { // list ()
let flag = false; let flag = false;
this.sectionList.forEach(section => { this.sectionList.forEach(section => {
section.points.forEach((point, index) => { section.points.forEach((point, index) => {