CreatingABasicForm

Version 1 (kervala, 09/29/2010 10:12 pm)

1 1 kervala
h1. Georges Form
2 1 kervala
3 1 kervala
h2. Introduction 
4 1 kervala
5 1 kervala
Georges is a versatile and flexible form loader built upon XML. A basic Georges form is comprised of three basic elements:
6 1 kervala
7 1 kervala
* The *Form* itself.
8 1 kervala
* The *Definition* (DFN) files.
9 1 kervala
* And *Type* (TYP) definitions.
10 1 kervala
11 1 kervala
To better understand how the pieces of a form come together it is easiest to learn the files in reverse order. Forms rely on definitions which rely on types. A type is the simplist piece of configuration in a Georges form.
12 1 kervala
13 1 kervala
h2. Types
14 1 kervala
15 1 kervala
Types are the smallest block of information in creating a Georges form. Before doing anything else you will need a set of basic types and an understanding of creating custom ones for your data types. First we'll show you two samples. These are types that can be used in a real application but are simple enough to see the basics of a type and give some examples elements to describe.
16 1 kervala
17 1 kervala
* int.typ - A basic integer.
18 1 kervala
19 1 kervala
<pre><code class="CPP"><?xml version="1.0"?>
20 1 kervala
<TYPE Type="SignedInt" UI="EditSpin" Default="0" Min="-9223372036854775808" Max="9223372036854775807">
21 1 kervala
</TYPE></code></pre>
22 1 kervala
23 1 kervala
* boolean.typ - A basic boolean.
24 1 kervala
25 1 kervala
<pre><code class="CPP"><?xml version="1.0"?>
26 1 kervala
<TYPE Type="String" UI="NonEditableCombo" Default="false">
27 1 kervala
  <DEFINITION Label="true" Value="true"/>
28 1 kervala
  <DEFINITION Label="false" Value="false"/
29 1 kervala
</TYPE></code></pre>
30 1 kervala
31 1 kervala
All type files should contain only one TYPE element but can contain several DEFINITION elements under TYPE. You can place other elements inside of a TYPE tag. For example some of the NeL tools will add a COMMENT and a LOG entry into the block to track changes on the type. Most of the properties of a type are self explanatory, but the DEFINITION elements need some extra commentary. DEFINITION's have a Label and a Value. The Label is the information used in form comparison and validation. The Value is what is returned when an atom is requested via the API for an atom matching that label. This is a way to create a list of valid values that don't adhere to minimum and maximum, for example the string-based boolean type above.
32 1 kervala
33 1 kervala
All types can contain the following properties:
34 1 kervala
35 1 kervala
    * Type - the type of data this will return. All Types must have this property.
36 1 kervala
    * UI - the type of UI widget an editor would use to edit this. All Types must have this property.
37 1 kervala
    * Default - the default value of elements/atoms using this data type.
38 1 kervala
    * Min - For numeric types the minimum valid value.
39 1 kervala
    * Max - For numeric types the maximum valid value.
40 1 kervala
    * Increment - For numeric values the increments the UI should edit in.
41 1 kervala
42 1 kervala
There are a number of valid data types a type can provide, they are:
43 1 kervala
44 1 kervala
    * UnsignedInt
45 1 kervala
    * SignedInt
46 1 kervala
    * Double
47 1 kervala
    * String
48 1 kervala
    * Color
49 1 kervala
50 1 kervala
The following are valid UI types that Georges will parse and provide to any tools using it:
51 1 kervala
52 1 kervala
    * Edit
53 1 kervala
    * EditSpin
54 1 kervala
    * NonEditableCombo
55 1 kervala
    * FileBrowser
56 1 kervala
    * BigEdit
57 1 kervala
    * ColorEdit
58 1 kervala
59 1 kervala
h2. Definitions
60 1 kervala
61 1 kervala
Definitions define the types of arrays, structures and atoms available in the form and the type of information they provide. All forms require one definition file at the minimum, the first definition file is loaded based upon the form's file extension. For example if your form file is named sample.config_data Georges will load the config_data.dfn definition file (and any definitions or types it utilizes) before it processes the form data. Definition files have two main elements:
62 1 kervala
63 1 kervala
    * ELEMENT - this describes the data contained in an array, struct, or atom.
64 1 kervala
    * PARENT - this forces a definition to load other definitions as dependencies. This is handy of you have some often-used atoms.
65 1 kervala
66 1 kervala
Lets see an example definition file:
67 1 kervala
sample_config.dfn
68 1 kervala
69 1 kervala
<pre><code class="CPP"><?xml version="1.0"?>
70 1 kervala
<DFN>
71 1 kervala
        <ELEMENT Name="TestVal1" Type="Type" Filename="int.typ" Default="0"/>
72 1 kervala
        <ELEMENT Name="TestVal2" Type="Type" Filename="int.typ" Default="0"/>
73 1 kervala
        <ELEMENT Name="WriteVal" Type="Type" Filename="int.typ" Default="0" />
74 1 kervala
        <ELEMENT Name="TestArray" Type="Type" Filename="string.typ" Array="true"/>
75 1 kervala
        <ELEMENT Name="CoolFilesInfo" Type="Dfn" Filename="coolfilesinfo.dfn" Array="true"/>
76 1 kervala
        <ELEMENT Name="TestByBracket" Type="Type" Filename="boolean.typ" Array="true"/>
77 1 kervala
        <ELEMENT Name="PositionData" Type="Dfn" Filename="positiondata.dfn" Array="false" />
78 1 kervala
</DFN></code></pre>
79 1 kervala
80 1 kervala
Elements are the most complicated piece of a definition as they have a number of variations depending on the type of data their atoms, etc. would contain. Elements with a type of "Type" will represent atoms that contain values. Elements require a Name, Type, and Filename property at the minimum. Elements represent three different types of data types: structs, arrays, and atoms. If you look ahead to forms, these different types of data may make more sense. In the XML above we see five examples of atom types, two arrays, and a structure. You can see the full set of these files in the sample in CVS, it may help make some of this make more sense.
81 1 kervala
82 1 kervala
h3. Elements for Atoms
83 1 kervala
84 1 kervala
When setting up an element for an atom you need to name it  (this is the name will be the one that the atom will use in the form,) you need to define it's type as "Type," and you need to define a filename. The filename defines the type of data (see types, above) any atoms using this element will use. Elements for atoms are the most simple types of element definitions. Note that you can also set the default value for an atom here, overriding the default value defined by the type.
85 1 kervala
86 1 kervala
<pre><code class="CPP"><ELEMENT Name="TestVal1" Type="Type" Filename="int.typ" Default="0"/></code></pre>
87 1 kervala
88 1 kervala
h3. Elements for Structs
89 1 kervala
90 1 kervala
In our example we also define a named struct. In the form when you do _<STRUCT Name="_PositionData">_ you need to create an element to describe this struct. Here is the example from above:
91 1 kervala
92 1 kervala
<pre><code class="CPP"><ELEMENT Name="PositionData" Type="Dfn" Filename="positiondata.dfn" Array="false" /></code></pre>
93 1 kervala
94 1 kervala
The name of the element must match the name of the struct in the form. You will set your type to Dfn and define the definition file's filename in the Filename property. This tells Georges this is a struct and how to determine what atoms are members of it. Finally you need to flag Array="false" so that Georges knows it's just one struct, not a named array of them.
95 1 kervala
96 1 kervala
h3. Elements for Arrays
97 1 kervala
98 1 kervala
There are two types of arrays to consider when creating an element entry for an array.
99 1 kervala
100 1 kervala
*Arrays of Atoms*
101 1 kervala
102 1 kervala
Arrays of atoms are the easiest types of array to define. Take the following snippet from the definition example above:
103 1 kervala
104 1 kervala
<pre><code class="CPP"><ELEMENT Name="TestArray" Type="Type" Filename="string.typ" Array="true"/></code></pre>
105 1 kervala
106 1 kervala
In essence what we've done was created an element definition for an atom and used the Array="true" property to tell Georges to expect a list of strings. You'll see an example of defining this array in the section on creating and editing forms.
107 1 kervala
108 1 kervala
*Arrays of Structs*
109 1 kervala
110 1 kervala
An array of structs is slightly more complicated, but still fairly simple in syntax. Instead of defining the type as "Type" you would define it as "Dfn." This tells Georges that it should expect a list of structures containing the elements listed in the Filename. Look at the following snippet from the XML above:
111 1 kervala
112 1 kervala
<pre><code class="CPP"><ELEMENT Name="CoolFilesInfo" Type="Dfn" Filename="coolfilesinfo.dfn" Array="true"/></code></pre>
113 1 kervala
114 1 kervala
We've informed Georges here that an array named "CoolFilesInfo" is going to contain a list of structs with the info contained in the definition file "coolfilesinfo.dfn." The sample for Georges in CVS contains that file and some code on accessing it through the Georges API.
115 1 kervala
116 1 kervala
h3. Element Information
117 1 kervala
118 1 kervala
Elements contain the following properties.
119 1 kervala
120 1 kervala
    * Name - the name of the element as it will be used in the form.
121 1 kervala
    * Filename - the filename of the file to be loaded to define this element's type.
122 1 kervala
    * FilenameExt - _I'm not sure what this is for, it defaults to "." and isn't used anywhere else in Georges or any of the tools or samples._
123 1 kervala
    * Type - specifies the type of dependency this element has for its type.
124 1 kervala
    * Default - specifies the default value for this element.
125 1 kervala
    * Array - this is a true/false string. This says that the form is going to specify multiple items of this element type in an array.
126 1 kervala
127 1 kervala
Valid Element Type values are:
128 1 kervala
129 1 kervala
    * Type - if this value is specified the definition loads the TYPE specified in the Filename property of the Element.
130 1 kervala
    * Dfn - for structs and arrays, defining the atoms they will contain.
131 1 kervala
    * DfnPointer - _I'm not sure what this is used for._
132 1 kervala
133 1 kervala
h2. Forms
134 1 kervala
135 1 kervala
Using the information from above about types and definitions you can finally get down to working on creating your form. Below is a trimmed down version of the form used in the Georges sample from SVN. Notice that the file extension of the form below is the filename of the extension list above in the definitions section.
136 1 kervala
137 1 kervala
default.sample_config
138 1 kervala
139 1 kervala
<pre><code class="CPP"><?xml version="1.0"?>
140 1 kervala
<FORM Version="0.0" State="modified">
141 1 kervala
        <STRUCT>
142 1 kervala
                <ATOM Name="TestVal1" Value="1"/>
143 1 kervala
                <ARRAY Name="TestArray">
144 1 kervala
                        <ATOM Value="Array Val 1"/>
145 1 kervala
                        <ATOM Value="Array Val 2"/>
146 1 kervala
                </ARRAY>
147 1 kervala
                <ARRAY Name="CoolFilesInfo">
148 1 kervala
                        <STRUCT>
149 1 kervala
                                <ATOM Name="ShortName" Value="Tiger Attack"/>
150 1 kervala
                                <ATOM Name="Ranking" Value="55"/>
151 1 kervala
                        </STRUCT>
152 1 kervala
                        <STRUCT>
153 1 kervala
                                <ATOM Name="ShortName" Value="Crazy Car Jump"/>
154 1 kervala
                                <ATOM Name="Ranking" Value="40"/>
155 1 kervala
                        </STRUCT>
156 1 kervala
                </ARRAY>
157 1 kervala
                <STRUCT Name="PositionData">
158 1 kervala
                        <ATOM Name="x" Value="1"/>
159 1 kervala
                        <ATOM Name="y" Value="1"/>
160 1 kervala
                        <ATOM Name="z" Value="2"/>
161 1 kervala
                </STRUCT>
162 1 kervala
        </STRUCT>
163 1 kervala
</FORM></code></pre>
164 1 kervala
165 1 kervala
Looking at the example form above you should start to see how forms reference elements in definitions. Some important things to note about forms. The first element must always be either a STRUCT or a PARENT and parents should come before STRUCTs. You should never put any other element type directly under a FORM. In the code example you will see that you can access the ATOMs in the first (default) struct by refering to them in dot notation such as ''".TestVal1"'' - the dot denotes they're a member of the root structure.
166 1 kervala
167 1 kervala
h3. Atoms
168 1 kervala
169 1 kervala
ATOMs represent individual data types, they define values you will use in your application. Atoms all have a Name property and a Value property. A name for an atom may be left out only if it is a member of a named array. Look at the ''TestArray'' example - the atoms contained in that array inherit their name (and thus element info) from the array.
170 1 kervala
171 1 kervala
h3. Arrays
172 1 kervala
173 1 kervala
Arrays in a form are simple. All they require is a name. This name allows Georges to find the element type from the definition and thus atom or definition information required to describe the items in the array. In the example above I provided two types of arrays. An array of structures and an array of atoms. Building these in the form is as straight forward as the example. Building the definitions is explained above in the definitions section. Arrays can be accessed programmatically by their name as well using bracket and bracket/dot notation. In the case of ''TestArray'' you can access the data using ''TestArray'' and in the case of ''CoolFilesInfo''  you could access it's member data as ''CoolFilesInfo.Ranking'' - examples of processes like this are given in the code sample.
174 1 kervala
175 1 kervala
h3. Structs
176 1 kervala
177 1 kervala
Structs are used in a number of ways already described in detail. But they can also be used in a standalone type to be accessed in dot notation as described in the arrays section. You can see this in the ''PositionData'' example in the form. Members of this structure can programmatically be accessed via the root node using the name ''PositionData.x'' or any of the other members.
178 1 kervala
179 1 kervala
h3. Form Information
180 1 kervala
181 1 kervala
Forms contain the following elements:
182 1 kervala
183 1 kervala
    * ATOM
184 1 kervala
    * STRUCT
185 1 kervala
    * VSTRUCT
186 1 kervala
    * ARRAY
187 1 kervala
    * And PARENT