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