123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
- * ;%@@$=$@@%* *@@@$=%@@%;
- * ::;:: ::;:: All rights reserved.
- *
- * ********************************************************************************************************************
- */
- import { Door } from "../types/Door";
- import { Opt } from "../types/Opt";
- import { SGraphyItem } from "@saga-web/graphy/lib";
- import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
- /**
- * 门item
- *
- * @author 郝建龙
- */
- export class DoorItem extends SGraphyItem {
- /** 门数据 */
- data: Door;
- /** 门轮廓线坐标list */
- private readonly pointArr: SPoint[] = [];
- /** 门长度 */
- private r: number = 0;
- /** 角度 */
- private ang: number = 0;
- /** 旋转点 */
- private p: SPoint = new SPoint(0, 0);
- /** 旋转起始角度 */
- private startAng: number = -Math.PI / 2;
- /** 旋转结束角度 */
- private endAng: number = 0;
- // number: number = 0;
- /**
- * 构造函数
- *
- * @param parent 指向父对象
- * @param data 门数据
- */
- constructor(parent: SGraphyItem | null, data: Door) {
- super(parent);
- this.data = data;
- if (this.data.OutLine.length) {
- this.pointArr = this.data.OutLine[0].map(t => {
- return new SPoint(t.X, -t.Y);
- });
- let p1 = this.pointArr[0];
- let p2 = this.pointArr[1];
- let fo = Math.atan(
- -this.data.FaceDirection.Y / this.data.FaceDirection.X
- );
- // 两点间距离
- this.r = Math.sqrt(
- (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)
- );
- // 门朝向角度
- this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
- // 旋转点
- if (
- Math.abs(this.data.HandDirection.X) >
- Math.abs(this.data.HandDirection.Y)
- ) {
- // this.startAng = 0;
- // this.endAng = Math.PI / 2;
- if (this.data.HandDirection.X > 0) {
- if (p1.x > p2.x) {
- this.p = p1;
- // this.number = 1; //
- } else {
- this.p = p2;
- // this.number = 2;
- }
- } else {
- if (p1.x < p2.x) {
- this.p = p1;
- // this.number = 3; //
- } else {
- this.p = p2;
- // this.number = 4; //
- }
- }
- } else {
- if (this.data.HandDirection.Y > 0) {
- if (p1.y > p2.y) {
- this.p = p1;
- // this.number = 5; //
- } else {
- this.p = p2;
- // this.number = 6;
- }
- } else {
- if (p1.y < p2.y) {
- this.p = p1;
- // this.number = 7;
- } else {
- this.p = p2;
- // this.number = 8;
- }
- }
- }
- }
- } // Constructor
- /**
- * Item绘制操作
- *
- * @param painter painter对象
- * @param rect 绘制区域
- */
- onDraw(painter: SPainter, rect?: SRect): void {
- if (this.visible) {
- painter.translate(this.p.x, this.p.y);
- painter.rotate(this.ang);
- painter.pen.lineWidth = 100;
- // let color = [
- // "#42b983", //1
- // "#4287b9", //2
- // "#9742b9", //3
- // "#b94242", //4
- // "#ffd945", //5
- // "#46ff45", //
- // "#45f5ff", //
- // "#f3f3f3"
- // ];
- // painter.pen.color = new SColor(color[this.number - 1]);
- painter.pen.color = Opt.doorColor;
- painter.drawLine(0, 0, this.r, 0);
- painter.pen.lineDash = [50, 100];
- // painter.drawArc(
- // -this.r,
- // -this.r,
- // this.r * 2,
- // this.r * 2,
- // this.startAng,
- // this.endAng
- // );
- }
- } // Function onDraw()
- } // Class DoorItem
|