Changeset 78 for java


Ignore:
Timestamp:
01/09/13 00:09:10 (11 years ago)
Author:
psniegowski
Message:

Add f0 parsing and f0->Model transformation.

Location:
java/main
Files:
36 added
3 deleted
38 edited

Legend:

Unmodified
Added
Removed
  • java/main/pom.xml

    r77 r78  
    1515                </repository>
    1616        </repositories>
    17 
     17        <properties>
     18                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     19        </properties>
    1820        <build>
    1921                <plugins>
     
    5860                        <version>1.5.2</version>
    5961                </dependency>
     62
     63        <dependency>
     64            <groupId>junit</groupId>
     65            <artifactId>junit</artifactId>
     66            <version>4.8.1</version>
     67            <scope>test</scope>
     68        </dependency>
    6069                <!--dependency>
    6170                </dependency>
  • java/main/src/main/java/com/framsticks/core/Entity.java

    r77 r78  
    44import com.framsticks.util.Thread;
    55import org.apache.log4j.Logger;
    6 
    7 import java.util.HashSet;
    8 import java.util.Set;
    96
    107/**
     
    3734    }
    3835
    39     public final void configurePublic() {
     36    public final void configurePublic() throws Exception {
    4037        configure();
    4138    }
    4239
    43     protected void configure() {
     40    protected void configure() throws Exception {
    4441
    4542    }
     
    5855    }
    5956
     57        public final void done() {
     58                LOGGER.info("stopping entity");
     59                if (owner != null) {
     60                        owner.onDone();
     61                }
     62        }
     63
    6064
    6165}
  • java/main/src/main/java/com/framsticks/core/Instance.java

    r77 r78  
    2323    protected Node root;
    2424
    25         protected final Map<String, FramsClass> infoCache = new HashMap<String, FramsClass>();
    2625    public Set<InstanceListener> listeners = new HashSet<InstanceListener>();
    2726
     
    3433    protected void run() {
    3534        super.run();
    36         registerTypicalReflectedClasses();
     35                com.framsticks.model.Package.register(registry);
    3736    }
    3837
    3938    @Override
    40     protected void configure() {
     39    protected void configure() throws Exception {
    4140        super.configure();
    4241    }
    4342
    44     protected abstract void fetchInfo(Path path, Future<FramsClass> future);
    45     public abstract void resolve(Path path, Future<Path> future);
    46     public abstract void fetchValue(Path path, Param param, StateFunctor stateFunctor);
    47     public abstract void fetchValues(Path path, StateFunctor stateFunctor);
    48     protected abstract void tryRegisterOnChangeEvents(Path path);
     43    protected void fetchInfo(Path path, Future<FramsClass> future) {
     44                future.result(null, new UnsupportedOperationException());
     45        }
     46
     47        public void resolve(Path path, Future<Path> future) {
     48                assert isActive();
     49                assert path.isOwner(this);
     50                if (path.getTop().getObject() != null) {
     51                        future.result(path, null);
     52                        return;
     53                }
     54                AccessInterface access = bindAccess(path.getUnder());
     55                Object object = access.get(path.getTop().getParam(), Object.class);
     56                if (object == null) {
     57                        future.result(path, null);
     58                        return;
     59                }
     60                future.result(path.appendResolution(object), null);
     61        }
     62
     63    public void fetchValue(Path path, Param param, StateFunctor stateFunctor) {
     64                stateFunctor.call(null);
     65        }
     66
     67    public void fetchValues(Path path, StateFunctor stateFunctor) {
     68                stateFunctor.call(null);
     69        }
     70
     71    protected void tryRegisterOnChangeEvents(Path path) {
     72
     73        }
    4974
    5075        public void storeValue(Path path, Param param, Object value, final StateFunctor stateFunctor) {
     
    98123        }
    99124
    100         public void putInfoIntoCache(FramsClass framsClass) {
    101         assert isActive();
    102         if (infoCache.containsKey(framsClass.getId())) {
    103             LOGGER.info("already cached " + framsClass);
    104             return;
    105         }
    106         LOGGER.debug("caching info for " + framsClass);
    107                 infoCache.put(framsClass.getId(), framsClass);
    108         }
    109125
    110126    public final FramsClass getInfoFromCache(Path path) {
     
    115131    public FramsClass getInfoFromCache(String id) {
    116132        assert isActive();
    117         if (id == null) {
    118                         return null;
    119                 }
    120         if (infoCache.containsKey(id)) {
    121             return infoCache.get(id);
    122         }
    123                 return null;
    124         }
    125 
    126         protected final Map<String, Class> reflectedClasses = new HashMap<String, Class>();
    127 
    128     public final void registerReflectedClass(String name, String className) {
    129         assert isActive();
    130         try {
    131             registerReflectedClass(name, Class.forName(className));
    132         } catch (ClassNotFoundException e) {
    133             LOGGER.fatal("class not found during registration: " + e);
    134         }
    135     }
    136 
    137     public void registerReflectedClass(String name, Class reflectedClass) {
    138         assert isActive();
    139         reflectedClasses.put(name, reflectedClass);
    140         }
     133                return registry.getInfoFromCache(id);
     134        }
     135
     136        protected Registry registry = new Registry();
    141137
    142138        public AccessInterface createAccess(String name) {
     
    150146                }
    151147
    152                 if (reflectedClasses.containsKey(name)) {
    153                         return new ReflectionAccess(reflectedClasses.get(name), framsClass);
    154                 }
    155 
    156                 return new PropertiesAccess(framsClass);
     148                return registry.createAccess(name, framsClass);
    157149        }
    158150
     
    188180        AccessInterface access = prepareAccess(node.getParam());
    189181        if (access == null) {
     182                        LOGGER.error("missing access for: " + node.getParam());
    190183            return null;
    191184        }
     
    287280            }
    288281        }
    289         putInfoIntoCache(framsClass);
     282        registry.putInfoIntoCache(framsClass);
    290283        return framsClass;
    291284    }
     
    338331    }
    339332
    340     public void registerTypicalReflectedClasses() {
    341         registerReflectedClass("MechPart", "com.framsticks.model.MechPart");
    342         registerReflectedClass("Joint", "com.framsticks.model.Joint");
    343         registerReflectedClass("MechJoint", "com.framsticks.model.MechJoint");
    344         registerReflectedClass("Neuro", "com.framsticks.model.Neuro");
    345         registerReflectedClass("NeuroDef", "com.framsticks.model.NeuroDef");
    346         registerReflectedClass("Part", "com.framsticks.model.Part");
    347         registerReflectedClass("Creature", "com.framsticks.model.Creature");
    348         registerReflectedClass("Genotype", "com.framsticks.model.Genotype");
    349     }
    350 
    351333    public static Iterator<String> splitPath(String path) {
    352334        List<String> list = new LinkedList<String>();
     
    359341    }
    360342
     343        public Registry getRegistry() {
     344                return registry;
     345        }
    361346}
     347
  • java/main/src/main/java/com/framsticks/core/LocalInstance.java

    r77 r78  
    4545
    4646    @Override
    47     protected void configure() {
     47    protected void configure() throws Exception {
    4848        super.configure();
    4949    }
     
    9797    }
    9898
    99 
    100 
    101     @Override
    102     public void resolve(Path path, Future<Path> future) {
    103         assert isActive();
    104         assert path.isOwner(this);
    105         if (path.getTop().getObject() != null) {
    106             future.result(path, null);
    107             return;
    108         }
    109         AccessInterface access = bindAccess(path.getUnder());
    110         Object object = access.get(path.getTop().getParam(), Object.class);
    111         if (object == null) {
    112             future.result(path, null);
    113             return;
    114         }
    115         future.result(path.appendResolution(object), null);
    116     }
    117 
    118 
    119     @Override
    120     public void fetchValue(Path path, Param param, StateFunctor stateFunctor) {
    121         stateFunctor.call(null);
    122     }
    123 
    124     @Override
    125     public void fetchValues(Path path, StateFunctor stateFunctor) {
    126         stateFunctor.call(null);
    127     }
    128 
    129 
    13099}
  • java/main/src/main/java/com/framsticks/core/Parameters.java

    r77 r78  
    1212    protected String name;
    1313    protected Dispatcher dispatcher;
     14        protected EntityOwner owner;
    1415
    15     public Parameters(Configuration config, String name, Dispatcher dispatcher) {
     16
     17
     18    public Parameters(Configuration config, String name, Dispatcher dispatcher, EntityOwner owner) {
    1619        this.config = config;
    1720        this.name = name;
    1821        this.dispatcher = dispatcher;
     22                this.owner = owner;
    1923    }
    2024
     
    2327        name = parameters.name;
    2428        dispatcher = parameters.dispatcher;
     29                owner = parameters.owner;
    2530    }
    2631
  • java/main/src/main/java/com/framsticks/core/Program.java

    r77 r78  
    66import org.apache.log4j.Logger;
    77import org.apache.log4j.PropertyConfigurator;
    8 import sun.misc.Signal;
    9 import sun.misc.SignalHandler;
     8//import sun.misc.Signal;
     9//import sun.misc.SignalHandler;
    1010
    1111import java.lang.reflect.Constructor;
     
    1919    private final static Logger LOGGER = Logger.getLogger(Program.class.getName());
    2020
     21/*
    2122    protected SignalHandler signalHandler = new SignalHandler() {
    2223        @Override
     
    2627        }
    2728    };
     29*/
    2830
    2931    protected Entity entity;
     
    3436    public Program(String name) {
    3537        super(name, java.lang.Thread.currentThread());
    36         Signal.handle(new Signal("INT"), signalHandler);
    37         Signal.handle(new Signal("TERM"), signalHandler);
     38//        Signal.handle(new Signal("INT"), signalHandler);
     39//        Signal.handle(new Signal("TERM"), signalHandler);
    3840    }
    3941
     
    4446            Class type = Class.forName(typeName);
    4547            Constructor constructor = type.getConstructor(Parameters.class);
    46             Entity entity = (Entity) constructor.newInstance(parameters);
    47             return entity;
     48            return (Entity) constructor.newInstance(parameters);
    4849        } catch (Exception e) {
    4950            LOGGER.error("failed to instantiate: " + e);
     
    9697        }
    9798
    98         entity = configureEntity(new Parameters(config.subset("com.framsticks.entity"), "main", null));
    99         entity.configurePublic();
     99        entity = configureEntity(new Parameters(config.subset("com.framsticks.entity"), "main", null, new EntityOwner() {
     100                        @Override
     101                        public void onDone() {
     102                                LOGGER.info("exiting");
     103                                Runtime.getRuntime().exit(0);
     104                        }
     105                }));
     106                try {
     107                entity.configurePublic();
     108                } catch (Exception e) {
     109                        LOGGER.fatal("exception caught during configuration: " + e);
     110                }
    100111        LOGGER.info("all entities were configured");
    101112        entity.start();
  • java/main/src/main/java/com/framsticks/diagnostics/Diagnostics.java

    r77 r78  
    2323
    2424    @Override
    25     protected void configure() {
     25    protected void configure() throws Exception {
    2626
    2727        super.configure();
  • java/main/src/main/java/com/framsticks/dumping/FileInstance.java

    r77 r78  
    5353    }
    5454
    55 
    56     @Override
    57     protected void fetchInfo(Path path, Future<FramsClass> future) {
    58         future.result(null, new UnsupportedOperationException());
    59     }
    60 
    61     @Override
    62     protected void tryRegisterOnChangeEvents(Path path) {
    63     }
    64 
    65 
    6655    @Override
    6756    public String toString() {
  • java/main/src/main/java/com/framsticks/dumping/SaveStream.java

    r77 r78  
    3737        this.instance = instance;
    3838        this.stateFunctor = stateFunctor;
    39         dispatched = 1;
    40         write(root);
     39                dispatchWrite(root);
    4140    }
     41
     42        protected void dispatchWrite(final Path path) {
     43                ++dispatched;
     44                instance.invokeLater(new Runnable() {
     45                        @Override
     46                        public void run() {
     47                                write(path);
     48                        }
     49                });
     50        }
    4251
    4352    protected void finished() {
     
    5362        } else {
    5463            AccessInterface access = instance.bindAccess(path);
     64                        assert access != null;
    5565            FramsClass framsClass = access.getFramsClass();
    5666            assert framsClass != null;
     
    7686                    final Path childPath = path.appendNode(new Node(childParam, access.get(childParam, Object.class)));
    7787                    if (childPath.isResolved() && instance.getInfoFromCache(childPath) != null) {
    78                         ++dispatched;
    79                         instance.invokeLater(new Runnable() {
    80                             @Override
    81                             public void run() {
    82                                 write(childPath);
    83                             }
    84                         });
     88                                                dispatchWrite(childPath);
    8589                    }
    8690                }
     
    9296        }
    9397    }
    94 
    95 
    9698}
  • java/main/src/main/java/com/framsticks/gui/Browser.java

    r77 r78  
    4545
    4646    @Override
    47     protected void configure() {
     47    protected void configure() throws Exception {
    4848        super.configure();
    4949    }
  • java/main/src/main/java/com/framsticks/gui/Frame.java

    r77 r78  
    11package com.framsticks.gui;
    22
     3import com.framsticks.core.Node;
    34import com.framsticks.core.Path;
    45import com.framsticks.gui.view.*;
     
    1213import javax.swing.tree.*;
    1314import java.awt.*;
     15import java.awt.datatransfer.StringSelection;
    1416import java.awt.event.ActionEvent;
    1517import java.awt.event.MouseAdapter;
     
    7577        treePopupMenu.add(new JMenuItem("Refresh"));
    7678        treePopupMenu.add(new JMenuItem("Open in new frame as root"));
     79                addNodeActionToTreePopupMenu("Copy path to clipboard", new NodeAction() {
     80                        @Override
     81                        public void actionPerformed(TreeNode treeNode) {
     82                                Path path = treeNode.getInstancePath();
     83                                StringSelection selection = new StringSelection(path.toString());
     84                                getToolkit().getSystemClipboard().setContents(selection, selection);
     85                        }
     86                });
    7787        //this.add(createMenuItem("Add to favourites", null));
    7888        //this.add(createMenuItem("Remove from favourites", null));
  • java/main/src/main/java/com/framsticks/gui/TreeNode.java

    r77 r78  
    124124        LOGGER.debug("updating children of " + this);
    125125        AccessInterface access = p.getInstance().bindAccess(p.getTop());
     126                if (access == null) {
     127                        return;
     128                }
    126129        final List<Path> childrenPaths = new LinkedList<Path>();
    127130        /**Prepare path for each child.*/
     
    210213    }
    211214
    212 
    213215        public final Panel getPanel() {
    214216        assert frame.isActive();
     
    222224        }
    223225        AccessInterface access = p.getInstance().bindAccess(p);
    224         assert access != null;
     226                if (access == null) {
     227                        return;
     228                }
    225229        StringBuilder t = new StringBuilder();
    226230        /** html formatting is used here, since tooltips in swing do not support simple \n line breaks */
     
    494498
    495499                return true;
     500        }
     501
     502        public Path getInstancePath() {
     503                assert frame.isActive();
     504                return path;
    496505        }
    497506
  • java/main/src/main/java/com/framsticks/hosting/ServerInstance.java

    r77 r78  
    3030
    3131    @Override
    32     protected void configure() {
     32    protected void configure() throws Exception {
    3333        super.configure();
    3434
    35         Parameters p = new Parameters(config.subset("hosted.entity"), "hosted", this);
     35        Parameters p = new Parameters(config.subset("hosted.entity"), "hosted", this, null);
    3636        hosted = Program.configureEntity(p);
    3737        if (hosted == null) {
     
    4949            return null;
    5050        }
    51         if (infoCache.containsKey(id)) {
    52             return infoCache.get(id);
     51                FramsClass cached = registry.getInfoFromCache(id);
     52        if (cached != null) {
     53                        return cached;
    5354        }
    5455        try {
     
    5657            FramsClass framsClass = new FramsClass.Constructor(nativeClass, id).getResult();
    5758
    58             registerReflectedClass(id, nativeClass);
    59             putInfoIntoCache(framsClass);
     59            registry.registerReflectedClass(null, id, nativeClass);
     60            registry.putInfoIntoCache(framsClass);
    6061            return framsClass;
    6162        } catch (ClassNotFoundException ignored) {
  • java/main/src/main/java/com/framsticks/model/Creature.java

    r77 r78  
    11package com.framsticks.model;
    22
    3 import com.framsticks.model.MechPart;
    4 import com.framsticks.model.Joint;
     3import com.framsticks.params.FramsClass;
     4import com.framsticks.util.Orientation;
    55import com.framsticks.util.Point3d;
    66
     
    88import java.util.List;
    99
    10 public class Creature {
     10public class Creature extends F0Model {
    1111        public String name;
    1212
     
    9494        public void setVertpos(Double c_vertpos) { averageVerticalPosition = c_vertpos; }
    9595
    96         public Point3d position = new Point3d();
     96        /** pos_x, pos_y, pos_z*/
     97        public double pos_x, pos_y, pos_z;
    9798
    98         public Double getPos_x() { return position.x; }
    99         public void setPos_x(Double pos_x) { position.x = pos_x; }
     99        public Point3d getPosition() { return new Point3d(pos_x, pos_y, pos_z) ; }
     100        public void setPosition(Point3d pos) { pos_x = pos.x; pos_y = pos.y; pos_z = pos.z; }
    100101
    101         public Double getPos_y() { return position.y; }
    102         public void setPos_y(Double pos_y) { position.y = pos_y; }
     102        public double size_x, size_y, size_z;
    103103
    104         public Double getPos_z() { return position.z; }
    105         public void setPos_z(Double pos_z) { position.z = pos_z; }
     104        public Point3d getBoundingBox() { return new Point3d(size_x, size_y, size_z) ; }
     105        public void setBoundingBox(Point3d size) { size_x = size.x; size_y = size.y; size_z = size.z; }
    106106
    107         public Point3d boundingBox = new Point3d();
    108         public Double getSize_x() { return boundingBox.x; }
    109         public void setSize_x(Double size_x) { boundingBox.x = size_x; }
    110107
    111         public Double getSize_y() { return boundingBox.y; }
    112         public void setSize_y(Double size_y) { boundingBox.y = size_y; }
     108        /** center_x, center_y, center_z*/
     109        public double center_x, center_y, center_z;
    113110
    114         public Double getSize_z() { return boundingBox.z; }
    115         public void setSize_z(Double size_z) { boundingBox.z = size_z; }
    116 
    117         public Point3d center = new Point3d();
    118 
    119         public Double getCenter_x() { return center.x; }
    120         public void setCenter_x(Double center_x) { center.x = center_x; }
    121 
    122         public Double getCenter_y() { return center.y; }
    123         public void setCenter_y(Double center_y) { center.y = center_y; }
    124 
    125         public Double getCenter_z() { return center.z; }
    126         public void setCenter_z(Double center_z) { center.z = center_z; }
     111        public Point3d getCenter() { return new Point3d(center_x, center_y, center_z) ; }
     112        public void setCenter(Point3d center) { center_x = center.x; center_y = center.y; center_z = center.z; }
    127113
    128114        public Integer getNumparts() { return parts.size(); }
     
    161147        public final List<NeuroDef> neurodefs = new ArrayList<NeuroDef>();
    162148
    163         public final List<MechPart> mechparts = new ArrayList<MechPart>();
    164         public final List<MechJoint> mechjoints = new ArrayList<MechJoint>();
    165         public final List<Neuro> neurons = new ArrayList<Neuro>();
     149
     150
     151        public final List<Part> getParts() { return parts; }
     152        public final List<Joint> getJoints() { return joints; }
     153        public final List<NeuroDef> getNeuroDefs() { return neurodefs; }
    166154
    167155
    168156
     157        public static void constructFramsClass(FramsClass.Constructor constructor) {
     158                constructor.field("name");
     159                constructor.field("parts");
     160                constructor.field("joints");
     161                constructor.field("neurodefs");
     162        }
     163
    169164}
  • java/main/src/main/java/com/framsticks/model/Genotype.java

    r77 r78  
    22
    33
    4 import com.framsticks.util.Containers;
     4import org.apache.log4j.Logger;
    55
    6 import java.util.ArrayList;
    7 import java.util.List;
     6public class Genotype extends F0Genotype {
     7        private final static Logger LOGGER = Logger.getLogger(Genotype.class);
    88
    9 public class Genotype {
    109        public String name;
    1110        public String genotype;
     
    1514        public Double getSimi() { return similarity; }
    1615        public void setSimi(Double simi) { similarity = simi; }
    17 
    18         public Double startingEnergy;
    19         public Double getEnerg0() { return startingEnergy; }
    20         public void setEnerg0(Double energ0) { startingEnergy = energ0; }
    2116
    2217        public Double brainConnections;
     
    4035        public Double velocity;
    4136        public Double distance;
    42 
    4337
    4438        public Double verticalVelocity;
     
    7872        public String uid;
    7973
    80         public final List<Part> parts = new ArrayList<Part>();
    81         public final List<Joint> joints = new ArrayList<Joint>();
    82         public final List<NeuroDef> neurodefs = new ArrayList<NeuroDef>();
     74}
    8375
    84 
    85     public Double getNumparts() { return (double)parts.size(); }
    86         public Double getNumjoints() { return (double)joints.size(); }
    87         public Double getNumneurons() { return (double)neurodefs.size(); }
    88 
    89     //this is impossible to use, because numparts field is marked as readonly
    90     public void setNumparts(Double numparts) { Containers.resizeList(parts, (int)(double)numparts); }
    91     public void setNumjoints(Double numjoints) { Containers.resizeList(joints, (int)(double)numjoints); }
    92     public void setNumneurons(Double numneurons) { Containers.resizeList(neurodefs, (int)(double)numneurons); }
    93 }
  • java/main/src/main/java/com/framsticks/model/Joint.java

    r77 r78  
    88 * All accessors are used by ReflectionAccess.
    99 */
    10 public class Joint {
     10public class Joint extends BaseJoint {
    1111
     12        /** i */
     13        public String info;
     14        public String getI() { return info; }
     15        public void setI(String i) { info = i; }
     16
     17        /** p1 */
     18        public Integer part1;
    1219        public void setP1(Integer p1) { part1 = p1; }
    1320        public Integer getP1() { return part1; }
     21
     22        /** p2 */
     23        public Integer part2;
    1424        public void setP2(Integer p2) { part2 = p2; }
    1525        public Integer getP2() { return part2; }
    1626
    17         public void setDx(Double dx) { delta.x = dx; }
    18         public void setDy(Double dy) { delta.y = dy; }
    19         public void setDz(Double dz) { delta.z = dz; }
    2027
    21         public Double getDx() { return delta.x; }
    22         public Double getDy() { return delta.y; }
    23         public Double getDz() { return delta.z; }
    24 
    25         public void setRx(Double rx) { rotation.x = rx; }
    26         public void setRy(Double ry) { rotation.y = ry; }
    27         public void setRz(Double rz) { rotation.z = rz; }
    28 
    29         public Double getRx() { return rotation.x; }
    30         public Double getRy() { return rotation.y; }
    31         public Double getRz() { return rotation.z; }   
    32 
     28        /** stam */
     29        public Double stamina;
    3330        public Double getStam() { return stamina; }
    3431        public void setStam(Double stam) { stamina = stam; }
    3532
    36         public Double getStif() { return stiffness; }
    37         public void setStif(Double stif) { stiffness = stif; }
    38 
    39         public Double getRotstif() { return rotationStiffness; }
    40         public void setRotstif(Double rotstif) { rotationStiffness = rotstif; }
    41 
    42         public String getI() { return info; }
    43         public void setI(String i) { info = i; }
    44 
    45         public String getVstyle() { return visualizationStyle; }
    46         public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; }
    47 
    48         /** p1 */
    49         public Integer part1;
    50 
    51         /** p2 */
    52         public Integer part2;
    53 
    54         /** dx, dy, dz*/
    55         public final Point3d delta = new Point3d();
    56 
    57         /** rx, ry, rz*/
    58         public final Point3d rotation = new Point3d();
    59 
    60         /** stam */
    61         public Double stamina;
    62 
    63         /** stif */
    64         public Double stiffness;
    65 
    66         /** rotstif */
    67         public Double rotationStiffness;
    68 
    69         /** i */
    70         public String info;
    7133
    7234        /** Vstyle */
    7335        public String visualizationStyle;
    74 
    75 
     36        public String getVstyle() { return visualizationStyle; }
     37        public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; }
    7638}
  • java/main/src/main/java/com/framsticks/model/MechJoint.java

    r77 r78  
    66 * @author Piotr Sniegowski
    77 */
    8 public class MechJoint {
    9         /** rx, ry, rz*/
    10         public final Point3d rotation = new Point3d();
    11 
    12         /** dx, dy, dz*/
    13         public final Point3d delta = new Point3d();
    14 
    15         /** stif */
    16         public Double stiffness;
    17 
    18         /** rotstif */
    19         public Double rotationStiffness;
     8public class MechJoint extends BaseJoint {
    209
    2110        /** stress */
    2211        public Double stress;
     12        public Double getStress() { return stress; }
     13        public void setStress(Double stress) { this.stress = stress; }
    2314
    2415        /** rotstress */
    2516        public Double rotationStress;
    26 
    27         public Double getRx() { return rotation.x; }
    28         public void setRx(Double rx) { rotation.x = rx; }
    29 
    30         public Double getRy() { return rotation.y; }
    31         public void setRy(Double ry) { rotation.y = ry; }
    32 
    33         public Double getRz() { return rotation.z; }
    34         public void setRz(Double rz) { rotation.z = rz; }
    35 
    36         public Double getDx() { return delta.x; }
    37         public void setDx(Double dx) { delta.x = dx; }
    38 
    39         public Double getDy() { return delta.y; }
    40         public void setDy(Double dy) { delta.y = dy; }
    41 
    42         public Double getDz() { return delta.z; }
    43         public void setDz(Double dz) { delta.z = dz; }
    44 
    45         public Double getStif() { return stiffness; }
    46         public void setStif(Double stif) { stiffness = stif; }
    47 
    48         public Double getRotstif() { return rotationStiffness; }
    49         public void setRotstif(Double rotstif) { rotationStiffness = rotstif; }
    50 
    51         public Double getStress() { return stress; }
    52         public void setStress(Double stress) { this.stress = stress; }
    53 
    5417        public Double getRotstress() { return rotationStress; }
    5518        public void setRotstress(Double rotstress) { rotationStress = rotstress; }
    56 
    5719}
  • java/main/src/main/java/com/framsticks/model/MechPart.java

    r77 r78  
    66/*
    77 */
    8 public class MechPart {
    9 
    10         /** x, y, z */
    11         public final Point3d position = new Point3d();
    12 
    13         /** m */
    14         public Double mass = 0.0;
    15 
    16         /** s */
    17         public Double size = 0.0;
     8public class MechPart extends BasePart {
    189
    1910        /** vol */
    2011        public Double volume = 0.0;
    21 
    22         /** fr */
    23         public Double friction = 0.0;
    24 
    25         /** vx, vy, vz */
    26         public final Point3d velocity = new Point3d();
    27 
    28     /** oxx, oxy, oxz, oyx, oyy, oyz, ozx, ozy, ozz*/
    29     public final Orientation orientation = new Orientation();
    30 
    31         public Double getX() { return position.x; }
    32         public void setX(Double x) { position.x = x; }
    33 
    34         public Double getY() { return position.y; }
    35         public void setY(Double y) { position.y = y; }
    36 
    37         public Double getZ() { return position.z; }
    38         public void setZ(Double z) { position.z = z; }
    39 
    40         public Double getM() { return mass; }
    41         public void setM(Double m) { mass = m; }
    42 
    43         public Double getS() { return size; }
    44         public void setS(Double s) { size = s; }
    45 
    4612        public Double getVol() { return volume; }
    4713        public void setVol(Double vol) { volume = vol; }
    4814
    49         public Double getFr() { return friction; }
    50         public void setFr(Double fr) { friction = fr; }
     15        /** vx, vy, vz*/
     16        public double vx, vy, vz;
    5117
    52         public Double getVx() { return velocity.x; }
    53         public void setVx(Double vx) { velocity.x = vx; }
     18        public Point3d getVelocity() { return new Point3d(vx, vy, vz); }
     19        public void setVelocity(Point3d v) { vx = v.x; vy = v.y; vz = v.z; }
    5420
    55         public Double getVy() { return velocity.y; }
    56         public void setVy(Double vy) { velocity.y = vy; }
     21    public double oxx, oxy, oxz, oyx, oyy, oyz, ozx, ozy, ozz;
    5722
    58         public Double getVz() { return velocity.z; }
    59         public void setVz(Double vz) { velocity.z = vz; }
     23        public Orientation getOrientation() { return new Orientation(new Point3d(oxx, oxy, oxz), new Point3d(oyx, oyy, oyz), new Point3d(ozx, ozy, ozz)); }
    6024
    61         public Double getOxx() { return orientation.x.x; }
    62         public void setOxx(Double oxx) { orientation.x.x = oxx; }
    63 
    64         public Double getOxy() { return orientation.x.y; }
    65         public void setOxy(Double oxy) { orientation.x.y = oxy; }
    66 
    67         public Double getOxz() { return orientation.x.z; }
    68         public void setOxz(Double oxz) { orientation.x.z = oxz; }
    69 
    70         public Double getOyx() { return orientation.y.x; }
    71         public void setOyx(Double oyx) { orientation.y.x = oyx; }
    72 
    73         public Double getOyy() { return orientation.y.y; }
    74         public void setOyy(Double oyy) { orientation.y.y = oyy; }
    75 
    76         public Double getOyz() { return orientation.y.z; }
    77         public void setOyz(Double oyz) { orientation.y.z = oyz; }
    78 
    79         public Double getOzx() { return orientation.z.x; }
    80         public void setOzx(Double ozx) { orientation.z.x = ozx; }
    81 
    82         public Double getOzy() { return orientation.z.y; }
    83         public void setOzy(Double ozy) { orientation.z.y = ozy; }
    84 
    85         public Double getOzz() { return orientation.z.z; }
    86         public void setOzz(Double ozz) { orientation.z.z = ozz; }
     25        public void setOrientation(Orientation o) {
     26                oxx = o.x.x;
     27                oxy = o.x.y;
     28                oxz = o.x.z;
     29                oyx = o.y.x;
     30                oyy = o.y.y;
     31                oyz = o.y.z;
     32                ozx = o.z.x;
     33                ozy = o.z.y;
     34                ozz = o.z.z;
     35        }
    8736
    8837}
  • java/main/src/main/java/com/framsticks/model/Neuro.java

    r77 r78  
    66 * @author Piotr Sniegowski
    77 */
    8 public class Neuro {
     8public class Neuro extends BaseNeuro {
    99
    1010        public Integer channelCount;
    11 
    12         public Integer inputCount;
    13         public Integer getGetInputCount() { return inputCount; }
    14         public void setGetInputCount(Integer getInputCount) { inputCount = getInputCount; }
    1511
    1612        public Double inputSum;
     
    2622        public Boolean hold;
    2723
     24        public double position_x, position_y, position_z;
    2825
    29         /** position_x, position_y, position_z*/
    30         public final Point3d position = new Point3d();
    31 
    32         public Double getPosition_x() { return position.x; }
    33         public void setPosition_x(Double position_x) { position.x = position_x; }
    34 
    35         public Double getPosition_y() { return position.y; }
    36         public void setPosition_y(Double position_y) { position.y = position_y; }
    37 
    38         public Double getPosition_z() { return position.z; }
    39         public void setPosition_z(Double position_z) { position.z = position_z; }
     26        public Point3d getPosition() { return new Point3d(position_x, position_y, position_z); }
     27        public void setPosition(Point3d p) { position_x = p.x; position_y = p.y; position_z = p.z; }
    4028
    4129}
  • java/main/src/main/java/com/framsticks/model/NeuroDef.java

    r77 r78  
    44 * @author Piotr Sniegowski
    55 */
    6 public class NeuroDef {
     6public class NeuroDef extends BaseNeuro {
    77
    88        /** p */
     
    2121        public String visualizationStyle;
    2222
    23         /** getInputCount */
    24         public Integer inputCount;
    25 
    2623        public Integer getP() { return part; }
    2724        public void setP(Integer p) { part = p; }
     
    3936        public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; }
    4037
    41         public Integer getGetInputCount() { return inputCount; }
    42         public void setGetInputCount(Integer getInputCount) { inputCount = getInputCount; }
    4338
    4439
  • java/main/src/main/java/com/framsticks/model/Part.java

    r77 r78  
    77 * The Class Part.
    88 */
    9 public class Part {
    10 
    11         /** x, y, z*/
    12         public final Point3d position = new Point3d();
     9public class Part extends BasePart {
    1310
    1411        /** rx, ry, rz*/
    15         public final Point3d rotation = new Point3d();
     12        public double rx, ry, rz;
    1613
    17         /** m */
    18         public Double mass;
    19 
    20         /** s */
    21         public Double size;
     14        public Point3d getRotation() { return new Point3d(rx, ry, rz); }
     15        public void setRotation(Point3d r) { rx = r.x; ry = r.y; rz = r.z; }
    2216
    2317        /** dn */
    2418        public Double density;
    25 
    26         /** fr */
    27         public Double friction;
    2819
    2920        /** ing */
     
    3930        public String visualizationStyle;
    4031
    41         public Double getX() { return position.x; }
    42         public void setX(Double x) { position.x = x; }
    43 
    44         public Double getY() { return position.y; }
    45         public void setY(Double y) { position.y = y; }
    46 
    47         public Double getZ() { return position.z; }
    48         public void setZ(Double z) { position.z = z; }
    49 
    50         public Double getM() { return mass; }
    51         public void setM(Double m) { mass = m; }
    52 
    53         public Double getS() { return size; }
    54         public void setS(Double s) { size = s; }
    55 
    5632        public Double getDn() { return density; }
    5733        public void setDn(Double dn) { density = dn; }
    5834
    59         public Double getFr() { return friction; }
    60         public void setFr(Double fr) { friction = fr; }
    6135
    6236        public Double getIng() { return ingestion; }
     
    6539        public Double getAs() { return assimilation; }
    6640        public void setAs(Double as) { assimilation = as; }
    67 
    68         public Double getRx() { return rotation.x; }
    69         public void setRx(Double rx) { rotation.x = rx; }
    70 
    71         public Double getRy() { return rotation.y; }
    72         public void setRy(Double ry) { rotation.y = ry; }
    73 
    74         public Double getRz() { return rotation.z; }
    75         public void setRz(Double rz) { rotation.z = rz; }
    7641
    7742        public String getI() { return info; }
  • java/main/src/main/java/com/framsticks/observers/Observer.java

    r77 r78  
    3030
    3131    @Override
    32     protected void configure() {
     32    protected void configure() throws Exception {
    3333        super.configure();
    3434        for (String name : config.getStringArray("endpoints")) {
     
    3838            }
    3939            Configuration c = config.subset("endpoints." + name);
    40             Parameters p = new Parameters(c.subset("entity"), name, null);
     40            Parameters p = new Parameters(c.subset("entity"), name, null, null);
    4141            Entity e = Program.configureEntity(p);
    4242            Instance i = Casting.tryCast(Instance.class, e);
  • java/main/src/main/java/com/framsticks/params/AccessInterface.java

    r77 r78  
    8080
    8181        /**
    82          * Load values from single line String.
    83          *
    84          * @param line
    85          *            the line with values
    86          * @return the list of not severe exceptions which occurred while loading
    87          * @throws Exception
    88          *             the severe exception occurred while loading
    89          */
    90         List<Exception> load2(String line) throws Exception;
    91 
    92         /**
    9382         * Removes all the properties values.
    9483         */
     
    10796    FramsClass getFramsClass();
    10897
     98
    10999}
  • java/main/src/main/java/com/framsticks/params/FramsClass.java

    r77 r78  
    55import com.framsticks.params.types.FloatParam;
    66import com.framsticks.params.types.StringParam;
     7import com.framsticks.parsers.FileSource;
     8import com.framsticks.parsers.Loaders;
    79import com.framsticks.util.Casting;
    810import org.apache.log4j.Logger;
    911
    1012import javax.lang.model.element.TypeElement;
     13import java.io.InputStream;
    1114import java.lang.reflect.*;
    1215import java.util.*;
     
    5861
    5962        public Collection<Param> getParamEntries() {
    60                 return paramEntryMap.values();
     63                return paramList;
    6164        }
    6265
     
    214217                }
    215218            }
     219                        if (rawType.equals(List.class)) {
     220                                Type containedType = p.getActualTypeArguments()[0];
     221                                if (containedType instanceof Class) {
     222                                        return "l " + ((Class) containedType).getCanonicalName();
     223                                }
     224                        }
    216225            return null;
    217226        }
     
    234243    public static final String GENERATE_HELP_PREFIX = "automatically generated from: ";
    235244
    236 
    237 
    238     public static class Constructor {
     245        public static FramsClass readFromStream(InputStream stream) {
     246                return Loaders.loadFramsClass(new FileSource(stream));
     247        }
     248
     249        public static class Constructor {
    239250        protected final FramsClass result;
    240251        protected Class currentClass;
     
    249260                currentClass = currentClass.getSuperclass();
    250261            }
     262                        currentClass = src;
    251263        }
    252264
     
    254266            return result;
    255267        }
     268
     269                public Constructor allFields() {
     270                        for (Field f : currentClass.getFields()) {
     271                                field(f.getName());
     272                        }
     273                        return this;
     274                }
    256275
    257276        public Constructor method(String name, Class<?> ... arguments) {
  • java/main/src/main/java/com/framsticks/params/ListAccess.java

    r77 r78  
    7373        }
    7474
    75         @Override
    76         public List<Exception> load2(String line) throws Exception {
    77                 return null;
    78         }
    79 
    8075        public AccessInterface getElementAccess() {
    8176                return elementAccess;
  • java/main/src/main/java/com/framsticks/params/Param.java

    r77 r78  
    109109        } catch (ClassCastException e) {
    110110            throw new ClassCastException("property \"" + name
    111                     + "\" getType is \"" + value.getClass().getName()
     111                    + "\" type is \"" + value.getClass().getName()
    112112                    + "\", not \"" + type.getName() + "\"");
    113113        }
  • java/main/src/main/java/com/framsticks/params/PropertiesAccess.java

    r77 r78  
    2020    @Override
    2121        public Map<String, Object> createAccessee() {
     22                return PropertiesAccess.createPropertiesMap();
     23        }
     24
     25        public static Map<String, Object> createPropertiesMap() {
    2226                return new HashMap<String, Object>();
    2327        }
    24 
    2528
    2629        public PropertiesAccess(FramsClass framsClass) {
     
    8386
    8487
    85 
    86 
    8788}
  • java/main/src/main/java/com/framsticks/params/ReflectionAccess.java

    r77 r78  
    33import java.lang.reflect.Field;
    44import java.lang.reflect.InvocationTargetException;
     5import java.lang.reflect.Modifier;
     6import java.lang.reflect.Type;
    57import java.util.List;
    68
     
    4345                        String id = param.getId();
    4446                        try {
    45                                 return type.cast(object.getClass().getField(id).get(object));
     47                                return type.cast(reflectedClass.getField(id).get(object));
    4648                        } catch (NoSuchFieldException ignored) {
    4749                        }
    4850                        try {
    49                                 return type.cast(object.getClass().getMethod(accessorName(true, id)).invoke(object));
     51                                return type.cast(reflectedClass.getMethod(accessorName(true, id)).invoke(object));
    5052                        } catch (NoSuchMethodException ex) {
    5153                                //ex.printStackTrace();
     
    6870        }
    6971
    70         private <T> void setValue(Param param, T val) {
     72        private <T> void setValue(Param param, T value) {
    7173                if (object == null) {
    7274                        return;
     
    7577                        String id = param.getId();
    7678                        try {
    77                                 object.getClass().getField(id).set(object, val);
     79                                Field f = reflectedClass.getField(id);
     80                                Class t = f.getType();
     81                                if (Modifier.isFinal(f.getModifiers())) {
     82                                        return;
     83                                }
     84                                if (value != null || (!t.isPrimitive())) {
     85                                        f.set(object, value);
     86                                }
    7887                                return;
    7988                        } catch (NoSuchFieldException ignored) {
    8089                        }
    8190                        try {
    82                                 object.getClass().getMethod(accessorName(false, id), new Class[]{val.getClass()}).invoke(object, val);
    83                         } catch (InvocationTargetException e) {
    84                                 //e.printStackTrace();
     91                                reflectedClass.getMethod(accessorName(false, id), new Class[]{param.getStorageType()}).invoke(object, value);
     92                        } catch (InvocationTargetException ignored) {
    8593                        } catch (NoSuchMethodException ignored) {
    8694                        }
    87                 } catch (IllegalAccessException ex) {
    88                         LOGGER.warn("illegal access error occurred while trying to access returnedObject");
     95                } catch (Exception ex) {
    8996                        ex.printStackTrace();
    9097                }
     
    103110                resetErrors();
    104111
    105                 Field[] fields;
    106112                try {
    107                         // TODO: conceptually invalid - should clean only fields that are specified in FramsClass
    108                         fields = object.getClass().getFields();
    109 
    110                         for (Field field : fields) {
    111                                 field.set(object, null);
     113                        for (Param p : framsClass.getParamEntries()) {
     114                                setValue(p, p.getDef(Object.class));
    112115                        }
    113                 } catch (IllegalAccessException ex) {
    114                         LOGGER.warn("IllegalAccessException thrown while trying to reset object values");
     116                } catch (IllegalArgumentException ex) {
    115117                        ex.printStackTrace();
    116118                }
     
    125127        @Override
    126128        public void select(Object object) {
     129                assert object == null || reflectedClass.isInstance(object);
    127130                this.object = object;
    128131        }
     
    166169        }
    167170        LOGGER.fatal("failed to create reflected object of class " + reflectedClass.getCanonicalName() + " for frams type " + framsClass.getId());
    168 
    169171        return null;
    170172    }
  • java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java

    r77 r78  
    3838                this.framsClass = framsClass;
    3939        }
    40 
    41 
    42 
    43 
    4440    /**
    4541         * Simple String key, value class.
    4642         */
    47         private static class Entry {
    48 
    49                 String key;
    50                 String value;
    51 
    52                 Entry(String key, String value) {
     43        public static class Entry {
     44
     45                public final String key;
     46                public final String value;
     47
     48                public Entry(String key, String value) {
    5349                        this.key = key;
    5450                        this.value = value;
     
    331327
    332328        Entry entry;
    333 
    334329        while ((entry = readEntry(source)) != null) {
    335330            Param param = getParam(entry.key);
     
    351346    }
    352347
    353     @Override
    354         public List<Exception> load2(String line) throws Exception {
    355                 this.clearValues();
    356 
    357                 // list of not terminable exceptions that occured
    358                 List<Exception> exceptions = new ArrayList<Exception>();
    359 
    360                 int indexOfColon = line.indexOf(':');
    361                 if (indexOfColon < 0)
    362                         indexOfColon = line.length();
    363                 String classId = line.substring(0, indexOfColon).trim();
    364                 if (!getId().equals(classId))
    365                         throw new Exception(
    366                                         "Inappropriate getId of param interface (class), specified \""
    367                                                         + classId + "\" while should be \"" + getId()
    368                                                         + "\"");
    369                 String parameters;
    370                 if (indexOfColon == line.length())
    371                         parameters = "";
    372                 else
    373                         parameters = line.substring(indexOfColon + 1);
    374 
    375                 // tokenize
    376                 boolean doubleQuotes = false;
    377                 char previousChar = ',';
    378                 List<Entry> result = new ArrayList<Entry>();
    379                 StringBuilder stringBuilder = new StringBuilder();
    380                 String key = "";
    381                 if (parameters.trim().length() > 0) {
    382                         for (char currentChar : parameters.toCharArray()) {
    383                                 if (!doubleQuotes && currentChar == '=' && "".equals(key)) {
    384                                         key = stringBuilder.toString();
    385                                         stringBuilder = new StringBuilder();
    386                                 } else if (!doubleQuotes && currentChar == ',') {
    387                                         if (previousChar == ',') {
    388                                                 result.add(new Entry(key.trim(), null));
    389                                         } else {
    390                                                 result.add(new Entry(key.trim(), stringBuilder
    391                                                                 .toString().trim()));
    392                                         }
    393                                         stringBuilder = new StringBuilder();
    394                                         key = "";
    395                                 } else if (currentChar == '"') {
    396                                         if (previousChar == '\\') {
    397                                                 stringBuilder.deleteCharAt(stringBuilder.length() - 1);
    398                                                 stringBuilder.append(currentChar);
    399                                         } else
    400                                                 doubleQuotes = !doubleQuotes;
    401                                 } else {
    402                                         stringBuilder.append(currentChar);
    403                                 }
    404 
    405                                 previousChar = currentChar;
    406                         }
    407 
    408                         String last = stringBuilder.toString().trim();
    409                         // if (last.length() > 0 || previousChar == '\"'
    410                         // || previousChar == ':')
    411                         result.add(new Entry(key.trim(), last));
    412 
    413                         if (doubleQuotes)
    414                                 throw new Exception(
    415                                                 "Double quotes expected while end of line met");
    416                 }
    417 
    418                 // if successfully parsed set all necessary values
    419 
    420                 //TODO: name omitting
    421                 Param currentParam = null;
    422                 boolean illegallyOmittedName = false;
    423                 for (Entry pair : result) {
    424                         try {
    425 
    426                                 if (pair.key != null && !"".equals(pair.key)) {
    427                                         Param param = getParam(pair.key);
    428                                         if (param == null) {
    429                                                 illegallyOmittedName = true;
    430                                                 throw new Exception("No parameter with such id: "
    431                                                                 + pair.key);
    432                                         } else {
    433                                                 currentParam = param;
    434                                                 illegallyOmittedName = false;
    435                                         }
    436                                 } else if (illegallyOmittedName
    437                                                 || (currentParam.getFlags() & Flags.CANOMITNAME) == 0) {
    438                                         throw new Exception(
    439                                                         "Parameter with offset: "
    440                                                                         + currentParam
    441                                                                         + " is not set, "
    442                                                                         + "because it's definition or definition of one of the previous params "
    443                                                                         + "does not contain flag, which allow to skip the getName (flag 1024)");
    444                                 }
    445 
    446                                 if (pair.value != null) {
    447                                         int setFlag = this.set(currentParam, pair.value);
    448                                         if ((setFlag & Flags.PSET_HITMIN) != 0) {
    449                                                 exceptions.add(createBoundaryHitException(currentParam, pair.value, Flags.PSET_HITMIN));
    450                                         }
    451 
    452                                         if ((setFlag & Flags.PSET_HITMAX) != 0) {
    453                                                 exceptions.add(createBoundaryHitException(currentParam, pair.value, Flags.PSET_HITMAX));
    454                                         }
    455 
    456                                         if ((setFlag & Flags.PSET_RONLY) != 0) {
    457                                                 throw (new Exception(
    458                                                                 "Tried to set a read-only attribute \""
    459                                                                                 + currentParam.getId()
    460                                                                                 + "\" in class \"" + getId() + "\""));
    461                                         }
    462                                 }
    463 
    464                         } catch (Exception e) {
    465                                 exceptions.add(e);
    466                         //} finally {
    467                         //  currentProperty++;
    468                         }
    469                 }
    470                 return exceptions;
    471         }
    472 
    473         private Exception createBoundaryHitException(Param param, String value, int flag) {
    474                 boolean minimum = (flag & Flags.PSET_HITMIN) != 0;
    475                 String boundary = (minimum ? param.getMin(Object.class) : param.getMax(Object.class)).toString();
    476                 String name =  (minimum ? "minimum" : "maximum");
    477                 return new Exception("Tried to set attribute \""
    478                                 + param.getId()
    479                                 + "\" in class \""
    480                                 + getId()
    481                                 + "\" to value which exceeds " + name + " ("
    482                                 + value
    483                                 + "), truncated to: "
    484                                 + boundary);
    485         }
    486        
     348
     349
    487350        protected abstract <T> void internalSet(Param param, T value);
    488351
  • java/main/src/main/java/com/framsticks/params/Util.java

    r77 r78  
    11package com.framsticks.params;
     2
     3import java.util.ArrayList;
     4import java.util.List;
    25
    36/**
     
    1417        return result.toString();
    1518    }
     19        public static List<Object> stripAccessInterface(List<AccessInterface> accesses) {
     20                List<Object> result = new ArrayList<Object>();
     21                for (AccessInterface a : accesses) {
     22                        result.add(a.getSelected());
     23                }
     24                return result;
     25        }
     26        public static int copyParams(AccessInterface to, AccessInterface from) {
     27                int copied = 0;
     28                for (Param f : from.getParams()) {
     29                        Param t = from.getParam(f.getId());
     30                        if (t == null) {
     31                                continue;
     32                        }
     33                        if (to.getClass() != f.getClass()) {
     34                                continue;
     35                        }
     36                        to.set(t, from.get(f, Object.class));
     37                        ++copied;
     38                }
     39                return copied;
     40        }
    1641}
  • java/main/src/main/java/com/framsticks/parsers/FileSource.java

    r77 r78  
    33import com.framsticks.params.SourceInterface;
    44
    5 import java.io.BufferedReader;
    6 import java.io.FileReader;
    7 import java.io.IOException;
     5import java.io.*;
    86
    97
     
    1715                this.filename = filename;
    1816        reader = new BufferedReader(new FileReader(filename));
     17        }
     18
     19        public FileSource(InputStream stream) {
     20                filename = "<stream>";
     21                reader = new BufferedReader(new InputStreamReader(stream));
    1922        }
    2023
  • java/main/src/main/java/com/framsticks/parsers/Schema.java

    r77 r78  
    11package com.framsticks.parsers;
    22
     3import java.io.File;
     4import java.io.FileInputStream;
    35import java.io.IOException;
    46import java.io.InputStream;
     
    810import java.util.Map.Entry;
    911
    10 import com.framsticks.params.FramsClass;
    11 import com.framsticks.params.Param;
     12import com.framsticks.params.*;
    1213import com.framsticks.params.types.DecimalParam;
     14import com.framsticks.params.types.FloatParam;
    1315import com.framsticks.params.types.StringParam;
    1416import org.apache.log4j.Logger;
     
    1921
    2022import com.framsticks.leftovers.f0.NeuroClass;
    21 import com.framsticks.params.Group;
    22 import com.framsticks.params.ParamBuilder;
    2323import org.w3c.dom.Document;
    2424import org.w3c.dom.NamedNodeMap;
     
    3939        private final static Logger logger = Logger.getLogger(Schema.class);
    4040
    41         /** The main classes (such as part, joint, etc.) */
    42         private Map<String, FramsClass> mainClasses = new HashMap<String, FramsClass>();
     41        protected final Registry registry = new Registry();
    4342
    4443        /** The neuro classes (classess representing different types of neurons). */
    4544        private Map<String, NeuroClass> neuroClasses = new HashMap<String, NeuroClass>();
    4645
    47         // TODO: definition can be changed
    48         /**
    49          * Instantiates a new schema with usage of f0def.xml file stored in
    50          * resources.
    51          *
    52          * @throws Exception
    53          *             the exception if one occured while reading the stream
    54          */
    55         public Schema() throws Exception {
    56                 this(Thread.currentThread().getContextClassLoader()
    57                                 .getResourceAsStream("f0def.xml"));
     46        public static InputStream getDefaultDefinitionAsStream() {
     47                //return new FileInputStream(new File(Schema.class.getResource("/parsers/f0def.xml").getPath()));
     48                return Schema.class.getResourceAsStream("/parsers/f0def.xml");
    5849        }
    5950
     
    6152         * Instantiates a new schema.
    6253         *
    63          * @param xmlStream
     54         * @param inputStream
    6455         *            the xml stream with schema
    6556         * @throws Exception
    66          *             the exception if one occured while reading the stream
    67          */
    68         public Schema(InputStream xmlStream) throws Exception {
     57         *             the exception if one occurred while reading the stream
     58         */
     59        public Schema(InputStream inputStream) throws Exception {
    6960
    7061                DocumentBuilderFactory factory;
     
    7566                        db = factory.newDocumentBuilder();
    7667
    77                         Document document = db.parse(xmlStream);
     68                        Document document = db.parse(inputStream);
    7869                        NodeList classes = document.getElementsByTagName("CLASS");
    7970
     
    8172                                Node classNode = classes.item(i);
    8273                                FramsClass framsClass = processClass(classNode);
    83                                 mainClasses.put(framsClass.getId(), framsClass);
     74                                registry.putInfoIntoCache(framsClass);
    8475                        }
    8576
     
    10697                                                        symbolGlymph[j] = Integer.parseInt(sgha[j]);
    10798                                                } catch (NumberFormatException e) {
    108                                                         logger.error("an error occured while parsing symbol glymph, class getId: "
     99                                                        logger.error("an error occurred while parsing symbol glymph, class getId: "
    109100                                                                        + framsClass.getId()
    110101                                                                        + ", glymph offset: " + j);
     
    119110
    120111                } catch (IOException e) {
    121                         logger.fatal("unexpected exception occured: ", e);
     112                        logger.fatal("unexpected exception occurred: ", e);
    122113                        throw e;
    123114                } catch (ParserConfigurationException e) {
    124                         logger.fatal("unexpected exception occured: ", e);
     115                        logger.fatal("unexpected exception occurred: ", e);
    125116                        throw e;
    126117                } catch (SAXException e) {
    127                         logger.fatal("unexpected exception occured: ", e);
     118                        logger.fatal("unexpected exception occurred: ", e);
    128119                        throw e;
    129120                }
     
    140131         */
    141132        private static int getIntAttribute(NamedNodeMap attributes, String name) {
     133                String v = getAttribute(attributes, name);
     134                if (v == null) {
     135                        return 0;
     136                }
    142137                try {
    143                         return Integer.parseInt(getAttribute(attributes, name));
     138                        return Integer.parseInt(v);
    144139                } catch (NullPointerException e) {
    145140                        return 0;
    146141                } catch (NumberFormatException e) {
    147142                        logger.fatal("attribute " + name
    148                                         + " should be numeric (it is not)");
     143                                        + " should be numeric: " + v);
    149144                        return 0;
    150145                }
     
    186181         *             the exception in case of any error
    187182         */
    188         private FramsClass processClass(Node classNode) throws Exception {
     183        private static FramsClass processClass(Node classNode) throws Exception {
    189184                String classId = null;
    190185                String className = "";
     
    200195                classDescription = getAttributeFromNode("DESCRIPTION", classNode);
    201196
    202                 FramsClass framsClass = new FramsClass(classId, className,
    203                                 classDescription);
     197                FramsClass framsClass = new FramsClass(classId, className, classDescription);
    204198
    205199                NodeList classProperties = classNode.getChildNodes();
     
    210204                        if ("GROUP".equals(node.getNodeName())) {
    211205                                NamedNodeMap attributes = node.getAttributes();
    212                                 String name = attributes.getNamedItem("NAME") == null ? null
    213                                                 : attributes.getNamedItem("NAME").getNodeValue();
    214                                 if (name == null)
    215                                         logger.warn("Group getName in class \"" + classId + "\" ("
     206                                String name = getAttribute(attributes, "NAME");
     207                                if (name == null) {
     208                                        logger.warn("Group name in class \"" + classId + "\" ("
    216209                                                        + className + ") is undefined");
    217                                 else
     210                                } else {
    218211                                        framsClass.appendGroup(new Group(name));
    219 
     212                                }
    220213                        } else if ("PROP".equals(node.getNodeName())
    221214                                        || "NEUROPROP".equals(node.getNodeName())) {
     
    232225
    233226        /**
    234          * It analyses the single property within the clas
     227         * It analyses the single property within the class
    235228         *
    236229         * @param attributes
     
    242235         *             the exception in case of any error
    243236         */
    244         private Param processParameter(NamedNodeMap attributes, String classId)
     237        private static Param processParameter(NamedNodeMap attributes, String classId)
    245238                        throws Exception {
    246239
     
    315308                                }
    316309                        }
    317                         builder.setType(DecimalParam.class);
     310                        builder.setType(FloatParam.class);
    318311                        builder.setMin(minMaxDefDouble.get("MIN"));
    319312                        builder.setMax(minMaxDefDouble.get("MAX"));
     
    330323        }
    331324
    332         public Map<String, FramsClass> getMainClasses() {
    333                 return Collections.unmodifiableMap(mainClasses);
    334         }
    335325
    336326        public Map<String, NeuroClass> getNeuroClasses() {
     
    338328        }
    339329
     330        public final Registry getRegistry() {
     331                return registry;
     332        }
     333
     334
    340335}
  • java/main/src/main/java/com/framsticks/portals/Portal.java

    r77 r78  
    3636
    3737    @Override
    38     protected void configure() {
     38    protected void configure() throws Exception {
    3939        super.configure();
    4040    }
  • java/main/src/main/java/com/framsticks/util/Orientation.java

    r77 r78  
    99    public final Point3d z;
    1010
    11     public Orientation() {
    12         x = new Point3d();
    13         y = new Point3d();
    14         z = new Point3d();
    15     }
     11        public Orientation(Point3d x, Point3d y, Point3d z) {
     12                this.x = x;
     13                this.y = y;
     14                this.z = z;
     15        }
     16
     17        public Orientation() {
     18                x = new Point3d(1, 0, 0);
     19                y = new Point3d(0, 1, 0);
     20                z = new Point3d(0, 0, 1);
     21        }
     22
     23        /** based on c++ void Orient::transform(Pt3D& target,const Pt3D &s) const */
     24        public Point3d transform(Point3d source) {
     25                Point3d.Builder b = new Point3d.Builder();
     26                for (int i = 0; i < 3; ++i) {
     27                        double v = 0;
     28                        for (int j = 0; j < 3; ++j) {
     29                                v += source.get(j) * this.get(j).get(i);
     30                        }
     31                        b.set(i, v);
     32                }
     33                return b.build();
     34        }
     35
     36        /** based on c++ void Orient::transform(Orient& target,const Orient& src) const */
     37        public Orientation transform(Orientation source) {
     38                return new Orientation(transform(source.x), transform(source.y), transform(source.z));
     39        }
     40
     41        protected static Point3d rotate2D(double sin, double cos, Point3d p, int a0, int a1, int im) {
     42                Point3d.Builder b = new Point3d.Builder();
     43                b.set(a0, cos * p.get(a0) - sin * p.get(a1));
     44                b.set(a1, sin * p.get(a0) + cos * p.get(a1));
     45                b.set(im, p.get(im));
     46                return b.build();
     47        }
     48
     49        /** based on c++ Orient::rotate(const Pt3D &v) */
     50        public Orientation rotate(Point3d v) {
     51                Point3d[] p = new Point3d[] {x, y, z};
     52
     53                for (int i = 0; i < 3; ++i) {
     54                        double sin = Math.sin(v.get(i));
     55                        double cos = Math.cos(v.get(i));
     56
     57                        for (int j = 0; j < 3; ++j) {
     58                                p[j] = rotate2D(sin, cos, p[j], i == 0 ? 1 : 0, i == 2 ? 1 : 2, i);
     59                        }
     60                }
     61                return new Orientation(p[0], p[1], p[2]);
     62        }
     63
     64        final Point3d get(int i) {
     65                switch (i) {
     66                        case 0: return x;
     67                        case 1: return y;
     68                        case 2: return z;
     69                }
     70                assert false;
     71                return null;
     72        }
    1673
    1774
     75        @Override
     76        public final String toString() {
     77                return x + " | " + y + " | " + z;
     78        }
    1879}
  • java/main/src/main/java/com/framsticks/util/Point3d.java

    r77 r78  
    66public class Point3d
    77{
    8         public Double x;
    9         public Double y;
    10         public Double z;
     8        public final double x;
     9        public final double y;
     10        public final double z;
    1111
    1212        public Point3d() {
     
    1616        }
    1717
    18         public Point3d(Double x, Double y, Double z) {
     18        public Point3d(double x, double y, double z) {
    1919                this.x = x;
    2020                this.y = y;
     
    2222        }
    2323
     24        public Point3d(Point3d p) {
     25                x = p.x;
     26                y = p.y;
     27                z = p.z;
     28        }
     29
    2430        @Override
    25         public String toString() {
    26                 //return new StringBuilder().append(x).append(" ").append(y).append(" ").append("z").toString();
     31        public final String toString() {
    2732                return x + " " + y + " " + z;
    2833        }
     34
     35        public final double get(int i) {
     36                switch (i) {
     37                        case 0: return x;
     38                        case 1: return y;
     39                        case 2: return z;
     40                }
     41                assert false;
     42                return 0;
     43        }
     44
     45
     46        public final Point3d add(Point3d p) {
     47                return new Point3d(x + p.x, y + p.y, z + p.z);
     48        }
     49
     50        public final Point3d sub(Point3d p) {
     51                return new Point3d(x - p.x, y - p.y, z - p.z);
     52        }
     53
     54        public final double length() {
     55                return Math.sqrt(x * x + y * y + z * z);
     56        }
     57
     58        public static class Builder {
     59                double[] a = new double[3];
     60
     61                public Point3d build() { return new Point3d(a[0], a[1], a[2]); }
     62
     63                public final void set(int i, double v) {
     64                        a[i] = v;
     65                }
     66        }
    2967}
  • java/main/src/main/java/com/framsticks/visualization/Viewer.java

    r77 r78  
    11package com.framsticks.visualization;
    22
    3 import com.framsticks.communication.Connection;
    43import com.framsticks.model.World;
    54import com.sun.j3d.loaders.IncorrectFormatException;
     
    2221import java.awt.event.ActionListener;
    2322import java.io.FileNotFoundException;
    24 import java.util.ArrayList;
    2523
    2624import org.apache.log4j.Logger;
    2725
    28 
    29 
    3026public class Viewer {
    31     static final long serialVersionUID = 1;
    32 
    33     private static Logger logger = Logger.getLogger(Viewer.class);
     27
     28    private static Logger LOGGER = Logger.getLogger(Viewer.class);
    3429
    3530    Canvas3D canvas3d;
     
    4540    private JCheckBoxMenuItem autorefreshItem;
    4641
    47         private Connection connection;
    48     ArrayList<String> args;
    49 
    50     public Viewer(ArrayList<String> args, JMenuBar menuBar) {
     42    public Viewer(JMenuBar menuBar) {
    5143        super();
    52         this.args = args;
    5344        this.menuBar = menuBar;
    5445        loggingItem = new JCheckBoxMenuItem("Logging");
     
    5647
    5748        init();
    58 
    5949    }
    6050
     
    261251    }
    262252
    263 
    264 
    265 
    266     public void setCommunication(Connection connection) {
    267         this.connection = connection;
    268     }
    269 
    270253    public void rebuildViewMenu(Object creatures) {
    271254
  • java/main/src/main/resources/configs/framsticks.properties

    r77 r78  
    11com.framsticks.entities.browser.class=com.framsticks.gui.Browser
    2 #com.framsticks.entities.browser.endpoints=localhost,dump,remote_portal
    32com.framsticks.entities.browser.size.width=1500
    43com.framsticks.entities.browser.size.height=800
    5 com.framsticks.entities.browser.endpoints=localhost,dump
     4com.framsticks.entities.browser.endpoints=localhost,dump,genotype_browser
    65com.framsticks.entities.browser.endpoints.dump.entity.class=com.framsticks.dumping.FileInstance
    76com.framsticks.entities.browser.endpoints.dump.entity.filename=dumps/localhost:9009__.param
    87com.framsticks.entities.browser.endpoints.localhost.entity.mount=com.framsticks.entities.localhost
    98com.framsticks.entities.browser.endpoints.remote_portal.entity.mount=com.framsticks.entities.remote_portal
     9com.framsticks.entities.browser.endpoints.genotype_browser.entity.mount=com.framsticks.entities.genotype_browser
    1010
    1111com.framsticks.entities.diagnostics.class=com.framsticks.diagnostics.Diagnostics
     
    3030com.framsticks.entities.hosted_portal.hosted.entity.mount=com.framsticks.entities.portal
    3131
    32 #com.framsticks.entity=browser
     32com.framsticks.entities.genotype_browser.class=com.framsticks.examples.GenotypeBrowser
     33
     34com.framsticks.entity.mount = com.framsticks.entities.browser
  • java/main/src/main/resources/configs/log4j.properties

    r77 r78  
    33# -------------------------------------------------------------------
    44#log4j.rootLogger=INFO, STDOUT, FILE
    5 log4j.rootLogger=DEBUG, STDOUT, FILE
     5log4j.rootLogger=DEBUG, STDOUT
    66
    77
     
    2727log4j.appender.STDOUT.layout.ConversionPattern=%d{ABSOLUTE} [%-5p] [%t] %c -- %m%n
    2828
    29 # File appender
    30 log4j.appender.FILE=org.apache.log4j.FileAppender
    31 log4j.appender.FILE.File=${user.home}/frams_network_client.log
    32 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    33 log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} [%-5p] [%t] %c -- %m%n
    3429
    3530log4j.logger.com.framsticks=INFO
Note: See TracChangeset for help on using the changeset viewer.