整理代码.对全局设置进行重构

This commit is contained in:
JackLee 2026-03-30 16:53:00 +08:00
parent c20ff10e02
commit b42620f109
22 changed files with 325 additions and 348 deletions

View File

@ -38,34 +38,34 @@ endforeach()
#
add_library(opencax SHARED
napi_init.cpp
# Header
NativeEGLOCCT/EGLCore.h
NativeEGLOCCT/NativeRender.h
NativeEGLOCCT/NativeRenderThread.h
NativeEGLOCCT/NativeManager.h
NativeEGLOCCT/Axis/Axis.h
NativeEGLOCCT/OGD/OpenGLGraphicDriver.h
NativeEGLOCCT/TextStyle/TextStyle.h
NativeEGLOCCT/Viewer/Viewer.h
NativeEGLOCCT/Context/Context.h
NativeEGLOCCT/View/View.h
NativeEGLOCCT/window/window.h
NativeEGLOCCT/Camera/Camera.h
NativeEGLOCCT/V3d/Axis/Axis.h
NativeEGLOCCT/V3d/V3dOGD/V3dOGD.h
NativeEGLOCCT/V3d/V3dViewer/V3dViewer.h
NativeEGLOCCT/V3d/V3dCtx/V3dCtx.h
NativeEGLOCCT/V3d/V3dView/V3dView.h
NativeEGLOCCT/V3d/V3dWin/V3dWin.h
NativeEGLOCCT/V3d/V3dCa/V3dCa.h
NativeEGLOCCT/V3d/V3dDrawer/V3dDrawer.h
# Cpp Src
NativeEGLOCCT/EGLCore.cpp
NativeEGLOCCT/NativeRender.cpp
NativeEGLOCCT/NativeRenderThread.cpp
NativeEGLOCCT/NativeManager.cpp
NativeEGLOCCT/OGD/OpenGLGraphicDriver.cpp
NativeEGLOCCT/TextStyle/TextStyle.cpp
NativeEGLOCCT/Viewer/Viewer.cpp
NativeEGLOCCT/Context/Context.cpp
NativeEGLOCCT/View/View.cpp
NativeEGLOCCT/Camera/Camera.cpp
NativeEGLOCCT/Axis/Axis.cpp
NativeEGLOCCT/window/window.cpp
napi_init.cpp
)
NativeEGLOCCT/V3d/V3dOGD/V3dOGD.cpp
NativeEGLOCCT/V3d/V3dViewer/V3dViewer.cpp
NativeEGLOCCT/V3d/V3dCtx/V3dCtx.cpp
NativeEGLOCCT/V3d/V3dView/V3dView.cpp
NativeEGLOCCT/V3d/V3dCa/V3dCa.cpp
NativeEGLOCCT/V3d/Axis/Axis.cpp
NativeEGLOCCT/V3d/V3dWin/V3dWin.cpp
NativeEGLOCCT/V3d/V3dDrawer/V3dDrawer.cpp
)
#
find_library(EGL-lib EGL)

View File

@ -1,31 +0,0 @@
//
// Created on 2026/3/6.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "Context.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "CONTEXT"
#endif
namespace NativeOpenCAX {
Context::Context() : context(nullptr) {}
Context::~Context() {}
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) {
HILOG_INFO(NATIVE_TAG, "InitCtx Fail:%{public}d", e.what());
return false;
}
}
}

View File

@ -10,69 +10,80 @@
static std::mutex renderMutex;
namespace NativeOpenCAX {
NativeRender::NativeRender(int w, int h)
: width(0), height(0), mAxis(new Axis),nAxis(new Axis), cr(new Camera), ctx(new Context),
ogd(new OpenGlGraphicDriver), ts(new TextStyle), vw(new View), vr(new Viewer), win(new Window) {
NativeRender::NativeRender(int w, int h):
width(0),
height(0),
mAxis(new Axis),
nAxis(new Axis),
v3dcr(new V3dCa),
v3dctx(new V3dCtx),
v3dogd(new V3dOGD),
v3dview(new V3dView),
v3ddrawer(new V3dDrawer),
v3dviewer(new V3dViewer),
v3dwin(new V3dWin)
{
width = w;
height = h;
}
NativeRender::~NativeRender() { shapes_.clear(); }
bool NativeRender::init(EGLCore &_eglCore) {
eglCore = _eglCore;
if (!ogd->InitOpenGlGraphicDriver(eglCore)) {
//初始化OpenGL
if (!v3dogd->InitV3dOGD(eglCore)) {
HILOG_ERROR(NATIVE_TAG, "Init GraphicDriver Fail!");
return false;
}
if (!ts->InitTextStyle()) {
HILOG_ERROR(NATIVE_TAG, "Init TextSyle Fail!");
return false;
}
if (!vr->InitViewer(ogd->graphicDriver)) {
//初始化视口管理
if (!v3dviewer->InitV3dViewer(v3dogd->graphicDriver)) {
HILOG_ERROR(NATIVE_TAG, "Init Viewer Fail!");
return false;
}
if (!ctx->InitContext(vr->viewer,ts->GetFontStyle(STYLE_AXIS))) {
//初始化OCCT内部上下文
if (!v3dctx->InitV3dCtx(v3dviewer->viewer)) {
HILOG_ERROR(NATIVE_TAG, "Init Ctx Fail!");
return false;
}else{
//初始化OCCT上下文的Drawer(全局属性设置)
v3ddrawer->InitV3dAllAspect(v3dctx->ctx);
}
if (!win->InitWindow(width, height)) {
//初始化绑定Window
if (!v3dwin->InitV3dWin(width, height)) {
HILOG_ERROR(NATIVE_TAG, "Init Window Fail!");
return false;
}
if (!vw->InitView(vr->viewer)) {
//初始化视图
if (!v3dview->InitV3dView(v3dviewer->viewer,v3dwin->win)) {
HILOG_ERROR(NATIVE_TAG, "Init View Fail!");
return false;
} else {
vw->SetViewOption(ts->GetFontStyle(STYLE_AXIS));
vw->SetText(ts->GetFontStyle(STYLE_AXIS));
vw->SetWin(win->window);
v3dview->InitViewOption();
}
if (!cr->InitCamera(vw->view)) {
if (!v3dcr->InitV3dCa(v3dview->view)) {
HILOG_ERROR(NATIVE_TAG, "Init Camera Fail!");
return false;
}
if (!mAxis->InitAxis(ctx->context)) {
if (!mAxis->InitAxis(v3dctx->ctx)) {
HILOG_ERROR(NATIVE_TAG, "Init AXIS Fail!");
return false;
}
if (!mAxis->InitAxisCube(ctx->context,ts->GetFontStyle(STYLE_FACE))) {
if (!mAxis->InitAxisCube(v3dctx->ctx)) {
HILOG_ERROR(NATIVE_TAG, "Init AXIS Cuba Fail!");
return false;
}
//InitDevText();
vw->ResetView();
v3dview->ResetView();
return true;
}
bool NativeRender::loadModel(const std::string &filePath) {
// 清除现有模型
for (auto &shape : shapes_) {
ctx->context->Remove(shape, false);
v3dctx->ctx->Remove(shape, false);
}
shapes_.clear();
@ -150,13 +161,13 @@ bool NativeRender::loadModel(const std::string &filePath) {
drawer->SetFaceBoundaryDraw(true);
drawer->SetWireAspect(aLineAspect);
drawer->SetShadingAspect(shadingAspect);
ctx->context->Display(aisShape, true);
v3dctx->ctx->Display(aisShape, true);
// ctx->context->SetDisplayMode(AIS_WireFrame, Standard_False);
shapes_.push_back(aisShape);
}
}
vw->view->ZFitAll();
vw->ResetView();
v3dview->view->ZFitAll();
v3dview->ResetView();
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "LoadModel",
"Successfully loaded STEP file with %{public}d shapes", numShapes);
return true;
@ -169,38 +180,36 @@ void NativeRender::setTranslation(float tx, float ty) {
}
void NativeRender::render() {
if (vw->view.IsNull()) {
if (v3dview->view.IsNull()) {
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Render", "View Is Null");
return;
}
vw->MustBeResized();
vw->Redraw();
v3dview->MustBeResized();
v3dview->Redraw();
}
void NativeRender::resize(int w, int h) {
HILOG_ERROR(NATIVE_TAG, "InPut Size:%{public}d,%{public}d", w, h);
win->Resize(w, h);
v3dwin->Resize(w, h);
}
void NativeRender::setRotation(float xAngle, float yAngle) { cr->SetRotation(xAngle, yAngle); }
void NativeRender::setRotation(float xAngle, float yAngle) { v3dcr->SetRotation(xAngle, yAngle); }
void NativeRender::setZoomLevel(float zoom) {
nAxis->SetZoomLevel(std::max(0.1f, std::min(zoom, 5.0f))); // 限制缩放范围
}
void NativeRender::setClearColor(float r, float g, float b, float a) { vw->SetClearColor(r, g, b, a); }
void NativeRender::resetView() { vw->ResetView(); }
void NativeRender::setClearColor(float r, float g, float b, float a) { v3dview->SetClearColor(r, g, b, a); }
void NativeRender::resetView() { v3dview->ResetView(); }
void NativeRender::SwitchView(std::string str) {
vw->SwitchView(str);
v3dview->SwitchView(str);
}
void NativeRender::InitDevText(){
Handle(AIS_TextLabel) aTextLabel = new AIS_TextLabel();
const char16_t chinese_array[] = u"新时代社会主义中国接班人";
aTextLabel->SetText(chinese_array);
aTextLabel->Attributes()->SetTextAspect(ts->GetFontStyle(STYLE_AXIS));
gp_Pnt position(0-(width/3), 0-(height/3), 0.0); // 例如,在原点
aTextLabel->SetPosition(position);
ctx->context->Display(aTextLabel, Standard_True);
v3dctx->ctx->Display(aTextLabel, Standard_True);
HILOG_ERROR(NATIVE_TAG, "aTextLabel字体名字:%{public}s", aTextLabel->FontName().ToCString());
HILOG_ERROR(NATIVE_TAG, "aTextLabel字体名字:%{public}s", aTextLabel->Attributes()->TextAspect()->Aspect()->Font().ToCString());
}

View File

@ -5,7 +5,7 @@
#include <vector>
#include "AIS_Shape.hxx"
#include "NativeEGLOCCT/Window/Window.h"
#include "common.h"
#include "EGLCore.h"
#include <Standard_Handle.hxx>
@ -15,23 +15,15 @@
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include "Axis/Axis.h"
#include "Camera/Camera.h"
#include "Context/Context.h"
#include "OGD/OpenGLGraphicDriver.h"
#include "TextStyle/TextStyle.h"
#include "View/View.h"
#include "Viewer/Viewer.h"
#include "Viewer/Viewer.h"
#include <native_drawing/drawing_font_collection.h>
#include <native_drawing/drawing_text_typography.h>
#include <native_drawing/drawing_register_font.h>
#include <Font_FontMgr.hxx>
#include "V3d/Axis/Axis.h"
#include "V3d/V3dCa/V3dCa.h"
#include "V3d/V3dCtx/V3dCtx.h"
#include "V3d/V3dOGD/V3dOGD.h"
#include "V3d/V3dWin/V3dWin.h"
#include "V3d/V3dView/V3dView.h"
#include "V3d/V3dViewer/V3dViewer.h"
//TextLabel_Dev
#include <AIS_TextLabel.hxx>
#include <Resource_Unicode.hxx>
namespace NativeOpenCAX {
class NativeRender {
@ -58,13 +50,13 @@ private:
EGLCore eglCore;
Axis* mAxis;
Axis* nAxis;
Camera* cr;
Context* ctx;
OpenGlGraphicDriver* ogd;
TextStyle* ts;
View* vw;
Viewer* vr;
Window* win;
V3dCa* v3dcr;
V3dCtx* v3dctx;
V3dOGD* v3dogd;
V3dDrawer* v3ddrawer;
V3dView* v3dview;
V3dViewer* v3dviewer;
V3dWin* v3dwin;
std::vector<Handle(AIS_Shape)> shapes_;
};
} // namespace NativeRender

View File

@ -1,105 +0,0 @@
//
// Created on 2026/3/6.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "TextStyle.h"
#include "Font_FontAspect.hxx"
#ifndef NATIVE_TAG
#define NATIVE_TAG "TEXTSTYLE"
#endif
//该类型主要用于全局字体,样式设置.包含字体.大小.颜色.渲染方式
namespace NativeOpenCAX {
TextStyle::TextStyle() :
currentFontType(FONT_STYLE_TYPE::STYLE_AXIS),
fontStyle(std::map<FONT_STYLE_TYPE, Handle(Prs3d_TextAspect)>())
{
}
TextStyle::~TextStyle() {}
bool TextStyle::InitTextStyle() {
try {
InitAxisText();
InitCubeText();
HILOG_INFO(NATIVE_TAG, "InitTextSyle Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitTextSyle Fail:%{public}d", e.what());
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(50);
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_Bold);
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

@ -1,52 +0,0 @@
//
// Created on 2026/3/6.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#ifndef OPENCAX_TEXTSTYLE_H
#define OPENCAX_TEXTSTYLE_H
#include <map>
#include "NativeEGLOCCT/common.h"
#include <Prs3d_TextAspect.hxx>
#include <Graphic3d_AspectText3d.hxx>
//字体样式类型.主要用于区别该样式用于何处
enum FONT_STYLE_TYPE{
STYLE_AXIS,
STYLE_FACE,
};
struct TextStyleOpts{
};
namespace NativeOpenCAX{
class TextStyle{
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:
//一个字体管理样式对象管理.主要负责对字体样式的归一化集中管理
FONT_STYLE_TYPE currentFontType;
std::map<FONT_STYLE_TYPE, Handle(Prs3d_TextAspect)> fontStyle;
};
}
#endif //OPENCAX_TEXTSTYLE_H

View File

@ -63,7 +63,7 @@ bool Axis::InitAxis(Handle(AIS_InteractiveContext) & context) {
return false;
}
}
bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context,Handle(Prs3d_TextAspect) _textStyle) {
bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context) {
try {
//立方体面显示文本
const char16_t rightCube[] = u"右视图";
@ -86,11 +86,7 @@ bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context,Handle(Prs3d_Te
axiViewCube->SetFixedAnimationLoop(true);
axiViewCube->SetTextColor(Quantity_Color(Quantity_NOC_YELLOW2));
axiViewCube->SetFontHeight(30);
axiViewCube->SetFont("HarmonyOS Sans");
axiViewCube->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM));
axiViewCube->BoxEdgeStyle()->Aspect()->SetTextFont(_textStyle->Aspect()->TextFont());
axiViewCube->BoxCornerStyle()->Aspect()->SetTextFont(_textStyle->Aspect()->TextFont());
axiViewCube->BoxSideStyle()->Aspect()->SetTextFont(_textStyle->Aspect()->TextFont());
axiViewCube->SetTransformPersistence(
new Graphic3d_TransformPers(Graphic3d_TMF_TriedronPers, Aspect_TOTP_RIGHT_UPPER, NCollection_Vec2<int>(125, 125)));
context->Display(axiViewCube, true);

View File

@ -20,7 +20,7 @@ public:
Axis();
~Axis();
bool InitAxis(Handle(AIS_InteractiveContext)& context);
bool InitAxisCube(Handle(AIS_InteractiveContext) & context,Handle(Prs3d_TextAspect) _textStyle);
bool InitAxisCube(Handle(AIS_InteractiveContext) & context);
void SetRotationX(float x);
void SetRotationY(float y);
void SetRotationZ(float z);

View File

@ -4,7 +4,7 @@
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "Camera.h"
#include "V3dCa.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "CAMERA"
@ -12,9 +12,9 @@
namespace NativeOpenCAX {
Camera::Camera() : camera(nullptr) {}
Camera::~Camera() {}
bool Camera::InitCamera(Handle(V3d_View)& view) {
V3dCa::V3dCa() : camera(nullptr) {}
V3dCa::~V3dCa() {}
bool V3dCa::InitV3dCa(Handle(V3d_View)& view) {
try {
camera = new Graphic3d_Camera;
// 将角度转换为弧度并计算对应的缩放因子
@ -29,7 +29,7 @@ bool Camera::InitCamera(Handle(V3d_View)& view) {
return false;
}
}
void Camera::SetRotation(float xAngle, float yAngle) {
void V3dCa::SetRotation(float xAngle, float yAngle) {
gp_Pnt currentEye = camera->Eye();
gp_Pnt currentCenter = camera->Center();
gp_Dir currentUp = camera->Up();

View File

@ -12,11 +12,11 @@
#include <gp_Quaternion.hxx>
namespace NativeOpenCAX {
class Camera{
class V3dCa{
public:
Camera();
~Camera();
bool InitCamera(Handle(V3d_View)& view);
V3dCa();
~V3dCa();
bool InitV3dCa(Handle(V3d_View)& view);
void SetRotation(float xAngle, float yAngle);
public:
Handle(Graphic3d_Camera) camera;

View File

@ -0,0 +1,34 @@
//
// Created on 2026/3/6.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "V3dCtx.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "CTX"
#endif
namespace NativeOpenCAX {
V3dCtx::V3dCtx():
ctx(nullptr)
{
}
V3dCtx::~V3dCtx() {
}
bool V3dCtx::InitV3dCtx(Handle(V3d_Viewer)& viewer) {
ctx = new AIS_InteractiveContext(viewer);
if(!ctx.IsNull()){
HILOG_INFO(NATIVE_TAG, "InitCtx Done");
return true;
}else{
HILOG_INFO(NATIVE_TAG, "InitCtx Faile");
return false;
}
}
}

View File

@ -8,18 +8,21 @@
#define OPENCAX_CONTEXT_H
#include "NativeEGLOCCT/common.h"
#include <AIS_InteractiveContext.hxx>
#include <V3d_Viewer.hxx>
#include <AIS_InteractiveContext.hxx>
#include "../V3dDrawer/V3dDrawer.h"
namespace NativeOpenCAX{
class Context{
class V3dCtx{
public:
Context();
~Context();
bool InitContext(Handle(V3d_Viewer)& viewer,Handle(Prs3d_TextAspect) _textAspect);
V3dCtx();
~V3dCtx();
bool InitV3dCtx(Handle(V3d_Viewer)& viewer);
public:
Handle(AIS_InteractiveContext) context;
Handle(AIS_InteractiveContext) ctx;
};
}

View File

@ -0,0 +1,78 @@
//
// Created on 2026/3/30.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#ifndef NATIVE_TAG
#define NATIVE_TAG "V3DDRAWER"
#endif
#include "V3dDrawer.h"
namespace NativeOpenCAX {
V3dDrawer::V3dDrawer() :
drawer(nullptr),
v3d_IsoAspect(nullptr),
v3d_LineAspect(nullptr),
v3d_TextAspect(nullptr),
v3d_ShadingAspect(nullptr),
v3d_PlaneAspect(nullptr),
v3d_ArrowAspect(nullptr),
v3d_DatumAspect(nullptr),
v3d_DimAspect(nullptr)
{
}
V3dDrawer::~V3dDrawer() {}
bool V3dDrawer::InitV3dAllAspect(Handle(AIS_InteractiveContext)& ctx) {
try {
drawer=ctx->DefaultDrawer();
v3d_IsoAspect=drawer->UIsoAspect();
v3d_LineAspect=drawer->LineAspect();
v3d_TextAspect=drawer->TextAspect();
v3d_ShadingAspect=drawer->ShadingAspect();
v3d_PlaneAspect=drawer->PlaneAspect();
v3d_ArrowAspect=drawer->ArrowAspect();
v3d_DatumAspect=drawer->DatumAspect();
v3d_DimAspect=drawer->DimensionAspect();
InitV3dIsoAspectOpts();
InitV3dLineAspectOpts();
InitV3dTextAspectOpts();
InitV3dShadingAspectOpts();
InitV3dPlaneAspectOpts();
InitV3dArrowAspectOpts();
InitV3dDatumAspectOpts();
InitV3dDimAspectOpts();
HILOG_INFO(NATIVE_TAG, "InitV3dDrawer Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "InitV3dDrawer Fail:%{public}d", e.what());
return false;
}
}
void V3dDrawer::InitV3dIsoAspectOpts() {
v3d_IsoAspect->SetWidth(1.0);
}
void V3dDrawer::InitV3dLineAspectOpts() {
v3d_LineAspect->SetWidth(1.0);
}
void V3dDrawer::InitV3dTextAspectOpts() {
v3d_TextAspect->SetFont("HarmonyOS Sans");
v3d_TextAspect->SetHeight(35);
}
void V3dDrawer::InitV3dShadingAspectOpts() {
}
void V3dDrawer::InitV3dPlaneAspectOpts() {
}
void V3dDrawer::InitV3dArrowAspectOpts() {
}
void V3dDrawer::InitV3dDatumAspectOpts() {
}
void V3dDrawer::InitV3dDimAspectOpts() {
}
}

View File

@ -0,0 +1,66 @@
//
// Created on 2026/3/30.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#ifndef OPENCAX_V3DDRAWER_H
#define OPENCAX_V3DDRAWER_H
#include "AIS_InteractiveContext.hxx"
#include "NativeEGLOCCT/common.h"
#include "PrsMgr_PresentationManager.hxx"
#include <Prs3d_IsoAspect.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_TextAspect.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_PointAspect.hxx>
#include <Prs3d_PlaneAspect.hxx>
#include <Prs3d_ArrowAspect.hxx>
#include <Prs3d_DatumAspect.hxx>
#include <Prs3d_DimensionAspect.hxx>
namespace NativeOpenCAX{
class V3dDrawer {
public:
V3dDrawer();
~V3dDrawer();
bool InitV3dAllAspect(Handle(AIS_InteractiveContext)& ctx);
private:
void InitV3dIsoAspectOpts();
void InitV3dLineAspectOpts();
void InitV3dTextAspectOpts();
void InitV3dShadingAspectOpts();
void InitV3dPlaneAspectOpts();
void InitV3dArrowAspectOpts();
void InitV3dDatumAspectOpts();
void InitV3dDimAspectOpts();
public:
Handle(Prs3d_Drawer) drawer;
//曲面上等参线:颜色、线型(实线、虚线等)、线宽。
Handle(Prs3d_IsoAspect) v3d_IsoAspect;
//直线和线段的基本外观。这包括模型的边缘线、轴线、构造线
//颜色、线型、线宽。
Handle(Prs3d_LineAspect) v3d_LineAspect;
//定义文本的外观。例如,在模型旁边添加的标签、注释或尺寸数值等
//文本颜色、字体名称、字体大小、文本样式(粗体、斜体等)、文本方向
Handle(Prs3d_TextAspect) v3d_TextAspect;
//用于定义实体模型表面在着色模式下的外观。它决定了物体的填充颜色和材质特性
//前后表面颜色、材料属性(如环境光、漫反射、镜面反射系数)、线框/着色模式
Handle(Prs3d_ShadingAspect) v3d_ShadingAspect;
//用于定义平面的外观。例如,在可视化中表示一个无限大的平面对象或坐标系中的参考平面
//平面边界线的样式LineAspect、平面填充的样式InteriorStyle如网格、阴影等、颜色
Handle(Prs3d_PlaneAspect) v3d_PlaneAspect;
//用于定义箭头的外观。例如,向量的方向指示、坐标轴的箭头、尺寸标注的引出线箭头等
//箭头的样式(实心三角形、空心、线条等)、颜色、大小。
Handle(Prs3d_ArrowAspect) v3d_ArrowAspect;
//用于定义基准Datum的外观。在 CAD/CAM 和工程图纸中,基准是用于测量和定位的参考元素,如基准点、基准线、基准面。这个 Aspect 专门用来设置这些特殊参考元素的显示样式
//通常包含定义基准符号、线条、文本等组合元素的样式。
Handle(Prs3d_DatumAspect) v3d_DatumAspect;
//用于定义尺寸标注Dimension的外观。如上一个问题所述它控制着尺寸线、延伸线、箭头、文本等尺寸标注所有组成部分的视觉表现。
//尺寸线颜色/样式、文本颜色/字体、箭头样式、公差显示格式等。
Handle(Prs3d_DimensionAspect) v3d_DimAspect;
};
}
#endif //OPENCAX_V3DDRAWER_H

View File

@ -4,7 +4,7 @@
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "OpenGLGraphicDriver.h"
#include "V3dOGD.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "GRAPHIC_DRIVER"
@ -12,9 +12,9 @@
namespace NativeOpenCAX {
OpenGlGraphicDriver::OpenGlGraphicDriver() : graphicDriver(nullptr), displayConnection(nullptr) {}
OpenGlGraphicDriver::~OpenGlGraphicDriver() {}
bool OpenGlGraphicDriver::InitOpenGlGraphicDriver(EGLCore& eglCore) {
V3dOGD::V3dOGD() : graphicDriver(nullptr), displayConnection(nullptr) {}
V3dOGD::~V3dOGD() {}
bool V3dOGD::InitV3dOGD(EGLCore& eglCore) {
try {
displayConnection = new Aspect_DisplayConnection();

View File

@ -14,11 +14,11 @@
#include <Graphic3d_GraphicDriver.hxx>
namespace NativeOpenCAX{
class OpenGlGraphicDriver{
class V3dOGD{
public:
OpenGlGraphicDriver();
~OpenGlGraphicDriver();
bool InitOpenGlGraphicDriver(EGLCore& eglCore);
V3dOGD();
~V3dOGD();
bool InitV3dOGD(EGLCore& eglCore);
public:
Handle(OpenGl_GraphicDriver) graphicDriver;
Handle(Aspect_DisplayConnection) displayConnection;

View File

@ -4,7 +4,7 @@
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "View.h"
#include "V3dView.h"
#include "Quantity_NameOfColor.hxx"
#include "V3d_TypeOfAxe.hxx"
#include "V3d_TypeOfVisualization.hxx"
@ -15,12 +15,13 @@
namespace NativeOpenCAX {
View::View() : view(nullptr) {}
View::~View() {}
V3dView::V3dView() : view(nullptr) {}
V3dView::~V3dView() {}
bool View::InitView(Handle(V3d_Viewer) & viewer) {
bool V3dView::InitV3dView(Handle(V3d_Viewer) & viewer,Handle(Aspect_NeutralWindow)& win) {
try {
view = viewer->CreateView();
view->SetWindow(win, (Aspect_RenderingContext)eglGetCurrentContext());
HILOG_INFO(NATIVE_TAG, "InitView Done");
return true;
} catch (std::exception &e) {
@ -28,7 +29,7 @@ bool View::InitView(Handle(V3d_Viewer) & viewer) {
return false;
}
}
void View::SetViewOption(Handle(Prs3d_TextAspect) _textStyle) {
void V3dView::InitViewOption() {
// 设置渲染参数
view->SetImmediateUpdate(false);
view->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
@ -51,39 +52,28 @@ void View::SetViewOption(Handle(Prs3d_TextAspect) _textStyle) {
view->SetBackgroundColor(Quantity_NOC_GRAY90);
//左下角默认坐标系
view->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_ANTIQUEWHITE, 0.3, V3d_ZBUFFER);
// 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) {
view->ChangeRenderingParams().StatsTextAspect = text->Aspect();
view->ChangeRenderingParams().StatsTextHeight = text->Height();
}
void View::SetWin(Handle(Aspect_NeutralWindow) & win) {
view->SetWindow(win, (Aspect_RenderingContext)eglGetCurrentContext());
}
void View::SetClearColor(float r, float g, float b, float a) {
void V3dView::SetClearColor(float r, float g, float b, float a) {
clearColor = Quantity_Color(r, g, b, Quantity_TOC_RGB);
if (!view.IsNull()) {
view->SetBackgroundColor(clearColor);
}
}
void View::MustBeResized() { view->MustBeResized(); }
void V3dView::MustBeResized() { view->MustBeResized(); }
void View::Redraw() {
void V3dView::Redraw() {
view->Redraw();
}
void View::ResetView() {
void V3dView::ResetView() {
if (!view.IsNull()) {
view->SetProj(V3d_XposYnegZpos);
view->FitAll(0.05, false);
}
}
void View::SwitchView(std::string nView) {
void V3dView::SwitchView(std::string nView) {
V3d_TypeOfOrientation tV3d;
if (nView == "CMD_VIEW_FRONT") {
tV3d = V3d_Yneg;

View File

@ -7,7 +7,7 @@
#ifndef OPENCAX_VIEW_H
#define OPENCAX_VIEW_H
#include "NativeEGLOCCT/Context/Context.h"
#include "../V3dCtx/V3dCtx.h"
#include "NativeEGLOCCT/common.h"
#include <V3d_View.hxx>
#include <Aspect_NeutralWindow.hxx>
@ -16,14 +16,12 @@
namespace NativeOpenCAX{
class View{
class V3dView{
public:
View();
~View();
bool InitView(Handle(V3d_Viewer)& viewer);
void SetViewOption(Handle(Prs3d_TextAspect) _textStyle);
void SetWin(Handle(Aspect_NeutralWindow)& win);
void SetText(Handle(Prs3d_TextAspect) text);
V3dView();
~V3dView();
bool InitV3dView(Handle(V3d_Viewer)& viewer,Handle(Aspect_NeutralWindow)& win);
void InitViewOption();
void SetClearColor(float r, float g, float b, float a);
void MustBeResized();
void Redraw();

View File

@ -4,7 +4,7 @@
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "Viewer.h"
#include "V3dViewer.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "VIEWER"
@ -13,10 +13,10 @@
#include <V3d_AmbientLight.hxx>
namespace NativeOpenCAX {
Viewer::Viewer() : viewer(nullptr) {}
Viewer::~Viewer() {}
V3dViewer::V3dViewer() : viewer(nullptr) {}
V3dViewer::~V3dViewer() {}
bool Viewer::InitViewer(Handle(OpenGl_GraphicDriver)& graphicDriver) {
bool V3dViewer::InitV3dViewer(Handle(OpenGl_GraphicDriver)& graphicDriver) {
try {
viewer = new V3d_Viewer(graphicDriver);
viewer->SetDefaultBackgroundColor(Quantity_NOC_BLACK);
@ -29,5 +29,4 @@ bool Viewer::InitViewer(Handle(OpenGl_GraphicDriver)& graphicDriver) {
return false;
}
}
}

View File

@ -8,16 +8,17 @@
#define OPENCAX_VIEWER_H
#include "NativeEGLOCCT/common.h"
#include "PrsMgr_PresentationManager.hxx"
#include <V3d_Viewer.hxx>
#include <OpenGl_GraphicDriver.hxx>
namespace NativeOpenCAX{
class Viewer{
class V3dViewer{
public:
Viewer();
~Viewer();
bool InitViewer(Handle(OpenGl_GraphicDriver)& graphicDriver);
V3dViewer();
~V3dViewer();
bool InitV3dViewer(Handle(OpenGl_GraphicDriver)& graphicDriver);
public:
Handle(V3d_Viewer) viewer;
};

View File

@ -4,31 +4,31 @@
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "Window.h"
#include "V3dWin.h"
#ifndef NATIVE_TAG
#define NATIVE_TAG "WINDOW"
#endif
namespace NativeOpenCAX {
Window::Window():window(nullptr){
V3dWin::V3dWin():win(nullptr){
}
Window::~Window(){
V3dWin::~V3dWin(){
}
bool Window::InitWindow(int& width, int& height){
if(window.IsNull()){
window = new Aspect_NeutralWindow();
window->SetSize(width, height);
bool V3dWin::InitV3dWin(int& width, int& height){
if(win.IsNull()){
win = new Aspect_NeutralWindow();
win->SetSize(width, height);
HILOG_INFO(NATIVE_TAG, "Init Window Done");
return true;
}
HILOG_INFO(NATIVE_TAG, "Init Window Done");
return false;
}
void Window::Resize(int w, int h) {
window->SetSize(w, h);
window->DoResize();
void V3dWin::Resize(int w, int h) {
win->SetSize(w, h);
win->DoResize();
HILOG_ERROR(NATIVE_TAG,"Resize:(%{public}d,%{public}d)",w,h);
}
}

View File

@ -8,19 +8,18 @@
#define OPENCAX_WINDOW_H
#include "NativeEGLOCCT/common.h"
#include <Standard_TypeDef.hxx>
#include <Aspect_NeutralWindow.hxx>
namespace NativeOpenCAX {
class Window {
class V3dWin {
public:
Window();
~Window();
bool InitWindow(int& width,int& height);
V3dWin();
~V3dWin();
bool InitV3dWin(int& width,int& height);
void Resize(int w, int h);
public:
Handle(Aspect_NeutralWindow) window;
Handle(Aspect_NeutralWindow) win;
};
}