4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2009 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
35 #include "DNA_action_types.h"
36 #include "DNA_armature_types.h"
37 #include "DNA_curve_types.h"
38 #include "DNA_camera_types.h"
39 #include "DNA_lamp_types.h"
40 #include "DNA_lattice_types.h"
41 #include "DNA_meta_types.h"
42 #include "DNA_mesh_types.h"
43 #include "DNA_meshdata_types.h"
44 #include "DNA_object_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_scene_types.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_userdef_types.h"
49 #include "DNA_view3d_types.h"
50 #include "DNA_world_types.h"
52 #include "MEM_guardedalloc.h"
54 #include "BLI_arithb.h"
55 #include "BLI_blenlib.h"
56 #include "BLI_editVert.h"
59 #include "BKE_action.h"
60 #include "BKE_brush.h"
61 #include "BKE_context.h"
62 #include "BKE_curve.h"
63 #include "BKE_customdata.h"
64 #include "BKE_depsgraph.h"
65 #include "BKE_idprop.h"
67 #include "BKE_object.h"
68 #include "BKE_global.h"
69 #include "BKE_scene.h"
70 #include "BKE_screen.h"
71 #include "BKE_utildefines.h"
78 #include "RNA_access.h"
79 #include "RNA_define.h"
81 #include "ED_armature.h"
84 #include "ED_keyframing.h"
86 #include "ED_object.h"
87 #include "ED_particle.h"
88 #include "ED_screen.h"
89 #include "ED_transform.h"
93 #include "UI_interface.h"
94 #include "UI_resources.h"
95 #include "UI_view2d.h"
97 #include "view3d_intern.h" // own include
100 /* ******************* view3d space & buttons ************** */
104 static void redo_cb(bContext *C, void *arg_op, void *arg2)
106 wmOperator *lastop= arg_op;
111 printf("operator redo %s\n", lastop->type->name);
112 ED_undo_pop_op(C, lastop);
113 retval= WM_operator_repeat(C, lastop);
114 if((retval & OPERATOR_FINISHED)==0) {
115 printf("operator redo failed %s\n", lastop->type->name);
121 static void view3d_panel_operator_redo_buts(const bContext *C, Panel *pa, wmOperator *op)
123 wmWindowManager *wm= CTX_wm_manager(C);
126 if(!op->properties) {
127 IDPropertyTemplate val = {0};
128 op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
131 RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
132 uiDefAutoButsRNA(C, pa->layout, &ptr, 1);
136 static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
138 wmWindowManager *wm= CTX_wm_manager(C);
142 block= uiLayoutGetBlock(pa->layout);
144 /* only for operators that are registered and did an undo push */
145 for(op= wm->operators.last; op; op= op->prev)
146 if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO))
151 if(op->type->poll && op->type->poll((bContext *)C)==0)
154 uiBlockSetFunc(block, redo_cb, op, NULL);
156 if(op->macro.first) {
157 for(op= op->macro.first; op; op= op->next)
158 view3d_panel_operator_redo_buts(C, pa, op);
161 view3d_panel_operator_redo_buts(C, pa, op);
165 /* ******************* */
167 char *view3d_context_string(const bContext *C)
169 Object *obedit= CTX_data_edit_object(C);
172 switch(obedit->type) {
174 return "editmode_mesh";
176 return "editmode_curve";
178 return "editmode_surface";
180 return "editmode_text";
182 return "editmode_armature";
184 return "editmode_mball";
186 return "editmode_lattice";
190 Object *ob = CTX_data_active_object(C);
192 if(ob && (ob->flag & OB_POSEMODE)) return "pose_mode";
193 else if (ob && ob->mode & OB_MODE_SCULPT) return "sculpt_mode";
194 else if (G.f & G_WEIGHTPAINT) return "weight_paint";
195 else if (G.f & G_VERTEXPAINT) return "vertex_paint";
196 else if (G.f & G_TEXTUREPAINT) return "texture_paint";
197 else if(G.f & G_PARTICLEEDIT) return "particle_mode";
203 typedef struct CustomTool {
204 struct CustomTool *next, *prev;
205 char opname[OP_MAX_TYPENAME];
206 char context[OP_MAX_TYPENAME];
209 static void operator_call_cb(struct bContext *C, void *arg_listbase, void *arg2)
211 wmOperatorType *ot= arg2;
214 CustomTool *ct= MEM_callocN(sizeof(CustomTool), "CustomTool");
216 BLI_addtail(arg_listbase, ct);
217 BLI_strncpy(ct->opname, ot->idname, OP_MAX_TYPENAME);
218 BLI_strncpy(ct->context, view3d_context_string(C), OP_MAX_TYPENAME);
223 static void operator_search_cb(const struct bContext *C, void *arg, char *str, uiSearchItems *items)
225 wmOperatorType *ot = WM_operatortype_first();
227 for(; ot; ot= ot->next) {
229 if(BLI_strcasestr(ot->name, str)) {
230 if(ot->poll==NULL || ot->poll((bContext *)C)) {
232 if(0==uiSearchItemAdd(items, ot->name, ot, 0))
240 /* ID Search browse menu, open */
241 static uiBlock *tool_search_menu(bContext *C, ARegion *ar, void *arg_listbase)
243 static char search[OP_MAX_TYPENAME];
245 wmWindow *win= CTX_wm_window(C);
249 /* clear initial search string, then all items show */
252 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
253 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
255 /* fake button, it holds space for search items */
256 uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
258 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, OP_MAX_TYPENAME, 10, 0, 150, 19, "");
259 uiButSetSearchFunc(but, operator_search_cb, arg_listbase, operator_call_cb, NULL);
261 uiBoundsBlock(block, 6);
262 uiBlockSetDirection(block, UI_DOWN);
263 uiEndBlock(C, block);
265 event= *(win->eventstate); /* XXX huh huh? make api call */
266 event.type= EVT_BUT_OPEN;
268 event.customdata= but;
269 event.customdatafree= FALSE;
270 wm_event_add(win, &event);
276 static void view3d_panel_tool_shelf(const bContext *C, Panel *pa)
278 SpaceLink *sl= CTX_wm_space_data(C);
281 const char *context= view3d_context_string(C);
284 st= BKE_spacetype_from_id(sl->spacetype);
286 if(st && st->toolshelf.first) {
289 for(ct= st->toolshelf.first; ct; ct= ct->next) {
290 if(0==strncmp(context, ct->context, OP_MAX_TYPENAME)) {
291 col= uiLayoutColumn(pa->layout, 1);
292 uiItemFullO(col, NULL, 0, ct->opname, NULL, WM_OP_INVOKE_REGION_WIN);
296 col= uiLayoutColumn(pa->layout, 1);
297 uiDefBlockBut(uiLayoutGetBlock(pa->layout), tool_search_menu, &st->toolshelf, "Add Tool", 0, 0, UI_UNIT_X, UI_UNIT_Y, "Add Tool in shelf, gets saved in files");
301 void view3d_toolbar_register(ARegionType *art)
305 pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel tools");
306 strcpy(pt->idname, "VIEW3D_PT_tool_shelf");
307 strcpy(pt->label, "Tool Shelf");
308 pt->draw= view3d_panel_tool_shelf;
309 BLI_addtail(&art->paneltypes, pt);
312 void view3d_tool_props_register(ARegionType *art)
316 pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel last operator");
317 strcpy(pt->idname, "VIEW3D_PT_last_operator");
318 strcpy(pt->label, "Last Operator");
319 pt->draw= view3d_panel_operator_redo;
320 BLI_addtail(&art->paneltypes, pt);
323 /* ********** operator to open/close toolbar region */
325 static int view3d_toolbar(bContext *C, wmOperator *op)
327 ScrArea *sa= CTX_wm_area(C);
328 ARegion *ar= view3d_has_tools_region(sa);
331 ar->flag ^= RGN_FLAG_HIDDEN;
332 ar->v2d.flag &= ~V2D_IS_INITIALISED; /* XXX should become hide/unhide api? */
334 ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
335 ED_area_tag_redraw(sa);
337 return OPERATOR_FINISHED;
340 void VIEW3D_OT_toolbar(wmOperatorType *ot)
343 ot->idname= "VIEW3D_OT_toolbar";
345 ot->exec= view3d_toolbar;
346 ot->poll= ED_operator_view3d_active;