~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/util/ed_util.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: ed_util.c 29988 2010-07-05 13:14:14Z blendix $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
26
24
 * ***** END GPL LICENSE BLOCK *****
27
25
 */
28
26
 
 
27
/** \file blender/editors/util/ed_util.c
 
28
 *  \ingroup edutil
 
29
 */
 
30
 
 
31
 
29
32
#include <stdlib.h>
 
33
#include <string.h>
30
34
#include <math.h>
31
35
 
32
36
#include "MEM_guardedalloc.h"
33
37
 
 
38
#include "DNA_mesh_types.h"
34
39
#include "DNA_object_types.h"
35
40
#include "DNA_scene_types.h"
 
41
#include "DNA_packedFile_types.h"
36
42
 
37
43
#include "BLI_blenlib.h"
38
 
#include "BLI_editVert.h"
39
44
 
40
45
#include "BKE_context.h"
41
46
#include "BKE_global.h"
42
47
#include "BKE_main.h"
 
48
#include "BKE_utildefines.h"
 
49
#include "BKE_packedFile.h"
43
50
 
44
51
#include "ED_armature.h"
45
52
#include "ED_mesh.h"
48
55
#include "ED_util.h"
49
56
 
50
57
#include "UI_interface.h"
 
58
#include "UI_resources.h"
 
59
 
 
60
#include "WM_types.h"
 
61
#include "WM_api.h"
 
62
#include "RNA_access.h"
 
63
 
 
64
 
51
65
 
52
66
/* ********* general editor util funcs, not BKE stuff please! ********* */
53
67
 
54
68
void ED_editors_init(bContext *C)
55
69
{
56
 
        Main *bmain= CTX_data_main(C);
57
 
        Scene *sce= CTX_data_scene(C);
58
 
        Object *ob, *obact= (sce && sce->basact)? sce->basact->object: NULL;
 
70
        Main *bmain = CTX_data_main(C);
 
71
        Scene *sce = CTX_data_scene(C);
 
72
        Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL;
59
73
        ID *data;
60
74
 
61
75
        /* toggle on modes for objects that were saved with these enabled. for
62
 
           e.g. linked objects we have to ensure that they are actually the
63
 
           active object in this scene. */
64
 
        for(ob=bmain->object.first; ob; ob=ob->id.next) {
65
 
                int mode= ob->mode;
66
 
 
67
 
                if(mode && (mode != OB_MODE_POSE)) {
68
 
                        ob->mode= 0;
69
 
                        data= ob->data;
70
 
 
71
 
                        if(ob == obact && !ob->id.lib && !(data && data->lib))
 
76
         * e.g. linked objects we have to ensure that they are actually the
 
77
         * active object in this scene. */
 
78
        for (ob = bmain->object.first; ob; ob = ob->id.next) {
 
79
                int mode = ob->mode;
 
80
 
 
81
                if (mode && (mode != OB_MODE_POSE)) {
 
82
                        ob->mode = 0;
 
83
                        data = ob->data;
 
84
 
 
85
                        if (ob == obact && !ob->id.lib && !(data && data->lib))
72
86
                                ED_object_toggle_modes(C, mode);
73
87
                }
74
88
        }
77
91
/* frees all editmode stuff */
78
92
void ED_editors_exit(bContext *C)
79
93
{
 
94
        Main *bmain = CTX_data_main(C);
80
95
        Scene *sce;
 
96
 
 
97
        if (!bmain)
 
98
                return;
81
99
        
82
100
        /* frees all editmode undos */
83
101
        undo_editmode_clear();
84
102
        ED_undo_paint_free();
85
103
        
86
 
        for(sce=G.main->scene.first; sce; sce= sce->id.next) {
87
 
                if(sce->obedit) {
88
 
                        Object *ob= sce->obedit;
 
104
        for (sce = bmain->scene.first; sce; sce = sce->id.next) {
 
105
                if (sce->obedit) {
 
106
                        Object *ob = sce->obedit;
89
107
                
90
 
                        /* global in meshtools... */
91
 
                        mesh_octree_table(NULL, NULL, NULL, 'e');
92
 
                        mesh_mirrtopo_table(NULL, 'e');
93
 
                        
94
 
                        if(ob) {
95
 
                                if(ob->type==OB_MESH) {
96
 
                                        Mesh *me= ob->data;
97
 
                                        if(me->edit_mesh) {
98
 
                                                free_editMesh(me->edit_mesh);
99
 
                                                MEM_freeN(me->edit_mesh);
100
 
                                                me->edit_mesh= NULL;
 
108
                        if (ob) {
 
109
                                if (ob->type == OB_MESH) {
 
110
                                        Mesh *me = ob->data;
 
111
                                        if (me->edit_btmesh) {
 
112
                                                EDBM_mesh_free(me->edit_btmesh);
 
113
                                                MEM_freeN(me->edit_btmesh);
 
114
                                                me->edit_btmesh = NULL;
101
115
                                        }
102
116
                                }
103
 
                                else if(ob->type==OB_ARMATURE) {
 
117
                                else if (ob->type == OB_ARMATURE) {
104
118
                                        ED_armature_edit_free(ob);
105
119
                                }
106
 
                                else if(ob->type==OB_FONT) {
107
 
                                        //                      free_editText();
108
 
                                }
109
 
                                //              else if(ob->type==OB_MBALL) 
110
 
                                //                      BLI_freelistN(&editelems);
111
 
                                //      free_editLatt();
112
 
                                //      free_posebuf();         // XXX this is still a global...
113
 
                        }
114
 
                }
115
 
                else if(sce->basact && sce->basact->object) {
116
 
                        Object *ob= sce->basact->object;
117
 
                        
118
 
                        /* if weight-painting is on, free mesh octree data */
119
 
                        if(ob->mode & OB_MODE_WEIGHT_PAINT) {
120
 
                                mesh_octree_table(NULL, NULL, NULL, 'e');
121
 
                                mesh_mirrtopo_table(NULL, 'e');
122
120
                        }
123
121
                }
124
122
        }
125
 
        
 
123
 
 
124
        /* global in meshtools... */
 
125
        mesh_octree_table(NULL, NULL, NULL, 'e');
 
126
        mesh_mirrtopo_table(NULL, 'e');
126
127
}
127
128
 
128
129
 
134
135
void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert)
135
136
{
136
137
        /* fac1 is for 'nothing', fac2 for CTRL, fac3 for SHIFT */
137
 
        if(invert)
138
 
                ctrl= !ctrl;
 
138
        if (invert)
 
139
                ctrl = !ctrl;
139
140
        
140
 
        if(ctrl && shift) {
141
 
                if(fac3!= 0.0) *val= fac3*floor(*val/fac3 +.5);
 
141
        if (ctrl && shift) {
 
142
                if (fac3 != 0.0f) *val = fac3 * floorf(*val / fac3 + 0.5f);
142
143
        }
143
 
        else if(ctrl) {
144
 
                if(fac2!= 0.0) *val= fac2*floor(*val/fac2 +.5);
 
144
        else if (ctrl) {
 
145
                if (fac2 != 0.0f) *val = fac2 * floorf(*val / fac2 + 0.5f);
145
146
        }
146
147
        else {
147
 
                if(fac1!= 0.0) *val= fac1*floor(*val/fac1 +.5);
 
148
                if (fac1 != 0.0f) *val = fac1 * floorf(*val / fac1 + 0.5f);
148
149
        }
149
150
}
150
151
 
151
 
 
152
 
int GetButStringLength(char *str) 
 
152
#if 0 /* UNUSED */
 
153
int GetButStringLength(const char *str) 
153
154
{
154
155
        int rt;
155
156
        
156
 
        rt= UI_GetStringWidth(str);
 
157
        rt = UI_GetStringWidth(str);
157
158
        
158
159
        return rt + 15;
159
160
}
160
 
 
 
161
#endif
 
162
 
 
163
void unpack_menu(bContext *C, const char *opname, const char *id_name, const char *abs_name, const char *folder, struct PackedFile *pf)
 
164
{
 
165
        PointerRNA props_ptr;
 
166
        uiPopupMenu *pup;
 
167
        uiLayout *layout;
 
168
        char line[FILE_MAX + 100];
 
169
        wmOperatorType *ot = WM_operatortype_find(opname, 1);
 
170
 
 
171
        pup = uiPupMenuBegin(C, "Unpack file", ICON_NONE);
 
172
        layout = uiPupMenuLayout(pup);
 
173
 
 
174
        strcpy(line, "Remove Pack");
 
175
        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
176
        RNA_enum_set(&props_ptr, "method", PF_REMOVE);
 
177
        RNA_string_set(&props_ptr, "id", id_name);
 
178
 
 
179
        if (G.relbase_valid) {
 
180
                char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
 
181
 
 
182
                BLI_strncpy(local_name, abs_name, sizeof(local_name));
 
183
                BLI_splitdirstring(local_name, fi);
 
184
                BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi);
 
185
                if (strcmp(abs_name, local_name) != 0) {
 
186
                        switch (checkPackedFile(local_name, pf)) {
 
187
                                case PF_NOFILE:
 
188
                                        BLI_snprintf(line, sizeof(line), "Create %s", local_name);
 
189
                                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
190
                                        RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL);
 
191
                                        RNA_string_set(&props_ptr, "id", id_name);
 
192
 
 
193
                                        break;
 
194
                                case PF_EQUAL:
 
195
                                        BLI_snprintf(line, sizeof(line), "Use %s (identical)", local_name);
 
196
                                        //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL);
 
197
                                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
198
                                        RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL);
 
199
                                        RNA_string_set(&props_ptr, "id", id_name);
 
200
 
 
201
                                        break;
 
202
                                case PF_DIFFERS:
 
203
                                        BLI_snprintf(line, sizeof(line), "Use %s (differs)", local_name);
 
204
                                        //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_LOCAL);
 
205
                                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
206
                                        RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL);
 
207
                                        RNA_string_set(&props_ptr, "id", id_name);
 
208
 
 
209
                                        BLI_snprintf(line, sizeof(line), "Overwrite %s", local_name);
 
210
                                        //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_LOCAL);
 
211
                                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
212
                                        RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL);
 
213
                                        RNA_string_set(&props_ptr, "id", id_name);
 
214
                                        break;
 
215
                        }
 
216
                }
 
217
        }
 
218
 
 
219
        switch (checkPackedFile(abs_name, pf)) {
 
220
                case PF_NOFILE:
 
221
                        BLI_snprintf(line, sizeof(line), "Create %s", abs_name);
 
222
                        //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL);
 
223
                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
224
                        RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL);
 
225
                        RNA_string_set(&props_ptr, "id", id_name);
 
226
                        break;
 
227
                case PF_EQUAL:
 
228
                        BLI_snprintf(line, sizeof(line), "Use %s (identical)", abs_name);
 
229
                        //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL);
 
230
                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
231
                        RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL);
 
232
                        RNA_string_set(&props_ptr, "id", id_name);
 
233
                        break;
 
234
                case PF_DIFFERS:
 
235
                        BLI_snprintf(line, sizeof(line), "Use %s (differs)", abs_name);
 
236
                        //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_USE_ORIGINAL);
 
237
                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
238
                        RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL);
 
239
                        RNA_string_set(&props_ptr, "id", id_name);
 
240
 
 
241
                        BLI_snprintf(line, sizeof(line), "Overwrite %s", abs_name);
 
242
                        //uiItemEnumO_ptr(layout, ot, line, 0, "method", PF_WRITE_ORIGINAL);
 
243
                        props_ptr = uiItemFullO_ptr(layout, ot, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
 
244
                        RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL);
 
245
                        RNA_string_set(&props_ptr, "id", id_name);
 
246
                        break;
 
247
        }
 
248
 
 
249
        uiPupMenuEnd(C, pup);
 
250
}