世界坐标系和view的Graphic3d_AspectText3d和Prs3d_TextAspect不是同一个

This commit is contained in:
JackLee 2026-03-29 19:50:31 +08:00
parent adbd81bf1a
commit 23cf94de71
11 changed files with 127 additions and 59 deletions

View File

@ -5,6 +5,7 @@
// please include "napi/native_api.h".
#include "Axis.h"
#include "Graphic3d_NameOfMaterial.hxx"
#include "Prs3d_DatumMode.hxx"
#include "Quantity_NameOfColor.hxx"
@ -16,9 +17,6 @@ namespace NativeOpenCAX {
Axis::Axis() : axiPlacement(nullptr), axiTrihedron(nullptr), axiViewCube(nullptr) {}
Axis::~Axis() {}
void Axis::SetAxisTextStyle(Handle(Prs3d_TextAspect) _textStyle){
textStyle=_textStyle;
}
bool Axis::InitAxis(Handle(AIS_InteractiveContext) & context) {
try {
//坐标显示文本
@ -27,7 +25,7 @@ bool Axis::InitAxis(Handle(AIS_InteractiveContext) & context) {
const char16_t z_Axis[] = u"Z";
// 创建场景中心参考坐标系
gp_Ax2 theAxis;
double theSize =200; // 大小
double theSize =250; // 大小
// 设置原点
theAxis.SetLocation(gp_Pnt(0, 0, 0));
// 以世界坐标轴为准,设置Z,X轴方向
@ -55,9 +53,6 @@ bool Axis::InitAxis(Handle(AIS_InteractiveContext) & context) {
axiTrihedron->SetLabel(Prs3d_DP_YAxis, y_Axis);
axiTrihedron->SetLabel(Prs3d_DP_ZAxis, z_Axis);
axiTrihedron->SetSize(theSize);
if(!textStyle.IsNull()){
axiTrihedron->Attributes()->DatumAspect()->SetTextAspect(textStyle);
}
axiTrihedron->SetTransformPersistence(new Graphic3d_TransformPers(Graphic3d_TMF_ZoomPers, anOrg));
axiTrihedron->Attributes()->SetZLayer(Graphic3d_ZLayerId_Topmost);
context->Display(axiTrihedron, true);
@ -68,7 +63,7 @@ bool Axis::InitAxis(Handle(AIS_InteractiveContext) & context) {
return false;
}
}
bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context) {
bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context,Handle(Prs3d_TextAspect) _textStyle) {
try {
//立方体面显示文本
const char16_t rightCube[] = u"右视图";
@ -90,8 +85,7 @@ bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context) {
axiViewCube->SetTransparency(0.0);
axiViewCube->SetFixedAnimationLoop(true);
axiViewCube->SetTextColor(Quantity_Color(Quantity_NOC_YELLOW2));
axiViewCube->SetFontHeight(2000);
axiViewCube->SetFont("HarmonyOS Sans");
axiViewCube->SetFontHeight(35);
axiViewCube->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM));
axiViewCube->SetTransformPersistence(
new Graphic3d_TransformPers(Graphic3d_TMF_TriedronPers, Aspect_TOTP_RIGHT_UPPER, NCollection_Vec2<int>(125, 125)));
@ -102,6 +96,7 @@ bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context) {
HILOG_INFO(NATIVE_TAG, "Init Axi View Cube Fail:%{public}d", e.what());
return false;
}
}
void Axis::SetRotationX(float rx) { rotationX = rx; }

View File

@ -20,8 +20,7 @@ public:
Axis();
~Axis();
bool InitAxis(Handle(AIS_InteractiveContext)& context);
bool InitAxisCube(Handle(AIS_InteractiveContext) & context);
void SetAxisTextStyle(Handle(Prs3d_TextAspect) textStyle);
bool InitAxisCube(Handle(AIS_InteractiveContext) & context,Handle(Prs3d_TextAspect) _textStyle);
void SetRotationX(float x);
void SetRotationY(float y);
void SetRotationZ(float z);
@ -34,7 +33,6 @@ private:
Handle(AIS_Trihedron) axiTrihedron;
//定义三面体
Handle(AIS_ViewCube) axiViewCube;
Handle(Prs3d_TextAspect) textStyle;
private:
//旋转X轴
float rotationX=0.0f;

View File

@ -14,10 +14,12 @@ namespace NativeOpenCAX {
Context::Context() : context(nullptr) {}
Context::~Context() {}
bool Context::InitContext(Handle(V3d_Viewer)& viewer) {
bool Context::InitContext(Handle(V3d_Viewer)& viewer,Handle(Prs3d_TextAspect) _textAspect) {
try {
context = new AIS_InteractiveContext(viewer);
context->SetDisplayMode(AIS_Shaded, true); // 默认使用着色模式
Handle(Prs3d_Drawer) theDrawer=context->DefaultDrawer();
theDrawer->SetTextAspect(_textAspect);
HILOG_INFO(NATIVE_TAG, "InitCtx Done");
return true;
} catch (std::exception &e) {

View File

@ -17,7 +17,7 @@ class Context{
public:
Context();
~Context();
bool InitContext(Handle(V3d_Viewer)& viewer);
bool InitContext(Handle(V3d_Viewer)& viewer,Handle(Prs3d_TextAspect) _textAspect);
public:
Handle(AIS_InteractiveContext) context;
};

View File

@ -26,9 +26,7 @@ bool NativeRender::init(EGLCore &_eglCore) {
HILOG_ERROR(NATIVE_TAG, "Init GraphicDriver Fail!");
return false;
}
if (ts->InitTextStyle()) {
mAxis->SetAxisTextStyle(ts->text);
}else{
if (!ts->InitTextStyle()) {
HILOG_ERROR(NATIVE_TAG, "Init TextSyle Fail!");
return false;
}
@ -36,7 +34,7 @@ bool NativeRender::init(EGLCore &_eglCore) {
HILOG_ERROR(NATIVE_TAG, "Init Viewer Fail!");
return false;
}
if (!ctx->InitContext(vr->viewer)) {
if (!ctx->InitContext(vr->viewer,ts->GetFontStyle(STYLE_AXIS))) {
HILOG_ERROR(NATIVE_TAG, "Init Ctx Fail!");
return false;
}
@ -48,8 +46,8 @@ bool NativeRender::init(EGLCore &_eglCore) {
HILOG_ERROR(NATIVE_TAG, "Init View Fail!");
return false;
} else {
vw->SetViewOption();
vw->SetText(ts->text);
vw->SetViewOption(ts->GetFontStyle(STYLE_AXIS));
vw->SetText(ts->GetFontStyle(STYLE_AXIS));
vw->SetWin(win->window);
}
if (!cr->InitCamera(vw->view)) {
@ -62,7 +60,7 @@ bool NativeRender::init(EGLCore &_eglCore) {
return false;
}
if (!mAxis->InitAxisCube(ctx->context)) {
if (!mAxis->InitAxisCube(ctx->context,ts->GetFontStyle(STYLE_FACE))) {
HILOG_ERROR(NATIVE_TAG, "Init AXIS Cuba Fail!");
return false;
}

View File

@ -56,6 +56,7 @@ void NativeRenderThread::renderLoop() {
if (!eglCore_->init(nativeWindow_)) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","Failed to initialize EGL");
}
ftMgr=Font_FontMgr::GetInstance();
// 初始化OCCT渲染器
if (!renderer_->init(*eglCore_)) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","Failed to initialize OCCT renderer");

View File

@ -5,6 +5,7 @@
// please include "napi/native_api.h".
#include "TextStyle.h"
#include "Font_FontAspect.hxx"
#ifndef NATIVE_TAG
#define NATIVE_TAG "TEXTSTYLE"
@ -14,22 +15,18 @@
namespace NativeOpenCAX {
TextStyle::TextStyle() : text(nullptr) {}
TextStyle::TextStyle() :
currentFontType(FONT_STYLE_TYPE::STYLE_AXIS),
fontStyle(std::map<FONT_STYLE_TYPE, Handle(Prs3d_TextAspect)>())
{
}
TextStyle::~TextStyle() {}
bool TextStyle::InitTextStyle() {
try {
text = new Prs3d_TextAspect();
text->SetFont("HarmonyOS Sans");
//缩放比例计算.根据XComp的对角线大小.按照Camera的缩放
text->SetHeight(2000);
text->Aspect()->SetColor(Quantity_NOC_GRAY95);
text->Aspect()->SetColorSubTitle(Quantity_NOC_BLACK);
text->Aspect()->SetDisplayType(Aspect_TODT_SHADOW);
text->Aspect()->SetTextFontAspect(Font_FA_Bold);
text->Aspect()->SetTextZoomable(false);
text->SetHorizontalJustification(Graphic3d_HTA_LEFT);
text->SetVerticalJustification(Graphic3d_VTA_BOTTOM);
InitAxisText();
InitCubeText();
HILOG_INFO(NATIVE_TAG, "InitTextSyle Done");
return true;
} catch (std::exception &e) {
@ -37,4 +34,72 @@ bool TextStyle::InitTextStyle() {
return false;
}
}
void TextStyle::InitAxisText(){
FONT_STYLE_TYPE styleType=FONT_STYLE_TYPE::STYLE_AXIS;
Handle(Prs3d_TextAspect) axisText= new Prs3d_TextAspect();
axisText = new Prs3d_TextAspect();
axisText->SetHeight(70);
axisText->SetFont("HarmonyOS Sans");
axisText->Aspect()->SetFont("HarmonyOS Sans");
axisText->Aspect()->SetColor(Quantity_NOC_GRAY95);
axisText->Aspect()->SetColorSubTitle(Quantity_NOC_BLACK);
axisText->Aspect()->SetDisplayType(Aspect_TODT_SHADOW);
axisText->Aspect()->SetTextFontAspect(Font_FA_Regular);
axisText->Aspect()->SetTextZoomable(false);
axisText->SetHorizontalJustification(Graphic3d_HTA_LEFT);
axisText->SetVerticalJustification(Graphic3d_VTA_BOTTOM);
fontStyle[styleType]=axisText;
}
void TextStyle::InitCubeText(){
FONT_STYLE_TYPE styleType=FONT_STYLE_TYPE::STYLE_FACE;
Handle(Prs3d_TextAspect) cubeText= new Prs3d_TextAspect();
cubeText = new Prs3d_TextAspect();
cubeText->SetHeight(2000);
cubeText->SetFont("HarmonyOS Sans");
cubeText->Aspect()->SetFont("HarmonyOS Sans");
cubeText->Aspect()->SetColor(Quantity_NOC_GRAY95);
cubeText->Aspect()->SetColorSubTitle(Quantity_NOC_BLACK);
cubeText->Aspect()->SetDisplayType(Aspect_TODT_SHADOW);
cubeText->Aspect()->SetTextFontAspect(Font_FA_Bold);
cubeText->Aspect()->SetTextZoomable(true);
cubeText->SetHorizontalJustification(Graphic3d_HTA_LEFT);
cubeText->SetVerticalJustification(Graphic3d_VTA_BOTTOM);
fontStyle[styleType]=cubeText;
}
Handle(Prs3d_TextAspect) TextStyle::GetFontStyle(FONT_STYLE_TYPE type){
return fontStyle[type];
}
void TextStyle::SetPrs3dFont(const char* theFont){
fontStyle[currentFontType]->SetFont(theFont);
}
void TextStyle::SetPrs3dHeight(int textSize){
fontStyle[currentFontType]->SetHeight(textSize);
}
void TextStyle::SetPrs3dColor(Quantity_Color &theColor){
fontStyle[currentFontType]->SetColor(theColor);
}
void TextStyle::SetPrs3dHTA(Graphic3d_HorizontalTextAlignment theJustification){
fontStyle[currentFontType]->SetHorizontalJustification(theJustification);
}
void TextStyle::SetPrs3dVTA(Graphic3d_VerticalTextAlignment theJustification){
fontStyle[currentFontType]->SetVerticalJustification(theJustification);
}
void TextStyle::SetPrs3dAspectText3d(Handle(Graphic3d_AspectText3d) theAspect){
fontStyle[currentFontType]->SetAspect(theAspect);
}
void TextStyle::SetGrs3dSetColor(const Quantity_Color &theColor){
fontStyle[currentFontType]->Aspect()->SetColor(theColor);
}
void TextStyle::SetGrs3dSetColorRGBA(const Quantity_ColorRGBA &theColor){
fontStyle[currentFontType]->Aspect()->SetColor(theColor);
}
void TextStyle::SetGrs3dSetTextFont(Handle(TCollection_HAsciiString) theFont){
fontStyle[currentFontType]->Aspect()->SetTextFont(theFont);
}
void TextStyle::SetGrs3dSetZoomable(bool theFlag){
fontStyle[currentFontType]->Aspect()->SetTextZoomable(theFlag);
}
void TextStyle::SetGrs3dDisplayType(Font_FontAspect theFontAspect){
fontStyle[currentFontType]->Aspect()->SetTextFontAspect(theFontAspect);
}
}

View File

@ -9,13 +9,15 @@
#include <map>
#include "NativeEGLOCCT/common.h"
#include "Font_NameOfFont.hxx"
#include <Prs3d_TextAspect.hxx>
#include <Graphic3d_AspectText3d.hxx>
//字体样式类型.主要用于区别该样式用于何处
enum FONT_STYLE_TYPE{
STYLE_AXIS,
STYLE_FACE,
};
struct TextStyleOpts{
};
namespace NativeOpenCAX{
class TextStyle{
@ -23,9 +25,26 @@ public:
TextStyle();
~TextStyle();
bool InitTextStyle();
Handle(Prs3d_TextAspect) GetFontStyle(FONT_STYLE_TYPE);
//Prs3d
void SetPrs3dFont(const char* theFont);
void SetPrs3dHeight(int textSize);
void SetPrs3dColor(Quantity_Color &theColor);
void SetPrs3dHTA(Graphic3d_HorizontalTextAlignment theJustification);
void SetPrs3dVTA(Graphic3d_VerticalTextAlignment theJustification);
void SetPrs3dAspectText3d(Handle(Graphic3d_AspectText3d) theAspect);
//Grs3d
void SetGrs3dSetColor(const Quantity_Color &theColor);
void SetGrs3dSetColorRGBA(const Quantity_ColorRGBA &theColor);
void SetGrs3dSetTextFont(Handle(TCollection_HAsciiString) theFont);
void SetGrs3dSetZoomable(bool theFlag);
void SetGrs3dDisplayType(Font_FontAspect theFontAspect);
private:
void InitAxisText();
void InitCubeText();
public:
Handle(Prs3d_TextAspect) text;
//一个字体管理样式对象管理.主要负责对字体样式的归一化集中管理
FONT_STYLE_TYPE currentFontType;
std::map<FONT_STYLE_TYPE, Handle(Prs3d_TextAspect)> fontStyle;
};
}

View File

@ -7,6 +7,7 @@
#include "View.h"
#include "Quantity_NameOfColor.hxx"
#include "V3d_TypeOfAxe.hxx"
#include "V3d_TypeOfVisualization.hxx"
#ifndef NATIVE_TAG
#define NATIVE_TAG "VIEW"
@ -27,40 +28,29 @@ bool View::InitView(Handle(V3d_Viewer) & viewer) {
return false;
}
}
void View::SetViewOption() {
void View::SetViewOption(Handle(Prs3d_TextAspect) _textStyle) {
// 设置渲染参数
view->SetImmediateUpdate(false);
view->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
view->ChangeRenderingParams().IsShadowEnabled = Standard_False;
view->ChangeRenderingParams().IsReflectionEnabled = Standard_False;
view->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True;
view->ChangeRenderingParams().Resolution = 1;
// view->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True;
// view->ChangeRenderingParams().Resolution = 2;
// 设置背景渐变
view->SetBgGradientColors(Quantity_Color(Quantity_NOC_GRAY), Quantity_Color(Quantity_NOC_BLACK),
Aspect_GFM_VER, // 垂直渐变
false);
// 设置默认相机位置
view->SetSize(0.1);
view->SetProj(V3d_XposYnegZpos);
view->FitAll(0.02, false);
// 可选:显示坐标轴
view->ZBufferTriedronSetup();
// 调整相机视角
view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
view->SetBackgroundColor(Quantity_NOC_GRAY90);
//左下角默认坐标系
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(1500.0);
tri->LabelAspect(V3d_X)->SetColor(Quantity_Color(Quantity_NOC_YELLOW));
}
view->Trihedron(false)->LabelAspect(V3d_Y)->SetAspect(_textStyle->Aspect());
view->Trihedron(false)->LabelAspect(V3d_X)->SetAspect(_textStyle->Aspect());
view->Trihedron(false)->LabelAspect(V3d_Z)->SetAspect(_textStyle->Aspect());
view->SetBackgroundColor(Quantity_NOC_GRAY90);
}
void View::SetText(Handle(Prs3d_TextAspect) & text) {
void View::SetText(Handle(Prs3d_TextAspect) text) {
view->ChangeRenderingParams().StatsTextAspect = text->Aspect();
view->ChangeRenderingParams().StatsTextHeight = text->Height();
}

View File

@ -21,9 +21,9 @@ public:
View();
~View();
bool InitView(Handle(V3d_Viewer)& viewer);
void SetViewOption();
void SetViewOption(Handle(Prs3d_TextAspect) _textStyle);
void SetWin(Handle(Aspect_NeutralWindow)& win);
void SetText(Handle(Prs3d_TextAspect)& text);
void SetText(Handle(Prs3d_TextAspect) text);
void SetClearColor(float r, float g, float b, float a);
void MustBeResized();
void Redraw();