Skip to content

Commit

Permalink
Merge pull request #1 from junqi108/AoMedium_plugin-functionality
Browse files Browse the repository at this point in the history
Update from upstream
  • Loading branch information
AoMedium authored Nov 23, 2022
2 parents 98ab349 + faa3c4f commit 8032847
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "templates"]
path = templates
url = https://github.com/junqi108/functional-structural-model-templates.git
url = https://github.com/junqi108/functional-structural-model-templates
1 change: 0 additions & 1 deletion experiments/README.md

This file was deleted.

19 changes: 19 additions & 0 deletions src/FileReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.io.File;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import models.config.ConfigFile;

public class FileReader {
// public FileReader() {

// }

// public ConfigFile readConfig(String path) {
// File file = new File("src/simulationModels/test.json");

// ObjectMapper mapper = new ObjectMapper();
// ConfigFile config = mapper.readValue(file, ConfigFile.class);
// }
}
31 changes: 31 additions & 0 deletions src/functions/FunctionCollector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package functions;

import java.util.ArrayList;
import java.util.List;

public class FunctionCollector {
// XCompiler unable to compile <> with type <IFunction>, so left generic
private List functions;

public FunctionCollector() {
init();
}

public void init() {
functions = new ArrayList();
}

public void run() {
for (IFunction function : functions) {
function.run();
}
}

public void add(IFunction function) {
functions.add(function);
}

public List getFunctions() {
return functions;
}
}
11 changes: 11 additions & 0 deletions src/functions/Growth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package functions;

public class Growth implements IFunction {
public void init() {
println("init Growth");
}

public void run() {
println("run Growth");
}
}
6 changes: 6 additions & 0 deletions src/functions/IFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package functions;

public interface IFunction {
void init();
void run();
}
11 changes: 11 additions & 0 deletions src/functions/LightInterception.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package functions;

public class LightInterception implements IFunction {
public void init() {
println("init LightInterception");
}

public void run() {
println("run LightInterception");
}
}
10 changes: 7 additions & 3 deletions src/graph.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?><graph xmlns:gx="http://grogra.de/xmlpersistence" xmlns="http://grogra.de/xmlpersistence">
<node root="MainGraph" id="0" type="de.grogra.graph.impl.Node">
<data gx:name="extentIndex" gx:value="7"/>
<node id="360" type="de.grogra.rgg.RGGRoot" edges="+">
<node id="362" type="main$Bud" edges="-"/>
<node id="14968" type="de.grogra.rgg.RGGRoot" edges="+">
<node id="14969" type="de.grogra.rgg.Axiom" edges="-"/>
</node>
</node>
<node root="MetaGraph" id="1" type="de.grogra.graph.impl.Node">
<data gx:name="extentIndex" gx:value="7"/>
<node id="359" type="main" edges="+">
<node id="14966" type="main" edges="+">
<data gx:name="extentIndex" gx:value="7"/>
<object gx:name="initialTurtleState" color="14" length="100.0" diameter="0.1" tropism="0.0" parameter="0.0" carbon="0.0" heartwood="0.0" internodeCount="0"/>
</node>
<node id="14967" type="Leaf" edges="+">
<data gx:name="extentIndex" gx:value="7"/>
<object gx:name="initialTurtleState" color="14" length="100.0" diameter="0.1" tropism="0.0" parameter="0.0" carbon="0.0" heartwood="0.0" internodeCount="0"/>
</node>
Expand Down
88 changes: 41 additions & 47 deletions src/main.rgg
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
/**
* The base module for all organs.
*
* @author James Bristow
* @version 1.0
* @since 04-08-2022
*/
abstract module Organ(float len) extends Sphere(0.1)
{
{setShader(GREEN);}
}
import java.util.List;
import java.util.ArrayList;
import java.io.File;

/**
* The bud organ.
*
* @author James Bristow
* @version 1.0
* @since 04-08-2022
*/
module Bud extends Organ(0.1) {

protected int ID;

/**
* Gets a plant ID value.
*
* @return The organ ID.
*/
public int getID() {
return ID;
}
}
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import models.*;
import functions.*;

static List organs = new ArrayList();

protected void init() {

Leaf leaf = new Leaf();
File organConfig = new File("/var/model/src/organConfig.yml");

/**
* Initialise the model.
*
*/
protected void init ()
[
Axiom ==> Bud;
]

/**
* Runs each time step of the simulation.
*/
public void run ()
[
Bud ==> F(0.5) [RU(30) RH(90) Bud] [RU(-30) RH(90) Bud];
]
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
JsonNode organTree = mapper.readTree(organConfig);

for (JsonNode organNode : organTree) {
// Create organ instances
String organName = organNode.get("name");
Class organClass = Class.forName(organName);
GenericOrgan organ = (GenericOrgan) organClass.getDeclaredConstructor().newInstance();

JsonNode functions = organNode.get("functions");

for (JsonNode functionName : functions) {
String className = functionName.asText();
Class functionClass = Class.forName(className);
IFunction function = (IFunction) functionClass.getDeclaredConstructor().newInstance();

organ.getCollector().add(function);
}
}
}
public void run() {
for (GenericOrgan organ : organs) {
organ.run();
}
}
5 changes: 5 additions & 0 deletions src/models/Fruit.rgg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import models.GenericOrgan;

public class Fruit extends GenericOrgan {

}
15 changes: 15 additions & 0 deletions src/models/GenericOrgan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package models;

import functions.FunctionCollector;

public abstract class GenericOrgan {
private FunctionCollector collector;

public FunctionCollector getCollector() {
return collector;
}

public void run() {
collector.run();
}
}
4 changes: 4 additions & 0 deletions src/models/Leaf.rgg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import models.GenericOrgan;

public class Leaf extends GenericOrgan {
}
11 changes: 11 additions & 0 deletions src/models/config/BooleanField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package models.config;

public class BooleanField extends Field {

private boolean value;

public BooleanField(String name, boolean value) {
super(name);
this.value = value;
}
}
24 changes: 24 additions & 0 deletions src/models/config/ConfigFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package models.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.*;

public class ConfigFile {
private Map fields;

public ConfigFile() {
fields = new HashMap();
}

@JsonAnySetter
public void addField(String name, String value) {
fields.put(name, value);
}

public Map getFields() {
return fields;
}
}
13 changes: 13 additions & 0 deletions src/models/config/Field.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package models.config;

abstract class Field {
private String name;

public Field(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
10 changes: 10 additions & 0 deletions src/organConfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
leaf:
name: models.Leaf
functions:
- functions.Growth
- functions.LightInterception

fruit:
name: models.Fruit
functions:
- functions.Growth
27 changes: 16 additions & 11 deletions src/project.gs
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://grogra.de/registry" graph="graph.xml">
<import plugin="de.grogra.imp" version="1.6"/>
<import plugin="de.grogra.math" version="1.6"/>
<import plugin="de.grogra.imp3d" version="1.6"/>
<import plugin="de.grogra.pf" version="1.6"/>
<import plugin="de.grogra.rgg" version="1.6"/>
<import plugin="de.grogra.imp" version="1.6"/>
<import plugin="de.grogra.imp3d" version="1.6"/>
<registry>
<ref name="project">
<ref name="objects">
<ref name="files">
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-grogra-rgg" name="pfs:main.rgg"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-grogra-xl" name="/var/model/src/shared/graph/GraphExport.xl"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-java" name="/var/model/src/models/GenericOrgan.java"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-java" name="/var/model/src/functions/IFunction.java"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-java" name="/var/model/src/functions/FunctionCollector.java"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="application/octet-stream" name="/var/model/src/organConfig.yml"/>
<de.grogra.pf.ui.registry.SourceFile mimeType="text/x-grogra-rgg" name="/var/model/src/models/Leaf.rgg"/>
</ref>
<ref name="meta">
<de.grogra.pf.registry.NodeReference name="main" ref="359"/>
<de.grogra.pf.registry.NodeReference name="main" ref="14966"/>
<de.grogra.pf.registry.NodeReference name="Leaf" ref="14967"/>
</ref>
</ref>
</ref>
<ref name="workbench">
<ref name="state">
<de.grogra.pf.ui.registry.Layout name="layout">
<de.grogra.pf.ui.registry.MainWindow>
<de.grogra.pf.ui.registry.Split location="0.49267015">
<de.grogra.pf.ui.registry.Split location="0.68154156" orientation="0">
<de.grogra.pf.ui.registry.Split location="0.50966746">
<de.grogra.pf.ui.registry.Split location="0.61290324" orientation="0">
<de.grogra.pf.ui.registry.Split orientation="0">
<de.grogra.pf.registry.Link source="/ui/panels/rgg/toolbar"/>
<de.grogra.pf.ui.registry.PanelFactory source="/ui/panels/3d/defaultview">
<de.grogra.pf.registry.Option name="panelId" type="java.lang.String" value="/ui/panels/3d/defaultview"/>
<de.grogra.pf.registry.Option name="panelTitle" type="java.lang.String" value="View"/>
<de.grogra.pf.registry.Option name="view" type="de.grogra.imp3d.View3D" value="graphDescriptor=[de.grogra.imp.ProjectGraphDescriptor]visibleScales={true true true true true true true true true true true true true true true}visibleLayers={true true true true true true true true true true true true true true true true}epsilon=1.0E-6 visualEpsilon=0.01 magnitude=1.0 camera=(minZ=0.1 maxZ=2000.0 projection=[de.grogra.imp3d.PerspectiveProjection aspect=1.0 fieldOfView=1.0471976]transformation=(1.0 0.0 0.0 0.0 0.0 0.7071067811865476 0.7071067811865475 0.0 0.0 -0.7071067811865475 0.7071067811865476 -8.0 0.0 0.0 0.0 1.0))navigator=null"/>
<de.grogra.pf.registry.Option name="view" type="de.grogra.imp3d.View3D" value="graphDescriptor=[de.grogra.imp.ProjectGraphDescriptor]visibleScales={true true true true true true true true true true true true true true true}visibleLayers={true true true true true true true true true true true true true true true true}epsilon=1.0E-6 visualEpsilon=0.01 magnitude=1.0 camera=(minZ=0.1 maxZ=2000.0 projection=[de.grogra.imp3d.PerspectiveProjection aspect=1.0 fieldOfView=1.0471976]transformation=(0.0026110166485736885 0.9999965912902207 0.0 0.0 -0.18924923304053543 4.941345825598123E-4 0.9819289605794219 0.0 0.9819256134685717 -0.0025638328637891117 0.18924987813844601 -40.82507045481592 0.0 0.0 0.0 1.0))navigator=null"/>
</de.grogra.pf.ui.registry.PanelFactory>
</de.grogra.pf.ui.registry.Split>
<de.grogra.pf.ui.registry.Split orientation="0">
Expand All @@ -38,13 +43,13 @@
<de.grogra.pf.registry.Link source="/ui/panels/statusbar"/>
</de.grogra.pf.ui.registry.Split>
</de.grogra.pf.ui.registry.Split>
<de.grogra.pf.ui.registry.Split location="0.69776875" orientation="0">
<de.grogra.pf.ui.registry.Split location="0.50490886" orientation="0">
<de.grogra.pf.ui.registry.Tab selectedIndex="0">
<de.grogra.pf.ui.registry.PanelFactory source="/ui/panels/texteditor">
<de.grogra.pf.registry.Option name="documents" type="java.lang.String" value="&quot;\&quot;/var/model/src/shared/config/Config.xl\&quot;,\&quot;/var/model/src/shared/services/Container.xl\&quot;,\&quot;/var/model/src/shared/graph/GraphExport.xl\&quot;,\&quot;pfs:main.rgg\&quot;&quot;"/>
<de.grogra.pf.registry.Option name="documents" type="java.lang.String" value="&quot;\&quot;pfs:Untitled-1\&quot;&quot;"/>
<de.grogra.pf.registry.Option name="panelId" type="java.lang.String" value="/ui/panels/texteditor"/>
<de.grogra.pf.registry.Option name="panelTitle" type="java.lang.String" value="jEdit - main.rgg"/>
<de.grogra.pf.registry.Option name="selected" type="java.lang.String" value="pfs:main.rgg"/>
<de.grogra.pf.registry.Option name="panelTitle" type="java.lang.String" value="jEdit - Untitled-1"/>
<de.grogra.pf.registry.Option name="selected" type="java.lang.String" value="pfs:Untitled-1"/>
</de.grogra.pf.ui.registry.PanelFactory>
<de.grogra.pf.registry.Link source="/ui/panels/attributeeditor"/>
</de.grogra.pf.ui.registry.Tab>
Expand Down
4 changes: 4 additions & 0 deletions src/simulationModels/simpleModel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: Simple Model
configs:
- environmentConfig.yml
- organConfig.yml

0 comments on commit 8032847

Please sign in to comment.