All files / app/codeCharta/services/3DExports/3DPreview/MeshModels/BackMeshModels backPrintContainerMesh.ts

100% Statements 38/38
100% Branches 1/1
100% Functions 10/10
100% Lines 38/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72  6x 6x 6x 6x 6x 6x 6x 6x   6x   6x     16x 16x 16x       9x 9x 9x 9x 9x 9x 9x         9x 54x 54x 54x       9x 9x       12x 12x 12x 87x 70x           3x       14x 14x 14x       15x 15x     5x      
import { GeometryOptions } from "../../preview3DPrintMesh"
import { GeneralMesh, GeneralSizeChangeMesh } from "../generalMesh"
import { BackPrintColorChangeStrategy } from "../../ColorChangeStrategies/backPrintColorChangeStrategy"
import { BackMWLogoMesh } from "./backMWLogoMesh"
import { BackBelowLogoTextMesh } from "./backBelowLogoTextMesh"
import { QrCodeMesh } from "./qrCodeMesh"
import { CodeChartaLogoMesh } from "./codeChartaLogoMesh"
import { CodeChartaTextMesh } from "./codeChartaTextMesh"
import { MetricDescriptionsContainerMesh } from "./metricDescriptionsContainerMesh"
import { Font } from "three/examples/jsm/loaders/FontLoader"
import { CustomVisibilityMesh } from "../customVisibilityMesh"
 
export class BackPrintContainerMesh extends GeneralMesh implements GeneralSizeChangeMesh {
    private childrenMeshes: Map<string, GeneralMesh>
 
    constructor(private font: Font) {
        const colorChangeStrategy = new BackPrintColorChangeStrategy()
        super("BackPrintContainer", colorChangeStrategy)
    }
 
    async init(geometryOptions: GeometryOptions): Promise<BackPrintContainerMesh> {
        this.childrenMeshes = new Map<string, GeneralMesh>()
        this.childrenMeshes.set("BackMWLogo", new BackMWLogoMesh("BackMWLogo"))
        this.childrenMeshes.set("BackBelowLogoText", new BackBelowLogoTextMesh("BackBelowLogoText", this.font))
        this.childrenMeshes.set("QrCode", new QrCodeMesh("QrCode"))
        this.childrenMeshes.set("CodeChartaLogo", new CodeChartaLogoMesh("CodeChartaLogo"))
        this.childrenMeshes.set("CodeChartaText", new CodeChartaTextMesh("CodeChartaText", this.font))
        this.childrenMeshes.set(
            "MetricDescriptionsContainer",
            new MetricDescriptionsContainerMesh("MetricDescriptionsContainer", this.font)
        )
 
        await Promise.all(
            [...this.childrenMeshes.values()].map(async mesh => {
                await mesh.init(geometryOptions)
                this.add(mesh)
            })
        )
 
        this.changeSize(geometryOptions, 1)
        return this
    }
 
    changeSize(geometryOptions: GeometryOptions, oldWidth: number): void {
        const scaleFactor = geometryOptions.width / oldWidth
        this.scale.set(this.scale.x * scaleFactor, this.scale.y * scaleFactor, this.scale.z)
        this.traverse(mesh => {
            if (mesh instanceof CustomVisibilityMesh) {
                mesh.setCurrentWidth(geometryOptions.width)
            }
        })
    }
 
    isQRCodeVisible(): boolean {
        return this.childrenMeshes.get("QrCode").visible
    }
 
    async updateQrCodeText(qrCodeText: string, geometryOptions: GeometryOptions): Promise<void> {
        geometryOptions.qrCodeText = qrCodeText
        const qrCodeMesh = this.childrenMeshes.get("QrCode") as QrCodeMesh
        await qrCodeMesh.changeText(geometryOptions)
    }
 
    updateQrCodeVisibility(qrCodeVisible: boolean) {
        const qrCodeMesh = this.childrenMeshes.get("QrCode") as QrCodeMesh
        qrCodeMesh.setManualVisibility(qrCodeVisible)
    }
    getChildrenMeshes(): Map<string, GeneralMesh> {
        return this.childrenMeshes
    }
}