-> more FLT tweaks
[blender-staging.git] / release / scripts / flt_dofedit.py
1 #!BPY
2
3 """
4 Name: 'FLT DOF Editor'
5 Blender: 240
6 Group: 'Misc'
7 Tooltip: 'Degree of Freedom editor for FLT nodes'
8 """
9
10 __author__ = "Geoffrey Bantle"
11 __version__ = "1.0 11/21/07"
12 __email__ = ('scripts', 'Author, ')
13 __url__ = ('blender', 'blenderartists.org')
14
15 __bpydoc__ ="""\
16 This script provides tools for working with OpenFlight databases in Blender. OpenFlight is a
17 registered trademark of MultiGen-Paradigm, Inc.
18
19 Feature overview and more availible at:
20 http://wiki.blender.org/index.php/Scripts/Manual/FLTools
21 """
22
23 # --------------------------------------------------------------------------
24 # flt_palettemanager.py version 0.1 2005/04/08
25 # --------------------------------------------------------------------------
26 # ***** BEGIN GPL LICENSE BLOCK *****
27 #
28 # Copyright (C) 2007: Blender Foundation
29 #
30 # This program is free software; you can redistribute it and/or
31 # modify it under the terms of the GNU General Public License
32 # as published by the Free Software Foundation; either version 2
33 # of the License, or (at your option) any later version.
34 #
35 # This program is distributed in the hope that it will be useful,
36 # but WITHOUT ANY WARRANTY; without even the implied warranty of
37 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38 # GNU General Public License for more details.
39 #
40 # You should have received a copy of the GNU General Public License
41 # along with this program; if not, write to the Free Software Foundation,
42 # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
43 #
44 # ***** END GPL LICENCE BLOCK *****
45 # --------------------------------------------------------------------------
46
47 import Blender.Draw as Draw
48 from Blender.BGL import *
49 import Blender
50 import flt_properties
51 reload(flt_properties)
52 from flt_properties import *
53
54 #event codes
55 evcode = {
56         "DOF_MAKE" : 100,
57         "DOF_UPDATE" : 138,
58         "DOF_DELETE" : 101,
59         "DOF_TRANSX" : 102,
60         "DOF_TRANSY" : 103,
61         "DOF_TRANSZ" : 104,
62         "DOF_ROTX" : 105,
63         "DOF_ROTY" : 106,
64         "DOF_ROTZ" : 107,
65         "DOF_SCALEX" : 108,
66         "DOF_SCALEY" : 109,
67         "DOF_SCALEZ" : 110,
68         "DOF_MIN_TRANSX" : 111,
69         "DOF_MIN_TRANSY" : 112,
70         "DOF_MIN_TRANSZ" : 113,
71         "DOF_MIN_ROTX" : 114,
72         "DOF_MIN_ROTY" : 115,
73         "DOF_MIN_ROTZ" : 116,
74         "DOF_MIN_SCALEX" : 117,
75         "DOF_MIN_SCALEY" : 118,
76         "DOF_MIN_SCALEZ" : 119,
77         "DOF_MAX_TRANSX" : 120,
78         "DOF_MAX_TRANSY" : 121,
79         "DOF_MAX_TRANSZ" : 122,
80         "DOF_MAX_ROTX" : 123,
81         "DOF_MAX_ROTY" : 124,
82         "DOF_MAX_ROTZ" : 125,
83         "DOF_MAX_SCALEX" : 126,
84         "DOF_MAX_SCALEY" : 127,
85         "DOF_MAX_SCALEZ" : 128,
86         "DOF_STEP_TRANSX" : 129,
87         "DOF_STEP_TRANSY" : 130,
88         "DOF_STEP_TRANSZ" : 131,
89         "DOF_STEP_ROTX" : 132,
90         "DOF_STEP_ROTY" : 133,
91         "DOF_STEP_ROTZ" : 134,
92         "DOF_STEP_SCALEX" : 135,
93         "DOF_STEP_SCALEY" : 136,
94         "DOF_STEP_SCALEZ" : 137
95 }
96
97 #system
98 DOF_MAKE = None
99 DOF_UPDATE = None
100 DOF_DELETE = None
101
102 #toggle buttons
103 DOF_TRANSX = None
104 DOF_TRANSY = None
105 DOF_TRANSZ = None
106 DOF_ROTX = None
107 DOF_ROTY = None
108 DOF_ROTZ = None
109 DOF_SCALEX = None
110 DOF_SCALEY = None
111 DOF_SCALEZ = None
112
113 #Minimums
114 DOF_MIN_TRANSX = None
115 DOF_MIN_TRANSY = None
116 DOF_MIN_TRANSZ = None
117 DOF_MIN_ROTX = None
118 DOF_MIN_ROTY = None
119 DOF_MIN_ROTZ = None
120 DOF_MIN_SCALEX = None
121 DOF_MIN_SCALEY = None
122 DOF_MIN_SCALEZ = None
123
124 #maximums
125 DOF_MAX_TRANSX = None
126 DOF_MAX_TRANSY = None
127 DOF_MAX_TRANSZ = None
128 DOF_MAX_ROTX = None
129 DOF_MAX_ROTY = None
130 DOF_MAX_ROTZ = None
131 DOF_MAX_SCALEX = None
132 DOF_MAX_SCALEY = None
133 DOF_MAX_SCALEZ = None
134
135 #step
136 DOF_STEP_TRANSX = None
137 DOF_STEP_TRANSY = None
138 DOF_STEP_TRANSZ = None
139 DOF_STEP_ROTX = None
140 DOF_STEP_ROTY = None
141 DOF_STEP_ROTZ = None
142 DOF_STEP_SCALEX = None
143 DOF_STEP_SCALEY = None
144 DOF_STEP_SCALEZ = None
145
146 #labels
147 DOF_ROTSTRING = None
148 DOF_TRANSTRING = None
149 DOF_SCALESTRING = None
150 DOF_EDITLABEL = None
151
152 #make ID props easier/morereadable
153 zmin = '14d!ZMIN'
154 zmax = '15d!ZMAX'
155 zcur = '16d!ZCUR'
156 zstep = '17d!ZSTEP'
157 ymin = '18d!YMIN'
158 ymax = '19d!YMAX'
159 ycur = '20d!YCUR'
160 ystep = '21d!YSTEP'
161 xmin = '22d!XMIN'
162 xmax = '23d!XMAX'
163 xcur = '24d!XCUR'
164 xstep = '25d!XSTEP'
165 pitchmin = '26d!PITCH-MIN'
166 pitchmax = '27d!PITCH-MAX'
167 pitchcur = '28d!PITCH-CUR'
168 pitchstep = '29d!PITCH-STEP'
169 rollmin = '30d!ROLL-MIN'
170 rollmax = '31d!ROLL-MAX'
171 rollcur = '32d!ROLL-CUR'
172 rollstep = '33d!ROLL-STEP'
173 yawmin = '34d!YAW-MIN'
174 yawmax = '35d!YAW-MAX'
175 yawcur = '36d!YAW-CUR'
176 yawstep = '37d!YAW-STEP'
177 zscalemin = '38d!ZSIZE-MIN'
178 zscalemax = '39d!ZSIZE-MAX'
179 zscalecur = '40d!ZSIZE-CUR'
180 zscalestep = '41d!ZSIZE-STEP'
181 yscalemin = '42d!YSIZE-MIN'
182 yscalemax = '43d!YSIZE-MAX'
183 yscalecur = '44d!YSIZE-CUR'
184 yscalestep = '45d!YSIZE-STEP'
185 xscalemin = '46d!XSIZE-MIN'
186 xscalemax = '47d!XSIZE-MAX'
187 xscalecur = '48d!XSIZE-CUR'
188 xscalestep = '49d!XSIZE-STEP'
189
190
191
192 def update_state():
193         state = dict()
194         state["activeScene"] = Blender.Scene.GetCurrent()
195         state["activeObject"] = state["activeScene"].objects.active
196         if state["activeObject"] and not state["activeObject"].sel:
197                 state["activeObject"] = None
198         state["activeMesh"] = None
199         if state["activeObject"] and state["activeObject"].type == 'Mesh':
200                 state["activeMesh"] = state["activeObject"].getData(mesh=True)
201         
202
203         state["activeFace"] = None
204         if state["activeMesh"]:
205                 if state["activeMesh"].faceUV and state["activeMesh"].activeFace != None:
206                         state["activeFace"] = state["activeMesh"].faces[state["activeMesh"].activeFace]
207                 
208                 
209         #update editmode
210         state["editmode"]       = Blender.Window.EditMode()
211
212         return state
213         
214 def idprops_append(object, typecode, props):
215         object.properties["FLT"] = dict()
216         object.properties["FLT"]['type'] = typecode 
217         for prop in props:
218                 object.properties["FLT"][prop] = props[prop]
219         object.properties["FLT"]['3t8!id'] = object.name
220
221 def idprops_kill():
222         state = update_state()
223         if state["activeObject"] and state["activeObject"].properties.has_key('FLT'):
224                 state["activeObject"].properties.pop('FLT')
225
226 def idprops_copy(source):
227         state = update_state()
228         if source.properties.has_key('FLT'):
229                 for object in state["activeScene"].objects:
230                         if object.sel and object != source and (state["activeScene"].Layers & object.Layers):
231                                 idprops_kill(object)
232                                 object.properties['FLT'] = dict()
233                                 for key in source.properties['FLT']:
234                                         object.properties['FLT'][key] = source.properties['FLT'][key]
235
236 def select_by_typecode(typecode):
237         state = update_state()
238         
239         for object in state["activeScene"].objects:
240                 if object.properties.has_key('FLT') and object.properties['FLT']['type'] == typecode and state["activeScene"].Layers & object.Layers:
241                                 object.select(1)
242
243 def DOF_get_frame():
244         state = update_state()
245         
246         if not state["activeObject"] and not id_props_type(state["activeObject"], 14):
247                 return
248         
249         #Warning! assumes 1 BU == 10 meters.
250         #do origin
251         state["activeObject"].properties['FLT']['5d!ORIGX'] = state["activeObject"].getLocation('worldspace')[0]*10.0
252         state["activeObject"].properties['FLT']['6d!ORIGY'] = state["activeObject"].getLocation('worldspace')[1]*10.0
253         state["activeObject"].properties['FLT']['7d!ORIGZ'] = state["activeObject"].getLocation('worldspace')[2]*10.0
254         #do X axis
255         x = Blender.Mathutils.Vector(1.0,0.0,0.0)
256         x = x * state["activeObject"].getMatrix('worldspace')
257         x = x * 10.0
258         state["activeObject"].properties['FLT']['8d!XAXIS-X'] = x[0]
259         state["activeObject"].properties['FLT']['9d!XAXIS-Y'] = x[1]
260         state["activeObject"].properties['FLT']['10d!XAXIS-Z'] = x[2]
261         #do X/Y plane
262         x = Blender.Mathutils.Vector(0.0,1.0,0.0)
263         x.normalize()
264         x = x * state["activeObject"].getMatrix('worldspace')
265         x = x * 10.0
266         state["activeObject"].properties['FLT']['11d!XYPLANE-X'] = x[0]
267         state["activeObject"].properties['FLT']['12d!XYPLANE-Y'] = x[1]
268         state["activeObject"].properties['FLT']['13d!XZPLANE-Z'] = x[2]
269
270 def idprops_type(object, typecode):
271         if object.properties.has_key('FLT') and object.properties['FLT'].has_key('type') and object.properties['FLT']['type'] == typecode:
272                 return True
273         return False
274
275 #ui type code
276 def get_prop(typecode, prop):
277         
278         state = update_state()
279         if state["activeObject"] and idprops_type(state["activeObject"], typecode):
280                 props = state["activeObject"].properties['FLT']
281         else:
282                 props =  flt_properties.FLTDOF
283                 
284         return props[prop]      
285
286 def set_prop(typecode, prop, value):
287         state = update_state()
288         if state["activeObject"] and idprops_type(state["activeObject"],typecode):
289                 state["activeObject"].properties['FLT'][prop] = value           
290
291 lockxtrans = (1 << 31)
292 lockytrans = (1 << 30)
293 lockztrans = (1 << 29)
294 lockxrot = (1 << 28)
295 lockyrot = (1 << 27)
296 lockzrot = (1 << 26)
297 lockxscale = (1 << 25)
298 lockyscale = (1 << 24)
299 lockzscale = (1 << 23)
300
301 def get_lockmask(mask): 
302         state = update_state()
303         if state["activeObject"]:
304                 flag = get_prop(14,'50I!FLAG')
305                 if flag & mask:
306                         return True
307         return False    
308
309 def set_lockmask(mask):
310         state = update_state()
311         if state["activeObject"] and idprops_type(state["activeObject"], 14):
312                 oldvalue = state["activeObject"].properties['FLT']['50I!FLAG']
313                 oldvalue = struct.unpack('>I', struct.pack('>i', oldvalue))[0]
314                 oldvalue |= mask
315                 state["activeObject"].properties['FLT']['50I!FLAG'] = struct.unpack('>i', struct.pack(">I", oldvalue))[0]
316
317 def clear_lockmask(mask):
318         state = update_state()
319         if state["activeObject"] and idprops_type(state["activeObject"], 14):
320                 oldvalue = state["activeObject"].properties['FLT']['50I!FLAG']
321                 oldvalue = struct.unpack('>I', struct.pack('>i', oldvalue))[0]
322                 oldvalue &= ~mask
323                 state["activeObject"].properties['FLT']['50I!FLAG'] = struct.unpack('>i',struct.pack('>I',oldvalue))[0] 
324
325         
326 def create_dof():
327         state = update_state()
328         actobj = state["activeObject"]
329         if actobj and not idprops_type(actobj, 14):
330                 idprops_kill()
331                 idprops_append(actobj,14, flt_properties.FLTDOF)
332                 DOF_get_frame()
333         
334                 
335 def event(evt,val):
336         if evt == Draw.ESCKEY:
337                 Draw.Exit()
338                 
339 def but_event(evt):
340         global DOF_MAKE
341         global DOF_UPDATE
342         global DOF_DELETE
343
344         global DOF_TRANSX
345         global DOF_TRANSY
346         global DOF_TRANSZ
347         global DOF_ROTX
348         global DOF_ROTY
349         global DOF_ROTZ
350         global DOF_SCALEX
351         global DOF_SCALEY
352         global DOF_SCALEZ
353
354         global DOF_MIN_TRANSX
355         global DOF_MIN_TRANSY
356         global DOF_MIN_TRANSZ
357         global DOF_MIN_ROTX
358         global DOF_MIN_ROTY
359         global DOF_MIN_ROTZ
360         global DOF_MIN_SCALEX
361         global DOF_MIN_SCALEY
362         global DOF_MIN_SCALEZ
363
364         global DOF_MAX_TRANSX
365         global DOF_MAX_TRANSY
366         global DOF_MAX_TRANSZ
367         global DOF_MAX_ROTX
368         global DOF_MAX_ROTY
369         global DOF_MAX_ROTZ
370         global DOF_MAX_SCALEX
371         global DOF_MAX_SCALEY
372         global DOF_MAX_SCALEZ
373
374         global DOF_STEP_TRANSX
375         global DOF_STEP_TRANSY
376         global DOF_STEP_TRANSZ
377         global DOF_STEP_ROTX
378         global DOF_STEP_ROTY
379         global DOF_STEP_ROTZ
380         global DOF_STEP_SCALEX
381         global DOF_STEP_SCALEY
382         global DOF_STEP_SCALEZ
383         
384         #labels
385         global DOF_ROTSTRING
386         global DOF_TRANSTRING
387         global DOF_SCALESTRING
388         
389         
390         #masks
391         global lockxtrans
392         global lockytrans
393         global lockztrans
394         global lockxrot
395         global lockyrot
396         global lockzrot
397         global lockxscale
398         global lockyscale
399         global lockzscale
400
401         global zmin
402         global zmax
403         global zcur
404         global zstep
405         global ymin
406         global ymax
407         global ycur
408         global ystep
409         global xmin
410         global xmax
411         global xcur
412         global xstep
413         global pitchmin
414         global pitchmax
415         global pitchcur
416         global pitchstep
417         global rollmin
418         global rollmax
419         global rollcur
420         global rollstep
421         global yawmin
422         global yawmax
423         global yawcur
424         global yawstep
425         global zscalemin
426         global zscalemax
427         global zscalecur
428         global zscalestep
429         global yscalemin
430         global yscalemax
431         global yscalecur
432         global yscalestep
433         global xscalemin
434         global xscalemax
435         global xscalecur
436         global xscalestep       
437
438         
439         
440         #do "system" events
441         if evt == evcode["DOF_MAKE"]:
442                 create_dof()
443
444         if evt == evcode["DOF_UPDATE"]:
445                 DOF_get_frame()
446         
447         if evt == evcode["DOF_DELETE"]:
448                 idprops_kill()
449         #do translation lock events
450         if evt == evcode["DOF_TRANSX"]:
451                 if DOF_TRANSX.val == True:
452                         set_lockmask(lockxtrans)
453                 else:
454                         clear_lockmask(lockxtrans)
455
456         if evt == evcode["DOF_TRANSY"]:
457                 if DOF_TRANSY.val == True:
458                         set_lockmask(lockytrans)
459                 else:
460                         clear_lockmask(lockytrans)
461
462         if evt == evcode["DOF_TRANSZ"]:
463                 if DOF_TRANSZ.val == True:
464                         set_lockmask(lockztrans)
465                 else:
466                         clear_lockmask(lockztrans)
467
468
469         #do rotation lock events
470         if evt == evcode["DOF_ROTX"]:
471                 if DOF_ROTX.val == True:
472                         set_lockmask(lockxrot)
473                 else:
474                         clear_lockmask(lockxrot)
475
476         if evt == evcode["DOF_ROTY"]:
477                 if DOF_ROTY.val == True:
478                         set_lockmask(lockyrot)
479                 else:
480                         clear_lockmask(lockyrot)
481
482         if evt == evcode["DOF_ROTZ"]:
483                 if DOF_ROTZ.val == True:
484                         set_lockmask(lockzrot)
485                 else:
486                         clear_lockmask(lockzrot)
487
488         #do scale lock events
489         if evt == evcode["DOF_SCALEX"]:
490                 if DOF_SCALEX.val == True:
491                         set_lockmask(lockxscale)
492                 else:
493                         clear_lockmask(lockxscale)
494
495         if evt == evcode["DOF_SCALEY"]:
496                 if DOF_SCALEY.val == True:
497                         set_lockmask(lockyscale)
498                 else:
499                         clear_lockmask(lockyscale)
500
501         if evt == evcode["DOF_SCALEZ"]:
502                 if DOF_SCALEZ.val == True:
503                         set_lockmask(lockzscale)
504                 else:
505                         clear_lockmask(lockzscale)
506                         
507         
508         #do translation buttons
509         if evt == evcode["DOF_MIN_TRANSX"]:
510                 set_prop(14, xmin, DOF_MIN_TRANSX.val)
511         if evt == evcode["DOF_MAX_TRANSX"]:
512                 set_prop(14,xmax, DOF_MAX_TRANSX.val)
513         if evt == evcode["DOF_STEP_TRANSX"]:
514                 set_prop(14,xstep, DOF_STEP_TRANSX.val)
515                 
516         if evt == evcode["DOF_MIN_TRANSY"]:
517                 set_prop(14, ymin, DOF_MIN_TRANSY.val)
518         if evt == evcode["DOF_MAX_TRANSY"]:
519                 set_prop(14,ymax, DOF_MAX_TRANSY.val)
520         if evt == evcode["DOF_STEP_TRANSY"]:
521                 set_prop(14,ystep, DOF_STEP_TRANSY.val)
522                 
523         if evt == evcode["DOF_MIN_TRANSZ"]:
524                 set_prop(14, zmin, DOF_MIN_TRANSZ.val)
525         if evt == evcode["DOF_MAX_TRANSZ"]:
526                 set_prop(14, zmax, DOF_MAX_TRANSZ.val)
527         if evt == evcode["DOF_STEP_TRANSZ"]:
528                 set_prop(14, zstep, DOF_STEP_TRANSZ.val)
529
530         #do rotation buttons
531         if evt == evcode["DOF_MIN_ROTX"]:
532                 set_prop(14, pitchmin, DOF_MIN_ROTX.val)
533         if evt == evcode["DOF_MAX_ROTX"]:
534                 set_prop(14, pitchmax, DOF_MAX_ROTX.val)
535         if evt == evcode["DOF_STEP_ROTX"]:
536                 set_prop(14, pitchstep, DOF_STEP_ROTX.val)
537
538         if evt == evcode["DOF_MIN_ROTY"]:
539                 set_prop(14, rollmin, DOF_MIN_ROTY.val)
540         if evt == evcode["DOF_MAX_ROTY"]:
541                 set_prop(14, rollmax, DOF_MAX_ROTY.val)
542         if evt == evcode["DOF_STEP_ROTY"]:
543                 set_prop(14, rollstep, DOF_STEP_ROTY.val)       
544
545         if evt == evcode["DOF_MIN_ROTZ"]:
546                 set_prop(14, yawmin, DOF_MIN_ROTZ.val)
547         if evt == evcode["DOF_MAX_ROTZ"]:
548                 set_prop(14, yawmax, DOF_MAX_ROTZ.val)
549         if evt == evcode["DOF_STEP_ROTZ"]:
550                 set_prop(14, yawstep, DOF_STEP_ROTZ.val)        
551                 
552         #do scale buttons
553         if evt == evcode["DOF_MIN_SCALEX"]:
554                 set_prop(14, xscalemin, DOF_MIN_SCALEX.val)
555         if evt == evcode["DOF_MAX_SCALEX"]:
556                 set_prop(14, xscalemax, DOF_MAX_SCALEX.val)
557         if evt == evcode["DOF_STEP_SCALEX"]:
558                 set_prop(14, xscalestep, DOF_STEP_SCALEX.val)
559         
560         if evt == evcode["DOF_MIN_SCALEY"]:
561                 set_prop(14, yscalemin, DOF_MIN_SCALEY.val)
562         if evt == evcode["DOF_MAX_SCALEY"]:
563                 set_prop(14, yscalemax, DOF_MAX_SCALEY.val)
564         if evt == evcode["DOF_STEP_SCALEY"]:
565                 set_prop(14, yscalestep, DOF_STEP_SCALEY.val)   
566
567         if evt == evcode["DOF_MIN_SCALEZ"]:
568                 set_prop(14, zscalemin, DOF_MIN_SCALEZ.val)
569         if evt == evcode["DOF_MAX_SCALEZ"]:
570                 set_prop(14, zscalemax, DOF_MAX_SCALEZ.val)
571         if evt == evcode["DOF_STEP_SCALEZ"]:
572                 set_prop(14, zscalestep, DOF_STEP_SCALEZ.val)
573
574
575         Draw.Redraw(1)
576         Blender.Window.RedrawAll()
577
578 def draw_propsheet(x,y):
579         #UI buttons
580         global DOF_MAKE
581         global DOF_UPDATE
582         global DOF_DELETE
583
584         global DOF_TRANSX
585         global DOF_TRANSY
586         global DOF_TRANSZ
587         global DOF_ROTX
588         global DOF_ROTY
589         global DOF_ROTZ
590         global DOF_SCALEX
591         global DOF_SCALEY
592         global DOF_SCALEZ
593
594         global DOF_MIN_TRANSX
595         global DOF_MIN_TRANSY
596         global DOF_MIN_TRANSZ
597         global DOF_MIN_ROTX
598         global DOF_MIN_ROTY
599         global DOF_MIN_ROTZ
600         global DOF_MIN_SCALEX
601         global DOF_MIN_SCALEY
602         global DOF_MIN_SCALEZ
603
604         global DOF_MAX_TRANSX
605         global DOF_MAX_TRANSY
606         global DOF_MAX_TRANSZ
607         global DOF_MAX_ROTX
608         global DOF_MAX_ROTY
609         global DOF_MAX_ROTZ
610         global DOF_MAX_SCALEX
611         global DOF_MAX_SCALEY
612         global DOF_MAX_SCALEZ
613
614         global DOF_STEP_TRANSX
615         global DOF_STEP_TRANSY
616         global DOF_STEP_TRANSZ
617         global DOF_STEP_ROTX
618         global DOF_STEP_ROTY
619         global DOF_STEP_ROTZ
620         global DOF_STEP_SCALEX
621         global DOF_STEP_SCALEY
622         global DOF_STEP_SCALEZ
623
624         #labels
625         global DOF_ROTSTRING
626         global DOF_TRANSTRING
627         global DOF_SCALESTRING  
628         global DOF_EDITLABEL
629         
630         #masks
631         global lockxtrans
632         global lockytrans
633         global lockztrans
634         global lockxrot
635         global lockyrot
636         global lockzrot
637         global lockxscale
638         global lockyscale
639         global lockzscale
640         
641         global zmin
642         global zmax
643         global zcur
644         global zstep
645         global ymin
646         global ymax
647         global ycur
648         global ystep
649         global xmin
650         global xmax
651         global xcur
652         global xstep
653         global pitchmin
654         global pitchmax
655         global pitchcur
656         global pitchstep
657         global rollmin
658         global rollmax
659         global rollcur
660         global rollstep
661         global yawmin
662         global yawmax
663         global yawcur
664         global yawstep
665         global zscalemin
666         global zscalemax
667         global zscalecur
668         global zscalestep
669         global yscalemin
670         global yscalemax
671         global yscalecur
672         global yscalestep
673         global xscalemin
674         global xscalemax
675         global xscalecur
676         global xscalestep       
677
678         
679         global evcode
680         
681         state = update_state()
682         
683         row_height = 20
684         toggle_width = 50
685         input_width = 100
686         pad = 10
687         origx = x
688         origy = (row_height * 15) + (pad * 15)
689
690
691         #editor label
692         x = origx
693         y = origy
694         #y = y - (row_height + pad)
695         DOF_EDITLABEL = Blender.Draw.Label("FLT Degree of Freedom Editor", x, y, 200, row_height)
696
697
698         #draw Translation limits
699         x = origx
700         y = y- (row_height + pad)
701         DOF_TRANSTRING = Blender.Draw.Label("Translation Limits", x, y, input_width, row_height)
702
703
704         #X limits
705         x = origx
706         y = y- (row_height + pad)
707         DOF_TRANSX = Blender.Draw.Toggle("LimX", evcode["DOF_TRANSX"], x, y, toggle_width, row_height, get_lockmask(lockxtrans), "")
708         x = x + (toggle_width + pad)
709         DOF_MIN_TRANSX = Blender.Draw.Number("MinX", evcode["DOF_MIN_TRANSX"], x, y, input_width, row_height,get_prop(14,xmin),  -1000000.0, 1000000.0, "")
710         x = x + (input_width + pad)
711         DOF_MAX_TRANSX = Blender.Draw.Number("MaxX", evcode["DOF_MAX_TRANSX"], x, y, input_width, row_height,get_prop(14,xmax), -1000000.0, 1000000.0, "")
712         x = x + (input_width + pad)
713         DOF_STEP_TRANSX = Blender.Draw.Number("StepX", evcode["DOF_STEP_TRANSX"], x, y, input_width, row_height,get_prop(14,xstep), -1000000.0, 1000000.0, "")
714         
715         #Y limits
716         x = origx
717         y = y- (row_height + pad)
718         DOF_TRANSY = Blender.Draw.Toggle("LimY", evcode["DOF_TRANSY"], x, y, toggle_width, row_height, get_lockmask(lockytrans), "")
719         x = x + (toggle_width + pad)
720         DOF_MIN_TRANSY = Blender.Draw.Number("MinY", evcode["DOF_MIN_TRANSY"], x, y, input_width, row_height, get_prop(14,ymin),  -1000000.0, 1000000.0, "")
721         x = x + (input_width + pad)
722         DOF_MAX_TRANSY = Blender.Draw.Number("MaxY", evcode["DOF_MAX_TRANSY"], x, y, input_width, row_height, get_prop(14,ymax), -1000000.0, 1000000.0, "")
723         x = x + (input_width + pad)
724         DOF_STEP_TRANSY = Blender.Draw.Number("StepY", evcode["DOF_STEP_TRANSY"], x, y, input_width, row_height, get_prop(14,ystep), -1000000.0, 1000000.0, "") 
725         
726         #Z limits
727         x = origx
728         y = y- (row_height + pad)
729         DOF_TRANSZ = Blender.Draw.Toggle("LimZ", evcode["DOF_TRANSZ"], x, y, toggle_width, row_height, get_lockmask(lockztrans), "")
730         x = x + (toggle_width + pad)
731         DOF_MIN_TRANSZ = Blender.Draw.Number("MinZ", evcode["DOF_MIN_TRANSZ"], x, y, input_width, row_height, get_prop(14,zmin),  -1000000.0, 1000000.0, "")
732         x = x + (input_width + pad)
733         DOF_MAX_TRANSZ = Blender.Draw.Number("MaxZ", evcode["DOF_MAX_TRANSZ"], x, y, input_width, row_height, get_prop(14,zmax), -1000000.0, 1000000.0, "")
734         x = x + (input_width + pad)
735         DOF_STEP_TRANSZ = Blender.Draw.Number("StepZ", evcode["DOF_STEP_TRANSZ"], x, y, input_width, row_height, get_prop(14,zstep), -1000000.0, 1000000.0, "")
736         
737         #draw Rotation limits
738         x = origx
739         y = y- (row_height + pad)
740         DOF_ROTSTRING = Blender.Draw.Label("Rotation Limits", x, y, input_width, row_height)
741
742         #draw Rotation limits
743         #X limits
744         x = origx
745         y = y- (row_height + pad)
746         DOF_ROTX = Blender.Draw.Toggle("LimX", evcode["DOF_ROTX"], x, y, toggle_width, row_height, get_lockmask(lockxrot), "")
747         x = x + (toggle_width + pad)
748         DOF_MIN_ROTX = Blender.Draw.Number("MinX", evcode["DOF_MIN_ROTX"], x, y, input_width, row_height, get_prop(14,pitchmin),  -1000000.0, 1000000.0, "")
749         x = x + (input_width + pad)
750         DOF_MAX_ROTX = Blender.Draw.Number("MaxX", evcode["DOF_MAX_ROTX"], x, y, input_width, row_height, get_prop(14,pitchmax), -1000000.0, 1000000.0, "")
751         x = x + (input_width + pad)
752         DOF_STEP_ROTX = Blender.Draw.Number("StepX", evcode["DOF_STEP_ROTX"], x, y, input_width, row_height, get_prop(14,pitchstep), -1000000.0, 1000000.0, "")
753                 
754         #Y limits
755         x = origx
756         y = y- (row_height + pad)
757         DOF_ROTY = Blender.Draw.Toggle("LimY", evcode["DOF_ROTY"], x, y, toggle_width, row_height, get_lockmask(lockyrot), "")
758         x = x + (toggle_width + pad)
759         DOF_MIN_ROTY = Blender.Draw.Number("MinY", evcode["DOF_MIN_ROTY"], x, y, input_width, row_height, get_prop(14,rollmin),  -1000000.0, 1000000.0, "")
760         x = x + (input_width + pad)
761         DOF_MAX_ROTY = Blender.Draw.Number("MaxY", evcode["DOF_MAX_ROTY"], x, y, input_width, row_height, get_prop(14,rollmax), -1000000.0, 1000000.0, "")
762         x = x + (input_width + pad)
763         DOF_STEP_ROTY = Blender.Draw.Number("StepY", evcode["DOF_STEP_ROTY"], x, y, input_width, row_height, get_prop(14,rollstep), -1000000.0, 1000000.0, "")
764                 
765         #Z limits
766         x = origx
767         y = y- (row_height + pad)
768         DOF_ROTZ = Blender.Draw.Toggle("LimZ", evcode["DOF_ROTZ"], x, y, toggle_width, row_height, get_lockmask(lockzrot), "")
769         x = x + (toggle_width + pad)
770         DOF_MIN_ROTZ = Blender.Draw.Number("MinZ", evcode["DOF_MIN_ROTZ"], x, y, input_width, row_height, get_prop(14, yawmin),  -1000000.0, 1000000.0, "")
771         x = x + (input_width + pad)
772         DOF_MAX_ROTZ = Blender.Draw.Number("MaxZ", evcode["DOF_MAX_ROTZ"], x, y, input_width, row_height, get_prop(14, yawmax), -1000000.0, 1000000.0, "")
773         x = x + (input_width + pad)
774         DOF_STEP_ROTZ = Blender.Draw.Number("StepZ", evcode["DOF_STEP_ROTZ"], x, y, input_width, row_height, get_prop(14, yawstep), -1000000.0, 1000000.0, "")
775                         
776
777         #draw Scale limits
778         x = origx
779         y = y- (row_height + pad)
780         DOF_SCALESTRING = Blender.Draw.Label("Scale Limits", x, y, input_width, row_height)
781
782         #draw Scale limits
783         #X limits
784         x = origx
785         y = y- (row_height + pad)
786         DOF_SCALEX = Blender.Draw.Toggle("LimX", evcode["DOF_SCALEX"], x, y, toggle_width, row_height, get_lockmask(lockxscale), "")
787         x = x + (toggle_width + pad)
788         DOF_MIN_SCALEX = Blender.Draw.Number("MinX", evcode["DOF_MIN_SCALEX"], x, y, input_width, row_height, get_prop(14, xscalemin),  -1000000.0, 1000000.0, "")
789         x = x + (input_width + pad)
790         DOF_MAX_SCALEX = Blender.Draw.Number("MaxX", evcode["DOF_MAX_SCALEX"], x, y, input_width, row_height, get_prop(14, xscalemax), -1000000.0, 1000000.0, "")
791         x = x + (input_width + pad)
792         DOF_STEP_SCALEX = Blender.Draw.Number("StepX", evcode["DOF_STEP_SCALEX"], x, y, input_width, row_height, get_prop(14, xscalestep), -1000000.0, 1000000.0, "")
793                 
794         #Y limits
795         x = origx
796         y = y- (row_height + pad)
797         DOF_SCALEY = Blender.Draw.Toggle("LimY", evcode["DOF_SCALEY"], x, y, toggle_width, row_height, get_lockmask(lockyscale), "")
798         x = x + (toggle_width + pad)
799         DOF_MIN_SCALEY = Blender.Draw.Number("MinY", evcode["DOF_MIN_SCALEY"], x, y, input_width, row_height, get_prop(14, yscalemin),  -1000000.0, 1000000.0, "")
800         x = x + (input_width + pad)
801         DOF_MAX_SCALEY = Blender.Draw.Number("MaxY", evcode["DOF_MAX_SCALEY"], x, y, input_width, row_height, get_prop(14, yscalemax), -1000000.0, 1000000.0, "")
802         x = x + (input_width + pad)
803         DOF_STEP_SCALEY = Blender.Draw.Number("StepY", evcode["DOF_STEP_SCALEY"], x, y, input_width, row_height, get_prop(14, yscalestep), -1000000.0, 1000000.0, "")           
804
805         #Z limits
806         x = origx
807         y = y- (row_height + pad)
808         DOF_SCALEZ = Blender.Draw.Toggle("LimZ", evcode["DOF_SCALEZ"], x, y, toggle_width, row_height, get_lockmask(lockzscale), "")
809         x = x + (toggle_width + pad)
810         DOF_MIN_SCALEZ = Blender.Draw.Number("MinZ", evcode["DOF_MIN_SCALEZ"], x, y, input_width, row_height, get_prop(14, zscalemin),  -1000000.0, 1000000.0, "")
811         x = x + (input_width + pad)
812         DOF_MAX_SCALEZ = Blender.Draw.Number("MaxZ", evcode["DOF_MAX_SCALEZ"], x, y, input_width, row_height, get_prop(14, zscalemax), -1000000.0, 1000000.0, "")
813         x = x + (input_width + pad)
814         DOF_STEP_SCALEZ = Blender.Draw.Number("StepZ", evcode["DOF_STEP_SCALEZ"], x, y, input_width, row_height, get_prop(14, zscalestep), -1000000.0, 1000000.0, "")           
815
816         #System
817         x = origx
818         y = y - (row_height + (pad)*3)
819         DOF_MAKE = Blender.Draw.PushButton("Make DOF", evcode["DOF_MAKE"], x, y, input_width, row_height, "Make a Dof Node out of Active Object")
820         x = x + (input_width + pad)
821         DOF_UPDATE = Blender.Draw.PushButton("Grab Loc/Rot", evcode["DOF_UPDATE"], x, y, input_width, row_height, "Update the Dof Node position/orientation")
822         x = x + (input_width + pad)
823         DOF_DELETE = Blender.Draw.PushButton("Delete DOF", evcode["DOF_DELETE"], x, y, input_width, row_height, "Delete the Dof Node properties")
824
825
826         
827         
828 def gui():
829         #draw the propsheet/toolbox.
830         psheety = 800
831         #psheetx = psheety + 10
832         draw_propsheet(20,psheety)
833
834 Draw.Register(gui,event,but_event)
835