| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2020. 北京上格云技术有限公司
- * ;%@@$=$@@%* *@@@$=%@@%;
- * ::;:: ::;:: All rights reserved.
- *
- * ********************************************************************************************************************
- */
- import { SGraphItem } from "@saga-web/graph/lib";
- import { SColor, SLine, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
- import { Relation } from "../types/Relation";
- import { SMouseEvent } from "@saga-web/base/lib";
- import { BaseRelationItem } from "./BaseRelationItem";
- import { AnchorItem } from "./AnchorItem";
- import { ItemOrder } from "../types/ItemOrder";
- import { SMathUtil } from "../util/SMathUtil";
- /**
- * 关系item-折线画法-横平竖直
- *
- * @author 郝建龙
- */
- export class RelationItem extends BaseRelationItem {
- /** 关系数据 */
- data: Relation | null = null;
- /** 折点信息 */
- pointList: SPoint[] = [];
- /** 尾端折点3 */
- lastPointList: SPoint[] = [];
- /** 是否结束 */
- closeFlag = false;
- //
- Anchor1: AnchorItem | null = null;
- //
- Anchor2: AnchorItem | null = null;
- //
- private _dashOffset: number = 20;
- get dashOffset(): number {
- return this._dashOffset;
- }
- set dashOffset(value: number) {
- this._dashOffset = value;
- this.update();
- }
- // 定时器
- timer: number | null = null;
- /**
- * 构造函数
- *
- * @param parent 指向父对象
- * @param data Relation数据
- */
- constructor(parent: SGraphItem | null, data: Relation) {
- super(parent);
- this.data = data;
- this.Anchor1 = data.Anchor1 || null;
- this.Anchor2 = data.Anchor2 || null;
- this.zOrder = ItemOrder.RelateOrder;
- if (data.PointList) {
- this.pointList = data.PointList.map(it => {
- let x = it.X,
- y = it.Y;
- if (x < this.minX) {
- this.minX = x;
- }
- if (y < this.minY) {
- this.minY = y;
- }
- if (x > this.maxX) {
- this.maxX = x;
- }
- if (y > this.maxY) {
- this.maxY = y;
- }
- return new SPoint(x, y);
- });
- } else {
- if (this.Anchor1) {
- this.pointList.push(
- this.Anchor1.mapToScene(this.Anchor1.X, this.Anchor1.Y)
- );
- this.lastPointList = [
- this.Anchor1.mapToScene(this.Anchor1.X, this.Anchor1.Y)
- ];
- }
- }
- } // Constructor
- /**
- * 鼠标按下事件
- *
- * @param event 事件参数
- * @return boolean
- */
- onMouseDown(event: SMouseEvent): boolean {
- if (!this.closeFlag && event.buttons == 1) {
- if (this.lastPointList.length > 1) {
- for (let i = 1; i < this.lastPointList.length; i++) {
- this.pointList.push(this.lastPointList[i]);
- }
- }
- }
- if (this.Anchor2) {
- this.closeFlag = true;
- }
- this.update();
- return true;
- } // Function onMouseDown()
- /**
- * 鼠标移动事件
- *
- * @param event 事件参数
- * @return boolean
- */
- onMouseMove(event: SMouseEvent): boolean {
- if (this.pointList.length) {
- this.lastPointList = [
- this.pointList[this.pointList.length - 1],
- this.getPoint(
- this.pointList[this.pointList.length - 1],
- new SPoint(event.x, event.y)
- ),
- new SPoint(event.x, event.y)
- ];
- }
- this.update();
- return true;
- } // Function onMouseMove()
- /***
- * 键盘按键弹起事件
- *
- * @param event 事件参数
- */
- onKeyUp(event: KeyboardEvent): void {
- if (event.keyCode == 13) {
- this.closeFlag = true;
- }
- } // Function onKeyUp()
- /**
- * 鼠标右键事件
- *
- * @param event 事件参数
- * @return boolean
- */
- onContextMenu(event: SMouseEvent): boolean {
- this.$emit("ContextMenu", event);
- return true;
- } // Function onContextMenu()
- /**
- * 点击点是否在item范围内
- *
- */
- contains(x: number, y: number): boolean {
- if (this.closeFlag) {
- let p = new SPoint(x, y),
- l = 10;
- // todo差缩放
- for (let i = 1; i < this.pointList.length; i++) {
- let PTL = SMathUtil.pointToLine(
- p,
- new SLine(
- this.pointList[i - 1].x,
- this.pointList[i - 1].y,
- this.pointList[i].x,
- this.pointList[i].y
- )
- );
- if (PTL.MinDis < l) {
- return true;
- }
- }
- return false;
- }
- return false;
- }
- /**
- * 根据点计算出折线点
- *
- */
- getPoint(p1: SPoint, p2: SPoint): SPoint {
- if (Math.abs(p1.x - p2.x) >= Math.abs(p1.y - p2.y)) {
- return new SPoint(p2.x, p1.y);
- } else {
- return new SPoint(p1.x, p2.y);
- }
- }
- /***/
- change(): void {
- if (this.pointList.length) {
- if (this.Anchor1) {
- // 判断删除equip后,不移动
- if (this.Anchor1.parent && this.Anchor1.parent.parent) {
- this.pointList[0] = this.Anchor1.mapToScene(
- this.Anchor1.X,
- this.Anchor1.Y
- );
- if (this.pointList[1] && this.pointList[2]) {
- this.pointList[1] = this.getPoint(
- this.pointList[0],
- this.pointList[2]
- );
- }
- }
- }
- if (this.Anchor2) {
- // 删除equip后
- if (this.Anchor2.parent && this.Anchor2.parent.parent) {
- this.pointList[
- this.pointList.length - 1
- ] = this.Anchor2.mapToScene(this.Anchor2.X, this.Anchor2.Y);
- if (
- this.pointList[this.pointList.length - 1] &&
- this.pointList[this.pointList.length - 3]
- ) {
- this.pointList[
- this.pointList.length - 2
- ] = this.getPoint(
- this.pointList[this.pointList.length - 1],
- this.pointList[this.pointList.length - 3]
- );
- }
- }
- }
- }
- this.update();
- } // Function change()
- /**
- * Item绘制操作
- *
- * @param painter painter对象
- */
- onDraw(painter: SPainter): void {
- painter.pen.lineWidth = 3;
- painter.pen.color = new SColor("#409EFF");
- painter.brush.color = new SColor("#409EFF");
- painter.drawPolyline(this.pointList);
- painter.pen.lineWidth = 1;
- painter.pen.lineDash = [10, 10];
- painter.pen.dashOffset = this.dashOffset;
- painter.pen.color = SColor.White;
- painter.drawPolyline(this.pointList);
- if (this.name) {
- painter.brush.color = SColor.Black;
- painter.font.size = 12;
- painter.drawText(
- this.name,
- this.pointList[0].x + 20,
- this.pointList[0].y
- );
- }
- this.dashOffset -= 2;
- if (!this.closeFlag) {
- painter.pen.color = new SColor("#409EFF");
- painter.drawPolyline(this.lastPointList);
- }
- } // Function onDraw()
- } // Class RelationItem
|