调整道岔生成逻辑
This commit is contained in:
parent
e5a51e0d90
commit
b85dcb41dc
@ -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];
|
||||||
|
@ -260,7 +260,7 @@ 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;
|
||||||
@ -282,11 +282,11 @@ export default {
|
|||||||
models.push(startModel);
|
models.push(startModel);
|
||||||
models.push(endModel);
|
models.push(endModel);
|
||||||
this.$emit('updateMapModel', models);
|
this.$emit('updateMapModel', models);
|
||||||
} else {
|
// } else {
|
||||||
this.$messageBox('画图顺序应左往右绘制, 请求重新定义左右关联区段');
|
// this.$messageBox('画图顺序应左往右绘制, 请求重新定义左右关联区段');
|
||||||
this.createModel.rightSectionCode = '';
|
// this.createModel.rightSectionCode = '';
|
||||||
this.createModel.leftSectionCode = '';
|
// this.createModel.leftSectionCode = '';
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
// 创建区段
|
// 创建区段
|
||||||
create() {
|
create() {
|
||||||
|
@ -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,21 +157,37 @@ 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.code != code) {
|
||||||
|
if (this.handleResetPoint(item.points)) {
|
||||||
if (item.points[0].x == pointX && item.points[0].y == pointY) {
|
if (item.points[0].x == pointX && item.points[0].y == pointY) {
|
||||||
list.push(item);
|
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.code != code) {
|
||||||
|
if (this.handleResetPoint(item.points)) {
|
||||||
if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) {
|
if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) {
|
||||||
list.push(item);
|
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,20 +219,25 @@ 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 = '';
|
||||||
@ -184,18 +245,19 @@ export default {
|
|||||||
sectionModelElem.type = '03';
|
sectionModelElem.type = '03';
|
||||||
changeSectionList.push(sectionModelElem);
|
changeSectionList.push(sectionModelElem);
|
||||||
});
|
});
|
||||||
|
sectionModel['typeModel'] = 'start';
|
||||||
changeSectionList.push(sectionModel);
|
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 = '';
|
||||||
@ -203,8 +265,9 @@ export default {
|
|||||||
sectionModelElem.type = '03';
|
sectionModelElem.type = '03';
|
||||||
changeSectionList.push(sectionModelElem);
|
changeSectionList.push(sectionModelElem);
|
||||||
});
|
});
|
||||||
|
sectionModel['typeModel'] = 'end';
|
||||||
changeSectionList.push(sectionModel);
|
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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user