123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import { SMouseEvent, SUndoStack } from "@saga-web/base";
- import { SGraphScene,SGraphyItem } from '@saga-web/graph/lib';
- import { SPoint } from '@saga-web/draw/lib';
- import { SFloorParser, SImageItem, STextItem, SLineItem, SPolylineItem } from "@saga-web/big";
- import { SGraphItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
- import { SPolygonItem } from "./SPolygonItem";
- /**
- * 在线绘图
- *
- * @author 韩耀龙
- */
- export class EditScence extends SGraphScene {
- undoStack = new SUndoStack();
- /** 命令 1 绘制直线 */
- private cmd = 0;
- /** 获取当前状态 */
- get getCmd(): number {
- return this.cmd;
- }
- /** 编辑当前状态 */
- set setCmd(cmd: number) {
- if (cmd == 0) {
- this.grabItem = null;
- this.focusItem = null;
- }
- this.cmd = cmd;
- if(this.focusItem){
- // 取消操作
- this.focusItem.cancelOperate();
- this.focusItem = null;
- }
- };
- /** 当前选中焦点Item */
- focusItem:SGraphyItem:null = null;
- constructor() {
- super();
- // 选择绑定选额item事件
- this.selectContainer.connect('listChange', this, this.listChange)
- }
- /**
- * 监听选择item数据
- *
- */
- listChange() {
- console.log(arguments)
- }
- /**
- * 增加线段item
- */
- addLine(event: SMouseEvent): boolean {
- const item = new SLineItem(null, new SPoint(event.x, event.y));
- this.addItem(item);
- this.grabItem = item;
- this.undoStack.push(new SGraphAddCommand(this, item));
- // item.connect("onMove", this, this.onItemMove.bind(this));
- return true
- }
- /**
- * 增加多边形item
- */
- addPolygonItem(event: SMouseEvent): void {
- //创建item
- const Polylines = new SPolygonItem(null);
- //设置状态
- Polylines.setStatus = 3;
- const point = new SPoint(event.x, event.y)
- Polylines.setPointList = [point];
- this.addItem(Polylines);
- this.grabItem = Polylines;
- this.focusItem = Polylines
- }
- /**
- * 增加textItem
- */
- addImgItem() {
- }
- /**
- * 增加管道
- */
- addTextItem(event: SMouseEvent): void {
- const item = new STextItem(null, '请在右侧属性栏输入文字!');
- item.moveTo(event.x, event.y);
- this.addItem(item);
- this.grabItem == null
- this.cmd = 0;
- }
- /**
- * 增加图标
- */
- addIconItem(): void {
- }
- /**
- * 更改item对应属性
- */
- editItemStatus(): void {
- }
- /**
- * 删除指定item
- */
- deleiteItemStatus(): void {
- }
- /**
- * 对齐指定item
- */
- alignItem(type, itemList): void {
- }
- /**
- * 提取item
- */
- extractItem(): void {
- }
- /**
- * 锁住item
- */
- lockItem(): void {
- }
- /**
- * 执行取消操作
- */
- redo(): void {
- this.undoStack.undo();
- }
- /**
- * 执行重做操作执行
- */
- undo(): void {
- this.undoStack.redo();
- }
- ////////////////////////
- // 以下为鼠标键盘操作事件
- onMouseDown(event: SMouseEvent): any {
- if (this.grabItem) {
- return this.grabItem.onMouseDown(event);
- }
- switch (this.cmd) {
- case 1:
- this.addLine(event);
- break;
- case 2:
- this.addTextItem(event);
- break;
- case 3:
- this.addPolygonItem(event);
- break;
- default:
- return super.onMouseDown(event);
- }
- }
- /**
- * 键盘事件
- *
- * @param event 事件参数
- * @return boolean
- */
- onKeyDown(event: KeyboardEvent): any {
- if (this.grabItem) {
- this.grabItem.onKeyDown(event);
- }
- if (event.key == "Enter") {
- this.cmd = 0
- }
- return false
- }
- }
|