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