source: java/main/src/main/java/com/framsticks/leftovers/f0/NeuroClass.java @ 87

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

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

File size: 4.6 KB
Line 
1package com.framsticks.leftovers.f0;
2
3import java.util.Arrays;
4
5import com.framsticks.params.FramsClass;
6import com.framsticks.params.Param;
7
8/**
9 * The Class NeuroClass.
10 */
11public class NeuroClass {
12        /*
13        public String name, longname, description, code, icon;
14        public Integer prefinputs, prefoutput, preflocation, vhints;
15        */
16
17        /**
18         * The symbol glyph.
19         */
20        private int[] symbolGlyph;
21
22        /**
23         * The pref inputs.
24         */
25        private int prefInputs;
26
27        /**
28         * The pref output.
29         */
30        private int prefOutput;
31
32        /**
33         * The pref location.
34         */
35        private int prefLocation;
36
37        /**
38         * The param entry list.
39         */
40        private FramsClass framsClass;
41
42        /**
43         * The visual hints.
44         */
45        private int visualHints;
46
47        /**
48         * long description.
49         *
50         * @return the description
51         */
52        String getDescription() {
53                return framsClass.getDescription();
54        }
55
56        /**
57         * class getId (short getName).
58         *
59         * @return the getId
60         */
61        String getId() {
62                return framsClass.getId();
63        }
64
65        /**
66         * Instantiates a new neuro class.
67         *
68         * @param framsClass   the param entry list
69         * @param prefInputs   the pref inputs
70         * @param prefOutput   the pref output
71         * @param prefLocation the pref location
72         * @param visualHints  the visual hints
73         * @param symbolGlyph the symbol glymph
74         */
75        public NeuroClass(FramsClass framsClass, int prefInputs,
76                                          int prefOutput, int prefLocation, int visualHints,
77                                          int[] symbolGlyph) {
78                this.framsClass = framsClass;
79                this.prefInputs = prefInputs;
80                this.prefOutput = prefOutput;
81                this.prefLocation = prefLocation;
82                this.visualHints = visualHints;
83                this.symbolGlyph = (symbolGlyph == null ? null : Arrays.copyOf(symbolGlyph, symbolGlyph.length));
84        }
85
86        /**
87         * human friendly getName, eg. "Neuron","Link","Gyroscope"
88         *
89         * @return the getName
90         */
91        String getName() {
92                return framsClass.getName();
93        }
94
95        /**
96         * NeuroClass specific properties, recognized by all neurons of this class.
97         *
98         * @return the param entry list
99         */
100        FramsClass getFramsClass() {
101                return framsClass;
102        }
103
104        /**
105         * Gets the param tab.
106         *
107         * @return the param tab
108         */
109        FramsClass getParamTab() {
110                return framsClass;
111        }
112
113        /**
114         * preferred number of inputs, -1 = no preference (any number will go).
115         * extra inputs may be ignored by the object (depends on the class).
116         *
117         * @return the preferred inputs
118         */
119        int getPreferredInputs() {
120                return prefInputs;
121        }
122
123        /**
124         * Gets the preferred location.
125         *
126         * @return 0 if the object doesn't need any assignment to the body element.
127         *         1 = it likes to be attached to the Part ( @see
128         *         Neuro::attachToPart() )
129         *         2 = the object prefers to have the Joint ( @see
130         *         Neuro::attachToJoint() )
131         */
132        int getPreferredLocation() {
133                return prefLocation;
134        }
135
136        /**
137         * Gets the preferred output.
138         *
139         * @return 0 if this object doesn't provide useful output signal.
140         */
141        int getPreferredOutput() {
142                return prefOutput;
143        }
144
145        /**
146         * vector drawing to be used in neuro net diagram. interpretation: { LEN =
147         * datalength (excluding this number) NL = number_of_lines line#1 -> NS =
148         * number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1, ... line#NL -> NS =
149         * number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1, }
150         *
151         * @return the symbol glyph
152         */
153        int[] getSymbolGlyph() {
154                return symbolGlyph;
155        }
156
157        /**
158         * vector drawing to be used in neuro net diagram. interpretation: { LEN =
159         * datalength (excluding this number) NL = number_of_lines line#1 -> NS =
160         * number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1, ... line#NL -> NS =
161         * number_of_segments, x1,y1, x2,y2, ... xNS-1,yNS-1, }
162         *
163         * @param data the new symbol glyph
164         */
165        void setSymbolGlyph(int[] data) {
166                symbolGlyph = data;
167        }
168
169        /**
170         * additional information about how the neuron should be drawn used by
171         * structure view (and maybe some other components). return value is defined
172         * by the enum Hint
173         *
174         * @return the visual hints
175         */
176        int getVisualHints() {
177                return visualHints;
178        }
179
180
181        @Override
182        public String toString() {
183                StringBuilder sb = new StringBuilder();
184                sb.append("NeuroClass [getId=").append(framsClass.getId())
185                                .append(", name=").append(framsClass.getName())
186                                .append(", description=").append(framsClass.getDescription())
187                                .append(", groups#=").append(framsClass.getGroupCount())
188                                .append(", prefInputs=").append(prefInputs)
189                                .append(", prefOutput=").append(prefOutput)
190                                .append(", prefLocation=").append(prefLocation)
191                                .append(", visualHints=").append(visualHints)
192                                .append(", symbolGlymph=").append(Arrays.toString(symbolGlyph));
193
194                sb.append(", paramList={");
195                for (int i = 0; i < framsClass.getParamCount(); i++) {
196                        sb.append("\n");
197                        sb.append(framsClass.getParamEntry(i, Param.class).toString());
198                }
199                sb.append("\n}]");
200                return sb.toString();
201        }
202}
Note: See TracBrowser for help on using the repository browser.