解决XYZ走文本无法显示问题
This commit is contained in:
parent
e2ce55218e
commit
51dd9c79b6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
entry/libs/x86_64/libfreetype.so.6
Normal file
BIN
entry/libs/x86_64/libfreetype.so.6
Normal file
Binary file not shown.
@ -22,9 +22,15 @@ set(OCCT_CORE_LIBS
|
||||
TKTopAlgo TKMesh TKService TKV3d TKXCAF TKCAF TKLCAF TKCDF TKFillet
|
||||
TKDESTEP TKShHealing TKHLR TKVCAF TKBO TKPrim TKBool TKDE TKXSBase
|
||||
)
|
||||
|
||||
set(OCCT_3RD_LIBS libfreetype.so.6)
|
||||
|
||||
foreach(LIB_NAME ${OCCT_CORE_LIBS})
|
||||
list(APPEND OCCT_IMPORTED_LIBS ${OCCT_LIB_DIR}/lib${LIB_NAME}.so.${OCCT_VERSION})
|
||||
endforeach()
|
||||
foreach(LIB_NAME ${OCCT_3RD_LIBS})
|
||||
list(APPEND OCCT_IMPORTED_LIBS ${OCCT_LIB_DIR}/${LIB_NAME})
|
||||
endforeach()
|
||||
|
||||
# 添加源文件
|
||||
add_library(opencax SHARED
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
// please include "napi/native_api.h".
|
||||
|
||||
#include "Axis.h"
|
||||
#include "Prs3d_DatumMode.hxx"
|
||||
#include "Quantity_NameOfColor.hxx"
|
||||
|
||||
#ifndef NATIVE_TAG
|
||||
@ -37,24 +38,32 @@ bool Axis::InitAxis(Handle(AIS_InteractiveContext) & context) {
|
||||
axiTrihedron->Attributes()->DatumAspect()->LineAspect(Prs3d_DP_XAxis)->SetWidth(1.5);
|
||||
axiTrihedron->Attributes()->DatumAspect()->LineAspect(Prs3d_DP_YAxis)->SetWidth(1.5);
|
||||
axiTrihedron->Attributes()->DatumAspect()->LineAspect(Prs3d_DP_ZAxis)->SetWidth(1.5);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_XArrow, Quantity_NOC_RED2);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_YArrow, Quantity_NOC_GREEN2);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_ZArrow, Quantity_NOC_BLUE2);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_XAxis, Quantity_NOC_RED2);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_YAxis, Quantity_NOC_GREEN2);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_ZAxis, Quantity_NOC_BLUE2);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_XArrow, Quantity_NOC_GRAY85);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_YArrow, Quantity_NOC_GRAY85);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_ZArrow, Quantity_NOC_GRAY85);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_XAxis, Quantity_NOC_GRAY85);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_YAxis, Quantity_NOC_GRAY85);
|
||||
axiTrihedron->SetDatumPartColor(Prs3d_DP_ZAxis, Quantity_NOC_GRAY85);
|
||||
axiTrihedron->SetLabel(Prs3d_DP_XAxis, "X");
|
||||
axiTrihedron->SetLabel(Prs3d_DP_YAxis, "Y");
|
||||
axiTrihedron->SetLabel(Prs3d_DP_ZAxis, "Z");
|
||||
axiTrihedron->SetSize(theSize);
|
||||
textAspect = axiTrihedron->Attributes()->TextAspect();
|
||||
if(textAspect.IsNull()){
|
||||
textAspect=new Prs3d_TextAspect();
|
||||
//textAspect->SetFont("HarmonyOS Sans");
|
||||
textAspect->SetHeight(3000.0);
|
||||
textAspect->SetColor(Quantity_NOC_GRAY85);
|
||||
axiTrihedron->Attributes()->DatumAspect()->SetTextAspect(textAspect);
|
||||
}
|
||||
axiTrihedron->SetTransformPersistence(new Graphic3d_TransformPers(Graphic3d_TMF_ZoomPers, anOrg));
|
||||
axiTrihedron->Attributes()->SetZLayer(Graphic3d_ZLayerId_Topmost);
|
||||
axiTrihedron->SetInfiniteState(true);
|
||||
//axiTrihedron->SetInfiniteState(true);
|
||||
context->Display(axiTrihedron, true);
|
||||
HILOG_INFO(NATIVE_TAG, "InitLocalAxis Done");
|
||||
return true;
|
||||
} catch (std::exception &e) {
|
||||
HILOG_INFO(NATIVE_TAG, "InitLocalAxis Fail:%{public}d", e.what());
|
||||
HILOG_INFO(NATIVE_TAG, "InitLocalAxis Fail:%s", e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -70,10 +79,10 @@ bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context) {
|
||||
axiViewCube->SetBoxSideLabel(V3d_Zneg, "Bottom");
|
||||
axiViewCube->SetDrawAxes(false);
|
||||
axiViewCube->SetSize(60, true);
|
||||
axiViewCube->SetTransparency(0.3);
|
||||
axiViewCube->SetTransparency(0.0);
|
||||
axiViewCube->SetFixedAnimationLoop(true);
|
||||
axiViewCube->SetTextColor(Quantity_Color(Quantity_NOC_BLUE1));
|
||||
axiViewCube->SetFontHeight(100);
|
||||
axiViewCube->SetFontHeight(20);
|
||||
axiViewCube->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM));
|
||||
axiViewCube->SetTransformPersistence(
|
||||
new Graphic3d_TransformPers(Graphic3d_TMF_TriedronPers, Aspect_TOTP_RIGHT_UPPER, NCollection_Vec2<int>(100, 100)));
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <AIS_Trihedron.hxx>
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
#include <Geom_Axis2Placement.hxx>
|
||||
|
||||
namespace NativeOpenCAX {
|
||||
|
||||
class Axis {
|
||||
@ -32,6 +33,7 @@ private:
|
||||
Handle(AIS_Trihedron) axiTrihedron;
|
||||
//定义三面体
|
||||
Handle(AIS_ViewCube) axiViewCube;
|
||||
Handle(Prs3d_TextAspect) textAspect;
|
||||
private:
|
||||
//旋转X轴
|
||||
float rotationX=0.0f;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "NativeRender.h"
|
||||
#include "Aspect_TypeOfLine.hxx"
|
||||
#include "Font_FontAspect.hxx"
|
||||
#include "STEPControl_Reader.hxx"
|
||||
|
||||
#ifndef NATIVE_TAG
|
||||
@ -14,6 +15,9 @@ NativeRender::NativeRender(int w, int h)
|
||||
ogd(new OpenGlGraphicDriver), ts(new TextStyle), vw(new View), vr(new Viewer), win(new Window) {
|
||||
width = w;
|
||||
height = h;
|
||||
ftMgr=Font_FontMgr::GetInstance();
|
||||
ftMgr->SetPrintErrors(true);
|
||||
ftMgr->SetTraceAliases(true);
|
||||
}
|
||||
|
||||
NativeRender::~NativeRender() { shapes_.clear(); }
|
||||
@ -36,16 +40,6 @@ bool NativeRender::init(EGLCore &_eglCore) {
|
||||
HILOG_ERROR(NATIVE_TAG, "Init Ctx Fail!");
|
||||
return false;
|
||||
}
|
||||
if (!mAxis->InitAxis(ctx->context)) {
|
||||
HILOG_ERROR(NATIVE_TAG, "Init AXIS Fail!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mAxis->InitAxisCube(ctx->context)) {
|
||||
HILOG_ERROR(NATIVE_TAG, "Init AXIS Cuba Fail!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!win->InitWindow(width, height)) {
|
||||
HILOG_ERROR(NATIVE_TAG, "Init Window Fail!");
|
||||
return false;
|
||||
@ -62,6 +56,15 @@ bool NativeRender::init(EGLCore &_eglCore) {
|
||||
HILOG_ERROR(NATIVE_TAG, "Init Camera Fail!");
|
||||
return false;
|
||||
}
|
||||
if (!mAxis->InitAxis(ctx->context)) {
|
||||
HILOG_ERROR(NATIVE_TAG, "Init AXIS Fail!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mAxis->InitAxisCube(ctx->context)) {
|
||||
HILOG_ERROR(NATIVE_TAG, "Init AXIS Cuba Fail!");
|
||||
return false;
|
||||
}
|
||||
vw->ResetView();
|
||||
return true;
|
||||
}
|
||||
@ -152,8 +155,6 @@ bool NativeRender::loadModel(const std::string &filePath) {
|
||||
shapes_.push_back(aisShape);
|
||||
}
|
||||
}
|
||||
// 调整相机到合适位置
|
||||
vw->view->FitAll(0.5, true);
|
||||
vw->view->ZFitAll();
|
||||
vw->ResetView();
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "LoadModel",
|
||||
@ -188,35 +189,86 @@ void NativeRender::setZoomLevel(float zoom) {
|
||||
}
|
||||
void NativeRender::setClearColor(float r, float g, float b, float a) { vw->SetClearColor(r, g, b, a); }
|
||||
void NativeRender::resetView() { vw->ResetView(); }
|
||||
void NativeRender::SwitchView(std::string view) {
|
||||
void NativeRender::SwitchView(std::string view) {
|
||||
fontDev();
|
||||
vw->SwitchView(view);
|
||||
OH_Drawing_FontConfigInfoErrorCode fontConfigInfoErrorCode; // 用于接收错误代码
|
||||
OH_Drawing_FontConfigInfo* fontConfigInfo = OH_Drawing_GetSystemFontConfigInfo(&fontConfigInfoErrorCode);
|
||||
if(fontConfigInfoErrorCode != SUCCESS_FONT_CONFIG_INFO) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "PrintSysFontMetrics", "获取系统信息失败,错误代码为: %{public}d", fontConfigInfoErrorCode);
|
||||
}
|
||||
// 获取系统字体配置信息示例
|
||||
if (fontConfigInfo != nullptr) {
|
||||
// 获取字体文件路径数量,打印日志
|
||||
size_t fontDirCount = fontConfigInfo->fontDirSize;
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics", "字体文件路径数量为: %{public}zu\n", fontDirCount);
|
||||
// 遍历字体文件路径列表,打印日志
|
||||
for (size_t i = 0; i < fontDirCount; ++i) {
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics", "字体文件路径为: %{public}s\n",
|
||||
fontConfigInfo->fontDirSet[i]);
|
||||
}
|
||||
// 获取通用字体集数量,打印日志
|
||||
size_t genericCount = fontConfigInfo->fontGenericInfoSize;
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics", "通用字体集数量为: %{public}zu\n", genericCount);
|
||||
// 遍历获取每个通用字体集中的字体家族名(例如 HarmonyOS Sans),打印日志
|
||||
for (size_t i = 0; i < genericCount; ++i) {
|
||||
OH_Drawing_FontGenericInfo &genericInfo = fontConfigInfo->fontGenericInfoSet[i];
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics",
|
||||
"获取第%{public}zu个通用字体集中的字体家族名为: %{public}s", i, genericInfo.familyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 字体测试
|
||||
void NativeRender::fontDev() {
|
||||
//获取鸿蒙系统字体管理信息
|
||||
// OH_Drawing_FontConfigInfoErrorCode fontConfigInfoErrorCode; // 用于接收错误代码
|
||||
// OH_Drawing_FontConfigInfo *fontConfigInfo = OH_Drawing_GetSystemFontConfigInfo(&fontConfigInfoErrorCode);
|
||||
// if (fontConfigInfoErrorCode != SUCCESS_FONT_CONFIG_INFO) {
|
||||
// OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "PrintSysFontMetrics", "获取系统信息失败,错误代码为: %{public}d",
|
||||
// fontConfigInfoErrorCode);
|
||||
// }
|
||||
// // 获取系统字体配置信息示例
|
||||
// if (fontConfigInfo != nullptr) {
|
||||
// // 获取字体文件路径数量,打印日志
|
||||
// size_t fontDirCount = fontConfigInfo->fontDirSize;
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics", "字体文件路径数量为: %{public}zu\n",
|
||||
// fontDirCount);
|
||||
// // 遍历字体文件路径列表,打印日志
|
||||
// for (size_t i = 0; i < fontDirCount; ++i) {
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics", "字体文件路径为: %{public}s\n",
|
||||
// fontConfigInfo->fontDirSet[i]);
|
||||
// }
|
||||
// // 获取通用字体集数量,打印日志
|
||||
// size_t genericCount = fontConfigInfo->fontGenericInfoSize;
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics", "通用字体集数量为: %{public}zu\n",
|
||||
// genericCount);
|
||||
// // 遍历获取每个通用字体集中的字体家族名(例如 HarmonyOS Sans),打印日志
|
||||
// for (size_t i = 0; i < genericCount; ++i) {
|
||||
// OH_Drawing_FontGenericInfo &genericInfo = fontConfigInfo->fontGenericInfoSet[i];
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics",
|
||||
// "获取第%{public}zu个通用字体集中的字体家族名为: %{public}s", i, genericInfo.familyName);
|
||||
// for(size_t i = 0; i < genericInfo.adjustInfoSize; ++i){
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "PrintSysFontMetrics",
|
||||
// "获取第%{public}zu个通用字体集中的字体别名: %{public}s", i, genericInfo.aliasInfoSet->familyName);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//OCCT字体管理信息获取
|
||||
// auto mgr=Font_FontMgr::GetInstance();
|
||||
// Font_FontAspect aspect = Font_FA_Regular;
|
||||
// // 查找sans别名,优先匹配HarmonyOS Sans
|
||||
// Handle(Font_SystemFont) font = mgr->FindFont("HarmonyOS-Sans", aspect);
|
||||
// if (!font.IsNull()) {
|
||||
// // 打印实际匹配到的字体名,若为HarmonyOS Sans则生效
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","SO库匹配到的字体名:%{public}s",font->FontName().ToCString());
|
||||
// }
|
||||
// mgr->InitFontDataBase();
|
||||
// Handle(Font_SystemFont) sysFont=new Font_SystemFont("HarmonyOS-Sans");
|
||||
// sysFont->SetFontPath(Font_FontAspect_Regular, "/system/fonts/");
|
||||
// bool err=mgr->RegisterFont(sysFont,false);
|
||||
// if(err){
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT RegisterFont Done");
|
||||
// }
|
||||
// NCollection_Sequence<occ::handle<TCollection_HAsciiString>> theAliases;
|
||||
// mgr->GetAllAliases(theAliases);
|
||||
// for(auto ft:theAliases){
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT Aliases: %{public}s", ft->ToCString());
|
||||
// }
|
||||
// Handle(Font_SystemFont)sFont = mgr->GetFont("HarmonyOS-Sans");
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT sysFont: %{public}s", sFont->FontName().ToCString());
|
||||
// //查找指定的字体
|
||||
// const TCollection_AsciiString theFontName='HarmonyOS-Sans';
|
||||
// Font_FontAspect theFontAspect;
|
||||
// mgr->FindFont(theFontName, theFontAspect);
|
||||
// OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT Font_FontAspect: %{public}s", theFontAspect);
|
||||
|
||||
|
||||
|
||||
//字体示例
|
||||
Handle(AIS_TextLabel) aTextLabel = new AIS_TextLabel();
|
||||
aTextLabel->SetText(TCollection_ExtendedString(u8"共产主义接班人"));
|
||||
Handle(Prs3d_TextAspect) textAspect = aTextLabel->Attributes()->TextAspect();
|
||||
textAspect->SetFont("HarmonyOS Sans");
|
||||
textAspect->SetHeight(10000.0);
|
||||
textAspect->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
|
||||
gp_Pnt position(0.0, 0.0, 0.0); // 例如,在原点
|
||||
aTextLabel->SetPosition(position);
|
||||
ctx->context->Display(aTextLabel, Standard_True);
|
||||
vw->ResetView();
|
||||
}
|
||||
} // namespace NativeOpenCAX
|
||||
@ -28,6 +28,10 @@
|
||||
#include <native_drawing/drawing_text_typography.h>
|
||||
#include <native_drawing/drawing_register_font.h>
|
||||
|
||||
#include <Font_FontMgr.hxx>
|
||||
#include <AIS_TextLabel.hxx>
|
||||
#include <Resource_Unicode.hxx>
|
||||
|
||||
namespace NativeOpenCAX {
|
||||
|
||||
class NativeRender {
|
||||
@ -45,6 +49,7 @@ public:
|
||||
void setZoomLevel(float zoom);
|
||||
void setTranslation(float x, float y);
|
||||
void setCameraRotationMode(bool state);
|
||||
void fontDev();
|
||||
//视图
|
||||
void SwitchView(std::string);
|
||||
void SetFrontView();
|
||||
@ -68,7 +73,7 @@ private:
|
||||
View* vw;
|
||||
Viewer* vr;
|
||||
Window* win;
|
||||
|
||||
Handle(Font_FontMgr) ftMgr ;
|
||||
std::vector<Handle(AIS_Shape)> shapes_;
|
||||
};
|
||||
} // namespace NativeRender
|
||||
|
||||
@ -19,7 +19,7 @@ TextStyle::~TextStyle() {}
|
||||
bool TextStyle::InitTextStyle() {
|
||||
try {
|
||||
text = new Prs3d_TextAspect();
|
||||
text->SetFont(Font_NOF_ASCII_MONO);
|
||||
text->SetFont("HarmonyOS Sans");
|
||||
text->SetHeight(12);
|
||||
text->Aspect()->SetColor(Quantity_NOC_GRAY95);
|
||||
text->Aspect()->SetColorSubTitle(Quantity_NOC_BLACK);
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
// please include "napi/native_api.h".
|
||||
|
||||
#include "View.h"
|
||||
#include "Quantity_NameOfColor.hxx"
|
||||
#include "V3d_TypeOfAxe.hxx"
|
||||
|
||||
#ifndef NATIVE_TAG
|
||||
#define NATIVE_TAG "VIEW"
|
||||
@ -46,7 +48,15 @@ void View::SetViewOption() {
|
||||
view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Perspective);
|
||||
view->SetBackgroundColor(Quantity_NOC_GRAY90);
|
||||
//左下角默认坐标系
|
||||
view->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_ALICEBLUE, 0.3, V3d_ZBUFFER);
|
||||
view->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_ANTIQUEWHITE, 0.3, V3d_ZBUFFER);
|
||||
Handle(V3d_Trihedron) tri;
|
||||
tri=view->Trihedron(false);
|
||||
if(!tri.IsNull()){
|
||||
HILOG_INFO(NATIVE_TAG, "V3d_Trihedron X");
|
||||
tri->LabelAspect(V3d_X)->SetFont("HarmonyOS Sans");
|
||||
tri->LabelAspect(V3d_X)->SetHeight(20.0);
|
||||
tri->LabelAspect(V3d_X)->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
|
||||
}
|
||||
}
|
||||
|
||||
void View::SetText(Handle(Prs3d_TextAspect) & text) {
|
||||
@ -64,8 +74,7 @@ void View::SetClearColor(float r, float g, float b, float a) {
|
||||
}
|
||||
void View::MustBeResized() { view->MustBeResized(); }
|
||||
|
||||
void View::Redraw() {
|
||||
view->ZFitAll();
|
||||
void View::Redraw() {
|
||||
view->Redraw();
|
||||
}
|
||||
void View::ResetView() {
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { window,display,AppStorageV2} from '@kit.ArkUI';
|
||||
import {MainScreenDisplayInfo,MainWindowInfo,MainWindowStageInfo} from '../pages/AppStorageV2Class'
|
||||
import { window, display, AppStorageV2 } from '@kit.ArkUI';
|
||||
import { MainScreenDisplayInfo, MainWindowInfo, MainWindowStageInfo } from '../pages/AppStorageV2Class'
|
||||
import { IBestInit } from "@ibestservices/ibest-ui-v2"
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
@ -25,23 +26,25 @@ export default class EntryAbility extends UIAbility {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(DOMAIN, 'Tag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
//Get DefaultDispplay width&&height&&id
|
||||
const screenDisplayId:number=display.getDefaultDisplaySync().id;
|
||||
const screenWidth:number=display.getDefaultDisplaySync().width;
|
||||
const screenHeight:number=display.getDefaultDisplaySync().height;
|
||||
const screenDisplayId: number = display.getDefaultDisplaySync().id;
|
||||
const screenWidth: number = display.getDefaultDisplaySync().width;
|
||||
const screenHeight: number = display.getDefaultDisplaySync().height;
|
||||
//Set Main Window Size
|
||||
const mainWindowWidth: number = screenWidth-100;
|
||||
const mainWindowHeight: number = screenHeight-200;
|
||||
const mainWindowWidth: number = screenWidth - 100;
|
||||
const mainWindowHeight: number = screenHeight - 200;
|
||||
console.error(`main window Width: mainWindowWidth, Height: mainWindowHeight`);
|
||||
//Init&&Save AppStorageV2
|
||||
const mainDisplayInfo = AppStorageV2.connect<MainScreenDisplayInfo>(MainScreenDisplayInfo, () => new MainScreenDisplayInfo())!;
|
||||
const mainWinInfo=AppStorageV2.connect<MainWindowInfo>(MainWindowInfo, () => new MainWindowInfo())!;
|
||||
const mainWinStage=AppStorageV2.connect<MainWindowStageInfo>(MainWindowStageInfo, () => new MainWindowStageInfo())!;
|
||||
mainDisplayInfo.mainScreenDisplayId=screenDisplayId;
|
||||
mainDisplayInfo.mainScreenWidth=screenWidth;
|
||||
mainDisplayInfo.mainScreenHeight=screenHeight;
|
||||
mainWinInfo.mainWindowWidth=mainWindowWidth;
|
||||
mainWinInfo.mainWindowHeight=mainWindowHeight;
|
||||
mainWinStage.ws=windowStage;
|
||||
const mainDisplayInfo =
|
||||
AppStorageV2.connect<MainScreenDisplayInfo>(MainScreenDisplayInfo, () => new MainScreenDisplayInfo())!;
|
||||
const mainWinInfo = AppStorageV2.connect<MainWindowInfo>(MainWindowInfo, () => new MainWindowInfo())!;
|
||||
const mainWinStage =
|
||||
AppStorageV2.connect<MainWindowStageInfo>(MainWindowStageInfo, () => new MainWindowStageInfo())!;
|
||||
mainDisplayInfo.mainScreenDisplayId = screenDisplayId;
|
||||
mainDisplayInfo.mainScreenWidth = screenWidth;
|
||||
mainDisplayInfo.mainScreenHeight = screenHeight;
|
||||
mainWinInfo.mainWindowWidth = mainWindowWidth;
|
||||
mainWinInfo.mainWindowHeight = mainWindowHeight;
|
||||
mainWinStage.ws = windowStage;
|
||||
|
||||
//Get Main Window
|
||||
windowStage.getMainWindow((err, data) => {
|
||||
@ -49,9 +52,9 @@ export default class EntryAbility extends UIAbility {
|
||||
console.error(`Failed to obtain the main window. Code: ${err.code}, message: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
this.mainWindow=data;
|
||||
this.mainWindow = data;
|
||||
//moveWindowTo
|
||||
this.mainWindow.moveWindowTo(50,50)
|
||||
this.mainWindow.moveWindowTo(50, 50)
|
||||
//resize mainWindow Size
|
||||
this.mainWindow.resize(mainWindowWidth, mainWindowHeight, (err) => {
|
||||
if (err.code) {
|
||||
@ -64,9 +67,10 @@ export default class EntryAbility extends UIAbility {
|
||||
// windowSizeChangeListener to Change mainWindowWidth&&mainWindowHeight in AppStorage
|
||||
this.mainWindow.on('windowSizeChange', (ListenerData) => {
|
||||
// if Size Change save to AppStorage
|
||||
mainWinInfo.mainWindowWidth=ListenerData.width;
|
||||
mainWinInfo.mainWindowHeight=ListenerData.height;
|
||||
console.info('Succeeded in enabling the listener for window size changes. Data:'+ListenerData.width,ListenerData.height);
|
||||
mainWinInfo.mainWindowWidth = ListenerData.width;
|
||||
mainWinInfo.mainWindowHeight = ListenerData.height;
|
||||
console.info('Succeeded in enabling the listener for window size changes. Data:' + ListenerData.width,
|
||||
ListenerData.height);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -5,15 +5,76 @@ import { LeftSideTab } from './LeftSideLayout/LeftSideTab'
|
||||
import { ModelViewTab } from './modelViewTab'
|
||||
import { TitleColumnSub } from './TitleLayout/TitleColumnSub'
|
||||
import { mwInfo } from './AppStorageV2Class'
|
||||
import fs from '@ohos.file.fs';
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import fileIO from '@ohos.fileio';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
|
||||
let Fonts: Array<string> = [
|
||||
"HarmonyOS_Sans_Black.tff",
|
||||
"HarmonyOS_Sans_Bold.tff",
|
||||
"HarmonyOS_Sans_Light.tff",
|
||||
"HarmonyOS_Sans_Medium.tff",
|
||||
"HarmonyOS_Sans_Regular.tff",
|
||||
"HarmonyOS_Sans_Semibold.tff",
|
||||
"HarmonyOS_Sans_Thin.tff",
|
||||
]
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
struct Index {
|
||||
@Local startX:number=0;
|
||||
@Local isDragging:boolean=false;
|
||||
@Provider('panelWidth') panelWidth:number=mwInfo.mainWindowWidth * 0.15;
|
||||
|
||||
//列出资源管理器指定目录下的所有问题件
|
||||
async HilogToDirFile(dir: string){
|
||||
const context = getContext(this);
|
||||
// 获取资源管理器
|
||||
const rm = context.resourceManager;
|
||||
|
||||
// 列出 rawfile/fonts/
|
||||
const fontFiles: string[] = await rm.getRawFileList(dir);
|
||||
console.info(dir+'目录下文件:', JSON.stringify(fontFiles));
|
||||
|
||||
if (fontFiles.length === 0) {
|
||||
console.warn(dir +':目录为空');
|
||||
return;
|
||||
}
|
||||
}
|
||||
//复制字体到沙盒指定目录
|
||||
//SandBoxFontDir:"/data/storage/el2/base/haps/entry/files/fonts"
|
||||
async CopyFontToSandbox(fontFiles: Array<string>) {
|
||||
try {
|
||||
const context = getContext(this);
|
||||
let srcPath = context.resourceDir+'/fonts/';
|
||||
let destPath = context.filesDir + '/fonts/';
|
||||
// 判断文件夹是否存在
|
||||
if (!fs.accessSync(destPath)) {
|
||||
fs.mkdirSync(destPath);
|
||||
console.info('创建沙箱目录成功:', destPath);
|
||||
}
|
||||
console.info('srcPath:', srcPath);
|
||||
console.info('destPath:', destPath);
|
||||
fs.copyDirSync(srcPath, destPath, 0)
|
||||
} 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 ${fontFiles} to sandbox: ${msg}`);
|
||||
}
|
||||
}
|
||||
//Copy Font File to Sandbox
|
||||
aboutToAppear() {
|
||||
this.HilogToDirFile('fonts/');
|
||||
this.CopyFontToSandbox(Fonts);
|
||||
}
|
||||
|
||||
build() {
|
||||
//OpenCAX主界面整体布局,采用多行布局
|
||||
Column({ space: 0 }) {
|
||||
|
||||
@ -6,6 +6,7 @@ import NativeOpenCAX from 'libopencax.so';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
let modelPath: string = '';
|
||||
|
||||
export function OCCTLoadModel(Command: undefined, Param:undefined) {
|
||||
try {
|
||||
NativeOpenCAX.loadModel(modelPath);
|
||||
@ -22,38 +23,12 @@ export struct ModelView {
|
||||
@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}`);
|
||||
modelPath = `${context.filesDir}/${this.modelName}`
|
||||
NativeOpenCAX.createNativeNode(this.nodeContent);
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column }) {
|
||||
Row(){
|
||||
|
||||
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Black.ttf
Normal file
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Black.ttf
Normal file
Binary file not shown.
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Bold.ttf
Normal file
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Bold.ttf
Normal file
Binary file not shown.
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Light.ttf
Normal file
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Light.ttf
Normal file
Binary file not shown.
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Medium.ttf
Normal file
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Medium.ttf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Thin.ttf
Normal file
BIN
entry/src/main/resources/rawfile/fonts/HarmonyOS_Sans_Thin.ttf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user