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