[78] | 1 | package com.framsticks.examples; |
---|
| 2 | |
---|
| 3 | import com.framsticks.core.Instance; |
---|
| 4 | import com.framsticks.core.Node; |
---|
| 5 | import com.framsticks.core.Parameters; |
---|
| 6 | import com.framsticks.core.Path; |
---|
| 7 | import com.framsticks.model.*; |
---|
| 8 | import com.framsticks.model.Package; |
---|
| 9 | import com.framsticks.params.*; |
---|
| 10 | import com.framsticks.params.types.CompositeParam; |
---|
| 11 | import com.framsticks.parsers.F0Parser; |
---|
| 12 | import com.framsticks.parsers.Schema; |
---|
| 13 | import org.apache.log4j.Logger; |
---|
| 14 | |
---|
| 15 | import java.util.List; |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * Author: Piotr Śniegowski |
---|
| 19 | */ |
---|
| 20 | public class GenotypeBrowser extends Instance { |
---|
| 21 | |
---|
| 22 | private static final Logger LOGGER = Logger.getLogger(Instance.class.getName()); |
---|
| 23 | protected Schema schema; |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | public GenotypeBrowser(Parameters parameters) { |
---|
| 27 | super(parameters); |
---|
| 28 | LOGGER.info("model builder created"); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | @Override |
---|
| 32 | protected void configure() throws Exception { |
---|
| 33 | super.configure(); |
---|
| 34 | schema = new Schema(Schema.getDefaultDefinitionAsStream()); |
---|
| 35 | this.registry = schema.getRegistry(); |
---|
| 36 | Package.register(this.getRegistry()); |
---|
| 37 | |
---|
| 38 | registry.putInfoIntoCache(new FramsClass("ModelBuilderRoot", "ModelBuilderRoot", null) |
---|
| 39 | .append(new ParamBuilder().setType("o Model").setId("f0genotype").setName("f0genotype").build()) |
---|
| 40 | .append(new ParamBuilder().setType("o F0Model").setId("f0model").setName("f0model").build()) |
---|
| 41 | ); |
---|
| 42 | root = new Node((CompositeParam)new ParamBuilder().setType("o ModelBuilderRoot").setId(name).setName("Instance").build(), PropertiesAccess.createPropertiesMap()); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | @Override |
---|
| 46 | protected void run() { |
---|
| 47 | assert isActive(); |
---|
| 48 | |
---|
| 49 | try { |
---|
| 50 | List<AccessInterface> accesses = new F0Parser(schema, GenotypeBrowser.class.getResourceAsStream("/examples/f0_example.txt")).parse(); |
---|
| 51 | List<Object> objects = Util.stripAccessInterface(accesses); |
---|
| 52 | F0Genotype f0Genotype = F0Genotype.build(objects); |
---|
| 53 | F0Model f0Model = F0Model.build(f0Genotype); |
---|
| 54 | |
---|
| 55 | for (String n : new String[] {"MechPart", "MechJoint", "Neuro"}) { |
---|
| 56 | registry.putInfoIntoCache(FramsClass.readFromStream(GenotypeBrowser.class.getResourceAsStream("/info/" + n + ".info"))); |
---|
| 57 | } |
---|
| 58 | AccessInterface rootAccess = bindAccess(new Path(this, "/")); |
---|
| 59 | |
---|
| 60 | rootAccess.set("f0genotype", f0Genotype); |
---|
| 61 | rootAccess.set("f0model", f0Model); |
---|
| 62 | |
---|
| 63 | } catch (Exception e) { |
---|
| 64 | LOGGER.error("exception caught: " + e); |
---|
| 65 | } |
---|
| 66 | //done(); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | } |
---|