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