This commit is contained in:
fan 2023-06-20 17:32:12 +08:00
commit f52bc51759
11 changed files with 54 additions and 31 deletions

@ -1 +1 @@
Subproject commit 5f7052ba9bcd3c9543250eda9ccb490dcb56739d
Subproject commit bf2d81625f3fa89eaca241ea3a04f2198dcfbba2

View File

@ -33,6 +33,18 @@ export class SectionData extends GraphicDataBase implements ISectionData {
(p) => new graphicData.Point({ x: p.x, y: p.y })
);
}
get paRef(): graphicData.RelatedRef {
return new graphicData.RelatedRef();
}
set paRef(ref: graphicData.RelatedRef) {
this.data.paRef = ref;
}
get pbRef(): graphicData.RelatedRef {
return new graphicData.RelatedRef();
}
set pbRef(ref: graphicData.RelatedRef) {
this.data.paRef = ref;
}
clone(): SectionData {
return new SectionData(this.data.cloneMessage());
}

View File

@ -53,7 +53,7 @@ import {
} from 'src/graphics/trainWindow/TrainWindow';
import { TrainWindowDraw } from 'src/graphics/trainWindow/TrainWindowDrawAssistant';
import { TrainWindowData } from './graphics/TrainWindowInteraction';
import { Turnout } from 'src/graphics/turnout/Turnout';
import { Turnout, TurnoutTemplate } from 'src/graphics/turnout/Turnout';
import { TurnoutDraw } from 'src/graphics/turnout/TurnoutDrawAssistant';
import { TurnoutData } from './graphics/TurnoutInteraction';
import { RunLine, RunLineTemplate } from 'src/graphics/runLine/RunLine';
@ -62,7 +62,7 @@ import { RunLineData, DrawRunLinePlugin } from './graphics/RunLineInteraction';
import { saveDraft, getDraft } from 'src/api/DraftApi';
import { useDrawStore } from 'src/stores/draw-store';
import { successNotify, errorNotify } from '../utils/CommonNotify';
import { Section } from 'src/graphics/section/Section';
import { Section, SectionTemplate } from 'src/graphics/section/Section';
import { SectionDraw } from 'src/graphics/section/SectionDrawAssistant';
import { SectionData } from './graphics/SectionInteraction';
import { PathLine, PathLineTemplate } from 'src/graphics/pathLine/PathLine';
@ -167,13 +167,11 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp {
app,
new SignalTemplate(new SignalData(), new SignalState())
),
new TurnoutDraw(app, () => {
return new TurnoutData();
}),
// new TrainDraw(app, () => {
// return new TrainData();
// }),
new SectionDraw(app, () => new SectionData()),
new SectionDraw(app, new SectionTemplate(new SectionData())),
new TurnoutDraw(app, new TurnoutTemplate(new TurnoutData())),
new TrainWindowDraw(app, new TrainWindowTemplate(new TrainWindowData())),
];
DrawSignalInteraction.init(app);

View File

@ -70,10 +70,17 @@ export class Section extends JlGraphic implements ILineGraphic {
});
this.labelGraphic.text = this.datas.code;
this.labelGraphic.position.set(
this.datas.points[0].x,
this.datas.points[0].y + 20
);
const labelPosition = this.datas.childTransforms?.find(
(t) => t.name === this.labelGraphic.name
)?.transform.position;
if (labelPosition) {
this.labelGraphic.position.set(labelPosition.x, labelPosition.y);
} else {
this.labelGraphic.position.set(
this.datas.points[0].x,
this.datas.points[0].y + 20
);
}
}
getStartPoint() {
@ -171,8 +178,8 @@ export class Section extends JlGraphic implements ILineGraphic {
}
}
loadRealtions() {
if (this.datas.paRef) {
loadRelations() {
if (this.datas.paRef.id) {
this.relationManage.addRelation(
new GraphicRelationParam(this, SectionPort.A),
new GraphicRelationParam(
@ -181,7 +188,7 @@ export class Section extends JlGraphic implements ILineGraphic {
)
);
}
if (this.datas.pbRef) {
if (this.datas.pbRef.id) {
this.relationManage.addRelation(
new GraphicRelationParam(this, SectionPort.B),
new GraphicRelationParam(
@ -199,8 +206,8 @@ export enum SectionPort {
}
export class SectionTemplate extends JlGraphicTemplate<Section> {
constructor() {
super(Section.Type, {});
constructor(dataTemplate: ISectionData) {
super(Section.Type, { dataTemplate });
}
new() {
return new Section();

View File

@ -40,8 +40,8 @@ export class SectionDraw extends GraphicDrawAssistant<
points: Point[] = [];
graphic = new Graphics();
constructor(app: JlDrawApp) {
super(app, new SectionTemplate(), 'sym_o_timeline', '区段Section');
constructor(app: JlDrawApp, template: SectionTemplate) {
super(app, template, 'sym_o_timeline', '区段Section');
this.container.addChild(this.graphic);
SectionPointEditPlugin.init(app);

View File

@ -57,7 +57,7 @@ export class TrainWindow extends JlGraphic {
);
rectGraphic.pivot = getRectangleCenter(rectP);
}
loadRealtions(): void {
loadRelations(): void {
const sectionId = this.datas.sectionId;
if (sectionId) {
const section = this.queryStore.queryById<Section>(sectionId);
@ -78,7 +78,7 @@ export class TrainWindow extends JlGraphic {
export class TrainWindowTemplate extends JlGraphicTemplate<TrainWindow> {
constructor(dataTemplate: ITrainWindowData) {
super(TrainWindow.Type,{
super(TrainWindow.Type, {
dataTemplate,
});
}

View File

@ -121,7 +121,7 @@ export class TrainWindowDraw extends GraphicDrawAssistant<
trainWindow.id = GraphicIdGenerator.next();
trainWindow.datas.sectionId = section.id;
this.storeGraphic(trainWindow);
trainWindow.loadRealtions();
trainWindow.loadRelations();
}
});
}

View File

@ -246,7 +246,7 @@ export class Turnout extends JlGraphic {
}
loadRelations() {
if (this.datas.paRef) {
if (this.datas.paRef.id) {
this.relationManage.addRelation(
new GraphicRelationParam(this, TurnoutPort.A),
new GraphicRelationParam(
@ -255,7 +255,7 @@ export class Turnout extends JlGraphic {
)
);
}
if (this.datas.pbRef) {
if (this.datas.pbRef.id) {
this.relationManage.addRelation(
new GraphicRelationParam(this, TurnoutPort.B),
new GraphicRelationParam(
@ -264,7 +264,7 @@ export class Turnout extends JlGraphic {
)
);
}
if (this.datas.pcRef) {
if (this.datas.pcRef.id) {
this.relationManage.addRelation(
new GraphicRelationParam(this, TurnoutPort.C),
new GraphicRelationParam(
@ -283,11 +283,17 @@ export enum TurnoutPort {
}
export class TurnoutTemplate extends JlGraphicTemplate<Turnout> {
constructor() {
super(Turnout.Type, {});
constructor(dataTemplate: ITurnoutData, stateTemplate?: ITurnoutState) {
super(Turnout.Type, {
dataTemplate,
stateTemplate,
});
}
new() {
return new Turnout();
const g = new Turnout();
g.loadData(this.datas);
// g.loadState(this.states);
return g;
}
}

View File

@ -37,8 +37,8 @@ export class TurnoutDraw extends GraphicDrawAssistant<
ITurnoutData
> {
turnout: Turnout;
constructor(app: JlDrawApp) {
super(app, new TurnoutTemplate(), 'sym_o_ramp_left', '道岔Turnout');
constructor(app: JlDrawApp, template: TurnoutTemplate) {
super(app, template, 'sym_o_ramp_left', '道岔Turnout');
this.turnout = this.graphicTemplate.new();
this.container.addChild(this.turnout);

View File

@ -631,7 +631,7 @@ export class GraphicApp extends EventEmitter<GraphicAppEvents> {
this.addGraphics(g);
});
// 加载数据关系
this.graphicStore.getAllGraphics().forEach((g) => g.loadRealtions());
this.graphicStore.getAllGraphics().forEach((g) => g.loadRelations());
// 更新id生成器
const max =
this.graphicStore

View File

@ -755,7 +755,7 @@ export abstract class JlGraphic extends Container {
/**
*
*/
loadRealtions() {}
loadRelations() {}
/**
*