Browse Source

Merge branch 'master' into merge-selection

bill 2 tháng trước cách đây
mục cha
commit
7ab274fd14

+ 50 - 42
src/core/components/icon/icon.ts

@@ -14,69 +14,76 @@ import { Color } from "three";
 
 export const shapeName = "图例";
 export const defaultStyle = {
-  coverFill: '#000000',
+  coverFill: "#000000",
   coverOpcatiy: 0,
   strokeScaleEnabled: false,
   width: 80,
   height: 80,
 };
 
-  type ColorCounts = [string, number][]
-  const colorsManage = (counts: ColorCounts, color: any) => {
+type ColorCounts = [string, number][];
+const colorsManage = (counts: ColorCounts, color: any) => {
   if (!color) {
     return;
   }
-  const colorHex = new Color(color).getHexString()
-  const item = counts.find(([c]) => c === colorHex)
+  const colorHex = new Color(color).getHexString();
+  const item = counts.find(([c]) => c === colorHex);
   if (!item) {
-    counts.push([colorHex, 1])
+    counts.push([colorHex, 1]);
   } else {
-    item[1]++
+    item[1]++;
   }
-}
+};
 const findColor = (counts: ColorCounts) => {
-  let ndx = -1
-  let max = 0
+  let ndx = -1;
+  let max = 0;
   for (let i = 0; i < counts.length; i++) {
     if (counts[i][1] >= max) {
-      ndx = i
-      max = counts[i][1]
+      ndx = i;
+      max = counts[i][1];
     }
   }
   if (~ndx) {
-    return `#${counts[ndx][0]}`
+    return `#${counts[ndx][0]}`;
   }
-}
+};
 
-export const getIconStyle = async (url: string, width = defaultStyle.width, height = defaultStyle.height) => {
+export const getIconStyle = async (
+  url: string,
+  width = defaultStyle.width,
+  height = defaultStyle.height,
+  fixed = false
+) => {
   const svgContent = parseSvgContent(await getSvgContent(url));
-  if (width / height > svgContent.width / svgContent.height) {
-    width = svgContent.width / svgContent.height * height
-  } else {
-    height = svgContent.height / svgContent.width * width
+  if (!fixed) {
+    if (width / height < svgContent.width / svgContent.height) {
+      width = (svgContent.width / svgContent.height) * height;
+    } else {
+      height = (svgContent.height / svgContent.width) * width;
+    }
   }
-  const fillColorCounts: [string, number][] = []
-  const strokeColorCounts: [string, number][] = []
+  const fillColorCounts: [string, number][] = [];
+  const strokeColorCounts: [string, number][] = [];
 
   for (let i = 0; i < svgContent.paths.length; i++) {
-    colorsManage(fillColorCounts, svgContent.paths[i].fill)
-    colorsManage(strokeColorCounts, svgContent.paths[i].stroke)
+    colorsManage(fillColorCounts, svgContent.paths[i].fill);
+    colorsManage(strokeColorCounts, svgContent.paths[i].stroke);
   }
 
   const color = {
     fill: findColor(fillColorCounts) || null,
-    stroke: findColor(strokeColorCounts) || null
+    stroke: findColor(strokeColorCounts) || null,
   };
   if (!color.fill && !color.stroke) {
     color.stroke = "#000000";
-  } 
+  }
   return {
     url,
     width,
     height,
-    ...color
-  }
-}
+    ...color,
+  };
+};
 
 export const addMode = "dot";
 
@@ -102,17 +109,18 @@ export const getMouseStyle = (data: IconData) => {
       coverOpcatiy: data.coverOpcatiy || 0,
     },
     hover: { coverFill: fillStatus.hover, coverOpcatiy: hCoverOpcaoty },
-    select: { coverFill: fillStatus.select, coverOpcatiy: hCoverOpcaoty  },
-    focus: { coverFill: fillStatus.select, coverOpcatiy: hCoverOpcaoty  },
+    select: { coverFill: fillStatus.select, coverOpcatiy: hCoverOpcaoty },
+    focus: { coverFill: fillStatus.select, coverOpcatiy: hCoverOpcaoty },
     press: { coverFill: fillStatus.press, coverOpcatiy: hCoverOpcaoty },
   };
 };
 
 export type IconData = Partial<typeof defaultStyle> &
-  BaseItem & Size & {
+  BaseItem &
+  Size & {
     fill?: string | null;
     stroke?: string | null;
-    name?: string
+    name?: string;
     strokeWidth?: number;
     coverFill?: string;
     coverStroke?: string;
@@ -136,7 +144,7 @@ export const interactiveToData: InteractiveTo<"icon"> = ({
   ...args
 }) => {
   if (info.cur) {
-  console.error(preset)
+    console.error(preset);
     return interactiveFixData({
       ...args,
       viewTransform,
@@ -168,17 +176,17 @@ export const interactiveFixData: InteractiveFix<"icon"> = ({
   return data;
 };
 
-
-
-
-export const matResponse = ({data, mat, increment}: MatResponseProps<'icon'>) => {
+export const matResponse = ({
+  data,
+  mat,
+  increment,
+}: MatResponseProps<"icon">) => {
   data.mat = increment ? mat.copy().multiply(new Transform(data.mat)).m : mat.m;
   return data;
-}
-
+};
 
 export const getPredefine = (key: keyof IconData) => {
-  if (key === 'fill' || key === 'stroke') {
-    return { canun: true }
+  if (key === "fill" || key === "stroke") {
+    return { canun: true };
   }
-}
+};

+ 13 - 8
src/core/hook/use-dxf.ts

@@ -10,7 +10,6 @@ import {
   HatchPolylineBoundary,
   vertex,
 } from "@tarikjabiri/dxf";
-import { defaultStyle as iconDefStyle } from '../components/icon'
 import { useStore } from "../store";
 import Zip from "jszip";
 import { LineData } from "../components/line";
@@ -33,6 +32,7 @@ import {
 } from "./use-viewer";
 import { nextTick } from "vue";
 import { SLineData } from "../components/sequent-line";
+import { IRect } from "konva/lib/types";
 
 export const useGetDXF = () => {
   const store = useStore();
@@ -131,7 +131,6 @@ export const useGetDXF = () => {
         }
       }
 
-      console.log(textArr);
       textArr.forEach((item) => {
         const lineWidth = charWidth * item.charCount;
         let p = { x: pad, y: pad + lineNum * fontSize * 1.2 };
@@ -161,18 +160,21 @@ export const useGetDXF = () => {
       });
     };
 
-    const writeImage = async (imgGroup: Group, scaleCallback?: (scale: Size) => () => void) => {
+    const writeImage = async (imgGroup: Group, scaleCallback?: (scale: Size, box: IRect) => () => void) => {
       let curRect = imgGroup.getClientRect();
       const oldViewMat = viewer.viewMat;
       setViewport(curRect);
       await nextTick();
       const imgRect = imgGroup.getClientRect();
-      const back = scaleCallback && scaleCallback({ width: imgRect.width / curRect.width, height: imgRect.height / curRect.height })
+      const back = scaleCallback && scaleCallback({ width: imgRect.width / curRect.width, height: imgRect.height / curRect.height }, imgRect)
       await nextTick()
       const img = (await imgGroup!.toImage({
         pixelRatio: 1,
         quality: 1,
         mimeType: "image/png",
+      }).catch((e) => {
+        console.error(e)
+        throw e
       })) as HTMLImageElement;
       back && back()
       await nextTick()
@@ -195,6 +197,9 @@ export const useGetDXF = () => {
         fetch(img.src)
           .then((res) => res.blob())
           .then((blob) => zip.file(path, blob, {}))
+          .catch(e => {
+            console.error(e)
+          })
       );
       viewer.setViewMat(oldViewMat);
     };
@@ -362,11 +367,11 @@ export const useGetDXF = () => {
           const pathGroup = $stage
             .findOne<Group>(`#${iconItem.id}`)!
             .findOne<Group>(".rep-position")!;
-          await writeImage(pathGroup, (scale) => {
-            const sw = iconItem.strokeWidth || (iconDefStyle as any).strokeWidth || undefined
-            iconItem.strokeWidth = sw && (sw * Math.max(scale.width, scale.height))
+
+          await writeImage(pathGroup, () => {
+            iconItem.strokeScaleEnabled = true
             return () => {
-              iconItem.strokeWidth = sw
+              iconItem.strokeScaleEnabled = false
             }
           });
           break;

+ 1 - 1
src/core/hook/use-global-vars.ts

@@ -366,7 +366,7 @@ export const useRendererDOM = installGlobalVar(() => ref<HTMLDivElement>())
 export const useTempStatus = installGlobalVar(() => {
   const temp = ref(false);
   const enterTemp = <T>(fn: () => T): T => {
-    temp.value = true
+    temp.value = !import.meta.env.DEV && true
     const result = fn()
     if (result instanceof Promise) {
       return result.then(async (data) => {

+ 1 - 1
src/core/html-mount/propertys/components/fix-proportion.vue

@@ -4,7 +4,7 @@
     <el-input-number
       :controls="false"
       :model-value="value"
-      @update:model-value="(value: any) => $emit('update:value', value)"
+      @update:model-value="(value: any) => value !== null && $emit('update:value', value)"
       @change="$emit('change')"
       style="width: 98px"
       :precision="0"

+ 6 - 3
src/core/html-mount/propertys/components/input-num.vue

@@ -3,7 +3,7 @@
     <el-input-number
       :controls="false"
       :modelValue="props.proportion ? transform(value) : value"
-      @update:model-value="(val: any) => props.proportion ? changeHandler(invTransform(val)) : changeHandler(val)"
+      @update:model-value="(val: any) => props.proportion ? changeHandler(invTransform(val), val) : changeHandler(val, val)"
       @change="$emit('change')"
       style="width: 98px"
       :precision="0"
@@ -35,7 +35,10 @@ const emit = defineEmits<{
 }>();
 const { proportion, transform, invTransform } = useProportion();
 
-const changeHandler = (val: number) => {
-  emit("update:value", val);
+const changeHandler = (val: number, rawVal: any) => {
+  if (rawVal !== null) {
+    console.log(rawVal);
+    emit("update:value", val);
+  }
 };
 </script>

+ 2 - 0
src/example/fuse/views/overview/header.vue

@@ -99,6 +99,8 @@ const setViewToTableCover = async () => {
   const oldShowCompass = draw.config.showCompass;
   const oldLabelLineConfig = { ...draw.config.labelLineConfig };
   const oldShowOffset = draw.config.labelLineConfig.showOffset;
+  draw.initViewport(0);
+  await nextTick();
   const getRect = () => draw.stage!.findOne<Group>(`#${DataGroupId}`)!.getClientRect();
 
   const pop = draw.mode.push(Mode.readonly);

+ 1 - 1
src/example/loadding.ts

@@ -16,7 +16,7 @@ watchEffect(() => {
     instance.close()
     instance = null
   }
-  if (loadingStack.value.length && !instance) {
+  if (loadingStack.value.length && !instance && !import.meta.env.DEV) {
     instance = ElLoading.service(loadingStack.value[0])
   }
 })

+ 4 - 3
src/example/platform/platform-draw.ts

@@ -60,6 +60,7 @@ const scaleResource = (info: AIExposeData, scale: number) => {
         if (!floor || !floor.box) return;
         const w = floor.box.bound.x_max - floor.box.bound.x_min;
         const h = floor.box.bound.y_max - floor.box.bound.y_min;
+        console.log(item.size)
         return {
           ...item,
           position: {
@@ -67,6 +68,7 @@ const scaleResource = (info: AIExposeData, scale: number) => {
             y: floor.box.bound.y_min + h * item.position.y,
             z: floor.box.bound.z_min + 0.001,
           },
+          fixed: true,
           size: item.size
             ? {
                 width: item.size!.width * w,
@@ -118,13 +120,11 @@ const getResourceLayers = (data: AIExposeData) => {
       box.bound.z_min = -999999;
       box.bound.z_max = 999999;
 
-      console.log("楼层范围", box.bound.z_min, box.bound.z_max);
       return {
         ...floor,
         box,
         taggings: data.taggings
           .filter((item) => {
-            console.log("tag高度", item.position.z);
             return (
               item.position.z === undefined ||
               (item.position.z >= box.bound.z_min &&
@@ -317,7 +317,8 @@ const drawLayerResource = async (
           attach = await getIconStyle(
             item.url,
             item.size?.width,
-            item.size?.height
+            item.size?.height,
+            item.fixed,
           );
         } catch {}
       }

+ 2 - 1
src/example/platform/platform-resource.ts

@@ -42,6 +42,7 @@ export type Taging = {
   url: string;
   position: Pos & { z: number };
   size?: Size;
+  fixed?: boolean
   rotate?: number;
   name?: string;
   pixel?: boolean;
@@ -288,7 +289,7 @@ export const taggingGets = {
 
     await getSceneApi(
       "oss",
-      `${prev}/data/floorplan/ai.json?_=${config.version}`
+      `${prev}/data/floorplan/ai-entire.json?_=${config.version}`
     )
       .then((url) => fetch(url))
       .then((res) => res.json())