Added LSCM UV Unwrapping:
[blender.git] / source / blender / src / buttons_editing.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #ifdef WIN32
43 #include "BLI_winstuff.h"
44 #ifndef snprintf
45 #define snprintf _snprintf
46 #endif
47 #endif
48
49 #include "MEM_guardedalloc.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_space_types.h"
52 #include "DNA_scene_types.h"
53
54 #include "DNA_action_types.h"
55 #include "DNA_armature_types.h"
56 #include "DNA_camera_types.h"
57 #include "DNA_constraint_types.h"
58 #include "DNA_curve_types.h"
59 #include "DNA_effect_types.h"
60 #include "DNA_group_types.h"
61 #include "DNA_ika_types.h"
62 #include "DNA_image_types.h"
63 #include "DNA_key_types.h"
64 #include "DNA_lamp_types.h"
65 #include "DNA_lattice_types.h"
66 #include "DNA_material_types.h"
67 #include "DNA_meta_types.h"
68 #include "DNA_mesh_types.h"
69 #include "DNA_meshdata_types.h"
70 #include "DNA_object_types.h"
71 #include "DNA_radio_types.h"
72 #include "DNA_screen_types.h"
73 #include "DNA_sound_types.h"
74 #include "DNA_texture_types.h"
75 #include "DNA_userdef_types.h"
76 #include "DNA_vfont_types.h"
77 #include "DNA_view3d_types.h"
78 #include "DNA_world_types.h"
79 #include "DNA_packedFile_types.h"
80
81 #include "BKE_global.h"
82 #include "BKE_main.h"
83 #include "BKE_library.h"
84 #include "BKE_packedFile.h"
85
86 #include "BLI_blenlib.h"
87 #include "BLI_arithb.h"
88 #include "BLI_vfontdata.h"
89 #include "BLI_editVert.h"
90
91 #include "BSE_filesel.h"
92
93 #include "BIF_gl.h"
94 #include "BIF_editarmature.h"
95 #include "BIF_editconstraint.h"
96 #include "BIF_editdeform.h"
97 #include "BIF_editfont.h"
98 #include "BIF_editmesh.h"
99 #include "BIF_editsound.h"
100 #include "BIF_interface.h"
101 #include "BIF_mywindow.h"
102 #include "BIF_renderwin.h"
103 #include "BIF_resources.h"
104 #include "BIF_screen.h"
105 #include "BIF_scrarea.h"
106 #include "BIF_space.h"
107 #include "BIF_toets.h"
108 #include "BIF_toolbox.h"
109 #include "BIF_previewrender.h"
110 #include "BIF_butspace.h"
111
112 #include "mydevice.h"
113 #include "blendef.h"
114
115 #include "BKE_action.h"
116 #include "BKE_anim.h"
117 #include "BKE_armature.h"
118 #include "BKE_constraint.h"
119 #include "BKE_curve.h"
120 #include "BKE_displist.h"
121 #include "BKE_effect.h"
122 #include "BKE_font.h"
123 #include "BKE_ika.h"
124 #include "BKE_image.h"
125 #include "BKE_ipo.h"
126 #include "BKE_lattice.h"
127 #include "BKE_material.h"
128 #include "BKE_mball.h"
129 #include "BKE_mesh.h"
130 #include "BKE_object.h"
131 #include "BKE_sound.h"
132 #include "BKE_texture.h"
133 #include "BKE_utildefines.h"
134
135 #include "BDR_drawobject.h"
136 #include "BDR_editcurve.h"
137 #include "BDR_editface.h"
138 #include "BDR_editobject.h"
139 #include "BDR_vpaint.h"
140 #include "BDR_unwrapper.h"
141
142 #include "BSE_drawview.h"
143 #include "BSE_editipo.h"
144 #include "BSE_edit.h"
145 #include "BSE_filesel.h"
146 #include "BSE_headerbuttons.h"
147 #include "BSE_trans_types.h"
148 #include "BSE_view.h"
149 #include "BSE_buttons.h"
150 #include "BSE_seqaudio.h"
151
152 #include "LOD_DependKludge.h"
153 #include "LOD_decimation.h"
154
155 #include "butspace.h" // own module
156
157 static int decim_faces=0;
158 static short degr= 90, step= 9, turn= 1;
159 static float extr_offs= 1.0;
160 static float editbutweight=1.0;
161 short editbutflag= 1;
162 float doublimit= 0.001, editbutvweight=1, editbutsize=0.1;
163 float uv_calc_radius= 1.0, uv_calc_cubesize= 1.0;
164 short uv_calc_mapdir= 1, uv_calc_mapalign= 1, facesel_draw_edges= 0;
165
166 extern ListBase editNurb;
167
168 /* *************************** MESH DECIMATE ******************************** */
169
170 /* should be removed from this c file (ton) */
171
172 static int decimate_count_tria(Object *ob)
173 {
174         int tottria;
175         MFace *mface;
176         Mesh *me;
177         int a;
178
179         me= ob->data;
180
181         /* count number of trias, since decimator doesnt allow quads */
182         tottria= 0;
183         mface= me->mface;
184         for(a=0; a<me->totface; a++, mface++) {
185                 if(mface->v4) tottria++;
186                 if(mface->v3) tottria++;
187         }
188
189         return tottria;
190 }
191
192 static void decimate_faces(void)
193 {
194         Object *ob;
195         Mesh *me;
196         MVert *mvert;
197         MFace *mface;
198         LOD_Decimation_Info lod;
199         float *vb=NULL;
200         float *vnb=NULL;
201         int *tib=NULL;
202         int a, tottria;
203
204         /* we assume the active object being decimated */
205         ob= OBACT;
206         if(ob==NULL || ob->type!=OB_MESH) return;
207         me= ob->data;
208
209         /* add warning for vertex col and tfaces */
210         if(me->tface || me->mcol || me->dvert) {
211                 if(okee("This will remove UV coordinates, vertexcolors, and deform weights")==0) return;
212                 if(me->tface) MEM_freeN(me->tface);
213                 if(me->mcol) MEM_freeN(me->mcol);
214                 if(me->dvert) free_dverts(me->dvert, me->totvert);
215                 me->tface= NULL;
216                 me->mcol= NULL;
217                 me->dvert= NULL;
218         }
219
220         /* count number of trias, since decimator doesnt allow quads */
221         tottria= decimate_count_tria(ob);
222
223         if(tottria<3) {
224                 error("You must have more than 3 input faces selected.");
225                 return;
226         }
227         /* allocate and init */
228         lod.vertex_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "vertices");
229         lod.vertex_normal_buffer= MEM_mallocN(3*sizeof(float)*me->totvert, "normals");
230         lod.triangle_index_buffer= MEM_mallocN(3*sizeof(int)*tottria, "trias");
231         lod.vertex_num= me->totvert;
232         lod.face_num= tottria;
233
234         /* fill vertex buffer */
235         vb= lod.vertex_buffer;
236         vnb= lod.vertex_normal_buffer;
237         mvert= me->mvert;
238         for(a=0; a<me->totvert; a++, mvert++, vb+=3, vnb+=3) {
239                 VECCOPY(vb, mvert->co);
240                 VECCOPY(vnb, mvert->no);
241                 Normalise(vnb);
242         }
243
244         /* fill index buffer */
245         mface= me->mface;
246         tib= lod.triangle_index_buffer;
247         for(a=0; a<me->totface; a++, mface++) {
248                 if(mface->v4) {
249                         tib[0]= mface->v1;
250                         tib[1]= mface->v3;
251                         tib[2]= mface->v4;
252                         tib+= 3;
253                 }
254                 if(mface->v3) {
255                         tib[0]= mface->v1;
256                         tib[1]= mface->v2;
257                         tib[2]= mface->v3;
258                         tib+= 3;
259                 }
260         }
261
262         if(LOD_LoadMesh(&lod) ) {
263                 if( LOD_PreprocessMesh(&lod) ) {
264                         DispList *dl;
265                         DispListMesh *dlm;
266                         MFace *mfaceint;
267
268                         /* we assume the decim_faces tells how much to reduce */
269
270                         while(lod.face_num > decim_faces) {
271                                 if( LOD_CollapseEdge(&lod)==0) break;
272                         }
273
274                         /* ok, put back the stuff in a displist */
275                         freedisplist(&(ob->disp));
276                         dl= MEM_callocN(sizeof(DispList), "disp");
277                         BLI_addtail(&ob->disp, dl);
278                         dl->type= DL_MESH;
279                         dlm=dl->mesh= MEM_callocN(sizeof(DispListMesh), "dispmesh");
280                         dlm->mvert= MEM_callocN(lod.vertex_num*sizeof(MVert), "mvert");
281                         dlm->mface= MEM_callocN(lod.face_num*sizeof(MFace), "mface");
282                         dlm->totvert= lod.vertex_num;
283                         dlm->totface= lod.face_num;
284
285                         mvert= dlm->mvert;
286                         vb= lod.vertex_buffer;
287                         for(a=0; a<lod.vertex_num; a++, vb+=3, mvert++) {
288                                 VECCOPY(mvert->co, vb);
289                         }
290
291                         mfaceint= dlm->mface;
292                         tib= lod.triangle_index_buffer;
293                         for(a=0; a<lod.face_num; a++, mfaceint++, tib+=3) {
294                                 mfaceint->v1= tib[0];
295                                 mfaceint->v2= tib[1];
296                                 mfaceint->v3= tib[2];
297                         }
298                 }
299                 else error("No memory");
300
301                 LOD_FreeDecimationData(&lod);
302         }
303         else error("No manifold Mesh");
304
305         MEM_freeN(lod.vertex_buffer);
306         MEM_freeN(lod.vertex_normal_buffer);
307         MEM_freeN(lod.triangle_index_buffer);
308
309         allqueue(REDRAWVIEW3D, 0);
310 }
311
312
313
314 static void decimate_cancel(void)
315 {
316         Object *ob;
317
318         ob= OBACT;
319         if(ob) {
320                 freedisplist(&ob->disp);
321                 makeDispList(ob);
322         }
323         allqueue(REDRAWVIEW3D, 0);
324 }
325
326 static void decimate_apply(void)
327 {
328         Object *ob;
329         DispList *dl;
330         DispListMesh *dlm;
331         Mesh *me;
332         MFace *mface;
333         MFace *mfaceint;
334         int a;
335
336         if(G.obedit) return;
337
338         ob= OBACT;
339         if(ob) {
340                 dl= ob->disp.first;
341                 if(dl && dl->mesh) {
342                         dlm= dl->mesh;
343                         me= ob->data;
344
345                         // vertices
346                         if(me->mvert) MEM_freeN(me->mvert);
347                         me->mvert= dlm->mvert;
348                         dlm->mvert= NULL;
349                         me->totvert= dlm->totvert;
350
351                         // faces
352                         if(me->mface) MEM_freeN(me->mface);
353                         me->mface= MEM_callocN(dlm->totface*sizeof(MFace), "mface");
354                         me->totface= dlm->totface;
355                         mface= me->mface;
356                         mfaceint= dlm->mface;
357                         for(a=0; a<me->totface; a++, mface++, mfaceint++) {
358                                 mface->v1= mfaceint->v1;
359                                 mface->v2= mfaceint->v2;
360                                 mface->v3= mfaceint->v3;
361                                 test_index_mface(mface, 3);
362                         }
363
364                         freedisplist(&ob->disp);
365
366                         G.obedit= ob;
367                         make_editMesh();
368                         load_editMesh();
369                         free_editMesh();
370                         G.obedit= NULL;
371                         tex_space_mesh(me);
372
373                         if (mesh_uses_displist(me)) {
374                                 makeDispList(ob);
375                         }
376                 }
377                 else error("Not a decimated Mesh");
378         }
379 }
380
381 /* *************** */
382
383 void do_common_editbuts(unsigned short event) // old name, is a mix of object and editing events.... 
384 {
385         EditMesh *em = G.editMesh;
386         EditVlak *evl;
387         Base *base;
388         Object *ob;
389         Mesh *me;
390         Nurb *nu;
391         Curve *cu;
392         BezTriple *bezt;
393         BPoint *bp;
394         unsigned int local;
395         int a, bit, index= -1;
396
397         switch(event) {
398                 
399         case B_MATWICH:
400                 if(G.obedit && G.obedit->actcol>0) {
401                         if(G.obedit->type == OB_MESH) {
402                                 evl= em->faces.first;
403                                 while(evl) {
404                                         if( vlakselectedAND(evl, 1) ) {
405                                                 if(index== -1) index= evl->mat_nr;
406                                                 else if(index!=evl->mat_nr) {
407                                                         error("Mixed colors");
408                                                         return;
409                                                 }
410                                         }
411                                         evl= evl->next;
412                                 }
413                         }
414                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
415                                 nu= editNurb.first;
416                                 while(nu) {
417                                         if( isNurbsel(nu) ) {
418                                                 if(index== -1) index= nu->mat_nr;
419                                                 else if(index!=nu->mat_nr) {
420                                                         error("Mixed colors");
421                                                         return;
422                                                 }
423                                         }
424                                         nu= nu->next;
425                                 }                               
426                         }
427                         if(index>=0) {
428                                 G.obedit->actcol= index+1;
429                                 scrarea_queue_winredraw(curarea);
430                         }
431                 }
432                 break;
433         case B_MATNEW:
434                 new_material_to_objectdata((G.scene->basact) ? (G.scene->basact->object) : 0);
435                 scrarea_queue_winredraw(curarea);
436                 allqueue(REDRAWVIEW3D_Z, 0);
437                 break;
438         case B_MATDEL:
439                 delete_material_index();
440                 scrarea_queue_winredraw(curarea);
441                 allqueue(REDRAWVIEW3D_Z, 0);
442                 break;
443         case B_MATASS:
444                 if(G.obedit && G.obedit->actcol>0) {
445                         if(G.obedit->type == OB_MESH) {
446                                 undo_push_mesh("Assign material index");
447                                 evl= em->faces.first;
448                                 while(evl) {
449                                         if( vlakselectedAND(evl, 1) )
450                                                 evl->mat_nr= G.obedit->actcol-1;
451                                         evl= evl->next;
452                                 }
453                                 allqueue(REDRAWVIEW3D_Z, 0);
454                                 makeDispList(G.obedit);
455                         }
456                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
457                                 nu= editNurb.first;
458                                 while(nu) {
459                                         if( isNurbsel(nu) )
460                                                 nu->mat_nr= G.obedit->actcol-1;
461                                         nu= nu->next;
462                                 }
463                         }
464                 }
465                 break;
466         case B_MATSEL:
467         case B_MATDESEL:
468                 if(G.obedit) {
469                         if(G.obedit->type == OB_MESH) {
470                                 if (event==B_MATSEL) {
471                                         editmesh_select_by_material(G.obedit->actcol-1);
472                                 } else {
473                                         editmesh_deselect_by_material(G.obedit->actcol-1);
474                                 }
475                                 allqueue(REDRAWVIEW3D, 0);
476                         }
477                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
478                                 nu= editNurb.first;
479                                 while(nu) {
480                                         if(nu->mat_nr==G.obedit->actcol-1) {
481                                                 if(nu->bezt) {
482                                                         a= nu->pntsu;
483                                                         bezt= nu->bezt;
484                                                         while(a--) {
485                                                                 if(bezt->hide==0) {
486                                                                         if(event==B_MATSEL) {
487                                                                                 bezt->f1 |= 1;
488                                                                                 bezt->f2 |= 1;
489                                                                                 bezt->f3 |= 1;
490                                                                         }
491                                                                         else {
492                                                                                 bezt->f1 &= ~1;
493                                                                                 bezt->f2 &= ~1;
494                                                                                 bezt->f3 &= ~1;
495                                                                         }
496                                                                 }
497                                                                 bezt++;
498                                                         }
499                                                 }
500                                                 else if(nu->bp) {
501                                                         a= nu->pntsu*nu->pntsv;
502                                                         bp= nu->bp;
503                                                         while(a--) {
504                                                                 if(bp->hide==0) {
505                                                                         if(event==B_MATSEL) bp->f1 |= 1;
506                                                                         else bp->f1 &= ~1;
507                                                                 }
508                                                                 bp++;
509                                                         }
510                                                 }
511                                         }
512                                         nu= nu->next;
513                                 }
514                                 allqueue(REDRAWVIEW3D, 0);
515                         }
516                 }
517                 break;
518         case B_HIDE:
519                 if(G.obedit) {
520                         if(G.obedit->type == OB_MESH) hide_mesh(0);
521                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) hideNurb(0);
522                 }
523                 break;
524         case B_REVEAL:
525                 if(G.obedit) {
526                         if(G.obedit->type == OB_MESH) reveal_mesh();
527                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) revealNurb();
528                 }
529                 else if(G.f & G_FACESELECT) reveal_tface();
530                 
531                 break;
532         case B_SELSWAP:
533                 if(G.obedit) {
534                         if(G.obedit->type == OB_MESH) selectswap_mesh();
535                         else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) selectswapNurb();
536                 }
537                 break;
538         case B_AUTOTEX:
539                 ob= OBACT;
540                 if(ob && G.obedit==0) {
541                         if(ob->type==OB_MESH) tex_space_mesh(ob->data);
542                         else if(ob->type==OB_MBALL) ;
543                         else tex_space_curve(ob->data);
544                 }
545                 break;
546         case B_DOCENTRE:
547                 docentre();
548                 break;
549         case B_DOCENTRENEW:
550                 docentre_new();
551                 break;
552         case B_DOCENTRECURSOR:
553                 docentre_cursor();
554                 break;
555         case B_SETSMOOTH:
556         case B_SETSOLID:
557                 if(G.obedit) {
558                         if(G.obedit->type == OB_MESH) {
559                                 evl= em->faces.first;
560                                 if (event == B_SETSMOOTH) undo_push_mesh("Set Smooth");
561                                 else if (event==B_SETSOLID) undo_push_mesh("Set Solid");
562                                 while(evl) {
563                                         if( vlakselectedAND(evl, 1) ) {
564                                                 if(event==B_SETSMOOTH) evl->flag |= ME_SMOOTH;
565                                                 else evl->flag &= ~ME_SMOOTH;
566                                         }
567                                         evl= evl->next;
568                                 }
569
570                                 makeDispList(G.obedit);
571                                 allqueue(REDRAWVIEW3D, 0);
572                         }
573                         else {
574                                 nu= editNurb.first;
575                                 while(nu) {
576                                         if(isNurbsel(nu)) {
577                                                 if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
578                                                 else nu->flag &= ~ME_SMOOTH;
579                                         }
580                                         nu= nu->next;
581                                 }
582                                 
583                         }
584                 }
585                 else {
586                         base= FIRSTBASE;
587                         while(base) {
588                                 if(TESTBASELIB(base)) {
589                                         if(base->object->type==OB_MESH) {
590                                                 me= base->object->data;
591                                                 mesh_set_smooth_flag(me, (event==B_SETSMOOTH));
592                                                 makeDispList(base->object);
593                                         }
594                                         else if ELEM(base->object->type, OB_SURF, OB_CURVE) {
595                                                 cu= base->object->data;
596                                                 nu= cu->nurb.first;
597                                                 while(nu) {
598                                                         if(event==B_SETSMOOTH) nu->flag |= ME_SMOOTH;
599                                                         else nu->flag &= ~ME_SMOOTH;
600                                                         nu= nu->next;
601                                                 }
602                                         }
603                                 }
604                                 base= base->next;
605                         }
606                         allqueue(REDRAWVIEW3D, 0);
607                 }
608                 break;
609
610         default:
611                 if(event>=B_OBLAY && event<=B_OBLAY+31) {
612                         local= BASACT->lay & 0xFF000000;
613                         BASACT->lay -= local;
614                         if(BASACT->lay==0 || (G.qual & LR_SHIFTKEY)==0) {
615                                 bit= event-B_OBLAY;
616                                 BASACT->lay= 1<<bit;
617                                 scrarea_queue_winredraw(curarea);
618                         }
619                         BASACT->lay += local;
620                         /* optimal redraw */
621                         if( (OBACT->lay & G.vd->lay) && (BASACT->lay & G.vd->lay) );
622                         else if( (OBACT->lay & G.vd->lay)==0 && (BASACT->lay & G.vd->lay)==0 );
623                         else allqueue(REDRAWVIEW3D, 0);
624                         
625                         OBACT->lay= BASACT->lay;
626                 }
627         }
628
629 }
630
631 /* *************************** MESH  ******************************** */
632
633
634 static void editing_panel_mesh_type(Object *ob, Mesh *me)
635 {
636         uiBlock *block;
637         float val;
638         /* Hope to support more than two subsurf algorithms */
639         char subsurfmenu[]="Subsurf Type%t|Catmull-Clark%x0|Simple Subdiv.%x1";
640
641         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_type", UI_EMBOSS, UI_HELV, curarea->win);
642         if( uiNewPanel(curarea, block, "Mesh", "Editing", 320, 0, 318, 204)==0) return;
643
644         uiBlockBeginAlign(block);
645         uiDefButS(block, TOG|BIT|5, REDRAWVIEW3D, "Auto Smooth",10,180,154,19, &me->flag, 0, 0, 0, 0, "Treats all faces with angles less than Degr: as 'smooth' during render");
646         uiDefButS(block, NUM, B_DIFF, "Degr:",                          10,160,154,19, &me->smoothresh, 1, 80, 0, 0, "Defines maximum angle between face normals that 'Auto Smooth' will operate on");
647
648         uiBlockBeginAlign(block);
649         uiBlockSetCol(block, TH_BUT_SETTING1);
650         uiDefButS(block, TOG|BIT|7, B_MAKEDISP, "SubSurf",      10,134,70,19, &me->flag, 0, 0, 0, 0, "Treats the active object as a Subdivision Surface");
651         uiDefButS(block, MENU, B_MAKEDISP, subsurfmenu,         80,134,84,19, &(me->subsurftype), 0, 0, 0, 0, "Selects type of Subsurf algorithm.");
652         uiBlockSetCol(block, TH_AUTO);
653         uiDefButS(block, NUM, B_MAKEDISP, "Subdiv:",            10, 114,110,19, &me->subdiv, 0, 6, 0, 0, "Defines the level of subdivision to display in real time interactively");
654         uiDefButS(block, NUM, B_DIFF, "",                               120,114, 44, 19, &me->subdivr, 0, 6, 0, 0, "Defines the level of subdivision to apply during rendering");
655         uiDefButS(block, TOG|BIT|8, B_MAKEDISP, "Optimal",      10, 94,154,19, &me->flag, 0, 0, 0, 0, "Only draws optimal wireframe");
656
657         uiBlockBeginAlign(block);
658
659         if(me->medge) val= 1.0; else val= 0.0;
660         uiDefBut(block, LABEL, 0, "Edges",                                      10,70,70,20, 0, val, 0, 0, 0, "");
661         if(me->medge==NULL) {
662                 uiDefBut(block, BUT, B_MAKEEDGES, "Make",               80,70,84,19, 0, 0, 0, 0, 0, "Adds edges data to active Mesh object, enables creases/seams and faster wireframe draw");
663         }
664         else uiDefBut(block, BUT, B_DELEDGES, "Delete",         80,70,84,19, 0, 0, 0, 0, 0, "Deletes edges data from active Mesh object");
665
666         if(me->mcol) val= 1.0; else val= 0.0;
667         uiDefBut(block, LABEL, 0, "VertCol",                            10,50,70,20, 0, val, 0, 0, 0, "");
668         if(me->mcol==NULL) {
669                 uiDefBut(block, BUT, B_MAKEVERTCOL, "Make",             80,50,84,19, 0, 0, 0, 0, 0, "Enables vertex colour painting on active object");
670         }
671         else uiDefBut(block, BUT, B_DELVERTCOL, "Delete",       80,50,84,19, 0, 0, 0, 0, 0, "Deletes vertex colours on active object");
672
673         if(me->tface) val= 1.0; else val= 0.0;
674         uiDefBut(block, LABEL, 0, "TexFace",                            10,30,70,20, 0, val, 0, 0, 0, "");
675         if(me->tface==NULL) {
676                 uiDefBut(block, BUT, B_MAKE_TFACES, "Make",             80,30,84,19, 0, 0, 0, 0, 0, "Enables the active object's faces for UV coordinate mapping");
677         }
678         else uiDefBut(block, BUT, B_DEL_TFACES, "Delete",       80,30,84,19, 0, 0, 0, 0, 0, "Deletes UV coordinates for active object's faces");
679         uiBlockEndAlign(block);
680
681         if(me->msticky) val= 1.0; else val= 0.0;
682         uiDefBut(block, LABEL, 0, "Sticky",                             10,10,70,20, 0, val, 0, 0, 0, "");
683         if(me->msticky==NULL) {
684                 uiDefBut(block, BUT, B_MAKESTICKY, "Make",              80,10,84,19, 0, 0, 0, 0, 0, "Creates Sticky coordinates for the active object from the current camera view background picture");
685         }
686         else uiDefBut(block, BUT, B_DELSTICKY, "Delete",        80,10,84,19, 0, 0, 0, 0, 0, "Deletes Sticky texture coordinates");
687
688
689         /* decimator */
690         if(G.obedit==NULL) {
691                 int tottria= decimate_count_tria(ob);
692                 DispList *dl;
693
694                 // wacko, wait for new displist system (ton)
695                 if( (dl=ob->disp.first) && dl->mesh);
696                 else decim_faces= tottria;
697
698                 uiBlockBeginAlign(block);
699                 uiBlockSetCol(block, TH_BUT_SETTING1);
700                 uiDefButI(block, NUM,B_DECIM_FACES, "Decimator:",       175,180,230,19, &decim_faces, 4.0, tottria, 10, 10, "Defines the number of triangular faces to decimate the active Mesh object to");
701                 uiBlockSetCol(block, TH_AUTO);
702                 uiDefBut(block, BUT,B_DECIM_APPLY, "Apply",             175,160,110,19, 0, 0, 0, 0, 0, "Applies the decimation to the active Mesh object");
703                 uiDefBut(block, BUT,B_DECIM_CANCEL, "Cancel",   285,160,120,19, 0, 0, 0, 0, 0, "Restores the Mesh to its original number of faces");
704                 uiBlockEndAlign(block);
705         }
706
707
708         uiDefIDPoinBut(block, test_meshpoin_but, 0, "TexMesh: ",        175,124,230,19, &me->texcomesh, "Enter the name of a Meshblock");
709
710         if(me->key) {
711                 uiBlockBeginAlign(block);
712                 uiDefButS(block, NUM, B_DIFF, "Slurph:",                                175,95,95,19, &(me->key->slurph), -500.0, 500.0, 0, 0, "");
713                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",                175,75,95,19, &me->key->type, 0, 0, 0, 0, "");
714         }
715
716         uiBlockBeginAlign(block);
717         uiDefBut(block, BUT, B_SLOWERDRAW,"SlowerDraw",                 175,30,95,19, 0, 0, 0, 0, 0, "Displays the active object with all possible edges shown");
718         uiDefBut(block, BUT, B_FASTERDRAW,"FasterDraw",                 175,10,95,19, 0, 0, 0, 0, 0, "Displays the active object faster by omitting some edges when drawing");
719
720         uiBlockBeginAlign(block);
721         uiDefBut(block, BUT,B_DOCENTRE, "Centre",                                       275, 95, 130, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
722         uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        275, 75, 130, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
723         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          275, 55, 130, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
724
725         uiBlockBeginAlign(block);
726         uiDefButS(block, TOG|BIT|2, REDRAWVIEW3D, "Double Sided",       275,30,130,19, &me->flag, 0, 0, 0, 0, "Toggles selected faces as doublesided or single-sided");
727         uiDefButS(block, TOG|BIT|1, REDRAWVIEW3D, "No V.Normal Flip",275,10,130,19, &me->flag, 0, 0, 0, 0, "Disables flipping of vertexnormals during render");
728         uiBlockEndAlign(block);
729
730 }
731
732
733
734 /* *************************** FONT ******************************** */
735
736 static short give_vfontnr(VFont *vfont)
737 {
738         VFont *vf;
739         short nr= 1;
740
741         vf= G.main->vfont.first;
742         while(vf) {
743                 if(vf==vfont) return nr;
744                 nr++;
745                 vf= vf->id.next;
746         }
747         return -1;
748 }
749
750 static VFont *give_vfontpointer(int nr) /* nr= button */
751 {
752         VFont *vf;
753         short tel= 1;
754
755         vf= G.main->vfont.first;
756         while(vf) {
757                 if(tel==nr) return vf;
758                 tel++;
759                 vf= vf->id.next;
760         }
761         return G.main->vfont.first;
762 }
763
764 static VFont *exist_vfont(char *str)
765 {
766         VFont *vf;
767
768         vf= G.main->vfont.first;
769         while(vf) {
770                 if(strcmp(vf->name, str)==0) return vf;
771                 vf= vf->id.next;
772         }
773         return 0;
774 }
775
776 static char *give_vfontbutstr(void)
777 {
778         VFont *vf;
779         int len= 0;
780         char *str, di[FILE_MAXDIR], fi[FILE_MAXFILE];
781
782         vf= G.main->vfont.first;
783         while(vf) {
784                 strcpy(di, vf->name);
785                 BLI_splitdirstring(di, fi);
786                 len+= strlen(fi)+4;
787                 vf= vf->id.next;
788         }
789
790         str= MEM_callocN(len+21, "vfontbutstr");
791         strcpy(str, "FONTS %t");
792         vf= G.main->vfont.first;
793         while(vf) {
794
795                 if(vf->id.us==0) strcat(str, "|0 ");
796                 else strcat(str, "|   ");
797
798                 strcpy(di, vf->name);
799                 BLI_splitdirstring(di, fi);
800
801                 strcat(str, fi);
802                 vf= vf->id.next;
803         }
804         return str;
805 }
806
807 static void load_buts_vfont(char *name)
808 {
809         VFont *vf;
810         Curve *cu;
811
812         if(OBACT && OBACT->type==OB_FONT) cu= OBACT->data;
813         else return;
814
815         vf= exist_vfont(name);
816         if(vf==0) {
817                 vf= load_vfont(name);
818                 if(vf==0) return;
819         }
820         else id_us_plus((ID *)vf);
821
822         if(cu->vfont) cu->vfont->id.us--;
823         cu->vfont= vf;
824
825         text_to_curve(OBACT, 0);
826         makeDispList(OBACT);
827         allqueue(REDRAWVIEW3D, 0);
828         allqueue(REDRAWBUTSEDIT, 0);
829 }
830
831 void do_fontbuts(unsigned short event)
832 {
833         Curve *cu;
834         VFont *vf;
835         Object *ob;
836         ScrArea *sa;
837         char str[80];
838
839         ob= OBACT;
840
841         switch(event) {
842         case B_MAKEFONT:
843                 text_to_curve(ob, 0);
844                 makeDispList(ob);
845                 allqueue(REDRAWVIEW3D, 0);
846                 break;
847         case B_TOUPPER:
848                 to_upper();
849                 break;
850         case B_LOADFONT:
851                 vf= give_vfontpointer(G.buts->texnr);
852                 if(vf && vf->id.prev!=vf->id.next) strcpy(str, vf->name);
853                 else strcpy(str, U.fontdir);
854
855                 sa= closest_bigger_area();
856                 areawinset(sa->win);
857
858                 activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
859
860                 break;
861         case B_PACKFONT:
862                 if (ob) {
863                         cu= ob->data;
864                         if(cu && cu->vfont) {
865                                 if (cu->vfont->packedfile) {
866                                         if (G.fileflags & G_AUTOPACK) {
867                                                 if (okee("Disable AutoPack ?")) {
868                                                         G.fileflags &= ~G_AUTOPACK;
869                                                 }
870                                         }
871
872                                         if ((G.fileflags & G_AUTOPACK) == 0) {
873                                                 if (unpackVFont(cu->vfont, PF_ASK) == RET_OK) {
874                                                         text_to_curve(ob, 0);
875                                                         makeDispList(ob);
876                                                         allqueue(REDRAWVIEW3D, 0);
877                                                 }
878                                         }
879                                 } else {
880                                         cu->vfont->packedfile = newPackedFile(cu->vfont->name);
881                                 }
882                         }
883                 }
884                 allqueue(REDRAWHEADERS, 0);
885                 allqueue(REDRAWBUTSEDIT, 0);
886                 break;
887
888         case B_SETFONT:
889                 if(ob) {
890                         cu= ob->data;
891
892                         vf= give_vfontpointer(G.buts->texnr);
893                         if(vf) {
894                                 id_us_plus((ID *)vf);
895                                 cu->vfont->id.us--;
896                                 cu->vfont= vf;
897                                 text_to_curve(ob, 0);
898                                 makeDispList(ob);
899                                 allqueue(REDRAWVIEW3D, 0);
900                                 allqueue(REDRAWBUTSEDIT, 0);
901                         }
902                 }
903                 break;
904         case B_TEXTONCURVE:
905                 if(ob) {
906                         cu= ob->data;
907                         if(cu->textoncurve && cu->textoncurve->type!=OB_CURVE) {
908                                 error("Only Curve Objects");
909                                 cu->textoncurve= 0;
910                                 allqueue(REDRAWBUTSEDIT, 0);
911                         }
912                         text_to_curve(ob, 0);
913                         makeDispList(ob);
914                 }
915         }
916 }
917
918 static void editing_panel_font_type(Object *ob, Curve *cu)
919 {
920         uiBlock *block;
921         char *strp;
922         static int packdummy = 0;
923         VFontData *vfd;
924
925         block= uiNewBlock(&curarea->uiblocks, "editing_panel_font_type", UI_EMBOSS, UI_HELV, curarea->win);
926         if(uiNewPanel(curarea, block, "Font", "Editing", 640, 0, 318, 204)==0) return;
927
928         G.buts->texnr= give_vfontnr(cu->vfont);
929         strp= give_vfontbutstr();
930         vfd= cu->vfont->data;
931
932         uiDefBut(block, BUT,B_LOADFONT, "Load", 480,188,68,20, 0, 0, 0, 0, 0, "Load a new font");
933         uiDefButS(block, MENU, B_SETFONT, strp, 550,188,220,20, &G.buts->texnr, 0, 0, 0, 0, "Change font for object");
934
935         if (cu->vfont->packedfile) {
936                 packdummy = 1;
937         } else {
938                 packdummy = 0;
939         }
940         uiDefIconButI(block, TOG|BIT|0, B_PACKFONT, ICON_PACKAGE,       772,188,20,20, &packdummy, 0, 0, 0, 0, "Pack/Unpack this font");
941         uiDefBut(block, LABEL, 0, vfd->name,  480, 165,314,20, 0, 0, 0, 0, 0, "Postscript name of the font");
942
943         MEM_freeN(strp);
944
945         uiBlockBeginAlign(block);
946         uiDefButS(block, ROW,B_MAKEFONT, "Left",                480,135,53,20, &cu->spacemode, 0.0,0.0, 0, 0, "Left align the text from the object centre");
947         uiDefButS(block, ROW,B_MAKEFONT, "Middle",              535,135,55,20, &cu->spacemode, 0.0,1.0, 0, 0, "Middle align the text from the object centre");
948         uiDefButS(block, ROW,B_MAKEFONT, "Right",               592,135,53,20, &cu->spacemode, 0.0,2.0, 0, 0, "Right align the text from the object centre");
949         uiDefButS(block, ROW,B_MAKEFONT, "Flush",               647,135,53,20, &cu->spacemode, 0.0,3.0, 0, 0, "Fill characters to maximum linewidth. (Multiple lines required)");
950         uiDefBut(block, BUT, B_TOUPPER, "ToUpper",              715,135,78,20, 0, 0, 0, 0, 0, "Toggle between upper and lower case in editmode");
951         uiBlockEndAlign(block);
952
953         uiDefIDPoinBut(block, test_obpoin_but, B_TEXTONCURVE, "TextOnCurve:",   480,105,220,19, &cu->textoncurve, "Apply a deforming curve to the text");
954         uiDefBut(block, TEX,REDRAWVIEW3D, "Ob Family:", 480,84,220,19, cu->family, 0.0, 20.0, 0, 0, "Blender uses font from selfmade objects");
955
956         uiBlockBeginAlign(block);
957         uiDefButF(block, NUM,B_MAKEFONT, "Size:",               480,56,155,20, &cu->fsize, 0.1,10.0, 10, 0, "Size of the text");
958         uiDefButF(block, NUM,B_MAKEFONT, "Linedist:",   640,56,155,20, &cu->linedist, 0.0,10.0, 10, 0, "Distance between text lines");
959         uiDefButF(block, NUM,B_MAKEFONT, "Spacing:",    480,34,155,20, &cu->spacing, 0.0,10.0, 10, 0, "Spacing of individual characters");
960         uiDefButF(block, NUM,B_MAKEFONT, "X offset:",   640,34,155,20, &cu->xof, -50.0,50.0, 10, 0, "Horizontal position from object centre");
961         uiDefButF(block, NUM,B_MAKEFONT, "Shear:",              480,12,155,20, &cu->shear, -1.0,1.0, 10, 0, "Italic angle of the characters");
962         uiDefButF(block, NUM,B_MAKEFONT, "Y offset:",   640,12,155,20, &cu->yof, -50.0,50.0, 10, 0, "Vertical position from object centre");
963         uiBlockEndAlign(block);
964 }
965
966
967 /* *************************** CURVE ******************************** */
968
969
970 void do_curvebuts(unsigned short event)
971 {
972         extern Nurb *lastnu;
973         extern ListBase editNurb;  /* from editcurve */
974         Base *base;
975         Object *ob;
976         Curve *cu;
977         Nurb *nu;
978
979         ob= OBACT;
980         if(ob==0) return;
981
982         switch(event) {
983
984         case B_CONVERTPOLY:
985         case B_CONVERTBEZ:
986         case B_CONVERTBSPL:
987         case B_CONVERTCARD:
988         case B_CONVERTNURB:
989                 if(G.obedit) {
990                         setsplinetype(event-B_CONVERTPOLY);
991                         makeDispList(G.obedit);
992                         allqueue(REDRAWVIEW3D, 0);
993                 }
994                 break;
995         case B_UNIFU:
996         case B_ENDPU:
997         case B_BEZU:
998         case B_UNIFV:
999         case B_ENDPV:
1000         case B_BEZV:
1001                 if(G.obedit) {
1002                         nu= editNurb.first;
1003                         while(nu) {
1004                                 if(isNurbsel(nu)) {
1005                                         if((nu->type & 7)==CU_NURBS) {
1006                                                 if(event<B_UNIFV) {
1007                                                         nu->flagu &= 1;
1008                                                         nu->flagu += ((event-B_UNIFU)<<1);
1009                                                         makeknots(nu, 1, nu->flagu>>1);
1010                                                 }
1011                                                 else if(nu->pntsv>1) {
1012                                                         nu->flagv &= 1;
1013                                                         nu->flagv += ((event-B_UNIFV)<<1);
1014                                                         makeknots(nu, 2, nu->flagv>>1);
1015                                                 }
1016                                         }
1017                                 }
1018                                 nu= nu->next;
1019                         }
1020                         makeDispList(G.obedit);
1021                         allqueue(REDRAWVIEW3D, 0);
1022                 }
1023                 break;
1024         case B_SETWEIGHT:
1025                 if(G.obedit) {
1026                         weightflagNurb(1, editbutweight, 0);
1027                         makeDispList(G.obedit);
1028                         allqueue(REDRAWVIEW3D, 0);
1029                 }
1030                 break;
1031         case B_SETW1:
1032                 editbutweight= 1.0;
1033                 scrarea_queue_winredraw(curarea);
1034                 break;
1035         case B_SETW2:
1036                 editbutweight= sqrt(2.0)/4.0;
1037                 scrarea_queue_winredraw(curarea);
1038                 break;
1039         case B_SETW3:
1040                 editbutweight= 0.25;
1041                 scrarea_queue_winredraw(curarea);
1042                 break;
1043         case B_SETW4:
1044                 editbutweight= sqrt(0.5);
1045                 scrarea_queue_winredraw(curarea);
1046                 break;
1047         case B_SETORDER:
1048                 if(G.obedit) {
1049                         nu= lastnu;
1050                         if(nu && (nu->type & 7)==CU_NURBS ) {
1051                                 if(nu->orderu>nu->pntsu) {
1052                                         nu->orderu= nu->pntsu;
1053                                         scrarea_queue_winredraw(curarea);
1054                                 }
1055                                 makeknots(nu, 1, nu->flagu>>1);
1056                                 if(nu->orderv>nu->pntsv) {
1057                                         nu->orderv= nu->pntsv;
1058                                         scrarea_queue_winredraw(curarea);
1059                                 }
1060                                 makeknots(nu, 2, nu->flagv>>1);
1061                         }
1062                         makeDispList(G.obedit);
1063                         allqueue(REDRAWVIEW3D, 0);
1064                 }
1065                 break;
1066         case B_MAKEDISP:
1067                 if(ob->type==OB_FONT) text_to_curve(ob, 0);
1068                 makeDispList(ob);
1069                 /* we need signal to send to other users of same data to recalc... */
1070                 base= FIRSTBASE;
1071                 while(base) {
1072                         if(base->lay & G.vd->lay) {
1073                                 if(base->object->data==ob->data && base->object!=ob)
1074                                         makeDispList(base->object);
1075                         }
1076                         base= base->next;
1077                 }
1078                 allqueue(REDRAWVIEW3D, 0);
1079                 allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
1080                 break;
1081
1082         case B_SUBDIVCURVE:
1083                 subdivideNurb();
1084                 break;
1085         case B_SPINNURB:
1086                 /* bad bad bad!!! use brackets!!! In case you wondered:
1087                   {==,!=} goes before & goes before || */
1088                 if( (G.obedit==0) ||
1089                     (G.obedit->type!=OB_SURF) ||
1090                         ((G.obedit->lay & G.vd->lay) == 0) ) return;
1091                 spinNurb(0, 0);
1092                 countall();
1093                 makeDispList(G.obedit);
1094                 allqueue(REDRAWVIEW3D, 0);
1095                 break;
1096         case B_CU3D:        /* allow 3D curve */
1097                 if(G.obedit) {
1098                         cu= G.obedit->data;
1099                         nu= editNurb.first;
1100                         while(nu) {
1101                                 nu->type &= ~CU_2D;
1102                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
1103                                 test2DNurb(nu);
1104                                 nu= nu->next;
1105                         }
1106                 }
1107                 if(ob->type==OB_CURVE) {
1108                         cu= ob->data;
1109                         nu= cu->nurb.first;
1110                         while(nu) {
1111                                 nu->type &= ~CU_2D;
1112                                 if((cu->flag & CU_3D)==0) nu->type |= CU_2D;
1113                                 test2DNurb(nu);
1114                                 nu= nu->next;
1115                         }
1116                 }
1117                 makeDispList(G.obedit);
1118                 allqueue(REDRAWVIEW3D, 0);
1119                 break;
1120         case B_SETRESOLU:
1121                 if(ob->type==OB_CURVE) {
1122                         cu= ob->data;
1123                         if(ob==G.obedit) nu= editNurb.first;
1124                         else nu= cu->nurb.first;
1125
1126                         while(nu) {
1127                                 nu->resolu= cu->resolu;
1128                                 nu= nu->next;
1129                         }
1130                 }
1131                 else if(ob->type==OB_FONT) text_to_curve(ob, 0);
1132
1133                 makeDispList(ob);
1134                 allqueue(REDRAWVIEW3D, 0);
1135
1136                 break;
1137         }
1138 }
1139
1140 static void editing_panel_curve_tools(Object *ob, Curve *cu)
1141 {
1142         Nurb *nu;
1143         extern ListBase editNurb;  /* from editcurve */
1144         extern Nurb *lastnu;
1145         uiBlock *block;
1146         short *sp;
1147
1148         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools", UI_EMBOSS, UI_HELV, curarea->win);
1149         if(uiNewPanel(curarea, block, "Curve Tools", "Editing", 640, 0, 318, 204)==0) return;
1150
1151         uiDefBut(block, LABEL, 0, "Make Knots",562,173,102, 18, 0, 0, 0, 0, 0, "");
1152
1153         if(ob->type==OB_CURVE) {
1154                 uiDefBut(block, LABEL, 0, "Convert",    463,173,72, 18, 0, 0, 0, 0, 0, "");
1155                 uiBlockBeginAlign(block);
1156                 uiDefBut(block, BUT,B_CONVERTPOLY,"Poly",               467,152,72, 18, 0, 0, 0, 0, 0, "");
1157                 uiDefBut(block, BUT,B_CONVERTBEZ,"Bezier",      467,132,72, 18, 0, 0, 0, 0, 0, "");
1158                 uiDefBut(block, BUT,B_CONVERTBSPL,"Bspline",    467,112,72, 18, 0, 0, 0, 0, 0, "");
1159                 uiDefBut(block, BUT,B_CONVERTCARD,"Cardinal",   467,92,72, 18, 0, 0, 0, 0, 0, "");
1160                 uiDefBut(block, BUT,B_CONVERTNURB,"Nurb",               467,72,72, 18, 0, 0, 0, 0, 0, "");
1161         }
1162         uiBlockBeginAlign(block);
1163         uiDefBut(block, BUT,B_UNIFU,"Uniform U",        565,152,102, 18, 0, 0, 0, 0, 0, "");
1164         uiDefBut(block, BUT,B_UNIFV,"V",                        670,152,50, 18, 0, 0, 0, 0, 0, "");
1165         uiDefBut(block, BUT,B_ENDPU,"Endpoint U",       565,132,102, 18, 0, 0, 0, 0, 0, "");
1166         uiDefBut(block, BUT,B_ENDPV,"V",                        670,132,50, 18, 0, 0, 0, 0, 0, "");
1167         uiDefBut(block, BUT,B_BEZU,"Bezier U",          565,112,102, 18, 0, 0, 0, 0, 0, "");
1168         uiDefBut(block, BUT,B_BEZV,"V",                         670,112,50, 18, 0, 0, 0, 0, 0, "");
1169         uiBlockEndAlign(block);
1170
1171         uiDefBut(block, BUT,B_SETWEIGHT,"Set Weight",   465,11,95,49, 0, 0, 0, 0, 0, "");
1172
1173         uiBlockBeginAlign(block);
1174         uiDefButF(block, NUM,0,"Weight:",               565,36,102,22, &editbutweight, 0.01, 100.0, 10, 0, "");
1175         uiDefBut(block, BUT,B_SETW1,"1.0",              670,36,50,22, 0, 0, 0, 0, 0, "");
1176         uiDefBut(block, BUT,B_SETW2,"sqrt(2)/4",565,11,55,20, 0, 0, 0, 0, 0, "");
1177         uiDefBut(block, BUT,B_SETW3,"0.25",             620,11,45,20, 0, 0, 0, 0, 0, "");
1178         uiDefBut(block, BUT,B_SETW4,"sqrt(0.5)",665,11,55,20, 0, 0, 0, 0, 0, "");
1179         uiBlockEndAlign(block);
1180
1181         if(ob==G.obedit) {
1182                 nu= lastnu;
1183                 if(nu==NULL) nu= editNurb.first;
1184                 if(nu) {
1185                         uiBlockBeginAlign(block);
1186                         sp= &(nu->orderu);
1187                         uiDefButS(block, NUM, B_SETORDER, "Order U:", 565,90,102, 19, sp, 2.0, 6.0, 0, 0, "");
1188                         sp= &(nu->orderv);
1189                         uiDefButS(block, NUM, B_SETORDER, "V:",         670,90,50, 19, sp, 2.0, 6.0, 0, 0, "");
1190                         sp= &(nu->resolu);
1191                         uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 19, sp, 1.0, 128.0, 0, 0, "");
1192                         sp= &(nu->resolv);
1193                         uiDefButS(block, NUM, B_MAKEDISP, "V:",         670,70,50, 19, sp, 1.0, 128.0, 0, 0, "");
1194                 }
1195         }
1196
1197
1198 }
1199
1200 static void editing_panel_curve_tools1(Object *ob, Curve *cu)
1201 {
1202         uiBlock *block;
1203
1204         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_tools1", UI_EMBOSS, UI_HELV, curarea->win);
1205         if(uiNewPanel(curarea, block, "Curve Tools1", "Editing", 960, 0, 318, 204)==0) return;
1206
1207         uiDefBut(block, BUT, B_SUBDIVCURVE, "Subdivide", 400,180,150,20, 0, 0, 0, 0, 0, "");
1208         if(ob->type==OB_SURF) {
1209                 uiDefBut(block, BUT, B_SPINNURB, "Spin",         400,160,150,20, 0, 0, 0, 0, 0, "");
1210         }
1211         uiBlockBeginAlign(block);
1212         uiDefBut(block, BUT,B_HIDE,             "Hide",                 400,120,150,18, 0, 0, 0, 0, 0, "Hides selected faces");
1213         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               400,100,150,18, 0, 0, 0, 0, 0, "Reveals selected faces");
1214         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  400,80,150,18, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
1215         uiBlockEndAlign(block);
1216
1217         uiDefButF(block, NUM,   REDRAWVIEW3D, "NSize:", 400, 40, 150, 19, &editbutsize, 0.001, 1.0, 10, 0, "");
1218 }
1219
1220 /* for curve, surf and font! */
1221 static void editing_panel_curve_type(Object *ob, Curve *cu)
1222 {
1223         uiBlock *block;
1224
1225         block= uiNewBlock(&curarea->uiblocks, "editing_panel_curve_type", UI_EMBOSS, UI_HELV, curarea->win);
1226         if(uiNewPanel(curarea, block, "Curve and Surface", "Editing", 320, 0, 318, 204)==0) return;
1227
1228         uiDefButS(block, TOG|BIT|5, 0, "UV Orco",                                       600,160,150,19, &cu->flag, 0, 0, 0, 0, "");
1229         if(ob->type==OB_SURF)
1230                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "No Puno Flip",       600,140,150,19, &cu->flag, 0, 0, 0, 0, "");
1231
1232         uiBlockBeginAlign(block);
1233         uiDefBut(block, BUT,B_DOCENTRE, "Centre",                                       600, 115, 150, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
1234         uiDefBut(block, BUT,B_DOCENTRENEW, "Centre New",                        600, 95, 150, 19, 0, 0, 0, 0, 0, "Shifts object's origin to center of object data");
1235         uiDefBut(block, BUT,B_DOCENTRECURSOR, "Centre Cursor",          600, 75, 150, 19, 0, 0, 0, 0, 0, "Shifts object's origin to cursor location");
1236         uiBlockEndAlign(block);
1237
1238         if(ob->type==OB_SURF) {
1239                 if(cu->key) {
1240                         /* uiDefButS(block, NUM, B_DIFF, "Slurph:",                     600,25,140,19, &(cu->key->slurph), -500.0, 500.0,0,0); ,""*/
1241                         uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        600,45,140,19, &cu->key->type, 0, 0, 0, 0, "");
1242                 }
1243         }
1244
1245         if(ob->type!=OB_SURF) {
1246
1247                 if(ob->type==OB_CURVE) {
1248                         extern float prlen;             // buttons_object.c, should be moved....
1249                         char str[32];
1250                         uiBlockBeginAlign(block);
1251                         uiDefButS(block, NUM, B_RECALCPATH, "PathLen:",                 600,50,150,19, &cu->pathlen, 1.0, 9000.0, 0, 0, "");
1252                         uiDefButS(block, TOG|BIT|3, B_RECALCPATH, "CurvePath",  600,30,75,19 , &cu->flag, 0, 0, 0, 0, "");
1253                         uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "CurveFollow",675,30,75,19, &cu->flag, 0, 0, 0, 0, "");
1254                         sprintf(str, "%.4f", prlen);
1255                         uiDefBut(block, BUT, B_PRINTLEN,                "PrintLen",     600,10,75,19, 0, 0, 0, 0, 0, "");
1256                         uiDefBut(block, LABEL, 0, str,                                          675,10,75,19, 0, 1.0, 0, 0, 0, "");
1257                 }
1258
1259                 uiBlockBeginAlign(block);
1260                 uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 760,160,120,19, &cu->resolu, 1.0, 128.0, 0, 0, "");
1261                 uiDefBut(block, BUT, B_SETRESOLU, "Set",                880,160,30,19, 0, 0, 0, 0, 0, "");
1262
1263                 uiBlockBeginAlign(block);
1264                 uiDefButF(block, NUM, B_MAKEDISP, "Width:",             760,90,150,19, &cu->width, 0.0, 2.0, 1, 0, "");
1265                 uiDefButF(block, NUM, B_MAKEDISP, "Ext1:",              760,70,150,19, &cu->ext1, 0.0, 5.0, 10, 0, "");
1266                 uiDefButF(block, NUM, B_MAKEDISP, "Ext2:",              760,50,150,19, &cu->ext2, 0.0, 2.0, 1, 0, "");
1267                 uiDefButS(block, NUM, B_MAKEDISP, "BevResol:",  760,30,150,19, &cu->bevresol, 0.0, 10.0, 0, 0, "");
1268                 uiDefIDPoinBut(block, test_obcurpoin_but, B_MAKEDISP, "BevOb:",         760,10,150,19, &cu->bevobj, "");
1269
1270                 uiBlockBeginAlign(block);
1271                 uiBlockSetCol(block, TH_BUT_SETTING1);
1272                 uiDefButS(block, TOG|BIT|2, B_MAKEDISP, "Back", 760,130,50,19, &cu->flag, 0, 0, 0, 0, "");
1273                 uiDefButS(block, TOG|BIT|1, B_MAKEDISP, "Front",810,130,50,19, &cu->flag, 0, 0, 0, 0, "");
1274                 uiDefButS(block, TOG|BIT|0, B_CU3D, "3D",               860,130,50,19, &cu->flag, 0, 0, 0, 0, "");
1275
1276
1277         }
1278
1279 }
1280
1281
1282 /* *************************** CAMERA ******************************** */
1283
1284
1285 static void editing_panel_camera_type(Object *ob, Camera *cam)
1286 {
1287         uiBlock *block;
1288         float grid=0.0;
1289
1290         if(G.vd) grid= G.vd->grid;
1291         if(grid<1.0) grid= 1.0;
1292
1293         block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_type", UI_EMBOSS, UI_HELV, curarea->win);
1294         if(uiNewPanel(curarea, block, "Camera", "Editing", 320, 0, 318, 204)==0) return;
1295
1296         uiDefButF(block, NUM,REDRAWVIEW3D, "Lens:", 470,178,160,20, &cam->lens, 1.0, 250.0, 100, 0, "Specify the lens of the camera");
1297
1298         uiBlockBeginAlign(block);
1299         uiDefButF(block, NUM,REDRAWVIEW3D, "ClipSta:", 470,147,160,20, &cam->clipsta, 0.001*grid, 100.0*grid, 10, 0, "Specify the startvalue of the the field of view");
1300         uiDefButF(block, NUM,REDRAWVIEW3D, "ClipEnd:", 470,125,160,20, &cam->clipend, 1.0, 5000.0*grid, 100, 0, "Specify the endvalue of the the field of view");
1301         uiBlockEndAlign(block);
1302
1303         uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
1304
1305         uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
1306         uiBlockBeginAlign(block);
1307         uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
1308         uiDefButS(block, TOG|BIT|1,REDRAWVIEW3D, "Show Mist", 533,49,97,20, &cam->flag, 0, 0, 0, 0, "Draw a line that indicates the mist area");
1309         uiBlockEndAlign(block);
1310 }
1311
1312 /* *************************** MBALL ******************************** */
1313
1314 void do_mballbuts(unsigned short event)
1315 {
1316         switch(event) {
1317         case B_RECALCMBALL:
1318                 makeDispList(OBACT);
1319                 allqueue(REDRAWVIEW3D, 0);
1320                 break;
1321         }
1322 }
1323
1324 static void editing_panel_mball_type(Object *ob, MetaBall *mb)
1325 {
1326         uiBlock *block;
1327
1328         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_type", UI_EMBOSS, UI_HELV, curarea->win);
1329         if(uiNewPanel(curarea, block, "MetaBall", "Editing", 320, 0, 318, 204)==0) return;
1330
1331         ob= find_basis_mball(ob);
1332         mb= ob->data;
1333
1334         uiBlockBeginAlign(block);
1335         uiDefButF(block, NUMSLI, B_RECALCMBALL, "Wiresize:",    470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "");
1336         uiDefButF(block, NUMSLI, 0, "Rendersize:",                      470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "");
1337         uiDefButF(block, NUMSLI, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "");
1338
1339         uiBlockBeginAlign(block);
1340         uiBlockSetCol(block, TH_BUT_SETTING1);
1341         uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
1342         uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "");
1343         uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "");
1344         uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "");
1345         uiDefButS(block, ROW, B_DIFF, "Never",          471, 25, 120, 19, &mb->flag, 0.0, 3.0, 0, 0, "");
1346
1347 }
1348
1349 static void editing_panel_mball_tools(Object *ob, MetaBall *mb)
1350 {
1351         extern MetaElem *lastelem;
1352         uiBlock *block;
1353
1354         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mball_tools", UI_EMBOSS, UI_HELV, curarea->win);
1355         if( uiNewPanel(curarea, block, "MetaBall tools", "Editing", 640, 0, 318, 204)==0) return;
1356
1357         if(ob==G.obedit && lastelem) {
1358                 uiBlockBeginAlign(block);
1359                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "");
1360                 if(lastelem->type!=MB_BALL)
1361                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dx:",          750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "");
1362                 if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
1363                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dy:",          750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "");
1364
1365                 if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
1366                 uiDefButF(block, NUMSLI, B_RECALCMBALL, "dz:",          750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "");
1367                 uiBlockEndAlign(block);
1368
1369                 uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "");
1370                 uiBlockBeginAlign(block);
1371                 uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "");
1372                 uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "");
1373                 uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "");
1374                 uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "");
1375                 uiBlockEndAlign(block);
1376
1377                 uiDefButS(block, TOG|BIT|1, B_RECALCMBALL, "Negative",753,16,60,19, &lastelem->flag, 0, 0, 0, 0, "");
1378
1379         }
1380
1381 }
1382
1383
1384 /* *************************** LATTICE ******************************** */
1385
1386 void do_latticebuts(unsigned short event)
1387 {
1388         Object *ob;
1389         Lattice *lt;
1390
1391         ob= OBACT;
1392         if(ob->type!=OB_LATTICE) return;
1393
1394         switch(event) {
1395         case B_RESIZELAT:
1396                 if(ob) {
1397                         if(ob==G.obedit) resizelattice(editLatt);
1398                         else resizelattice(ob->data);
1399                 }
1400                 allqueue(REDRAWVIEW3D, 0);
1401                 break;
1402         case B_DRAWLAT:
1403                 if(ob==G.obedit) calc_lattverts_ext();
1404                 allqueue(REDRAWVIEW3D, 0);
1405                 break;
1406         case B_LATTCHANGED:
1407
1408                 lt= ob->data;
1409                 if(lt->flag & LT_OUTSIDE) outside_lattice(lt);
1410
1411                 make_displists_by_parent(ob);
1412
1413                 allqueue(REDRAWVIEW3D, 0);
1414
1415                 break;
1416         }
1417 }
1418
1419 static void editing_panel_lattice_type(Object *ob, Lattice *lt)
1420 {
1421         uiBlock *block;
1422
1423         block= uiNewBlock(&curarea->uiblocks, "editing_panel_lattice_type", UI_EMBOSS, UI_HELV, curarea->win);
1424         if(uiNewPanel(curarea, block, "Latice", "Editing", 320, 0, 318, 204)==0) return;
1425
1426
1427         uiSetButLock(lt->key!=0, "Not with VertexKeys");
1428         uiSetButLock(ob==G.obedit, "Unable to perform function in EditMode");
1429
1430         uiBlockBeginAlign(block);
1431         uiDefButS(block, NUM, B_RESIZELAT,      "U:",                           470, 178,100,19, &lt->pntsu, 1.0, 64.0, 0, 0, "Points in U direction");
1432         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1433         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1434         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 178, 40, 19, &lt->typeu, 1.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1435
1436         uiBlockBeginAlign(block);
1437         uiDefButS(block, NUM, B_RESIZELAT,      "V:",                           470, 158,100,19, &lt->pntsv, 1.0, 64.0, 0, 0, "Points in V direction");
1438         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 158, 40, 19, &lt->typev, 2.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1439         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 158, 40, 19, &lt->typev, 2.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1440         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 158, 40, 19, &lt->typev, 2.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1441
1442         uiBlockBeginAlign(block);
1443         uiDefButS(block, NUM, B_RESIZELAT,      "W:",                           470, 138,100,19, &lt->pntsw, 1.0, 64.0, 0, 0, "Points in W direction");
1444         uiDefButC(block, ROW, B_LATTCHANGED,            "Lin",          572, 138, 40, 19, &lt->typew, 3.0, (float)KEY_LINEAR, 0, 0, "Set Linear interpolation");
1445         uiDefButC(block, ROW, B_LATTCHANGED,            "Card",         612, 138, 40, 19, &lt->typew, 3.0, (float)KEY_CARDINAL, 0, 0, "Set Cardinal interpolation");
1446         uiDefButC(block, ROW, B_LATTCHANGED,            "B",            652, 138, 40, 19, &lt->typew, 3.0, (float)KEY_BSPLINE, 0, 0, "Set B-spline interpolation");
1447         uiBlockEndAlign(block);
1448
1449         uiDefBut(block, BUT, B_RESIZELAT,       "Make Regular",         470,101,99,32, 0, 0, 0, 0, 0, "Make Lattice regular");
1450
1451         uiClearButLock();
1452         uiDefButS(block, TOG|BIT|1, B_LATTCHANGED, "Outside",   571,101,120,31, &lt->flag, 0, 0, 0, 0, "Only draw, and take into account, the outer vertices");
1453
1454         if(lt->key) {
1455                 uiDefButS(block, NUM, B_DIFF, "Slurph:",                        470,60,120,19, &(lt->key->slurph), -500.0, 500.0, 0, 0, "Set time value to denote 'slurph' (sequential delay) vertices with key framing");
1456                 uiDefButS(block, TOG, B_RELKEY, "Relative Keys",        470,40,120,19, &lt->key->type, 0, 0, 0, 0, "Use relative keys (instead of absolute)");
1457         }
1458
1459 }
1460
1461 /* *************************** ARMATURE ******************************** */
1462
1463
1464
1465 static int editbone_to_parnr (EditBone *bone)
1466 {
1467         EditBone *ebone;
1468         int     index;
1469
1470         for (ebone=G.edbo.first, index=0; ebone; ebone=ebone->next, index++){
1471                 if (ebone==bone)
1472                         return index;
1473         }
1474
1475         return -1;
1476 }
1477
1478 static void parnr_to_editbone(EditBone *bone)
1479 {
1480         if (bone->parNr == -1){
1481                 bone->parent = NULL;
1482                 bone->flag &= ~BONE_IK_TOPARENT;
1483         }
1484         else{
1485                 bone->parent = BLI_findlink(&G.edbo, bone->parNr);
1486                 attach_bone_to_parent(bone);
1487         }
1488 }
1489
1490 static void parnr_to_editbone_cb(void *bonev, void *arg2_unused)
1491 {
1492         EditBone *curBone= bonev;
1493         parnr_to_editbone(curBone);
1494 }
1495
1496 static void build_bonestring (char *string, EditBone *bone)
1497 {
1498         EditBone *curBone;
1499         EditBone *pBone;
1500         int             skip=0;
1501         int             index, numbones, i;
1502         char (*qsort_ptr)[32] = NULL;
1503
1504         sprintf (string, "Parent%%t| %%x%d", -1);       /* That space is there
1505                                                                                                  * for a reason
1506                                                                                                  */
1507
1508         numbones = BLI_countlist(&G.edbo);
1509
1510         /*
1511          * This will hold the bone names temporarily so we can sort them
1512          */
1513         if (numbones > 0)
1514                 qsort_ptr = MEM_callocN (numbones * sizeof (qsort_ptr[0]),
1515                                                                  "qsort_ptr");
1516
1517         numbones = 0;
1518         for (curBone = G.edbo.first, index=0; curBone;
1519                  curBone=curBone->next, index++){
1520                 /* Make sure this is a valid child */
1521                 if (curBone != bone){
1522                         skip=0;
1523                         for (pBone=curBone->parent; pBone; pBone=pBone->parent){
1524                                 if (pBone==bone){
1525                                         skip=1;
1526                                         break;
1527                                 }
1528                         }
1529
1530                         if (skip)
1531                                 continue;
1532
1533                         sprintf (qsort_ptr[numbones], "|%s%%x%d", curBone->name, index);
1534                         numbones++;
1535                 }
1536         }
1537         qsort (qsort_ptr, numbones, sizeof (qsort_ptr[0]),
1538                    ( int (*)(const void *, const void *) ) strcmp);
1539
1540         for (i=0; i < numbones; ++i) {
1541                 sprintf (string, "%s%s", string, qsort_ptr[i]);
1542         }
1543
1544         if (qsort_ptr)
1545                 MEM_freeN(qsort_ptr);
1546 }
1547
1548 static void constraint_ebone_name_fix(ListBase *conlist, EditBone *eBone)
1549 {
1550
1551         bConstraint *curcon;
1552         char *subtarget;
1553
1554         for (curcon = conlist->first; curcon; curcon=curcon->next){
1555                 subtarget = get_con_subtarget_name(curcon, G.obedit);
1556                 if (subtarget)
1557                         if (!strcmp(subtarget,eBone->oldname) )
1558                                 strcpy(subtarget, eBone->name);
1559         }
1560 }
1561
1562 static void validate_editbonebutton(EditBone *eBone)
1563 {
1564         EditBone        *prev;
1565         bAction         *act=NULL;
1566         bActionChannel *chan;
1567         Base *base;
1568         bPose        *pose;
1569         bPoseChannel *pchan;
1570
1571         /* Separate the bone from the G.edbo */
1572         prev=eBone->prev;
1573         BLI_remlink (&G.edbo, eBone);
1574
1575         /*      Validate the name */
1576         unique_editbone_name (eBone->name);
1577
1578         /* Re-insert the bone */
1579         if (prev)
1580                 BLI_insertlink(&G.edbo, prev, eBone);
1581         else
1582                 BLI_addhead (&G.edbo, eBone);
1583
1584         /* Rename *action* channel if necessary */
1585         if (G.obedit)
1586                 act = G.obedit->action;
1587
1588         if (act && !act->id.lib){
1589                 /*      Find the appropriate channel
1590                  */
1591                 for (chan = act->chanbase.first; chan; chan=chan->next){
1592                         if (!strcmp (chan->name, eBone->oldname)){
1593                                 strcpy (chan->name, eBone->name);
1594                         }
1595                 }
1596                 allqueue(REDRAWACTION, 0);
1597         }
1598
1599         /* Rename the *pose* channel, if it exists (thus making sure
1600          * that the constraints are still valid)
1601          */
1602         pose = G.obedit->pose;
1603         if (pose) {
1604                 pchan = get_pose_channel(pose, eBone->oldname);
1605                 if (pchan) {
1606                         strcpy (pchan->name, eBone->name);
1607                 }
1608         }
1609
1610         /* Update the parenting info of any users */
1611         /*      Yes, I know this is the worst thing you have ever seen. */
1612
1613         for (base = G.scene->base.first; base; base=base->next){
1614                 Object *ob = base->object;
1615                 ListBase *conlist;
1616
1617                 /* See if an object is parented to this armature */
1618                 if (ob->parent && ob->partype==PARBONE &&
1619                         (ob->parent->type==OB_ARMATURE) &&
1620                         (ob->parent->data == G.obedit->data)){
1621                         if (!strcmp(ob->parsubstr, eBone->oldname))
1622                                 strcpy(ob->parsubstr, eBone->name);
1623                 }
1624
1625                 /* Update any constraints to use the new bone name */
1626                 conlist = &ob->constraints;
1627                 constraint_ebone_name_fix(conlist, eBone);
1628
1629                 switch (ob->type){
1630                         case OB_ARMATURE:
1631                                 if (ob->pose){
1632                                         for (pchan = ob->pose->chanbase.first; pchan;
1633                                                  pchan=pchan->next){
1634                                                 conlist = &pchan->constraints;
1635                                                 constraint_ebone_name_fix(conlist, eBone);
1636                                         }
1637                                 }
1638                                 break;
1639                         default:
1640                                 break;
1641         }
1642
1643         }
1644
1645         exit_editmode(0);       /* To ensure new names make it to the edit armature */
1646
1647 }
1648
1649 static void validate_editbonebutton_cb(void *bonev, void *arg2_unused)
1650 {
1651         EditBone *curBone= bonev;
1652         validate_editbonebutton(curBone);
1653 }
1654
1655 static void armature_rest_pos_func(void *notused1, void *notused2) 
1656 {
1657         clear_object_constraint_status(OBACT);
1658         make_displists_by_armature(OBACT);
1659 }
1660
1661 static void editing_panel_armature_type(Object *ob, bArmature *arm)
1662 {
1663         uiBlock         *block;
1664         uiBut       *but;
1665         int                     bx=148, by=100;
1666
1667         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_type", UI_EMBOSS, UI_HELV, curarea->win);
1668         if(uiNewPanel(curarea, block, "Armature", "Editing", 320, 0, 318, 204)==0) return;
1669
1670         but = uiDefButI(block, TOG|BIT|ARM_RESTPOSBIT,REDRAWVIEW3D,
1671                                         "Rest Pos", bx,by,97,20, &arm->flag, 0, 0, 0, 0,
1672                                         "Disable all animation for this object");
1673         uiButSetFunc(but, armature_rest_pos_func, NULL, NULL);
1674
1675         uiBlockBeginAlign(block);
1676         uiDefButI(block, TOG|BIT|ARM_DRAWAXESBIT,REDRAWVIEW3D, "Draw Axes", bx,by-46,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone axes");
1677         uiDefButI(block, TOG|BIT|ARM_DRAWNAMESBIT,REDRAWVIEW3D, "Draw Names", bx,by-69,97,20, &arm->flag, 0, 0, 0, 0, "Draw bone names");
1678         uiDefButI(block, TOG|BIT|ARM_DRAWXRAYBIT,REDRAWVIEW3D, "X-Ray", bx,by-92,97,20, &arm->flag, 0, 0, 0, 0, "Draw armature in front of shaded objects");
1679         uiDefButI(block, TOG|BIT|ARM_DELAYBIT,REDRAWVIEW3D,
1680                           "Delay Deform", bx,by-115,97,20, &arm->flag, 0, 0, 0, 0,
1681                           "Don't deform children when manipulating bones in pose mode");
1682 }
1683
1684 static void editing_panel_armature_bones(Object *ob, bArmature *arm)
1685 {
1686         uiBlock         *block;
1687         EditBone        *curBone;
1688         uiBut           *but;
1689         char            *boneString=NULL;
1690         int                     bx=148, by=180;
1691         int                     index;
1692
1693         /* Draw the bone name block */
1694
1695         block= uiNewBlock(&curarea->uiblocks, "editing_panel_armature_bones", UI_EMBOSS, UI_HELV, curarea->win);
1696         if(uiNewPanel(curarea, block, "Armature Bones", "Editing", 640, 0, 318, 204)==0) return;
1697
1698         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
1699         /* so first we make it default height */
1700         uiNewPanelHeight(block, 204);
1701
1702
1703         uiDefBut(block, LABEL, 0, "Selected Bones",                                             bx,by,158,18, 0, 0, 0, 0, 0, "");
1704         by-=20;
1705         for (curBone=G.edbo.first, index=0; curBone; curBone=curBone->next, index++){
1706                 if (curBone->flag & (BONE_SELECTED)) {
1707
1708                         /* Hide in posemode flag */
1709                         uiDefButI(block, TOG|BIT|BONE_HIDDENBIT, REDRAWVIEW3D, "Hide", bx-55,by,45,18, &curBone->flag, 0, 0, 0, 0, "Toggles display of this bone in posemode");
1710
1711                         /*      Bone naming button */
1712                         strcpy (curBone->oldname, curBone->name);
1713                         but=uiDefBut(block, TEX, REDRAWVIEW3D, "BO:", bx-10,by,117,18, &curBone->name, 0, 24, 0, 0, "Change the bone name");
1714                         uiButSetFunc(but, validate_editbonebutton_cb, curBone, NULL);
1715
1716                         uiDefBut(block, LABEL, 0, "child of", bx+107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1717
1718                         boneString = malloc((BLI_countlist(&G.edbo) * 64)+64);
1719                         build_bonestring (boneString, curBone);
1720
1721                         curBone->parNr = editbone_to_parnr(curBone->parent);
1722                         but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, bx+180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
1723                         uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
1724
1725                         free(boneString);
1726
1727                         /* IK to parent flag */
1728                         if (curBone->parent){
1729                                 but=uiDefButI(block, TOG|BIT|BONE_IK_TOPARENTBIT, REDRAWVIEW3D, "IK", bx+300,by,32,18, &curBone->flag, 0.0, 0.0, 0.0, 0.0, "IK link to parent");
1730                                 uiButSetFunc(but, attach_bone_to_parent_cb, curBone, NULL);
1731                         }
1732
1733                         /* Dist and weight buttons */
1734                         uiBlockBeginAlign(block);
1735                         but=uiDefButS(block, MENU, REDRAWVIEW3D,
1736                                                         "Skinnable %x0|"
1737                                                         "Unskinnable %x1|"
1738                                                         "Head %x2|"
1739                                                         "Neck %x3|"
1740                                                         "Back %x4|"
1741                                                         "Shoulder %x5|"
1742                                                         "Arm %x6|"
1743                                                         "Hand %x7|"
1744                                                         "Finger %x8|"
1745                                                         "Thumb %x9|"
1746                                                         "Pelvis %x10|"
1747                                                         "Leg %x11|"
1748                                                         "Foot %x12|"
1749                                                         "Toe %x13|"
1750                                                         "Tentacle %x14",
1751                                                         bx-10,by-19,117,18,
1752                                                         &curBone->boneclass,
1753                                                         0.0, 0.0, 0.0, 0.0,
1754                                                         "Classification of armature element");
1755
1756                         /* Dist and weight buttons */
1757                         uiDefButF(block, NUM,REDRAWVIEW3D, "Dist:", bx+110, by-19,
1758                                                 105, 18, &curBone->dist, 0.0, 1000.0, 10.0, 0.0,
1759                                                 "Bone deformation distance");
1760                         uiDefButF(block, NUM,REDRAWVIEW3D, "Weight:", bx+223, by-19,
1761                                                 110, 18, &curBone->weight, 0.0F, 1000.0F,
1762                                                 10.0F, 0.0F, "Bone deformation weight");
1763
1764                         uiBlockEndAlign(block);
1765                         by-=42;
1766                 }
1767         }
1768
1769         if(by<0) {
1770                 uiNewPanelHeight(block, 204 - by);
1771         }
1772
1773 }
1774
1775
1776 /* *************************** MESH ******************************** */
1777
1778 void do_meshbuts(unsigned short event)
1779 {
1780         void decimate_faces(void);
1781         void decimate_cancel(void);
1782         void decimate_apply(void);
1783         Object *ob;
1784         Mesh *me;
1785         float fac;
1786         short randfac;
1787
1788         ob= OBACT;
1789         if(ob && ob->type==OB_MESH) {
1790
1791                 me= get_mesh(ob);
1792                 if(me==0) return;
1793
1794                 switch(event) {
1795                 case B_AUTOVGROUP:
1796                         if (!get_armature(ob->parent)){
1797                                 error ("Mesh must be the child of an armature");
1798                                 break;
1799                         }
1800                                 /* Verify that there are vertex groups for bones in armature */
1801                                 /* Remove selected vertices from all defgroups */
1802                                 /* Perform assignment for selected vertices */
1803
1804                         allqueue (REDRAWVIEW3D, 1);
1805                         break;
1806                 case B_NEWVGROUP:
1807                         add_defgroup (G.obedit);
1808                         scrarea_queue_winredraw(curarea);
1809                         break;
1810                 case B_DELVGROUP:
1811                         del_defgroup (G.obedit);
1812                         allqueue (REDRAWVIEW3D, 1);
1813                         break;
1814                 case B_ASSIGNVGROUP:
1815                         undo_push_mesh("Assign to vertex group");
1816                         assign_verts_defgroup ();
1817                         allqueue (REDRAWVIEW3D, 1);
1818                         break;
1819                 case B_REMOVEVGROUP:
1820                         undo_push_mesh("Remove from vertex group");
1821                         remove_verts_defgroup (0);
1822                         allqueue (REDRAWVIEW3D, 1);
1823                         break;
1824                 case B_SELVGROUP:
1825                         sel_verts_defgroup(1);
1826                         allqueue (REDRAWVIEW3D, 1);
1827                         break;
1828                 case B_DESELVGROUP:
1829                         sel_verts_defgroup(0);
1830                         allqueue (REDRAWVIEW3D, 1);
1831                         break;
1832                 case B_DELSTICKY:
1833
1834                         if(me->msticky) MEM_freeN(me->msticky);
1835                         me->msticky= NULL;
1836                         allqueue(REDRAWBUTSEDIT, 0);
1837                         break;
1838                 case B_MAKESTICKY:
1839                         make_sticky();
1840                         break;
1841                 
1842                 case B_MAKEEDGES:
1843                         /* in editmode we only have to set edge pointer */
1844                         if(ob==G.obedit) {
1845                                 me->medge= MEM_callocN(sizeof(MEdge), "fake mesh edge");
1846                                 me->totedge= 1;
1847                         }
1848                         else make_edges(me);
1849                         allqueue(REDRAWBUTSEDIT, 0);
1850                         break;
1851                 case B_DELEDGES:
1852                         if(me->medge) MEM_freeN(me->medge);
1853                         me->medge= NULL;
1854                         me->totedge= 0;
1855                         makeDispList(ob);
1856                         allqueue(REDRAWBUTSEDIT, 0);
1857                         allqueue(REDRAWVIEW3D, 0);
1858                         break;
1859                         
1860                 case B_MAKEVERTCOL:
1861                         make_vertexcol();
1862                         break;
1863                 case B_DELVERTCOL:
1864                         if(me->mcol) MEM_freeN(me->mcol);
1865                         me->mcol= NULL;
1866                         G.f &= ~G_VERTEXPAINT;
1867                         freedisplist(&(ob->disp));
1868                         allqueue(REDRAWBUTSEDIT, 0);
1869                         allqueue(REDRAWVIEW3D, 0);
1870                         break;
1871
1872                 case B_MAKE_TFACES:
1873                         make_tfaces(me);
1874                         allqueue(REDRAWBUTSEDIT, 0);
1875                         break;
1876
1877                 case B_DEL_TFACES:
1878                         if(me->tface) MEM_freeN(me->tface);
1879                         me->tface= 0;
1880                         G.f &= ~G_FACESELECT;
1881                         allqueue(REDRAWBUTSEDIT, 0);
1882                         allqueue(REDRAWVIEW3D, 0);
1883                         allqueue(REDRAWIMAGE, 0);
1884                         break;
1885
1886                 case B_FLIPNORM:
1887                         if(G.obedit) {
1888                                 flip_editnormals();
1889                         }
1890                         else flipnorm_mesh( get_mesh(ob) );
1891
1892                         allqueue(REDRAWVIEW3D, 0);
1893                         break;
1894
1895                 case B_DECIM_FACES:
1896                         decimate_faces();
1897                         break;
1898                 case B_DECIM_CANCEL:
1899                         decimate_cancel();
1900                         break;
1901                 case B_DECIM_APPLY:
1902                         decimate_apply();
1903                         break;
1904
1905                 case B_SLOWERDRAW:
1906                         slowerdraw();
1907                         break;
1908                 case B_FASTERDRAW:
1909                         fasterdraw();
1910                         break;
1911                 }
1912         }
1913
1914         if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return;
1915
1916         switch(event) {
1917         case B_SPIN:
1918                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 0);
1919                 break;
1920         case B_SPINDUP:
1921                 if( select_area(SPACE_VIEW3D)) spin_mesh(step, degr, 0, 1);
1922                 break;
1923         case B_EXTR:
1924                 G.f |= G_DISABLE_OK;
1925                 if( select_area(SPACE_VIEW3D)) extrude_mesh();
1926                 G.f -= G_DISABLE_OK;
1927                 break;
1928         case B_SCREW:
1929                 if( select_area(SPACE_VIEW3D)) screw_mesh(step, turn);
1930                 break;
1931         case B_EXTREP:
1932                 if( select_area(SPACE_VIEW3D)) extrude_repeat_mesh(step, extr_offs);
1933                 break;
1934         case B_SPLIT:
1935                 G.f |= G_DISABLE_OK;
1936                 split_mesh();
1937                 G.f -= G_DISABLE_OK;
1938                 break;
1939         case B_REMDOUB:
1940                 undo_push_mesh("Rem Doubles");
1941                 notice("Removed: %d", removedoublesflag(1, doublimit));
1942                 allqueue(REDRAWVIEW3D, 0);
1943                 break;
1944         case B_SUBDIV:
1945                 waitcursor(1);
1946                 undo_push_mesh("Subdivide");
1947                 subdivideflag(1, 0.0, editbutflag & B_BEAUTY);
1948                 countall();
1949                 waitcursor(0);
1950                 allqueue(REDRAWVIEW3D, 0);
1951                 break;
1952         case B_FRACSUBDIV:
1953                 randfac= 10;
1954                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
1955                 waitcursor(1);
1956                 undo_push_mesh("Fractal Subdivide");
1957                 fac= -( (float)randfac )/100;
1958                 subdivideflag(1, fac, editbutflag & B_BEAUTY);
1959                 countall();
1960                 waitcursor(0);
1961                 allqueue(REDRAWVIEW3D, 0);
1962                 break;
1963         case B_XSORT:
1964                 if( select_area(SPACE_VIEW3D)) xsortvert_flag(1);
1965                 break;
1966         case B_HASH:
1967                 hashvert_flag(1);
1968                 break;
1969         case B_TOSPHERE:
1970                 vertices_to_sphere();
1971                 break;
1972         case B_VERTEXNOISE:
1973                 vertexnoise();
1974                 break;
1975         case B_VERTEXSMOOTH:
1976                 vertexsmooth();
1977                 break;
1978         }
1979         /* WATCH IT: previous events only in editmode! */
1980 }
1981
1982 static void editing_panel_mesh_tools(Object *ob, Mesh *me)
1983 {
1984         uiBlock *block;
1985
1986         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools", UI_EMBOSS, UI_HELV, curarea->win);
1987         if(uiNewPanel(curarea, block, "Mesh Tools", "Editing", 640, 0, 318, 204)==0) return;
1988
1989         uiBlockBeginAlign(block);
1990         uiDefButS(block, TOG|BIT|2, 0, "Beauty",                10,195,80,19, &editbutflag, 0, 0, 0, 0, "Causes 'Subdivide' to split faces in halves instead of quarters");
1991         uiDefBut(block, BUT,B_SUBDIV,"Subdivide",               90,195,80,19, 0, 0, 0, 0, 0, "Splits selected faces into halves or quarters");
1992         uiDefBut(block, BUT,B_FRACSUBDIV, "Fract Subd", 170,195,85,19, 0, 0, 0, 0, 0, "Subdivides selected faces with a random factor");
1993
1994         uiDefBut(block, BUT,B_VERTEXNOISE,"Noise",              10,175,80,19, 0, 0, 0, 0, 0, "Use vertex coordinate as texture coordinate");
1995         uiDefBut(block, BUT,B_HASH,"Hash",                              90,175,80,19, 0, 0, 0, 0, 0, "Randomizes selected vertice sequence data");
1996         uiDefBut(block, BUT,B_XSORT,"Xsort",                    170,175,85,19, 0, 0, 0, 0, 0, "Sorts selected vertice data in the X direction");
1997
1998         uiDefBut(block, BUT,B_TOSPHERE,"To Sphere",             10,155,80,19, 0, 0, 0, 0, 0, "Moves selected vertices outwards into a spherical shape");
1999         uiDefBut(block, BUT,B_VERTEXSMOOTH,"Smooth",    90,155,80,19, 0, 0, 0, 0, 0, "Flattens angles of selected faces");
2000         uiDefBut(block, BUT,B_SPLIT,"Split",                    170,155,85,19, 0, 0, 0, 0, 0, "Splits selected verts to separate sub-mesh.");
2001
2002         uiDefBut(block, BUT,B_FLIPNORM,"Flip Normals",  10,135,80,19, 0, 0, 0, 0, 0, "Toggles the direction of the selected face's normals");
2003         uiDefBut(block, BUT,B_REMDOUB,"Rem Doubles",    90,135,80,19, 0, 0, 0, 0, 0, "Removes duplicates from selected vertices");
2004         uiDefButF(block, NUM, B_DIFF, "Limit:",                 170,135,85,19, &doublimit, 0.0001, 1.0, 10, 0, "Specifies the max distance 'Rem Doubles' will consider vertices as 'doubled'");
2005         uiBlockEndAlign(block);
2006
2007         uiDefBut(block, BUT,B_EXTR,"Extrude",                   10,105,245,24, 0, 0, 0, 0, 0, "Converts selected edges to faces and selects the new vertices");
2008
2009         uiBlockBeginAlign(block);
2010         uiDefBut(block, BUT,B_SCREW,"Screw",                    10,75,80,24, 0, 0, 0, 0, 0, "Activates the screw tool");  // Bish - This could use some more definition
2011         uiDefBut(block, BUT,B_SPIN, "Spin",                             90,75,80,24, 0, 0, 0, 0, 0, "Extrudes the selected vertices in a circle around the cursor in the indicated viewport");
2012         uiDefBut(block, BUT,B_SPINDUP,"Spin Dup",               170,75,85,24, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a circle around the cursor in the indicated viewport");
2013
2014         uiDefButS(block, NUM, B_DIFF, "Degr:",                  10,55,80,19, &degr,10.0,360.0, 0, 0, "Specifies the number of degrees 'Spin' revolves");
2015         uiDefButS(block, NUM, B_DIFF, "Steps:",                 90,55,80,19, &step,1.0,180.0, 0, 0, "Specifies the total number of 'Spin' slices");
2016         uiDefButS(block, NUM, B_DIFF, "Turns:",                 170,55,85,19, &turn,1.0,360.0, 0, 0, "Specifies the number of revolutions the screw turns");
2017         uiDefButS(block, TOG|BIT|1, B_DIFF, "Keep Original",10,35,160,19, &editbutflag, 0, 0, 0, 0, "Keeps a copy of the original vertices and faces after executing tools");
2018         uiDefButS(block, TOG|BIT|0, B_DIFF, "Clockwise",        170,35,85,19, &editbutflag, 0, 0, 0, 0, "Specifies the direction for 'Screw' and 'Spin'");
2019
2020         uiBlockBeginAlign(block);
2021         uiDefBut(block, BUT,B_EXTREP, "Extrude Dup",    10,10,120,19, 0, 0, 0, 0, 0, "Creates copies of the selected vertices in a straight line away from the current viewport");
2022         uiDefButF(block, NUM, B_DIFF, "Offset:",                130,10,125,19, &extr_offs, 0.01, 100.0, 100, 0, "Sets the distance between each copy for 'Extrude Dup'");
2023         uiBlockEndAlign(block);
2024 }
2025
2026 static void verify_vertexgroup_name_func(void *datav, void *data2_unused)
2027 {
2028         unique_vertexgroup_name((bDeformGroup*)datav, OBACT);
2029 }
2030
2031
2032
2033 static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
2034 {
2035         uiBlock *block;
2036
2037
2038         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_tools1", UI_EMBOSS, UI_HELV, curarea->win);
2039         if(uiNewPanel(curarea, block, "Mesh Tools 1", "Editing", 960, 0, 318, 204)==0) return;
2040
2041         uiBlockBeginAlign(block);
2042         uiDefBut(block, BUT,B_DOCENTRE, "Centre",               1091, 200, 166, 19, 0, 0, 0, 0, 0, "Shifts object data to be centered about object's origin");
2043         uiDefBut(block, BUT,B_HIDE,             "Hide",                 1091, 180,  77, 19, 0, 0, 0, 0, 0, "Hides selected faces");
2044         uiDefBut(block, BUT,B_REVEAL,   "Reveal",               1171, 180,  86, 19, 0, 0, 0, 0, 0, "Reveals selected faces");
2045         uiDefBut(block, BUT,B_SELSWAP,  "Select Swap",  1091, 160, 166, 19, 0, 0, 0, 0, 0, "Selects unselected faces, and deselects selected faces");
2046         uiBlockEndAlign(block);
2047
2048         uiBlockBeginAlign(block);
2049         uiDefButF(block, NUM,             REDRAWVIEW3D, "NSize:",               1090, 131, 166, 19, &editbutsize, 0.001, 2.0, 10, 0, "Sets the length to use when displaying face normals");
2050         uiDefButI(block, TOG|BIT|6, REDRAWVIEW3D, "Draw Normals",       1090,110,166,19, &G.f, 0, 0, 0, 0, "Displays face normals as lines");
2051         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces",         1090,88,166,19, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2052         uiDefButI(block, TOG|BIT|18, REDRAWVIEW3D, "Draw Edges",        1090,66,166,19, &G.f, 0, 0, 0, 0, "Displays selected edges using hilights");
2053         uiDefButI(block, TOG|BIT|19, REDRAWVIEW3D, "Draw Creases",      1090,44,166,19, &G.f, 0, 0, 0, 0, "Displays creased edges using hilights");
2054         uiDefButI(block, TOG|BIT|20, REDRAWVIEW3D, "Draw Seams",        1090,22,166,19, &G.f, 0, 0, 0, 0, "Displays UV unwrapping seams");
2055         uiDefButI(block, TOG|BIT|11, 0, "All Edges",                            1090, 0,166,19, &G.f, 0, 0, 0, 0, "Displays all edges in object mode without optimization");
2056         uiBlockEndAlign(block);
2057
2058 }
2059
2060 static void editing_panel_links(Object *ob)
2061 {
2062         uiBlock *block;
2063         ID *id, *idfrom;
2064         int *poin, xco=143;
2065         float min;
2066         Material *ma;
2067         char str[64];
2068         uiBut *but;
2069
2070         block= uiNewBlock(&curarea->uiblocks, "editing_panel_links", UI_EMBOSS, UI_HELV, curarea->win);
2071         if(uiNewPanel(curarea, block, "Link and Materials", "Editing", 0, 0, 318, 204)==0) return;
2072
2073         buttons_active_id(&id, &idfrom);
2074
2075         if(id) {
2076                 int alone= 0;
2077                 int local= 0;
2078                 int browse= B_EDITBROWSE;
2079
2080                 if(ob->type==OB_MESH) {
2081                         browse= B_MESHBROWSE;
2082                         alone= B_MESHALONE;
2083                         local= B_MESHLOCAL;
2084                         uiSetButLock(G.obedit!=0, "Unable to perform function in EditMode");
2085                 }
2086                 else if(ob->type==OB_MBALL) {
2087                         alone= B_MBALLALONE;
2088                         local= B_MBALLLOCAL;
2089                 }
2090                 else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
2091                         alone= B_CURVEALONE;
2092                         local= B_CURVELOCAL;
2093                 }
2094                 else if(ob->type==OB_CAMERA) {
2095                         alone= B_CAMERAALONE;
2096                         local= B_CAMERALOCAL;
2097                 }
2098                 else if(ob->type==OB_LAMP) {
2099                         alone= B_LAMPALONE;
2100                         local= B_LAMPLOCAL;
2101                 }
2102                 else if (ob->type==OB_ARMATURE){
2103                         alone = B_ARMALONE;
2104                         local = B_ARMLOCAL;
2105                 }
2106                 else if(ob->type==OB_LATTICE) {
2107                         alone= B_LATTALONE;
2108                         local= B_LATTLOCAL;
2109                 }
2110                 uiBlockSetCol(block, TH_BUT_SETTING2);
2111                 xco= std_libbuttons(block, 143, 180, 0, NULL, browse, id, idfrom, &(G.buts->menunr), alone, local, 0, 0, B_KEEPDATA);
2112                 uiBlockSetCol(block, TH_AUTO);
2113         }
2114         if(ob) {
2115                 but = uiDefBut(block, TEX, B_IDNAME, "OB:",     xco, 180, 454-xco, YIC, ob->id.name+2, 0.0, 19.0, 0, 0, "Displays Active Object name. Click to change.");
2116                 uiButSetFunc(but, test_idbutton_cb, ob->id.name, NULL);
2117         }
2118
2119
2120
2121         /* to be sure */
2122         if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL);
2123         else return;
2124
2125
2126         if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag );
2127         else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag );
2128         else poin= &( ((Curve *)ob->data)->texflag );
2129         uiDefButI(block, TOG|BIT|0, B_AUTOTEX, "AutoTexSpace",  143,15,140,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object");
2130
2131         sprintf(str,"%d Mat:", ob->totcol);
2132         if(ob->totcol) min= 1.0; else min= 0.0;
2133         ma= give_current_material(ob, ob->actcol);
2134
2135         if(ma) uiDefBut(block, LABEL, 0, ma->id.name+2, 318,153, 103, 20, 0, 0, 0, 0, 0, "");
2136
2137         uiBlockBeginAlign(block);
2138         if(ma) uiDefButF(block, COL, B_REDR, "",                        291,123,24,30, &(ma->r), 0, 0, 0, 0, "");
2139         uiDefButC(block, NUM, B_REDR,   str,            318,123,103,30, &ob->actcol, min, (float)(ob->totcol), 0, 0, "Displays total number of material indices and the current index");
2140         uiDefBut(block, BUT,B_MATWICH,  "?",            423,123,31,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces");
2141
2142         uiBlockBeginAlign(block);
2143         uiDefBut(block, BUT,B_MATNEW,   "New",          292,98,80,20, 0, 0, 0, 0, 0, "Adds a new Material index");
2144         uiDefBut(block, BUT,B_MATDEL,   "Delete",       374,98,80,20, 0, 0, 0, 0, 0, "Deletes this Material index");
2145         uiDefBut(block, BUT,B_MATSEL,   "Select",       292,76,80,20, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index");
2146         uiDefBut(block, BUT,B_MATDESEL, "Deselect",     374,76,80,20, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber");
2147         uiDefBut(block, BUT,B_MATASS,   "Assign",       292,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces");
2148
2149         uiBlockBeginAlign(block);
2150         uiDefBut(block, BUT,B_SETSMOOTH,"Set Smooth",   291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces");
2151         uiDefBut(block, BUT,B_SETSOLID, "Set Solid",    373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces");
2152         uiBlockEndAlign(block);
2153
2154         /* vertex group... partially editmode... */
2155         if(ob->type==OB_MESH) {
2156                 uiBut *but;
2157                 int     defCount;
2158                 bDeformGroup    *defGroup;
2159                 char *s, *menustr;
2160                 bDeformGroup *dg;
2161                 int min, index;
2162                 char (*qsort_ptr)[32] = NULL;
2163
2164                 uiDefBut(block, LABEL,0,"Vertex Groups",
2165                                  143,153,130,20, 0, 0, 0, 0, 0, "");
2166
2167                 defCount=BLI_countlist(&ob->defbase);
2168
2169                 if (!defCount) min=0;
2170                 else min=1;
2171
2172                 if (defCount > 0) {
2173                         /*
2174                          * This will hold the group names temporarily
2175                          * so we can sort them
2176                          */
2177                         qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
2178                                                                          "qsort_ptr");
2179                         for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
2180                                 snprintf (qsort_ptr[index - 1], sizeof (qsort_ptr[0]),
2181                                                   "%s%%x%d|", dg->name, index);
2182                         }
2183
2184                         qsort (qsort_ptr, defCount, sizeof (qsort_ptr[0]),
2185                                    ( int (*)(const void *, const void *) ) strcmp);
2186                 }
2187
2188                 s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
2189                 for (index = 0; index < defCount; index++) {
2190                         int cnt= sprintf (s, "%s", qsort_ptr[index]);
2191                         if (cnt>0) s+= cnt;
2192                 }
2193
2194                 if (qsort_ptr)
2195                   MEM_freeN (qsort_ptr);
2196
2197                 uiBlockBeginAlign(block);
2198                 if (defCount)
2199                         uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr,
2200                                           143, 132,18,21, &ob->actdef, min, defCount, 0, 0,
2201                                           "Browses available vertex groups");
2202
2203                 MEM_freeN (menustr);
2204
2205                 if (ob->actdef){
2206                         defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
2207                         but= uiDefBut(block, TEX,REDRAWBUTSEDIT,"",             161,132,140-18,21, defGroup->name, 0, 32, 0, 0, "Displays current vertex group name. Click to change. (Match bone name for deformation.)");
2208                         uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL);
2209
2210                         uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:",          143, 111, 140, 21, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength");
2211                 }
2212                 uiBlockEndAlign(block);
2213
2214                 if (G.obedit && G.obedit==ob){
2215                         uiBlockBeginAlign(block);
2216         /*              uiDefBut(block, BUT,B_AUTOVGROUP,"Auto Weight",                 740,by-=22,93,18, 0, 0, 0, 0, 0, "Automatically assigns deformation groups"); */
2217                         uiDefBut(block, BUT,B_NEWVGROUP,"New",                  143,90,70,21, 0, 0, 0, 0, 0, "Creates a new vertex group");
2218                         uiDefBut(block, BUT,B_DELVGROUP,"Delete",               213,90,70,21, 0, 0, 0, 0, 0, "Removes the current vertex group");
2219
2220                         uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign",    143,69,70,21, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group");
2221                         uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove",    213,69,70,21, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group");
2222
2223                         uiDefBut(block, BUT,B_SELVGROUP,"Select",               143,48,70,21, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group");
2224                         uiDefBut(block, BUT,B_DESELVGROUP,"Desel.",             213,48,70,21, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group");
2225                         uiBlockEndAlign(block);
2226                 }
2227         }
2228
2229
2230 }
2231
2232 /* *************************** FACE/PAINT *************************** */
2233
2234 void do_fpaintbuts(unsigned short event)
2235 {
2236         Mesh *me;
2237         Object *ob;
2238         extern TFace *lasttface; /* caches info on tface bookkeeping ?*/
2239
2240         ob= OBACT;
2241         if(ob==0) return;
2242
2243         switch(event) {
2244
2245         case B_VPGAMMA:
2246                 vpaint_dogamma();
2247                 break;
2248         case B_COPY_TF_MODE:
2249         case B_COPY_TF_UV:
2250         case B_COPY_TF_COL:
2251         case B_COPY_TF_TEX:
2252                 me= get_mesh(ob);
2253                 if(me && me->tface) {
2254 /*                      extern TFace *lasttface; */
2255                         TFace *tface= me->tface;
2256                         int a= me->totface;
2257
2258                         set_lasttface();
2259                         if(lasttface) {
2260
2261                                 while(a--) {
2262                                         if(tface!=lasttface && (tface->flag & TF_SELECT)) {
2263                                                 if(event==B_COPY_TF_MODE) {
2264                                                         tface->mode= lasttface->mode;
2265                                                         tface->transp= lasttface->transp;
2266                                                 }
2267                                                 else if(event==B_COPY_TF_UV) {
2268                                                         memcpy(tface->uv, lasttface->uv, sizeof(tface->uv));
2269                                                         tface->tpage= lasttface->tpage;
2270                                                         tface->tile= lasttface->tile;
2271
2272                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2273                                                         else tface->mode &= ~TF_TILES;
2274
2275                                                 }
2276                                                 else if(event==B_COPY_TF_TEX) {
2277                                                         tface->tpage= lasttface->tpage;
2278                                                         tface->tile= lasttface->tile;
2279
2280                                                         if(lasttface->mode & TF_TILES) tface->mode |= TF_TILES;
2281                                                         else tface->mode &= ~TF_TILES;
2282                                                 }
2283                                                 else if(event==B_COPY_TF_COL) memcpy(tface->col, lasttface->col, sizeof(tface->col));
2284                                         }
2285                                         tface++;
2286                                 }
2287                         }
2288                         do_shared_vertexcol(me);
2289                         allqueue(REDRAWVIEW3D, 0);
2290                         allqueue(REDRAWIMAGE, 0);
2291                 }
2292                 break;
2293         case B_SET_VCOL:
2294                 clear_vpaint_selectedfaces();
2295                 break;
2296         case B_REDR_3D_IMA:
2297                 allqueue(REDRAWVIEW3D, 0);
2298                 allqueue(REDRAWIMAGE, 0);
2299                 break;
2300         case B_ASSIGNMESH:
2301
2302                 test_object_materials(ob->data);
2303                 allqueue(REDRAWVIEW3D, 0);
2304                 allqueue(REDRAWBUTSEDIT, 0);
2305                 break;
2306
2307         case B_TFACE_HALO:
2308                 set_lasttface();
2309                 if(lasttface) {
2310                         lasttface->mode &= ~TF_BILLBOARD2;
2311                         allqueue(REDRAWBUTSEDIT, 0);
2312                 }
2313                 break;
2314
2315         case B_TFACE_BILLB:
2316                 set_lasttface();
2317                 if(lasttface) {
2318                         lasttface->mode &= ~TF_BILLBOARD;
2319                         allqueue(REDRAWBUTSEDIT, 0);
2320                 }
2321                 break;
2322         }
2323 }
2324
2325
2326 /* -------------------- MODE: vpaint faceselect ------------------- */
2327
2328 static void editing_panel_mesh_paint(void)
2329 {
2330         extern VPaint Gvp;         /* from vpaint */
2331         uiBlock *block;
2332
2333         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_paint", UI_EMBOSS, UI_HELV, curarea->win);
2334         if(uiNewPanel(curarea, block, "Paint", "Editing", 640, 0, 318, 204)==0) return;
2335
2336         uiBlockBeginAlign(block);
2337         uiDefButF(block, NUMSLI, 0, "R ",                       979,160,194,19, &Gvp.r, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of red used for painting");
2338         uiDefButF(block, NUMSLI, 0, "G ",                       979,140,194,19, &Gvp.g, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of green used for painting");
2339         uiDefButF(block, NUMSLI, 0, "B ",                       979,120,194,19, &Gvp.b, 0.0, 1.0, B_VPCOLSLI, 0, "The amount of blue used for painting");
2340         uiBlockEndAlign(block);
2341
2342         uiDefButF(block, NUMSLI, 0, "Opacity ",         979,100,194,19, &Gvp.a, 0.0, 1.0, 0, 0, "The amount of pressure on the brush");
2343         uiDefButF(block, NUMSLI, 0, "Size ",            979,80,194,19, &Gvp.size, 2.0, 64.0, 0, 0, "The size of the brush");
2344
2345         uiDefButF(block, COL, B_REDR, "",               1176,100,28,80, &(Gvp.r), 0, 0, 0, B_VPCOLSLI, "");
2346         uiBlockBeginAlign(block);
2347         uiDefButS(block, ROW, B_DIFF, "Mix",                    1212,160,63,19, &Gvp.mode, 1.0, 0.0, 0, 0, "Mix the vertex colours");
2348         uiDefButS(block, ROW, B_DIFF, "Add",                    1212,140,63,19, &Gvp.mode, 1.0, 1.0, 0, 0, "Add the vertex colour");
2349         uiDefButS(block, ROW, B_DIFF, "Sub",                    1212, 120,63,19, &Gvp.mode, 1.0, 2.0, 0, 0, "Subtract from the vertex colour");
2350         uiDefButS(block, ROW, B_DIFF, "Mul",                    1212, 100,63,19, &Gvp.mode, 1.0, 3.0, 0, 0, "Multiply the vertex colour");
2351         uiDefButS(block, ROW, B_DIFF, "Filter",         1212, 80,63,19, &Gvp.mode, 1.0, 4.0, 0, 0, "Mix the colours with an alpha factor");
2352
2353         uiBlockBeginAlign(block);
2354         uiDefButS(block, TOG|BIT|1, 0, "Area",          980,50,80,19, &Gvp.flag, 0, 0, 0, 0, "Set the area the brush covers");
2355         uiDefButS(block, TOG|BIT|2, 0, "Soft",          1061,50,112,19, &Gvp.flag, 0, 0, 0, 0, "Use a soft brush");
2356         uiDefButS(block, TOG|BIT|3, 0, "Normals",       1174,50,102,19, &Gvp.flag, 0, 0, 0, 0, "Use vertex normal for painting");
2357
2358         uiBlockBeginAlign(block);
2359         uiDefBut(block, BUT, B_VPGAMMA, "Set",  980,30,80,19, 0, 0, 0, 0, 0, "Apply Mul and Gamma to vertex colours");
2360         uiDefButF(block, NUM, B_DIFF, "Mul:",           1061,30,112,19, &Gvp.mul, 0.1, 50.0, 10, 0, "Set the number to multiply vertex colours with");
2361         uiDefButF(block, NUM, B_DIFF, "Gamma:",         1174,30,102,19, &Gvp.gamma, 0.1, 5.0, 10, 0, "Change the clarity of the vertex colours");
2362         uiBlockEndAlign(block);
2363
2364         uiDefBut(block, BUT, B_SET_VCOL, "Set VertCol", 980,5,80,20, 0, 0, 0, 0, 0, "Set Vertex colour of selection to current (Shift+K)");
2365
2366 }
2367
2368 static void editing_panel_mesh_texface(void)
2369 {
2370         uiBlock *block;
2371         extern TFace *lasttface;
2372
2373         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_texface", UI_EMBOSS, UI_HELV, curarea->win);
2374         if(uiNewPanel(curarea, block, "Texture face", "Editing", 960, 0, 318, 204)==0) return;
2375
2376         set_lasttface();        // checks for ob type
2377         if(lasttface) {
2378
2379                 uiBlockBeginAlign(block);
2380                 uiDefButS(block, TOG|BIT|2, B_REDR_3D_IMA, "Tex",       600,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face with texture");
2381                 uiDefButS(block, TOG|BIT|7, B_REDR_3D_IMA, "Tiles",     660,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use tilemode for face");
2382                 uiDefButS(block, TOG|BIT|4, REDRAWVIEW3D, "Light",      720,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use light for face");
2383                 uiDefButS(block, TOG|BIT|10, REDRAWVIEW3D, "Invisible",780,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Make face invisible");
2384                 uiDefButS(block, TOG|BIT|0, REDRAWVIEW3D, "Collision", 840,160,60,19, &lasttface->mode, 0, 0, 0, 0, "Use face for collision detection");
2385
2386                 uiBlockBeginAlign(block);
2387                 uiDefButS(block, TOG|BIT|6, REDRAWVIEW3D, "Shared",     600,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Blend vertex colours across face when vertices are shared");
2388                 uiDefButS(block, TOG|BIT|9, REDRAWVIEW3D, "Twoside",660,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Render face twosided");
2389                 uiDefButS(block, TOG|BIT|11, REDRAWVIEW3D, "ObColor",720,135,60,19, &lasttface->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colours");
2390
2391                 uiBlockBeginAlign(block);
2392                 uiDefButS(block, TOG|BIT|8, B_TFACE_HALO, "Halo",       600,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Screen aligned billboard");
2393                 uiDefButS(block, TOG|BIT|12, B_TFACE_BILLB, "Billboard",660,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
2394                 uiDefButS(block, TOG|BIT|13, REDRAWVIEW3D, "Shadow", 720,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Face is used for shadow");
2395                 uiDefButS(block, TOG|BIT|14, REDRAWVIEW3D, "Text", 780,110,60,19, &lasttface->mode, 0, 0, 0, 0, "Enable bitmap text on face");
2396
2397                 uiBlockBeginAlign(block);
2398                 uiBlockSetCol(block, TH_BUT_SETTING1);
2399                 uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque",   600,80,60,19, &lasttface->transp, 2.0, 0.0, 0, 0, "Render colour of textured face as colour");
2400                 uiDefButC(block, ROW, REDRAWVIEW3D, "Add",              660,80,60,19, &lasttface->transp, 2.0, 1.0, 0, 0, "Render face transparent and add colour of face");
2401                 uiDefButC(block, ROW, REDRAWVIEW3D, "Alpha",    720,80,60,19, &lasttface->transp, 2.0, 2.0, 0, 0, "Render polygon transparent, depending on alpha channel of the texture");
2402
2403                 uiBlockSetCol(block, TH_AUTO);
2404                 uiBlockBeginAlign(block);
2405                 uiDefBut(block, BUT, B_COPY_TF_MODE, "Copy DrawMode", 600,7,117,28, 0, 0, 0, 0, 0, "Copy the drawmode from active face to selected faces");
2406                 uiDefBut(block, BUT, B_COPY_TF_UV, "Copy UV+tex",         721,7,85,28, 0, 0, 0, 0, 0, "Copy UV information and textures from active face to selected faces");
2407                 uiDefBut(block, BUT, B_COPY_TF_COL, "Copy VertCol",       809,7,103,28, 0, 0, 0, 0, 0, "Copy vertex colours from active face to selected faces");
2408         }
2409
2410 }
2411
2412 void do_uvautocalculationbuts(unsigned short event)
2413 {
2414         switch(event) {
2415         case B_UVAUTO_STD1:
2416         case B_UVAUTO_STD2:
2417         case B_UVAUTO_STD4:
2418         case B_UVAUTO_STD8:
2419         case B_UVAUTO_CUBE:
2420                 calculate_uv_map(event);
2421                 break;
2422         case B_UVAUTO_BOUNDS1:
2423         case B_UVAUTO_BOUNDS2:
2424         case B_UVAUTO_BOUNDS4:
2425         case B_UVAUTO_BOUNDS8:
2426         case B_UVAUTO_SPHERE:
2427         case B_UVAUTO_CYLINDER:
2428         case B_UVAUTO_WINDOW:
2429                 if(select_area(SPACE_VIEW3D)) calculate_uv_map(event);
2430                 break;
2431         case B_UVAUTO_LSCM:
2432                 unwrap_lscm();
2433                 break;
2434         }
2435 }
2436
2437 static void editing_panel_mesh_uvautocalculation(void)
2438 {
2439         uiBlock *block;
2440         int butH= 19, butHB= 20, row= 180, butS= 10;
2441
2442         block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_uvautocalculation", UI_EMBOSS, UI_HELV, curarea->win);
2443         /* make this a tab of "Texture face" to save screen space*/
2444         uiNewPanelTabbed("Texture face", "Editing");
2445         if(uiNewPanel(curarea, block, "UV Calculation", "Editing", 960, 0, 318, 204)==0)
2446                 return;
2447
2448         uiBlockBeginAlign(block);
2449         uiDefBut(block, BUT, B_UVAUTO_LSCM,"LSCM Unwrap",100,row,200,butH, 0, 0, 0, 0, 0, "Applies conformal UV mapping, preserving local angles");
2450         uiBlockEndAlign(block);
2451         row-= butHB+butS;
2452
2453         uiBlockBeginAlign(block);
2454         uiDefBut(block, BUT, B_UVAUTO_STD1,"Standard",100,row,100,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping");
2455         uiDefBut(block, BUT, B_UVAUTO_STD2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/2");
2456         uiDefBut(block, BUT, B_UVAUTO_STD4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/4");
2457         uiDefBut(block, BUT, B_UVAUTO_STD8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies standard UV mapping 1/8");
2458         uiBlockEndAlign(block);
2459         row-= butHB+butS;
2460
2461         uiBlockBeginAlign(block);
2462         uiDefBut(block, BUT, B_UVAUTO_BOUNDS1,"Bounds",100,row,100,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/1");
2463         uiDefBut(block, BUT, B_UVAUTO_BOUNDS2,"/2",200,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/2");
2464         uiDefBut(block, BUT, B_UVAUTO_BOUNDS4,"/4",233,row,34,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/4");
2465         uiDefBut(block, BUT, B_UVAUTO_BOUNDS8,"/8",267,row,33,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping with bounds 1/8");
2466         uiDefBut(block, BUT, B_UVAUTO_WINDOW,"From Window",100,row-butH,200,butH, 0, 0, 0, 0, 0, "Applies planar UV mapping from window");
2467         uiBlockEndAlign(block);
2468         row-= 2*butHB+butS;
2469
2470         uiBlockBeginAlign(block);
2471         uiDefButI(block, TOG|BIT|7, REDRAWVIEW3D, "Draw Faces", 100,row,200,butH, &G.f, 0, 0, 0, 0, "Displays all faces as shades");
2472         uiDefButI(block,TOG|BIT|18,REDRAWVIEW3D,"Draw Edges",100,row-butHB,200,butH,&G.f, 2.0, 0, 0, 0,  "Displays edges of visible faces");
2473         uiDefButI(block,TOG|BIT|21,REDRAWVIEW3D,"Draw Hidden Edges",100,row-2*butHB,200,butH,&G.f, 2.0, 1.0, 0, 0,  "Displays edges of hidden faces");
2474         uiDefButI(block,TOG|BIT|20,REDRAWVIEW3D,"Draw Seams",100,row-3*butHB,200,butH,&G.f, 2.0, 2.0, 0, 0,  "Displays UV unwrapping seams");
2475         uiBlockEndAlign(block);
2476         row-= 4*butHB+butS;
2477
2478         row= 180;
2479
2480         uiBlockBeginAlign(block);
2481         uiDefBut(block, BUT, B_UVAUTO_CUBE,"Cube",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cube UV mapping");
2482         uiDefButF(block, NUM,B_UVAUTO_CUBESIZE ,"Size:",315,row-butHB,200,butH, &uv_calc_cubesize, 0.0001, 100.0, 10, 0, "Defines the cubemap size");
2483         uiBlockEndAlign(block);
2484         row-= 2*butHB+butS;
2485
2486         uiBlockBeginAlign(block);
2487         uiDefBut(block, BUT, B_UVAUTO_SPHERE,"Sphere",315,row,200,butH, 0, 0, 0, 0, 0, "Applies spherical UV mapping");
2488         uiBlockEndAlign(block);
2489         row-= butHB+butS;
2490
2491         uiBlockBeginAlign(block);
2492         uiDefBut(block, BUT, B_UVAUTO_CYLINDER,"Cylinder",315,row,200,butH, 0, 0, 0, 0, 0, "Applies cylindrical UV mapping");
2493         uiDefButF(block, NUM,B_UVAUTO_CYLRADIUS ,"Radius:",315,row-butHB,200,butH, &uv_calc_radius, 0.1, 100.0, 10, 0, "Defines the radius of the UV mapping cylinder");
2494         uiBlockEndAlign(block);
2495         row-= 2*butHB+butS;
2496
2497
2498         uiBlockBeginAlign(block);
2499         uiDefButS(block, ROW,B_UVAUTO_FACE,"View Aligns Face",315,row,200,butH, &uv_calc_mapdir,2.0, 1.0, 0.0,0.0, "View is on equator for cylindrical and spherical UV mapping");
2500         uiDefButS(block, ROW,B_UVAUTO_TOP,"VA Top",315,row-butHB,100,butH, &uv_calc_mapdir,2.0, 0.0, 0.0,0.0, "View is on poles for cylindrical and spherical UV mapping");
2501         uiDefButS(block, ROW,B_UVAUTO_TOP,"Al Obj",415,row-butHB,100,butH, &uv_calc_mapdir,2.0, 2.0, 0.0,0.0, "Align to object for cylindrical and spherical UV mapping");
2502         uiBlockEndAlign(block);
2503         row-= 2*butHB+butS;
2504
2505         uiBlockBeginAlign(block);
2506         uiDefButS(block, ROW,B_UVAUTO_ALIGNX,"Polar ZX",315,row,100,butH, &uv_calc_mapalign,2.0, 0.0, 0.0,0.0, "Polar 0 is X for cylindrical and spherical UV mapping");
2507         uiDefButS(block, ROW,B_UVAUTO_ALIGNY,"Polar ZY",415,row,100,butH, &uv_calc_mapalign,2.0, 1.0, 0.0,0.0, "Polar 0 is Y for cylindrical and spherical UV mapping");
2508         uiBlockEndAlign(block);
2509 }
2510
2511 /* this is a mode context sensitive system */
2512
2513 void editing_panels()
2514 {
2515         Object *ob;
2516         Curve *cu;
2517         MetaBall *mb;
2518         Lattice *lt;
2519         bArmature *arm;
2520         Camera *cam;
2521
2522         ob= OBACT;
2523         if(ob==NULL) return;
2524
2525         switch(ob->type) {
2526         case OB_MESH:
2527                 editing_panel_links(ob); // no editmode!
2528                 editing_panel_mesh_type(ob, ob->data);  // no editmode!
2529                 /* modes */
2530                 if(G.obedit) {
2531                         editing_panel_mesh_tools(ob, ob->data); // no editmode!
2532                         editing_panel_mesh_tools1(ob, ob->data); // no editmode!
2533                 }
2534                 else {
2535                         if(G.f & G_FACESELECT) {
2536                                 editing_panel_mesh_texface();
2537                                 editing_panel_mesh_uvautocalculation();
2538                         }
2539                         if(G.f & (G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT) ) {
2540                                 editing_panel_mesh_paint();
2541                         }
2542                 }
2543                 break;
2544
2545         case OB_CURVE:
2546         case OB_SURF:
2547                 cu= ob->data;
2548                 editing_panel_links(ob); // no editmode!
2549                 editing_panel_curve_type(ob, cu);
2550                 if(G.obedit) {
2551                         editing_panel_curve_tools(ob, cu);
2552                         editing_panel_curve_tools1(ob, cu);
2553                 }
2554                 break;
2555
2556         case OB_MBALL:
2557                 mb= ob->data;
2558                 editing_panel_links(ob); // no editmode!
2559                 editing_panel_mball_type(ob, mb);
2560                 if(G.obedit) {
2561                         editing_panel_mball_tools(ob, mb);
2562                 }
2563                 break;
2564
2565         case OB_FONT:
2566                 cu= ob->data;
2567                 editing_panel_links(ob); // no editmode!
2568                 editing_panel_curve_type(ob, cu);
2569                 editing_panel_font_type(ob, cu);
2570                 break;
2571
2572         case OB_LATTICE:
2573                 lt= ob->data;
2574                 editing_panel_links(ob); // no editmode!
2575                 editing_panel_lattice_type(ob, lt);
2576                 break;
2577
2578         case OB_LAMP:
2579                 editing_panel_links(ob); // no editmode!
2580                 break;
2581
2582         case OB_EMPTY:
2583                 editing_panel_links(ob); // no editmode!
2584                 break;
2585
2586         case OB_CAMERA:
2587                 cam= ob->data;
2588                 editing_panel_links(ob); // no editmode!
2589                 editing_panel_camera_type(ob, cam);
2590                 break;
2591
2592         case OB_ARMATURE:
2593                 arm= ob->data;
2594                 editing_panel_links(ob); // no editmode!
2595                 editing_panel_armature_type(ob, arm);
2596                 if(G.obedit) {
2597                         editing_panel_armature_bones(ob, arm);
2598                 }
2599                 break;
2600         }
2601
2602 }