From d69e981de04bce23f1963f2e2a7c8c47bb26eceb Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期三, 10 十二月 2025 08:29:57 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/tool.js | 252 ++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 224 insertions(+), 28 deletions(-)
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index 946a72a..3ebb75d 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -2,6 +2,7 @@
import * as TWEEDLE from 'tweedle.js';
import {
MAP_DEFAULT_ROTATION,
+ MAP_MIRROR,
DEVICE_TYPE,
DEVICE_Z_INDEX,
AGV_STATUS_MODE,
@@ -11,8 +12,9 @@
DEVICE_SELECTED_EFFECT_COLOR,
POINT_ROUTE_DIRECTION,
ANIMATE_DURING_TIME,
+ AGV_ANGLE_OFFSET_VAL,
} from './constants';
-import { getRouteList } from './http';
+import { getRouteList, fetchAreaList } from './http';
import PointRoute from "./PointRoute";
import shelf from '/map/shelf.svg';
@@ -171,16 +173,17 @@
let batchMoveStartPos = null;
const batchMoving = (event) => {
- const scale = mapContainer.scale.x;
+ const scaleX = mapContainer.scale.x;
+ const scaleY = mapContainer.scale.y;
if (batchMove && batchMoveStartPos) {
// offset move val
var mouseMovement = {
- x: (event.global.x - batchMoveStartPos.x) / scale,
- y: (event.global.y - batchMoveStartPos.y) / scale
+ x: (event.global.x - batchMoveStartPos.x) / scaleX,
+ y: (event.global.y - batchMoveStartPos.y) / scaleY
};
for (let sprite of selectedSprites) {
- sprite.position.x = sprite.batchMoveStartPos.x + mouseMovement.x;
- sprite.position.y = sprite.batchMoveStartPos.y + mouseMovement.y;
+ sprite.position.x = sprite.batchMoveStartPos.x - mouseMovement.x;
+ sprite.position.y = sprite.batchMoveStartPos.y - mouseMovement.y;
}
}
}
@@ -373,7 +376,8 @@
return;
}
- mapContainer.scale.set(0.3);
+ const focusScale = 0.1;
+ mapContainer.scale.set(MAP_MIRROR ? -focusScale : focusScale, focusScale);
mapContainer.position.set(0, 0);
let bounds = sprite.getBounds();
@@ -500,7 +504,7 @@
const pointRoute = new PointRoute(POINT_ROUTE_DIRECTION[route.direction]);
pointRoute.setPoint(startPoint, endPoint);
pointRoute.clear();
- pointRoute.lineStyle(Math.max(7, 2 * (1 / mapContainer.scale.x)), themeMode === 'light' ? '#ced6e0' : '#535c68');
+ pointRoute.lineStyle(Math.max(7, 2 * (1 / Math.abs(mapContainer.scale.x))), themeMode === 'light' ? '#ced6e0' : '#535c68');
pointRoute.moveTo(startPoint.position.x, startPoint.position.y);
pointRoute.lineTo(endPoint.position.x, endPoint.position.y);
pointRoute.alpha = 1;
@@ -610,7 +614,6 @@
}
}
-
// service ------------------------
export const getAgvStatusMode = (backpack, battery) => {
@@ -653,23 +656,25 @@
}
export function createAgvJobPanel(parentContainer, text) {
+ const panelScale = 4;
+
const panel = new PIXI.Container();
- const sideLen = 50;
+ const sideLen = 50 * panelScale;
const halfCircle = new PIXI.Graphics();
- halfCircle.beginFill(themeMode === 'light' ? '#5c5a5a' : '#eee');
- halfCircle.lineStyle(2, themeMode === 'light' ? '#5c5a5a' : '#eee');
+ halfCircle.beginFill(themeMode === 'light' ? '#333333' : '#eee');
+ halfCircle.lineStyle(2 * panelScale, themeMode === 'light' ? '#333333' : '#eee');
halfCircle.arc(0, 0, sideLen, 0, Math.PI);
halfCircle.endFill();
const rectangle = new PIXI.Graphics();
- rectangle.lineStyle(2, themeMode === 'light' ? '#5c5a5a' : '#eee', 1);
+ rectangle.lineStyle(2 * panelScale, themeMode === 'light' ? '#333333' : '#eee', .8);
rectangle.drawRoundedRect(
-sideLen / 2, // 宸︿笂瑙� x
-sideLen / 2, // 宸︿笂瑙� y
sideLen, // 瀹�
- sideLen - 20, // 楂� (鐣欎竴鐐圭┖闂达紝鐪嬭捣鏉ユ洿鍍忓崐鍦嗗鍣�)
- 16 // 鍦嗚
+ sideLen - (20 * panelScale), // 楂� (鐣欎竴鐐圭┖闂达紝鐪嬭捣鏉ユ洿鍍忓崐鍦嗗鍣�)
+ 16 * panelScale // 鍦嗚
);
rectangle.endFill();
rectangle.mask = halfCircle;
@@ -678,21 +683,20 @@
const msg = new PIXI.Text(text, {
fill: themeMode === 'light' ? '#2b2b2b' : '#eee',
- fontSize: 12,
+ fontSize: 12 * panelScale,
fontFamily: 'MicrosoftYaHei',
- fontWeight: 'bold',
+ fontWeight: 'bolder',
align: 'center',
});
msg.anchor.set(0.5);
- msg.position.set(0, -10);
+ msg.position.set(0, -10 * panelScale);
panel.addChild(msg);
- panel.scale.set(3);
parentContainer.addChild(panel);
let phase = 0;
function onTick(delta) {
- phase += delta / 8; // 鏃嬭浆閫熷害鍙皟
+ phase += delta / 6; // 鏃嬭浆閫熷害鍙皟
phase %= (Math.PI * 2);
halfCircle.rotation = phase;
}
@@ -711,18 +715,14 @@
}
}
-const agvRotationOffsetDegrees = 90;
-const agvRotationOffset = rotationParseNum(agvRotationOffsetDegrees);
+const agvRotationOffset = rotationParseNum(AGV_ANGLE_OFFSET_VAL);
const showAgvSprite = (curZone, agvVo, setCurSprite) => {
- const { agvNo, code, direction, battery, jobType, backpack: backpackCount, error } = agvVo;
+ const { agvNo, code, direction, battery, jobType, backpack: backpackCount, slots, error } = agvVo;
if (!code) { return; }
const codeSprite = querySprite(DEVICE_TYPE.POINT, code);
if (!codeSprite) { return; }
- if (agvNo === '12') {
- console.log(backpackCount);
- }
-
+
const targetRotation = rotationParseNum(direction);
// const backpackCount = backpack?.filter(item => item.loaded === true).length || 0;
@@ -749,6 +749,7 @@
});
agvText.anchor.set(0.5, 0.5);
agvText.position.set(0, 8);
+ agvText.scale.set(MAP_MIRROR ? -1 : 1, 1)
agvSprite.addChild(agvText);
agvSprite.updateTextRotation = () => {
@@ -777,7 +778,7 @@
// job effect
if (jobType) {
if (!agvSprite.data.jobEffect) {
- agvSprite.data.jobEffect = createAgvJobPanel(agvSprite, jobType);
+ agvSprite.data.jobEffect = createAgvJobPanel(agvSprite, jobType + " (" + backpackCount + "/" + slots + ")");
agvSprite.data.jobEffect.x = -80;
agvSprite.data.jobEffect.y = 0;
}
@@ -852,3 +853,198 @@
mapContainer.addChild(agvPath);
}
+
+export const removeAgvGraphics = () => {
+ if (!mapContainer) {
+ return;
+ }
+ for (let i = mapContainer.children.length - 1; i >= 0; i--) {
+ const child = mapContainer.children[i];
+ if (child?.data?.type === DEVICE_TYPE.AGV) {
+ if (child.data.jobEffect) {
+ app?.ticker.remove(child.data.jobEffect._onTick);
+ child.removeChild(child.data.jobEffect);
+ child.data.jobEffect.destroy(true);
+ child.data.jobEffect = null;
+ }
+ mapContainer.removeChild(child);
+ child.destroy({ children: true, texture: false, baseTexture: false });
+ } else if (child?.name?.startsWith('agvPath-')) {
+ mapContainer.removeChild(child);
+ child.destroy({ children: true, texture: false, baseTexture: false });
+ }
+ }
+}
+
+
+// area operator -------------------------------
+
+let areaDrawingCleanup = null;
+const AREA_COLOR = 0x3498db;
+
+const addAreaLabel = (draft, text, from, to) => {
+ const centerX = (from.x + to.x) / 2;
+ const centerY = (from.y + to.y) / 2;
+ const label = new PIXI.Text(text, {
+ fill: themeMode === 'dark' ? '#f1f2f6' : '#535353ff',
+ fontSize: 20 / Math.abs(mapContainer.scale.x || 1),
+ fontWeight: 'bold',
+ });
+ label.anchor.set(0.5);
+ label.position.set(centerX, centerY);
+ label.rotation = rotationParseNum(MAP_DEFAULT_ROTATION);
+ label.scale.set(MAP_MIRROR ? -1 : 1, 1);
+ draft.addChild(label);
+};
+
+export const loadAreas = (curZone) => {
+ if (!mapContainer) return;
+ clearAreas();
+ fetchAreaList(curZone).then((areas) => {
+ areas.forEach((area) => {
+ const { name, color, id } = area || {};
+ const start = area?.start || (area?.startX != null ? { x: area.startX, y: area.startY } : null);
+ const end = area?.end || (area?.endX != null ? { x: area.endX, y: area.endY } : null);
+ if (!start || !end || !name) {
+ return;
+ }
+ const g = createAreaGraphic({ name, start, end, color, id });
+ if (g) {
+ mapContainer.addChild(g);
+ }
+ });
+ });
+};
+
+export const clearAreas = () => {
+ if (!mapContainer) return;
+ for (let i = mapContainer.children.length - 1; i >= 0; i--) {
+ const child = mapContainer.children[i];
+ if (child?.data?.type === DEVICE_TYPE.AREA) {
+ mapContainer.removeChild(child);
+ child.destroy({ children: true, texture: false, baseTexture: false });
+ }
+ }
+};
+
+const createAreaGraphic = ({ name, start, end, color, id }) => {
+ if (!mapContainer) return null;
+ const from = start || { x: 0, y: 0 };
+ const to = end || { x: 0, y: 0 };
+ const areaColor = color || AREA_COLOR;
+
+ const draft = new PIXI.Graphics();
+ draft.name = id ? `area_${id}` : 'area_' + generateID();
+ draft.zIndex = DEVICE_Z_INDEX.AREA;
+ draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), areaColor, 0.8);
+ draft.beginFill(areaColor, 0.18);
+ draft.drawRect(
+ Math.min(from.x, to.x),
+ Math.min(from.y, to.y),
+ Math.abs(from.x - to.x),
+ Math.abs(from.y - to.y),
+ );
+ draft.endFill();
+ addAreaLabel(draft, name, from, to);
+ draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name, color: areaColor, id };
+ return draft;
+};
+
+export const startAreaDrawing = ({ promptText, onComplete, onFinish } = {}) => {
+ if (!mapContainer || !mapContainer.parent) {
+ return false;
+ }
+ if (areaDrawingCleanup) {
+ areaDrawingCleanup();
+ }
+
+ const stage = mapContainer.parent;
+ stage.off('mousedown');
+ const draft = new PIXI.Graphics();
+ draft.name = 'area_' + generateID();
+ draft.zIndex = DEVICE_Z_INDEX.AREA;
+
+ let drawing = false;
+ let startPoint = null;
+ const areaColor = AREA_COLOR;
+ const originalCursor = stage.cursor;
+ stage.cursor = 'crosshair';
+
+ const drawRect = (from, to) => {
+ draft.clear();
+ const strokeColor = areaColor;
+ draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), strokeColor, 0.8);
+ draft.beginFill(strokeColor, 0.18);
+ draft.drawRect(
+ Math.min(from.x, to.x),
+ Math.min(from.y, to.y),
+ Math.abs(from.x - to.x),
+ Math.abs(from.y - to.y),
+ );
+ draft.endFill();
+ };
+
+ const cleanupListeners = () => {
+ stage.off('pointermove', handleMove);
+ stage.off('pointerup', handleUp);
+ stage.off('pointerdown', handleDown);
+ areaDrawingCleanup = null;
+ stage.cursor = originalCursor;
+ if (onFinish) {
+ onFinish();
+ }
+ };
+ areaDrawingCleanup = cleanupListeners;
+
+ const handleDown = (event) => {
+ if (event.button !== undefined && event.button !== 0) {
+ return;
+ }
+ drawing = true;
+ startPoint = mapContainer.toLocal(event.data.global);
+ mapContainer.addChild(draft);
+ };
+
+ const handleMove = (event) => {
+ if (!drawing || !startPoint) {
+ return;
+ }
+ const cur = mapContainer.toLocal(event.data.global);
+ drawRect(startPoint, cur);
+ };
+
+ const handleUp = (event) => {
+ if (!drawing || !startPoint) {
+ return;
+ }
+ drawing = false;
+ const endPoint = mapContainer.toLocal(event.data.global);
+ drawRect(startPoint, endPoint);
+ cleanupListeners();
+
+ const areaName = prompt(promptText || 'Please enter area name');
+ if (!areaName) {
+ mapContainer.removeChild(draft);
+ draft.destroy({ children: true, texture: false, baseTexture: false });
+ return;
+ }
+
+ addAreaLabel(draft, areaName, startPoint, endPoint);
+ draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name: areaName, color: areaColor };
+
+ if (onComplete) {
+ onComplete({
+ name: areaName,
+ start: startPoint,
+ end: endPoint,
+ color: areaColor,
+ graphics: draft
+ });
+ }
+ };
+
+ stage.on('pointerdown', handleDown);
+ stage.on('pointermove', handleMove);
+ stage.on('pointerup', handleUp);
+ return true;
+};
--
Gitblit v1.9.1