Within this brief tutorial, you will learn to setup your first, own Simcenter STAR-CCM+ plugin to customize the default installation. It will provide a custom menu with an action that prints the "Hello World" message in the output log.
Attachments: | MyCustomModule.zip (26 KB) |
XML Layer | (not yet created) This file can be used to get access to the Simcenter STAR-CCM+ GUI elements such as the menu, toolbar, or keyboard shortcuts. You will use this file later to change the order of the menu entries. |
Module Manifest | This file contains some basic information about your module that are important for its installation and startup. You will use it to control the versioning of your module and to declare your module dependencies so that all the needed libraries are available during runtime. |
Build Script | You can use this file in order to automate the steps that are necessary after code development and before publication, such as compiling, creation of the NBM file, signing or JAVA-doc creation. |
Project Properties | Contains the project properties that can be modified using this file or right-click on your project in the tree and then select "Properties" from the context menu. You will use this file later to include the STAR-CCM+ API. |
platform.build.dir=C\:\\Program Files\\Siemens\\17.02.006-R8\\STAR-CCM+17.02.006-R8\\star\\lib\\java\\platform
dir /s /b "C:\Program Files\Siemens\17.02.006-R8\STAR-CCM+17.02.006-R8\star\lib\java\platform\*.jar" >> filelist.txt
C:/Program Files/Siemens/17.02.006-R8/STAR-CCM+17.02.006-R8/star/lib/java/platformwith
cp.extra=${platform.build.dir}
\r\nC:/Program Files/Siemens/17.02.006-R8/STAR-CCM+17.02.006-R8/star/lib/java/platformwith
\:${platform.build.dir}Here, "\r" means "return" (not present in text files created in Linux) and "\n" means "new line". This step will essentially remove all line breaks and only a single line remains.
deploy.dir=D:/your/path/to/NBM build.major.number=2022 build.minor.number=1 build.revision.number=0Your Project Properties file should now look as follows:
package mycustommodule; import star.common.*; public class HelloWorld extends StarMacro { @Override public void execute() { getActiveSimulation().println("Hello World"); } }This code would simply print the "Hello World" message into the output log. In this place any other arbitrary Simcenter STAR-CCM+ macro could be used instead. If NetBeans does not complain about missing packages, then the library inclusion was successful and you can proceed with the next steps, otherwise review the classpath string in the Project Properties file.
After adding your macro to your NBM project, you have to think about, how you can make a call of the HelloWorld class from within the Simcenter STAR-CCM+ GUI. Usually, when you execute macros, you may use the macro toolbar and use the file browser to select the macro. An NBM-plugin provides the opportunity to create a custom menu or toolbar entry or a custom keyboard shortcut to execute your macro. In order to achieve that, you need an additional piece of code: An extension of the Action-class that controls the appearance of your function within the Simcenter STAR-CCM+ GUI and makes a call of your macro. Following classes are available:
LocalizedCallableSystemAction | Action can be performed without a present simulation |
SimulationAction | Action requires a present simulation and can be executed even during a running simulation |
ActiveSimulationAction | Action requires a present simulation but cannot be executed during a running simulation |
It depends on the type of macro whether at least one simulation must be loaded, or the macro can also be executed during a simulation run. The "Hello World" macro can also be played during a simulation run without any problems and is therefore of type "SimulationAction".
Create a new Java class with the name "MyAction" and replace the default code by following:
package mycustommodule; import org.openide.awt.*; import star.common.StarScript; import star.coremodule.actions.SimulationAction; import star.locale.annotation.StarAction; // Apply action annotations @StarAction(display = "Hello World", hint = "Displays Hello World Message") @ActionID(id = "mycustommodule.MyAction", category = "MyModule") @ActionRegistration(displayName = "Hello World", lazy = false) @ActionReferences(value = { @ActionReference(path = "Toolbars/HelloWorld", position = 1), @ActionReference(path = "Shortcuts", name = "D-Q"), @ActionReference(path = "Menu/MyModule", position = 1)}) // Extend the SimulationAction class public class MyAction extends SimulationAction { private static final String ICON = "mycustommodule/icons/helloworld.png"; @Override protected String iconResource() { return ICON; } @Override public void performAction() { // Create a separate thread Thread t = new Thread(new Runnable() { @Override public void run() { // Run macro as StarScript StarScript sc = new StarScript(getSimulationProcessObject().getSimulation(), new HelloWorld()); sc.play(); } }); t.start(); } }Let’s discuss following sections of the above code:
OpenIDE-Module-Module-Dependencies: star.coremodule > 16.3Whenever you update your module, the OpenIDE-Module-Specification-Version number needs to be increased. You could automate this step by make an entry within your build script. The OpenIDE-Module-Module-Dependencies statement will ensure that the necessary libraries are loaded on runtime of your NBM-plugin.
BUILD SUCCESSFUL (total time: 21 seconds)
Now, launch Simcenter STAR-CCM+ and install you freshly build NBM file under Tools > Plugins > Downloaded.
After a restart of STAR-CCM+ you will notice a new icon on the toolbar and a new menu entry, that will become active after you open a simulation file.
<folder name="Menu"> <folder name="MyModule"> <attr name="position" intvalue="300"/> <file name="mycustommodule-MyAction.shadow"> <!--mycustommodule.MyAction--> <attr name="originalFile" stringvalue="Actions/MyModule/mycustommodule-MyAction.instance"/> <attr intvalue="1" name="position"/> </file> </folder> </folder>
<?xml version="1.0" encoding="UTF-8"?> <project name="mycustommodule" default="allstep" basedir="."> <description>Builds, tests, and runs the project mycustommodule.</description> <import file="nbproject/build-impl.xml"/> <target name="allstep" depends="revision,netbeans,nbm"> <echo message="Your new NBM file has been created..." /> </target> <target name="revision"> <propertyfile file="nbproject/project.properties"> <entry key="build.revision.number" type="int" operation="+" value="1"/> </propertyfile> <antcall target="update-global-version"/> </target> <target name="update-global-version"> <property file="nbproject/project.properties"/> <echo>Building: ${build.major.number}.${build.minor.number}.${build.revision.number}</echo> <manifest mode="update" file="manifest.mf"> <attribute name="OpenIDE-Module-Specification-Version" value="${build.major.number}.${build.minor.number}.${build.revision.number}"/> </manifest> </target> </project>To execute your own function, you can right-click on the Build Script and select Run Target > allstep. Now your NBM file with a new revision number will be created. The updated version is then recognized by Simcenter STAR-CCM+ so that you can install the new version. After a restart of Simcenter STAR-CCM+, you will notice that your menu is now placed at the right-end. You can now open a simulation and execute your function by selecting it from the menu, from the toolbar or by hitting CTRL+Q on your keyboard. The output log will print: "Hello World". As reference, you may download the NetBeans project files that are attached to this article. Congratulations to your first own Simcenter STAR-CCM+ plugin!