svn merge -r 23207:23528 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[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         if (!pchan)     {
516                 uiDefBut(block, LABEL, 0, "No Bone Active",                     0, 240, 100, 20, 0, 0, 0, 0, 0, "");
517                 return; 
518         }
519         
520         if (pchan->rotmode == ROT_MODE_AXISANGLE) {
521                 float quat[4];
522                 /* convert to euler, passing through quats... */
523                 AxisAngleToQuat(quat, &pchan->quat[1], pchan->quat[0]);
524                 QuatToEul(quat, tfp->ob_eul);
525         }
526         else if (pchan->rotmode == ROT_MODE_QUAT)
527                 QuatToEul(pchan->quat, tfp->ob_eul);
528         else
529                 VecCopyf(tfp->ob_eul, pchan->eul);
530         tfp->ob_eul[0]*= 180.0/M_PI;
531         tfp->ob_eul[1]*= 180.0/M_PI;
532         tfp->ob_eul[2]*= 180.0/M_PI;
533         
534         uiDefBut(block, LABEL, 0, "Location:",                  0, 240, 100, 20, 0, 0, 0, 0, 0, "");
535         uiBlockBeginAlign(block);
536         uiDefButF(block, NUM, B_ARMATUREPANEL2, "X:",   0, 220, 120, 19, pchan->loc, -lim, lim, 100, 3, "");
537         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Y:",   0, 200, 120, 19, pchan->loc+1, -lim, lim, 100, 3, "");
538         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Z:",   0, 180, 120, 19, pchan->loc+2, -lim, lim, 100, 3, "");
539         uiBlockEndAlign(block);
540         
541         uiBlockBeginAlign(block);
542         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");
543         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");
544         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");
545         uiBlockEndAlign(block);
546         
547         uiDefBut(block, LABEL, 0, "Rotation:",                  0, 160, 100, 20, 0, 0, 0, 0, 0, "");
548         uiBlockBeginAlign(block);
549         uiDefButF(block, NUM, B_ARMATUREPANEL3, "X:",   0, 140, 120, 19, tfp->ob_eul, -1000.0, 1000.0, 100, 3, "");
550         uiDefButF(block, NUM, B_ARMATUREPANEL3, "Y:",   0, 120, 120, 19, tfp->ob_eul+1, -1000.0, 1000.0, 100, 3, "");
551         uiDefButF(block, NUM, B_ARMATUREPANEL3, "Z:",   0, 100, 120, 19, tfp->ob_eul+2, -1000.0, 1000.0, 100, 3, "");
552         uiBlockEndAlign(block);
553         
554         uiBlockBeginAlign(block);
555         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");
556         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");
557         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");
558         uiBlockEndAlign(block);
559         
560         uiDefBut(block, LABEL, 0, "Scale:",                             0, 80, 100, 20, 0, 0, 0, 0, 0, "");
561         uiBlockBeginAlign(block);
562         uiDefButF(block, NUM, B_ARMATUREPANEL2, "X:",   0, 60, 120, 19, pchan->size, -lim, lim, 10, 3, "");
563         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Y:",   0, 40, 120, 19, pchan->size+1, -lim, lim, 10, 3, "");
564         uiDefButF(block, NUM, B_ARMATUREPANEL2, "Z:",   0, 20, 120, 19, pchan->size+2, -lim, lim, 10, 3, "");
565         uiBlockEndAlign(block);
566         
567         uiBlockBeginAlign(block);
568         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");
569         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");
570         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");
571         uiBlockEndAlign(block);
572 }
573
574 /* assumes armature editmode */
575 void validate_editbonebutton_cb(bContext *C, void *bonev, void *namev)
576 {
577         EditBone *eBone= bonev;
578         char oldname[32], newname[32];
579         
580         /* need to be on the stack */
581         BLI_strncpy(newname, eBone->name, 32);
582         BLI_strncpy(oldname, (char *)namev, 32);
583         /* restore */
584         BLI_strncpy(eBone->name, oldname, 32);
585         
586         ED_armature_bone_rename(CTX_data_edit_object(C)->data, oldname, newname); // editarmature.c
587         WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, CTX_data_edit_object(C)); // XXX fix
588 }
589
590 static void v3d_editarmature_buts(uiBlock *block, View3D *v3d, Object *ob, float lim)
591 {
592         bArmature *arm= ob->data;
593         EditBone *ebone;
594         TransformProperties *tfp= v3d->properties_storage;
595         
596         ebone= arm->edbo->first;
597
598         for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
599                 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
600                         break;
601         }
602
603         if (!ebone)
604                 return;
605         
606         uiDefBut(block, LABEL, 0, "Head:",                                      0, 210, 100, 20, 0, 0, 0, 0, 0, "");
607         uiBlockBeginAlign(block);
608         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");
609         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");
610         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");
611         if (ebone->parent && ebone->flag & BONE_CONNECTED )
612                 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");
613         else
614                 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");
615         uiBlockEndAlign(block);
616         
617         uiBlockEndAlign(block);
618         uiDefBut(block, LABEL, 0, "Tail:",                                      0, 110, 100, 20, 0, 0, 0, 0, 0, "");
619         uiBlockBeginAlign(block);
620         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");
621         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");
622         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");
623         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");
624         uiBlockEndAlign(block);
625         
626         tfp->ob_eul[0]= 180.0*ebone->roll/M_PI;
627         uiDefButF(block, NUM, B_ARMATUREPANEL1, "Roll:",        0, 0, 100, 19, tfp->ob_eul, -lim, lim, 1000, 3, "Bone rotation around head-tail axis");
628         uiBlockBeginAlign(block);
629         
630         
631 }
632
633 static void v3d_editmetaball_buts(uiBlock *block, Object *ob, float lim)
634 {
635         MetaElem *lastelem= NULL; // XXX
636
637         if(lastelem) {
638                 uiBlockBeginAlign(block);
639                 uiDefButF(block, NUM, B_RECALCMBALL, "LocX:", 10, 70, 140, 19, &lastelem->x, -lim, lim, 100, 3, "");
640                 uiDefButF(block, NUM, B_RECALCMBALL, "LocY:", 10, 50, 140, 19, &lastelem->y, -lim, lim, 100, 3, "");
641                 uiDefButF(block, NUM, B_RECALCMBALL, "LocZ:", 10, 30, 140, 19, &lastelem->z, -lim, lim, 100, 3, "");
642
643                 uiBlockBeginAlign(block);
644                 if(lastelem->type!=MB_BALL)
645                         uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 160, 70, 140, 19, &lastelem->expx, 0, lim, 100, 3, "");
646                 if((lastelem->type!=MB_BALL) && (lastelem->type!=MB_TUBE))
647                         uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 160, 50, 140, 19, &lastelem->expy, 0, lim, 100, 3, "");
648                 if((lastelem->type==MB_ELIPSOID) || (lastelem->type==MB_CUBE))
649                         uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 160, 30, 140, 19, &lastelem->expz, 0, lim, 100, 3, "");
650
651                 uiBlockEndAlign(block); 
652
653                 uiBlockBeginAlign(block);
654                 uiDefButF(block, NUM, B_RECALCMBALL, "Radius:", 10, 120, 140, 19, &lastelem->rad, 0, lim, 100, 3, "Size of the active metaball");
655                 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 10, 100, 140, 19, &lastelem->s, 0, 10, 100, 3, "Stiffness of the active metaball");
656                 uiBlockEndAlign(block);
657                 
658                 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");
659                 
660         }
661 }
662
663 /* test if 'ob' is a parent somewhere in par's parents */
664 static int test_parent_loop(Object *par, Object *ob)
665 {
666         if(par == NULL) return 0;
667         if(ob == par) return 1;
668         return test_parent_loop(par->parent, ob);
669 }
670
671 static void do_view3d_region_buttons(bContext *C, void *arg, int event)
672 {
673         Scene *scene= CTX_data_scene(C);
674         Object *obedit= CTX_data_edit_object(C);
675         View3D *v3d= CTX_wm_view3d(C);
676         BoundBox *bb;
677         Object *ob= OBACT;
678         TransformProperties *tfp= v3d->properties_storage;
679         
680         switch(event) {
681         
682         case B_REDR:
683                 ED_area_tag_redraw(CTX_wm_area(C));
684                 return; /* no notifier! */
685                 
686         case B_OBJECTPANEL:
687                 DAG_id_flush_update(&ob->id, OB_RECALC_OB);
688                 break;
689                 
690         case B_OBJECTPANELROT:
691                 if(ob) {
692                         ob->rot[0]= M_PI*tfp->ob_eul[0]/180.0;
693                         ob->rot[1]= M_PI*tfp->ob_eul[1]/180.0;
694                         ob->rot[2]= M_PI*tfp->ob_eul[2]/180.0;
695                         DAG_id_flush_update(&ob->id, OB_RECALC_OB);
696                 }
697                 break;
698
699         case B_OBJECTPANELSCALE:
700                 if(ob) {
701
702                         /* link scale; figure out which axis changed */
703                         if (tfp->link_scale) {
704                                 float ratio, tmp, max = 0.0;
705                                 int axis;
706                                 
707                                 axis = 0;
708                                 max = fabs(tfp->ob_scale[0] - ob->size[0]);
709                                 tmp = fabs(tfp->ob_scale[1] - ob->size[1]);
710                                 if (tmp > max) {
711                                         axis = 1;
712                                         max = tmp;
713                                 }
714                                 tmp = fabs(tfp->ob_scale[2] - ob->size[2]);
715                                 if (tmp > max) {
716                                         axis = 2;
717                                         max = tmp;
718                                 }
719                         
720                                 if (ob->size[axis] != tfp->ob_scale[axis]) {
721                                         if (fabs(ob->size[axis]) > FLT_EPSILON) {
722                                                 ratio = tfp->ob_scale[axis] / ob->size[axis];
723                                                 ob->size[0] *= ratio;
724                                                 ob->size[1] *= ratio;
725                                                 ob->size[2] *= ratio;
726                                         }
727                                 }
728                         }
729                         else {
730                                 VECCOPY(ob->size, tfp->ob_scale);
731                                 
732                         }
733                         DAG_id_flush_update(&ob->id, OB_RECALC_OB);
734                 }
735                 break;
736
737         case B_OBJECTPANELDIMS:
738                 bb= object_get_boundbox(ob);
739                 if(bb) {
740                         float old_dims[3], scale[3], ratio, len[3];
741                         int axis;
742
743                         Mat4ToSize(ob->obmat, scale);
744
745                         len[0] = bb->vec[4][0] - bb->vec[0][0];
746                         len[1] = bb->vec[2][1] - bb->vec[0][1];
747                         len[2] = bb->vec[1][2] - bb->vec[0][2];
748
749                         old_dims[0] = fabs(scale[0]) * len[0];
750                         old_dims[1] = fabs(scale[1]) * len[1];
751                         old_dims[2] = fabs(scale[2]) * len[2];
752
753                         /* for each axis changed */
754                         for (axis = 0; axis<3; axis++) {
755                                 if (fabs(old_dims[axis] - tfp->ob_dims[axis]) > 0.0001) {
756                                         if (old_dims[axis] > 0.0) {
757                                                 ratio = tfp->ob_dims[axis] / old_dims[axis]; 
758                                                 if (tfp->link_scale) {
759                                                         ob->size[0] *= ratio;
760                                                         ob->size[1] *= ratio;
761                                                         ob->size[2] *= ratio;
762                                                         break;
763                                                 }
764                                                 else {
765                                                         ob->size[axis] *= ratio;
766                                                 }
767                                         }
768                                         else {
769                                                 if (len[axis] > 0) {
770                                                         ob->size[axis] = tfp->ob_dims[axis] / len[axis];
771                                                 }
772                                         }
773                                 }
774                         }
775                         
776                         /* prevent multiple B_OBJECTPANELDIMS events to keep scaling, cycling with TAB on buttons can cause that */
777                         VECCOPY(tfp->ob_dims, old_dims);
778                         
779                         DAG_id_flush_update(&ob->id, OB_RECALC_OB);
780                 }
781                 break;
782         
783         case B_OBJECTPANELMEDIAN:
784                 if(ob) {
785                         v3d_editvertex_buts(C, NULL, v3d, ob, 1.0);
786                         DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
787                 }
788                 break;
789                 
790                 /* note; this case also used for parbone */
791         case B_OBJECTPANELPARENT:
792                 if(ob) {
793                         if(ob->id.lib || test_parent_loop(ob->parent, ob) ) 
794                                 ob->parent= NULL;
795                         else {
796                                 DAG_scene_sort(scene);
797                                 DAG_id_flush_update(&ob->id, OB_RECALC_OB);
798                         }
799                 }
800                 break;
801                 
802         case B_ARMATUREPANEL1:
803                 {
804                         bArmature *arm= obedit->data;
805                         EditBone *ebone, *child;
806                         
807                         for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
808                                 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
809                                         break;
810                         }
811                         if (ebone) {
812                                 ebone->roll= M_PI*tfp->ob_eul[0]/180.0;
813                                 //      Update our parent
814                                 if (ebone->parent && ebone->flag & BONE_CONNECTED){
815                                         VECCOPY (ebone->parent->tail, ebone->head);
816                                 }
817                         
818                                 //      Update our children if necessary
819                                 for (child = arm->edbo->first; child; child=child->next){
820                                         if (child->parent == ebone && (child->flag & BONE_CONNECTED)){
821                                                 VECCOPY (child->head, ebone->tail);
822                                         }
823                                 }
824                                 if(arm->flag & ARM_MIRROR_EDIT) {
825                                         EditBone *eboflip= ED_armature_bone_get_mirrored(arm->edbo, ebone);
826                                         if(eboflip) {
827                                                 eboflip->roll= -ebone->roll;
828                                                 eboflip->head[0]= -ebone->head[0];
829                                                 eboflip->tail[0]= -ebone->tail[0];
830                                                 
831                                                 //      Update our parent
832                                                 if (eboflip->parent && eboflip->flag & BONE_CONNECTED){
833                                                         VECCOPY (eboflip->parent->tail, eboflip->head);
834                                                 }
835                                                 
836                                                 //      Update our children if necessary
837                                                 for (child = arm->edbo->first; child; child=child->next){
838                                                         if (child->parent == eboflip && (child->flag & BONE_CONNECTED)){
839                                                                 VECCOPY (child->head, eboflip->tail);
840                                                         }
841                                                 }
842                                         }
843                                 }
844                         }
845                 }
846                 break;
847         case B_ARMATUREPANEL3:  // rotate button on channel
848                 {
849                         bArmature *arm;
850                         bPoseChannel *pchan;
851                         Bone *bone;
852                         float eul[3];
853                         
854                         arm = ob->data;
855                         if (!arm || !ob->pose) return;
856                                 
857                         for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
858                                 bone = pchan->bone;
859                                 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
860                                         break;
861                         }
862                         if (!pchan) return;
863                         
864                         /* make a copy to eul[3], to allow TAB on buttons to work */
865                         eul[0]= M_PI*tfp->ob_eul[0]/180.0;
866                         eul[1]= M_PI*tfp->ob_eul[1]/180.0;
867                         eul[2]= M_PI*tfp->ob_eul[2]/180.0;
868                         
869                         if (pchan->rotmode == ROT_MODE_AXISANGLE) {
870                                 float quat[4];
871                                 /* convert to axis-angle, passing through quats  */
872                                 EulToQuat(eul, quat);
873                                 QuatToAxisAngle(quat, &pchan->quat[1], &pchan->quat[0]);
874                         }
875                         else if (pchan->rotmode == ROT_MODE_QUAT)
876                                 EulToQuat(eul, pchan->quat);
877                         else
878                                 VecCopyf(pchan->eul, eul);
879                         
880                 }
881                 /* no break, pass on */
882         case B_ARMATUREPANEL2:
883                 {
884                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
885                         DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
886                 }
887                 break;
888         case B_TRANSFORMSPACEADD:
889                 BIF_manageTransformOrientation(C, 1, 0);
890                 break;
891         case B_TRANSFORMSPACECLEAR:
892                 BIF_clearTransformOrientation(C);
893                 break;
894                 
895 #if 0 // XXX
896         case B_WEIGHT0_0:
897                 wpaint->weight = 0.0f;
898                 break;
899                 
900         case B_WEIGHT1_4:
901                 wpaint->weight = 0.25f;
902                 break;
903         case B_WEIGHT1_2:
904                 wpaint->weight = 0.5f;
905                 break;
906         case B_WEIGHT3_4:
907                 wpaint->weight = 0.75f;
908                 break;
909         case B_WEIGHT1_0:
910                 wpaint->weight = 1.0f;
911                 break;
912                 
913         case B_OPA1_8:
914                 wpaint->a = 0.125f;
915                 break;
916         case B_OPA1_4:
917                 wpaint->a = 0.25f;
918                 break;
919         case B_OPA1_2:
920                 wpaint->a = 0.5f;
921                 break;
922         case B_OPA3_4:
923                 wpaint->a = 0.75f;
924                 break;
925         case B_OPA1_0:
926                 wpaint->a = 1.0f;
927                 break;
928 #endif
929         case B_CLR_WPAINT:
930 //              if(!multires_level1_test()) {
931                 {
932                         bDeformGroup *defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
933                         if(defGroup) {
934                                 Mesh *me= ob->data;
935                                 int a;
936                                 for(a=0; a<me->totvert; a++)
937                                         ED_vgroup_vert_remove (ob, defGroup, a);
938                                 DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
939                         }
940                 }
941                 break;
942         case B_RV3D_LOCKED:
943         case B_RV3D_BOXVIEW:
944         case B_RV3D_BOXCLIP:
945                 {
946                         ScrArea *sa= CTX_wm_area(C);
947                         ARegion *ar= sa->regionbase.last;
948                         RegionView3D *rv3d;
949                         short viewlock;
950                         
951                         ar= ar->prev;
952                         rv3d= ar->regiondata;
953                         viewlock= rv3d->viewlock;
954                         
955                         if((viewlock & RV3D_LOCKED)==0)
956                                 viewlock= 0;
957                         else if((viewlock & RV3D_BOXVIEW)==0)
958                                 viewlock &= ~RV3D_BOXCLIP;
959                         
960                         for(; ar; ar= ar->prev) {
961                                 if(ar->alignment==RGN_ALIGN_QSPLIT) {
962                                         rv3d= ar->regiondata;
963                                         rv3d->viewlock= viewlock;
964                                 }
965                         }
966                         
967                         if(rv3d->viewlock & RV3D_BOXVIEW)
968                                 view3d_boxview_copy(sa, sa->regionbase.last);
969                         
970                         ED_area_tag_redraw(sa);
971                 }
972                 break;
973         }
974
975         /* default for now */
976         WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
977 }
978
979 void removeTransformOrientation_func(bContext *C, void *target, void *unused)
980 {
981         BIF_removeTransformOrientation(C, (TransformOrientation *) target);
982 }
983
984 void selectTransformOrientation_func(bContext *C, void *target, void *unused)
985 {
986         BIF_selectTransformOrientation(C, (TransformOrientation *) target);
987 }
988
989 #if 0 // XXX not used
990 static void view3d_panel_transform_spaces(const bContext *C, Panel *pa)
991 {
992         Scene *scene= CTX_data_scene(C);
993         Object *obedit= CTX_data_edit_object(C);
994         View3D *v3d= CTX_wm_view3d(C);
995         ListBase *transform_spaces = &scene->transform_spaces;
996         TransformOrientation *ts = transform_spaces->first;
997         uiBlock *block;
998         uiBut *but;
999         int xco = 20, yco = 70;
1000         int index;
1001
1002         block= uiLayoutFreeBlock(pa->layout);
1003
1004         uiBlockBeginAlign(block);
1005         
1006         if (obedit)
1007                 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the selected element as a Transform Orientation");
1008         else
1009                 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the active object as a Transform Orientation");
1010
1011         uiDefBut(block, BUT, B_TRANSFORMSPACECLEAR, "Clear", xco + 80,120,80,20, 0, 0, 0, 0, 0, "Removal all Transform Orientations");
1012         
1013         uiBlockEndAlign(block);
1014         
1015         uiBlockBeginAlign(block);
1016         
1017         uiDefButS(block, ROW, B_REDR, "Global", xco,            90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_GLOBAL,0, 0, "Global Transform Orientation");
1018         uiDefButS(block, ROW, B_REDR, "Local",  xco + 40,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_LOCAL, 0, 0, "Local Transform Orientation");
1019         uiDefButS(block, ROW, B_REDR, "Normal", xco + 80,       90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_NORMAL,0, 0, "Normal Transform Orientation");
1020         uiDefButS(block, ROW, B_REDR, "View",           xco + 120,      90, 40,20, &v3d->twmode, 5.0, (float)V3D_MANIP_VIEW,    0, 0, "View Transform Orientation");
1021         
1022         for (index = V3D_MANIP_CUSTOM, ts = transform_spaces->first ; ts ; ts = ts->next, index++) {
1023
1024                 if (v3d->twmode == index) {
1025                         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");
1026                 }
1027                 else {
1028                         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");
1029                 }
1030                 uiButSetFunc(but, selectTransformOrientation_func, ts, NULL);
1031                 uiDefBut(block, TEX, 0, "", xco+=XIC, yco,100+XIC,20, &ts->name, 0, 30, 0, 0, "Edits the name of this Transform Orientation");
1032                 but = uiDefIconBut(block, BUT, B_REDR, ICON_X, xco+=100+XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes this Transform Orientation");
1033                 uiButSetFunc(but, removeTransformOrientation_func, ts, NULL);
1034
1035                 xco = 20;
1036                 yco -= 25;
1037         }
1038         uiBlockEndAlign(block);
1039 }
1040 #endif // XXX not used
1041
1042 #if 0
1043 static void brush_idpoin_handle(bContext *C, ID *id, int event)
1044 {
1045         Brush **br = current_brush_source(CTX_data_scene(C));
1046
1047         if(!br)
1048                 return;
1049
1050         switch(event) {
1051         case UI_ID_BROWSE:
1052                 (*br) = (Brush*)id;
1053                 break;
1054         case UI_ID_DELETE:
1055                 brush_delete(br);
1056                 break;
1057         case UI_ID_RENAME:
1058                 /* XXX ? */
1059                 break;
1060         case UI_ID_ADD_NEW:
1061                 if(id) {
1062                         (*br) = copy_brush((Brush*)id);
1063                         id->us--;
1064                 }
1065                 else
1066                         (*br) = add_brush("Brush");
1067                 break;
1068         case UI_ID_OPEN:
1069                 /* XXX not implemented */
1070                 break;
1071         }
1072 }
1073 #endif
1074
1075 static void view3d_panel_object(const bContext *C, Panel *pa)
1076 {
1077         uiBlock *block;
1078         Scene *scene= CTX_data_scene(C);
1079         Object *obedit= CTX_data_edit_object(C);
1080         View3D *v3d= CTX_wm_view3d(C);
1081         //uiBut *bt;
1082         Object *ob= OBACT;
1083         TransformProperties *tfp;
1084         float lim;
1085         
1086         if(ob==NULL) return;
1087
1088         /* make sure we got storage */
1089         if(v3d->properties_storage==NULL)
1090                 v3d->properties_storage= MEM_callocN(sizeof(TransformProperties), "TransformProperties");
1091         tfp= v3d->properties_storage;
1092         
1093         block= uiLayoutFreeBlock(pa->layout);
1094         uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
1095
1096 // XXX  uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
1097         
1098         if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) {
1099         }
1100         else {
1101                 if((ob->mode & OB_MODE_PARTICLE_EDIT)==0) {
1102                         strcpy(ob->parsubstr, "");
1103                         uiBlockEndAlign(block);
1104                 }
1105         }
1106
1107         lim= 10000.0f*MAX2(1.0, v3d->grid);
1108
1109         if(ob==obedit) {
1110                 if(ob->type==OB_ARMATURE) v3d_editarmature_buts(block, v3d, ob, lim);
1111                 if(ob->type==OB_MBALL) v3d_editmetaball_buts(block, ob, lim);
1112                 else v3d_editvertex_buts(C, block, v3d, ob, lim);
1113         }
1114         else if(ob->mode & OB_MODE_POSE) {
1115                 v3d_posearmature_buts(block, v3d, ob, lim);
1116         }
1117         else {
1118                 BoundBox *bb = NULL;
1119                 
1120                 uiDefBut(block, LABEL, 0, "Location:",                                                                          0, 300, 100, 20, 0, 0, 0, 0, 0, "");
1121                 uiBlockBeginAlign(block);       
1122                 uiDefButF(block, NUM, B_OBJECTPANEL, "X:",                                                                      0, 280, 120, 19, &(ob->loc[0]), -lim, lim, 100, 3, "");         
1123                 uiDefButF(block, NUM, B_OBJECTPANEL, "Y:",                                                                      0, 260, 120, 19, &(ob->loc[1]), -lim, lim, 100, 3, "");
1124                 uiDefButF(block, NUM, B_OBJECTPANEL, "Z:",                                                                      0, 240, 120, 19, &(ob->loc[2]), -lim, lim, 100, 3, "");
1125                 uiBlockEndAlign(block);
1126                 
1127                 uiBlockBeginAlign(block);
1128                 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");
1129                 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");
1130                 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");
1131                 uiBlockEndAlign(block);
1132                 
1133                 tfp->ob_eul[0]= 180.0*ob->rot[0]/M_PI;
1134                 tfp->ob_eul[1]= 180.0*ob->rot[1]/M_PI;
1135                 tfp->ob_eul[2]= 180.0*ob->rot[2]/M_PI;
1136                 
1137                 uiBlockBeginAlign(block);
1138                 if ((ob->parent) && (ob->partype == PARBONE)) {
1139                         uiDefBut(block, LABEL, 0, "Rotation:",                                                                  0, 220, 100, 20, 0, 0, 0, 0, 0, "");
1140                         uiBlockBeginAlign(block);
1141                         uiDefButF(block, NUM, B_OBJECTPANELROT, "X:",                                                   0, 200, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");
1142                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Y:",                                                   0, 180, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
1143                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Z:",                                                   0, 160, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
1144                         uiBlockEndAlign(block);
1145                         
1146                         uiBlockBeginAlign(block);
1147                         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");
1148                         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");
1149                         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");
1150                         uiBlockEndAlign(block);
1151
1152                 }
1153                 else {
1154                         uiDefBut(block, LABEL, 0, "Rotation:",                                                                  0, 220, 100, 20, 0, 0, 0, 0, 0, "");
1155                         uiBlockBeginAlign(block);
1156                         uiDefButF(block, NUM, B_OBJECTPANELROT, "X:",                                                   0, 200, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");                    
1157                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Y:",                                                   0, 180, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
1158                         uiDefButF(block, NUM, B_OBJECTPANELROT, "Z:",                                                   0, 160, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
1159                         uiBlockEndAlign(block);
1160                         
1161                         uiBlockBeginAlign(block);
1162                         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");
1163                         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");
1164                         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");
1165                         uiBlockEndAlign(block);
1166                 }
1167
1168                 tfp->ob_scale[0]= ob->size[0];
1169                 tfp->ob_scale[1]= ob->size[1];
1170                 tfp->ob_scale[2]= ob->size[2];
1171
1172                 uiDefBut(block, LABEL, 0, "Scale:",                                                                                     0, 140, 100, 20, 0, 0, 0, 0, 0, "");
1173                 uiDefButS(block, OPTION, B_REDR, "Link",                                                                        60, 140, 50, 19, &(tfp->link_scale), 0, 1, 0, 0, "Scale values vary proportionally in all directions");
1174                 uiBlockBeginAlign(block);
1175                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "X:",                                                         0, 120, 120, 19, &(tfp->ob_scale[0]), -lim, lim, 10, 3, "");
1176                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "Y:",                                                         0, 100, 120, 19, &(tfp->ob_scale[1]), -lim, lim, 10, 3, "");
1177                 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "Z:",                                                         0, 80, 120, 19, &(tfp->ob_scale[2]), -lim, lim, 10, 3, "");
1178                 uiBlockEndAlign(block);
1179                 
1180                 uiBlockBeginAlign(block);
1181                 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");
1182                 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");
1183                 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");
1184                 
1185                 
1186
1187                 bb= object_get_boundbox(ob);
1188                 if (bb) {
1189                         float scale[3];
1190
1191                         Mat4ToSize(ob->obmat, scale);
1192
1193                         tfp->ob_dims[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
1194                         tfp->ob_dims[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
1195                         tfp->ob_dims[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
1196
1197                         
1198                         if ((ob->parent) && (ob->partype == PARBONE)) {
1199                                 uiDefBut(block, LABEL, 0, "Dimensions:",                        0, 60, 100, 20, 0, 0, 0, 0, 0, "");
1200                                 uiBlockBeginAlign(block);
1201                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "X:",          0, 40, 150, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate X bounding box size");
1202                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Y:",          0, 20, 150, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate Y bounding box size");
1203                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Z:",          0, 0, 150, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate Z bounding box size");
1204
1205                         }
1206                         else {
1207                                 uiDefBut(block, LABEL, 0, "Dimensions:",                        0, 60, 100, 20, 0, 0, 0, 0, 0, "");
1208                                 uiBlockBeginAlign(block);
1209                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "X:",          0, 40, 150, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate X bounding box size");
1210                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Y:",          0, 20, 150, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate Y bounding box size");
1211                                 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "Z:",          0, 0, 150, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate Z bounding box size");
1212                         }
1213
1214                         uiBlockEndAlign(block);
1215                 }
1216         }
1217 }
1218
1219 #if 0
1220 static void view3d_panel_preview(bContext *C, ARegion *ar, short cntrl) // VIEW3D_HANDLER_PREVIEW
1221 {
1222         uiBlock *block;
1223         View3D *v3d= sa->spacedata.first;
1224         int ofsx, ofsy;
1225         
1226         block= uiBeginBlock(C, ar, "view3d_panel_preview", UI_EMBOSS);
1227         uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
1228         uiSetPanelHandler(VIEW3D_HANDLER_PREVIEW);  // for close and esc
1229         
1230         ofsx= -150+(sa->winx/2)/v3d->blockscale;
1231         ofsy= -100+(sa->winy/2)/v3d->blockscale;
1232         if(uiNewPanel(C, ar, block, "Preview", "View3d", ofsx, ofsy, 300, 200)==0) return;
1233
1234         uiBlockSetDrawExtraFunc(block, BIF_view3d_previewdraw);
1235         
1236         if(scene->recalc & SCE_PRV_CHANGED) {
1237                 scene->recalc &= ~SCE_PRV_CHANGED;
1238                 //printf("found recalc\n");
1239                 BIF_view3d_previewrender_free(sa->spacedata.first);
1240                 BIF_preview_changed(0);
1241         }
1242 }
1243 #endif
1244
1245 static void delete_sketch_armature(bContext *C, void *arg1, void *arg2)
1246 {
1247         BIF_deleteSketch(C);
1248 }
1249
1250 static void convert_sketch_armature(bContext *C, void *arg1, void *arg2)
1251 {
1252         BIF_convertSketch(C);
1253 }
1254
1255 static void assign_template_sketch_armature(bContext *C, void *arg1, void *arg2)
1256 {
1257         int index = *(int*)arg1;
1258         BIF_setTemplate(C, index);
1259 }
1260
1261 static int view3d_panel_bonesketch_spaces_poll(const bContext *C, PanelType *pt)
1262 {
1263         Object *obedit = CTX_data_edit_object(C);
1264
1265         /* replace with check call to sketching lib */
1266         return (obedit && obedit->type == OB_ARMATURE);
1267 }
1268 static void view3d_panel_bonesketch_spaces(const bContext *C, Panel *pa)
1269 {
1270         Scene *scene = CTX_data_scene(C);
1271         static int template_index;
1272         static char joint_label[128];
1273         uiBlock *block;
1274         uiBut *but;
1275         char *bone_name;
1276         int yco = 130;
1277         int nb_joints;
1278         static char subdiv_tooltip[4][64] = {
1279                 "Subdivide arcs based on a fixed number of bones",
1280                 "Subdivide arcs in bones of equal length",
1281                 "Subdivide arcs based on correlation",
1282                 "Retarget template to stroke"
1283                 };
1284
1285         
1286         block= uiLayoutFreeBlock(pa->layout);
1287         uiBlockSetHandleFunc(block, do_view3d_region_buttons, NULL);
1288
1289         uiBlockBeginAlign(block);
1290         
1291         /* use real flag instead of 1 */
1292         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)");
1293         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");
1294         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");
1295         yco -= 20;
1296         
1297         but = uiDefBut(block, BUT, B_REDR, "Convert", 10,yco,100,20, 0, 0, 0, 0, 0, "Convert sketch to armature");
1298         uiButSetFunc(but, convert_sketch_armature, NULL, NULL);
1299
1300         but = uiDefBut(block, BUT, B_REDR, "Delete", 110,yco,100,20, 0, 0, 0, 0, 0, "Delete sketch");
1301         uiButSetFunc(but, delete_sketch_armature, NULL, NULL);
1302         yco -= 20;
1303         
1304         uiBlockEndAlign(block);
1305
1306         uiBlockBeginAlign(block);
1307         
1308         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]);
1309
1310         switch(scene->toolsettings->bone_sketching_convert)
1311         {
1312         case SK_CONVERT_CUT_LENGTH:
1313                 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");
1314                 yco -= 20;
1315                 break;
1316         case SK_CONVERT_CUT_ADAPTATIVE:
1317                 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");
1318                 yco -= 20;
1319                 break;
1320         default:
1321         case SK_CONVERT_CUT_FIXED:
1322                 uiDefButC(block, NUM, B_REDR,                                   "Num:",         70, yco, 140, 19, &scene->toolsettings->skgen_subdivision_number,1, 100, 1, 5,  "Number of subdivided bones");
1323                 yco -= 20;
1324                 break;
1325         case SK_CONVERT_RETARGET:
1326                 uiDefButC(block, ROW, B_NOP, "No",                      70,  yco, 40,19, &scene->toolsettings->skgen_retarget_roll, 0, 0, 0, 0,                                                                 "No special roll treatment");
1327                 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");
1328                 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");
1329                 yco -= 30;
1330
1331                 uiBlockEndAlign(block);
1332
1333                 uiBlockBeginAlign(block);
1334                 /* button here to select what to do (copy or not), template, ...*/
1335
1336                 BIF_makeListTemplates(C);
1337                 template_index = BIF_currentTemplate(C);
1338                 
1339                 but = uiDefButI(block, MENU, B_REDR, BIF_listTemplates(C), 10,yco,200,19, &template_index, 0, 0, 0, 0, "Template");
1340                 uiButSetFunc(but, assign_template_sketch_armature, &template_index, NULL);
1341                 
1342                 yco -= 20;
1343                 
1344                 uiDefButF(block, NUM, B_NOP,                                                    "A:",                   10, yco, 66,19, &scene->toolsettings->skgen_retarget_angle_weight, 0, 10, 1, 0,         "Angle Weight");
1345                 uiDefButF(block, NUM, B_NOP,                                                    "L:",                   76, yco, 67,19, &scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0,                "Length Weight");
1346                 uiDefButF(block, NUM, B_NOP,                                                    "D:",           143,yco, 67,19, &scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0,              "Distance Weight");
1347                 yco -= 20;
1348                 
1349                 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");
1350                 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");
1351                 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");        
1352                 yco -= 20;
1353
1354                 /* auto renaming magic */
1355                 uiBlockEndAlign(block);
1356                 
1357                 nb_joints = BIF_nbJointsTemplate(C);
1358
1359                 if (nb_joints == -1)
1360                 {
1361                         //XXX
1362                         //nb_joints = G.totvertsel;
1363                 }
1364                 
1365                 bone_name = BIF_nameBoneTemplate(C);
1366                 
1367                 BLI_snprintf(joint_label, 32, "%i joints: %s", nb_joints, bone_name);
1368                 
1369                 uiDefBut(block, LABEL, 1, joint_label,                                  10, yco, 200, 20, NULL, 0.0, 0.0, 0, 0, "");
1370                 yco -= 20;
1371                 break;
1372         }
1373
1374         uiBlockEndAlign(block);
1375 }
1376
1377 #if 0 // XXX not used
1378
1379 /* op->invoke */
1380 static void redo_cb(bContext *C, void *arg_op, void *arg2)
1381 {
1382         wmOperator *lastop= arg_op;
1383         
1384         if(lastop) {
1385                 int retval;
1386                 
1387                 printf("operator redo %s\n", lastop->type->name);
1388                 ED_undo_pop(C);
1389                 retval= WM_operator_repeat(C, lastop);
1390                 if((retval & OPERATOR_FINISHED)==0) {
1391                         printf("operator redo failed %s\n", lastop->type->name);
1392                         ED_undo_redo(C);
1393                 }
1394         }
1395 }
1396
1397 static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
1398 {
1399         wmWindowManager *wm= CTX_wm_manager(C);
1400         wmOperator *op;
1401         PointerRNA ptr;
1402         uiBlock *block;
1403         
1404         block= uiLayoutGetBlock(pa->layout);
1405
1406         /* only for operators that are registered and did an undo push */
1407         for(op= wm->operators.last; op; op= op->prev)
1408                 if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO))
1409                         break;
1410         
1411         if(op==NULL)
1412                 return;
1413         
1414         uiBlockSetFunc(block, redo_cb, op, NULL);
1415         
1416         if(!op->properties) {
1417                 IDPropertyTemplate val = {0};
1418                 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
1419         }
1420         
1421         RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
1422         uiDefAutoButsRNA(C, pa->layout, &ptr, 2);
1423 }
1424 #endif // XXX not used
1425
1426 void view3d_buttons_register(ARegionType *art)
1427 {
1428         PanelType *pt;
1429
1430         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel object");
1431         strcpy(pt->idname, "VIEW3D_PT_object");
1432         strcpy(pt->label, "Transform");
1433         pt->draw= view3d_panel_object;
1434         BLI_addtail(&art->paneltypes, pt);
1435         
1436         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel gpencil");
1437         strcpy(pt->idname, "VIEW3D_PT_gpencil");
1438         strcpy(pt->label, "Grease Pencil");
1439         pt->draw= gpencil_panel_standard;
1440         BLI_addtail(&art->paneltypes, pt);
1441 /*
1442         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel properties");
1443         strcpy(pt->idname, "VIEW3D_PT_properties");
1444         strcpy(pt->label, "View Properties");
1445         pt->draw= view3d_panel_properties;
1446         BLI_addtail(&art->paneltypes, pt);
1447
1448         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel transform spaces");
1449         strcpy(pt->idname, "VIEW3D_PT_transform spaces");
1450         strcpy(pt->label, "Transform Orientations");
1451         pt->draw= view3d_panel_transform_spaces;
1452         BLI_addtail(&art->paneltypes, pt);
1453
1454         pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel bonesketch spaces");
1455         strcpy(pt->idname, "VIEW3D_PT_bonesketch_spaces");
1456         strcpy(pt->label, "Bone Sketching");
1457         pt->draw= view3d_panel_bonesketch_spaces;
1458         pt->poll= view3d_panel_bonesketch_spaces_poll;
1459         BLI_addtail(&art->paneltypes, pt);
1460 */
1461         // XXX view3d_panel_preview(C, ar, 0);
1462 }
1463
1464 static int view3d_properties(bContext *C, wmOperator *op)
1465 {
1466         ScrArea *sa= CTX_wm_area(C);
1467         ARegion *ar= view3d_has_buttons_region(sa);
1468         
1469         if(ar)
1470                 ED_region_toggle_hidden(C, ar);
1471
1472         return OPERATOR_FINISHED;
1473 }
1474
1475 void VIEW3D_OT_properties(wmOperatorType *ot)
1476 {
1477         ot->name= "Properties";
1478         ot->description= "Toggles the properties panel display.";
1479         ot->idname= "VIEW3D_OT_properties";
1480         
1481         ot->exec= view3d_properties;
1482         ot->poll= ED_operator_view3d_active;
1483         
1484         /* flags */
1485         ot->flag= 0;
1486 }