|
@@ -121,7 +121,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param parent 父级
|
|
|
* @param list 坐标集合
|
|
|
- */
|
|
|
+ */
|
|
|
constructor(parent: null | SGraphItem, list: SPoint[]);
|
|
|
|
|
|
/**
|
|
@@ -129,7 +129,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param parent 父级
|
|
|
* @param list 第一个坐标
|
|
|
- */
|
|
|
+ */
|
|
|
constructor(parent: null | SGraphItem, list: SPoint);
|
|
|
|
|
|
/**
|
|
@@ -137,7 +137,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param parent 父级
|
|
|
* @param list 第一个坐标|坐标集合
|
|
|
- */
|
|
|
+ */
|
|
|
constructor(parent: null | SGraphItem, list: SPoint | SPoint[]) {
|
|
|
super(parent);
|
|
|
if (list instanceof SPoint) {
|
|
@@ -152,7 +152,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param p 添加的点
|
|
|
* @param index 添加到的索引
|
|
|
- */
|
|
|
+ */
|
|
|
private addPoint(p: SPoint, index?: number): void {
|
|
|
if (index && this.canHandle(index)) {
|
|
|
this.pointList.splice(index, 0, p);
|
|
@@ -174,7 +174,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param index 要添加到的索引
|
|
|
* @return 是否可添加
|
|
|
- */
|
|
|
+ */
|
|
|
private canHandle(index: number): boolean {
|
|
|
return index >= 0 && index <= this.pointList.length;
|
|
|
} // Function canHandle()
|
|
@@ -183,7 +183,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 根据索引删除点
|
|
|
*
|
|
|
* @param index 删除点
|
|
|
- */
|
|
|
+ */
|
|
|
deletePoint(index: number): void {
|
|
|
if (this.canHandle(index) && this.pointList.length > 2) {
|
|
|
const p = new SPoint(
|
|
@@ -207,7 +207,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 鼠标事件
|
|
|
* @return 是否处理事件
|
|
|
- */
|
|
|
+ */
|
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
|
this.curIndex = -1;
|
|
|
this.curPoint = null;
|
|
@@ -247,7 +247,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 鼠标事件
|
|
|
* @return 是否处理事件
|
|
|
- */
|
|
|
+ */
|
|
|
onMouseMove(event: SMouseEvent): boolean {
|
|
|
if (event.shiftKey) {
|
|
|
event = this.compare(event);
|
|
@@ -283,7 +283,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 鼠标事件
|
|
|
* @return 是否处理事件
|
|
|
- */
|
|
|
+ */
|
|
|
onMouseUp(event: SMouseEvent): boolean {
|
|
|
if (this.status == SItemStatus.Edit) {
|
|
|
if (this.curIndex > -1) {
|
|
@@ -311,16 +311,18 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 事件参数
|
|
|
* @return 是否处理
|
|
|
- */
|
|
|
+ */
|
|
|
onDoubleClick(event: SMouseEvent): boolean {
|
|
|
// 如果为show状态 双击改对象则需改为编辑状态
|
|
|
if (this.status == SItemStatus.Normal) {
|
|
|
this.status = SItemStatus.Edit;
|
|
|
this.grabItem(this);
|
|
|
- } else if (this.status == SItemStatus.Edit) { // 编辑状态
|
|
|
+ } else if (this.status == SItemStatus.Edit) {
|
|
|
+ // 编辑状态
|
|
|
this.status = SItemStatus.Normal;
|
|
|
this.releaseItem();
|
|
|
- } else if (this.status == SItemStatus.Create) { // 创建状态
|
|
|
+ } else if (this.status == SItemStatus.Create) {
|
|
|
+ // 创建状态
|
|
|
if (this.pointList.length > 1) {
|
|
|
this.status = SItemStatus.Normal;
|
|
|
this.releaseItem();
|
|
@@ -336,7 +338,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 键盘按键弹起事件
|
|
|
*
|
|
|
* @param event 事件参数
|
|
|
- */
|
|
|
+ */
|
|
|
onKeyUp(event: KeyboardEvent): void {
|
|
|
if (event.keyCode == SKeyCode.Enter) {
|
|
|
if (this.pointList.length > 1) {
|
|
@@ -363,14 +365,16 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param x x 坐标
|
|
|
* @param y y 坐标
|
|
|
- */
|
|
|
+ */
|
|
|
moveToOrigin(x: number, y: number): void {
|
|
|
super.moveToOrigin(x, y);
|
|
|
- this.pointList = this.pointList.map(t => {
|
|
|
- t.x = t.x + x;
|
|
|
- t.y = t.y + y;
|
|
|
- return t;
|
|
|
- });
|
|
|
+ this.pointList = this.pointList.map(
|
|
|
+ (t): SPoint => {
|
|
|
+ t.x = t.x + x;
|
|
|
+ t.y = t.y + y;
|
|
|
+ return t;
|
|
|
+ }
|
|
|
+ );
|
|
|
this.x = 0;
|
|
|
this.y = 0;
|
|
|
} // Function moveToOrigin()
|
|
@@ -379,7 +383,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 获取点击点与点集中距离最近点
|
|
|
*
|
|
|
* @param p 鼠标点击点
|
|
|
- */
|
|
|
+ */
|
|
|
findNearestPoint(p: SPoint): void {
|
|
|
let len = this.sceneDis;
|
|
|
for (let i = 0; i < this.pointList.length; i++) {
|
|
@@ -404,7 +408,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 计算增加点的位置
|
|
|
*
|
|
|
* @param p 鼠标点击点
|
|
|
- */
|
|
|
+ */
|
|
|
findAddPos(p: SPoint): void {
|
|
|
let len = SMathUtil.pointToLine(
|
|
|
p,
|
|
@@ -434,7 +438,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param event 事件
|
|
|
* @return 事件对象
|
|
|
- */
|
|
|
+ */
|
|
|
compare(event: SMouseEvent): SMouseEvent {
|
|
|
if (this.pointList.length) {
|
|
|
let last = new SPoint(event.x, event.y);
|
|
@@ -463,7 +467,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
*
|
|
|
* @param SGraphCommand 相关命令类
|
|
|
* @param any 对应传入参数
|
|
|
- */
|
|
|
+ */
|
|
|
protected recordAction(SGraphCommand: any, any: any[]): void {
|
|
|
// 记录相关命令并推入堆栈中
|
|
|
const command = new SGraphCommand(this.scene, this, ...any);
|
|
@@ -474,14 +478,14 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* Item 对象边界区域
|
|
|
*
|
|
|
* @return 外接矩阵
|
|
|
- */
|
|
|
+ */
|
|
|
boundingRect(): SRect {
|
|
|
if (this.pointList.length) {
|
|
|
this.minX = this.pointList[0].x;
|
|
|
this.maxX = this.pointList[0].x;
|
|
|
this.minY = this.pointList[0].y;
|
|
|
this.maxY = this.pointList[0].y;
|
|
|
- this.pointList.forEach(it => {
|
|
|
+ this.pointList.forEach((it): void => {
|
|
|
let x = it.x,
|
|
|
y = it.y;
|
|
|
if (x < this.minX) {
|
|
@@ -516,7 +520,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @param x x 坐标
|
|
|
* @param y y 坐标
|
|
|
* @return 是否在区域内
|
|
|
- */
|
|
|
+ */
|
|
|
contains(x: number, y: number): boolean {
|
|
|
let p = new SPoint(x, y);
|
|
|
for (let i = 1; i < this.pointList.length; i++) {
|
|
@@ -538,7 +542,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
|
|
|
/**
|
|
|
* 撤销操作
|
|
|
- */
|
|
|
+ */
|
|
|
undo(): void {
|
|
|
if (this._status != SItemStatus.Normal) {
|
|
|
this.undoStack.undo();
|
|
@@ -547,7 +551,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
|
|
|
/**
|
|
|
* 重做操作
|
|
|
- */
|
|
|
+ */
|
|
|
redo(): void {
|
|
|
if (this._status != SItemStatus.Normal) {
|
|
|
this.undoStack.redo();
|
|
@@ -556,7 +560,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
|
|
|
/**
|
|
|
* 取消操作执行
|
|
|
- */
|
|
|
+ */
|
|
|
cancelOperate(): void {
|
|
|
if (this.status == SItemStatus.Create) {
|
|
|
this.parent = null;
|
|
@@ -571,7 +575,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* 绘制基本图形
|
|
|
*
|
|
|
* @param painter 绘制对象
|
|
|
- */
|
|
|
+ */
|
|
|
drawBaseLine(painter: SPainter): void {
|
|
|
// 绘制基本图形
|
|
|
if (this.lineStyle == SLineStyle.Dashed) {
|
|
@@ -594,7 +598,7 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* Item 绘制操作
|
|
|
*
|
|
|
* @param painter 绘制对象
|
|
|
- */
|
|
|
+ */
|
|
|
onDraw(painter: SPainter): void {
|
|
|
// 缓存场景长度
|
|
|
this.sceneDis = painter.toPx(this.dis);
|