|
@@ -50,6 +50,9 @@ export class SGraphyView extends SCanvasView {
|
|
|
* @return URL地址
|
|
|
*/
|
|
|
sceneSvgData(width: number, height: number): string {
|
|
|
+ if (null == this.scene) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
let engine = new SSvgPaintEngine(width, height);
|
|
|
let painter = new SPainter(engine);
|
|
|
|
|
@@ -58,7 +61,9 @@ export class SGraphyView extends SCanvasView {
|
|
|
let x0 = this.origin.x;
|
|
|
let y0 = this.origin.y;
|
|
|
|
|
|
- this.fitSceneToSize(width, height);
|
|
|
+ // 场景中无对象
|
|
|
+ let rect = this.scene.allItemRect();
|
|
|
+ this.fitRectToSize(width, height, rect);
|
|
|
this.onDraw(painter);
|
|
|
|
|
|
// 恢复视图缩放比例与原点位置
|
|
@@ -73,10 +78,29 @@ export class SGraphyView extends SCanvasView {
|
|
|
* 适配视图到视图
|
|
|
*/
|
|
|
fitSceneToView(): void {
|
|
|
- this.fitSceneToSize(this.width, this.height);
|
|
|
+ if (null == this.scene) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 场景中无对象
|
|
|
+ let rect = this.scene.allItemRect();
|
|
|
+ this.fitRectToSize(this.width, this.height, rect);
|
|
|
} // Function FitView()
|
|
|
|
|
|
/**
|
|
|
+ * 适配选中的对象在视图中可见
|
|
|
+ */
|
|
|
+ fitSelectedToView(): void {
|
|
|
+ if (null == this.scene) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 场景中无对象
|
|
|
+ let rect = this.scene.selectedItemRect();
|
|
|
+ this.fitRectToSize(this.width, this.height, rect);
|
|
|
+ } // Function fitSelectedToSize()
|
|
|
+
|
|
|
+ /**
|
|
|
* 将场景中的xy坐标转换成视图坐标。
|
|
|
*
|
|
|
* @param x 场景中的横坐标
|
|
@@ -314,20 +338,19 @@ export class SGraphyView extends SCanvasView {
|
|
|
} // Function onKeyUp()
|
|
|
|
|
|
/**
|
|
|
- * 适配视图到指定大小
|
|
|
+ * 适配场景在视图中可见
|
|
|
*
|
|
|
* @param width 宽度
|
|
|
* @param height 高度
|
|
|
+ * @param rect 对象的矩阵大小
|
|
|
*/
|
|
|
- private fitSceneToSize(width: number, height: number): void {
|
|
|
+ private fitRectToSize(
|
|
|
+ width: number,
|
|
|
+ height: number,
|
|
|
+ rect: SRect | null
|
|
|
+ ): void {
|
|
|
// 未设置场景
|
|
|
- if (null == this.scene) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 场景中无对象
|
|
|
- let rect = this.scene.worldRect();
|
|
|
- if (null == rect) {
|
|
|
+ if (null == rect || !rect.isValid()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -337,7 +360,7 @@ export class SGraphyView extends SCanvasView {
|
|
|
let center = rect.center();
|
|
|
this.origin.x = width / 2.0 - center.x * this.scale;
|
|
|
this.origin.y = height / 2.0 - center.y * this.scale;
|
|
|
- } // Function fitSceneToSize()
|
|
|
+ } // Function fitRectToSize()
|
|
|
|
|
|
/**
|
|
|
* MouseEvent事件转换成场景SMouseEvent事件
|