Skip to content

Instantly share code, notes, and snippets.

@gidili
Created June 27, 2015 12:00
Show Gist options
  • Save gidili/9c576c2e11f541ff160e to your computer and use it in GitHub Desktop.
Save gidili/9c576c2e11f541ff160e to your computer and use it in GitHub Desktop.
snippets to save
private void init(GeppettoModel geppettoModel)
{
this.clearWatchLists();
// retrieve model interpreters and simulators
CreateModelInterpreterServicesVisitor createServicesVisitor = new CreateModelInterpreterServicesVisitor(modelInterpreters, geppettoManagerCallbackListener);
geppettoModel.accept(createServicesVisitor);
LoadSimulationVisitor loadSimulationVisitor = new LoadSimulationVisitor(modelInterpreters, instancePathToIModelMap, geppettoManagerCallbackListener);
geppettoModel.accept(loadSimulationVisitor);
CreateRuntimeTreeVisitor runtimeTreeVisitor = new CreateRuntimeTreeVisitor(modelInterpreters, instancePathToIModelMap, runtimeTreeRoot, geppettoManagerCallbackListener);
geppettoModel.accept(runtimeTreeVisitor);
runtimeTreeRoot = runtimeTreeVisitor.getRuntimeModel();
PopulateVisualTreeVisitor populateVisualVisitor = new PopulateVisualTreeVisitor(geppettoManagerCallbackListener);
runtimeTreeRoot.apply(populateVisualVisitor);
// If it is queued the whole simulation tree will be populated in order to have the units
if(!experiment.getStatus().equals(ExperimentStatus.QUEUED))
{
// create variables for each aspect node's simulation tree
for(IAspectConfiguration a : experiment.getAspectConfigurations())
{
List<? extends IInstancePath> vars = a.getWatchedVariables();
String aspect = a.getAspect().getInstancePath();
FindAspectNodeVisitor findAspectNodeVisitor = new FindAspectNodeVisitor(aspect);
runtimeTreeRoot.apply(findAspectNodeVisitor);
AspectNode node = findAspectNodeVisitor.getAspectNode();
for(IInstancePath var : vars)
{
AspectTreeType treeType = var.getAspect().contains(AspectTreeType.SIMULATION_TREE.toString()) ? AspectTreeType.SIMULATION_TREE : AspectTreeType.VISUALIZATION_TREE;
this.createVariables(var, node.getSubTree(treeType));
}
}
}
}
/**
* Creates variables to store in simulation tree
*
* @param variables
* @param tree
*/
public void createVariables(IInstancePath variable, AspectSubTreeNode tree)
{
String path = "/" + variable.getEntityInstancePath().replace(tree.getInstancePath() + ".", "");
path = path.replace(".", "/");
path = path.replaceFirst("/", "");
StringTokenizer tokenizer = new StringTokenizer(path, "/");
ACompositeNode node = tree;
while(tokenizer.hasMoreElements())
{
String current = tokenizer.nextToken();
boolean found = false;
for(ANode child : node.getChildren())
{
if(child.getId().equals(current))
{
if(child instanceof ACompositeNode)
{
node = (ACompositeNode) child;
}
found = true;
break;
}
}
if(found)
{
continue;
}
else
{
if(tokenizer.hasMoreElements())
{
// not a leaf, create a composite state node
ACompositeNode newNode = new CompositeNode(current);
node.addChild(newNode);
node = newNode;
}
else
{
// it's a leaf node
if(tree.getType() == AspectTreeType.SIMULATION_TREE)
{
// for now leaf nodes in the Sim tree can only be variable nodes
VariableNode newNode = new VariableNode(current);
node.addChild(newNode);
}
else if (tree.getType() == AspectTreeType.VISUALIZATION_TREE)
{
// for now leaf nodes in the Viz tree can only be skeleton animation nodes
SkeletonAnimationNode newNode = new SkeletonAnimationNode(current);
node.addChild(newNode);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment