/* STAR-CCM+ Macro: rotate_zoom_translate_GUI.java //------------------------------------------------------------------ // PREFACE //------------------------------------------------------------------ Java macro that can be used to give the user a range of control on rotation, translation and zooming of a scene to create an animation. ## WRITTEN BY LILUNNAHAR DEJU ## Script written: 07/13/2015 * */ package macro; import star.common.*; import java.io.File; import javax.swing.JOptionPane; import javax.swing.*; import star.base.neo.DoubleVector; import star.base.neo.IntVector; import star.base.neo.NeoObjectVector; import star.vis.CurrentView; import star.vis.Scene; public class rotate_zoom_translate_GUI extends StarMacro { public void execute() { execute0(); } private void execute0() { // We will make a sim instance of our simulation class: Simulation sim = getActiveSimulation(); File imagesGUI; int count=1; // ------------------------------------------------------------------------- //Dialog box apprears for scene name input String inputScene = JOptionPane.showInputDialog("Enter the scene name:"); // Print to the STAR-CCM+ output window: sim.println("Scene " + inputScene + " selected."); Scene scene_0 = sim.getSceneManager().getScene(inputScene); CurrentView currentView_0 = scene_0.getCurrentView(); //create cartesian coordinate JOptionPane.showMessageDialog(null, "A Cartesian Coordinate system will be created " + inputScene, "Message", JOptionPane.INFORMATION_MESSAGE); LabCoordinateSystem labCoordinateSystem_0 = sim.getCoordinateSystemManager().getLabCoordinateSystem(); CartesianCoordinateSystem cartesianCoordinateSystem_0 = labCoordinateSystem_0.getLocalCoordinateSystemManager().createLocalCoordinateSystem(CartesianCoordinateSystem.class, "Cartesian"); sim.println("Cartesian coordinate is created. "); JOptionPane.showMessageDialog(null, "The Cartesian Coordinate will be assigned to the scence " + inputScene, "Message", JOptionPane.INFORMATION_MESSAGE); currentView_0.setCoordinateSystem(cartesianCoordinateSystem_0); sim.println("Cartisian coordinate is assigned to " + inputScene + " scene"); int diag1; //Dialog box pop up for selection of movement do { Object[] possibleMove = {"Rotate", "Zoom", "Translate"}; Object selectedMove = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleMove, possibleMove[0]); if (selectedMove == "Rotate") { double angle = 0.0175; int filename = 0; //rotation angle selection String[] possibleAngles = {"1", "2", "5"}; String selectedAngle = (String) JOptionPane.showInputDialog(null, "Select the angle of rotation for each frame (values in degree) ", "Single Choice Dropdown", JOptionPane.INFORMATION_MESSAGE, null, possibleAngles, possibleAngles[0]); int AngleChosen = Integer.parseInt(selectedAngle); double RAngle = angle * AngleChosen; String TotalAngle = JOptionPane.showInputDialog("Enter total angle of rotation (in degree):"); int TAngle = Integer.parseInt(TotalAngle); int iLoop = TAngle / AngleChosen; //view up direction selection String[] possibleUp = {"X", "Y", "Z", "-X", "-Y", "-Z"}; String selectedUp = (String) JOptionPane.showInputDialog(null, "Choose one", "View Up direction", JOptionPane.INFORMATION_MESSAGE, null, possibleUp, possibleUp[1]); Units units_0 = sim.getUnitsManager().getPreferredUnits(new IntVector(new int[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})); switch (selectedUp) { case "X": for (double i = 0; i < iLoop; i = i + 1) { cartesianCoordinateSystem_0.getLocalCoordinateSystemManager().rotateLocalCoordinateSystems(new NeoObjectVector(new Object[]{cartesianCoordinateSystem_0}), new DoubleVector(new double[]{1.0, 0.0, 0.0}), new NeoObjectVector(new Object[]{units_0, units_0, units_0}), RAngle, labCoordinateSystem_0); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "rotate_"+ filename + ".png"), 1, 1920, 1080); filename++; } break; case "Y": for (double i = 0; i < iLoop; i = i + 1) { cartesianCoordinateSystem_0.getLocalCoordinateSystemManager().rotateLocalCoordinateSystems(new NeoObjectVector(new Object[]{cartesianCoordinateSystem_0}), new DoubleVector(new double[]{0.0, 1.0, 0.0}), new NeoObjectVector(new Object[]{units_0, units_0, units_0}), RAngle, labCoordinateSystem_0); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "rotate_"+ filename + ".png"), 1, 1920, 1080); filename++; } break; case "Z": for (double i = 0; i < iLoop; i = i + 1) { cartesianCoordinateSystem_0.getLocalCoordinateSystemManager().rotateLocalCoordinateSystems(new NeoObjectVector(new Object[]{cartesianCoordinateSystem_0}), new DoubleVector(new double[]{0.0, 0.0, 1.0}), new NeoObjectVector(new Object[]{units_0, units_0, units_0}), RAngle, labCoordinateSystem_0); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "rotate_"+ filename + ".png"), 1, 1920, 1080); filename++; } break; case "-X": for (double i = 0; i < iLoop; i = i + 1) { cartesianCoordinateSystem_0.getLocalCoordinateSystemManager().rotateLocalCoordinateSystems(new NeoObjectVector(new Object[]{cartesianCoordinateSystem_0}), new DoubleVector(new double[]{-1.0, 0.0, 0.0}), new NeoObjectVector(new Object[]{units_0, units_0, units_0}), RAngle, labCoordinateSystem_0); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "rotate_"+ filename + ".png"), 1, 1920, 1080); filename++; } break; case "-Y": for (double i = 0; i < iLoop; i = i + 1) { cartesianCoordinateSystem_0.getLocalCoordinateSystemManager().rotateLocalCoordinateSystems(new NeoObjectVector(new Object[]{cartesianCoordinateSystem_0}), new DoubleVector(new double[]{0.0, -1.0, 0.0}), new NeoObjectVector(new Object[]{units_0, units_0, units_0}), RAngle, labCoordinateSystem_0); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "rotate_"+ filename + ".png"), 1, 1920, 1080); filename++; } break; case "-Z": for (double i = 0; i < iLoop; i = i + 1) { cartesianCoordinateSystem_0.getLocalCoordinateSystemManager().rotateLocalCoordinateSystems(new NeoObjectVector(new Object[]{cartesianCoordinateSystem_0}), new DoubleVector(new double[]{0.0, 0.0, -1.0}), new NeoObjectVector(new Object[]{units_0, units_0, units_0}), RAngle, labCoordinateSystem_0); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "rotate_"+ filename + ".png"), 1, 1920, 1080); filename++; } break; } } if (selectedMove == "Zoom") { double para_scale = currentView_0.getParallelScale(); String inputScale = JOptionPane.showInputDialog("Your current view scale is: " + para_scale + "\nPlease enter new value for view scale" + "\nHint: Lower value will zoom in and higher value will make zoom out"); double inScale = Double.parseDouble(inputScale); sim.println("entered scale value " + inScale); int filename = 0; int totalNumI = 20; for (int i = 0; i <= totalNumI; i = i + 1) { double incrm = (inScale - para_scale) / totalNumI; double scale = para_scale + incrm * i; currentView_0.setParallelScale(scale); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "zoom_"+ filename + ".png"), 1, 1920, 1080); filename++; } } if (selectedMove == "Translate") { int filetranslate = 0; JTextField xField = new JTextField("0",5); JTextField yField = new JTextField ("0",5); JTextField zField = new JTextField("1", 5); JPanel myPanel = new JPanel(); myPanel.add(new JLabel("x:")); myPanel.add(xField); myPanel.add(new JLabel("m")); myPanel.add(Box.createVerticalStrut(15)); myPanel.add(new JLabel("y:")); myPanel.add(yField); myPanel.add(new JLabel("m")); myPanel.add(Box.createVerticalStrut(15)); myPanel.add(new JLabel("z:")); myPanel.add(zField); myPanel.add(new JLabel("m")); JOptionPane.showMessageDialog(null,myPanel, "Please enter values", JOptionPane.OK_CANCEL_OPTION); String xValue = xField.getText(); double xValueD = Double.parseDouble(xValue); String yValue = yField.getText(); double yValueD = Double.parseDouble(yValue); String zValue = zField.getText(); double zValueD = Double.parseDouble(zValue); Units units_0 = sim.getUnitsManager().getPreferredUnits(new IntVector(new int[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})); for (double i = 0; i < 20; i = i + 1) { cartesianCoordinateSystem_0.getLocalCoordinateSystemManager().translateLocalCoordinateSystems(new NeoObjectVector(new Object[]{cartesianCoordinateSystem_0}), new DoubleVector(new double[]{xValueD, yValueD, zValueD}), new NeoObjectVector(new Object[]{units_0, units_0, units_0}), labCoordinateSystem_0); scene_0.printAndWait(resolvePath("imagesGUI\\action_" +count + "translate_"+ filetranslate + ".png"), 1, 1920, 1080); filetranslate++; } } diag1 = JOptionPane.showConfirmDialog(null, "More?", "Would you like to continue?",JOptionPane.YES_NO_OPTION); count++; }while (diag1 ==0); } }