use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method calcPluginSet.
// toXML
/**
* collect all objects and put all top-level beastObjects in a PluginSet
*/
BEASTObjectSet calcPluginSet() {
// collect all plug-ins
Collection<BEASTInterface> beastObjects = getPlugins();
// calc outputs
HashMap<BEASTInterface, List<BEASTInterface>> outputs = BEASTObjectPanel.getOutputs(beastObjects);
// put all beastObjects with no ouputs in the PluginSet
BEASTObjectSet pluginSet = new BEASTObjectSet();
for (BEASTInterface beastObject : outputs.keySet()) {
if (outputs.get(beastObject).size() == 0) {
try {
pluginSet.setInputValue("beastObject", beastObject);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return pluginSet;
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method checkForOtherPluginShapes.
// addNewShape
void checkForOtherPluginShapes(List<Integer> objects, BEASTObjectShape shape) {
// check whether we need to create any input beastObjects
try {
List<Input<?>> inputs = shape.m_beastObject.listInputs();
for (Input<?> input : inputs) {
if (input.get() instanceof BEASTInterface) {
BEASTInterface beastObject = (BEASTInterface) input.get();
BEASTObjectShape beastObjectShape = new BEASTObjectShape(beastObject, this);
beastObjectShape.m_x = Math.max(shape.m_x - DX, 0);
beastObjectShape.m_y = shape.m_y;
beastObjectShape.m_w = 100;
beastObjectShape.m_h = 80;
setPluginID(beastObjectShape);
m_objects.add(beastObjectShape);
objects.add(m_objects.size() - 1);
Arrow arrow = new Arrow(beastObjectShape, shape, input.getName());
m_objects.add(arrow);
objects.add(m_objects.size() - 1);
// recurse
checkForOtherPluginShapes(objects, beastObjectShape);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method reinit.
void reinit() {
String xml = toXML();
m_objects.clear();
try {
XMLParser parser = new XMLParser();
BEASTInterface plugin0 = parser.parseBareFragment(xml, false);
init(plugin0);
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method isValidModel.
int isValidModel() {
BEASTObjectSet pluginSet = calcPluginSet();
if (pluginSet.m_plugins.get().size() == 0) {
return STATUS_EMPTY_MODEL;
}
if (pluginSet.m_plugins.get().size() > 1) {
return STATUS_ORPHANS_IN_MODEL;
}
boolean hasRunable = false;
for (BEASTInterface beastObject : pluginSet.m_plugins.get()) {
if (beastObject instanceof Runnable) {
hasRunable = true;
}
}
if (!hasRunable) {
return STATUS_NOT_RUNNABLE;
}
return STATUS_OK;
}
use of beast.core.BEASTInterface in project beast2 by CompEvol.
the class Document method loadFile.
public void loadFile(String fileName) {
m_objects.clear();
XMLParser parser = new XMLParser();
try {
// fileName;
StringBuilder xml = new StringBuilder();
String NL = System.getProperty("line.separator");
Scanner scanner = new Scanner(new File(fileName));
try {
while (scanner.hasNextLine()) {
xml.append(scanner.nextLine() + NL);
}
} finally {
scanner.close();
}
BEASTInterface plugin0 = parser.parseBareFragment(xml.toString(), false);
init(plugin0);
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
Aggregations