diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp index b0e0a7d3..c9e3e495 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.cpp @@ -345,7 +345,7 @@ ArkUI_NodeHandle CreateNodeHandle(void* userData) { // 注册XComponent回调函数 OH_NativeXComponent_RegisterCallback(nativeXComponent, &NativeMgr::xSurfaceTouchEventCallBack); //注册XComponent组件鼠标回调事件 - OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent, &NativeMgr::xMouseEventCallBack); + //OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent, &NativeMgr::xMouseEventCallBack); // nodeAPI->registerNodeEvent(xc, NODE_ON_MOUSE, 1, &xc); // nodeAPI->registerNodeEvent(xc, NODE_ON_AXIS, 1, &xc); // nodeAPI->addNodeEventReceiver(xc, [](ArkUI_NodeEvent *event) { @@ -456,7 +456,19 @@ napi_value NativeMgr::initNativeNode(napi_env env, napi_callback_info info) { void NativeMgr::DispatchTouchEvent(OH_NativeXComponent* component, void* window) { + OH_NativeXComponent_TouchEvent touchEvent_; int32_t ret = OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_); + std::lock_guard lock(mapMutex); + //通过时间戳判断事件唯一性.保证单一时间戳只触发一次事件 + if(touchEvent_.timeStamp==NativeMgr::timestamp){ + return; + } + NativeMgr::timestamp=touchEvent_.timeStamp; + auto renderThread=OCCTMgr::GetInstance()->getRenderThread(crtXCompId); + if(renderThread==nullptr){ + HILOG_WARN(NATIVE_TAG, "Render thread not found for rotation."); + return; + } if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { float tiltX = 2.2; float tiltY = 2.2; @@ -470,8 +482,37 @@ void NativeMgr::DispatchTouchEvent(OH_NativeXComponent* component, void* window) "type=%{public}d, force=%{public}f, tiltX=%{public}f, tiltY=%{public}f, toolType=%{public}d", touchEvent_.x, touchEvent_.y, touchEvent_.screenX, touchEvent_.screenY, touchEvent_.type, touchEvent_.force, tiltX, tiltY, toolType); - if (touchEvent_.type == OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UP) { - + //判断触控点数量 + //当触点为1则判定为单指,处理单指对应事件 + if(touchEvent_.numPoints==1){ + //触屏按下记录按下点坐标 + if(touchEvent_.type ==OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_DOWN){ + NativeMgr::x=touchEvent_.x; + NativeMgr::y=touchEvent_.y; + } + //按下并移动,计算移动增量需要乘以灵敏度 + if (touchEvent_.type == OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_MOVE) { + float dtx=(NativeMgr::x-touchEvent_.x)*0.1; + + float dty=(NativeMgr::y-touchEvent_.y)*0.1; + renderThread->setRotation(dtx, dty); + OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_); + NativeMgr::x=touchEvent_.x; + NativeMgr::y=touchEvent_.y; + } + //的判断为双指,处理双指事件功能(缩放视距) + } + else if(touchEvent_.numPoints==2) + { + //双指同时处于按下状态,并且移动 + if(touchEvent_.touchPoints[0].isPressed + &&touchEvent_.touchPoints[1].isPressed){ + //当双指按下时候,分别记录每个指的坐标 + + //双指移动,计算移动位移量,同时根据移动缩放因子计算视距,从调整相机相对于模型的距离.从而实现双指缩放 + }else if(touchEvent_.type==OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_MOVE){ + + } } } else { OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "XComponent_Native", "touch fail"); diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.h b/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.h index f08bb84c..b6ebe0c4 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.h +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeMgr.h @@ -85,7 +85,6 @@ private: std::unordered_map pluginManagerMap_; public: // [StartExclude plugin_manager_h_part] - OH_NativeXComponent_TouchEvent touchEvent_; static std::string crtXCompId; static std::unordered_map NxInfos; std::string modelPath_; @@ -96,6 +95,9 @@ public: uint64_t afWidth; uint64_t afHeight; + float x; + float y; + int64_t timestamp; static int32_t hasDraw_; static int32_t hasChangeColor_; diff --git a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp index 88e00624..7ed2dc92 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp @@ -45,14 +45,14 @@ void V3dCa::SetRotation(float xAngle, float yAngle) { // 从 gp_Ax1 中提取方向向量 (gp_Dir -> gp_Vec) gp_Vec xRotationAxis = camera->Direction().XYZ().Crossed(currentUp.XYZ()); // 叉积得到X旋转轴 if (xRotationAxis.Magnitude() > gp::Resolution()) { // 防止零向量导致的无效四元数 - rotX.SetVectorAndAngle(xRotationAxis, xAngle * M_PI / 180.0); + rotX.SetVectorAndAngle(-xRotationAxis, xAngle * M_PI / 180.0); } else { rotX.SetIdent(); // 如果叉积为零,则无旋转 } // 从 gp_Ax1 中提取方向向量 (gp_Dir -> gp_Vec) gp_Vec yRotationAxis = currentUp.XYZ(); // Y旋转轴就是当前的Up方向 if (yRotationAxis.Magnitude() > gp::Resolution()) { - rotY.SetVectorAndAngle(yRotationAxis, yAngle * M_PI / 180.0); + rotY.SetVectorAndAngle(-yRotationAxis, yAngle * M_PI / 180.0); } else { rotY.SetIdent(); // 如果Up向量无效,则无旋转 } @@ -70,7 +70,7 @@ void V3dCa::SetRotation(float xAngle, float yAngle) { camera->SetEye(newEye); camera->SetCenter(rotationCenter); camera->SetUp(newUp); - HILOG_ERROR(NATIVE_TAG,"Rotation"); + //HILOG_ERROR(NATIVE_TAG,"Rotation"); } diff --git a/entry/src/main/ets/pages/CustomController/Button.ets b/entry/src/main/ets/pages/CustomController/Button.ets index 6afd09ae..2cf4788d 100644 --- a/entry/src/main/ets/pages/CustomController/Button.ets +++ b/entry/src/main/ets/pages/CustomController/Button.ets @@ -28,7 +28,7 @@ export struct EventBtn { @Builder build() { - Column({ space: 2 }) { + Column() { //如果该类型是false表示为配普通事件按钮 if (this.eventBtn != undefined) { Button() @@ -56,16 +56,15 @@ export struct EventBtn { }) } if (this.eventBtn != undefined) { - Text() + Blank() .width('auto') .height(edHeigth) - .backgroundColor(Color.Transparent) Text(this.eventBtn.eName) .fontSize(16) .width('auto') - .height(edHeigth) .textAlign(TextAlign.Center) .backgroundColor(Color.Transparent) + .fontColor($r('sys.color.font_emphasize')) } }.padding(1) } @@ -75,9 +74,9 @@ export struct EventBtn { //功能目录菜单,主要用于针对单一按钮多个功能形式 @ComponentV2 export struct MenuBtn { - @Param menus: Array | undefined = undefined; + @Param menus?: Array=undefined; @Local curtIndex:number=0; - + @Local action?:TitleButton= undefined; @Builder BaseMenu (){ Menu() { @@ -93,13 +92,13 @@ export struct MenuBtn { } }) }.fontSize(20) + .fontColor($r('sys.color.font_emphasize')) } build() { Column({ space: 0 }) { if (this.menus != undefined) { Button() - .bindMenu(this.BaseMenu) .width(ebWidth) .height(ebHeigth) .backgroundImage($r('app.media.' + this.menus[this.curtIndex].eIcon)) @@ -108,21 +107,24 @@ export struct MenuBtn { .backgroundImageSize({ width: '90%', // 图片宽度占满按钮 height: '90%' // 图片高度占满按钮 - }) + }).onClick(()=> { + ExecuteCommand((this.menus as Array)[this.curtIndex] as TitleButton); + }) Button() - .type(ButtonType.Normal) .bindMenu(this.BaseMenu) + .type(ButtonType.Normal) .width(ebWidth) .height(edHeigth) .backgroundImage($r('app.media.base_chevron_down')) .backgroundImagePosition({ x: '35%', y: '0%' }) .backgroundColor(Color.Transparent) - Text((this.menus[this.curtIndex].eName)) + .bindMenu(this.BaseMenu) .fontSize(16) .width('auto') - .height(edHeigth) .textAlign(TextAlign.Center) + .backgroundColor(Color.Transparent) + .fontColor($r('sys.color.font_emphasize')) } } .padding(1) @@ -152,6 +154,7 @@ export struct SubColumnMenu { .size({ height: ebWidth }) }) }.fontSize(20) + .fontColor($r('sys.color.font_emphasize')) } @Builder BaseMenu (){ @@ -174,6 +177,7 @@ export struct SubColumnMenu { } }) }.fontSize(20) + .fontColor($r('sys.color.font_emphasize')) } build(){ @@ -183,7 +187,9 @@ export struct SubColumnMenu { Image($r('app.media.'+(this.icon!=undefined ? this.icon:(this.menus[this.curtIndex]as TitleButton).eIcon))) .height(mwInfo.width*0.01) if(this.name!=undefined){ - Text(this.name).fontSize(16) + Text(this.name) + .fontSize(16) + .fontColor($r('sys.color.font_emphasize')) } } }.height(mwInfo.width*0.01) diff --git a/entry/src/main/ets/pages/CustomController/Menu.ets b/entry/src/main/ets/pages/CustomController/Menu.ets index a27f4a37..ae2c657a 100644 --- a/entry/src/main/ets/pages/CustomController/Menu.ets +++ b/entry/src/main/ets/pages/CustomController/Menu.ets @@ -63,7 +63,7 @@ export struct GroupTextEventMenu { Blank().width('auto') Text(this.grpEvent.grpName) .fontSize(16) - .fontColor(Color.Gray) + .fontColor($r('sys.color.font_emphasize')) Blank().width('auto') Button() .height(mwInfo.width*0.005) diff --git a/entry/src/main/ets/pages/EventSubWin/Opts/OptisModeling.ets b/entry/src/main/ets/pages/EventSubWin/Opts/OptsModeling.ets similarity index 100% rename from entry/src/main/ets/pages/EventSubWin/Opts/OptisModeling.ets rename to entry/src/main/ets/pages/EventSubWin/Opts/OptsModeling.ets diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 9f058049..91ad9005 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -2,6 +2,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { edgeColors, display, AppStorageV2 } from '@kit.ArkUI'; import { TitleTab } from './TitleLayout/TitleTab' import { LeftSideTab } from './LeftSideLayout/LeftSideTab' +import { RightSideTab } from './RightSideLayout/RightSideTab' import { ModelViewTab } from './ModelViewTab' import { TitleColumnSub } from './TitleLayout/TitleColumnSub' import { mwInfo } from './DispWinInfo/DispWinInfo' @@ -13,29 +14,29 @@ const DOMAIN = 0x0000; struct Index { @Local startX:number=0; @Local isDragging:boolean=false; - @Provider('panelWidth') panelWidth:number=mwInfo.width * 0.15; - + @Provider('LeftSideWidth') leftSideWidth:number=mwInfo.width * 0.1; + @Provider('RightSideWidth') rightSideWidth:number=mwInfo.width * 0.1; build() { //OpenCAX主界面整体布局,采用多行布局 Column({ space: 0 }) { //头部导航功能区 TitleTab() - .height(mwInfo.height * 0.08) //分割线 Divider().vertical(false).strokeWidth(1).lineCap(LineCapStyle.Round).width('100%').backgroundColor(Color.Grey) //工具栏 Row() { TitleColumnSub(); + Blank().layoutWeight(1) } - .width('100%') .height(mwInfo.height * 0.02) .align(Alignment.Start) + //分割线 Divider().vertical(false).strokeWidth(1).lineCap(LineCapStyle.Round).width('100%').backgroundColor(Color.Grey) Row() { //左侧边导航区 LeftSideTab() - // 拖拽手柄 + // 左拖拽手柄 Divider().vertical(true).strokeWidth(3).lineCap(LineCapStyle.Round).height('100%').backgroundColor(Color.Grey) .onMouse((event) => { if(event.button==MouseButton.Left&&event.action==MouseAction.Press){ @@ -43,10 +44,10 @@ struct Index { this.isDragging = true; }else if(event.action==MouseAction.Move&&this.isDragging){ // 计算新的宽度 - let newWidth = this.panelWidth + (event.screenX - this.startX); + let newWidth = this.leftSideWidth + (event.screenX - this.startX); // 添加最小宽度限制 newWidth = Math.max(newWidth, 0); - this.panelWidth = newWidth; + this.leftSideWidth = newWidth; // 更新起始坐标,实现连续拖动 this.startX = event.screenX; }else if(event.action==MouseAction.Release){ @@ -58,6 +59,26 @@ struct Index { ModelViewTab() }.layoutWeight(1) .align(Alignment.Center) + //右拖拽手柄 + Divider().vertical(true).strokeWidth(3).lineCap(LineCapStyle.Round).height('100%').backgroundColor(Color.Grey) + .onMouse((event) => { + if(event.button==MouseButton.Left&&event.action==MouseAction.Press){ + this.startX = event.screenX; // 记录起始坐标 + this.isDragging = true; + }else if(event.action==MouseAction.Move&&this.isDragging){ + // 计算新的宽度 + let newWidth = this.rightSideWidth - (event.screenX - this.startX); + // 添加最小宽度限制 + newWidth = Math.max(newWidth, 0); + this.rightSideWidth = newWidth; + // 更新起始坐标,实现连续拖动 + this.startX = event.screenX; + }else if(event.action==MouseAction.Release){ + this.isDragging = false; + } + }) + //右侧边导航区 + RightSideTab() }.width('100%') .height(mwInfo.height * 0.39) //分割线 @@ -68,9 +89,8 @@ struct Index { }.width('100%') .align(Alignment.End) .alignItems(HorizontalAlign.Start) - .height(20) - }.backgroundColor('#f3f3f0') - .width('100%') - .height('100%') + .justifyContent(FlexAlign.Center) + .height(25) + }.margin({ top:0, left: 0, bottom: 0, right: 0 }) } } diff --git a/entry/src/main/ets/pages/LeftSideLayout/LeftSideTab.ets b/entry/src/main/ets/pages/LeftSideLayout/LeftSideTab.ets index d1264d80..1e00d85a 100644 --- a/entry/src/main/ets/pages/LeftSideLayout/LeftSideTab.ets +++ b/entry/src/main/ets/pages/LeftSideLayout/LeftSideTab.ets @@ -7,7 +7,7 @@ export struct LeftSideTab { private leftSideBarTabs: TabsController = new TabsController(); @Local leftSideBarFocusIndex: number = 0; @Local isExpanded:boolean=true; - @Consumer('panelWidth') panelWidth:number=mwInfo.width * 0.1; + @Consumer('LeftSideWidth') leftSideWidth:number=mwInfo.width * 0.1; build() { Row() { @@ -25,14 +25,10 @@ export struct LeftSideTab { .backgroundImage(this.isExpanded ? $r('app.media.base_expand_on'):$r('app.media.base_expand_off')) .type(ButtonType.Normal) .width(mwInfo.width*0.013) - .height(mwInfo.height*0.013) + .height(mwInfo.width*0.013) .onClick(()=>{ this.isExpanded = !this.isExpanded; - if(this.isExpanded){ - this.panelWidth=mwInfo.width * 0.1; - }else{ - this.panelWidth=0; - } + this.leftSideWidth=this.isExpanded?mwInfo.width * 0.1:0 }).margin({ top: 2,left:1,bottom:0,right:2}) Scroll() { Flex({ direction: FlexDirection.Column}) { @@ -70,19 +66,15 @@ export struct LeftSideTab { }.borderWidth(1) .borderColor(Color.Grey) Column({space:1}){ - if (this.isExpanded) { - Column() { - Tabs({ barPosition: BarPosition.Start, controller: this.leftSideBarTabs }) { - ForEach(LeftSideBars, (item: TitleButton, index: number) => { - TabContent() { - LeftSideComponent(); - } - }) - }.barHeight(0) - } - } - }.width(this.panelWidth) + Tabs({ barPosition: BarPosition.Start, controller: this.leftSideBarTabs }) { + ForEach(LeftSideBars, (item: TitleButton, index: number) => { + TabContent() { + LeftSideComponent(); + } + }) + }.barHeight(0) + }.width(this.isExpanded?this.leftSideWidth:0) }.width('auto') - .backgroundColor('#f3f3f0') + .backgroundColor($r('sys.color.background_secondary')) } } diff --git a/entry/src/main/ets/pages/RightSideLayout/RightSideTab.ets b/entry/src/main/ets/pages/RightSideLayout/RightSideTab.ets new file mode 100644 index 00000000..366b9ed7 --- /dev/null +++ b/entry/src/main/ets/pages/RightSideLayout/RightSideTab.ets @@ -0,0 +1,46 @@ +import { TitleButton } from '../LayoutInterface/Interface/ButtonInterface'; +import {LeftSideBars} from '../LayoutInterface/Layout/LeftSideBar' +import { mwInfo } from '../DispWinInfo/DispWinInfo' + +@ComponentV2 +export struct RightSideTab { + private leftSideBarTabs: TabsController = new TabsController(); + @Local leftSideBarFocusIndex: number = 0; + @Local isExpanded:boolean=false; + @Consumer('RightSideWidth') rightSideWidth:number=mwInfo.width * 0.1; + + build() { + Row() { + Column({space:1}){ + Tabs({ barPosition: BarPosition.Start, controller: this.leftSideBarTabs }) { + TabContent() { + + } + }.barHeight(0) + }.width(this.isExpanded?this.rightSideWidth:0) + Column({space:1}){ + Button() + .borderWidth(1) + .borderColor(Color.Grey) + .borderRadius(5) + .backgroundImagePosition({ x: '5%', y: '5%' }) + .backgroundColor(Color.Transparent) + .backgroundImageSize({ + width: '90%', // 图片宽度占满按钮 + height: '90%' // 图片高度占满按钮 + }) + .backgroundImage(this.isExpanded ? $r('app.media.base_expand_on'):$r('app.media.base_expand_off')) + .type(ButtonType.Normal) + .width(mwInfo.width*0.013) + .height(mwInfo.width*0.013) + .onClick(()=>{ + this.isExpanded = !this.isExpanded; + this.rightSideWidth=this.isExpanded?mwInfo.width * 0.1:0; + }).margin({ top: 2,left:1,bottom:0,right:2}) + Blank().layoutWeight(1) + }.borderWidth(1) + .borderColor(Color.Grey) + }.width('auto') + .backgroundColor($r('sys.color.background_secondary')) + } +} diff --git a/entry/src/main/ets/pages/TitleLayout/TitleTab.ets b/entry/src/main/ets/pages/TitleLayout/TitleTab.ets index 4403b37c..ffaa08f4 100644 --- a/entry/src/main/ets/pages/TitleLayout/TitleTab.ets +++ b/entry/src/main/ets/pages/TitleLayout/TitleTab.ets @@ -26,10 +26,10 @@ export struct TitleTab { .fontSize(16) .fontColor(Color.Black) .height(mwInfo.height*0.025) - .width(mwInfo.width*0.035) .bindMenu(BaseMenu(FileMenuData)) .type(ButtonType.Normal) - .backgroundColor('#f3f3f0') + .backgroundColor($r('sys.color.background_secondary')) + .fontColor($r('sys.color.font_emphasize')) ForEach(this.curtModel, (item: TitleModel, index: number) => { Button(item.cmName) @@ -37,21 +37,21 @@ export struct TitleTab { .fontColor(Color.Black) .fontWeight(index === this.titleBarFocusIndex ? FontWeight.Bold : FontWeight.Normal) .height(mwInfo.height*0.025) - .width(mwInfo.width*0.035) .type(ButtonType.Normal) - .backgroundColor('#f3f3f0') + .backgroundColor($r('sys.color.background_secondary')) + .fontColor($r('sys.color.font_emphasize')) .onClick(() => { this.titleBarTabs.changeIndex(index); this.titleBarFocusIndex = index; }) }) + Blank().layoutWeight(1) } } .align(Alignment.Start) .scrollable(ScrollDirection.Horizontal) .scrollBar(BarState.Off) - .margin({ top: 2,left:2,bottom:0,right:2}) - .width('100%') + .margin({ top: 0,left:0,bottom:0,right:0}) //分割线 Divider() .vertical(false) @@ -69,6 +69,7 @@ export struct TitleTab { }.scrollable(true) .barHeight(0) .barMode(BarMode.Fixed) - }.width(mwInfo.width) + }.width('100%') + .height(mwInfo.height * 0.08) } } diff --git a/entry/src/main/ets/pages/rightSideTab.ets b/entry/src/main/ets/pages/rightSideTab.ets deleted file mode 100644 index e69de29b..00000000