|
@@ -28,7 +28,7 @@ import { SGraphEdit, SBaseCirclePolylineEdit } from "@persagy-web/edit";
|
|
|
import { SGraphItem } from "@persagy-web/graph/lib";
|
|
|
import { SMouseEvent } from "@persagy-web/base/lib";
|
|
|
import { Marker } from "@persagy-web/big/lib";
|
|
|
-import { SColor, SFont, SPoint, SRect, SSize } from "@persagy-web/draw/lib";
|
|
|
+import { SColor,SPath, SFont, SPainter, SPoint, SRect, SSize } from "@persagy-web/draw/lib";
|
|
|
|
|
|
/**
|
|
|
* 编辑基础管道接头类
|
|
@@ -44,16 +44,58 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
// 宽高
|
|
|
width: number = 64;
|
|
|
height: number = 64;
|
|
|
- /** 轮廓 */
|
|
|
- outLine: SBaseCirclePolylineEdit;
|
|
|
// 轮廓点
|
|
|
outLineTpye: any = {
|
|
|
'wantou': 2,
|
|
|
'santong': 3,
|
|
|
'sitong': 4,
|
|
|
}
|
|
|
+
|
|
|
+ // 旋转角度
|
|
|
+ _angle:number = 0;
|
|
|
+ get angle(): number {
|
|
|
+ return this._angle;
|
|
|
+ }
|
|
|
+ set angle(v: number) {
|
|
|
+ this._angle = v;
|
|
|
+ this.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** path 对象 */
|
|
|
+ path: SPath = new SPath();
|
|
|
/** 轮廓点 */
|
|
|
- outLineLine: SPoint[] = []
|
|
|
+ outLineLine: SPoint[] = [];
|
|
|
+
|
|
|
+ /** 填充色 */
|
|
|
+ _fillColor: SColor = new SColor('#2196f3');
|
|
|
+ get fillColor(): SColor {
|
|
|
+ return this._fillColor;
|
|
|
+ }
|
|
|
+ set fillColor(v: SColor) {
|
|
|
+ this._fillColor = v;
|
|
|
+ this.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 弧度 */
|
|
|
+ _radius:number = 0;
|
|
|
+ get radius(): number {
|
|
|
+ return this._radius;
|
|
|
+ }
|
|
|
+ set radius(v: number) {
|
|
|
+ this._radius = v;
|
|
|
+ this.generatePath(this.outLineLine,v)
|
|
|
+ this.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 线条宽度 */
|
|
|
+ _lineWidth: number = 20;
|
|
|
+ get lineWidth(): number {
|
|
|
+ return this._lineWidth;
|
|
|
+ }
|
|
|
+ set lineWidth(v: number) {
|
|
|
+ this._lineWidth = v;
|
|
|
+ this.update();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
@@ -64,7 +106,6 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
constructor(parent: SGraphItem | null, data: Marker) {
|
|
|
super(parent);
|
|
|
this.data = data;
|
|
|
- this.outLine = new SBaseCirclePolylineEdit(this)
|
|
|
this.initData(data);
|
|
|
} // Constructor
|
|
|
|
|
@@ -77,12 +118,8 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
this.width = data.style.default.width ? data.style.default.width : 64;
|
|
|
this.height = data.style.default.height ? data.style.default.height : 64;
|
|
|
this.moveTo(data.pos.x, data.pos.y);
|
|
|
- this.outLine.strokeColor = SColor.Red;
|
|
|
- this.outLine.fillColor = SColor.Red;
|
|
|
- this.outLine.lineWidth = 20;
|
|
|
// 判断为几通管道
|
|
|
this.computeUninNumber(this.outLineTpye[data.style.uninToolType]);
|
|
|
- this.outLine.pointList = this.outLineLine; //赋值轮廓
|
|
|
this.update()
|
|
|
}
|
|
|
|
|
@@ -102,12 +139,11 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
* @param oldSize 旧大小
|
|
|
* @param newSize 新大小
|
|
|
*/
|
|
|
- resize(oldSize:SSize, newSize:SSize) {
|
|
|
+ resize(oldSize: SSize, newSize: SSize) {
|
|
|
this.width = newSize.width;
|
|
|
this.height = newSize.height;
|
|
|
this.computeUninNumber(this.outLineTpye[this.data.style.uninToolType]);
|
|
|
- this.outLine.pointList = this.outLineLine; //赋值轮廓
|
|
|
- console.log('this.outLineLine',this.outLineLine)
|
|
|
+ // this.outLine.pointList = this.outLineLine; //赋值轮廓
|
|
|
this.update();
|
|
|
}
|
|
|
|
|
@@ -117,7 +153,7 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
* @return 对象边界区域
|
|
|
*/
|
|
|
boundingRect(): SRect {
|
|
|
- return new SRect(0,0, this.width, this.height);
|
|
|
+ return new SRect(0, 0, this.width, this.height);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -128,9 +164,9 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
// 如果为二通
|
|
|
const topPoint = new SPoint(this.width / 2, 0);
|
|
|
const centerPoint = this.boundingRect().center();
|
|
|
- const rightPoint = new SPoint( this.width, this.height / 2);
|
|
|
- const leftPoint = new SPoint(0, this.height / 2);
|
|
|
- const bottomPoint = new SPoint(this.width / 2,this.height)
|
|
|
+ const rightPoint = new SPoint(this.width, this.height / 2);
|
|
|
+ const leftPoint = new SPoint(0, this.height / 2);
|
|
|
+ const bottomPoint = new SPoint(this.width / 2, this.height)
|
|
|
if (2 == type) {
|
|
|
this.outLineLine = [topPoint, centerPoint, rightPoint];
|
|
|
} else if (3 == type) {
|
|
@@ -138,6 +174,7 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
} else if (4 == type) {
|
|
|
this.outLineLine = [topPoint, centerPoint, rightPoint, leftPoint, centerPoint, bottomPoint];
|
|
|
}
|
|
|
+ this.generatePath(this.outLineLine,this.radius)
|
|
|
}
|
|
|
|
|
|
|
|
@@ -149,4 +186,67 @@ export class SBasePipeUninTool extends SGraphEdit {
|
|
|
toData(): any {
|
|
|
return super.toData()
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据点集生成 path 对象
|
|
|
+ *
|
|
|
+ * @param list 需要生成的点击
|
|
|
+ * @param r 拐点处圆角半径
|
|
|
+ */
|
|
|
+ generatePath(list: SPoint[], r: number = 0): void {
|
|
|
+ const len = list.length;
|
|
|
+ // 当前这小有效
|
|
|
+ if (len) {
|
|
|
+ this.path = new SPath();
|
|
|
+ this.path.moveTo(list[0].x, list[0].y);
|
|
|
+ // 遍历点集列表
|
|
|
+ for (let i = 1; i < len - 1; i++) {
|
|
|
+ const temp = list[i];
|
|
|
+ const next = list[i + 1];
|
|
|
+ this.path.arcTo(temp.x, temp.y, next.x, next.y, r);
|
|
|
+ }
|
|
|
+ const last = list[len - 1];
|
|
|
+ this.path.lineTo(last.x, last.y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Item 绘制操作
|
|
|
+ *
|
|
|
+ * @param painter 绘画对象
|
|
|
+ */
|
|
|
+ onDraw(painter: SPainter): void {
|
|
|
+ super.onDraw(painter);
|
|
|
+ const topPoint = this.outLineLine[0];
|
|
|
+ const rightPoint = this.outLineLine[2];
|
|
|
+ const leftPoint = this.outLineLine[3];
|
|
|
+ const bottomPoint = this.outLineLine[5];
|
|
|
+ const pipeWidth = this.lineWidth;
|
|
|
+ painter.pen.color = this.fillColor
|
|
|
+ painter.pen.lineWidth = this.lineWidth;
|
|
|
+ //设置旋转角度
|
|
|
+ if(this.angle != 0){
|
|
|
+ painter.rotate(this.angle);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ painter.drawPath(this.path);
|
|
|
+ const lineWidth = this.lineWidth / 4;
|
|
|
+ painter.pen.lineWidth = lineWidth;
|
|
|
+
|
|
|
+ // 绘制装饰线
|
|
|
+ if (3 == this.outLineLine.length) {
|
|
|
+ painter.drawLine(topPoint.x - pipeWidth, topPoint.y, topPoint.x + pipeWidth, topPoint.y);
|
|
|
+ painter.drawLine(rightPoint.x, rightPoint.y - pipeWidth, rightPoint.x, rightPoint.y + pipeWidth);
|
|
|
+ } else if (4 == this.outLineLine.length) {
|
|
|
+ painter.drawLine(topPoint.x - pipeWidth, topPoint.y, topPoint.x + pipeWidth, topPoint.y);
|
|
|
+ painter.drawLine(rightPoint.x, rightPoint.y - pipeWidth, rightPoint.x, rightPoint.y + pipeWidth);
|
|
|
+ painter.drawLine(leftPoint.x, leftPoint.y - pipeWidth, leftPoint.x, leftPoint.y + pipeWidth);
|
|
|
+ } else {
|
|
|
+ painter.drawLine(topPoint.x - pipeWidth, topPoint.y, topPoint.x + pipeWidth, topPoint.y);
|
|
|
+ painter.drawLine(rightPoint.x, rightPoint.y - pipeWidth, rightPoint.x, rightPoint.y + pipeWidth);
|
|
|
+ painter.drawLine(leftPoint.x, leftPoint.y - pipeWidth, leftPoint.x, leftPoint.y + pipeWidth);
|
|
|
+ painter.drawLine(bottomPoint.x - pipeWidth, bottomPoint.y, bottomPoint.x + pipeWidth, bottomPoint.y);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|