source: java/main/src/main/java/com/framsticks/model/ModelBuilder.java @ 90

Last change on this file since 90 was 90, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File size: 3.4 KB
Line 
1package com.framsticks.model;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.Iterator;
6import java.util.List;
7
8import com.framsticks.model.f0.Schema;
9import com.framsticks.params.Util;
10import com.framsticks.params.annotations.AutoAppendAnnotation;
11import com.framsticks.params.annotations.FramsClassAnnotation;
12// import com.framsticks.params.annotations.ParamAnnotation;
13import com.framsticks.parsers.F0Parser;
14import com.framsticks.util.AutoBuilder;
15import com.framsticks.util.FramsticksException;
16import com.framsticks.util.ResourceBuilder;
17import com.framsticks.util.lang.Casting;
18import com.framsticks.util.lang.IterableIterator;
19import com.framsticks.util.math.Orientation;
20
21@FramsClassAnnotation
22public class ModelBuilder extends ResourceBuilder<Model> implements AutoBuilder {
23
24        Schema schema;
25        final List<ModelComponent> components = new ArrayList<>();
26
27        @Override
28        public Model finish() {
29                if (stream == null && components.isEmpty()) {
30                        throw new FramsticksException().msg("model builder instance not ready");
31                }
32                if (stream != null) {
33                        if (schema == null) {
34                                schema = Schema.getDefaultSchema();
35                        }
36                        F0Parser parser = new F0Parser(schema, stream);
37                        components.addAll(Util.stripAccessInterface(parser.parse(), ModelComponent.class));
38                }
39                return build();
40        }
41
42        /**
43         * @return the schema
44         */
45        public Schema getSchema() {
46                return schema;
47        }
48
49        /**
50         * @param schema the schema to set
51         */
52        @AutoAppendAnnotation
53        public ModelBuilder schema(Schema schema) {
54                this.schema = schema;
55                return this;
56        }
57
58        @AutoAppendAnnotation
59        public ModelBuilder addComponent(ModelComponent component) {
60                components.add(component);
61                return this;
62        }
63
64        @AutoAppendAnnotation
65        public ModelBuilder addComponents(List<ModelComponent> component) {
66                this.components.addAll(component);
67                return this;
68        }
69
70        public Model build() {
71                Iterator<ModelComponent> i = components.iterator();
72                if (!i.hasNext()) {
73                        throw new FramsticksException().msg("empty components list");
74                }
75                Model f0Genotype = Casting.tryCast(Model.class, i.next());
76                if (f0Genotype == null) {
77                        throw new FramsticksException().msg("first component is not a Model");
78                }
79                for (ModelComponent component : new IterableIterator<ModelComponent>(i)) {
80                        if (component instanceof Joint) {
81                                f0Genotype.joints.add((Joint)component);
82                                continue;
83                        }
84                        if (component instanceof Part) {
85                                f0Genotype.parts.add((Part)component);
86                                continue;
87                        }
88                        if (component instanceof NeuroDefinition) {
89                                f0Genotype.neuroDefinitions.add((NeuroDefinition) component);
90                                continue;
91                        }
92                        if (component instanceof NeuroConnection) {
93                                f0Genotype.neuroConnections.add((NeuroConnection) component);
94                                continue;
95                        }
96                        throw new FramsticksException().msg("invalid class").arg("class", component.getClass().getCanonicalName());
97                }
98
99                for (Part p : f0Genotype.getParts()) {
100                        p.setOrientation(new Orientation().rotate(p.getRotation()));
101                }
102                for (Joint j : f0Genotype.getJoints()) {
103                        /** based on c++ Joint::attachToParts*/
104                        Part p1 = f0Genotype.parts.get(j.part1);
105                        Part p2 = f0Genotype.parts.get(j.part2);
106                        assert p1 != null && p2 != null;
107                        Orientation o = new Orientation().rotate(j.getRotation());
108                        p2.setOrientation(p1.getOrientation().transform(o));
109                        p2.setPosition(p2.getOrientation().transform(j.getDelta()).add(p1.getPosition()));
110                }
111                return f0Genotype;
112        }
113
114        @Override
115        public List<Object> autoFinish() {
116                Model model = finish();
117                assert schema != null;
118                return Arrays.asList(schema.getRegistry(), model);
119        }
120
121}
Note: See TracBrowser for help on using the repository browser.