Java 示例

以下示例显示响应的几种用法,以从查询诊断获取特定信息。

作为前提条件,本节包含所需的导入路径和基本 Java 代码。

这些示例汇总如下:

  • 整数 — 访问节点 ID
  • 整数矢量 — 访问属于边界的面数
  • 双精度 — 访问选定边的总长度
  • 双矢量 — 访问节点的 X、Y 和 Z 坐标
  • 客户端 - 服务器对象 — 访问查询单位、查询坐标系以及面所属的零部件表面或边界。

导入路径

要访问和使用查询响应,将以下导入部分添加到宏:


import star.base.neo.*;
import star.common.*;
import star.meshing.*;

前提条件

要使用这些示例,将以下 Java 代码添加到宏:


Simulation simulation_0 = getActiveSimulation();
PartSurfaceMeshWidget partSurfaceMeshWidget_0 =
  simulation_0.get(PartSurfaceMeshWidget.class);
SurfaceMeshWidgetQueryController
surfaceMeshWidgetQueryController_0 =
  partSurfaceMeshWidget_0.getControllers()
  .getController(
  SurfaceMeshWidgetQueryController.class
  );

Int 示例

以下示例说明如何使用整数访问选定节点的 ID:


NeoProperty response = 
  surfaceMeshWidgetQueryController_0.queryVertexXYZ();
int vertId = response.getInt("VertexId");
simulation_0.println(
  "Vertex ID: " + vertId
  );

IntVector 示例

以下示例说明如何使用整数矢量访问属于边界的选定面数:


NeoProperty response = 
  surfaceMeshWidgetQueryController_0
  .queryFaceRegionBoundaryList();
IntVector faceCount = 
  response.getIntVector("SelectedBoundaryFaceCount");
simulation_0.println(
  "Face count: " + faceCount.getComponent(0)
  );

Double 示例

以下示例说明如何使用双精度访问所有选定边的总长度:


NeoProperty response = 
  surfaceMeshWidgetQueryController_0.queryEdgeLength();
simulation_0.println(
  "Total length: " + response.getDouble("TotalLength")
  );

DoubleVector 示例

以下示例说明如何使用双矢量访问选定节点的 X、Y 和 Z 坐标:


NeoProperty response =
  surfaceMeshWidgetQueryController_0.queryVertexXYZ();
DoubleVector labXYZ = response.getDoubleVector("LabXYZ");
simulation_0.println(
  "Vertex Coordinates: " + labXYZ
  );
simulation_0.println(
  "Vertex X-Coordinate: " + labXYZ.toDoubleArray()[0]
  );

ClientServerObject 示例

以下示例说明如何使用客户端 - 服务器对象。

单位

此示例访问查询的首选单位:


NeoProperty response =
  surfaceMeshWidgetQueryController_0.queryVertexXYZ();
Units units = 
  response.<Units>getObject(
  "LengthUnits",simulation_0.getObjectRegistry()
  );
simulation_0.println(
  "Units: " + units.getPresentationName()
  );

坐标系

此示例访问查询的局部坐标系:


NeoProperty response =
  surfaceMeshWidgetQueryController_0.queryVertexXYZ();
CoordinateSystem csys =
  response.<CoordinateSystem>getObject(
  "LocalCoordinateSystem",simulation_0.getObjectRegistry()
  );
simulation_0.println(
  "Local CSys: " + csys.getPresentationName()
  );

零部件表面或边界

此示例访问选定的面所属的第一个零部件表面:


NeoProperty response =
  surfaceMeshWidgetQueryController_0.
  queryFacePartSurfaceList();
Vector<PartSurface> partSurfaces =
  response.<PartSurface>getObjectVector(
  "SelectedPartSurfaces",simulation_0.getObjectRegistry()
  );
simulation_0.println(
  "First part surface: " + partSurfaces.get(0)
  );

此示例访问选定的面所属的第一个边界:


NeoProperty response =
  surfaceMeshWidgetQueryController_0
  .queryFaceRegionBoundaryList();
Vector<Boundary> boundaries =
  response.<Boundary>getObjectVector(
  "SelectedBoundarySurfaces",
  simulation_0.getObjectRegistry()
  );
simulation_0.println(
  "First boundary: " + boundaries.get(0)
  );