From ecae5dca40996bcf97056d60f9a1df2a38dde7b0 Mon Sep 17 00:00:00 2001 From: JackLee <809262979@qq.com> Date: Thu, 12 Mar 2026 17:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=8F=91=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/cpp/NativeEGLOCCT/NativeManager.cpp | 9 ++--- .../src/main/ets/pages/CustomStyle/Button.ets | 6 +++ entry/src/main/ets/pages/ExecuteCommand.ets | 6 +++ .../ets/pages/LayoutInterface/Layout/CAD.ets | 5 ++- .../ets/pages/LayoutInterface/Layout/CAE.ets | 5 ++- .../ets/pages/LayoutInterface/Layout/CAM.ets | 7 +++- .../pages/LayoutInterface/Layout/MainPage.ets | 5 ++- .../LayoutInterface/Layout/MatrixModel.ets | 8 ++++ .../pages/TitleTabLayout/TitleTabContent.ets | 2 +- entry/src/main/ets/pages/modelView.ets | 38 ++++++++++--------- 10 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 entry/src/main/ets/pages/ExecuteCommand.ets diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp index 15e6e50d..c0257ce5 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp @@ -214,6 +214,9 @@ void NativeManager::OnMouseEvent(OH_NativeXComponent *component, void *window) { HILOG_WARN(NATIVE_TAG, "ALLTimestamp:%{public}d",event.timestamp); //鼠标按下并且事件为鼠标中键 if(event.button==OH_NATIVEXCOMPONENT_LEFT_BUTTON&&event.action==OH_NATIVEXCOMPONENT_MOUSE_PRESS){ + if(NativeManager::isMouseMiddleBtnPressed){ + NativeManager::isMouseMiddleBtnPressed=false; + } //记录按下时候的X.Y坐标 NativeManager::lastMouseX_=event.x; NativeManager::lastMouseY_=event.y; @@ -243,11 +246,7 @@ void NativeManager::OnMouseEvent(OH_NativeXComponent *component, void *window) { HILOG_WARN(NATIVE_TAG, "MoveButton:%{public}d",event.button); HILOG_WARN(NATIVE_TAG, "MoveButtonAction:%{public}d",event.action); HILOG_WARN(NATIVE_TAG, "MoveIsMouseMiddleBtnPressed:%{public}d",NativeManager::isMouseMiddleBtnPressed); - } - else if(event.button==OH_NATIVEXCOMPONENT_LEFT_BUTTON&&event.action==OH_NATIVEXCOMPONENT_MOUSE_RELEASE){ - //NativeManager::isMouseMiddleBtnPressed = false; - HILOG_WARN(NATIVE_TAG, "ReleaseIsMouseMiddleBtnPressed:%{public}d",NativeManager::isMouseMiddleBtnPressed); - } + } } static std::string value2String(napi_env env, napi_value value) { diff --git a/entry/src/main/ets/pages/CustomStyle/Button.ets b/entry/src/main/ets/pages/CustomStyle/Button.ets index 204b3b15..9270ea35 100644 --- a/entry/src/main/ets/pages/CustomStyle/Button.ets +++ b/entry/src/main/ets/pages/CustomStyle/Button.ets @@ -2,6 +2,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { TitleButton } from "../LayoutInterface/Interface/ButtonInterface"; import { TitleModel } from "../LayoutInterface/Interface/ModelInterface"; import { TitleData } from '../LayoutInterface/Layout/TabContent'; +import { OCCTLoadModel } from '../modelView'; //单一功能按钮 //图片->文本 @@ -22,6 +23,11 @@ export struct EventBtn { width: '80%', // 图片宽度占满按钮 height: '80%' // 图片高度占满按钮 }) + .onClick(()=>{ + if(this.eventBtn?.eEvent=='Execute_LoadModel'){ + OCCTLoadModel(undefined,undefined) + } + }) Text(this.eventBtn.eName) .fontSize('10fp') .width('45vp') diff --git a/entry/src/main/ets/pages/ExecuteCommand.ets b/entry/src/main/ets/pages/ExecuteCommand.ets new file mode 100644 index 00000000..9cb90f11 --- /dev/null +++ b/entry/src/main/ets/pages/ExecuteCommand.ets @@ -0,0 +1,6 @@ +import { OCCTLoadModel } from './modelView'; + +//该ets是一个映射指令表.主要是功能得Event事件和对应实现函数进行映射. +//要求Event的事件名必须与该事件对应实现功能的函数名一致. +// 定义一个函数类型别名,表示无参数无返回值的函数 +//ActionMap相当于一个Event的事件列表和函数连接器 diff --git a/entry/src/main/ets/pages/LayoutInterface/Layout/CAD.ets b/entry/src/main/ets/pages/LayoutInterface/Layout/CAD.ets index e32aa183..10a1128b 100644 --- a/entry/src/main/ets/pages/LayoutInterface/Layout/CAD.ets +++ b/entry/src/main/ets/pages/LayoutInterface/Layout/CAD.ets @@ -3,7 +3,7 @@ import {TitleMainPage} from './MainPage' import {ModelType} from './ModelType' import { GroupOption } from "./GroupOption"; import { TitleGroup } from "../Interface/GroupInterface"; -import { MatrixModel } from "./MatrixModel"; +import { MatrixModel ,DevModel} from "./MatrixModel"; export let TitleCAD:Array=[ TitleMainPage[0], @@ -98,5 +98,6 @@ export let TitleCAD:Array=[ ],grpMenu:GroupOption}] as Array ] ]}, - MatrixModel + MatrixModel, + DevModel ] \ No newline at end of file diff --git a/entry/src/main/ets/pages/LayoutInterface/Layout/CAE.ets b/entry/src/main/ets/pages/LayoutInterface/Layout/CAE.ets index 8b889173..9d2e4d6b 100644 --- a/entry/src/main/ets/pages/LayoutInterface/Layout/CAE.ets +++ b/entry/src/main/ets/pages/LayoutInterface/Layout/CAE.ets @@ -3,7 +3,7 @@ import {TitleMainPage} from './MainPage' import {ModelType} from './ModelType' import { GroupOption } from "./GroupOption"; import { TitleGroup } from "../Interface/GroupInterface"; -import { MatrixModel } from "./MatrixModel"; +import { MatrixModel ,DevModel} from "./MatrixModel"; import { TitleButton } from "../Interface/ButtonInterface"; export let TitleCAE:Array=[ @@ -27,5 +27,6 @@ export let TitleCAE:Array=[ ],grpMenu:GroupOption}] as Array ] ]}, - MatrixModel + MatrixModel, + DevModel ] \ No newline at end of file diff --git a/entry/src/main/ets/pages/LayoutInterface/Layout/CAM.ets b/entry/src/main/ets/pages/LayoutInterface/Layout/CAM.ets index 4442af9b..e0318df0 100644 --- a/entry/src/main/ets/pages/LayoutInterface/Layout/CAM.ets +++ b/entry/src/main/ets/pages/LayoutInterface/Layout/CAM.ets @@ -3,7 +3,7 @@ import {TitleMainPage} from './MainPage' import {ModelType} from './ModelType' import { GroupOption } from "./GroupOption"; import { TitleGroup } from "../Interface/GroupInterface"; -import { MatrixModel } from "./MatrixModel"; +import { MatrixModel,DevModel } from "./MatrixModel"; import { TitleButton } from "../Interface/ButtonInterface"; export let TitleCAM:Array=[TitleMainPage[0], @@ -24,4 +24,7 @@ export let TitleCAM:Array=[TitleMainPage[0], {eModel:[ModelType.BASE],eName:"帮助",eNamed:"",eIcon:"base_help_file",eTips:"",eEvent:""}, ],grpMenu:GroupOption}] as Array ] - ]},MatrixModel] \ No newline at end of file + ]}, + MatrixModel, + DevModel +] \ No newline at end of file diff --git a/entry/src/main/ets/pages/LayoutInterface/Layout/MainPage.ets b/entry/src/main/ets/pages/LayoutInterface/Layout/MainPage.ets index 70569afb..36db30fc 100644 --- a/entry/src/main/ets/pages/LayoutInterface/Layout/MainPage.ets +++ b/entry/src/main/ets/pages/LayoutInterface/Layout/MainPage.ets @@ -1,6 +1,6 @@ import { TitleButton } from "../Interface/ButtonInterface"; import { TitleGroup } from "../Interface/GroupInterface"; -import { MatrixModel } from "./MatrixModel"; +import { DevModel, MatrixModel } from "./MatrixModel"; import { ModelType } from "./ModelType"; import { GroupOption } from "./GroupOption"; import { TitleModel } from "./TabContent"; @@ -22,5 +22,6 @@ export let TitleMainPage:Array= {eModel:[ModelType.BASE],eName:"帮助",eNamed:"",eIcon:"base_help_file",eTips:"",eEvent:""}, ], grpMenu:GroupOption}] as Array]]}, - MatrixModel + MatrixModel, + DevModel ] diff --git a/entry/src/main/ets/pages/LayoutInterface/Layout/MatrixModel.ets b/entry/src/main/ets/pages/LayoutInterface/Layout/MatrixModel.ets index 7110a9ec..6415f096 100644 --- a/entry/src/main/ets/pages/LayoutInterface/Layout/MatrixModel.ets +++ b/entry/src/main/ets/pages/LayoutInterface/Layout/MatrixModel.ets @@ -12,4 +12,12 @@ export let MatrixModel:TitleModel= { {eModel:[ModelType.BASE],eName:"仿真",eNamed:"",eIcon:"base_save_file",eTips:"",eEvent:"Switch_Model_CAE"}, ],grpMenu:GroupOption}] as Array ]] +} +//模块矩阵布局数据 +export let DevModel:TitleModel= { + cmName:"开发模式",cmPage:"",cmTips:"",cmEvents:[ + [[{grpName:'工具矩阵',grpBtn:[ + {eModel:[ModelType.BASE],eName:"加载模型",eNamed:"",eIcon:"base_new_file",eTips:"",eEvent:"Execute_LoadModel"}, + ],grpMenu:GroupOption}] as Array + ]] } \ No newline at end of file diff --git a/entry/src/main/ets/pages/TitleTabLayout/TitleTabContent.ets b/entry/src/main/ets/pages/TitleTabLayout/TitleTabContent.ets index 0a6bea31..c3027ed1 100644 --- a/entry/src/main/ets/pages/TitleTabLayout/TitleTabContent.ets +++ b/entry/src/main/ets/pages/TitleTabLayout/TitleTabContent.ets @@ -30,7 +30,7 @@ export struct TitleTabContent { MenuBtn({menuBtn:btn_item}) }else{ //针对最后一个Bar特化处理.如果为最后一个Bar则在子组件Image真假onClick事件 - if(mIndex==this.tabLayout.length-1){ + if(mIndex==this.tabLayout.length-2){ SwitchModelBtn({eventBtn:btn_item}) }else{ EventBtn({eventBtn:btn_item}) diff --git a/entry/src/main/ets/pages/modelView.ets b/entry/src/main/ets/pages/modelView.ets index 291cd7bb..6da47ed6 100644 --- a/entry/src/main/ets/pages/modelView.ets +++ b/entry/src/main/ets/pages/modelView.ets @@ -5,16 +5,24 @@ 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 modelPath: string = ''; @State modelName:string='2027.stp'; @State currentStatus: string = 'init'; private nodeContent: NodeContent = new NodeContent(); + aboutToAppear() { NativeOpenCAX.createNativeNode(this.nodeContent); this.copyRawFileToSandbox(); @@ -22,19 +30,19 @@ export struct ModelView { async copyRawFileToSandbox() { try { const context = getContext(this); - this.modelPath = `${context.filesDir}/${this.modelName}`; + 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(this.modelPath)) { - fs.unlinkSync(this.modelPath); + if (fs.accessSync(modelPath)) { + fs.unlinkSync(modelPath); } - const fd = fileIO.openSync(this.modelPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE,0o666); + 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:', this.modelPath); + console.log('WriteModelPath:', modelPath); } catch (err) { let msg = 'Unknown error'; if (err instanceof Error) { @@ -48,21 +56,15 @@ export struct ModelView { } build() { Flex({ direction: FlexDirection.Column }) { - Row(){ - Button('加载模型').onClick(()=>{ - try { - console.info('Model copied to:', this.modelPath); - NativeOpenCAX.loadModel(this.modelPath); - } catch (e) { - hilog.error(0x0000, 'ModelView', `LoadModel Failed: ${JSON.stringify(e)}`); - } - }) - }.height('5%') Row(){ ContentSlot(this.nodeContent); }.layoutWeight(1) + .borderWidth(1) } + .borderWidth(1) .width('100%') .height('100%'); } -} \ No newline at end of file +} + +