Parcourir la source

Merge remote-tracking branch 'origin/master'

bill il y a 2 ans
Parent
commit
e9f6c74c76

+ 9 - 13
src/graphic/Geometry/Circle.js

@@ -2,7 +2,7 @@ import VectorType from "../enum/VectorType.js";
 import SelectState from "../enum/SelectState.js";
 import Geometry from "./Geometry";
 import Constant from "../Constant.js";
-import Style from '../CanvasStyle'
+import Style from "../CanvasStyle";
 
 //不靠墙
 export default class Circle extends Geometry {
@@ -20,18 +20,6 @@ export default class Circle extends Geometry {
     this.createPoints();
   }
 
-  setRadius(radius) {
-    this.radius = radius;
-  }
-
-  setCenter(center) {
-    if (center) {
-      this.center = {};
-      this.center.x = center.x;
-      this.center.y = center.y;
-    }
-  }
-
   createPoints() {
     this.points[0] = {
       x: this.center.x - this.radius,
@@ -51,6 +39,14 @@ export default class Circle extends Geometry {
     };
   }
 
+  setPoints(points) {
+    if (points && points.length == 4) {
+      this.points = JSON.parse(JSON.stringify(points));
+    } else {
+      this.createPoints();
+    }
+  }
+
   setColor(value) {
     this.color = value;
   }

+ 24 - 0
src/graphic/Geometry/Geometry.js

@@ -40,10 +40,34 @@ export default class Geometry {
     this.rightEdgeId = edgeId;
   }
 
+  setDisplay(value) {
+    this.display = value;
+  }
+
+  setParent(value) {
+    this.parent = value;
+  }
+
   getParent() {
     return this.parent;
   }
 
+  setCenter(center) {
+    if (center) {
+      this.center = {};
+      this.center.x = center.x;
+      this.center.y = center.y;
+    }
+  }
+
+  setRadius(radius) {
+    this.radius = radius;
+  }
+
+  setColor(value) {
+    this.color = value;
+  }
+
   // ptSrc: 圆上某点(初始点);
   // ptRotationCenter: 圆心点;
   // angle: 旋转角度°  -- [angle * M_PI / 180]:将角度换算为弧度

+ 2 - 3
src/graphic/Geometry/Img.js

@@ -15,9 +15,8 @@ export default class Img extends Geometry {
     this.setSrc(src);
   }
 
-  setCenter(value) {
-    this.center = {};
-    mathUtil.clonePoint(this.center, value);
+  setAngle(value) {
+    this.angle = value;
   }
 
   setSrc(src) {

+ 8 - 0
src/graphic/Geometry/Magnifier.js

@@ -52,6 +52,14 @@ export default class Magnifier extends Geometry {
     }
   }
 
+  setPopPosition(value) {
+    if (value) {
+      this.popPosition = {};
+      this.popPosition.x = value.x;
+      this.popPosition.y = value.y;
+    }
+  }
+
   setSrc(src) {
     this.photoUrl = src;
   }

+ 0 - 7
src/graphic/Geometry/SVG.js

@@ -12,11 +12,4 @@ export default class SVG extends Geometry {
     this.geoType = VectorType.SVG;
     this.setId(vectorId);
   }
-
-  setCenter(center) {
-    this.center = {
-      x: center.x,
-      y: center.y,
-    };
-  }
 }

+ 0 - 11
src/graphic/Geometry/Text.js

@@ -17,21 +17,10 @@ export default class Text extends Geometry {
     this.setId(vectorId);
   }
 
-  setCenter(center) {
-    this.center = {
-      x: center.x,
-      y: center.y,
-    };
-  }
-
   setValue(value) {
     this.value = value;
   }
 
-  setColor(value) {
-    this.color = value;
-  }
-
   setFontSize(value) {
     this.fontSize = value;
   }

+ 37 - 3
src/graphic/History/HistoryUtil.js

@@ -60,10 +60,11 @@ export default class HistoryUtil {
     }
   }
 
-  isDifferentForMagnifiers(text1, text2) {
+  isDifferentForMagnifiers(magnifier1, magnifier2) {
     if (
-      mathUtil.equalPoint(text1.center, text2.center) &&
-      text1.value == text2.value
+      mathUtil.equalPoint(magnifier1.position, magnifier2.position) &&
+      magnifier1.photoUrl == magnifier2.photoUrl &&
+      mathUtil.equalPoint(magnifier1.popPosition, magnifier2.popPosition)
     ) {
       return false;
     } else {
@@ -126,6 +127,17 @@ export default class HistoryUtil {
     this.setTextInfo(textInfo);
   }
 
+  assignMagnifierFromMagnifier(magnifier1, magnifier2) {
+    const magnifierInfo = {};
+    magnifierInfo.vectorId = magnifier1.vectorId;
+    magnifierInfo.photoUrl = magnifier2.photoUrl;
+    magnifierInfo.position = JSON.parse(JSON.stringify(magnifier2.position));
+    magnifierInfo.popPosition = JSON.parse(
+      JSON.stringify(magnifier2.popPosition)
+    );
+    this.setMagnifierInfo(magnifierInfo);
+  }
+
   assignSVGFromSVG(svg1, svg2) {
     const svgInfo = {};
     svgInfo.vectorId = svg1.vectorId;
@@ -175,6 +187,18 @@ export default class HistoryUtil {
     return data;
   }
 
+  getDataForMagnifier(magnifier) {
+    const data = {};
+    data.id = magnifier.vectorId;
+    data.type = magnifier.geoType;
+    data.position = {};
+    data.popPosition = {};
+    mathUtil.clonePoint(data.position, magnifier.position);
+    mathUtil.clonePoint(data.popPosition, magnifier.popPosition);
+    data.photoUrl = magnifier.photoUrl;
+    return data;
+  }
+
   getDataForSVG(svg) {
     const data = {};
     data.id = svg.vectorId;
@@ -223,6 +247,16 @@ export default class HistoryUtil {
     text.value = textInfo.value;
   }
 
+  setMagnifierInfo(magnifierInfo) {
+    let magnifier = dataService.getMagnifier(magnifierInfo.vectorId);
+    magnifier.vectorId = magnifierInfo.vectorId;
+    magnifier.position = JSON.parse(JSON.stringify(magnifierInfo.position));
+    magnifier.popPosition = JSON.parse(
+      JSON.stringify(magnifierInfo.popPosition)
+    );
+    magnifier.photoUrl = magnifierInfo.photoUrl;
+  }
+
   setSVGInfo(svgInfo) {
     let svg = dataService.getSVG(svgInfo.vectorId);
     svg.vectorId = svgInfo.vectorId;

+ 92 - 2
src/graphic/Load.js

@@ -4,6 +4,9 @@ import { pointService } from "./Service/PointService.js";
 import { imageService } from "./Service/ImageService.js";
 import VectorCategory from "./enum/VectorCategory.js";
 import { coordinate } from "./Coordinate.js";
+import { circleService } from "./Service/CircleService.js";
+import { magnifierService } from "./Service/MagnifierService.js";
+import { textService } from "./Service/TextService.js";
 
 export default class Load {
   constructor(layer) {
@@ -15,11 +18,97 @@ export default class Load {
 
   async load(dataLocal, data3d) {
     if (dataLocal) {
-      dataService.vectorData = JSON.parse(JSON.stringify(dataLocal));
+      if (dataLocal.backgroundImg) {
+        let bgImg = imageService.create(
+          dataLocal.backgroundImg.src,
+          dataLocal.vectorId
+        );
+        bgImg.setCenter(dataLocal.backgroundImg.center);
+        bgImg.setDisplay(dataLocal.backgroundImg.display);
+        bgImg.setAngle(dataLocal.backgroundImg.angle);
+        try {
+          await bgImg.setImageData();
+        } catch (e) {}
+      }
+      if (dataLocal.circles) {
+        for (let key in dataLocal.circles) {
+          let circle = circleService.create(
+            dataLocal.circles[key].center,
+            dataLocal.circles[key].radius,
+            key
+          );
+          circle.setPoints(dataLocal.circles[key].points);
+          circle.setColor(dataLocal.circles[key].color);
+          circle.setDisplay(dataLocal.circles[key].display);
+        }
+      }
+      if (dataLocal.magnifiers) {
+        for (let key in dataLocal.magnifiers) {
+          let magnifier = magnifierService.create(
+            dataLocal.magnifiers[key].position,
+            key
+          );
+          magnifier.setPopPosition(dataLocal.magnifiers[key].popPosition);
+          magnifier.setSrc(dataLocal.magnifiers[key].photoUrl);
+          magnifier.setDisplay(dataLocal.magnifiers[key].display);
+          try {
+            await magnifier.setImageData();
+          } catch (e) {}
+        }
+      }
+      if (dataLocal.texts) {
+        for (let key in dataLocal.texts) {
+          let text = textService.create(dataLocal.texts[key].center, key);
+          text.setValue(dataLocal.texts[key].value);
+          text.setFontSize(dataLocal.texts[key].fontSize);
+          text.setColor(dataLocal.texts[key].color);
+          text.setDisplay(dataLocal.texts[key].display);
+        }
+      }
+      // if (data3d.baseLines) {
+      //   for (let i = 0; i < data3d.baseLines.length; ++i) {
+      //     //理论上基准线只能有一条
+      //     lineService.create(
+      //       data3d.baseLines[i][0],
+      //       data3d.baseLines[i][1],
+      //       VectorCategory.Line.BaseLine
+      //     );
+      //   }
+      // }
+      // if (data3d.measures) {
+      //   for (let i = 0; i < data3d.measures.length; ++i) {
+      //     //理论上基准线只能有一条
+      //     lineService.create(
+      //       data3d.measures[i][0],
+      //       data3d.measures[i][1],
+      //       VectorCategory.Line.MeasureLine
+      //     );
+      //   }
+      // }
+      // if (data3d.basePoints) {
+      //   for (let i = 0; i < data3d.basePoints.length; ++i) {
+      //     let point = pointService.create(
+      //       data3d.basePoints[i],
+      //       data3d.basePoints[i].category,
+      //       data3d.basePoints[i].vectorId
+      //     );
+      //     point.setParent(data3d.basePoints[i].parent);
+      //   }
+      // }
+      // if (data3d.fixPoints) {
+      //   for (let i = 0; i < data3d.fixPoints.length; ++i) {
+      //     let point = pointService.create(
+      //       data3d.fixPoints[i],
+      //       data3d.fixPoints[i].category,
+      //       data3d.fixPoints[i].vectorId
+      //     );
+      //     point.setParent(data3d.fixPoints[i].parent);
+      //   }
+      // }
     }
     if (data3d) {
       if (data3d.backImage) {
-        let bgImg = imageService.create(data3d.backImage);
+        let bgImg = imageService.create(data3d.backImage, data3d.vectorId);
         bgImg.setCenter(coordinate.center);
         try {
           await bgImg.setImageData();
@@ -63,6 +152,7 @@ export default class Load {
       }
     }
     this.layer.history.init();
+    this.layer.renderer.autoRedraw();
   }
 
   save() {