Warning fixes for blenkernel and editors.
[blender.git] / source / blender / editors / space_view3d / view3d_buttons.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2009 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31 #include <math.h>
32 #include <float.h>
33
34 #include "DNA_ID.h"
35 #include "DNA_action_types.h"
36 #include "DNA_armature_types.h"
37 #include "DNA_curve_types.h"
38 #include "DNA_camera_types.h"
39 #include "DNA_gpencil_types.h"
40 #include "DNA_lamp_types.h"
41 #include "DNA_lattice_types.h"
42 #include "DNA_meta_types.h"
43 #include "DNA_mesh_types.h"
44 #include "DNA_meshdata_types.h"
45 #include "DNA_object_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_scene_types.h"
48 #include "DNA_screen_types.h"
49 #include "DNA_userdef_types.h"
50 #include "DNA_view3d_types.h"
51 #include "DNA_world_types.h"
52
53 #include "MEM_guardedalloc.h"
54
55 #include "BLI_arithb.h"
56 #include "BLI_blenlib.h"
57 #include "BLI_editVert.h"
58 #include "BLI_rand.h"
59
60 #include "BKE_action.h"
61 #include "BKE_brush.h"
62 #include "BKE_context.h"
63 #include "BKE_curve.h"
64 #include "BKE_customdata.h"
65 #include "BKE_depsgraph.h"
66 #include "BKE_idprop.h"
67 #include "BKE_mesh.h"
68 #include "BKE_object.h"
69 #include "BKE_global.h"
70 #include "BKE_scene.h"
71 #include "BKE_screen.h"
72 #include "BKE_utildefines.h"
73
74 #include "BIF_gl.h"
75
76 #include "WM_api.h"
77 #include "WM_types.h"
78
79 #include "RNA_access.h"
80 #include "RNA_define.h"
81
82 #include "ED_armature.h"
83 #include "ED_curve.h"
84 #include "ED_image.h"
85 #include "ED_gpencil.h"
86 #include "ED_keyframing.h"
87 #include "ED_mesh.h"
88 #include "ED_object.h"
89 #include "ED_particle.h"
90 #include "ED_screen.h"
91 #include "ED_transform.h"
92 #include "ED_types.h"
93 #include "ED_util.h"
94
95 #include "UI_interface.h"
96 #include "UI_resources.h"
97 #include "UI_view2d.h"
98
99 #include "view3d_intern.h"      // own include
100
101
102 /* ******************* view3d space & buttons ************** */
103 #define B_NOP           1
104 #define B_REDR          2
105 #define B_OBJECTPANELROT        1007
106 #define B_OBJECTPANELMEDIAN 1008
107 #define B_ARMATUREPANEL1        1009
108 #define B_ARMATUREPANEL2        1010
109 #define B_OBJECTPANELPARENT 1011
110 #define B_OBJECTPANEL           1012
111 #define B_ARMATUREPANEL3        1013
112 #define B_OBJECTPANELSCALE      1014
113 #define B_OBJECTPANELDIMS       1015
114 #define B_TRANSFORMSPACEADD     1016
115 #define B_TRANSFORMSPACECLEAR   1017
116 #define B_SETPT_AUTO    2125
117 #define B_SETPT_VECTOR  2126
118 #define B_SETPT_ALIGN   2127
119 #define B_SETPT_FREE    2128
120 #define B_RECALCMBALL   2501
121
122 #define B_WEIGHT0_0             2840
123 #define B_WEIGHT1_4             2841
124 #define B_WEIGHT1_2             2842
125 #define B_WEIGHT3_4             2843
126 #define B_WEIGHT1_0             2844
127
128 #define B_OPA1_8                2845
129 #define B_OPA1_4                2846
130 #define B_OPA1_2                2847
131 #define B_OPA3_4                2848
132 #define B_OPA1_0                2849
133
134 #define B_CLR_WPAINT    2850
135
136 #define B_RV3D_LOCKED   2900
137 #define B_RV3D_BOXVIEW  2901
138 #define B_RV3D_BOXCLIP  2902
139
140 #define B_IDNAME                3000
141
142 /* temporary struct for storing transform properties */
143 typedef struct {
144         float ob_eul[4];        // used for quat too....
145         float ob_scale[3]; // need temp space due to linked values
146         float ob_dims[3];
147         short link_scale;
148         float ve_median[5];
149         int curdef;
150         float *defweightp;
151 } TransformProperties;
152
153
154 /* is used for both read and write... */
155 static void v3d_editvertex_buts(const bContext *C, uiBlock *block, View3D *v3d, Object *ob, float lim)
156 {
157         MDeformVert *dvert=NULL;
158         TransformProperties *tfp= v3d->properties_storage;
159         float median[5], ve_median[5];
160         int tot, totw, totweight, totedge;
161         char defstr[320];
162         
163         median[0]= median[1]= median[2]= median[3]= median[4]= 0.0;
164         tot= totw= totweight= totedge= 0;
165         defstr[0]= 0;
166
167         if(ob->type==OB_MESH) {
168                 Mesh *me= ob->data;
169                 EditMesh *em = BKE_mesh_get_editmesh(me);
170                 EditVert *eve, *evedef=NULL;
171                 EditEdge *eed;
172                 
173                 eve= em->verts.first;
174                 while(eve) {
175                         if(eve->f & SELECT) {
176                                 evedef= eve;
177                                 tot++;
178                                 VecAddf(median, median, eve->co);
179                         }
180                         eve= eve->next;
181                 }
182                 eed= em->edges.first;
183                 while(eed) {
184                         if((eed->f & SELECT)) {
185                                 totedge++;
186                                 median[3]+= eed->crease;
187                         }
188                         eed= eed->next;
189                 }
190
191                 /* check for defgroups */
192                 if(evedef)
193                         dvert= CustomData_em_get(&em->vdata, evedef->data, CD_MDEFORMVERT);
194                 if(tot==1 && dvert && dvert->totweight) {
195                         bDeformGroup *dg;
196                         int i, max=1, init=1;
197                         char str[320];
198                         
199                         for (i=0; i<dvert->totweight; i++){
200                                 dg = BLI_findlink (&ob->defbase, dvert->dw[i].def_nr);
201                                 if(dg) {
202                                         max+= BLI_snprintf(str, sizeof(str), "%s %%x%d|", dg->name, dvert->dw[i].def_nr); 
203                                         if(max<320) strcat(defstr, str);
204                                 }
205                                 else printf("oh no!\n");
206                                 if(tfp->curdef==dvert->dw[i].def_nr) {
207                                         init= 0;
208                                         tfp->defweightp= &dvert->dw[i].weight;
209                                 }
210                         }
211                         
212                         if(init) {      // needs new initialized 
213                                 tfp->curdef= dvert->dw[0].def_nr;
214                                 tfp->defweightp= &dvert->dw[0].weight;
215                         }
216                 }
217
218                 BKE_mesh_end_editmesh(me, em);
219         }
220         else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
221                 Curve *cu= ob->data;
222                 Nurb *nu;
223                 BPoint *bp;
224                 BezTriple *bezt;
225                 int a;
226                 
227                 nu= cu->editnurb->first;
228                 while(nu) {
229                         if(nu->type == CU_BEZIER) {
230                                 bezt= nu->bezt;
231                                 a= nu->pntsu;
232                                 while(a--) {
233                                         if(bezt->f2 & SELECT) {
234                                                 VecAddf(median, median, bezt->vec[1]);
235                                                 tot++;
236                                                 median[4]+= bezt->weight;
237                                                 totweight++;
238                                         }
239                                         else {
240                                                 if(bezt->f1 & SELECT) {
241                                                         VecAddf(median, median, bezt->vec[0]);
242                                                         tot++;
243                                                 }
244                                                 if(bezt->f3 & SELECT) {
245                                                         VecAddf(median, median, bezt->vec[2]);
246                                                         tot++;
247                                                 }
248                                         }
249                                         bezt++;
250                                 }
251                         }
252                         else {
253                                 bp= nu->bp;
254                                 a= nu->pntsu*nu->pntsv;
255                                 while(a--) {
256                                         if(bp->f1 & SELECT) {
257                                                 VecAddf(median, median, bp->vec);
258                                                 median[3]+= bp->vec[3];
259                                                 totw++;
260                                                 tot++;
261                                                 median[4]+= bp->weight;
262                                                 totweight++;
263                                         }
264                                         bp++;
265                                 }
266                         }
267                         nu= nu->next;
268                 }
269         }
270         else if(ob->type==OB_LATTICE) {
271                 Lattice *lt= ob->data;
272                 BPoint *bp;
273                 int a;
274                 
275                 a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
276                 bp= lt->editlatt->def;
277                 while(a--) {
278                         if(bp->f1 & SELECT) {
279                                 VecAddf(median, median, bp->vec);
280                                 tot++;
281                                 median[4]+= bp->weight;
282                                 totweight++;
283                         }
284                         bp++;
285                 }
286         }
287         
288         if(tot==0) return;
289
290         median[0] /= (float)tot;
291         median[1] /= (float)tot;
292         median[2] /= (float)tot;
293         if(totedge) median[3] /= (float)totedge;
294         else if(totw) median[3] /= (float)totw;
295         if(totweight) median[4] /= (float)totweight;
296         
297         if(v3d->flag & V3D_GLOBAL_STATS)
298                 Mat4MulVecfl(ob->obmat, median);
299         
300         if(block) {     // buttons
301                 int but_y;
302                 if((ob->parent) && (ob->partype == PARBONE))    but_y = 135;
303                 else                                                                                    but_y = 150;
304                 
305                 
306                 
307                 memcpy(tfp->ve_median, median, sizeof(tfp->ve_median));
308                 
309                 uiBlockBeginAlign(block);
310                 if(tot==1) {
311                         uiDefBut(block, LABEL, 0, "Vertex:",                                    0, 130, 200, 20, 0, 0, 0, 0, 0, "");
312                         uiBlockBeginAlign(block);
313                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "X:",                0, 110, 200, 20, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
314                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Y:",                0, 90, 200, 20, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
315                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:",                0, 70, 200, 20, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
316                         
317                         if(totw==1) {
318                                 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
319                                 uiBlockBeginAlign(block);
320                                 uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
321                                 uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
322                                 uiBlockEndAlign(block);
323                                 if(totweight)
324                                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 0, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "");
325                                 }
326                         else {
327                                 uiBlockBeginAlign(block);
328                                 uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 45, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
329                                 uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 45, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
330                                 uiBlockEndAlign(block);
331                                 if(totweight)
332                                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 20, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "");
333                         }
334                 }
335                 else {
336                         uiDefBut(block, LABEL, 0, "Median:",                                    0, 130, 200, 20, 0, 0, 0, 0, 0, "");
337                         uiBlockBeginAlign(block);
338                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "X:",                0, 110, 200, 20, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
339                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Y:",                0, 90, 200, 20, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
340                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:",                0, 70, 200, 20, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
341                         if(totw==tot) {
342                                 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
343                                 uiBlockEndAlign(block);
344                                 uiBlockBeginAlign(block);
345                                 uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
346                                 uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
347                                 uiBlockEndAlign(block);
348                                 if(totweight)
349                                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 0, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
350                                 uiBlockEndAlign(block);
351                         }
352                         else {
353                                 uiBlockBeginAlign(block);
354                                 uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 45, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
355                                 uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 45, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
356                                 uiBlockEndAlign(block);
357                                 if(totweight)
358                                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 20, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
359                                 uiBlockEndAlign(block);
360                         }
361                 }
362                                 
363                 if(totedge==1)
364                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease:",   0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
365                 else if(totedge>1)
366                         uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Crease:",    0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
367                 
368         }
369         else {  // apply
370                 memcpy(ve_median, tfp->ve_median, sizeof(tfp->ve_median));
371                 
372                 if(v3d->flag & V3D_GLOBAL_STATS) {
373                         Mat4Invert(ob->imat, ob->obmat);
374                         Mat4MulVecfl(ob->imat, median);
375                         Mat4MulVecfl(ob->imat, ve_median);
376                 }
377                 VecSubf(median, ve_median, median);
378                 median[3]= ve_median[3]-median[3];
379                 median[4]= ve_median[4]-median[4];
380                 
381                 if(ob->type==OB_MESH) {
382                         Mesh *me= ob->data;
383                         EditMesh *em = BKE_mesh_get_editmesh(me);
384                         EditVert *eve;
385                         EditEdge *eed;
386                         
387                         eve= em->verts.first;
388                         while(eve) {
389                                 if(eve->f & SELECT) {
390                                         VecAddf(eve->co, eve->co, median);
391                                 }
392                                 eve= eve->next;
393                         }
394                         
395                         for(eed= em->edges.first; eed; eed= eed->next) {
396                                 if(eed->f & SELECT) {
397                                         /* ensure the median can be set to zero or one */
398                                         if(ve_median[3]==0.0f) eed->crease= 0.0f;
399                                         else if(ve_median[3]==1.0f) eed->crease= 1.0f;
400                                         else {
401                                                 eed->crease+= median[3];
402                                                 CLAMP(eed->crease, 0.0, 1.0);
403                                         }
404                                 }
405                         }
406                         
407                         recalc_editnormals(em);
408
409                         BKE_mesh_end_editmesh(me, em);
410                 }
411                 else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
412                         Curve *cu= ob->data;
413                         Nurb *nu;
414                         BPoint *bp;
415                         BezTriple *bezt;
416                         int a;
417                         
418                         nu= cu->editnurb->first;
419                         while(nu) {
420                                 if(nu->type == CU_BEZIER) {
421                                         bezt= nu->bezt;
422                                         a= nu->pntsu;
423                                         while(a--) {
424                                                 if(bezt->f2 & SELECT) {
425                                                         VecAddf(bezt->vec[0], bezt->vec[0], median);
426                                                         VecAddf(bezt->vec[1], bezt->vec[1], median);
427                                                         VecAddf(bezt->vec[2], bezt->vec[2], median);
428                                                         bezt->weight+= median[4];
429                                                 }
430                                                 else {
431                                                         if(bezt->f1 & SELECT) {
432                                                                 VecAddf(bezt->vec[0], bezt->vec[0], median);
433                                                         }
434                                                         if(bezt->f3 & SELECT) {
435                                                                 VecAddf(bezt->vec[2], bezt->vec[2], median);
436                                                         }
437                                                 }
438                                                 bezt++;
439                                         }
440                                 }
441                                 else {
442                                         bp= nu->bp;
443                                         a= nu->pntsu*nu->pntsv;
444                                         while(a--) {
445                                                 if(bp->f1 & SELECT) {
446                                                         VecAddf(bp->vec, bp->vec, median);
447                                                         bp->vec[3]+= median[3];
448                                                         bp->weight+= median[4];
449                                                 }
450                                                 bp++;
451                                         }
452                                 }
453                                 test2DNurb(nu);
454                                 testhandlesNurb(nu); /* test for bezier too */
455
456                                 nu= nu->next;
457                         }
458                 }
459                 else if(ob->type==OB_LATTICE) {
460                         Lattice *lt= ob->data;
461                         BPoint *bp;
462                         int a;
463                         
464                         a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
465                         bp= lt->editlatt->def;
466                         while(a--) {
467                                 if(bp->f1 & SELECT) {
468                                         VecAddf(bp->vec, bp->vec, median);
469                                         bp->weight+= median[4];
470                                 }
471                                 bp++;
472                         }
473                 }
474                 
475 //              ED_undo_push(C, "Transform properties");
476         }
477 }
478
479 #if 0
480 /* assumes armature active */
481 static void validate_bonebutton_cb(bContext *C, void *bonev, void *namev)
482 {
483         Object *ob= CTX_data_active_object(C);
484         
485         if(ob && ob->type==OB_ARMATURE) {
486                 Bone *bone= bonev;
487                 char oldname[32], newname[32];
488                 
489                 /* need to be on the stack */
490                 BLI_strncpy(newname, bone->name, 32);
491                 BLI_strncpy(oldname, (char *)namev, 32);
492                 /* restore */
493                 BLI_strncpy(bone->name, oldname, 32);
494                 
495                 ED_armature_bone_rename(ob->data, oldname, newname); // editarmature.c
496         }
497 }
498 #endif
499
500 static void v3d_posearmature_buts(uiBlock *block, View3D *v3d, Object *ob, float lim)
501 {
502         bArmature *arm;
503         bPoseChannel *pchan;
504         Bone *bone= NULL;
505         TransformProperties *tfp= v3d->properties_storage;
506
507         arm = ob->data;
508         if (!arm || !ob->pose) return;
509
510         for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
511                 bone = pchan->bone;
512                 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
513                         break;
514         }
515         
516         if (pchan->rotmode == PCHAN_ROT_AXISANGLE) {
517                 float quat[4];
518                 /* convert to euler, passing through quats... */
519                 AxisAngleToQuat(quat, &pchan->quat[1], pchan->quat[0]);
520                 QuatToEul(quat, tfp->ob_eul);
521         }
522         else if (pchan->rotmode == PCHAN_ROT_QUAT)
523                 QuatToEul(pchan->quat, tfp->ob_eul);
524         else
525                 VecCopyf(tfp->ob_eul, pchan->eul);
526         tfp->ob_eul[0]*= 180.0/M_PI;
527         tfp->ob_eul[1]*= 180.0/M_PI;
528         tfp->ob_eul[2]*= 180.0/M_PI;
529         
530         uiDefBut(block, LABEL, 0, "Location:",                  0, 240, 100, 20, 0, 0, 0, 0, 0, "");
531         uiBlockBeginAlign(block);
532         uiDefButF(block, NUM, B_ARMATUREPANEL2, "X:",   0, 220, 120, 19, pchan->loc, -lim, lim, 100, 3, "");
533         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Y:",   0, 200, 120, 19, pchan->loc+1, -lim, lim, 100, 3, "");
534         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Z:",   0, 180, 120, 19, pchan->loc+2, -lim, lim, 100, 3, "");
535         uiBlockEndAlign(block);
536         
537         uiBlockBeginAlign(block);
538         uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCX, B_REDR, ICON_UNLOCKED,   125, 220, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects X Location value from being Transformed");
539         uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCY, B_REDR, ICON_UNLOCKED,   125, 200, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects Y Location value from being Transformed");
540         uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCZ, B_REDR, ICON_UNLOCKED,   125, 180, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects Z Location value from being Transformed");
541         uiBlockEndAlign(block);
542         
543         uiDefBut(block, LABEL, 0, "Rotation:",                  0, 160, 100, 20, 0, 0, 0, 0, 0, "");
544         uiBlockBeginAlign(block);
545         uiDefButF(block, NUM, B_ARMATUREPANEL3, "X:",   0, 140, 120, 19, tfp->ob_eul, -1000.0, 1000.0, 100, 3, "");
546         uiDefButF(block, NUM, B_ARMATUREPANEL3, "Y:",   0, 120, 120, 19, tfp->ob_eul+1, -1000.0, 1000.0, 100, 3, "");
547         uiDefButF(block, NUM, B_ARMATUREPANEL3, "Z:",   0, 100, 120, 19, tfp->ob_eul+2, -1000.0, 1000.0, 100, 3, "");
548         uiBlockEndAlign(block);
549         
550         uiBlockBeginAlign(block);
551         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   125, 140, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects X Rotation value from being Transformed");
552         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   125, 120, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects Y Rotation value from being Transformed");
553         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   125, 100, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects Z Rotation value from being Transformed");
554         uiBlockEndAlign(block);
555         
556         uiDefBut(block, LABEL, 0, "Scale:",                             0, 80, 100, 20, 0, 0, 0, 0, 0, "");
557         uiBlockBeginAlign(block);
558         uiDefButF(block, NUM, B_ARMATUREPANEL2, "X:",   0, 60, 120, 19, pchan->size, -lim, lim, 10, 3, "");
559         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Y:",   0, 40, 120, 19, pchan->size+1, -lim, lim, 10, 3, "");
560         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Z:",   0, 20, 120, 19, pchan->size+2, -lim, lim, 10, 3, "");
561         uiBlockEndAlign(block);
562         
563         uiBlockBeginAlign(block);
564         uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEX, B_REDR, ICON_UNLOCKED, 125, 60, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects X Scale value from being Transformed");
565         uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, B_REDR, ICON_UNLOCKED, 125, 40, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects Y Scale value from being Transformed");
566         uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, B_REDR, ICON_UNLOCKED, 125, 20, 25, 19, &(pchan->protectflag), 0, 0, 0, 0, "Protects z Scale value from being Transformed");
567         uiBlockEndAlign(block);
568 }
569
570 /* assumes armature editmode */
571 void validate_editbonebutton_cb(bContext *C, void *bonev, void *namev)
572 {
573         EditBone *eBone= bonev;
574         char oldname[32], newname[32];
575         
576         /* need to be on the stack */
577         BLI_strncpy(newname, eBone->name, 32);
578         BLI_strncpy(oldname, (char *)namev, 32);
579         /* restore */
580         BLI_strncpy(eBone->name, oldname, 32);
581         
582         ED_armature_bone_rename(CTX_data_edit_object(C)->data, oldname, newname); // editarmature.c
583         WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, CTX_data_edit_object(C)); // XXX fix
584 }
585
586 static void v3d_editarmature_buts(uiBlock *block, View3D *v3d, Object *ob, float lim)
587 {
588         bArmature *arm= ob->data;
589         EditBone *ebone;
590         TransformProperties *tfp= v3d->properties_storage;
591         
592         ebone= arm->edbo->first;
593
594         for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
595                 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
596                         break;
597         }
598
599         if (!ebone)
600                 return;
601         
602         uiDefBut(block, LABEL, 0, "Head:",                                      0, 210, 100, 20, 0, 0, 0, 0, 0, "");
603         uiBlockBeginAlign(block);
604         uiDefButF(block, NUM, B_ARMATUREPANEL1, "X:",           0, 190, 100, 19, ebone->head, -lim, lim, 10, 3, "X Location of the head end of the bone");
605         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Y:",           0, 170, 100, 19, ebone->head+1, -lim, lim, 10, 3, "Y Location of the head end of the bone");
606         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Z:",           0, 150, 100, 19, ebone->head+2, -lim, lim, 10, 3, "Z Location of the head end of the bone");
607         if (ebone->parent && ebone->flag & BONE_CONNECTED )
608                 uiDefButF(block, NUM, B_ARMATUREPANEL1, "Radius:",      0, 130, 100, 19, &ebone->parent->rad_tail, 0, lim, 10, 3, "Head radius. Visualize with the Envelope display option");
609         else
610                 uiDefButF(block, NUM, B_ARMATUREPANEL1, "Radius:",      0, 130, 100, 19, &ebone->rad_head, 0, lim, 10, 3, "Head radius. Visualize with the Envelope display option");
611         uiBlockEndAlign(block);
612         
613         uiBlockEndAlign(block);
614         uiDefBut(block, LABEL, 0, "Tail:",                                      0, 110, 100, 20, 0, 0, 0, 0, 0, "");
615         uiBlockBeginAlign(block);
616         uiDefButF(block, NUM, B_ARMATUREPANEL1, "X:",           0, 90, 100, 19, ebone->tail, -lim, lim, 10, 3, "X Location of the tail end of the bone");
617         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Y:",           0, 70, 100, 19, ebone->tail+1, -lim, lim, 10, 3, "Y Location of the tail end of the bone");
618         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Z:",           0, 50, 100, 19, ebone->tail+2, -lim, lim, 10, 3, "Z Location of the tail end of the bone");
619         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Radius:",      0, 30, 100, 19, &ebone->rad_tail, 0, lim, 10, 3, "Tail radius. Visualize with the Envelope display option");
620         uiBlockEndAlign(block);
621         
622         tfp->ob_eul[0]= 180.0*ebone->roll/M_PI;
623         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Roll:",        0, 0, 100, 19, tfp->ob_eul, -lim, lim, 1000, 3, "Bone rotation around head-tail axis");
624         uiBlockBeginAlign(block);
625         
626         
627 }
628
629 static void v3d_editmetaball_buts(uiBlock *block, Object *ob, float lim)
630 {
631         MetaElem *lastelem= NULL; // XXX
632
633         if(lastelem) {
634                 uiBlockBeginAlign(block);
635                 uiDefButF(block, NUM, B_RECALCMBALL, "LocX:", 10, 70, 140, 19, &lastelem->x, -lim, lim, 100, 3, "");
636                 uiDefButF(block, NUM, B_RECALCMBALL, "LocY:", 10, 50, 140, 19, &lastelem->y, -lim, lim, 100, 3, "");
637                 uiDefButF(block, NUM, B_RECALCMBALL, "LocZ:", 10, 30, 140, 19, &lastelem->z, -lim, lim, 100, 3, "");
638
639                 uiBlockBeginAlign(block);
640                 if(lastelem->type!=MB_BALL)
641                         uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 160, 70, 140, 19, &lastelem->expx, 0, lim, 100, 3, "");
642                 if((lastelem->type!=MB_BALL) && (lastelem->type!=MB_TUBE))
643                         uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 160, 50, 140, 19, &lastelem->expy, 0, lim, 100, 3, "");
644                 if((lastelem->type==MB_ELIPSOID) || (lastelem->type==MB_CUBE))
645                         uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 160, 30, 140, 19, &lastelem->expz, 0, lim, 100, 3, "");
646
647                 uiBlockEndAlign(block); 
648
649                 uiBlockBeginAlign(block);
650                 uiDefButF(block, NUM, B_RECALCMBALL, "Radius:", 10, 120, 140, 19, &lastelem->rad, 0, lim, 100, 3, "Size of the active metaball");
651                 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 10, 100, 140, 19, &lastelem->s, 0, 10, 100, 3, "Stiffness of the active metaball");
652                 uiBlockEndAlign(block);
653                 
654                 uiDefButS(block, MENU, B_RECALCMBALL, "Type%t|Ball%x0|Tube%x4|Plane%x5|Elipsoid%x6|Cube%x7", 160, 120, 140, 19, &lastelem->type, 0.0, 0.0, 0, 0, "Set active element type");
655                 
656         }
657 }
658
659 /* test if 'ob' is a parent somewhere in par's parents */
660 static int test_parent_loop(Object *par, Object *ob)
661 {
662         if(par == NULL) return 0;
663         if(ob == par) return 1;
664         return test_parent_loop(par->parent, ob);
665 }
666
667 static void do_view3d_region_buttons(bContext *C, void *arg, int event)
668 {
669         Scene *scene= CTX_data_scene(C);
670         Object *obedit= CTX_data_edit_object(C);
671         View3D *v3d= CTX_wm_view3d(C);
672         BoundBox *bb;
673         Object *ob= OBACT;
674         TransformProperties *tfp= v3d->properties_storage;
675         
676         switch(event) {
677         
678         case B_REDR:
679                 ED_area_tag_redraw(CTX_wm_area(C));
680                 return; /* no notifier! */
681                 
682         case B_OBJECTPANEL:
683                 DAG_id_flush_update(&ob->id, OB_RECALC_OB);
684                 break;
685                 
686         case B_OBJECTPANELROT:
687                 if(ob) {
688                         ob->rot[0]= M_PI*tfp->ob_eul[0]/180.0;
689                         ob->rot[1]= M_PI*tfp->ob_eul[1]/180.0;
690                         ob->rot[2]= M_PI*tfp->ob_eul[2]/180.0;
691                         DAG_id_flush_update(&ob->id, OB_RECALC_OB);
692                 }
693                 break;
694
695         case B_OBJECTPANELSCALE:
696                 if(ob) {
697
698                         /* link scale; figure out which axis changed */
699                         if (tfp->link_scale) {
700                                 float ratio, tmp, max = 0.0;
701                                 int axis;
702                                 
703                                 axis = 0;
704                                 max = fabs(tfp->ob_scale[0] - ob->size[0]);
705                                 tmp = fabs(tfp->ob_scale[1] - ob->size[1]);
706                                 if (tmp > max) {
707                                         axis = 1;
708                                         max = tmp;
709                                 }
710                                 tmp = fabs(tfp->ob_scale[2] - ob->size[2]);
711                                 if (tmp > max) {
712                                         axis = 2;
713                                         max = tmp;
714                                 }
715                         
716                                 if (ob->size[axis] != tfp->ob_scale[axis]) {
717                                         if (fabs(ob->size[axis]) > FLT_EPSILON) {
718                                                 ratio = tfp->ob_scale[axis] / ob->size[axis];
719                                                 ob->size[0] *= ratio;
720                                                 ob->size[1] *= ratio;
721                                                 ob->size[2] *= ratio;
722                                         }
723                                 }
724                         }
725                         else {
726                                 VECCOPY(ob->size, tfp->ob_scale);
727                                 
728                         }
729                         DAG_id_flush_update(&ob->id, OB_RECALC_OB);
730                 }
731                 break;
732
733         case B_OBJECTPANELDIMS:
734                 bb= object_get_boundbox(ob);
735                 if(bb) {
736                         float old_dims[3], scale[3], ratio, len[3];
737                         int axis;
738
739                         Mat4ToSize(ob->obmat, scale);
740
741                         len[0] = bb->vec[4][0] - bb->vec[0][0];
742                         len[1] = bb->vec[2][1] - bb->vec[0][1];
743                         len[2] = bb->vec[1][2] - bb->vec[0][2];
744
745                         old_dims[0] = fabs(scale[0]) * len[0];
746                         old_dims[1] = fabs(scale[1]) * len[1];
747                         old_dims[2] = fabs(scale[2]) * len[2];
748
749                         /* for each axis changed */
750                         for (axis = 0; axis<3; axis++) {
751                                 if (fabs(old_dims[axis] - tfp->ob_dims[axis]) > 0.0001) {
752                                         if (old_dims[axis] > 0.0) {
753                                                 ratio = tfp->ob_dims[axis] / old_dims[axis]; 
754                                                 if (tfp->link_scale) {
755                                                         ob->size[0] *= ratio;
756                                                         ob->size[1] *= ratio;
757                                                         ob->size[2] *= ratio;
758                                                         break;
759                                                 }
760                                                 else {
761                                                         ob->size[axis] *= ratio;
762                                                 }
763                                         }
764                                         else {
765                                                 if (len[axis] > 0) {
766                                                         ob->size[axis] = tfp->ob_dims[axis] / len[axis];
767                                                 }
768                                         }
769                                 }
770                         }
771                         
772                         /* prevent multiple B_OBJECTPANELDIMS events to keep scaling, cycling with TAB on buttons can cause that */
773                         VECCOPY(tfp->ob_dims, old_dims);
774                         
775                         DAG_id_flush_update(&ob->id, OB_RECALC_OB);
776                 }
777                 break;
778         
779         case B_OBJECTPANELMEDIAN:
780                 if(ob) {
781                         v3d_editvertex_buts(C, NULL, v3d, ob, 1.0);
782                         DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
783                 }
784                 break;
785                 
786                 /* note; this case also used for parbone */
787         case B_OBJECTPANELPARENT:
788                 if(ob) {
789                         if(ob->id.lib || test_parent_loop(ob->parent, ob) ) 
790                                 ob->parent= NULL;
791                         else {
792                                 DAG_scene_sort(scene);
793                                 DAG_id_flush_update(&ob->id, OB_RECALC_OB);
794                         }
795                 }
796                 break;
797                 
798         case B_ARMATUREPANEL1:
799                 {
800                         bArmature *arm= obedit->data;
801                         EditBone *ebone, *child;
802                         
803                         for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
804                                 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
805                                         break;
806                         }
807                         if (ebone) {
808                                 ebone->roll= M_PI*tfp->ob_eul[0]/180.0;
809                                 //      Update our parent
810                                 if (ebone->parent && ebone->flag & BONE_CONNECTED){
811                                         VECCOPY (ebone->parent->tail, ebone->head);
812                                 }
813                         
814                                 //      Update our children if necessary
815                                 for (child = arm->edbo->first; child; child=child->next){
816                                         if (child->parent == ebone && (child->flag & BONE_CONNECTED)){
817                                                 VECCOPY (child->head, ebone->tail);
818                                         }
819                                 }
820                                 if(arm->flag & ARM_MIRROR_EDIT) {
821                                         EditBone *eboflip= ED_armature_bone_get_mirrored(arm->edbo, ebone);
822                                         if(eboflip) {
823                                                 eboflip->roll= -ebone->roll;
824                                                 eboflip->head[0]= -ebone->head[0];
825                                                 eboflip->tail[0]= -ebone->tail[0];
826                                                 
827                                                 //      Update our parent
828                                                 if (eboflip->parent && eboflip->flag & BONE_CONNECTED){
829                                                         VECCOPY (eboflip->parent->tail, eboflip->head);
830                                                 }
831                                                 
832                                                 //      Update our children if necessary
833                                                 for (child = arm->edbo->first; child; child=child->next){
834                                                         if (child->parent == eboflip && (child->flag & BONE_CONNECTED)){
835                                                                 VECCOPY (child->head, eboflip->tail);
836                                                         }
837                                                 }
838                                         }
839                                 }
840                         }
841                 }
842                 break;
843         case B_ARMATUREPANEL3:  // rotate button on channel
844                 {
845                         bArmature *arm;
846                         bPoseChannel *pchan;
847                         Bone *bone;
848                         float eul[3];
849                         
850                         arm = ob->data;
851                         if (!arm || !ob->pose) return;
852                                 
853                         for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
854                                 bone = pchan->bone;
855                                 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
856                                         break;
857                         }
858                         if (!pchan) return;
859                         
860                         /* make a copy to eul[3], to allow TAB on buttons to work */
861                         eul[0]= M_PI*tfp->ob_eul[0]/180.0;
862                         eul[1]= M_PI*tfp->ob_eul[1]/180.0;
863                         eul[2]= M_PI*tfp->ob_eul[2]/180.0;
864                         
865                         if (pchan->rotmode == PCHAN_ROT_AXISANGLE) {
866                                 float quat[4];
867                                 /* convert to axis-angle, passing through quats  */
868                                 EulToQuat(eul, quat);
869                                 QuatToAxisAngle(quat, &pchan->quat[1], &pchan->quat[0]);
870                         }
871                         else if (pchan->rotmode == PCHAN_ROT_QUAT)
872                                 EulToQuat(eul, pchan->quat);
873                         else
874                                 VecCopyf(pchan->eul, eul);
875                         
876                 }
877                 /* no break, pass on */
878         case B_ARMATUREPANEL2:
879                 {
880                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
881                         DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
882                 }
883                 break;
884         case B_TRANSFORMSPACEADD:
885                 BIF_manageTransformOrientation(C, 1, 0);
886                 break;
887         case B_TRANSFORMSPACECLEAR:
888                 BIF_clearTransformOrientation(C);
889                 break;
890                 
891 #if 0 // XXX
892         case B_WEIGHT0_0:
893                 wpaint->weight = 0.0f;
894                 break;
895                 
896         case B_WEIGHT1_4:
897                 wpaint->weight = 0.25f;
898                 break;
899         case B_WEIGHT1_2:
900                 wpaint->weight = 0.5f;
901                 break;
902         case B_WEIGHT3_4:
903                 wpaint->weight = 0.75f;
904                 break;
905         case B_WEIGHT1_0:
906                 wpaint->weight = 1.0f;
907                 break;
908                 
909         case B_OPA1_8:
910                 wpaint->a = 0.125f;
911                 break;
912         case B_OPA1_4:
913                 wpaint->a = 0.25f;
914                 break;
915         case B_OPA1_2:
916                 wpaint->a = 0.5f;
917                 break;
918         case B_OPA3_4:
919                 wpaint->a = 0.75f;
920                 break;
921         case B_OPA1_0:
922                 wpaint->a = 1.0f;
923                 break;
924 #endif
925         case B_CLR_WPAINT:
926 //              if(!multires_level1_test()) {
927                 {
928                         bDeformGroup *defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
929                         if(defGroup) {
930                                 Mesh *me= ob->data;
931                                 int a;
932                                 for(a=0; a<me->totvert; a++)
933                                         ED_vgroup_vert_remove (ob, defGroup, a);
934                                 DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
935                         }
936                 }
937                 break;
938         case B_RV3D_LOCKED:
939         case B_RV3D_BOXVIEW:
940         case B_RV3D_BOXCLIP:
941                 {
942                         ScrArea *sa= CTX_wm_area(C);
943                         ARegion *ar= sa->regionbase.last;
944                         RegionView3D *rv3d;
945                         short viewlock;
946                         
947                         ar= ar->prev;
948                         rv3d= ar->regiondata;
949                         viewlock= rv3d->viewlock;
950                         
951                         if((viewlock & RV3D_LOCKED)==0)
952                                 viewlock= 0;
953                         else if((viewlock & RV3D_BOXVIEW)==0)
954                                 viewlock &= ~RV3D_BOXCLIP;
955                         
956                         for(; ar; ar= ar->prev) {
957                                 if(ar->alignment==RGN_ALIGN_QSPLIT) {
958                                         rv3d= ar->regiondata;
959                                         rv3d->viewlock= viewlock;
960                                 }
961                         }
962                         
963                         if(rv3d->viewlock & RV3D_BOXVIEW)
964                                 view3d_boxview_copy(sa, sa->regionbase.last);
965                         
966                         ED_area_tag_redraw(sa);
967                 }
968                 break;
969         }
970
971         /* default for now */
972         WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
973 }
974
975 void removeTransformOrientation_func(bContext *C, void *target, void *unused)
976 {
977         BIF_removeTransformOrientation(C, (TransformOrientation *) target);
978 }
979
980 void selectTransformOrientation_func(bContext *C, void *target, void *unused)
981 {
982         BIF_selectTransformOrientation(C, (TransformOrientation *) target);
983 }
984
985 #if 0 // XXX not used
986 static void view3d_panel_transform_spaces(const bContext *C, Panel *pa)
987 {
988         Scene *scene= CTX_data_scene(C);
989         Object *obedit= CTX_data_edit_object(C);
990         View3D *v3d= CTX_wm_view3d(C);
991         ListBase *transform_spaces = &scene->transform_spaces;
992         TransformOrientation *ts = transform_spaces->first;
993         uiBlock *block;
994         uiBut *but;
995         int xco = 20, yco = 70;
996         int index;
997
998         block= uiLayoutFreeBlock(pa->layout);
999
1000         uiBlockBeginAlign(block);
1001         
1002         if (obedit)
1003                 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the selected element as a Transform Orientation");
1004         else
1005                 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the active object as a Transform Orientation");
1006
1007         uiDefBut(block, BUT, B_TRANSFORMSPACECLEAR, "Clear", xco + 80,120,80,20, 0, 0, 0, 0, 0, "Removal all Transform Orientations");
1008         
1009         uiBlockEndAlign(block);
1010         
1011         uiBlockBeginAlign(block);
1012         
1013         uiDefButS(block, ROW, B_REDR, "Global", xco,            90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_GLOBAL,0, 0, "Global Transform Orientation");
1014         uiDefButS(block, ROW, B_REDR, "Local",  xco + 40,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_LOCAL, 0, 0, "Local Transform Orientation");
1015         uiDefButS(block, ROW, B_REDR, "Normal", xco + 80,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_NORMAL,0, 0, "Normal Transform Orientation");
1016         uiDefButS(block, ROW, B_REDR, "View",           xco + 120,      90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_VIEW,    0, 0, "View Transform Orientation");
1017         
1018         for (index = V3D_MANIP_CUSTOM, ts = transform_spaces->first ; ts ; ts = ts->next, index++) {
1019
1020                 if (v3d->twmode == index) {
1021                         but = uiDefIconButS(block,ROW, B_REDR, ICON_CHECKBOX_HLT, xco,yco,XIC,YIC, &v3d->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
1022                 }
1023                 else {
1024                         but = uiDefIconButS(block,ROW, B_REDR, ICON_CHECKBOX_DEHLT, xco,yco,XIC,YIC, &v3d->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
1025                 }
1026                 uiButSetFunc(but, selectTransformOrientation_func, ts, NULL);
1027                 uiDefBut(block, TEX, 0, "", xco+=XIC, yco,100+XIC,20, &ts->name, 0, 30, 0, 0, "Edits the name of this Transform Orientation");
1028                 but = uiDefIconBut(block, BUT, B_REDR, ICON_X, xco+=100+XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes this Transform Orientation");
1029                 uiButSetFunc(but, removeTransformOrientation_func, ts, NULL);
1030
1031                 xco = 20;
1032                 yco -= 25;
1033         }
1034         uiBlockEndAlign(block);
1035 }
1036 #endif // XXX not used
1037
1038 #if 0
1039 static void brush_idpoin_handle(bContext *C, ID *id, int event)
1040 {
1041         Brush **br = current_brush_source(CTX_data_scene(C));
1042
1043         if(!br)
1044                 return;
1045
1046         switch(event) {
1047         case UI_ID_BROWSE:
1048                 (*br) = (Brush*)id;
1049                 break;
1050         case UI_ID_DELETE:
1051                 brush_delete(br);
1052                 break;
1053         case UI_ID_RENAME:
1054                 /* XXX ? */
1055                 break;
1056         case UI_ID_ADD_NEW:
1057                 if(id) {
1058                         (*br) = copy_brush((Brush*)id);
1059                         id->us--;
1060                 }
1061                 else
1062                         (*br) = add_brush("Brush");
1063                 break;
1064         case UI_ID_OPEN:
1065                 /* XXX not implemented */
1066                 break;
1067         }
1068 }
1069 #endif
1070
1071 static void view3d_panel_object(const bContext *C, Panel *pa)
1072 {
1073         uiBlock *block;
1074         Scene *scene= CTX_data_scene(C);
1075         Object *obedit= CTX_data_edit_object(C);
1076         View3D *v3d= CTX_wm_view3d(C);
1077         //uiBut *bt;
1078         Object *ob= OBACT;
1079         TransformProperties *tfp;
1080         float lim;
1081         
1082         if(ob==NULL) return;
1083
1084         /* make sure we got storage */
1085         if(v3d->properties_storage==NULL)
1086                 v3d->properties_storage= MEM_callocN(sizeof(TransformProperties), "TransformProperties");
1087         tfp= v3d->properties_storage;
1088         
1089         block= uiLayoutFreeBlock(pa->layout);
1090         uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
1091
1092 // XXX  uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
1093         
1094         if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) {
1095         }
1096         else {
1097                 if((ob->mode & OB_MODE_PARTICLE_EDIT)==0) {
1098                         strcpy(ob->parsubstr, "");
1099                         uiBlockEndAlign(block);
1100                 }
1101         }
1102
1103         lim= 10000.0f*MAX2(1.0, v3d->grid);
1104
1105         if(ob==obedit) {
1106                 if(ob->type==OB_ARMATURE) v3d_editarmature_buts(block, v3d, ob, lim);
1107                 if(ob->type==OB_MBALL) v3d_editmetaball_buts(block, ob, lim);
1108                 else v3d_editvertex_buts(C, block, v3d, ob, lim);
1109         }
1110         else if(ob->mode & OB_MODE_POSE) {
1111                 v3d_posearmature_buts(block, v3d, ob, lim);
1112         }
1113         else {
1114                 BoundBox *bb = NULL;
1115                 
1116                 uiDefBut(block, LABEL, 0, "Location:",                                                                          0, 300, 100, 20, 0, 0, 0, 0, 0, "");
1117                 uiBlockBeginAlign(block);       
1118                 uiDefButF(block, NUM, B_OBJECTPANEL, "X:",                                                                      0, 280, 120, 19, &(ob->loc[0]), -lim, lim, 100, 3, "");         
1119                 uiDefButF(block, NUM, B_OBJECTPANEL, "Y:",                                                                      0, 260, 120, 19, &(ob->loc[1]), -lim, lim, 100, 3, "");
1120                 uiDefButF(block, NUM, B_OBJECTPANEL, "Z:",                                                                      0, 240, 120, 19, &(ob->loc[2]), -lim, lim, 100, 3, "");
1121                 uiBlockEndAlign(block);
1122                 
1123                 uiBlockBeginAlign(block);
1124                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCX, B_REDR, ICON_UNLOCKED,           125, 280, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Location value from being Transformed");
1125                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCY, B_REDR, ICON_UNLOCKED,           125, 260, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Location value from being Transformed");
1126                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCZ, B_REDR, ICON_UNLOCKED,           125, 240, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Location value from being Transformed");
1127                 uiBlockEndAlign(block);
1128                 
1129                 tfp->ob_eul[0]= 180.0*ob->rot[0]/M_PI;
1130                 tfp->ob_eul[1]= 180.0*ob->rot[1]/M_PI;
1131                 tfp->ob_eul[2]= 180.0*ob->rot[2]/M_PI;
1132                 
1133                 uiBlockBeginAlign(block);
1134                 if ((ob->parent) && (ob->partype == PARBONE)) {
1135                         uiDefBut(block, LABEL, 0, "Rotation:",                                                                  0, 220, 100, 20, 0, 0, 0, 0, 0, "");
1136                         uiBlockBeginAlign(block);
1137                         uiDefButF(block, NUM, B_OBJECTPANELROT, "X:",                                                   0, 200, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");
1138                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Y:",                                                   0, 180, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
1139                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Z:",                                                   0, 160, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
1140                         uiBlockEndAlign(block);
1141                         
1142                         uiBlockBeginAlign(block);
1143                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   125, 200, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Rotation from being Transformed");
1144                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   125, 180, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Rotation value from being Transformed");
1145                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   125, 160, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Rotation value from being Transformed");
1146                         uiBlockEndAlign(block);
1147
1148                 }
1149                 else {
1150                         uiDefBut(block, LABEL, 0, "Rotation:",                                                                  0, 220, 100, 20, 0, 0, 0, 0, 0, "");
1151                         uiBlockBeginAlign(block);
1152                         uiDefButF(block, NUM, B_OBJECTPANELROT, "X:",                                                   0, 200, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");                    
1153                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Y:",                                                   0, 180, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
1154                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Z:",                                                   0, 160, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
1155                         uiBlockEndAlign(block);
1156                         
1157                         uiBlockBeginAlign(block);
1158                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, B_REDR, ICON_UNLOCKED,   125, 200, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Rotation value from being Transformed");
1159                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, B_REDR, ICON_UNLOCKED,   125, 180, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Rotation value from being Transformed");
1160                         uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, B_REDR, ICON_UNLOCKED,   125, 160, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Rotation value from being Transformed");
1161                         uiBlockEndAlign(block);
1162                 }
1163
1164                 tfp->ob_scale[0]= ob->size[0];
1165                 tfp->ob_scale[1]= ob->size[1];
1166                 tfp->ob_scale[2]= ob->size[2];
1167
1168                 uiDefBut(block, LABEL, 0, "Scale:",                                                                                     0, 140, 100, 20, 0, 0, 0, 0, 0, "");
1169                 uiDefButS(block, OPTION, B_REDR, "Link",                                                                        60, 140, 50, 19, &(tfp->link_scale), 0, 1, 0, 0, "Scale values vary proportionally in all directions");
1170                 uiBlockBeginAlign(block);
1171                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "X:",                                                         0, 120, 120, 19, &(tfp->ob_scale[0]), -lim, lim, 10, 3, "");
1172                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "Y:",                                                         0, 100, 120, 19, &(tfp->ob_scale[1]), -lim, lim, 10, 3, "");
1173                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "Z:",                                                         0, 80, 120, 19, &(tfp->ob_scale[2]), -lim, lim, 10, 3, "");
1174                 uiBlockEndAlign(block);
1175                 
1176                 uiBlockBeginAlign(block);
1177                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEX, B_REDR, ICON_UNLOCKED,         125, 120, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects X Scale value from being Transformed");
1178                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, B_REDR, ICON_UNLOCKED,         125, 100, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Y Scale value from being Transformed");
1179                 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, B_REDR, ICON_UNLOCKED,         125, 80, 25, 19, &(ob->protectflag), 0, 0, 0, 0, "Protects Z Scale value from being Transformed");
1180                 
1181                 
1182
1183                 bb= object_get_boundbox(ob);
1184                 if (bb) {
1185                         float scale[3];
1186
1187                         Mat4ToSize(ob->obmat, scale);
1188
1189                         tfp->ob_dims[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
1190                         tfp->ob_dims[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
1191                         tfp->ob_dims[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
1192
1193                         
1194                         if ((ob->parent) && (ob->partype == PARBONE)) {
1195                                 uiDefBut(block, LABEL, 0, "Dimensions:",                        0, 60, 100, 20, 0, 0, 0, 0, 0, "");
1196                                 uiBlockBeginAlign(block);
1197                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "X:",          0, 40, 150, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate X bounding box size");
1198                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Y:",          0, 20, 150, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate Y bounding box size");
1199                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Z:",          0, 0, 150, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate Z bounding box size");
1200
1201                         }
1202                         else {
1203                                 uiDefBut(block, LABEL, 0, "Dimensions:",                        0, 60, 100, 20, 0, 0, 0, 0, 0, "");
1204                                 uiBlockBeginAlign(block);
1205                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "X:",          0, 40, 150, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate X bounding box size");
1206                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Y:",          0, 20, 150, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate Y bounding box size");
1207                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Z:",          0, 0, 150, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate Z bounding box size");
1208                         }
1209
1210                         uiBlockEndAlign(block);
1211                 }
1212         }
1213 }
1214
1215 #if 0
1216 static void view3d_panel_preview(bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_PREVIEW
1217 {
1218         uiBlock *block;
1219         View3D *v3d= sa->spacedata.first;
1220         int ofsx, ofsy;
1221         
1222         block= uiBeginBlock(C, ar, "view3d_panel_preview", UI_EMBOSS);
1223         uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
1224         uiSetPanelHandler(VIEW3D_HANDLER_PREVIEW);  // for close and esc
1225         
1226         ofsx= -150+(sa->winx/2)/v3d->blockscale;
1227         ofsy= -100+(sa->winy/2)/v3d->blockscale;
1228         if(uiNewPanel(C, ar, block, "Preview", "View3d", ofsx, ofsy, 300, 200)==0) return;
1229
1230         uiBlockSetDrawExtraFunc(block, BIF_view3d_previewdraw);
1231         
1232         if(scene->recalc & SCE_PRV_CHANGED) {
1233                 scene->recalc &= ~SCE_PRV_CHANGED;
1234                 //printf("found recalc\n");
1235                 BIF_view3d_previewrender_free(sa->spacedata.first);
1236                 BIF_preview_changed(0);
1237         }
1238 }
1239 #endif
1240
1241 static void delete_sketch_armature(bContext *C, void *arg1, void *arg2)
1242 {
1243         BIF_deleteSketch(C);
1244 }
1245
1246 static void convert_sketch_armature(bContext *C, void *arg1, void *arg2)
1247 {
1248         BIF_convertSketch(C);
1249 }
1250
1251 static void assign_template_sketch_armature(bContext *C, void *arg1, void *arg2)
1252 {
1253         int index = *(int*)arg1;
1254         BIF_setTemplate(C, index);
1255 }
1256
1257 static int view3d_panel_bonesketch_spaces_poll(const bContext *C, PanelType *pt)
1258 {
1259         Object *obedit = CTX_data_edit_object(C);
1260
1261         /* replace with check call to sketching lib */
1262         return (obedit && obedit->type == OB_ARMATURE);
1263 }
1264 static void view3d_panel_bonesketch_spaces(const bContext *C, Panel *pa)
1265 {
1266         Scene *scene = CTX_data_scene(C);
1267         static int template_index;
1268         static char joint_label[128];
1269         uiBlock *block;
1270         uiBut *but;
1271         char *bone_name;
1272         int yco = 130;
1273         int nb_joints;
1274         static char subdiv_tooltip[4][64] = {
1275                 "Subdivide arcs based on a fixed number of bones",
1276                 "Subdivide arcs in bones of equal length",
1277                 "Subdivide arcs based on correlation",
1278                 "Retarget template to stroke"
1279                 };
1280
1281         
1282         block= uiLayoutFreeBlock(pa->layout);
1283         uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
1284
1285         uiBlockBeginAlign(block);
1286         
1287         /* use real flag instead of 1 */
1288         uiDefButBitC(block, TOG, BONE_SKETCHING, B_REDR, "Use Bone Sketching", 10, yco, 160, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Use sketching to create and edit bones, (Ctrl snaps to mesh volume)");
1289         uiDefButBitC(block, TOG, BONE_SKETCHING_ADJUST, B_REDR, "A", 170, yco, 20, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Adjust strokes by drawing near them");
1290         uiDefButBitC(block, TOG, BONE_SKETCHING_QUICK, B_REDR, "Q", 190, yco, 20, 20, &scene->toolsettings->bone_sketching, 0, 0, 0, 0, "Automatically convert and delete on stroke end");
1291         yco -= 20;
1292         
1293         but = uiDefBut(block, BUT, B_REDR, "Convert", 10,yco,100,20, 0, 0, 0, 0, 0, "Convert sketch to armature");
1294         uiButSetFunc(but, convert_sketch_armature, NULL, NULL);
1295
1296         but = uiDefBut(block, BUT, B_REDR, "Delete", 110,yco,100,20, 0, 0, 0, 0, 0, "Delete sketch");
1297         uiButSetFunc(but, delete_sketch_armature, NULL, NULL);
1298         yco -= 20;
1299         
1300         uiBlockEndAlign(block);
1301
1302         uiBlockBeginAlign(block);
1303         
1304         uiDefButC(block, MENU, B_REDR, "Subdivision Method%t|Length%x1|Adaptative%x2|Fixed%x0|Template%x3", 10,yco,60,19, &scene->toolsettings->bone_sketching_convert, 0, 0, 0, 0, subdiv_tooltip[(unsigned char)scene->toolsettings->bone_sketching_convert]);
1305
1306         switch(scene->toolsettings->bone_sketching_convert)
1307         {
1308         case SK_CONVERT_CUT_LENGTH:
1309                 uiDefButF(block, NUM, B_REDR,                                   "Lim:",         70, yco, 140, 19, &scene->toolsettings->skgen_length_limit,0.1,50.0, 10, 0,             "Maximum length of the subdivided bones");
1310                 yco -= 20;
1311                 break;
1312         case SK_CONVERT_CUT_ADAPTATIVE:
1313                 uiDefButF(block, NUM, B_REDR,                                   "Thres:",                       70, yco, 140, 19, &scene->toolsettings->skgen_correlation_limit,0.0, 1.0, 0.01, 0,      "Correlation threshold for subdivision");
1314                 yco -= 20;
1315                 break;
1316         default:
1317         case SK_CONVERT_CUT_FIXED:
1318                 uiDefButC(block, NUM, B_REDR,                                   "Num:",         70, yco, 140, 19, &scene->toolsettings->skgen_subdivision_number,1, 100, 1, 5,  "Number of subdivided bones");
1319                 yco -= 20;
1320                 break;
1321         case SK_CONVERT_RETARGET:
1322                 uiDefButC(block, ROW, B_NOP, "No",                      70,  yco, 40,19, &scene->toolsettings->skgen_retarget_roll, 0, 0, 0, 0,                                                                 "No special roll treatment");
1323                 uiDefButC(block, ROW, B_NOP, "View",            110,  yco, 50,19, &scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_VIEW, 0, 0,                            "Roll bones perpendicular to view");
1324                 uiDefButC(block, ROW, B_NOP, "Joint",           160, yco, 50,19, &scene->toolsettings->skgen_retarget_roll, 0, SK_RETARGET_ROLL_JOINT, 0, 0,                            "Roll bones relative to joint bend");
1325                 yco -= 30;
1326
1327                 uiBlockEndAlign(block);
1328
1329                 uiBlockBeginAlign(block);
1330                 /* button here to select what to do (copy or not), template, ...*/
1331
1332                 BIF_makeListTemplates(C);
1333                 template_index = BIF_currentTemplate(C);
1334                 
1335                 but = uiDefButI(block, MENU, B_REDR, BIF_listTemplates(C), 10,yco,200,19, &template_index, 0, 0, 0, 0, "Template");
1336                 uiButSetFunc(but, assign_template_sketch_armature, &template_index, NULL);
1337                 
1338                 yco -= 20;
1339                 
1340                 uiDefButF(block, NUM, B_NOP,                                                    "A:",                   10, yco, 66,19, &scene->toolsettings->skgen_retarget_angle_weight, 0, 10, 1, 0,         "Angle Weight");
1341                 uiDefButF(block, NUM, B_NOP,                                                    "L:",                   76, yco, 67,19, &scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0,                "Length Weight");
1342                 uiDefButF(block, NUM, B_NOP,                                                    "D:",           143,yco, 67,19, &scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0,              "Distance Weight");
1343                 yco -= 20;
1344                 
1345                 uiDefBut(block, TEX,B_REDR,"S:",                                                        10,  yco, 90, 20, scene->toolsettings->skgen_side_string, 0.0, 8.0, 0, 0, "Text to replace &S with");
1346                 uiDefBut(block, TEX,B_REDR,"N:",                                                        100, yco, 90, 20, scene->toolsettings->skgen_num_string, 0.0, 8.0, 0, 0, "Text to replace &N with");
1347                 uiDefIconButBitC(block, TOG, SK_RETARGET_AUTONAME, B_NOP, ICON_AUTO,190,yco,20,20, &scene->toolsettings->skgen_retarget_options, 0, 0, 0, 0, "Use Auto Naming");        
1348                 yco -= 20;
1349
1350                 /* auto renaming magic */
1351                 uiBlockEndAlign(block);
1352                 
1353                 nb_joints = BIF_nbJointsTemplate(C);
1354
1355                 if (nb_joints == -1)
1356                 {
1357                         //XXX
1358                         //nb_joints = G.totvertsel;
1359                 }
1360                 
1361                 bone_name = BIF_nameBoneTemplate(C);
1362                 
1363                 BLI_snprintf(joint_label, 32, "%i joints: %s", nb_joints, bone_name);
1364                 
1365                 uiDefBut(block, LABEL, 1, joint_label,                                  10, yco, 200, 20, NULL, 0.0, 0.0, 0, 0, "");
1366                 yco -= 20;
1367                 break;
1368         }
1369
1370         uiBlockEndAlign(block);
1371 }
1372
1373 #if 0 // XXX not used
1374
1375 /* op->invoke */
1376 static void redo_cb(bContext *C, void *arg_op, void *arg2)
1377 {
1378         wmOperator *lastop= arg_op;
1379         
1380         if(lastop) {
1381                 int retval;
1382                 
1383                 printf("operator redo %s\n", lastop->type->name);
1384                 ED_undo_pop(C);
1385                 retval= WM_operator_repeat(C, lastop);
1386                 if((retval & OPERATOR_FINISHED)==0) {
1387                         printf("operator redo failed %s\n", lastop->type->name);
1388                         ED_undo_redo(C);
1389                 }
1390         }
1391 }
1392
1393 static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
1394 {
1395         wmWindowManager *wm= CTX_wm_manager(C);
1396         wmOperator *op;
1397         PointerRNA ptr;
1398         uiBlock *block;
1399         
1400         block= uiLayoutGetBlock(pa->layout);
1401
1402         /* only for operators that are registered and did an undo push */
1403         for(op= wm->operators.last; op; op= op->prev)
1404                 if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO))
1405                         break;
1406         
1407         if(op==NULL)
1408                 return;
1409         
1410         uiBlockSetFunc(block, redo_cb, op, NULL);
1411         
1412         if(!op->properties) {
1413                 IDPropertyTemplate val = {0};
1414                 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
1415         }
1416         
1417         RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
1418         uiDefAutoButsRNA(C, pa->layout, &ptr, 2);
1419 }
1420 #endif // XXX not used
1421
1422 void view3d_buttons_register(ARegionType *art)
1423 {
1424         PanelType *pt;
1425
1426         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel object");
1427         strcpy(pt->idname, "VIEW3D_PT_object");
1428         strcpy(pt->label, "Transform");
1429         pt->draw= view3d_panel_object;
1430         BLI_addtail(&art->paneltypes, pt);
1431         
1432         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel gpencil");
1433         strcpy(pt->idname, "VIEW3D_PT_gpencil");
1434         strcpy(pt->label, "Grease Pencil");
1435         pt->draw= gpencil_panel_standard;
1436         BLI_addtail(&art->paneltypes, pt);
1437 /*
1438         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel properties");
1439         strcpy(pt->idname, "VIEW3D_PT_properties");
1440         strcpy(pt->label, "View Properties");
1441         pt->draw= view3d_panel_properties;
1442         BLI_addtail(&art->paneltypes, pt);
1443
1444         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel transform spaces");
1445         strcpy(pt->idname, "VIEW3D_PT_transform spaces");
1446         strcpy(pt->label, "Transform Orientations");
1447         pt->draw= view3d_panel_transform_spaces;
1448         BLI_addtail(&art->paneltypes, pt);
1449
1450         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel gpencil");
1451         strcpy(pt->idname, "VIEW3D_PT_gpencil");
1452         strcpy(pt->label, "Greas Pencil");
1453         pt->draw= view3d_panel_gpencil;
1454         BLI_addtail(&art->paneltypes, pt);*/
1455
1456         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel bonesketch spaces");
1457         strcpy(pt->idname, "VIEW3D_PT_bonesketch_spaces");
1458         strcpy(pt->label, "Bone Sketching");
1459         pt->draw= view3d_panel_bonesketch_spaces;
1460         pt->poll= view3d_panel_bonesketch_spaces_poll;
1461         BLI_addtail(&art->paneltypes, pt);
1462
1463         /*
1464         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel redo");
1465         strcpy(pt->idname, "VIEW3D_PT_redo");
1466         strcpy(pt->label, "Last Operator");
1467         pt->draw= view3d_panel_operator_redo;
1468         BLI_addtail(&art->paneltypes, pt);
1469 */
1470         // XXX view3d_panel_preview(C, ar, 0);
1471 }
1472
1473 static int view3d_properties(bContext *C, wmOperator *op)
1474 {
1475         ScrArea *sa= CTX_wm_area(C);
1476         ARegion *ar= view3d_has_buttons_region(sa);
1477         
1478         if(ar)
1479                 ED_region_toggle_hidden(C, ar);
1480
1481         return OPERATOR_FINISHED;
1482 }
1483
1484 void VIEW3D_OT_properties(wmOperatorType *ot)
1485 {
1486         ot->name= "Properties";
1487         ot->description= "Toggles the properties panel display.";
1488         ot->idname= "VIEW3D_OT_properties";
1489         
1490         ot->exec= view3d_properties;
1491         ot->poll= ED_operator_view3d_active;
1492         
1493         /* flags */
1494         ot->flag= 0;
1495 }