|
@@ -32,89 +32,59 @@ export class DoorItem extends SGraphyItem {
|
|
|
/** 门数据 */
|
|
|
data: Door;
|
|
|
/** 门轮廓线坐标list */
|
|
|
- private readonly pointArr: SPoint[];
|
|
|
+ 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;
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
|
*
|
|
|
- * @param data
|
|
|
+ * @param parent 指向父对象
|
|
|
+ * @param data 门数据
|
|
|
*/
|
|
|
- constructor(data: Door) {
|
|
|
- super();
|
|
|
+ constructor(parent: SGraphyItem | null, data: Door) {
|
|
|
+ super(parent);
|
|
|
this.data = data;
|
|
|
- this.pointArr = this.data.OutLine[0].map(t => {
|
|
|
- return new SPoint(t.X, t.Y);
|
|
|
- });
|
|
|
- } // Constructor
|
|
|
-
|
|
|
- /**
|
|
|
- * Item对象边界区域
|
|
|
- *
|
|
|
- * @return SRect
|
|
|
- */
|
|
|
- boundingRect(): SRect {
|
|
|
- let pointArr = this.data.OutLine[0];
|
|
|
- let minX = pointArr[0].X;
|
|
|
- let maxX = minX;
|
|
|
- let minY = pointArr[0].Y;
|
|
|
- let maxY = minY;
|
|
|
- for (let i = 1; i < pointArr.length; i++) {
|
|
|
- if (pointArr[i].X < minX) {
|
|
|
- minX = pointArr[i].Y;
|
|
|
- }
|
|
|
- if (pointArr[i].Y < minY) {
|
|
|
- minY = pointArr[i].Y;
|
|
|
- }
|
|
|
- if (pointArr[i].X > maxX) {
|
|
|
- maxX = pointArr[i].X;
|
|
|
- }
|
|
|
- if (pointArr[i].Y > maxY) {
|
|
|
- maxY = pointArr[i].Y;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return new SRect(minX, minY, maxX - minX, maxY - minY);
|
|
|
- } // Function boundingRect()
|
|
|
+ if (this.data.OutLine.length) {
|
|
|
+ this.pointArr = this.data.OutLine[0].map(t => {
|
|
|
+ return new SPoint(t.X, t.Y);
|
|
|
+ });
|
|
|
|
|
|
- /**
|
|
|
- * 判断点是否在区域内
|
|
|
- *
|
|
|
- * @param x
|
|
|
- * @param y
|
|
|
- */
|
|
|
- contains(x: number, y: number): boolean {
|
|
|
- let nCross = 0,
|
|
|
- point = [x, y],
|
|
|
- APoints = this.data.OutLine[0],
|
|
|
- length = APoints.length,
|
|
|
- p1,
|
|
|
- p2,
|
|
|
- i,
|
|
|
- xinters;
|
|
|
- p1 = APoints[0];
|
|
|
- for (i = 1; i <= length; i++) {
|
|
|
- p2 = APoints[i % length];
|
|
|
- if (
|
|
|
- point[0] > Math.min(p1.X, p2.X) &&
|
|
|
- point[0] <= Math.max(p1.X, p2.X)
|
|
|
- ) {
|
|
|
- if (point[1] <= Math.max(p1.Y, p2.Y)) {
|
|
|
- if (p1.X != p2.X) {
|
|
|
- //计算位置信息
|
|
|
- xinters =
|
|
|
- ((point[0] - p1.X) * (p2.Y - p1.Y)) /
|
|
|
- (p2.X - p1.X) +
|
|
|
- p1.Y;
|
|
|
- if (p1.Y == p2.Y || point[1] <= xinters) {
|
|
|
- nCross++;
|
|
|
- }
|
|
|
- }
|
|
|
+ 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(
|
|
|
+ Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)
|
|
|
+ );
|
|
|
+ // 门朝向角度
|
|
|
+ this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
|
|
|
+ // 旋转点
|
|
|
+ if (this.data.HandDirection.X > this.data.HandDirection.Y) {
|
|
|
+ if (this.data.HandDirection.X > 0) {
|
|
|
+ this.p = p1.x > p2.x ? p1 : p2;
|
|
|
+ } else {
|
|
|
+ this.p = p1.x < p2.x ? p1 : p2;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (this.data.HandDirection.Y > 0) {
|
|
|
+ this.p = p1.y > p2.y ? p1 : p2;
|
|
|
+ } else {
|
|
|
+ this.p = p1.y < p2.y ? p1 : p2;
|
|
|
}
|
|
|
}
|
|
|
- p1 = p2;
|
|
|
}
|
|
|
- return nCross % 2 === 1;
|
|
|
- } // Function contains()
|
|
|
+ } // Constructor
|
|
|
|
|
|
/**
|
|
|
* Item绘制操作
|
|
@@ -123,8 +93,15 @@ export class DoorItem extends SGraphyItem {
|
|
|
* @param rect 绘制区域
|
|
|
*/
|
|
|
onDraw(painter: SPainter, rect?: SRect): void {
|
|
|
- painter.pen.color = Opt.doorColor;
|
|
|
- painter.pen.lineWidth = 400;
|
|
|
- painter.drawPolyline(this.pointArr);
|
|
|
+ if (this.visible) {
|
|
|
+ painter.translate(this.p.x, this.p.y);
|
|
|
+ painter.rotate(this.ang);
|
|
|
+ painter.pen.lineWidth = 50;
|
|
|
+ painter.pen.color = Opt.doorColor;
|
|
|
+ painter.drawLine(0, 0, this.r, 0);
|
|
|
+
|
|
|
+ painter.pen.lineDash = [10, 10];
|
|
|
+ painter.drawArc(0, 0, this.r, this.r, this.startAng, this.endAng);
|
|
|
+ }
|
|
|
} // Function onDraw()
|
|
|
} // Class DoorItem
|