From 6a4e702dbd3f318458f3592aeebd83d6a7d4be05 Mon Sep 17 00:00:00 2001 From: JackLee <809262979@qq.com> Date: Sun, 22 Mar 2026 22:38:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A7=86=E5=9B=BE=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=8A=9F=E8=83=BD,=E4=BD=86=E6=98=AF=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=BD=92=E4=B8=80=E5=8C=96=E6=93=8D=E4=BD=9C.=20?= =?UTF-8?q?=E7=9B=AE=E5=89=8D=E5=8F=AA=E6=98=AF=E5=AE=9E=E7=8E=B0=E4=BA=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD.=E9=9C=80=E8=A6=81=E5=AF=B9=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E4=B8=96=E7=95=8C=E5=9D=90=E6=A0=87=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=A0=87=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 1 + entry/build-profile.json5 | 1 + entry/src/main/cpp/CMakeLists.txt | 2 +- .../main/cpp/NativeEGLOCCT/Camera/Camera.cpp | 84 +++++++++- .../main/cpp/NativeEGLOCCT/Camera/Camera.h | 16 +- .../main/cpp/NativeEGLOCCT/NativeManager.cpp | 145 ++++++++++++++---- .../main/cpp/NativeEGLOCCT/NativeManager.h | 16 ++ .../main/cpp/NativeEGLOCCT/NativeRender.cpp | 25 ++- .../src/main/cpp/NativeEGLOCCT/NativeRender.h | 9 ++ .../cpp/NativeEGLOCCT/NativeRenderThread.cpp | 55 ++++++- .../cpp/NativeEGLOCCT/NativeRenderThread.h | 11 +- entry/src/main/cpp/napi_init.cpp | 2 + .../src/main/cpp/types/libopencax/Index.d.ts | 3 +- .../src/main/ets/pages/CustomStyle/Dialog.ets | 6 +- .../pages/EventSubWindow/ExecuteCommand.ets | 19 +++ .../LayoutInterface/Layout/SwitchView.ets | 16 +- entry/src/main/module.json5 | 5 + 17 files changed, 369 insertions(+), 47 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 2c0b056d..cfa1bac8 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,6 +1,7 @@ { "app": { "signingConfigs": [], + "products": [ { "name": "default", diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 index 739fe627..b5eb0d92 100644 --- a/entry/build-profile.json5 +++ b/entry/build-profile.json5 @@ -10,6 +10,7 @@ ] } }, + "buildOptionSet": [ { "name": "release", diff --git a/entry/src/main/cpp/CMakeLists.txt b/entry/src/main/cpp/CMakeLists.txt index c3eeb710..1cfb2007 100644 --- a/entry/src/main/cpp/CMakeLists.txt +++ b/entry/src/main/cpp/CMakeLists.txt @@ -63,7 +63,7 @@ find_library(GLES-lib GLESv3) #System so set(SYSTEM_LIBS libace_napi.z.so libnative_window.so libnative_display_manager.so - hilog_ndk.z ace_ndk.z uv z + hilog_ndk.z ace_ndk.z libohinput.so uv z ) # 链接系统库 diff --git a/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.cpp b/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.cpp index 1c6b8b61..4954ccaf 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.cpp @@ -12,16 +12,96 @@ namespace NativeOpenCAX { -bool InitCamera(RenderOption& opt) { +bool InitCamera(RenderOption &opt) { if (opt.camera.IsNull()) { // 设置相机参数 opt.camera = opt.view->Camera(); opt.camera->SetFOVy(45.0); // 使用正确的FOV设置API opt.camera->SetZRange(1.0, 1000.0); - HILOG_INFO(NATIVE_TAG,"InitCamera Done"); + HILOG_INFO(NATIVE_TAG, "InitCamera Done"); return true; } return false; } + +// 主视图 (Front View) +void FrontView(RenderOption &opt) { + opt.view->SetProj(V3d_XposYposZneg); // 先设置坐标系,Y向上是常用选择 + opt.view->SetAt(0, 0, 0); // 设置目标点为中心 + opt.view->SetEye(0, 0, 1); + opt.view->FitAll(); + opt.view->Redraw(); +} + +// 俯视图 (Top View) +void TopView(RenderOption &opt) { + opt.view->SetProj(V3d_XposYnegZpos); + opt.view->SetAt(0, 0, 0); + opt.view->SetEye(0, -1, 0); + opt.view->FitAll(); + opt.view->Redraw(); +} + +// 左视图 (Left View) +// 观察方向为 -X, Z轴向上 +void LeftSideView(RenderOption &opt) { + opt.view->SetProj(V3d_XnegYnegZpos); + opt.view->SetAt(0, 0, 0); + opt.view->SetEye(1, 0, 0); // 从 X 轴正方向向左看 + opt.view->FitAll(); + opt.view->Redraw(); +} + +// 右视图 (Right View) +// 观察方向为 +X, Z轴向上 +void RightSideView(RenderOption &opt) { + opt.view->SetProj(V3d_XposYnegZpos); + opt.view->SetAt(0, 0, 0); + opt.view->SetEye(-1, 0, 0); // 从 X 轴负方向向右看 + opt.view->FitAll(); + opt.view->Redraw(); +} + +// 仰视图 (Bottom View) +// 观察方向为 +Y, Z轴向上 +void BottomView(RenderOption &opt) { + opt.view->SetProj(V3d_XposYposZpos); + opt.view->SetAt(0, 0, 0); + opt.view->SetEye(0, 1, 0); + opt.view->FitAll(); + opt.view->Redraw(); +} + +// 后视图 (Back View) +// 观察方向为 +Z, Y轴向上 +void RearView(RenderOption &opt) { + opt.view->SetProj(V3d_XnegYposZpos); + opt.view->SetAt(0, 0, 0); + opt.view->SetEye(0, 0, -1); // 从 Z 轴负方向向前看 + opt.view->FitAll(); + opt.view->Redraw(); +} + +// 正等轴测图 (Isometric View) +void ISOView(RenderOption &opt) { + opt.view->SetProj(V3d_XposYposZpos); // 先重置一个标准方向作为参考 + opt.view->SetAt(0, 0, 0); // 观察目标点 + // 经典的等轴测视角,从 (1, 1, 1) 方向看过去 + double dist = 1000.0; // 距离,影响缩放 + opt.view->SetEye(dist, dist, dist); + // 为了美观,通常还需要将视角调整为框满模型 + opt.view->FitAll(); + opt.view->Redraw(); +} + +// 正二等轴测图 (Diametric View) +void DIMView(RenderOption &opt) { + opt.view->SetAt(0, 0, 0); + double dist = 1000.0; + opt.view->SetEye(-dist, -dist, dist * 0.5); + opt.view->FitAll(); + opt.view->Redraw(); +} + void ChangeCarmera() {} } \ No newline at end of file diff --git a/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.h b/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.h index 6ca2884f..2b5281fa 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.h +++ b/entry/src/main/cpp/NativeEGLOCCT/Camera/Camera.h @@ -9,10 +9,18 @@ #include "../RenderStruct.h" -namespace NativeOpenCAX{ +namespace NativeOpenCAX { -bool InitCamera(RenderOption& opt); +bool InitCamera(RenderOption &opt); void ChangeCamera(); -} +void FrontView(RenderOption &opt); +void TopView(RenderOption &opt); +void LeftSideView(RenderOption &opt); +void RightSideView(RenderOption &opt); +void BottomView(RenderOption &opt); +void RearView(RenderOption &opt); +void ISOView(RenderOption &opt); +void DIMView(RenderOption &opt); +} // namespace NativeOpenCAX -#endif //OPENCAX_CAMERA_H +#endif // OPENCAX_CAMERA_H diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp index 5b3e113c..47c87f7c 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.cpp @@ -17,6 +17,7 @@ #ifndef NATIVE_TAG #define NATIVE_TAG "NativeManager" #endif +#include "arkui/ui_input_event.h" namespace NativeOpenCAX { // [Start plugin_manager_cpp] @@ -31,13 +32,13 @@ ArkUI_NativeNodeAPI_1 *nodeAPI = reinterpret_cast( NativeManager NativeManager::pluginManager_; OH_NativeXComponent_Callback NativeManager::xSurfaceTouchEventCallBack; OH_NativeXComponent_MouseEvent_Callback NativeManager::xMouseEventCallBack; + std::string comId; std::string nodeId; int32_t NativeManager::hasDraw_ = 0; int32_t NativeManager::hasChangeColor_ = 0; static std::map> renderThreadMap; static std::mutex mapMutex; - NativeManager::~NativeManager() { OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", "~NativeManager"); @@ -140,6 +141,7 @@ void NativeManager::OnSurfaceCreated(OH_NativeXComponent *component, void *windo "ERROR: window is NULL in OnSurfaceCreated!"); return; } + OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_); int64_t id = 0; std::lock_guard lock(mapMutex); @@ -162,7 +164,7 @@ void NativeManager::OnSurfaceDestroyed(OH_NativeXComponent *component, void *win } void NativeManager::OnSurfaceChanged(OH_NativeXComponent *component, void *window) { OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_); - + int64_t id = 0; { std::lock_guard lock(mapMutex); @@ -191,16 +193,28 @@ void OnMouseEventCB(OH_NativeXComponent* component, void* window) { auto *pluginManger = NativeManager::GetInstance(); pluginManger->OnMouseEvent(component, window); } -void NativeManager::OnMouseEvent(OH_NativeXComponent *component, void *window) { - OH_NativeXComponent_MouseEvent event; +void NativeManager::OnMouseEvent(OH_NativeXComponent *comp, void *win) { int32_t ret; - ret=OH_NativeXComponent_GetMouseEvent(component, window, &event); - std::lock_guard lock(mapMutex); - //通过时间戳判断事件唯一性.保证单一时间戳只触发一次事件 - if(event.timestamp==NativeManager::timestamp){ + OH_NativeXComponent_MouseEvent mouseEvent; + ret = OH_NativeXComponent_GetMouseEvent(comp, win, &mouseEvent); + if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { return; } - NativeManager::timestamp=event.timestamp; + OH_NativeXComponent_ExtraMouseEventInfo* extra = NULL; + + ret = OH_NativeXComponent_GetExtraMouseEventInfo(comp, &extra); + + if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + return; + } + //Test Mouse MIDDLE_BUTTON Long Press + //HILOG_WARN(NATIVE_TAG, "ExtraMouseEventInfo:%{public}s",extra); + std::lock_guard lock(mapMutex); + //通过时间戳判断事件唯一性.保证单一时间戳只触发一次事件 + if(mouseEvent.timestamp==NativeManager::timestamp){ + return; + } + NativeManager::timestamp=mouseEvent.timestamp; int64_t id = 0; auto it = renderThreadMap.find(id); if (it == renderThreadMap.end()) { @@ -209,25 +223,27 @@ void NativeManager::OnMouseEvent(OH_NativeXComponent *component, void *window) { } auto renderThread = it->second; float curtX,curtY; - HILOG_WARN(NATIVE_TAG, "ALLButton:%{public}d",event.button); - HILOG_WARN(NATIVE_TAG, "ALLAction:%{public}d",event.action); - HILOG_WARN(NATIVE_TAG, "ALLTimestamp:%{public}d",event.timestamp); + //HILOG_WARN(NATIVE_TAG, "ALLButton:%{public}d",mouseEvent.button); + //HILOG_WARN(NATIVE_TAG, "ALLAction:%{public}d",mouseEvent.action); + //HILOG_WARN(NATIVE_TAG, "ALLTimestamp:%{public}d",mouseEvent.timestamp); + + //鼠标按下并且事件为鼠标中键 - if(event.button==OH_NATIVEXCOMPONENT_LEFT_BUTTON&&event.action==OH_NATIVEXCOMPONENT_MOUSE_PRESS){ + if(mouseEvent.button==OH_NATIVEXCOMPONENT_LEFT_BUTTON&&mouseEvent.action==OH_NATIVEXCOMPONENT_MOUSE_PRESS){ if(NativeManager::isMouseMiddleBtnPressed){ NativeManager::isMouseMiddleBtnPressed=false; return; } //记录按下时候的X.Y坐标 - NativeManager::lastMouseX_=event.x; - NativeManager::lastMouseY_=event.y; + NativeManager::lastMouseX_=mouseEvent.x; + NativeManager::lastMouseY_=mouseEvent.y; NativeManager::isMouseMiddleBtnPressed = true; - HILOG_WARN(NATIVE_TAG, "AtlastMouseX:%{public}d",NativeManager::lastMouseX_); - HILOG_WARN(NATIVE_TAG, "AtlastMouseY:%{public}d",NativeManager::lastMouseY_); - HILOG_WARN(NATIVE_TAG, "AtButton:%{public}d",event.button); - HILOG_WARN(NATIVE_TAG, "AtButtonAction:%{public}d",event.action); - HILOG_WARN(NATIVE_TAG, "AtisMouseMiddleBtnPressed:%{public}d",NativeManager::isMouseMiddleBtnPressed); - }else if(event.action==OH_NATIVEXCOMPONENT_MOUSE_MOVE&&NativeManager::isMouseMiddleBtnPressed){ + //HILOG_WARN(NATIVE_TAG, "AtlastMouseX:%{public}d",NativeManager::lastMouseX_); + //HILOG_WARN(NATIVE_TAG, "AtlastMouseY:%{public}d",NativeManager::lastMouseY_); + //HILOG_WARN(NATIVE_TAG, "AtButton:%{public}d",mouseEvent.button); + //HILOG_WARN(NATIVE_TAG, "AtButtonAction:%{public}d",mouseEvent.action); + //HILOG_WARN(NATIVE_TAG, "AtisMouseMiddleBtnPressed:%{public}d",NativeManager::isMouseMiddleBtnPressed); + }else if(mouseEvent.action==OH_NATIVEXCOMPONENT_MOUSE_MOVE&&NativeManager::isMouseMiddleBtnPressed){ // 计算鼠标移动距离 float deltaX = curtX - NativeManager::lastMouseX_; float deltaY = curtY - NativeManager::lastMouseY_; @@ -242,11 +258,11 @@ void NativeManager::OnMouseEvent(OH_NativeXComponent *component, void *window) { // 更新最后的位置 //NativeManager::lastMouseX_ = deltaX; //NativeManager::lastMouseY_ = deltaY; - HILOG_WARN(NATIVE_TAG, "MoveAngleX:%{public}d",angleX); - HILOG_WARN(NATIVE_TAG, "MoveAngleY:%{public}d",angleY); - 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); + //HILOG_WARN(NATIVE_TAG, "MoveAngleX:%{public}d",angleX); + //HILOG_WARN(NATIVE_TAG, "MoveAngleY:%{public}d",angleY); + //HILOG_WARN(NATIVE_TAG, "MoveButton:%{public}d",mouseEvent.button); + //HILOG_WARN(NATIVE_TAG, "MoveButtonAction:%{public}d",mouseEvent.action); + //HILOG_WARN(NATIVE_TAG, "MoveIsMouseMiddleBtnPressed:%{public}d",NativeManager::isMouseMiddleBtnPressed); } } @@ -258,6 +274,16 @@ static std::string value2String(napi_env env, napi_value value) { napi_get_value_string_utf8(env, value, &valueString[0], stringSize + 1, &stringSize); return valueString; } +struct AxisEvent { + int32_t axisAction; + float displayX; + float displayY; + std::map axisValues; + int64_t actionTime { -1 }; + int32_t sourceType; + int32_t axisEventType { -1 }; +}; + // XComponent回调事件 NativeManager::NativeManager() { xSurfaceTouchEventCallBack.OnSurfaceCreated = OnSurfaceCreatedCB; @@ -313,6 +339,43 @@ ArkUI_NodeHandle CreateNodeHandle(const std::string &tag) { OH_NativeXComponent_RegisterCallback(nativeXComponent, &NativeManager::xSurfaceTouchEventCallBack); //注册XComponent组件鼠标回调事件 OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent, &NativeManager::xMouseEventCallBack); +// nodeAPI->registerNodeEvent(xc, NODE_ON_MOUSE, 1, &xc); +// nodeAPI->registerNodeEvent(xc, NODE_ON_AXIS, 1, &xc); +// nodeAPI->addNodeEventReceiver(xc, [](ArkUI_NodeEvent *event) { +// auto *inputEvent = OH_ArkUI_NodeEvent_GetInputEvent(event); +// auto eventType = OH_ArkUI_UIInputEvent_GetType(inputEvent); +// if (OH_ArkUI_NodeEvent_GetEventType(event) == NODE_ON_AXIS ) { +// HILOG_WARN(NATIVE_TAG, "NODE_ON_AXIS:%{public}d",OH_ArkUI_NodeEvent_GetEventType(event)); +// } +// if (eventType == ARKUI_UIINPUTEVENT_TYPE_MOUSE) { +// auto action = OH_ArkUI_MouseEvent_GetMouseAction(inputEvent); +// auto button= OH_ArkUI_MouseEvent_GetMouseButton(inputEvent); +// //HILOG_WARN(NATIVE_TAG, "MouseAction:%{public}d",action); +// //HILOG_WARN(NATIVE_TAG, "MouseButton:%{public}d",button); +// +// int32_t buttonArray[10]; +// int32_t arraySize = sizeof(buttonArray) / sizeof(buttonArray[0]); +// int32_t actualCount = arraySize; // 将数组大小存入actualCount,作为输入值 +// int32_t ret = OH_ArkUI_MouseEvent_GetPressedButtons(inputEvent, buttonArray, &actualCount); +// +// // --- 步骤 3: 检查API调用结果 --- +// if (ret != 0) { +// HILOG_WARN(NATIVE_TAG, "Error getting pressed mouse buttons. Error code: %{public}d\n", ret); +// return; +// } +// for (int i = 0; i < actualCount; ++i) { +// HILOG_WARN(NATIVE_TAG, "Curt code: %{public}d\n", buttonArray[i]); +// // 根据常见的鼠标按钮ID进行解释 (具体ID定义请查阅官方文档) +// // 通常 1=主按钮(左键), 2=辅助按钮(右键), 3=中间按钮(滚轮) +// switch (buttonArray[i]) { +// case 1: HILOG_WARN(NATIVE_TAG, "MouseButton:Left");break; +// case 2: HILOG_WARN(NATIVE_TAG, "MouseButton:Right");break; +// case 3: HILOG_WARN(NATIVE_TAG, "MouseButton:Middle"); break; +// default: printf("(Other_%d) ", buttonArray[i]); break; +// } +// } +// } +// }); // 组件类型 auto comTypeRet = nodeAPI->getAttribute(xc, NODE_XCOMPONENT_TYPE); HILOG_INFO(NATIVE_TAG,"XCom type: %{public}d",comTypeRet->value[0].i32); @@ -424,4 +487,34 @@ napi_value NativeManager::NapiLoadModel(napi_env env, napi_callback_info info) { } return nullptr; } + +//切换视图 +napi_value NativeManager::SwitchView(napi_env env, napi_callback_info info){ + size_t argc = 1; + napi_value args[1]; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + std::string viewName = value2String(env, args[0]); + int64_t id = 0; + { + std::lock_guard lock(mapMutex); + if (renderThreadMap.find(id) != renderThreadMap.end()) { + renderThreadMap[id]->swicthView(viewName); + } + } + return nullptr; +} + +//显示模型边界 +napi_value NativeManager::displayModelEdges(napi_env env, napi_callback_info info){ + +} +//显示模型线框 +napi_value NativeManager::displayHLR(napi_env env, napi_callback_info info){ + +} +//显示隐藏线 +napi_value NativeManager::displayHL(napi_env env, napi_callback_info info){ + +} + } // namespace NativeOpenCAX diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.h b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.h index 694c73ee..96f03645 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeManager.h +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeManager.h @@ -27,6 +27,12 @@ #include "arkui/native_node_napi.h" #include "NativeRenderThread.h" +#include "arkui/ui_input_event.h" +#include +#include +#include +#include + namespace NativeOpenCAX { constexpr const int FIRST_ARG = 1; @@ -41,6 +47,7 @@ public: static OH_NativeXComponent_Callback xSurfaceTouchEventCallBack; //鼠标事件回调 static OH_NativeXComponent_MouseEvent_Callback xMouseEventCallBack; + NativeManager(); ~NativeManager(); @@ -52,6 +59,15 @@ public: static napi_value SetFrameRate(napi_env env, napi_callback_info info); static napi_value SetNeedSoftKeyboard(napi_env env, napi_callback_info info); static napi_value NapiLoadModel(napi_env env, napi_callback_info info); + //切换视图 + static napi_value SwitchView(napi_env env, napi_callback_info info); + //显示模型边界 + static napi_value displayModelEdges(napi_env env, napi_callback_info info); + //显示模型线框 + static napi_value displayHLR(napi_env env, napi_callback_info info); + //显示隐藏线 + static napi_value displayHL(napi_env env, napi_callback_info info); + // CApi XComponent void OnSurfaceChanged(OH_NativeXComponent* component, void* window); void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp index 28541f8d..227a6ab4 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp @@ -235,5 +235,28 @@ void NativeRender::setClearColor(float r, float g, float b, float a) { rendOption.view->SetBackgroundColor(rendOption.clearColor); } } - +void NativeRender::SetFrontView(){ + FrontView(rendOption); +} +void NativeRender::SetTopView(){ + TopView(rendOption); +} +void NativeRender::SetLeftSideView(){ + LeftSideView(rendOption); +} +void NativeRender::SetRightSideView(){ + RightSideView(rendOption); +} +void NativeRender::SetBottomView(){ + BottomView(rendOption); +} +void NativeRender::SetRearView(){ + RearView(rendOption); +} +void NativeRender::SetISOView(){ + ISOView(rendOption); +} +void NativeRender::SetDIMView(){ + DIMView(rendOption); +} } // namespace NativeRenderer \ No newline at end of file diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h index 735e1ed9..016e30c2 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h @@ -35,6 +35,15 @@ public: void setZoomLevel(float zoom); void setTranslation(float x, float y); void setCameraRotationMode(bool state); + //视图 + void SetFrontView(); + void SetTopView(); + void SetLeftSideView(); + void SetRightSideView(); + void SetBottomView(); + void SetRearView(); + void SetISOView(); + void SetDIMView(); private: RenderOption rendOption; AxisOption axis; diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp index 86eedc27..755b907e 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp @@ -98,6 +98,30 @@ void NativeRenderThread::renderLoop() { windowHeight_ = static_cast(command.param3); renderer_.resize(windowWidth_, windowHeight_); break; + case CMD_VIEW_FRONT: + renderer_.SetFrontView(); + break; + case CMD_VIEW_TOP: + renderer_.SetFrontView(); + break; + case CMD_VIEW_LEFT_SIDE: + renderer_.SetFrontView(); + break; + case CMD_VIEW_RIGHT_SIDE: + renderer_.SetFrontView(); + break; + case CMD_VIEW_BOTTOM: + renderer_.SetFrontView(); + break; + case CMD_VIEW_REAR: + renderer_.SetFrontView(); + break; + case CMD_VIEW_ISO: + renderer_.SetFrontView(); + break; + case CMD_VIEW_DIM: + renderer_.SetFrontView(); + break; case CMD_EXIT: isRunning_ = false; break; @@ -157,7 +181,36 @@ void NativeRenderThread::resetView() { commandQueue_.push(RenderCommand(CMD_RESET_VIEW)); commandCondition_.notify_one(); } - +void NativeRenderThread::swicthView(std::string strView) { + std::lock_guard lock(commandMutex_); + CommandType cmdType; + if(strView=="CMD_VIEW_FRONT"){ + cmdType=CMD_VIEW_FRONT; + } + if(strView=="CMD_VIEW_TOP"){ + cmdType=CMD_VIEW_TOP; + } + if(strView=="CMD_VIEW_LEFT_SIDE"){ + cmdType=CMD_VIEW_LEFT_SIDE; + } + if(strView=="CMD_VIEW_RIGHT_SIDE"){ + cmdType=CMD_VIEW_RIGHT_SIDE; + } + if(strView=="CMD_VIEW_BOTTOM"){ + cmdType=CMD_VIEW_BOTTOM; + } + if(strView=="CMD_VIEW_REAR"){ + cmdType=CMD_VIEW_REAR; + } + if(strView=="CMD_VIEW_ISO"){ + cmdType=CMD_VIEW_ISO; + } + if(strView=="CMD_VIEW_DIM"){ + cmdType=CMD_VIEW_DIM; + } + commandQueue_.push(RenderCommand(cmdType)); + commandCondition_.notify_one(); +} void NativeRenderThread::setClearColor(float r, float g, float b, float a) { std::lock_guard lock(commandMutex_); RenderCommand cmd(CMD_SET_CLEAR_COLOR); diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.h b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.h index 6366d359..9fc60c04 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.h +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.h @@ -27,7 +27,7 @@ public: void resetView(); void setClearColor(float r, float g, float b, float a); void resizeWindow(int width, int height); - + void swicthView(std::string strView); using Callback = std::function; void registerRenderCompleteCallback(Callback callback); @@ -51,6 +51,15 @@ private: CMD_RESET_VIEW, CMD_SET_CLEAR_COLOR, CMD_RESIZE, + //视图枚举 + CMD_VIEW_FRONT, + CMD_VIEW_TOP, + CMD_VIEW_LEFT_SIDE, + CMD_VIEW_RIGHT_SIDE, + CMD_VIEW_BOTTOM, + CMD_VIEW_REAR, + CMD_VIEW_ISO, + CMD_VIEW_DIM, CMD_EXIT }; diff --git a/entry/src/main/cpp/napi_init.cpp b/entry/src/main/cpp/napi_init.cpp index 82a7e3c3..3e3bbd12 100644 --- a/entry/src/main/cpp/napi_init.cpp +++ b/entry/src/main/cpp/napi_init.cpp @@ -45,6 +45,8 @@ static napi_value Init(napi_env env, napi_value exports) { {"setFrameRate", nullptr, NativeManager::SetFrameRate, nullptr, nullptr, nullptr, napi_default, nullptr}, {"setNeedSoftKeyboard", nullptr, NativeManager::SetNeedSoftKeyboard, nullptr, nullptr, nullptr, napi_default,nullptr}, {"nativeLoadTest", nullptr, NativeLoadSoTest, nullptr, nullptr, nullptr, napi_default, nullptr}, + //切换视图 + {"switchView", nullptr, NativeManager::SwitchView, nullptr, nullptr, nullptr,napi_default, nullptr }, }; napi_status status = napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); if (status != napi_ok) { diff --git a/entry/src/main/cpp/types/libopencax/Index.d.ts b/entry/src/main/cpp/types/libopencax/Index.d.ts index 2db8179c..8b4f62cb 100644 --- a/entry/src/main/cpp/types/libopencax/Index.d.ts +++ b/entry/src/main/cpp/types/libopencax/Index.d.ts @@ -3,4 +3,5 @@ export interface NativeXOpenCAX { setNeedSoftKeyboard(nodeId: string, need: boolean): void; } export function createNativeNode(nodeContent: any): void; -export function loadModel(stepFilePath: string): void; \ No newline at end of file +export function loadModel(stepFilePath: string): void; +export function switchView(viewName: string): void; \ No newline at end of file diff --git a/entry/src/main/ets/pages/CustomStyle/Dialog.ets b/entry/src/main/ets/pages/CustomStyle/Dialog.ets index 40e9f311..3d44c8f5 100644 --- a/entry/src/main/ets/pages/CustomStyle/Dialog.ets +++ b/entry/src/main/ets/pages/CustomStyle/Dialog.ets @@ -1,4 +1,5 @@ import { mwInfo } from "../AppStorageV2Class"; +import { ExecuteCommand } from "../EventSubWindow/ExecuteCommand"; import { TitleButton } from "../LayoutInterface/Interface/ButtonInterface"; import {SwitchView} from "../LayoutInterface/Layout/SwitchView" @@ -21,9 +22,10 @@ export struct ViewDialog { .backgroundImageSize({ width: '100%', // 图片宽度占满按钮 height: '100%' // 图片高度占满按钮 + }).width(ebWidth).height(ebWidth) + .onClick(()=>{ + ExecuteCommand(item); }) - .width(ebWidth) - .height(ebWidth) } } }) diff --git a/entry/src/main/ets/pages/EventSubWindow/ExecuteCommand.ets b/entry/src/main/ets/pages/EventSubWindow/ExecuteCommand.ets index 7dd43fb5..6622174f 100644 --- a/entry/src/main/ets/pages/EventSubWindow/ExecuteCommand.ets +++ b/entry/src/main/ets/pages/EventSubWindow/ExecuteCommand.ets @@ -1,6 +1,7 @@ import { TitleButton } from '../LayoutInterface/Interface/ButtonInterface'; import { OCCTLoadModel } from '../modelView'; import { CloseSubWindow, CreateAndShowSubWindow} from './SWBase'; +import NativeOpenCAX from 'libopencax.so'; export function ExecuteCommand(event:TitleButton){ if(event?.eEvent=='Execute_LoadModel'){ @@ -10,4 +11,22 @@ export function ExecuteCommand(event:TitleButton){ }else if(event?.eEvent=='Execute_ExitSubWindow'){ CloseSubWindow(); } + + if(event?.eEvent=='CMD_VIEW_FRONT'){ + NativeOpenCAX.switchView("CMD_VIEW_FRONT"); + }else if(event?.eEvent=='CMD_VIEW_TOP'){ + NativeOpenCAX.switchView("CMD_VIEW_TOP"); + }else if(event?.eEvent=='CMD_VIEW_LEFT_SIDE'){ + NativeOpenCAX.switchView("CMD_VIEW_LEFT_SIDE"); + }else if(event?.eEvent=='CMD_VIEW_RIGHT_SIDE'){ + NativeOpenCAX.switchView("CMD_VIEW_RIGHT_SIDE"); + }else if(event?.eEvent=='CMD_VIEW_BOTTOM'){ + NativeOpenCAX.switchView("CMD_VIEW_BOTTOM"); + }else if(event?.eEvent=='CMD_VIEW_REAR'){ + NativeOpenCAX.switchView("CMD_VIEW_REAR"); + }else if(event?.eEvent=='CMD_VIEW_ISO'){ + NativeOpenCAX.switchView("CMD_VIEW_ISO"); + }else if(event?.eEvent=='CMD_VIEW_DIM'){ + NativeOpenCAX.switchView("CMD_VIEW_DIM"); + } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/LayoutInterface/Layout/SwitchView.ets b/entry/src/main/ets/pages/LayoutInterface/Layout/SwitchView.ets index 14997761..c67f9326 100644 --- a/entry/src/main/ets/pages/LayoutInterface/Layout/SwitchView.ets +++ b/entry/src/main/ets/pages/LayoutInterface/Layout/SwitchView.ets @@ -3,14 +3,14 @@ import { ModelType } from "./ModelType"; //视图选择布局数据 export let SwitchView:Array=[ - {eModel:[ModelType.BASE],eName:"正三轴测图",eNamed:"",ePage:'',eIcon:"base_view_tfr_tri",eTips:"正三轴测图",eEvent:""}, - {eModel:[ModelType.BASE],eName:"俯视图",eNamed:"",ePage:'',eIcon:"base_view_top",eTips:"俯视图",eEvent:""}, - {eModel:[ModelType.BASE],eName:"正等测图",eNamed:"",ePage:'',eIcon:"base_view_tfr_iso",eTips:"正等测图",eEvent:""}, + {eModel:[ModelType.BASE],eName:"正二轴测图",eNamed:"",ePage:'',eIcon:"base_view_tfr_tri",eTips:"正二轴测图",eEvent:"CMD_VIEW_DIM"}, + {eModel:[ModelType.BASE],eName:"俯视图",eNamed:"",ePage:'',eIcon:"base_view_top",eTips:"俯视图",eEvent:"CMD_VIEW_TOP"}, + {eModel:[ModelType.BASE],eName:"正等测图",eNamed:"",ePage:'',eIcon:"base_view_tfr_iso",eTips:"正等测图",eEvent:"CMD_VIEW_ISO"}, - {eModel:[ModelType.BASE],eName:"左视图",eNamed:"",ePage:'',eIcon:"base_view_left",eTips:"左视图",eEvent:""}, - {eModel:[ModelType.BASE],eName:"前视图",eNamed:"",ePage:'',eIcon:"base_view_front",eTips:"前视图",eEvent:""}, - {eModel:[ModelType.BASE],eName:"右视图",eNamed:"",ePage:'',eIcon:"base_view_right",eTips:"右视图",eEvent:""}, + {eModel:[ModelType.BASE],eName:"左视图",eNamed:"",ePage:'',eIcon:"base_view_left",eTips:"左视图",eEvent:"CMD_VIEW_LEFT_SIDE"}, + {eModel:[ModelType.BASE],eName:"前视图",eNamed:"",ePage:'',eIcon:"base_view_front",eTips:"前视图",eEvent:"CMD_VIEW_FRONT"}, + {eModel:[ModelType.BASE],eName:"右视图",eNamed:"",ePage:'',eIcon:"base_view_right",eTips:"右视图",eEvent:"CMD_VIEW_RIGHT_SIDE"}, - {eModel:[ModelType.BASE],eName:"后视图",eNamed:"",ePage:'',eIcon:"base_view_back",eTips:"后视图",eEvent:""}, - {eModel:[ModelType.BASE],eName:"仰视图",eNamed:"",ePage:'',eIcon:"base_view_bottom",eTips:"仰视图",eEvent:""}, + {eModel:[ModelType.BASE],eName:"后视图",eNamed:"",ePage:'',eIcon:"base_view_back",eTips:"后视图",eEvent:"CMD_VIEW_REAR"}, + {eModel:[ModelType.BASE],eName:"仰视图",eNamed:"",ePage:'',eIcon:"base_view_bottom",eTips:"仰视图",eEvent:"CMD_VIEW_BOTTOM"}, ] \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index ccea7ace..f42cd37d 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -10,6 +10,11 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + "requestPermissions": [ + { + "name": "ohos.permission.INPUT_MONITORING" + } + ], "abilities": [ { "name": "EntryAbility",