Changeset 78
- Timestamp:
- 01/09/13 00:09:10 (12 years ago)
- Location:
- java/main
- Files:
-
- 36 added
- 3 deleted
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/pom.xml
r77 r78 15 15 </repository> 16 16 </repositories> 17 17 <properties> 18 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 19 </properties> 18 20 <build> 19 21 <plugins> … … 58 60 <version>1.5.2</version> 59 61 </dependency> 62 63 <dependency> 64 <groupId>junit</groupId> 65 <artifactId>junit</artifactId> 66 <version>4.8.1</version> 67 <scope>test</scope> 68 </dependency> 60 69 <!--dependency> 61 70 </dependency> -
java/main/src/main/java/com/framsticks/core/Entity.java
r77 r78 4 4 import com.framsticks.util.Thread; 5 5 import org.apache.log4j.Logger; 6 7 import java.util.HashSet;8 import java.util.Set;9 6 10 7 /** … … 37 34 } 38 35 39 public final void configurePublic() {36 public final void configurePublic() throws Exception { 40 37 configure(); 41 38 } 42 39 43 protected void configure() {40 protected void configure() throws Exception { 44 41 45 42 } … … 58 55 } 59 56 57 public final void done() { 58 LOGGER.info("stopping entity"); 59 if (owner != null) { 60 owner.onDone(); 61 } 62 } 63 60 64 61 65 } -
java/main/src/main/java/com/framsticks/core/Instance.java
r77 r78 23 23 protected Node root; 24 24 25 protected final Map<String, FramsClass> infoCache = new HashMap<String, FramsClass>();26 25 public Set<InstanceListener> listeners = new HashSet<InstanceListener>(); 27 26 … … 34 33 protected void run() { 35 34 super.run(); 36 registerTypicalReflectedClasses();35 com.framsticks.model.Package.register(registry); 37 36 } 38 37 39 38 @Override 40 protected void configure() {39 protected void configure() throws Exception { 41 40 super.configure(); 42 41 } 43 42 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 } 49 74 50 75 public void storeValue(Path path, Param param, Object value, final StateFunctor stateFunctor) { … … 98 123 } 99 124 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 }109 125 110 126 public final FramsClass getInfoFromCache(Path path) { … … 115 131 public FramsClass getInfoFromCache(String id) { 116 132 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(); 141 137 142 138 public AccessInterface createAccess(String name) { … … 150 146 } 151 147 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); 157 149 } 158 150 … … 188 180 AccessInterface access = prepareAccess(node.getParam()); 189 181 if (access == null) { 182 LOGGER.error("missing access for: " + node.getParam()); 190 183 return null; 191 184 } … … 287 280 } 288 281 } 289 putInfoIntoCache(framsClass);282 registry.putInfoIntoCache(framsClass); 290 283 return framsClass; 291 284 } … … 338 331 } 339 332 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 351 333 public static Iterator<String> splitPath(String path) { 352 334 List<String> list = new LinkedList<String>(); … … 359 341 } 360 342 343 public Registry getRegistry() { 344 return registry; 345 } 361 346 } 347 -
java/main/src/main/java/com/framsticks/core/LocalInstance.java
r77 r78 45 45 46 46 @Override 47 protected void configure() {47 protected void configure() throws Exception { 48 48 super.configure(); 49 49 } … … 97 97 } 98 98 99 100 101 @Override102 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 @Override120 public void fetchValue(Path path, Param param, StateFunctor stateFunctor) {121 stateFunctor.call(null);122 }123 124 @Override125 public void fetchValues(Path path, StateFunctor stateFunctor) {126 stateFunctor.call(null);127 }128 129 130 99 } -
java/main/src/main/java/com/framsticks/core/Parameters.java
r77 r78 12 12 protected String name; 13 13 protected Dispatcher dispatcher; 14 protected EntityOwner owner; 14 15 15 public Parameters(Configuration config, String name, Dispatcher dispatcher) { 16 17 18 public Parameters(Configuration config, String name, Dispatcher dispatcher, EntityOwner owner) { 16 19 this.config = config; 17 20 this.name = name; 18 21 this.dispatcher = dispatcher; 22 this.owner = owner; 19 23 } 20 24 … … 23 27 name = parameters.name; 24 28 dispatcher = parameters.dispatcher; 29 owner = parameters.owner; 25 30 } 26 31 -
java/main/src/main/java/com/framsticks/core/Program.java
r77 r78 6 6 import org.apache.log4j.Logger; 7 7 import org.apache.log4j.PropertyConfigurator; 8 import sun.misc.Signal;9 import sun.misc.SignalHandler;8 //import sun.misc.Signal; 9 //import sun.misc.SignalHandler; 10 10 11 11 import java.lang.reflect.Constructor; … … 19 19 private final static Logger LOGGER = Logger.getLogger(Program.class.getName()); 20 20 21 /* 21 22 protected SignalHandler signalHandler = new SignalHandler() { 22 23 @Override … … 26 27 } 27 28 }; 29 */ 28 30 29 31 protected Entity entity; … … 34 36 public Program(String name) { 35 37 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); 38 40 } 39 41 … … 44 46 Class type = Class.forName(typeName); 45 47 Constructor constructor = type.getConstructor(Parameters.class); 46 Entity entity = (Entity) constructor.newInstance(parameters); 47 return entity; 48 return (Entity) constructor.newInstance(parameters); 48 49 } catch (Exception e) { 49 50 LOGGER.error("failed to instantiate: " + e); … … 96 97 } 97 98 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 } 100 111 LOGGER.info("all entities were configured"); 101 112 entity.start(); -
java/main/src/main/java/com/framsticks/diagnostics/Diagnostics.java
r77 r78 23 23 24 24 @Override 25 protected void configure() {25 protected void configure() throws Exception { 26 26 27 27 super.configure(); -
java/main/src/main/java/com/framsticks/dumping/FileInstance.java
r77 r78 53 53 } 54 54 55 56 @Override57 protected void fetchInfo(Path path, Future<FramsClass> future) {58 future.result(null, new UnsupportedOperationException());59 }60 61 @Override62 protected void tryRegisterOnChangeEvents(Path path) {63 }64 65 66 55 @Override 67 56 public String toString() { -
java/main/src/main/java/com/framsticks/dumping/SaveStream.java
r77 r78 37 37 this.instance = instance; 38 38 this.stateFunctor = stateFunctor; 39 dispatched = 1; 40 write(root); 39 dispatchWrite(root); 41 40 } 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 } 42 51 43 52 protected void finished() { … … 53 62 } else { 54 63 AccessInterface access = instance.bindAccess(path); 64 assert access != null; 55 65 FramsClass framsClass = access.getFramsClass(); 56 66 assert framsClass != null; … … 76 86 final Path childPath = path.appendNode(new Node(childParam, access.get(childParam, Object.class))); 77 87 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); 85 89 } 86 90 } … … 92 96 } 93 97 } 94 95 96 98 } -
java/main/src/main/java/com/framsticks/gui/Browser.java
r77 r78 45 45 46 46 @Override 47 protected void configure() {47 protected void configure() throws Exception { 48 48 super.configure(); 49 49 } -
java/main/src/main/java/com/framsticks/gui/Frame.java
r77 r78 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.core.Node; 3 4 import com.framsticks.core.Path; 4 5 import com.framsticks.gui.view.*; … … 12 13 import javax.swing.tree.*; 13 14 import java.awt.*; 15 import java.awt.datatransfer.StringSelection; 14 16 import java.awt.event.ActionEvent; 15 17 import java.awt.event.MouseAdapter; … … 75 77 treePopupMenu.add(new JMenuItem("Refresh")); 76 78 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 }); 77 87 //this.add(createMenuItem("Add to favourites", null)); 78 88 //this.add(createMenuItem("Remove from favourites", null)); -
java/main/src/main/java/com/framsticks/gui/TreeNode.java
r77 r78 124 124 LOGGER.debug("updating children of " + this); 125 125 AccessInterface access = p.getInstance().bindAccess(p.getTop()); 126 if (access == null) { 127 return; 128 } 126 129 final List<Path> childrenPaths = new LinkedList<Path>(); 127 130 /**Prepare path for each child.*/ … … 210 213 } 211 214 212 213 215 public final Panel getPanel() { 214 216 assert frame.isActive(); … … 222 224 } 223 225 AccessInterface access = p.getInstance().bindAccess(p); 224 assert access != null; 226 if (access == null) { 227 return; 228 } 225 229 StringBuilder t = new StringBuilder(); 226 230 /** html formatting is used here, since tooltips in swing do not support simple \n line breaks */ … … 494 498 495 499 return true; 500 } 501 502 public Path getInstancePath() { 503 assert frame.isActive(); 504 return path; 496 505 } 497 506 -
java/main/src/main/java/com/framsticks/hosting/ServerInstance.java
r77 r78 30 30 31 31 @Override 32 protected void configure() {32 protected void configure() throws Exception { 33 33 super.configure(); 34 34 35 Parameters p = new Parameters(config.subset("hosted.entity"), "hosted", this );35 Parameters p = new Parameters(config.subset("hosted.entity"), "hosted", this, null); 36 36 hosted = Program.configureEntity(p); 37 37 if (hosted == null) { … … 49 49 return null; 50 50 } 51 if (infoCache.containsKey(id)) { 52 return infoCache.get(id); 51 FramsClass cached = registry.getInfoFromCache(id); 52 if (cached != null) { 53 return cached; 53 54 } 54 55 try { … … 56 57 FramsClass framsClass = new FramsClass.Constructor(nativeClass, id).getResult(); 57 58 58 regist erReflectedClass(id, nativeClass);59 putInfoIntoCache(framsClass);59 registry.registerReflectedClass(null, id, nativeClass); 60 registry.putInfoIntoCache(framsClass); 60 61 return framsClass; 61 62 } catch (ClassNotFoundException ignored) { -
java/main/src/main/java/com/framsticks/model/Creature.java
r77 r78 1 1 package com.framsticks.model; 2 2 3 import com.framsticks. model.MechPart;4 import com.framsticks. model.Joint;3 import com.framsticks.params.FramsClass; 4 import com.framsticks.util.Orientation; 5 5 import com.framsticks.util.Point3d; 6 6 … … 8 8 import java.util.List; 9 9 10 public class Creature {10 public class Creature extends F0Model { 11 11 public String name; 12 12 … … 94 94 public void setVertpos(Double c_vertpos) { averageVerticalPosition = c_vertpos; } 95 95 96 public Point3d position = new Point3d(); 96 /** pos_x, pos_y, pos_z*/ 97 public double pos_x, pos_y, pos_z; 97 98 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; } 100 101 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; 103 103 104 public Double getPos_z() { return position.z; }105 public void set Pos_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; } 106 106 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; }110 107 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; 113 110 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; } 127 113 128 114 public Integer getNumparts() { return parts.size(); } … … 161 147 public final List<NeuroDef> neurodefs = new ArrayList<NeuroDef>(); 162 148 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; } 166 154 167 155 168 156 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 169 164 } -
java/main/src/main/java/com/framsticks/model/Genotype.java
r77 r78 2 2 3 3 4 import com.framsticks.util.Containers;4 import org.apache.log4j.Logger; 5 5 6 import java.util.ArrayList; 7 import java.util.List;6 public class Genotype extends F0Genotype { 7 private final static Logger LOGGER = Logger.getLogger(Genotype.class); 8 8 9 public class Genotype {10 9 public String name; 11 10 public String genotype; … … 15 14 public Double getSimi() { return similarity; } 16 15 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; }21 16 22 17 public Double brainConnections; … … 40 35 public Double velocity; 41 36 public Double distance; 42 43 37 44 38 public Double verticalVelocity; … … 78 72 public String uid; 79 73 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 } 83 75 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 readonly90 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 8 8 * All accessors are used by ReflectionAccess. 9 9 */ 10 public class Joint {10 public class Joint extends BaseJoint { 11 11 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; 12 19 public void setP1(Integer p1) { part1 = p1; } 13 20 public Integer getP1() { return part1; } 21 22 /** p2 */ 23 public Integer part2; 14 24 public void setP2(Integer p2) { part2 = p2; } 15 25 public Integer getP2() { return part2; } 16 26 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; }20 27 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; 33 30 public Double getStam() { return stamina; } 34 31 public void setStam(Double stam) { stamina = stam; } 35 32 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;71 33 72 34 /** Vstyle */ 73 35 public String visualizationStyle; 74 75 36 public String getVstyle() { return visualizationStyle; } 37 public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; } 76 38 } -
java/main/src/main/java/com/framsticks/model/MechJoint.java
r77 r78 6 6 * @author Piotr Sniegowski 7 7 */ 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; 8 public class MechJoint extends BaseJoint { 20 9 21 10 /** stress */ 22 11 public Double stress; 12 public Double getStress() { return stress; } 13 public void setStress(Double stress) { this.stress = stress; } 23 14 24 15 /** rotstress */ 25 16 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 54 17 public Double getRotstress() { return rotationStress; } 55 18 public void setRotstress(Double rotstress) { rotationStress = rotstress; } 56 57 19 } -
java/main/src/main/java/com/framsticks/model/MechPart.java
r77 r78 6 6 /* 7 7 */ 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; 8 public class MechPart extends BasePart { 18 9 19 10 /** vol */ 20 11 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 46 12 public Double getVol() { return volume; } 47 13 public void setVol(Double vol) { volume = vol; } 48 14 49 public Double getFr() { return friction; }50 public void setFr(Double fr) { friction = fr; }15 /** vx, vy, vz*/ 16 public double vx, vy, vz; 51 17 52 public Double getVx() { return velocity.x; }53 public void setV x(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; } 54 20 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; 57 22 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)); } 60 24 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 } 87 36 88 37 } -
java/main/src/main/java/com/framsticks/model/Neuro.java
r77 r78 6 6 * @author Piotr Sniegowski 7 7 */ 8 public class Neuro {8 public class Neuro extends BaseNeuro { 9 9 10 10 public Integer channelCount; 11 12 public Integer inputCount;13 public Integer getGetInputCount() { return inputCount; }14 public void setGetInputCount(Integer getInputCount) { inputCount = getInputCount; }15 11 16 12 public Double inputSum; … … 26 22 public Boolean hold; 27 23 24 public double position_x, position_y, position_z; 28 25 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; } 40 28 41 29 } -
java/main/src/main/java/com/framsticks/model/NeuroDef.java
r77 r78 4 4 * @author Piotr Sniegowski 5 5 */ 6 public class NeuroDef {6 public class NeuroDef extends BaseNeuro { 7 7 8 8 /** p */ … … 21 21 public String visualizationStyle; 22 22 23 /** getInputCount */24 public Integer inputCount;25 26 23 public Integer getP() { return part; } 27 24 public void setP(Integer p) { part = p; } … … 39 36 public void setVstyle(String Vstyle) { visualizationStyle = Vstyle; } 40 37 41 public Integer getGetInputCount() { return inputCount; }42 public void setGetInputCount(Integer getInputCount) { inputCount = getInputCount; }43 38 44 39 -
java/main/src/main/java/com/framsticks/model/Part.java
r77 r78 7 7 * The Class Part. 8 8 */ 9 public class Part { 10 11 /** x, y, z*/ 12 public final Point3d position = new Point3d(); 9 public class Part extends BasePart { 13 10 14 11 /** rx, ry, rz*/ 15 public final Point3d rotation = new Point3d();12 public double rx, ry, rz; 16 13 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; } 22 16 23 17 /** dn */ 24 18 public Double density; 25 26 /** fr */27 public Double friction;28 19 29 20 /** ing */ … … 39 30 public String visualizationStyle; 40 31 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 56 32 public Double getDn() { return density; } 57 33 public void setDn(Double dn) { density = dn; } 58 34 59 public Double getFr() { return friction; }60 public void setFr(Double fr) { friction = fr; }61 35 62 36 public Double getIng() { return ingestion; } … … 65 39 public Double getAs() { return assimilation; } 66 40 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; }76 41 77 42 public String getI() { return info; } -
java/main/src/main/java/com/framsticks/observers/Observer.java
r77 r78 30 30 31 31 @Override 32 protected void configure() {32 protected void configure() throws Exception { 33 33 super.configure(); 34 34 for (String name : config.getStringArray("endpoints")) { … … 38 38 } 39 39 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); 41 41 Entity e = Program.configureEntity(p); 42 42 Instance i = Casting.tryCast(Instance.class, e); -
java/main/src/main/java/com/framsticks/params/AccessInterface.java
r77 r78 80 80 81 81 /** 82 * Load values from single line String.83 *84 * @param line85 * the line with values86 * @return the list of not severe exceptions which occurred while loading87 * @throws Exception88 * the severe exception occurred while loading89 */90 List<Exception> load2(String line) throws Exception;91 92 /**93 82 * Removes all the properties values. 94 83 */ … … 107 96 FramsClass getFramsClass(); 108 97 98 109 99 } -
java/main/src/main/java/com/framsticks/params/FramsClass.java
r77 r78 5 5 import com.framsticks.params.types.FloatParam; 6 6 import com.framsticks.params.types.StringParam; 7 import com.framsticks.parsers.FileSource; 8 import com.framsticks.parsers.Loaders; 7 9 import com.framsticks.util.Casting; 8 10 import org.apache.log4j.Logger; 9 11 10 12 import javax.lang.model.element.TypeElement; 13 import java.io.InputStream; 11 14 import java.lang.reflect.*; 12 15 import java.util.*; … … 58 61 59 62 public Collection<Param> getParamEntries() { 60 return param EntryMap.values();63 return paramList; 61 64 } 62 65 … … 214 217 } 215 218 } 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 } 216 225 return null; 217 226 } … … 234 243 public static final String GENERATE_HELP_PREFIX = "automatically generated from: "; 235 244 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 { 239 250 protected final FramsClass result; 240 251 protected Class currentClass; … … 249 260 currentClass = currentClass.getSuperclass(); 250 261 } 262 currentClass = src; 251 263 } 252 264 … … 254 266 return result; 255 267 } 268 269 public Constructor allFields() { 270 for (Field f : currentClass.getFields()) { 271 field(f.getName()); 272 } 273 return this; 274 } 256 275 257 276 public Constructor method(String name, Class<?> ... arguments) { -
java/main/src/main/java/com/framsticks/params/ListAccess.java
r77 r78 73 73 } 74 74 75 @Override76 public List<Exception> load2(String line) throws Exception {77 return null;78 }79 80 75 public AccessInterface getElementAccess() { 81 76 return elementAccess; -
java/main/src/main/java/com/framsticks/params/Param.java
r77 r78 109 109 } catch (ClassCastException e) { 110 110 throw new ClassCastException("property \"" + name 111 + "\" getType is \"" + value.getClass().getName()111 + "\" type is \"" + value.getClass().getName() 112 112 + "\", not \"" + type.getName() + "\""); 113 113 } -
java/main/src/main/java/com/framsticks/params/PropertiesAccess.java
r77 r78 20 20 @Override 21 21 public Map<String, Object> createAccessee() { 22 return PropertiesAccess.createPropertiesMap(); 23 } 24 25 public static Map<String, Object> createPropertiesMap() { 22 26 return new HashMap<String, Object>(); 23 27 } 24 25 28 26 29 public PropertiesAccess(FramsClass framsClass) { … … 83 86 84 87 85 86 87 88 } -
java/main/src/main/java/com/framsticks/params/ReflectionAccess.java
r77 r78 3 3 import java.lang.reflect.Field; 4 4 import java.lang.reflect.InvocationTargetException; 5 import java.lang.reflect.Modifier; 6 import java.lang.reflect.Type; 5 7 import java.util.List; 6 8 … … 43 45 String id = param.getId(); 44 46 try { 45 return type.cast( object.getClass().getField(id).get(object));47 return type.cast(reflectedClass.getField(id).get(object)); 46 48 } catch (NoSuchFieldException ignored) { 47 49 } 48 50 try { 49 return type.cast( object.getClass().getMethod(accessorName(true, id)).invoke(object));51 return type.cast(reflectedClass.getMethod(accessorName(true, id)).invoke(object)); 50 52 } catch (NoSuchMethodException ex) { 51 53 //ex.printStackTrace(); … … 68 70 } 69 71 70 private <T> void setValue(Param param, T val ) {72 private <T> void setValue(Param param, T value) { 71 73 if (object == null) { 72 74 return; … … 75 77 String id = param.getId(); 76 78 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 } 78 87 return; 79 88 } catch (NoSuchFieldException ignored) { 80 89 } 81 90 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) { 85 93 } catch (NoSuchMethodException ignored) { 86 94 } 87 } catch (IllegalAccessException ex) { 88 LOGGER.warn("illegal access error occurred while trying to access returnedObject"); 95 } catch (Exception ex) { 89 96 ex.printStackTrace(); 90 97 } … … 103 110 resetErrors(); 104 111 105 Field[] fields;106 112 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)); 112 115 } 113 } catch (IllegalAccessException ex) { 114 LOGGER.warn("IllegalAccessException thrown while trying to reset object values"); 116 } catch (IllegalArgumentException ex) { 115 117 ex.printStackTrace(); 116 118 } … … 125 127 @Override 126 128 public void select(Object object) { 129 assert object == null || reflectedClass.isInstance(object); 127 130 this.object = object; 128 131 } … … 166 169 } 167 170 LOGGER.fatal("failed to create reflected object of class " + reflectedClass.getCanonicalName() + " for frams type " + framsClass.getId()); 168 169 171 return null; 170 172 } -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r77 r78 38 38 this.framsClass = framsClass; 39 39 } 40 41 42 43 44 40 /** 45 41 * Simple String key, value class. 46 42 */ 47 p rivatestatic 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) { 53 49 this.key = key; 54 50 this.value = value; … … 331 327 332 328 Entry entry; 333 334 329 while ((entry = readEntry(source)) != null) { 335 330 Param param = getParam(entry.key); … … 351 346 } 352 347 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 487 350 protected abstract <T> void internalSet(Param param, T value); 488 351 -
java/main/src/main/java/com/framsticks/params/Util.java
r77 r78 1 1 package com.framsticks.params; 2 3 import java.util.ArrayList; 4 import java.util.List; 2 5 3 6 /** … … 14 17 return result.toString(); 15 18 } 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 } 16 41 } -
java/main/src/main/java/com/framsticks/parsers/FileSource.java
r77 r78 3 3 import com.framsticks.params.SourceInterface; 4 4 5 import java.io.BufferedReader; 6 import java.io.FileReader; 7 import java.io.IOException; 5 import java.io.*; 8 6 9 7 … … 17 15 this.filename = filename; 18 16 reader = new BufferedReader(new FileReader(filename)); 17 } 18 19 public FileSource(InputStream stream) { 20 filename = "<stream>"; 21 reader = new BufferedReader(new InputStreamReader(stream)); 19 22 } 20 23 -
java/main/src/main/java/com/framsticks/parsers/Schema.java
r77 r78 1 1 package com.framsticks.parsers; 2 2 3 import java.io.File; 4 import java.io.FileInputStream; 3 5 import java.io.IOException; 4 6 import java.io.InputStream; … … 8 10 import java.util.Map.Entry; 9 11 10 import com.framsticks.params.FramsClass; 11 import com.framsticks.params.Param; 12 import com.framsticks.params.*; 12 13 import com.framsticks.params.types.DecimalParam; 14 import com.framsticks.params.types.FloatParam; 13 15 import com.framsticks.params.types.StringParam; 14 16 import org.apache.log4j.Logger; … … 19 21 20 22 import com.framsticks.leftovers.f0.NeuroClass; 21 import com.framsticks.params.Group;22 import com.framsticks.params.ParamBuilder;23 23 import org.w3c.dom.Document; 24 24 import org.w3c.dom.NamedNodeMap; … … 39 39 private final static Logger logger = Logger.getLogger(Schema.class); 40 40 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(); 43 42 44 43 /** The neuro classes (classess representing different types of neurons). */ 45 44 private Map<String, NeuroClass> neuroClasses = new HashMap<String, NeuroClass>(); 46 45 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"); 58 49 } 59 50 … … 61 52 * Instantiates a new schema. 62 53 * 63 * @param xmlStream54 * @param inputStream 64 55 * the xml stream with schema 65 56 * @throws Exception 66 * the exception if one occur ed while reading the stream67 */ 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 { 69 60 70 61 DocumentBuilderFactory factory; … … 75 66 db = factory.newDocumentBuilder(); 76 67 77 Document document = db.parse( xmlStream);68 Document document = db.parse(inputStream); 78 69 NodeList classes = document.getElementsByTagName("CLASS"); 79 70 … … 81 72 Node classNode = classes.item(i); 82 73 FramsClass framsClass = processClass(classNode); 83 mainClasses.put(framsClass.getId(),framsClass);74 registry.putInfoIntoCache(framsClass); 84 75 } 85 76 … … 106 97 symbolGlymph[j] = Integer.parseInt(sgha[j]); 107 98 } catch (NumberFormatException e) { 108 logger.error("an error occur ed while parsing symbol glymph, class getId: "99 logger.error("an error occurred while parsing symbol glymph, class getId: " 109 100 + framsClass.getId() 110 101 + ", glymph offset: " + j); … … 119 110 120 111 } catch (IOException e) { 121 logger.fatal("unexpected exception occur ed: ", e);112 logger.fatal("unexpected exception occurred: ", e); 122 113 throw e; 123 114 } catch (ParserConfigurationException e) { 124 logger.fatal("unexpected exception occur ed: ", e);115 logger.fatal("unexpected exception occurred: ", e); 125 116 throw e; 126 117 } catch (SAXException e) { 127 logger.fatal("unexpected exception occur ed: ", e);118 logger.fatal("unexpected exception occurred: ", e); 128 119 throw e; 129 120 } … … 140 131 */ 141 132 private static int getIntAttribute(NamedNodeMap attributes, String name) { 133 String v = getAttribute(attributes, name); 134 if (v == null) { 135 return 0; 136 } 142 137 try { 143 return Integer.parseInt( getAttribute(attributes, name));138 return Integer.parseInt(v); 144 139 } catch (NullPointerException e) { 145 140 return 0; 146 141 } catch (NumberFormatException e) { 147 142 logger.fatal("attribute " + name 148 + " should be numeric (it is not)");143 + " should be numeric: " + v); 149 144 return 0; 150 145 } … … 186 181 * the exception in case of any error 187 182 */ 188 private FramsClass processClass(Node classNode) throws Exception {183 private static FramsClass processClass(Node classNode) throws Exception { 189 184 String classId = null; 190 185 String className = ""; … … 200 195 classDescription = getAttributeFromNode("DESCRIPTION", classNode); 201 196 202 FramsClass framsClass = new FramsClass(classId, className, 203 classDescription); 197 FramsClass framsClass = new FramsClass(classId, className, classDescription); 204 198 205 199 NodeList classProperties = classNode.getChildNodes(); … … 210 204 if ("GROUP".equals(node.getNodeName())) { 211 205 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 + "\" (" 216 209 + className + ") is undefined"); 217 else210 } else { 218 211 framsClass.appendGroup(new Group(name)); 219 212 } 220 213 } else if ("PROP".equals(node.getNodeName()) 221 214 || "NEUROPROP".equals(node.getNodeName())) { … … 232 225 233 226 /** 234 * It analyses the single property within the clas 227 * It analyses the single property within the class 235 228 * 236 229 * @param attributes … … 242 235 * the exception in case of any error 243 236 */ 244 private Param processParameter(NamedNodeMap attributes, String classId)237 private static Param processParameter(NamedNodeMap attributes, String classId) 245 238 throws Exception { 246 239 … … 315 308 } 316 309 } 317 builder.setType( DecimalParam.class);310 builder.setType(FloatParam.class); 318 311 builder.setMin(minMaxDefDouble.get("MIN")); 319 312 builder.setMax(minMaxDefDouble.get("MAX")); … … 330 323 } 331 324 332 public Map<String, FramsClass> getMainClasses() {333 return Collections.unmodifiableMap(mainClasses);334 }335 325 336 326 public Map<String, NeuroClass> getNeuroClasses() { … … 338 328 } 339 329 330 public final Registry getRegistry() { 331 return registry; 332 } 333 334 340 335 } -
java/main/src/main/java/com/framsticks/portals/Portal.java
r77 r78 36 36 37 37 @Override 38 protected void configure() {38 protected void configure() throws Exception { 39 39 super.configure(); 40 40 } -
java/main/src/main/java/com/framsticks/util/Orientation.java
r77 r78 9 9 public final Point3d z; 10 10 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 } 16 73 17 74 75 @Override 76 public final String toString() { 77 return x + " | " + y + " | " + z; 78 } 18 79 } -
java/main/src/main/java/com/framsticks/util/Point3d.java
r77 r78 6 6 public class Point3d 7 7 { 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; 11 11 12 12 public Point3d() { … … 16 16 } 17 17 18 public Point3d( Double x, Double y, Double z) {18 public Point3d(double x, double y, double z) { 19 19 this.x = x; 20 20 this.y = y; … … 22 22 } 23 23 24 public Point3d(Point3d p) { 25 x = p.x; 26 y = p.y; 27 z = p.z; 28 } 29 24 30 @Override 25 public String toString() { 26 //return new StringBuilder().append(x).append(" ").append(y).append(" ").append("z").toString(); 31 public final String toString() { 27 32 return x + " " + y + " " + z; 28 33 } 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 } 29 67 } -
java/main/src/main/java/com/framsticks/visualization/Viewer.java
r77 r78 1 1 package com.framsticks.visualization; 2 2 3 import com.framsticks.communication.Connection;4 3 import com.framsticks.model.World; 5 4 import com.sun.j3d.loaders.IncorrectFormatException; … … 22 21 import java.awt.event.ActionListener; 23 22 import java.io.FileNotFoundException; 24 import java.util.ArrayList;25 23 26 24 import org.apache.log4j.Logger; 27 25 28 29 30 26 public 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); 34 29 35 30 Canvas3D canvas3d; … … 45 40 private JCheckBoxMenuItem autorefreshItem; 46 41 47 private Connection connection; 48 ArrayList<String> args; 49 50 public Viewer(ArrayList<String> args, JMenuBar menuBar) { 42 public Viewer(JMenuBar menuBar) { 51 43 super(); 52 this.args = args;53 44 this.menuBar = menuBar; 54 45 loggingItem = new JCheckBoxMenuItem("Logging"); … … 56 47 57 48 init(); 58 59 49 } 60 50 … … 261 251 } 262 252 263 264 265 266 public void setCommunication(Connection connection) {267 this.connection = connection;268 }269 270 253 public void rebuildViewMenu(Object creatures) { 271 254 -
java/main/src/main/resources/configs/framsticks.properties
r77 r78 1 1 com.framsticks.entities.browser.class=com.framsticks.gui.Browser 2 #com.framsticks.entities.browser.endpoints=localhost,dump,remote_portal3 2 com.framsticks.entities.browser.size.width=1500 4 3 com.framsticks.entities.browser.size.height=800 5 com.framsticks.entities.browser.endpoints=localhost,dump 4 com.framsticks.entities.browser.endpoints=localhost,dump,genotype_browser 6 5 com.framsticks.entities.browser.endpoints.dump.entity.class=com.framsticks.dumping.FileInstance 7 6 com.framsticks.entities.browser.endpoints.dump.entity.filename=dumps/localhost:9009__.param 8 7 com.framsticks.entities.browser.endpoints.localhost.entity.mount=com.framsticks.entities.localhost 9 8 com.framsticks.entities.browser.endpoints.remote_portal.entity.mount=com.framsticks.entities.remote_portal 9 com.framsticks.entities.browser.endpoints.genotype_browser.entity.mount=com.framsticks.entities.genotype_browser 10 10 11 11 com.framsticks.entities.diagnostics.class=com.framsticks.diagnostics.Diagnostics … … 30 30 com.framsticks.entities.hosted_portal.hosted.entity.mount=com.framsticks.entities.portal 31 31 32 #com.framsticks.entity=browser 32 com.framsticks.entities.genotype_browser.class=com.framsticks.examples.GenotypeBrowser 33 34 com.framsticks.entity.mount = com.framsticks.entities.browser -
java/main/src/main/resources/configs/log4j.properties
r77 r78 3 3 # ------------------------------------------------------------------- 4 4 #log4j.rootLogger=INFO, STDOUT, FILE 5 log4j.rootLogger=DEBUG, STDOUT , FILE5 log4j.rootLogger=DEBUG, STDOUT 6 6 7 7 … … 27 27 log4j.appender.STDOUT.layout.ConversionPattern=%d{ABSOLUTE} [%-5p] [%t] %c -- %m%n 28 28 29 # File appender30 log4j.appender.FILE=org.apache.log4j.FileAppender31 log4j.appender.FILE.File=${user.home}/frams_network_client.log32 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout33 log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} [%-5p] [%t] %c -- %m%n34 29 35 30 log4j.logger.com.framsticks=INFO
Note: See TracChangeset
for help on using the changeset viewer.