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