Creating a New Empty ModelThe main class for building and interacting with a model at the highest level is the DtModelManager class found in the com.engineous.sdk.model package. DtModelManager modelMgr = DtModelManager.createEmptyModel(); This class creates an empty model that does not have a root component in it. Adding components is described later. The Dt prefix refers to this class as “design time” (a class used for building and editing models) and is not applicable or has no use at “run time.” Loading an Existing ModelA common scenario is to start with an existing model as a template and then use the API to edit various aspects of that model (instead of always building one from scratch). InputStream inputStream = new FileInputStream("c:\\temp\\MyTemplateModel.zmf"); DtModelManager modelMgr = DtModelManager.createModel(inputStream); Accessing and Setting Model Properties Using the ModelProperties ObjectModelProperties modelProps = modelMgr.getModelProperties(); modelProps.setModelName("My Model"); modelProps.setModelDescription("This is my model…"); modelProps.setUseFixedSeed(true); modelProps.setDBLookupMode(ModelProperties.MODEL_DBLUMODE_ALL_J OBS); If you do not make the call to setModelName, you will see validation warnings if you open the model in the Design Gateway. Therefore, it is suggested that you always set the model name. For other properties that can be accessed and set using the ModelProperties object, refer to the javadocs in the following directory: <Isight_install_directory>/Doc/docs/api/_index/main.html Creating a Component and Setting the Root Component for the ModelDtComponent myTask = DtModelManager.createComponent("com.engineous.component.Task ", "My root task"); modelMgr.setRootComponent(myTask); The root component does not need to be a Task. It can be any component that is published to the Library, specified using the full path name under which that component is published. Creating Components and Adding Them to the Existing Task ComponentDtComponent mySimcode = DtModelManager.createComponent("com.engineous.component.Simc ode", "My simcode"); myTask.addComponent(mySimcode, true); The “true” value for the second argument adds the component to the end of the simulation process flow. DtComponent myExcel = DtModelManager.createComponent("com.engineous.component.Exce l", "My Excel"); myTask.addComponent(myExcel); The true argument for the second argument is not provided, and the component is added as a child of the Task but is left out of the simulation process flow. The simulation process flow will need to be constructed as described below. Creating Simulation Process Flow (control flow) Links Among ComponentsIn this example the Excel component is inserted before the Simcode. First, you must remove one of the existing control flows (between the start node and the Simcode). DtControlFlow cf = myTask.getControlFlow(null, mySimcode.getName()); myTask.removeControlFlow(cf); DtControlFlow cf1 = DtModelManager.createControlFlow(null,myExcel); You must use null to represent the start and end nodes. myTask.addControlFlow(cf1); DtControlFlow cf2 = DtModelManager.createControlFlow(myExcel,mySimcode); myTask.addControlFlow(cf2); If desired, conditional expressions can be applied to the simulation process flow links to determine whether or not the flow of execution should proceed along that path. The conditional expressions are used in the Calculator component, except parameter names which are preceded by the component name. If the component or parameter name contains spaces or other punctuation, enclose in single quotes. cf1.setCondition("‘My Simcode.a’>1"); cf1.setLabel("a > 1"); cf2.setCondition("‘My Simcode.a’<=1"); cf2.setLabel("a <= 1"); |