This commit is contained in:
fan 2023-07-12 17:25:45 +08:00
commit f34c4a9da0
5 changed files with 163 additions and 100 deletions

View File

@ -51,6 +51,12 @@ export class LogicSectionData
set indexNumber(v: number) {
this.data.indexNumber = v;
}
get turnoutId(): string {
return this.data.turnoutId;
}
set turnoutId(v: string) {
this.data.turnoutId = v;
}
clone(): LogicSectionData {
return new LogicSectionData(this.data.cloneMessage());
}

View File

@ -1,11 +1,4 @@
import {
DisplayObject,
FederatedMouseEvent,
FederatedPointerEvent,
IHitArea,
IPointData,
Point,
} from 'pixi.js';
import { FederatedPointerEvent, IHitArea, IPointData, Point } from 'pixi.js';
import {
GraphicDrawAssistant,
GraphicIdGenerator,
@ -13,7 +6,6 @@ import {
JlDrawApp,
JlGraphic,
linePoint,
splitLineEvenly,
} from 'src/jl-graphic';
import {
@ -28,11 +20,6 @@ import { Turnout } from '../turnout/Turnout';
import { createRelatedRefProto } from '../CommonGraphics';
import { MenuItemOptions } from 'src/jl-graphic/ui/Menu';
import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu';
import { Dialog } from 'quasar';
import { LogicSection } from '../logicSection/LogicSection';
import { LogicSectionData } from 'src/drawApp/graphics/LogicSectionInteraction';
import { graphicData } from 'src/protos/stationLayoutGraphics';
import SectionSplitDialog from 'src/components/draw-app/dialogs/SectionSplitDialog.vue';
function hasCommonElements(arr1: string[], arr2: string[]) {
for (let i = 0; i < arr1.length; i++) {
@ -66,7 +53,7 @@ export class AxleCountingSectionDraw extends GraphicDrawAssistant<
super(app, template, 'sym_o_circle', '不展示');
this.codeGraph = this.graphicTemplate.new();
this.container.addChild(this.codeGraph);
AxleCountingSectionInteraction.init(app, this);
AxleCountingSectionInteraction.init(app);
}
bind(): void {
@ -318,14 +305,12 @@ const SectionEditMenu: ContextMenu = ContextMenu.init({
export class AxleCountingSectionInteraction extends GraphicInteractionPlugin<AxleCountingSection> {
static Name = 'AxleCountingSection_transform';
drawAssistant: AxleCountingSectionDraw;
constructor(app: JlDrawApp, da: AxleCountingSectionDraw) {
constructor(app: JlDrawApp) {
super(AxleCountingSectionInteraction.Name, app);
this.drawAssistant = da;
app.registerMenu(SectionEditMenu);
}
static init(app: JlDrawApp, da: AxleCountingSectionDraw) {
return new AxleCountingSectionInteraction(app, da);
static init(app: JlDrawApp) {
return new AxleCountingSectionInteraction(app);
}
filter(...grahpics: JlGraphic[]): AxleCountingSection[] | undefined {
return grahpics
@ -344,7 +329,6 @@ export class AxleCountingSectionInteraction extends GraphicInteractionPlugin<Axl
g.labelGraphic.cursor = 'pointer';
g.labelGraphic.selectable = true;
g.labelGraphic.draggable = true;
g.on('_rightclick', this.onContextMenu, this);
}
unbind(g: AxleCountingSection): void {
g.eventMode = 'none';
@ -358,69 +342,5 @@ export class AxleCountingSectionInteraction extends GraphicInteractionPlugin<Axl
g.labelGraphic.draggable = false;
g.labelGraphic.selectable = false;
g.labelGraphic.transformSave = false;
g.off('_rightclick', this.onContextMenu, this);
}
onContextMenu(e: FederatedMouseEvent) {
const target = e.target as DisplayObject;
const axleCountingSection = target.getGraphic() as AxleCountingSection;
this.app.updateSelected(axleCountingSection);
splitSectionConfig.handler = () => {
Dialog.create({
title: '拆分逻辑区段',
message: '请选择生成数量和方向',
component: SectionSplitDialog,
cancel: true,
persistent: true,
}).onOk((data: { num: number; dir: 'ltr' | 'rtl' }) => {
const logicSections = this.app.queryStore.queryByType<LogicSection>(
LogicSection.Type
);
logicSections.forEach((logicSection) => {
if (logicSection.datas.axleSectionId == axleCountingSection.id) {
this.app.deleteGraphics(logicSection);
}
});
const { num, dir } = data;
const axleCountingSectionData = axleCountingSection.datas;
const points = splitLineEvenly(
axleCountingSection.localToCanvasPoint(
axleCountingSectionData.points[0]
),
axleCountingSection.localToCanvasPoint(
axleCountingSectionData.points[
axleCountingSectionData.points.length - 1
]
),
num
);
if (
(dir === 'ltr' &&
axleCountingSectionData.points[0].x >
axleCountingSectionData.points[
axleCountingSectionData.points.length - 1
].x) ||
(dir === 'rtl' &&
axleCountingSectionData.points[0].x <
axleCountingSectionData.points[
axleCountingSectionData.points.length - 1
].x)
) {
}
points.forEach((ps) => {
const data = new LogicSectionData();
data.id = GraphicIdGenerator.next();
data.axleSectionId = axleCountingSection.id;
// data.code = `${codeAppend.charAt(i % 26)}`;
data.points = ps.map(
(p) => new graphicData.Point({ x: p.x, y: p.y })
);
const g = new LogicSection();
g.loadData(data);
this.drawAssistant.storeGraphic(g);
});
});
};
SectionEditMenu.open(e.global);
}
}

View File

@ -16,6 +16,8 @@ export interface ILogicSectionData extends GraphicData {
set axleSectionId(v: string);
get indexNumber(): number; // 索引编号
set indexNumber(v: number);
get turnoutId(): string; // 关联岔芯的道岔id
set turnoutId(v: string);
clone(): ILogicSectionData;
copyFrom(data: ILogicSectionData): void;
eq(other: ILogicSectionData): boolean;

View File

@ -1,4 +1,10 @@
import { FederatedPointerEvent, IHitArea, Point } from 'pixi.js';
import {
DisplayObject,
FederatedMouseEvent,
FederatedPointerEvent,
IHitArea,
Point,
} from 'pixi.js';
import {
GraphicDrawAssistant,
GraphicIdGenerator,
@ -6,6 +12,7 @@ import {
JlDrawApp,
JlGraphic,
linePoint,
splitLineEvenly,
} from 'src/jl-graphic';
import {
@ -17,6 +24,11 @@ import {
import { Turnout } from '../turnout/Turnout';
import { LogicSectionData } from 'src/drawApp/graphics/LogicSectionInteraction';
import { AxleCountingSection } from '../axleCountingSection/AxleCountingSection';
import SectionSplitDialog from 'src/components/draw-app/dialogs/SectionSplitDialog.vue';
import { MenuItemOptions } from 'src/jl-graphic/ui/Menu';
import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu';
import { Dialog } from 'quasar';
import { graphicData } from 'src/protos/stationLayoutGraphics';
export interface ILogicSectionDrawOptions {
newData: () => ILogicSectionData;
@ -31,7 +43,7 @@ export class LogicSectionDraw extends GraphicDrawAssistant<
super(app, template, 'sym_o_circle', '不展示');
this.codeGraph = this.graphicTemplate.new();
this.container.addChild(this.codeGraph);
LogicSectionInteraction.init(app);
LogicSectionInteraction.init(app, this);
}
bind(): void {
@ -75,7 +87,10 @@ export class LogicSectionDraw extends GraphicDrawAssistant<
logicSection.datas.axleSectionId
) as AxleCountingSection;
if (ac) {
map.set(`${logicSection.datas.axleSectionId}`, 1);
map.set(
`${logicSection.datas.axleSectionId}-${logicSection.datas.turnoutId}`,
1
);
} else {
this.app.deleteGraphics(logicSection);
}
@ -85,14 +100,14 @@ export class LogicSectionDraw extends GraphicDrawAssistant<
AxleCountingSection.Type
);
axleCountingSections.forEach((axleCountingSection) => {
if (map.has(`${axleCountingSection.id}`)) {
return;
}
map.set(`${axleCountingSection.id}`, 1);
const turnoutPosRef = axleCountingSection.datas.turnoutPosRef;
if (turnoutPosRef.length > 0) {
turnoutPosRef.forEach((turnout) => {
if (turnout.position == 1) {
if (
turnout.position == 1 &&
!map.has(`${axleCountingSection.id}-${turnout.id}`)
) {
map.set(`${axleCountingSection.id}-${turnout.id}`, 1);
const t = this.app.queryStore.queryById(turnout.id) as Turnout;
const data = new LogicSectionData();
data.points = [
@ -100,14 +115,18 @@ export class LogicSectionDraw extends GraphicDrawAssistant<
...t.localToCanvasPoints(...t.datas.pointC),
];
data.axleSectionId = axleCountingSection.id;
data.turnoutId = turnout.id;
this.draw(data);
}
});
}
if (!map.has(`${axleCountingSection.id}-`)) {
map.set(`${axleCountingSection.id}-`, 1);
const data = new LogicSectionData();
data.points = axleCountingSection.datas.points;
data.axleSectionId = axleCountingSection.id;
this.draw(data);
}
});
}
}
@ -128,13 +147,28 @@ class LogicSectionGraphicHitArea implements IHitArea {
}
}
export const splitSectionConfig: MenuItemOptions = {
name: '拆分',
};
const SectionEditMenu: ContextMenu = ContextMenu.init({
name: '区段编辑菜单',
groups: [
{
items: [splitSectionConfig],
},
],
});
export class LogicSectionInteraction extends GraphicInteractionPlugin<LogicSection> {
static Name = 'LogicSection_transform';
constructor(app: JlDrawApp) {
drawAssistant: LogicSectionDraw;
constructor(app: JlDrawApp, da: LogicSectionDraw) {
super(LogicSectionInteraction.Name, app);
this.drawAssistant = da;
app.registerMenu(SectionEditMenu);
}
static init(app: JlDrawApp) {
return new LogicSectionInteraction(app);
static init(app: JlDrawApp, da: LogicSectionDraw) {
return new LogicSectionInteraction(app, da);
}
filter(...grahpics: JlGraphic[]): LogicSection[] | undefined {
return grahpics
@ -153,6 +187,7 @@ export class LogicSectionInteraction extends GraphicInteractionPlugin<LogicSecti
g.labelGraphic.cursor = 'pointer';
g.labelGraphic.selectable = true;
g.labelGraphic.draggable = true;
g.on('_rightclick', this.onContextMenu, this);
}
unbind(g: LogicSection): void {
g.eventMode = 'none';
@ -166,5 +201,82 @@ export class LogicSectionInteraction extends GraphicInteractionPlugin<LogicSecti
g.labelGraphic.draggable = false;
g.labelGraphic.selectable = false;
g.labelGraphic.transformSave = false;
g.off('_rightclick', this.onContextMenu, this);
}
onContextMenu(e: FederatedMouseEvent) {
const target = e.target as DisplayObject;
const logicSection = target.getGraphic() as LogicSection;
this.app.updateSelected(logicSection);
splitSectionConfig.handler = () => {
Dialog.create({
title: '拆分逻辑区段',
message: '请选择生成数量和方向',
component: SectionSplitDialog,
cancel: true,
persistent: true,
}).onOk((data: { num: number; dir: 'ltr' | 'rtl' }) => {
const axleSectionId = logicSection.datas.axleSectionId;
const turnoutId = logicSection.datas.turnoutId;
const axleCountingSection = this.app.queryStore.queryById(
axleSectionId
) as AxleCountingSection;
const logicSections = this.app.queryStore.queryByType<LogicSection>(
LogicSection.Type
);
logicSections.forEach((logicSection) => {
if (
logicSection.datas.axleSectionId == axleSectionId &&
logicSection.datas.turnoutId == turnoutId
) {
logicSection.selected = false;
this.app.deleteGraphics(logicSection);
}
});
const { num, dir } = data;
const axleCountingSectionData = axleCountingSection.datas;
let arrP = [];
if (turnoutId) {
const t = this.app.queryStore.queryById(turnoutId) as Turnout;
arrP = [t.position, ...t.localToCanvasPoints(...t.datas.pointC)];
} else {
arrP = [
...axleCountingSection.localToCanvasPoints(
...axleCountingSectionData.points
),
];
}
const points = splitLineEvenly(arrP[0], arrP[arrP.length - 1], num);
if (
(dir === 'ltr' &&
axleCountingSectionData.points[0].x >
axleCountingSectionData.points[
axleCountingSectionData.points.length - 1
].x) ||
(dir === 'rtl' &&
axleCountingSectionData.points[0].x <
axleCountingSectionData.points[
axleCountingSectionData.points.length - 1
].x)
) {
}
points.forEach((ps) => {
const data = new LogicSectionData();
data.id = GraphicIdGenerator.next();
data.axleSectionId = axleCountingSection.id;
if (turnoutId) {
data.turnoutId = turnoutId;
}
// data.code = `${codeAppend.charAt(i % 26)}`;
data.points = ps.map(
(p) => new graphicData.Point({ x: p.x, y: p.y })
);
const g = new LogicSection();
g.loadData(data);
this.drawAssistant.storeGraphic(g);
});
});
};
SectionEditMenu.open(e.global);
}
}

View File

@ -4172,6 +4172,7 @@ export namespace graphicData {
points?: Point[];
axleSectionId?: string;
indexNumber?: number;
turnoutId?: string;
}) {
super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [3], this.#one_of_decls);
@ -4191,6 +4192,9 @@ export namespace graphicData {
if ("indexNumber" in data && data.indexNumber != undefined) {
this.indexNumber = data.indexNumber;
}
if ("turnoutId" in data && data.turnoutId != undefined) {
this.turnoutId = data.turnoutId;
}
}
}
get common() {
@ -4226,12 +4230,19 @@ export namespace graphicData {
set indexNumber(value: number) {
pb_1.Message.setField(this, 5, value);
}
get turnoutId() {
return pb_1.Message.getFieldWithDefault(this, 6, "") as string;
}
set turnoutId(value: string) {
pb_1.Message.setField(this, 6, value);
}
static fromObject(data: {
common?: ReturnType<typeof CommonInfo.prototype.toObject>;
code?: string;
points?: ReturnType<typeof Point.prototype.toObject>[];
axleSectionId?: string;
indexNumber?: number;
turnoutId?: string;
}): LogicSection {
const message = new LogicSection({});
if (data.common != null) {
@ -4249,6 +4260,9 @@ export namespace graphicData {
if (data.indexNumber != null) {
message.indexNumber = data.indexNumber;
}
if (data.turnoutId != null) {
message.turnoutId = data.turnoutId;
}
return message;
}
toObject() {
@ -4258,6 +4272,7 @@ export namespace graphicData {
points?: ReturnType<typeof Point.prototype.toObject>[];
axleSectionId?: string;
indexNumber?: number;
turnoutId?: string;
} = {};
if (this.common != null) {
data.common = this.common.toObject();
@ -4274,6 +4289,9 @@ export namespace graphicData {
if (this.indexNumber != null) {
data.indexNumber = this.indexNumber;
}
if (this.turnoutId != null) {
data.turnoutId = this.turnoutId;
}
return data;
}
serialize(): Uint8Array;
@ -4290,6 +4308,8 @@ export namespace graphicData {
writer.writeString(4, this.axleSectionId);
if (this.indexNumber != 0)
writer.writeInt32(5, this.indexNumber);
if (this.turnoutId.length)
writer.writeString(6, this.turnoutId);
if (!w)
return writer.getResultBuffer();
}
@ -4314,6 +4334,9 @@ export namespace graphicData {
case 5:
message.indexNumber = reader.readInt32();
break;
case 6:
message.turnoutId = reader.readString();
break;
default: reader.skipField();
}
}