创建第一个任务:导入几何
第一个任务将几何导入 Simcenter STAR-CCM+。该任务的设计有互动性,也就是说当您单击任务内的链接时,会出现导入对话框。
开始加载:
-
将新的 java 类添加到助手程序包并命名为 Task01ImportGeometry。
-
将以下代码复制并粘贴至 Task01ImportGeometry 类,覆盖所有内容:
package Assistant; import java.io.File; import java.util.Collection; import javax.swing.JFileChooser; import star.assistant.Task; import star.assistant.ui.FunctionTaskController; import star.common.GeometryPart; import star.common.Simulation; import star.common.SimulationPartManager; import star.meshing.PartImportManager; public class Task01ImportGeometry extends Task { public Task01ImportGeometry() { } public class ImportGeometryTaskController extends FunctionTaskController { public void importSurfaceMeshDialog() { //open a file chooser JFileChooser fileChooser = new JFileChooser(); if (fileChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) { return; } File cadFile = fileChooser.getSelectedFile(); //import the part Simulation simulation_0 = getSimulation(); PartImportManager partImportManager_0 = simulation_0.get(PartImportManager.class); //use default import options partImportManager_0.importCadPart(cadFile.getPath(), "SharpEdges", 30.0, 2, true, 1.0E-5, true, false); //add the new part to the lookup Collection<GeometryPart> new_parts = simulation_0.get(SimulationPartManager.class).getParts(); if (!new_parts.isEmpty()) { addToTaskLookup(new_parts.iterator().next()); } //create a Geometry Scene simulation_0.getSceneManager().createGeometryScene("Geometry Scene", "Outline", "Geometry", 1); Scene scene_0 = simulation_0.getSceneManager().getScene("Geometry Scene 1"); scene_0.initializeAndWait(); PartDisplayer partDisplayer_1 = ((PartDisplayer) scene_0.getCreatorDisplayer()); partDisplayer_1.initialize(); PartDisplayer partDisplayer_0 = ((PartDisplayer) scene_0.getDisplayerManager().getDisplayer("Outline 1")); partDisplayer_0.initialize(); PartDisplayer partDisplayer_2 = ((PartDisplayer) scene_0.getDisplayerManager().getDisplayer("Geometry 1")); partDisplayer_2.initialize(); scene_0.open(true); CurrentView currentView_0 = scene_0.getCurrentView(); currentView_0.setInput(new DoubleVector(new double[]{0.07000000029802322, 0.02000000048428774, 0.0}), new DoubleVector(new double[]{-0.14607243684130425, 0.11741414039370678, 0.17860456694301519}), new DoubleVector(new double[]{0.20083797287207372, 0.9415226723669483, -0.2705534440210218}), 0.07747426272518879, 0); } } }
- 保存文件。
注 | 当编写自己的代码时,NetBeans 自动建议要导入的类别。需要注意的行都标有红色感叹号。在这些线上同时按下 "Alt" + "Enter" 以显示建议项。现在可忽略任何警告。 |