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 * Contributor(s): Blender Foundation 2009.
22 * ***** END GPL LICENSE BLOCK *****
28 #include "MEM_guardedalloc.h"
30 #include "DNA_screen_types.h"
32 #include "BLI_string.h"
34 #include "BKE_context.h"
35 #include "BKE_icons.h"
36 #include "BKE_library.h"
37 #include "BKE_utildefines.h"
39 #include "ED_screen.h"
40 #include "ED_previewrender.h"
42 #include "RNA_access.h"
47 #include "UI_interface.h"
48 #include "UI_resources.h"
50 void ui_template_fix_linking()
54 /********************** Header Template *************************/
56 void uiTemplateHeader(uiLayout *layout, bContext *C)
60 block= uiLayoutFreeBlock(layout);
61 ED_area_header_standardbuttons(C, block, 0);
64 /******************* Header ID Template ************************/
66 typedef struct TemplateID {
80 static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
82 TemplateID *template= (TemplateID*)arg_litem;
83 PointerRNA idptr= RNA_property_pointer_get(&template->ptr, template->prop);
85 int event= GET_INT_FROM_POINTER(arg_event);
87 if(event == UI_ID_BROWSE && template->browse == 32767)
89 else if(event == UI_ID_BROWSE && template->browse == 32766)
94 printf("warning, id browse shouldnt come here\n");
97 memset(&idptr, 0, sizeof(idptr));
98 RNA_property_pointer_set(&template->ptr, template->prop, idptr);
99 RNA_property_update(C, &template->ptr, template->prop);
101 case UI_ID_FAKE_USER:
103 if(id->flag & LIB_FAKEUSER) id->us++;
111 WM_operator_name_call(C, template->newop, WM_OP_INVOKE_REGION_WIN, NULL);
114 WM_operator_name_call(C, template->openop, WM_OP_INVOKE_REGION_WIN, NULL);
118 if(!id || id->us < 1)
122 if(!id || id->us < 1)
125 case UI_ID_AUTO_NAME:
131 /* ID Search browse menu, assign */
132 static void id_search_call_cb(struct bContext *C, void *arg_litem, void *item)
135 TemplateID *template= (TemplateID*)arg_litem;
136 PointerRNA idptr= RNA_property_pointer_get(&template->ptr, template->prop);
138 RNA_id_pointer_create(item, &idptr);
139 RNA_property_pointer_set(&template->ptr, template->prop, idptr);
140 RNA_property_update(C, &template->ptr, template->prop);
144 /* ID Search browse menu, do the search */
145 static void id_search_cb(const struct bContext *C, void *arg_litem, char *str, uiSearchItems *items)
147 TemplateID *template= (TemplateID*)arg_litem;
148 ListBase *lb= wich_libbase(CTX_data_main(C), template->idtype);
151 for(id= lb->first; id; id= id->next) {
157 case ID_MA: /* fall through */
158 case ID_TE: /* fall through */
159 case ID_IM: /* fall through */
160 case ID_WO: /* fall through */
161 case ID_LA: /* fall through */
162 iconid= BKE_icon_getid(id);
168 if(BLI_strcasestr(id->name+2, str)) {
169 if(0==uiSearchItemAdd(items, id->name+2, id, iconid))
175 /* ID Search browse menu, open */
176 static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
178 static char search[256];
179 static TemplateID template;
181 wmWindow *win= CTX_wm_window(C);
185 /* clear initial search string, then all items show */
187 /* arg_litem is malloced, can be freed by parent button */
188 template= *((TemplateID*)arg_litem);
190 block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
191 uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
193 /* fake button, it holds space for search items */
194 uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
196 but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
197 uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb);
199 uiBoundsBlock(block, 6);
200 uiBlockSetDirection(block, UI_DOWN);
201 uiEndBlock(C, block);
203 event= *(win->eventstate); /* XXX huh huh? make api call */
204 event.type= EVT_BUT_OPEN;
206 event.customdata= but;
207 event.customdatafree= FALSE;
208 wm_event_add(win, &event);
213 /* ****************** */
216 static void template_header_ID(bContext *C, uiBlock *block, TemplateID *template, StructRNA *type)
222 idptr= RNA_property_pointer_get(&template->ptr, template->prop);
223 lb= wich_libbase(CTX_data_main(C), template->idtype);
228 uiDefIconBut(block, LABEL, 0, RNA_struct_ui_icon(type), 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
230 uiBlockBeginAlign(block);
231 if(template->flag & UI_ID_BROWSE) {
233 char *extrastr, *str;
235 if((template->flag & UI_ID_ADD_NEW) && (template->flag & UI_ID_OPEN))
236 extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
237 else if(template->flag & UI_ID_ADD_NEW)
238 extrastr= "ADD NEW %x 32767";
239 else if(template->flag & UI_ID_OPEN)
240 extrastr= "OPEN NEW %x 32766";
244 duptemplate= MEM_dupallocN(template);
245 IDnames_to_pupstring(&str, NULL, extrastr, lb, idptr.data, &duptemplate->browse);
247 but= uiDefButS(block, MENU, 0, str, 0, 0, UI_UNIT_X, UI_UNIT_Y, &duptemplate->browse, 0, 0, 0, 0, "Browse existing choices, or add new");
248 uiButSetNFunc(but, template_id_cb, duptemplate, SET_INT_IN_POINTER(UI_ID_BROWSE));
252 uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template), "", 0, 0, UI_UNIT_X, UI_UNIT_Y, "Browse ID data");
255 /* text button with name */
259 //text_idbutton(idptr.data, name);
261 but= uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X*6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL);
262 uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
265 if(template->flag & UI_ID_ADD_NEW) {
266 int w= idptr.data?UI_UNIT_X:UI_UNIT_X*6;
268 if(template->newop[0]) {
269 but= uiDefIconTextButO(block, BUT, template->newop, WM_OP_EXEC_REGION_WIN, ICON_ZOOMIN, "Add New", 0, 0, w, UI_UNIT_Y, NULL);
272 but= uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, "Add New", 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
273 uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
278 if(idptr.data && (template->flag & UI_ID_DELETE)) {
279 if(template->unlinkop[0]) {
280 but= uiDefIconButO(block, BUT, template->unlinkop, WM_OP_EXEC_REGION_WIN, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
283 but= uiDefIconBut(block, BUT, 0, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
284 uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_DELETE));
288 uiBlockEndAlign(block);
291 void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, char *newop, char *openop, char *unlinkop)
293 TemplateID *template;
301 prop= RNA_struct_find_property(ptr, propname);
303 if(!prop || RNA_property_type(prop) != PROP_POINTER) {
304 printf("uiTemplateID: pointer property not found: %s\n", propname);
308 template= MEM_callocN(sizeof(TemplateID), "TemplateID");
310 template->prop= prop;
311 template->flag= UI_ID_BROWSE|UI_ID_RENAME|UI_ID_DELETE;
314 template->flag |= UI_ID_ADD_NEW;
315 BLI_strncpy(template->newop, newop, sizeof(template->newop));
318 template->flag |= UI_ID_OPEN;
319 BLI_strncpy(template->openop, openop, sizeof(template->openop));
322 BLI_strncpy(template->unlinkop, unlinkop, sizeof(template->unlinkop));
324 type= RNA_property_pointer_type(ptr, prop);
325 template->idtype = RNA_type_to_ID_code(type);
327 if(template->idtype) {
328 uiLayoutRow(layout, 1);
329 block= uiLayoutGetBlock(layout);
330 template_header_ID(C, block, template, type);
336 /************************ Modifier Template *************************/
338 #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
342 #include "DNA_object_force.h"
343 #include "DNA_object_types.h"
344 #include "DNA_modifier_types.h"
345 #include "DNA_scene_types.h"
347 #include "BKE_depsgraph.h"
348 #include "BKE_DerivedMesh.h"
349 #include "BKE_global.h"
350 #include "BKE_modifier.h"
351 #include "BKE_object.h"
352 #include "BKE_particle.h"
353 #include "BKE_report.h"
355 #include "UI_resources.h"
358 #include "BLI_arithb.h"
359 #include "BLI_listbase.h"
361 #include "ED_object.h"
363 static void modifiers_del(bContext *C, void *ob_v, void *md_v)
365 Scene *scene= CTX_data_scene(C);
369 BKE_reports_init(&reports, RPT_STORE);
371 if(ED_object_modifier_delete(&reports, ob_v, md_v)) {
372 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
373 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
375 ED_undo_push(C, "Delete modifier");
378 uiPupMenuReports(C, &reports);
380 BKE_reports_clear(&reports);
383 static void modifiers_activate(bContext *C, void *ob_v, void *md_v)
385 Scene *scene= CTX_data_scene(C);
388 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
389 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
392 static void modifiers_moveUp(bContext *C, void *ob_v, void *md_v)
394 Scene *scene= CTX_data_scene(C);
398 BKE_reports_init(&reports, RPT_STORE);
400 if(ED_object_modifier_move_up(&reports, ob_v, md_v)) {
401 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
402 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
404 ED_undo_push(C, "Move modifier");
407 uiPupMenuReports(C, &reports);
409 BKE_reports_clear(&reports);
412 static void modifiers_moveDown(bContext *C, void *ob_v, void *md_v)
414 Scene *scene= CTX_data_scene(C);
418 BKE_reports_init(&reports, RPT_STORE);
420 if(ED_object_modifier_move_down(&reports, ob_v, md_v)) {
421 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
422 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
424 ED_undo_push(C, "Move modifier");
427 uiPupMenuReports(C, &reports);
429 BKE_reports_clear(&reports);
432 static void modifiers_convertParticles(bContext *C, void *obv, void *mdv)
434 Scene *scene= CTX_data_scene(C);
438 BKE_reports_init(&reports, RPT_STORE);
440 if(ED_object_modifier_convert(&reports, scene, obv, mdv)) {
441 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
442 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
444 ED_undo_push(C, "Convert particles to mesh object(s).");
447 uiPupMenuReports(C, &reports);
449 BKE_reports_clear(&reports);
452 static void modifiers_applyModifier(bContext *C, void *obv, void *mdv)
454 Scene *scene= CTX_data_scene(C);
458 BKE_reports_init(&reports, RPT_STORE);
460 if(ED_object_modifier_apply(&reports, scene, obv, mdv)) {
461 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
462 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
464 ED_undo_push(C, "Apply modifier");
467 uiPupMenuReports(C, &reports);
469 BKE_reports_clear(&reports);
472 static void modifiers_copyModifier(bContext *C, void *ob_v, void *md_v)
474 Scene *scene= CTX_data_scene(C);
478 BKE_reports_init(&reports, RPT_STORE);
480 if(ED_object_modifier_copy(&reports, ob_v, md_v)) {
481 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
482 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
483 ED_undo_push(C, "Copy modifier");
486 uiPupMenuReports(C, &reports);
488 BKE_reports_clear(&reports);
491 static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
493 Scene *scene= CTX_data_scene(C);
497 int i, cageIndex = modifiers_getCageIndex(ob, NULL );
499 for(i = 0, md=ob->modifiers.first; md; ++i, md=md->next) {
502 md->mode ^= eModifierMode_OnCage;
507 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
508 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
511 static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v)
513 Scene *scene= CTX_data_scene(C);
515 ModifierData *md = md_v;
516 ModifierData *nmd = modifier_new(md->type);
518 modifier_copyData(md, nmd);
519 nmd->mode &= ~eModifierMode_Virtual;
521 BLI_addhead(&ob->modifiers, nmd);
523 ob->partype = PAROBJECT;
525 WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
526 DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
528 ED_undo_push(C, "Modifier convert to real");
531 static int modifier_can_delete(ModifierData *md)
533 // deletion over the deflection panel
534 // fluid particle modifier can't be deleted here
536 if(md->type==eModifierType_Fluidsim)
538 if(md->type==eModifierType_Collision)
540 if(md->type==eModifierType_Surface)
542 if(md->type == eModifierType_ParticleSystem)
543 if(((ParticleSystemModifierData *)md)->psys->part->type == PART_FLUID)
549 static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, int index, int cageIndex, int lastCageIndex)
551 ModifierTypeInfo *mti = modifierType_getInfo(md->type);
555 uiLayout *column, *row, *subrow, *result= NULL;
556 int isVirtual = md->mode&eModifierMode_Virtual;
557 // XXX short color = md->error?TH_REDALERT:TH_BUT_NEUTRAL;
558 short width = 295, buttonWidth = width-120-10;
561 RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
563 column= uiLayoutColumn(layout, 1);
564 uiLayoutSetContextPointer(column, "modifier", &ptr);
567 /* XXX uiBlockSetCol(block, color); */
568 /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */
570 row= uiLayoutRow(uiLayoutBox(column), 0);
571 block= uiLayoutGetBlock(row);
573 subrow= uiLayoutRow(row, 0);
574 uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT);
576 //uiDefBut(block, ROUNDBOX, 0, "", x-10, y-4, width, 25, NULL, 7.0, 0.0,
577 // (!isVirtual && (md->mode&eModifierMode_Expanded))?3:15, 20, "");
578 /* XXX uiBlockSetCol(block, TH_AUTO); */
580 /* open/close icon */
582 uiBlockSetEmboss(block, UI_EMBOSSN);
583 uiDefIconButBitI(block, ICONTOG, eModifierMode_Expanded, 0, ICON_TRIA_RIGHT, 0, 0, UI_UNIT_X, UI_UNIT_Y, &md->mode, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Modifier");
586 /* modifier-type icon */
587 uiDefIconBut(block, BUT, 0, RNA_struct_ui_icon(ptr.type), 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Current Modifier Type");
589 uiBlockSetEmboss(block, UI_EMBOSS);
592 sprintf(str, "%s parent deform", md->name);
593 uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name");
595 but = uiDefBut(block, BUT, 0, "Make Real", 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Convert virtual modifier to a real modifier");
596 uiButSetFunc(but, modifiers_convertToReal, ob, md);
598 uiBlockBeginAlign(block);
599 uiDefBut(block, TEX, 0, "", 0, 0, buttonWidth-40, UI_UNIT_Y, md->name, 0.0, sizeof(md->name)-1, 0.0, 0.0, "Modifier name");
601 /* Softbody not allowed in this situation, enforce! */
602 if (((md->type!=eModifierType_Softbody && md->type!=eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) && (md->type!=eModifierType_Surface)) {
603 uiDefIconButBitI(block, TOG, eModifierMode_Render, 0, ICON_SCENE, 0, 0, 19, UI_UNIT_Y,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering");
604 but= uiDefIconButBitI(block, TOG, eModifierMode_Realtime, 0, ICON_VIEW3D, 0, 0, 19, UI_UNIT_Y,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display");
605 uiButSetFunc(but, modifiers_activate, ob, md);
606 if (mti->flags&eModifierTypeFlag_SupportsEditmode) {
607 but= uiDefIconButBitI(block, TOG, eModifierMode_Editmode, 0, ICON_EDITMODE_HLT, 0, 0, 19, UI_UNIT_Y,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode (only if enabled for display)");
608 uiButSetFunc(but, modifiers_activate, ob, md);
611 uiBlockEndAlign(block);
613 /* XXX uiBlockSetEmboss(block, UI_EMBOSSR); */
615 if (ob->type==OB_MESH && modifier_couldBeCage(md) && index<=lastCageIndex) {
618 if (index==cageIndex) {
619 // XXX color = TH_BUT_SETTING;
620 icon = VICON_EDITMODE_HLT;
621 } else if (index<cageIndex) {
622 // XXX color = TH_BUT_NEUTRAL;
623 icon = VICON_EDITMODE_DEHLT;
625 // XXX color = TH_BUT_NEUTRAL;
628 /* XXX uiBlockSetCol(block, color); */
629 but = uiDefIconBut(block, BUT, 0, icon, 0, 0, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Apply modifier to editing cage during Editmode");
630 uiButSetFunc(but, modifiers_setOnCage, ob, md);
631 /* XXX uiBlockSetCol(block, TH_AUTO); */
635 subrow= uiLayoutRow(row, 0);
636 uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT);
639 /* XXX uiBlockSetCol(block, TH_BUT_ACTION); */
641 but = uiDefIconBut(block, BUT, 0, VICON_MOVE_UP, 0, 0, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier up in stack");
642 uiButSetFunc(but, modifiers_moveUp, ob, md);
644 but = uiDefIconBut(block, BUT, 0, VICON_MOVE_DOWN, 0, 0, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier down in stack");
645 uiButSetFunc(but, modifiers_moveDown, ob, md);
647 uiBlockSetEmboss(block, UI_EMBOSSN);
649 if(modifier_can_delete(md)) {
650 but = uiDefIconBut(block, BUT, 0, VICON_X, 0, 0, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Delete modifier");
651 uiButSetFunc(but, modifiers_del, ob, md);
653 /* XXX uiBlockSetCol(block, TH_AUTO); */
656 uiBlockSetEmboss(block, UI_EMBOSS);
658 if(!isVirtual && (md->mode&eModifierMode_Expanded)) {
661 box= uiLayoutBox(column);
662 row= uiLayoutRow(box, 1);
664 if (!isVirtual && (md->type!=eModifierType_Collision) && (md->type!=eModifierType_Surface)) {
665 uiBlockSetButLock(block, object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE); /* only here obdata, the rest of modifiers is ob level */
667 if (md->type==eModifierType_ParticleSystem) {
668 ParticleSystem *psys= ((ParticleSystemModifierData *)md)->psys;
670 if(!(G.f & G_PARTICLEEDIT)) {
671 if(ELEM3(psys->part->draw_as, PART_DRAW_PATH, PART_DRAW_GR, PART_DRAW_OB) && psys->pathcache) {
672 but = uiDefBut(block, BUT, 0, "Convert", 0,0,60,19, 0, 0, 0, 0, 0, "Convert the current particles to a mesh object");
673 uiButSetFunc(but, modifiers_convertParticles, ob, md);
678 but = uiDefBut(block, BUT, 0, "Apply", 0,0,60,19, 0, 0, 0, 0, 0, "Apply the current modifier and remove from the stack");
679 uiButSetFunc(but, modifiers_applyModifier, ob, md);
682 uiBlockClearButLock(block);
683 uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE);
685 if (md->type!=eModifierType_Fluidsim && md->type!=eModifierType_Softbody && md->type!=eModifierType_ParticleSystem && (md->type!=eModifierType_Cloth)) {
686 but = uiDefBut(block, BUT, 0, "Copy", 0,0,60,19, 0, 0, 0, 0, 0, "Duplicate the current modifier at the same position in the stack");
687 uiButSetFunc(but, modifiers_copyModifier, ob, md);
691 result= uiLayoutColumn(box, 0);
692 block= uiLayoutFreeBlock(box);
696 row = uiLayoutRow(uiLayoutBox(column), 0);
698 /* XXX uiBlockSetCol(block, color); */
699 uiItemL(row, md->error, ICON_ERROR);
700 /* XXX uiBlockSetCol(block, TH_AUTO); */
706 uiLayout *uiTemplateModifier(uiLayout *layout, PointerRNA *ptr)
709 ModifierData *md, *vmd;
710 int i, lastCageIndex, cageIndex;
712 /* verify we have valid data */
713 if(!RNA_struct_is_a(ptr->type, &RNA_Modifier)) {
714 printf("uiTemplateModifier: expected modifier on object.\n");
721 if(!ob || !(GS(ob->id.name) == ID_OB)) {
722 printf("uiTemplateModifier: expected modifier on object.\n");
726 uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
728 /* find modifier and draw it */
729 cageIndex = modifiers_getCageIndex(ob, &lastCageIndex);
731 // XXX virtual modifiers are not accesible for python
732 vmd = modifiers_getVirtualModifierList(ob);
734 for(i=0; vmd; i++, vmd=vmd->next) {
736 return draw_modifier(layout, ob, md, i, cageIndex, lastCageIndex);
737 else if(vmd->mode&eModifierMode_Virtual)
744 /************************ Constraint Template *************************/
746 #include "DNA_action_types.h"
747 #include "DNA_constraint_types.h"
749 #include "BKE_action.h"
750 #include "BKE_constraint.h"
754 #define REDRAWBUTSOBJECT 3
755 #define REDRAWACTION 4
756 #define B_CONSTRAINT_TEST 5
757 #define B_CONSTRAINT_CHANGETARGET 6
758 #define B_CONSTRAINT_INF 7
762 void do_constraint_panels(bContext *C, void *arg, int event)
764 Scene *scene= CTX_data_scene(C);
765 Object *ob= CTX_data_active_object(C);
768 case B_CONSTRAINT_TEST:
769 // XXX allqueue(REDRAWVIEW3D, 0);
770 // XXX allqueue(REDRAWBUTSOBJECT, 0);
771 // XXX allqueue(REDRAWBUTSEDIT, 0);
772 break; // no handling
773 case B_CONSTRAINT_INF:
774 /* influence; do not execute actions for 1 dag_flush */
776 ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
778 case B_CONSTRAINT_CHANGETARGET:
779 if (ob->pose) ob->pose->flag |= POSE_RECALC; // checks & sorts pose channels
780 DAG_scene_sort(scene);
786 object_test_constraints(ob);
788 if(ob->pose) update_pose_constraint_flags(ob->pose);
790 if(ob->type==OB_ARMATURE) DAG_object_flush_update(scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
791 else DAG_object_flush_update(scene, ob, OB_RECALC_OB);
793 // XXX allqueue(REDRAWVIEW3D, 0);
794 // XXX allqueue(REDRAWBUTSOBJECT, 0);
795 // XXX allqueue(REDRAWBUTSEDIT, 0);
798 static void constraint_active_func(bContext *C, void *ob_v, void *con_v)
800 ED_object_constraint_set_active(ob_v, con_v);
803 static void del_constraint_func (bContext *C, void *ob_v, void *con_v)
805 if(ED_object_constraint_delete(NULL, ob_v, con_v))
806 ED_undo_push(C, "Delete Constraint");
809 static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
811 Object *ob= CTX_data_active_object(C);
812 bConstraint *con= con_v;
818 /* put on the stack */
819 BLI_strncpy(oldname, (char *)name_v, 32);
821 ED_object_constraint_rename(ob, con, oldname);
822 ED_object_constraint_set_active(ob, con);
823 // XXX allqueue(REDRAWACTION, 0);
826 static void constraint_moveUp(bContext *C, void *ob_v, void *con_v)
828 if(ED_object_constraint_move_up(NULL, ob_v, con_v))
829 ED_undo_push(C, "Move Constraint");
832 static void constraint_moveDown(bContext *C, void *ob_v, void *con_v)
834 if(ED_object_constraint_move_down(NULL, ob_v, con_v))
835 ED_undo_push(C, "Move Constraint");
838 /* some commonly used macros in the constraints drawing code */
839 #define is_armature_target(target) (target && target->type==OB_ARMATURE)
840 #define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
841 #define is_geom_target(target) (target && (ELEM(target->type, OB_MESH, OB_LATTICE)) )
843 /* Helper function for draw constraint - draws constraint space stuff
844 * This function should not be called if no menus are required
845 * owner/target: -1 = don't draw menu; 0= not posemode, 1 = posemode
847 static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short xco, short yco, short owner, short target)
849 short tarx, ownx, iconx;
851 short iconwidth = 20;
853 /* calculate sizes and placement of menus */
859 else if (target == -1) {
867 iconx = tarx + bwidth + 5;
868 ownx = tarx + bwidth + iconwidth + 10;
872 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Convert:", xco, yco, 80,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
876 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1",
877 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in");
879 else if (target == 0) {
880 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1",
881 tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in");
884 if ((target != -1) && (owner != -1))
885 uiDefIconBut(block, LABEL, 0, ICON_ARROW_LEFTRIGHT,
886 iconx, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "");
890 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1",
891 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");
893 else if (owner == 0) {
894 uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Local (Without Parent) Space %x1",
895 ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in");
899 /* draw panel showing settings for a constraint */
900 static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
902 bPoseChannel *pchan= get_active_posechannel(ob);
903 bConstraintTypeInfo *cti;
905 uiLayout *result= NULL, *col, *box, *row, *subrow;
910 short proxy_protected, xco=0, yco=0;
913 /* get constraint typeinfo */
914 cti= constraint_get_typeinfo(con);
916 /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
917 if (con->type == CONSTRAINT_TYPE_NULL)
918 strcpy(typestr, "Null");
920 strcpy(typestr, "Unknown");
923 strcpy(typestr, cti->name);
925 /* determine whether constraint is proxy protected or not */
926 if (proxylocked_constraints_owner(ob, pchan))
927 proxy_protected= (con->flag & CONSTRAINT_PROXY_LOCAL)==0;
931 /* unless button has own callback, it adds this callback to button */
932 block= uiLayoutGetBlock(layout);
933 uiBlockSetHandleFunc(block, do_constraint_panels, NULL);
934 uiBlockSetFunc(block, constraint_active_func, ob, con);
936 RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr);
938 col= uiLayoutColumn(layout, 1);
939 uiLayoutSetContextPointer(col, "constraint", &ptr);
941 box= uiLayoutBox(col);
942 row= uiLayoutRow(box, 0);
944 block= uiLayoutFreeBlock(box);
946 subrow= uiLayoutRow(row, 0);
947 uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT);
949 /* Draw constraint header */
950 uiBlockSetEmboss(block, UI_EMBOSSN);
953 rb_col= (con->flag & CONSTRAINT_ACTIVE)?50:20;
956 uiDefIconButBitS(block, ICONTOG, CONSTRAINT_EXPAND, B_CONSTRAINT_TEST, ICON_TRIA_RIGHT, xco-10, yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
959 if ((con->flag & CONSTRAINT_EXPAND) && (proxy_protected==0)) {
960 /* XXX if (con->flag & CONSTRAINT_DISABLE)
961 uiBlockSetCol(block, TH_REDALERT);*/
963 uiBlockSetEmboss(block, UI_EMBOSS);
965 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco+10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
967 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", xco+120, yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name");
968 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
971 uiBlockSetEmboss(block, UI_EMBOSSN);
973 /* XXX if (con->flag & CONSTRAINT_DISABLE)
974 uiBlockSetCol(block, TH_REDALERT);*/
976 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, xco+10, yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
978 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, xco+120, yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, "");
981 // XXX uiBlockSetCol(block, TH_AUTO);
983 subrow= uiLayoutRow(row, 0);
984 uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT);
986 /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
987 if (proxy_protected) {
988 uiBlockSetEmboss(block, UI_EMBOSSN);
990 /* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
991 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, xco+244, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
992 uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
994 uiBlockSetEmboss(block, UI_EMBOSS);
997 short prev_proxylock, show_upbut, show_downbut;
1000 * Proxy-constraints are not allowed to occur after local (non-proxy) constraints
1001 * as that poses problems when restoring them, so disable the "up" button where
1002 * it may cause this situation.
1004 * Up/Down buttons should only be shown (or not greyed - todo) if they serve some purpose.
1006 if (proxylocked_constraints_owner(ob, pchan)) {
1008 prev_proxylock= (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
1016 show_upbut= ((prev_proxylock == 0) && (con->prev));
1017 show_downbut= (con->next) ? 1 : 0;
1019 if (show_upbut || show_downbut) {
1020 uiBlockBeginAlign(block);
1021 uiBlockSetEmboss(block, UI_EMBOSS);
1024 but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, xco+width-50, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint up in constraint stack");
1025 uiButSetFunc(but, constraint_moveUp, ob, con);
1029 but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
1030 uiButSetFunc(but, constraint_moveDown, ob, con);
1032 uiBlockEndAlign(block);
1036 /* Close 'button' - emboss calls here disable drawing of 'button' behind X */
1037 uiBlockSetEmboss(block, UI_EMBOSSN);
1039 but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
1040 uiButSetFunc(but, del_constraint_func, ob, con);
1042 uiBlockSetEmboss(block, UI_EMBOSS);
1045 /* Set but-locks for protected settings (magic numbers are used here!) */
1046 if (proxy_protected)
1047 uiBlockSetButLock(block, 1, "Cannot edit Proxy-Protected Constraint");
1049 /* Draw constraint data */
1050 if ((con->flag & CONSTRAINT_EXPAND) == 0) {
1054 box= uiLayoutBox(col);
1055 block= uiLayoutFreeBlock(box);
1057 switch (con->type) {
1058 #ifndef DISABLE_PYTHON
1059 case CONSTRAINT_TYPE_PYTHON:
1061 bPythonConstraint *data = con->data;
1062 bConstraintTarget *ct;
1064 int tarnum, theight;
1065 // static int pyconindex=0;
1068 theight = (data->tarnum)? (data->tarnum * 38) : (38);
1070 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Script:", xco+60, yco-24, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1072 /* do the scripts menu */
1073 /* XXX menustr = buildmenu_pyconstraints(data->text, &pyconindex);
1074 but2 = uiDefButI(block, MENU, B_CONSTRAINT_TEST, menustr,
1075 xco+120, yco-24, 150, 20, &pyconindex,
1076 0, 0, 0, 0, "Set the Script Constraint to use");
1077 uiButSetFunc(but2, validate_pyconstraint_cb, data, &pyconindex);
1078 MEM_freeN(menustr); */
1080 /* draw target(s) */
1081 if (data->flag & PYCON_USETARGETS) {
1082 /* Draw target parameters */
1083 for (ct=data->targets.first, tarnum=1; ct; ct=ct->next, tarnum++) {
1085 short yoffset= ((tarnum-1) * 38);
1088 sprintf(tarstr, "Target %d:", tarnum);
1089 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, xco+45, yco-(48+yoffset), 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1091 /* target space-selector - per target */
1092 if (is_armature_target(ct->tar)) {
1093 uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1",
1094 xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");
1097 uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Local (Without Parent) Space %x1",
1098 xco+10, yco-(66+yoffset), 100, 18, &ct->space, 0, 0, 0, 0, "Choose space that target is evaluated in");
1101 uiBlockBeginAlign(block);
1103 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", xco+120, yco-(48+yoffset), 150, 18, &ct->tar, "Target Object");
1106 if (is_armature_target(ct->tar)) {
1107 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", xco+120, yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1108 uiButSetCompleteFunc(but, autocomplete_bone, (void *)ct->tar);
1110 else if (is_geom_target(ct->tar)) {
1111 but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "VG:", xco+120, yco-(66+yoffset),150,18, &ct->subtarget, 0, 24, 0, 0, "Name of Vertex Group defining 'target' points");
1112 uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ct->tar);
1115 strcpy(ct->subtarget, "");
1117 uiBlockEndAlign(block);
1121 /* Draw indication that no target needed */
1122 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", xco+60, yco-48, 55, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1123 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Not Applicable", xco+120, yco-48, 150, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
1127 uiBlockBeginAlign(block);
1128 but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Options", xco, yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Change some of the constraint's settings.");
1129 // XXX uiButSetFunc(but, BPY_pyconstraint_settings, data, NULL);
1131 but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Refresh", xco+((width/2)+10), yco-(52+theight), (width/2),18, NULL, 0, 24, 0, 0, "Force constraint to refresh it's settings");
1132 uiBlockEndAlign(block);
1134 /* constraint space settings */
1135 draw_constraint_spaceselect(block, con, xco, yco-(73+theight), is_armature_owner(ob), -1);
1138 #endif /* DISABLE_PYTHON */
1139 /*case CONSTRAINT_TYPE_CHILDOF:
1142 uiBlockBeginAlign(block);
1143 but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Set Offset", xco, yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Calculate current Parent-Inverse Matrix (i.e. restore offset from parent)");
1144 // XXX uiButSetFunc(but, childof_const_setinv, con, NULL);
1146 but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Clear Offset", xco+((width/2)+10), yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Clear Parent-Inverse Matrix (i.e. clear offset from parent)");
1147 // XXX uiButSetFunc(but, childof_const_clearinv, con, NULL);
1148 uiBlockEndAlign(block);
1153 /*case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1155 if (data->type==CONSTRAINT_RB_GENERIC6DOF) {
1156 // Draw Pairs of LimitToggle+LimitValue
1157 uiBlockBeginAlign(block);
1158 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit");
1159 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"min x limit");
1160 uiBlockEndAlign(block);
1162 uiBlockBeginAlign(block);
1163 uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMaxX", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit");
1164 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"max x limit");
1165 uiBlockEndAlign(block);
1168 uiBlockBeginAlign(block);
1169 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
1170 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"min y limit");
1171 uiBlockEndAlign(block);
1173 uiBlockBeginAlign(block);
1174 uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMaxY", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit");
1175 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"max y limit");
1176 uiBlockEndAlign(block);
1179 uiBlockBeginAlign(block);
1180 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
1181 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"min z limit");
1182 uiBlockEndAlign(block);
1184 uiBlockBeginAlign(block);
1185 uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMaxZ", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit");
1186 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"max z limit");
1187 uiBlockEndAlign(block);
1190 if ((data->type==CONSTRAINT_RB_GENERIC6DOF) || (data->type==CONSTRAINT_RB_CONETWIST)) {
1191 // Draw Pairs of LimitToggle+LimitValue /
1192 uiBlockBeginAlign(block);
1193 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit");
1194 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"min x limit");
1195 uiBlockEndAlign(block);
1196 uiBlockBeginAlign(block);
1197 uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMaxX", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit");
1198 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"max x limit");
1199 uiBlockEndAlign(block);
1202 uiBlockBeginAlign(block);
1203 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit");
1204 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"min y limit");
1205 uiBlockEndAlign(block);
1207 uiBlockBeginAlign(block);
1208 uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMaxY", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit");
1209 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"max y limit");
1210 uiBlockEndAlign(block);
1213 uiBlockBeginAlign(block);
1214 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", xco, yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit");
1215 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+togButWidth, yco-offsetY, (textButWidth-5), 18, &(data->minLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"min z limit");
1216 uiBlockEndAlign(block);
1218 uiBlockBeginAlign(block);
1219 uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMaxZ", xco+(width-(textButWidth-5)-togButWidth), yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit");
1220 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", xco+(width-textButWidth-5), yco-offsetY, (textButWidth), 18, &(data->maxLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"max z limit");
1221 uiBlockEndAlign(block);
1228 case CONSTRAINT_TYPE_NULL:
1230 uiItemL(box, "", 0);
1239 /* clear any locks set up for proxies/lib-linking */
1240 uiBlockClearButLock(block);
1245 uiLayout *uiTemplateConstraint(uiLayout *layout, PointerRNA *ptr)
1250 /* verify we have valid data */
1251 if(!RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
1252 printf("uiTemplateConstraint: expected constraint on object.\n");
1259 if(!ob || !(GS(ob->id.name) == ID_OB)) {
1260 printf("uiTemplateConstraint: expected constraint on object.\n");
1264 uiBlockSetButLock(uiLayoutGetBlock(layout), (ob && ob->id.lib), ERROR_LIBDATA_MESSAGE);
1266 /* hrms, the temporal constraint should not draw! */
1267 if(con->type==CONSTRAINT_TYPE_KINEMATIC) {
1268 bKinematicConstraint *data= con->data;
1269 if(data->flag & CONSTRAINT_IK_TEMP)
1273 return draw_constraint(layout, ob, con);
1276 /************************* Group Template ***************************/
1279 static void do_add_groupmenu(void *arg, int event)
1286 Group *group= add_group( "Group" );
1287 add_to_group(group, ob);
1290 add_to_group(BLI_findlink(&G.main->group, event), ob);
1292 ob->flag |= OB_FROMGROUP;
1293 BASACT->flag |= OB_FROMGROUP;
1294 allqueue(REDRAWBUTSOBJECT, 0);
1295 allqueue(REDRAWVIEW3D, 0);
1299 static uiBlock *add_groupmenu(void *arg_unused)
1303 short xco=0, yco= 0, index=0;
1306 block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1307 uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
1309 uiDefBut(block, BUTM, B_NOP, "ADD NEW", 0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
1310 for(group= G.main->group.first; group; group= group->id.next, index++) {
1312 /*if(group->id.lib) strcpy(str, "L ");*/ /* we cant allow adding objects inside linked groups, it wont be saved anyway */
1313 if(group->id.lib==0) {
1315 strcat(str, group->id.name+2);
1316 uiDefBut(block, BUTM, B_NOP, str, xco*160, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, index, "");
1326 uiTextBoundsBlock(block, 50);
1327 uiBlockSetDirection(block, UI_DOWN);
1332 static void group_ob_rem(void *gr_v, void *ob_v)
1336 if(rem_from_group(gr_v, ob) && find_group(ob, NULL)==NULL) {
1337 ob->flag &= ~OB_FROMGROUP;
1338 BASACT->flag &= ~OB_FROMGROUP;
1340 allqueue(REDRAWBUTSOBJECT, 0);
1341 allqueue(REDRAWVIEW3D, 0);
1345 static void group_local(void *gr_v, void *unused)
1349 group->id.lib= NULL;
1351 allqueue(REDRAWBUTSOBJECT, 0);
1352 allqueue(REDRAWVIEW3D, 0);
1356 uiLayout *uiTemplateGroup(uiLayout *layout, Object *ob, Group *group)
1358 uiSetButLock(1, NULL);
1359 uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
1364 uiBlockBeginAlign(block);
1365 uiSetButLock(GET_INT_FROM_POINTER(group->id.lib), ERROR_LIBDATA_MESSAGE); /* We cant actually use this button */
1366 uiDefBut(block, TEX, B_IDNAME, "GR:", 10, 120-yco, 100, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1369 but= uiDefIconBut(block, BUT, B_NOP, ICON_PARLIB, 110, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Make Group local");
1370 uiButSetFunc(but, group_local, group, NULL);
1371 uiBlockEndAlign(block);
1373 but = uiDefBut(block, TEX, B_IDNAME, "GR:", 10, 120-yco, 120, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1374 uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
1378 if(group->id.lib==0) { /* cant remove objects from linked groups */
1379 but = uiDefIconBut(block, BUT, B_NOP, VICON_X, xco, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove Group membership");
1380 uiButSetFunc(but, group_ob_rem, group, ob);
1385 /************************* Preview Template ***************************/
1387 #include "DNA_material_types.h"
1392 static void do_preview_buttons(bContext *C, void *arg, int event)
1396 WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, arg);
1401 void uiTemplatePreview(uiLayout *layout, ID *id)
1403 uiLayout *row, *col;
1407 if(id && !ELEM4(GS(id->name), ID_MA, ID_TE, ID_WO, ID_LA)) {
1408 printf("uiTemplatePreview: expected ID of type material, texture, lamp or world.\n");
1412 block= uiLayoutGetBlock(layout);
1414 row= uiLayoutRow(layout, 0);
1416 col= uiLayoutColumn(row, 0);
1417 uiLayoutSetKeepAspect(col, 1);
1419 uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X*6, UI_UNIT_Y*6, id, 0.0, 0.0, 0, 0, "");
1420 uiBlockSetDrawExtraFunc(block, ED_preview_draw);
1422 uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
1425 if(GS(id->name) == ID_MA) {
1428 uiLayoutColumn(row, 1);
1430 uiDefIconButC(block, ROW, B_MATPRV, ICON_MATPLANE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_FLAT, 0, 0, "Preview type: Flat XY plane");
1431 uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE, 0, 0, "Preview type: Sphere");
1432 uiDefIconButC(block, ROW, B_MATPRV, ICON_MATCUBE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_CUBE, 0, 0, "Preview type: Cube");
1433 uiDefIconButC(block, ROW, B_MATPRV, ICON_MONKEY, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_MONKEY, 0, 0, "Preview type: Monkey");
1434 uiDefIconButC(block, ROW, B_MATPRV, ICON_HAIR, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_HAIR, 0, 0, "Preview type: Hair strands");
1435 uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE_A, 0, 0, "Preview type: Large sphere with sky");
1440 /********************** ColorRamp Template **************************/
1442 void uiTemplateColorRamp(uiLayout *layout, ColorBand *coba, int expand)
1448 rect.xmin= 0; rect.xmax= 200;
1449 rect.ymin= 0; rect.ymax= 190;
1451 block= uiLayoutFreeBlock(layout);
1452 colorband_buttons(block, coba, &rect, !expand);
1456 /********************* CurveMapping Template ************************/
1458 #include "DNA_color_types.h"
1460 void uiTemplateCurveMapping(uiLayout *layout, CurveMapping *cumap, int type)
1466 rect.xmin= 0; rect.xmax= 200;
1467 rect.ymin= 0; rect.ymax= 190;
1469 block= uiLayoutFreeBlock(layout);
1470 curvemap_buttons(block, cumap, type, 0, 0, &rect);
1474 /********************* Layer Buttons Template ************************/
1477 // - option for showing extra info like whether layer has contents?
1478 // - for now, grouping of layers is determined by dividing up the length of
1479 // the array of layer bitflags
1481 void uiTemplateLayers(uiLayout *layout, PointerRNA *ptr, char *propname)
1483 uiLayout *uRow, *uSplit, *uCol;
1485 int groups, cols, layers;
1486 int group, col, layer, row;
1491 prop= RNA_struct_find_property(ptr, propname);
1493 printf("uiTemplateLayer: layers property not found: %s\n", propname);
1497 /* the number of layers determines the way we group them
1498 * - we want 2 rows only (for now)
1499 * - the number of columns (cols) is the total number of buttons per row
1500 * the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
1501 * - for now, only split into groups if if group will have at least 5 items
1503 layers= RNA_property_array_length(prop);
1504 cols= (layers / 2) + (layers % 2);
1505 groups= ((cols / 2) < 5) ? (1) : (cols / 2);
1507 /* layers are laid out going across rows, with the columns being divided into groups */
1508 uSplit= uiLayoutSplit(layout, (1.0f/(float)groups));
1510 for (group= 0; group < groups; group++) {
1511 uCol= uiLayoutColumn(uSplit, 1);
1513 for (row= 0; row < 2; row++) {
1514 uRow= uiLayoutRow(uCol, 1);
1515 layer= groups*cols*row + cols*group;
1517 /* add layers as toggle buts */
1518 for (col= 0; (col < cols) && (layer < layers); col++, layer++) {
1519 int icon=0; // XXX - add some way of setting this...
1520 uiItemFullR(uRow, "", icon, ptr, prop, layer, 0, 0, 0, 1);
1527 /************************* List Template **************************/
1529 typedef struct ListItem {
1532 PropertyRNA *activeprop;
1534 PointerRNA activeptr;
1540 static void list_item_cb(bContext *C, void *arg_item, void *arg_unused)
1542 ListItem *item= (ListItem*)arg_item;
1543 PropertyType activetype;
1546 if(item->selected) {
1547 activetype= RNA_property_type(item->activeprop);
1549 if(activetype == PROP_POINTER)
1550 RNA_property_pointer_set(&item->ptr, item->activeprop, item->activeptr);
1551 else if(activetype == PROP_INT)
1552 RNA_property_int_set(&item->ptr, item->activeprop, item->activei);
1553 else if(activetype == PROP_STRING) {
1554 activename= RNA_struct_name_get_alloc(&item->activeptr, NULL, 0);
1555 RNA_property_string_set(&item->ptr, item->activeprop, activename);
1556 MEM_freeN(activename);
1561 void uiTemplateList(uiLayout *layout, PointerRNA *ptr, char *propname, char *activepropname, int items)
1563 PropertyRNA *prop, *activeprop;
1564 PropertyType type, activetype;
1565 PointerRNA activeptr;
1566 uiLayout *box, *row, *col;
1569 char *name, *activename= NULL;
1570 int i= 1, activei= 0, len;
1571 static int scroll = 1;
1573 /* validate arguments */
1577 prop= RNA_struct_find_property(ptr, propname);
1579 printf("uiTemplateList: property not found: %s\n", propname);
1583 activeprop= RNA_struct_find_property(ptr, activepropname);
1585 printf("uiTemplateList: property not found: %s\n", activepropname);
1589 type= RNA_property_type(prop);
1590 if(type != PROP_COLLECTION) {
1591 printf("uiTemplateList: expected collection property.\n");
1595 activetype= RNA_property_type(activeprop);
1596 if(!ELEM3(activetype, PROP_POINTER, PROP_INT, PROP_STRING)) {
1597 printf("uiTemplateList: expected pointer, integer or string property.\n");
1604 /* get active data */
1605 if(activetype == PROP_POINTER)
1606 activeptr= RNA_property_pointer_get(ptr, activeprop);
1607 else if(activetype == PROP_INT)
1608 activei= RNA_property_int_get(ptr, activeprop);
1609 else if(activetype == PROP_STRING)
1610 activename= RNA_property_string_get_alloc(ptr, activeprop, NULL, 0);
1612 box= uiLayoutBox(layout);
1613 row= uiLayoutRow(box, 0);
1614 col = uiLayoutColumn(row, 1);
1616 block= uiLayoutGetBlock(col);
1617 uiBlockSetEmboss(block, UI_EMBOSSN);
1619 len= RNA_property_collection_length(ptr, prop);
1620 scroll= MIN2(scroll, len-items+1);
1621 scroll= MAX2(scroll, 1);
1623 RNA_PROP_BEGIN(ptr, itemptr, prop) {
1624 if(i >= scroll && i<scroll+items) {
1625 name= RNA_struct_name_get_alloc(&itemptr, NULL, 0);
1628 ListItem *item= MEM_callocN(sizeof(ListItem), "uiTemplateList ListItem");
1632 item->activeprop= activeprop;
1633 item->activeptr= itemptr;
1636 if(activetype == PROP_POINTER)
1637 item->selected= (activeptr.data == itemptr.data)? i: -1;
1638 else if(activetype == PROP_INT)
1639 item->selected= (activei == i)? i: -1;
1640 else if(activetype == PROP_STRING)
1641 item->selected= (strcmp(activename, name) == 0)? i: -1;
1643 but= uiDefIconTextButI(block, ROW, 0, RNA_struct_ui_icon(itemptr.type), name, 0,0,UI_UNIT_X*10,UI_UNIT_Y, &item->selected, 0, i, 0, 0, "");
1644 uiButSetFlag(but, UI_ICON_LEFT|UI_TEXT_LEFT);
1645 uiButSetNFunc(but, list_item_cb, item, NULL);
1655 while(i < scroll+items) {
1657 uiItemL(col, "", 0);
1661 uiBlockSetEmboss(block, UI_EMBOSS);
1664 col= uiLayoutColumn(row, 0);
1665 uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*0.75,UI_UNIT_Y*items, &scroll, 1, len-items+1, items, 0, "");
1668 //uiDefButI(block, SCROLL, 0, "", 0,0,UI_UNIT_X*15,UI_UNIT_Y*0.75, &scroll, 1, 16-5, 5, 0, "");