xushiting 1 gadu atpakaļ
vecāks
revīzija
cc853f9233

+ 3 - 3
src/view/case/draw/board/editCAD/Controls/UIControl.js

@@ -85,9 +85,9 @@ export default class UIControl {
         if(type == VectorType.Tag){
             const tag = floorplanService.getTag(item.vectorId)
             if(value.hasOwnProperty('version')){
-                tag.setColor(value.color)
-                tag.setFontSize(value.fontSize)
-                tag.setValue(value.text)
+              value.color&&tag.setColor(value.color)
+              value.fontSize&&tag.setFontSize(value.fontSize)
+              value.text&&tag.setValue(value.text)
             }
             else{
                 tag.setValue(value)

+ 21 - 1
src/view/case/draw/board/editCAD/Geometry/Tag.js

@@ -16,7 +16,7 @@ export default class Tag extends Geometry {
         this.sideThickness = 30 //像素
 
         this.color = 'black';
-        this.fontSize = '12px';
+        this.fontSize = 12;
 
         this.geoType = VectorType.Tag
         this.setId(vectorId)
@@ -31,6 +31,26 @@ export default class Tag extends Geometry {
         return mathUtil.isPointInPoly(position, points)
     }
 
+    setFontLenAndHeight(){
+        let height = 0;
+        let row = 0;
+        let textValues = [];
+        textValues[0] = '';
+        for(let i=0;i<this.value.length;++i){
+            if(this.value[i] == '\n'){
+                ++height;
+                ++row;
+                textValues[row] = '';
+            }else{
+                textValues[row] += this.value[i]
+            }
+        }
+        return {
+            textValues:textValues,
+            height:height
+        }
+    }
+
     setPoints2d() {
         this.points2d = []
         const minX = this.center.x - ((this.sideWidth / coordinate.res) * Constant.defaultZoom) / coordinate.zoom / 2

+ 33 - 10
src/view/case/draw/board/editCAD/History/Change.js

@@ -104,7 +104,7 @@ export default class Change {
       this.elements.title == null &&
       this.elements.image == null &&
       this.elements.compass == null && 
-      this.elements.customImage == null
+      this.elements.customImages.length == 0
     ) {
       this.saveCurrentInfo();
       return false;
@@ -593,18 +593,41 @@ export default class Change {
   }
 
   compareCustomImages(){
-    this.elements.customImage = null;
-    const customImage = floorplanService.getCustomImage();
-    const lastCustomImage = this.lastData.customImage;
+    this.elements.customImages = [];
+    const customImages = floorplanService.getCustomImages();
+    for (const key in customImages) {
+      const customImage = customImages[key];
+      const lastCustomImage = this.lastData.customImages[key];
 
-    const flag = historyUtil.isDifferentForCustomImage(customImage, lastCustomImage);
-    if (flag) {
+      // 不存在意味着增加
+      if (!lastCustomImage) {
+        const item = {
+          handle: HistoryEvents.AddCustomImage,
+          customImage: historyUtil.getDataForCustomImage(customImage),
+        };
+        this.elements.customImages.push(item);
+      } else {
+        if (!historyUtil.isDifferentForCustomImages(customImage, lastCustomImage)) {
+          delete this.lastData.customImages[key];
+          continue;
+        } else {
+          const item = {
+            handle: HistoryEvents.ModifyCustomImage,
+            preCustomImage: historyUtil.getDataForCustomImage(lastCustomImage),
+            curCustomImage: historyUtil.getDataForCustomImage(customImage),
+          };
+          this.elements.customImages.push(item);
+        }
+      }
+      delete this.lastData.customImages[key];
+    }
+
+    for (const key in this.lastData.customImages) {
       const item = {
-        handle: HistoryEvents.ModifyCustomImage,
-        preCustomImage: historyUtil.getDataForCustomImage(lastCustomImage),
-        curCustomImage: historyUtil.getDataForCustomImage(customImage),
+        handle: HistoryEvents.DeleteCustomImage,
+        customImage: historyUtil.getDataForCustomImage(this.lastData.customImages[key]),
       };
-      this.elements.customImage = item;
+      this.elements.customImages.push(item);
     }
   }
 }

+ 20 - 13
src/view/case/draw/board/editCAD/History/History.js

@@ -142,7 +142,7 @@ export default class History {
             this.goPreForTitle(item.title)
             this.goPreForImage (item.image)
             this.goPreForCompass(item.compass)
-            this.goPreForCustomImages(item.customImage)
+            this.goPreForCustomImages(item.customImages)
 
             historyService.undoHistoryRecord()
             change.saveCurrentInfo()
@@ -346,7 +346,7 @@ export default class History {
         }
     }
 
-    goPreForCustomImage(itemForCustomImage) {
+    goPreForCustomImages(itemForCustomImage) {
         if (itemForCustomImage != null && itemForCustomImage.handle == HistoryEvents.ModifyCustomImage) {
             const preCustomImage = itemForCustomImage.preCustomImage
             let curCustomImage = floorplanService.getCustomImage()
@@ -354,6 +354,22 @@ export default class History {
         }
     }
 
+    goPreForCustomImages(itemForCustomImages) {
+        for (let i = 0; i < itemForCustomImages.length; ++i) {
+            const item = itemForCustomImages[i]
+            if (item.handle == HistoryEvents.AddCustomImage) {  
+                customImageService.deleteCustomImage(item.customImage.id)
+            } else if (item.handle == HistoryEvents.DeleteCustomImage) {
+                let newCustomImage = customImageService.createCustomImage(item.customImage.center,item.customImage.id)
+                historyUtil.assignCustomImageFromCustomImage(newCustomImage, item.customImage)
+            } else if (item.handle == HistoryEvents.ModifyCustomImage) {
+                const preCustomImage = item.preCustomImage
+                let curCustomImage = floorplanService.getCustomImage(item.curCustomImage.id)
+                historyUtil.assignCustomImageFromCustomImage(curCustomImage, preCustomImage)
+            }
+        }
+    }
+
     goNextForPoints(itemForPoints) {
         for (let i = 0; i < itemForPoints.length; ++i) {
             const item = itemForPoints[i]
@@ -539,7 +555,7 @@ export default class History {
         }
     }
 
-    goNextForCustomImage(itemForCustomImages) {
+    goNextForCustomImages(itemForCustomImages) {
         for (let i = 0; i < itemForCustomImages.length; ++i) {
             const item = itemForCustomImages[i]
             if (item.handle == HistoryEvents.AddCustomImage) {
@@ -585,19 +601,10 @@ export default class History {
                 this.goNextForImage (item.image)
                 this.goNextForCompass(item.compass)
 
-                this.goNextForCustomImage(item.customImage)
+                this.goNextForCustomImages(item.customImages)
             }
             change.saveCurrentInfo()
             this.setState()
-
-            // const points = floorplanService.getPoints()
-            // if (Object.keys(points).length > 0) {
-            //     this.layer.$xui.toolbar.clear = true
-            //     this.layer.$xui.toolbar.download = true
-            // } else {
-            //     this.layer.$xui.toolbar.clear = false
-            //     this.layer.$xui.toolbar.download = false
-            // }
         } else {
             historyService.undoHistoryRecord()
             console.error('goNextState超出范围!')

+ 17 - 15
src/view/case/draw/board/editCAD/History/HistoryUtil.js

@@ -22,7 +22,7 @@ export default class HistoryUtil {
     }
   
     isDifferentForTags(tag1, tag2) {
-        if (mathUtil.equalPoint(tag1.center, tag2.center) && tag1.value == tag2.value) {
+        if (mathUtil.equalPoint(tag1.center, tag2.center) && tag1.value == tag2.value && tag1.color == tag2.color && tag1.fontSize == tag2.fontSize) {
             return false
         } else {
             return true
@@ -61,7 +61,7 @@ export default class HistoryUtil {
 
     isDifferentForRectangles(rectangle1, rectangle2) {
         for(let i=0;i<rectangle1.points.length;++i){
-            if(!mathUtil.equalPoint(rectangle1.points[i], rectangle2.points[i])){
+            if(!mathUtil.equalPoint(rectangle1.points[i], rectangle2.points[i]) && rectangle1.color == rectangle2.color){
                 return true;
             }
         }
@@ -69,7 +69,7 @@ export default class HistoryUtil {
     }
 
     isDifferentForCircles(circle1, circle2) {
-        if(!mathUtil.equalPoint(circle1.center, circle2.center)){
+        if(!mathUtil.equalPoint(circle1.center, circle2.center) && circle1.color == circle2.color){
             return true;
         }
         else if(circle1.radius != circle2.radius){
@@ -86,7 +86,7 @@ export default class HistoryUtil {
     }
 
     isDifferentForArrows(arrow1, arrow2) {
-        if (mathUtil.equalPoint(arrow1.startPoint, arrow2.startPoint) && mathUtil.equalPoint(arrow1.endPoint, arrow2.endPoint)) {
+        if (mathUtil.equalPoint(arrow1.startPoint, arrow2.startPoint) && mathUtil.equalPoint(arrow1.endPoint, arrow2.endPoint) && arrow1.color == arrow2.color) {
             return false
         } else {
             return true
@@ -148,7 +148,7 @@ export default class HistoryUtil {
         }
     }
 
-    isDifferentForCustomImage(customImage1, customImage2) {
+    isDifferentForCustomImages(customImage1, customImage2) {
         if (customImage1.angle == customImage2.angle && customImage1.scale == customImage2.scale && customImage1.url == customImage2.url) {
             return false
         } else {
@@ -162,6 +162,7 @@ export default class HistoryUtil {
         wallInfo.vectorId = wall1.vectorId
         wallInfo.start = wall2.start
         wallInfo.end = wall2.end
+        wallInfo.color = wall2.color
         wallService.setWallInfo(wallInfo)
     }
 
@@ -177,6 +178,8 @@ export default class HistoryUtil {
         const tagInfo = {}
         tagInfo.vectorId = tag1.vectorId
         tagInfo.value = tag2.value
+        tagInfo.color = tag2.color
+        tagInfo.fontSize = tag2.fontSize
         tagInfo.center = JSON.parse(JSON.stringify(tag2.center))
         tagInfo.points2d = JSON.parse(JSON.stringify(tag2.points))
         tagService.setTagInfo(tagInfo)
@@ -205,20 +208,11 @@ export default class HistoryUtil {
         tableService.setTableInfo(tableInfo)
     }
 
-    // eslint-disable-next-line no-dupe-class-members
-    assignTagFromTag(tag1, tag2) {
-        const tagInfo = {}
-        tagInfo.vectorId = tag1.vectorId
-        tagInfo.value = tag2.value
-        tagInfo.center = JSON.parse(JSON.stringify(tag2.center))
-        tagInfo.points2d = JSON.parse(JSON.stringify(tag2.points))
-        tagService.setTagInfo(tagInfo)
-    }
-
     assignRectangleFromRectangle(rectangle1, rectangle2) {
         const rectangleInfo = {}
         rectangleInfo.vectorId = rectangle1.vectorId
         rectangleInfo.angle = rectangle2.angle
+        rectangleInfo.color = rectangle2.color
         rectangleInfo.points = JSON.parse(JSON.stringify(rectangle2.points))
         rectangleService.setRectangleInfo(rectangleInfo)
     }
@@ -227,6 +221,7 @@ export default class HistoryUtil {
         const circleInfo = {}
         circleInfo.vectorId = circle1.vectorId
         circleInfo.radius = circle2.radius
+        circleInfo.color = circle2.color
         circleInfo.center = JSON.parse(JSON.stringify(circle2.center))
         circleInfo.points = JSON.parse(JSON.stringify(circle2.points))
         circleService.setCircleInfo(circleInfo)
@@ -235,6 +230,7 @@ export default class HistoryUtil {
     assignArrowFromArrow(arrow1, arrow2) {
         const arrowInfo = {}
         arrowInfo.vectorId = arrow1.vectorId
+        arrowInfo.color = arrow2.color
         arrowInfo.startPoint = JSON.parse(JSON.stringify(arrow2.startPoint))
         arrowInfo.endPoint = JSON.parse(JSON.stringify(arrow2.endPoint))
         arrowService.setArrowInfo(arrowInfo)
@@ -309,6 +305,7 @@ export default class HistoryUtil {
     getDataForWall(wall) {
         const data = {}
         data.id = wall.vectorId
+        data.color = wall.color
         data.start = wall.start
         data.end = wall.end
         data.type = wall.geoType
@@ -329,6 +326,8 @@ export default class HistoryUtil {
         const data = {}
         data.id = tag.vectorId
         data.type = tag.geoType
+        data.color = tag.color
+        data.fontSize = tag.fontSize
         data.center = {}
         mathUtil.clonePoint(data.center, tag.center)
         data.points = [].concat(tag.points2d)
@@ -366,6 +365,7 @@ export default class HistoryUtil {
         const data = {}
         data.id = rectangle.vectorId
         data.type = rectangle.geoType
+        data.color = rectangle.color
         data.angle = rectangle.angle
         data.points = [].concat(rectangle.points)
         return data
@@ -375,6 +375,7 @@ export default class HistoryUtil {
         const data = {}
         data.id = circle.vectorId
         data.type = circle.geoType
+        data.color = circle.color
         data.center = {}
         mathUtil.clonePoint(data.center, circle.center)
         data.points = [].concat(circle.points)
@@ -386,6 +387,7 @@ export default class HistoryUtil {
         const data = {}
         data.id = arrow.vectorId
         data.type = arrow.geoType
+        data.color = arrow.color
         data.startPoint = {}
         mathUtil.clonePoint(data.startPoint, arrow.startPoint)
         data.endPoint = {}

+ 33 - 22
src/view/case/draw/board/editCAD/Renderer/Draw.js

@@ -57,6 +57,9 @@ export default class Draw {
 
         this.context.lineWidth = Style.Wall.lineWidth * coordinate.ratio
         this.context.strokeStyle = Style.Wall.strokeStyle
+        if(vector.color){
+            this.context.strokeStyle = vector.color
+        }
 
         const selectItem = stateService.getSelectItem()
         const draggingItem = stateService.getDraggingItem()
@@ -184,8 +187,8 @@ export default class Draw {
         this.context.save()
 
         this.context.lineWidth = Style.Tag.lineWidth * coordinate.ratio
-        this.context.strokeStyle = Style.Tag.strokeStyle
-        this.context.fillStyle = Style.Tag.fillStyle
+        this.context.strokeStyle = geometry.color
+        this.context.fillStyle = geometry.color
 
         const selectItem = stateService.getSelectItem()
         const draggingItem = stateService.getDraggingItem()
@@ -210,11 +213,17 @@ export default class Draw {
             }
         }
 
-        const fontSize = coordinate.ratio == Constant.ratio ? 36 : 12
-        this.context.font = `400 ${fontSize}px Microsoft YaHei`
+        this.context.font = `400 ${geometry.fontSize}px Microsoft YaHei`
 
         //根据文字的长度,更新标注范围
-        geometry.sideWidth = Math.max(this.context.measureText(geometry.value).width, this.context.measureText(parseFloat(geometry.value).toFixed(2)).width)
+        //geometry.sideWidth = Math.max(this.context.measureText(geometry.value).width, this.context.measureText(parseFloat(geometry.value).toFixed(2)).width)
+        let fontInfo = geometry.setFontLenAndHeight()
+        let sideWidth = 0;
+        for(let i=0;i<fontInfo.textValues.length;++i){
+            sideWidth = Math.max(sideWidth,this.context.measureText(fontInfo.textValues[i]).width, this.context.measureText(parseFloat(fontInfo.textValues[i]).toFixed(2)).width)
+        }
+        geometry.sideWidth = sideWidth
+        geometry.sideThickness = fontInfo.height * geometry.fontSize * 2
         geometry.setPoints2d()
 
         let points2d = geometry.points2d
@@ -223,18 +232,22 @@ export default class Draw {
             points[i] = coordinate.getScreenXY({ x: points2d[i].x, y: points2d[i].y })
         }
 
-        let pt = { x: geometry.center.x, y: geometry.center.y }
-        pt = coordinate.getScreenXY({ x: geometry.center.x, y: geometry.center.y })
-        const fontWidth1 = this.context.measureText(geometry.value).width
-        const line1 = mathUtil.createLine1({ x: (points[0].x + points[3].x) / 2, y: (points[0].y + points[3].y) / 2 }, { x: (points[2].x + points[1].x) / 2, y: (points[2].y + points[1].y) / 2 })
-        const fontStart1 = mathUtil.getDisPointsLine(line1, pt, fontWidth1 / 2, fontWidth1 / 2)
-
-        if (fontStart1.newpoint1.x < fontStart1.newpoint2.x) {
-            this.context.fillText(geometry.value, fontStart1.newpoint1.x, fontStart1.newpoint1.y)
-        } else {
-            this.context.fillText(geometry.value, fontStart1.newpoint2.x, fontStart1.newpoint2.y)
+        let pt = coordinate.getScreenXY({ x: geometry.center.x, y: geometry.center.y })
+        const fontWidth1 = geometry.sideWidth
+        let dy = (points[3].y - points[0].y)/fontInfo.textValues.length
+        for(let i=0;i<fontInfo.textValues.length;++i){
+            // const line1 = mathUtil.createLine1({ x: (points[0].x + points[3].x) / 2, y: (points[0].y + points[3].y) / 2 }, { x: (points[2].x + points[1].x) / 2, y: (points[2].y + points[1].y) / 2 })
+            // const fontStart1 = mathUtil.getDisPointsLine(line1, pt, fontWidth1 / 2, fontWidth1 / 2)
+    
+            // if (fontStart1.newpoint1.x < fontStart1.newpoint2.x) {
+            //     this.context.fillText(geometry.value, fontStart1.newpoint1.x, fontStart1.newpoint1.y)
+            // } else {
+            //     this.context.fillText(geometry.value, fontStart1.newpoint2.x, fontStart1.newpoint2.y)
+            // }
+            this.context.fillText(fontInfo.textValues[i], pt.x - fontWidth1/2, pt.y - geometry.sideThickness/2+dy*i)
         }
 
+
         this.context.restore()
     }
 
@@ -337,10 +350,9 @@ export default class Draw {
         this.context.save()
         this.context.beginPath()
         this.context.lineCap = 'round' //线段端点的样式;
-        this.context.strokeStyle = Style.Rectangle.strokeStyle
 
         this.context.lineWidth = Style.Rectangle.lineWidth * coordinate.ratio
-        this.context.strokeStyle = Style.Rectangle.strokeStyle
+        this.context.strokeStyle = geometry.color
 
         const selectItem = stateService.getSelectItem()
         const draggingItem = stateService.getDraggingItem()
@@ -431,8 +443,7 @@ export default class Draw {
         const pt = coordinate.getScreenXY(geometry.center)
 
         this.context.save()
-        this.context.strokeStyle = Style.Circle.strokeStyle
-
+        this.context.strokeStyle = geometry.color
         const selectItem = stateService.getSelectItem()
         const draggingItem = stateService.getDraggingItem()
         const focusItem = stateService.getFocusItem()
@@ -592,8 +603,8 @@ export default class Draw {
         this.context.save()
         this.setCanvasStyle(Style.Font)
         
-        let fonSize = Math.ceil(radius * 14/20);
-        this.context.font = fonSize + Style.Font.font;   
+        let fontSize = Math.ceil(radius * 14/20);
+        this.context.font = fontSize + Style.Font.font;   
         let center = coordinate.getScreenXY(geometry.center);
         this.context.fillText(geometry.value, center.x , center.y)
         this.context.restore()
@@ -604,7 +615,7 @@ export default class Draw {
         this.context.save()
         this.context.beginPath()
         this.context.lineCap = 'round' //线段端点的样式
-        this.context.strokeStyle = Style.Arrow.strokeStyle
+        this.context.strokeStyle = geometry.color
         this.context.lineWidth = Style.Arrow.lineWidth * coordinate.ratio
 
         const selectItem = stateService.getSelectItem()