Template plugIT » History » Version 2
arkeon, 06/13/2013 02:58 PM
1 | 1 | arkeon | h1. Template plugIT |
---|---|---|---|
2 | |||
3 | h2. Start a new plugIT (template) |
||
4 | |||
5 | 1 - choose his category (for example "misc") |
||
6 | create a new "template" directory in the category path : "Partition_LockedApp\tools\os3dplugins\misc" |
||
7 | |||
8 | 2 - create the plugIT definition file (xml) |
||
9 | the xml file MUST have the same name as the plugIT directory here "template.xml" |
||
10 | |||
11 | the PLUGIN tag : |
||
12 | - name : the plugIT name displayed in the OS3D plugIT menu |
||
13 | - version : the plugIT version |
||
14 | - type : the category name |
||
15 | |||
16 | the DESCRIPTION tag : |
||
17 | the plugIT description shown in the plugIT editor |
||
18 | |||
19 | the HELP tag : |
||
20 | the text shown as a tooltip on the help button in the plugIT editor, or an internet url pointing to the plugIT documentation |
||
21 | |||
22 | the RESOURCE tag : |
||
23 | it contain FILE tags with a "path" param, for additional files needed by the plugIT |
||
24 | |||
25 | the EDITOR tag : |
||
26 | it contain the scol scripts to load to execute the plugIT editor and the editor params and types to save |
||
27 | |||
28 | > the SCRIPT tag : |
||
29 | > > the "path" param contain the editor file, it can be relative to the plugIT directory with "./" |
||
30 | > the PARAM tag : |
||
31 | > > the "name" param contain the name of the editor variable to save |
||
32 | > > the "type" param contain the type of the param, it can be : |
||
33 | > > * "value" |
||
34 | > > * "file" |
||
35 | > > * "mesh" |
||
36 | > > * "material" |
||
37 | > > * "node" |
||
38 | > > * "light" |
||
39 | > > * "anim" |
||
40 | > > * ... |
||
41 | |||
42 | the CLIENT tag : |
||
43 | it contain the client side scol scripts and the default actions/events |
||
44 | |||
45 | > the SCRIPT tag : |
||
46 | > > the "path" param contain the editor file, it can be relative to the plugIT directory with "./" |
||
47 | |||
48 | > the EVENT tag : |
||
49 | > > it define an event name in the "name" param |
||
50 | |||
51 | > the ACTION tag : |
||
52 | > it define an action name in the "name" param |
||
53 | |||
54 | <pre> |
||
55 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||
56 | <PLUGIN name="template" version="1.0" type="misc"> |
||
57 | <DESCRIPTION>Template plugIT</DESCRIPTION> |
||
58 | <HELP>Template plugIT help</HELP> |
||
59 | <RESOURCE> |
||
60 | <FILE path="./myres.jpg" /> |
||
61 | </RESOURCE> |
||
62 | <EDITOR> |
||
63 | <SCRIPT path="./etemplate.pkg" /> |
||
64 | <PARAM name="oninit" type="value" /> |
||
65 | </EDITOR> |
||
66 | <CLIENT minstance="true"> |
||
67 | <SCRIPT path="./ctemplate.pkg" /> |
||
68 | <ACTION name="Go" /> |
||
69 | <EVENT name="Done" /> |
||
70 | </CLIENT> |
||
71 | </PLUGIN> |
||
72 | </pre> |
||
73 | |||
74 | 3 - create the editor file |
||
75 | here "etemplate.pkg" as defined in the template.xml file in the EDITOR SCRIPT tag |
||
76 | |||
77 | <pre> |
||
78 | // prototype of the cbCloseEdit function in case you don't use params |
||
79 | //proto cbCloseEdit = fun [] [[S S] r1];; |
||
80 | |||
81 | /*! \brief Callback on plugIT instance editor closed |
||
82 | * |
||
83 | * called on Apply / Ok button, this callback return the parameters to save in the XOS project |
||
84 | * |
||
85 | * <b>Prototype:</b> fun [] [[S S] r1] |
||
86 | * |
||
87 | * \return [[S S] r1] : parameters to save in the instance XML data |
||
88 | **/ |
||
89 | fun cbCloseEdit(ctrlinit)= |
||
90 | // get the check state and add it to the param list |
||
91 | let itoa getEdCtrlCheckState ctrlinit -> state in |
||
92 | ["oninit" state]:: |
||
93 | nil;; |
||
94 | |||
95 | |||
96 | /*! \brief Callback on plugIT instance editor destroyed |
||
97 | * |
||
98 | * called when the editor window is destroyed, this is useful to destroy added objects or resources |
||
99 | * |
||
100 | * <b>Prototype:</b> fun [] I |
||
101 | * |
||
102 | * \return I : 0 |
||
103 | **/ |
||
104 | fun cbDestroyEdit()= |
||
105 | 0;; |
||
106 | |||
107 | |||
108 | /*! \brief Callback on plugIT instance editor opened |
||
109 | * |
||
110 | * called when a user the plugIT Editor |
||
111 | * |
||
112 | 2 | arkeon | * <b>Prototype:</b> fun [EdWindow PInstance V3Dview] [fun [] [[S S] r1] fun [] I] |
113 | 1 | arkeon | * |
114 | * \param EdWindow : editor window structure |
||
115 | * \param PInstance : plugIT instance |
||
116 | * \param V3Dview : default 3D view structure |
||
117 | * |
||
118 | 2 | arkeon | * \return [fun [] [[S S] r1] fun [] I] : Callbacks to call on close and destroy |
119 | 1 | arkeon | **/ |
120 | fun dynamicedit(winstr, inst, viewstr) = |
||
121 | // size of the window |
||
122 | let [400 90] -> [iw ih] in |
||
123 | ( |
||
124 | // resize the editor window |
||
125 | setEdWindowSize winstr iw ih; |
||
126 | |||
127 | // retrieve the current param value |
||
128 | let atoi (getPluginInstanceParam inst "oninit") -> state in |
||
129 | |||
130 | // create the check box control on the editor window |
||
131 | let crEdCtrlCheck winstr 10 10 280 20 "Run on init" EDWIN_RESIZE_MW -> ctrlinit in |
||
132 | ( |
||
133 | // set the current check state |
||
134 | setEdCtrlCheckState ctrlinit state; |
||
135 | |||
136 | [(mkfun1 @cbCloseEdit ctrlinit) @cbDestroyEdit]; |
||
137 | ); |
||
138 | );; |
||
139 | </pre> |
||
140 | |||
141 | 4 - create the client file |
||
142 | here "ctemplate.pkg" as defined in the template.xml file in the CLIENT SCRIPT tag |
||
143 | |||
144 | <pre> |
||
145 | /*! \brief Callback on instance destruction |
||
146 | * Callback called when a plugIT instance is destroyed |
||
147 | * |
||
148 | * <b>Prototype:</b> fun [PInstance u0] I |
||
149 | * |
||
150 | * \param PInstance : destroyed plugIT instance |
||
151 | * \param u0 : user parameter, the type is not defined here because it is not used in this template |
||
152 | * |
||
153 | * \return I : 0 |
||
154 | **/ |
||
155 | fun deleteOb(inst, uparam)= |
||
156 | 0;; |
||
157 | |||
158 | |||
159 | // plugIT doing something |
||
160 | fun doSomething(value)= |
||
161 | // test the value to define a default one |
||
162 | let if value == nil then "none" else value -> value in |
||
163 | ( |
||
164 | // create a dialog box with the value as text |
||
165 | _DLGMessageBox _channel DMSwin "Template Plugit !!" value 0; |
||
166 | |||
167 | // send the Done event |
||
168 | _DMSevent this (getPluginInstanceEvent inst "Done") nil nil; |
||
169 | ); |
||
170 | 0;; |
||
171 | |||
172 | |||
173 | /*! \brief Callback on "Go" dms action |
||
174 | * |
||
175 | * Call the program function to display a dialog box |
||
176 | * |
||
177 | * <b>Prototype:</b> fun [PInstance DMI S S I u0] I |
||
178 | * |
||
179 | * \param PInstance : plugIT instance |
||
180 | * \param DMI : DMS module who call the action (not used) |
||
181 | * \param S : name of the launched action |
||
182 | * \param S : data posted in DMS action link |
||
183 | * \param I : reply flag (not used) |
||
184 | * \param u0 : user parameter, the type is not defined here because it is not used in this template |
||
185 | * |
||
186 | * \return I : 0 |
||
187 | **/ |
||
188 | fun cbGo(inst, from, action, param, rep, uparam)= |
||
189 | // call the dialog box and set the link parameter as text |
||
190 | doSomething param; |
||
191 | 0;; |
||
192 | |||
193 | |||
194 | /*! \brief Callback on new plugIT instance |
||
195 | * |
||
196 | * Read the parameters from editor values and initialise the plugIT |
||
197 | * |
||
198 | * <b>Prototype:</b> fun [PInstance] I |
||
199 | * |
||
200 | * \param PInstance : plugIT instance |
||
201 | * |
||
202 | * \return I : 0 |
||
203 | **/ |
||
204 | fun newOb(inst)= |
||
205 | // retrieve the oninit param value |
||
206 | let atoi (getPluginInstanceParam inst "oninit") -> state in |
||
207 | ( |
||
208 | // define the function to call when we receive the Go action |
||
209 | PluginRegisterAction inst "Go" mkfun6 @cbGo nil; |
||
210 | |||
211 | // test the oninit param to know if we have to start the plugIT functionalities here |
||
212 | if !state then nil else |
||
213 | doSomething nil; |
||
214 | |||
215 | // define the function to call when the plugIT instance is destroyed |
||
216 | setPluginInstanceCbDel inst mkfun2 @deleteOb nil; |
||
217 | ); |
||
218 | 0;; |
||
219 | |||
220 | |||
221 | /*! \brief Global plugIT function to initialize the plugIT callbacks |
||
222 | * |
||
223 | * called on plugIT load, here define the functions to use for a new instance and the editor |
||
224 | * |
||
225 | * <b>Prototype:</b> fun [s] I |
||
226 | * |
||
227 | * \param S : plugIT file path |
||
228 | * |
||
229 | * \return I : 0 |
||
230 | **/ |
||
231 | fun IniPlug(file)= |
||
232 | PlugRegister @newOb nil; |
||
233 | setPluginEditor @dynamicedit; |
||
234 | 0;; |
||
235 | </pre> |
||
236 | |||
237 | Now reload the plugITs in the OS3D Editor (hit F5 after a focus in the plugITs window, or right click > "reload") |
||
238 | |||
239 | If the plugIT don't appear in the plugITs menu : |
||
240 | - look at the error in the OS3D Editor log window (at the bottom of the main interface) |