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