import { hilog } from '@kit.PerformanceAnalysisKit'; import fs from '@ohos.file.fs'; import fileIO from '@ohos.fileio'; import {NodeContent} from '@kit.ArkUI'; import NativeOpenCAX from 'libopencax.so'; const DOMAIN = 0x0000; let modelPath: string = ''; export function OCCTLoadModel(Command: undefined, Param:undefined) { try { NativeOpenCAX.loadModel(modelPath); console.info('Model copied to:', modelPath); } catch (e) { hilog.error(0x0000, 'ModelView', `LoadModel Failed: ${JSON.stringify(e)}`); } } @Component export struct ModelView { private displayController: XComponentController = new XComponentController(); private displayContrId: string = 'OCCTRender'; @State modelName:string='2027.stp'; @State currentStatus: string = 'init'; private nodeContent: NodeContent = new NodeContent(); aboutToAppear() { NativeOpenCAX.createNativeNode(this.nodeContent); this.copyRawFileToSandbox(); } async copyRawFileToSandbox() { try { const context = getContext(this); modelPath = `${context.filesDir}/${this.modelName}`; const arrayBuffer:Uint8Array = await context.resourceManager.getRawFileContent(this.modelName); const buffer = arrayBuffer.buffer; console.log('Raw file size:', arrayBuffer.byteLength); if (fs.accessSync(modelPath)) { fs.unlinkSync(modelPath); } const fd = fileIO.openSync(modelPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE,0o666); const bytesWritten = fileIO.writeSync(fd, buffer); console.log('Bytes written:', bytesWritten); fileIO.closeSync(fd); console.log('SanBox File:', arrayBuffer.byteLength); console.log('WriteModelPath:', modelPath); } catch (err) { let msg = 'Unknown error'; if (err instanceof Error) { msg = err.message; } else if (typeof err === 'string') { msg = err; } console.error(`Copy failed: ${msg}`); throw new Error(`Failed to copy ${this.modelName} to sandbox: ${msg}`); } } build() { Flex({ direction: FlexDirection.Column }) { Row(){ ContentSlot(this.nodeContent); }.layoutWeight(1) } .width('100%') .height('100%'); } }