109 lines
5.1 KiB
C++
109 lines
5.1 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 "Graphic3d_NameOfMaterial.hxx"
|
|
#include "Prs3d_DatumMode.hxx"
|
|
#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 {
|
|
//坐标显示文本
|
|
const char16_t x_Axis[] = u"X";
|
|
const char16_t y_Axis[] = u"Y";
|
|
const char16_t z_Axis[] = u"Z";
|
|
// 创建场景中心参考坐标系
|
|
gp_Ax2 theAxis;
|
|
double theSize =250; // 大小
|
|
// 设置原点
|
|
theAxis.SetLocation(gp_Pnt(0, 0, 0));
|
|
// 以世界坐标轴为准,设置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_WireFrame);
|
|
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_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_Axis);
|
|
axiTrihedron->SetLabel(Prs3d_DP_YAxis, y_Axis);
|
|
axiTrihedron->SetLabel(Prs3d_DP_ZAxis, z_Axis);
|
|
axiTrihedron->SetSize(theSize);
|
|
axiTrihedron->SetTransformPersistence(new Graphic3d_TransformPers(Graphic3d_TMF_ZoomPers, anOrg));
|
|
axiTrihedron->Attributes()->SetZLayer(Graphic3d_ZLayerId_Topmost);
|
|
context->Display(axiTrihedron, true);
|
|
HILOG_INFO(NATIVE_TAG, "InitLocalAxis Done");
|
|
return true;
|
|
} catch (std::exception &e) {
|
|
HILOG_INFO(NATIVE_TAG, "InitLocalAxis Fail:%s", e.what());
|
|
return false;
|
|
}
|
|
}
|
|
bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context) {
|
|
try {
|
|
//立方体面显示文本
|
|
const char16_t rightCube[] = u"右视图";
|
|
const char16_t backCube[] = u"后视图";
|
|
const char16_t topCube[] = u"俯视图";
|
|
const char16_t leftCube[] = u"左视图";
|
|
const char16_t frontCube[] = u"前视图";
|
|
const char16_t bottomCube[] = u"仰视图";
|
|
// 视图立方体
|
|
axiViewCube = new AIS_ViewCube();
|
|
axiViewCube->SetBoxSideLabel(V3d_Xpos, TCollection_AsciiString(rightCube));
|
|
axiViewCube->SetBoxSideLabel(V3d_Ypos, TCollection_AsciiString(backCube));
|
|
axiViewCube->SetBoxSideLabel(V3d_Zpos, TCollection_AsciiString(topCube));
|
|
axiViewCube->SetBoxSideLabel(V3d_Xneg, TCollection_AsciiString(leftCube));
|
|
axiViewCube->SetBoxSideLabel(V3d_Yneg, TCollection_AsciiString(frontCube));
|
|
axiViewCube->SetBoxSideLabel(V3d_Zneg, TCollection_AsciiString(bottomCube));
|
|
axiViewCube->SetDrawAxes(false);
|
|
axiViewCube->SetSize(100, true);
|
|
axiViewCube->SetTransparency(0.0);
|
|
axiViewCube->SetFixedAnimationLoop(true);
|
|
axiViewCube->SetTextColor(Quantity_Color(Quantity_NOC_YELLOW2));
|
|
axiViewCube->SetFontHeight(30);
|
|
axiViewCube->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM));
|
|
axiViewCube->SetTransformPersistence(
|
|
new Graphic3d_TransformPers(Graphic3d_TMF_TriedronPers, Aspect_TOTP_RIGHT_UPPER, NCollection_Vec2<int>(125, 125)));
|
|
context->Display(axiViewCube, 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; }
|
|
} |