ForCAX/entry/src/main/cpp/NativeEGLOCCT/Axis/Axis.cpp

95 lines
4.4 KiB
C++

//
// Created on 2026/3/23.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".
#include "Axis.h"
#include "Quantity_NameOfColor.hxx"
#ifndef NATIVE_TAG
#define NATIVE_TAG "AXIS"
#endif
namespace NativeOpenCAX {
Axis::Axis() : axiPlacement(nullptr), axiTrihedron(nullptr), axiViewCube(nullptr) {}
Axis::~Axis() {}
bool Axis::InitAxis(Handle(AIS_InteractiveContext) & context) {
try {
// 创建场景中心参考坐标系
gp_Ax2 theAxis;
double theSize = 60; // 大小
// 设置原点
theAxis.SetLocation(gp_Pnt(10, 10, 10));
// 以世界坐标轴为准,设置Z,X轴方向
theAxis.SetDirection(gp_Dir(0, 0, 1));
theAxis.SetXDirection(gp_Dir(1, 0, 0));
gp_Pnt anOrg = theAxis.Location();
axiPlacement = new Geom_Axis2Placement(theAxis);
axiPlacement->SetLocation(gp::Origin());
axiTrihedron = new AIS_Trihedron(axiPlacement);
axiTrihedron->SetDatumDisplayMode(Prs3d_DM_Shaded);
axiTrihedron->SetDrawArrows(true);
axiTrihedron->Attributes()->DatumAspect()->LineAspect(Prs3d_DP_XArrow)->SetWidth(2);
axiTrihedron->Attributes()->DatumAspect()->LineAspect(Prs3d_DP_YArrow)->SetWidth(2);
axiTrihedron->Attributes()->DatumAspect()->LineAspect(Prs3d_DP_ZArrow)->SetWidth(2);
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->SetLabel(Prs3d_DP_XAxis, "X");
axiTrihedron->SetLabel(Prs3d_DP_YAxis, "Y");
axiTrihedron->SetLabel(Prs3d_DP_ZAxis, "Z");
axiTrihedron->SetSize(theSize);
axiTrihedron->SetTransformPersistence(new Graphic3d_TransformPers(Graphic3d_TMF_ZoomPers, anOrg));
axiTrihedron->Attributes()->SetZLayer(Graphic3d_ZLayerId_Topmost);
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());
return false;
}
}
bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context) {
try {
// 视图立方体
axiViewCube = new AIS_ViewCube();
axiViewCube->SetBoxSideLabel(V3d_Xpos, "Right");
axiViewCube->SetBoxSideLabel(V3d_Ypos, "Back");
axiViewCube->SetBoxSideLabel(V3d_Zpos, "Top");
axiViewCube->SetBoxSideLabel(V3d_Xneg, "Left");
axiViewCube->SetBoxSideLabel(V3d_Yneg, "Front");
axiViewCube->SetBoxSideLabel(V3d_Zneg, "Bottom");
axiViewCube->SetDrawAxes(false);
axiViewCube->SetSize(60, true);
axiViewCube->SetTransparency(0.5);
axiViewCube->SetTextColor(Quantity_Color(Quantity_NOC_BLUE1));
axiViewCube->SetFontHeight(30);
axiViewCube->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM));
axiViewCube->SetTransformPersistence(
new Graphic3d_TransformPers(Graphic3d_TMF_TriedronPers, Aspect_TOTP_RIGHT_UPPER, Graphic3d_Vec2i(100, 100)));
context->Display(axiViewCube, Standard_True);
HILOG_INFO(NATIVE_TAG, "Init Axi View Cube Done");
return true;
} catch (std::exception &e) {
HILOG_INFO(NATIVE_TAG, "Init Axi View Cube Fail:%{public}d", e.what());
return false;
}
}
void Axis::SetRotationX(float rx) { rotationX = rx; }
void Axis::SetRotationY(float ry) { rotationX = ry; }
void Axis::SetRotationZ(float rz) { rotationX = rz; }
void Axis::SetTranslationX(float tx) { translationX = tx; }
void Axis::SetTranslationY(float ty) { translationX = ty; }
void Axis::SetTranslationZ(float tz) { translationX = tz; }
void Axis::SetZoomLevel(float level) { zoomLevel = level; }
}