This commit is contained in:
fan 2024-09-13 16:36:59 +08:00
commit 383c97e305
5 changed files with 189 additions and 7 deletions

6
package-lock.json generated
View File

@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"@quasar/extras": "^1.16.4", "@quasar/extras": "^1.16.4",
"axios": "^1.2.1", "axios": "^1.2.1",
"google-protobuf": "^3.21.2",
"jl-graphic": "git+http://120.46.212.6:3000/joylink/graphic-pixi.git#v0.1.15", "jl-graphic": "git+http://120.46.212.6:3000/joylink/graphic-pixi.git#v0.1.15",
"js-base64": "^3.7.5", "js-base64": "^3.7.5",
"pinia": "^2.0.11", "pinia": "^2.0.11",
@ -3990,6 +3991,11 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/google-protobuf": {
"version": "3.21.4",
"resolved": "https://registry.npmmirror.com/google-protobuf/-/google-protobuf-3.21.4.tgz",
"integrity": "sha512-MnG7N936zcKTco4Jd2PX2U96Kf9PxygAPKBug+74LHzmHXmceN16MmRcdgZv+DGef/S9YvQAfRsNCn4cjf9yyQ=="
},
"node_modules/gopd": { "node_modules/gopd": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.0.1.tgz", "resolved": "https://registry.npmmirror.com/gopd/-/gopd-1.0.1.tgz",

View File

@ -21,6 +21,7 @@
"axios": "^1.2.1", "axios": "^1.2.1",
"pinia": "^2.0.11", "pinia": "^2.0.11",
"js-base64": "^3.7.5", "js-base64": "^3.7.5",
"google-protobuf": "^3.21.2",
"jl-graphic": "git+http://120.46.212.6:3000/joylink/graphic-pixi.git#v0.1.15" "jl-graphic": "git+http://120.46.212.6:3000/joylink/graphic-pixi.git#v0.1.15"
}, },
"devDependencies": { "devDependencies": {

View File

@ -47,11 +47,11 @@ function buildGenerateCmd(name, path = []) {
} }
function main() { function main() {
const protocDir = resolve(messageDir, 'protoc-27.4'); const protocDir = resolve(
const protocBin = resolve( messageDir,
protocDir, `protoc/protoc-27.4-${isLinux ? 'linux-x86_64' : 'win64'}`
`bin/${isLinux ? 'linux-x86_64' : 'win64'}`
); );
const protocBin = resolve(protocDir, 'bin');
const prepareCmds = []; const prepareCmds = [];
const setPathCmd = isLinux const setPathCmd = isLinux
? ['export', `PATH=${protocBin}:${protocDir}:"$PATH"`].join(' ') ? ['export', `PATH=${protocBin}:${protocDir}:"$PATH"`].join(' ')

View File

@ -10,6 +10,9 @@ import {
newDrawApp, newDrawApp,
} from 'jl-graphic'; } from 'jl-graphic';
import { useDrawStore } from 'src/stores/draw-store'; import { useDrawStore } from 'src/stores/draw-store';
import { iscsGraphicData } from 'src/protos/iscs_graphic_data';
import { toStorageTransform } from './graphics/GraphicDataBase';
import { fromUint8Array } from 'js-base64';
// import { Notify } from 'quasar'; // import { Notify } from 'quasar';
@ -124,9 +127,18 @@ export async function loadDrawDatas(): Promise<IGraphicStorage> {
} }
export function saveDrawDatas(app: IDrawApp) { export function saveDrawDatas(app: IDrawApp) {
const storage = ''; const storage = new iscsGraphicData.IscsGraphicStorage();
console.log(storage, '保存数据', app); const canvasData = app.canvas.saveData();
return storage; storage.canvas = new iscsGraphicData.Canvas({
width: canvasData.width,
height: canvasData.height,
backgroundColor: canvasData.backgroundColor,
viewportTransform: toStorageTransform(canvasData.viewportTransform),
});
const graphics = app.queryStore.getAllGraphics();
console.log(storage, '保存数据', graphics);
const base64 = fromUint8Array(storage.serialize());
return base64;
} }
export function loadCommonDrawDatas(storage: any): any[] { export function loadCommonDrawDatas(storage: any): any[] {
@ -144,3 +156,14 @@ export function saveDrawToServer(base64: string) {
} }
console.log('save' + base64); console.log('save' + base64);
} }
let UniqueIdPrefix = new iscsGraphicData.UniqueIdOfStationLayout();
export function loadUniqueIdPrefix() {
return UniqueIdPrefix;
}
export function setUniqueIdPrefix(
newUniqueIdPrefix: iscsGraphicData.UniqueIdOfStationLayout
) {
UniqueIdPrefix = newUniqueIdPrefix;
}

View File

@ -0,0 +1,152 @@
import * as pb_1 from 'google-protobuf';
import {
ChildTransform,
GraphicData,
GraphicState,
GraphicTransform,
IChildTransform,
IGraphicTransform,
} from 'jl-graphic';
// import { toStorageTransform } from '..';
import { iscsGraphicData } from 'src/protos/iscs_graphic_data';
import { IPointData, Point } from 'pixi.js';
export interface ICommonInfo {
id: number;
graphicType: string;
transform: IGraphicTransform;
childTransforms: IChildTransform[];
}
export function fromStoragePoint(p: iscsGraphicData.Point): Point {
return new Point(p.x, p.y);
}
export function toStoragePoint(p: IPointData): iscsGraphicData.Point {
return new iscsGraphicData.Point({ x: p.x, y: p.y });
}
export function fromStorageTransfrom(
transfrom: iscsGraphicData.Transform
): GraphicTransform {
return new GraphicTransform(
fromStoragePoint(transfrom.position),
fromStoragePoint(transfrom.scale),
transfrom.rotation,
fromStoragePoint(transfrom.skew)
);
}
export function toStorageTransform(
transform: GraphicTransform
): iscsGraphicData.Transform {
return new iscsGraphicData.Transform({
position: toStoragePoint(transform.position),
scale: toStoragePoint(transform.scale),
rotation: transform.rotation,
skew: toStoragePoint(transform.skew),
});
}
export interface IProtoGraphicData extends pb_1.Message {
common: ICommonInfo;
code?: string;
}
export abstract class GraphicDataBase implements GraphicData {
_data: IProtoGraphicData;
constructor(data: IProtoGraphicData) {
this._data = data;
}
static defaultCommonInfo(graphicType: string): iscsGraphicData.CommonInfo {
return new iscsGraphicData.CommonInfo({
id: 0,
graphicType: graphicType,
transform: new iscsGraphicData.Transform({
position: new iscsGraphicData.Point({ x: 0, y: 0 }),
scale: new iscsGraphicData.Point({ x: 1, y: 1 }),
rotation: 0,
skew: new iscsGraphicData.Point({ x: 0, y: 0 }),
}),
childTransforms: [],
});
}
getData<D extends IProtoGraphicData>(): D {
return this._data as D;
}
get id(): number {
return this._data.common.id;
}
set id(v: number) {
this._data.common.id = v;
}
get graphicType(): string {
return this._data.common.graphicType;
}
set graphicType(v: string) {
this._data.common.graphicType = v;
}
get transform(): GraphicTransform {
return GraphicTransform.from(this._data.common.transform);
}
set transform(v: GraphicTransform) {
this._data.common.transform = toStorageTransform(v);
}
get childTransforms(): ChildTransform[] | undefined {
const cts: ChildTransform[] = [];
if (this._data.common.childTransforms) {
this._data.common.childTransforms.forEach((ct) => {
cts.push(ChildTransform.from(ct));
});
}
return cts;
}
set childTransforms(v: ChildTransform[] | undefined) {
if (v) {
const cts: iscsGraphicData.ChildTransform[] = [];
v.forEach((ct) =>
cts.push(
new iscsGraphicData.ChildTransform({
...ct,
transform: toStorageTransform(ct.transform),
})
)
);
this._data.common.childTransforms = cts;
} else {
this._data.common.childTransforms = [];
}
}
clone(): GraphicData {
throw new Error('Method not implemented.');
}
copyFrom(gd: GraphicDataBase): void {
pb_1.Message.copyInto(gd._data, this._data);
}
eq(other: GraphicDataBase): boolean {
return pb_1.Message.equals(this._data, other._data);
}
}
export abstract class GraphicStateBase implements GraphicState {
_graphicType: string;
_state: pb_1.Message;
constructor(state: pb_1.Message, graphicType: string) {
this._state = state;
this._graphicType = graphicType;
}
abstract get code(): string;
abstract copyFrom(data: GraphicState): void;
abstract eq(data: GraphicState): boolean;
getState<S extends pb_1.Message>(): S {
return this._state as S;
}
get graphicType(): string {
return this._graphicType;
}
clone(): GraphicState {
throw new Error('Method not implemented.');
}
}