Sculpt:
[blender-staging.git] / source / blender / editors / util / ed_util.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL 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. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <stdlib.h>
30 #include <math.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "DNA_curve_types.h"
35 #include "DNA_mesh_types.h"
36 #include "DNA_object_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_userdef_types.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_editVert.h"
42
43 #include "BKE_context.h"
44 #include "BKE_global.h"
45 #include "BKE_main.h"
46
47 #include "ED_armature.h"
48 #include "ED_mesh.h"
49 #include "ED_sculpt.h"
50 #include "ED_util.h"
51
52 #include "UI_interface.h"
53
54 /* ********* general editor util funcs, not BKE stuff please! ********* */
55
56 /* frees all editmode stuff */
57 void ED_editors_exit(bContext *C)
58 {
59         Scene *sce;
60         
61         /* frees all editmode undos */
62         undo_editmode_clear();
63         ED_undo_paint_free();
64         
65         for(sce=G.main->scene.first; sce; sce= sce->id.next) {
66                 if(sce->obedit) {
67                         Object *ob= sce->obedit;
68                 
69                         /* global in meshtools... */
70                         mesh_octree_table(ob, NULL, NULL, 'e');
71                         
72                         if(ob) {
73                                 if(ob->type==OB_MESH) {
74                                         Mesh *me= ob->data;
75                                         if(me->edit_mesh) {
76                                                 free_editMesh(me->edit_mesh);
77                                                 MEM_freeN(me->edit_mesh);
78                                                 me->edit_mesh= NULL;
79                                         }
80                                 }
81                                 else if(ob->type==OB_ARMATURE) {
82                                         ED_armature_edit_free(ob);
83                                 }
84                                 else if(ob->type==OB_FONT) {
85                                         //                      free_editText();
86                                 }
87                                 //              else if(ob->type==OB_MBALL) 
88                                 //                      BLI_freelistN(&editelems);
89                                 //      free_editLatt();
90                                 //      free_posebuf();
91                         }
92                 }
93         }
94         
95 }
96
97
98 /* ***** XXX: functions are using old blender names, cleanup later ***** */
99
100
101 /* now only used in 2d spaces, like time, ipo, nla, sima... */
102 /* XXX shift/ctrl not configurable */
103 void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert)
104 {
105         /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */
106         if(invert)
107                 ctrl= !ctrl;
108         
109         if(ctrl && shift) {
110                 if(fac3!= 0.0) *val= fac3*floor(*val/fac3 +.5);
111         }
112         else if(ctrl) {
113                 if(fac2!= 0.0) *val= fac2*floor(*val/fac2 +.5);
114         }
115         else {
116                 if(fac1!= 0.0) *val= fac1*floor(*val/fac1 +.5);
117         }
118 }
119
120
121 int GetButStringLength(char *str) 
122 {
123         int rt;
124         
125         rt= UI_GetStringWidth(str);
126         
127         return rt + 15;
128 }
129