diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-06-03 04:09:30 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-06-03 04:09:30 +0400 |
commit | 084be86ea99673eb0f570ed723b235c70b98c7bc (patch) | |
tree | 5e798d5e28d4c72f7c6cecf4ce89c9c496073363 /source | |
parent | 9ed9acaf9a5a64a3471b4eca6a9e91bb8f0bc23e (diff) |
UI:
* Make modifier and constraint templates use left/right alignment for
buttons in the header.
* Added mdef bind operator as an example of how to use local context
for a modifier, and add some code I forgot to commit last time to
make this system actually work.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_object.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 7 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 13 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 325 | ||||
-rw-r--r-- | source/blender/editors/object/object_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/object/object_modifier.c | 162 | ||||
-rw-r--r-- | source/blender/editors/object/object_ops.c | 1 |
7 files changed, 296 insertions, 215 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 3d0de795778..bfa819632c9 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -56,7 +56,7 @@ void ED_base_object_free_and_unlink(struct Scene *scene, struct Base *base); void ED_object_apply_obmat(struct Object *ob); /* single object duplicate, if dupflag==0, fully linked, else it uses U.dupflag */ -Base *ED_object_add_duplicate(struct Scene *scene, struct Base *base, int usedupflag); +struct Base *ED_object_add_duplicate(struct Scene *scene, struct Base *base, int usedupflag); /* bitflags for enter/exit editmode */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 4fb2f27a618..69ee0d470d0 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -537,10 +537,17 @@ void uiEndBlock(const bContext *C, uiBlock *block) /* temp? Proper check for greying out */ if(but->optype) { wmOperatorType *ot= but->optype; + + if(but->context) + CTX_store_set((bContext*)C, but->context); + if(ot==NULL || (ot->poll && ot->poll((bContext *)C)==0)) { but->flag |= UI_BUT_DISABLED; but->lock = 1; } + + if(but->context) + CTX_store_set((bContext*)C, NULL); } /* only update soft range while not editing */ diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index e0e58e61752..5617874ab0e 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -160,6 +160,8 @@ typedef struct uiAfterFunc { PointerRNA rnapoin; PropertyRNA *rnaprop; + + bContextStore *context; } uiAfterFunc; static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState state); @@ -252,6 +254,9 @@ static void ui_apply_but_func(bContext *C, uiBut *but) after->rnapoin= but->rnapoin; after->rnaprop= but->rnaprop; + if(but->context) + after->context= CTX_store_copy(but->context); + but->optype= NULL; but->opcontext= 0; but->opptr= NULL; @@ -273,6 +278,9 @@ static void ui_apply_but_funcs_after(bContext *C) after= *afterf; /* copy to avoid memleak on exit() */ BLI_freelinkN(&funcs, afterf); + if(after.context) + CTX_store_set(C, after.context); + if(after.func) after.func(C, after.func_arg1, after.func_arg2); if(after.funcN) @@ -292,6 +300,11 @@ static void ui_apply_but_funcs_after(bContext *C) if(after.rnapoin.data) RNA_property_update(C, &after.rnapoin, after.rnaprop); + + if(after.context) { + CTX_store_set(C, NULL); + CTX_store_free(after.context); + } } } diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index cd905a9657b..4df5f99f224 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -240,33 +240,16 @@ void uiTemplateHeaderID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *pr #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata" -#define B_NOP 0 -#define B_MODIFIER_RECALC 1 -#define B_MODIFIER_REDRAW 2 -#define B_CHANGEDEP 3 -#define B_ARM_RECALCDATA 4 - #include <string.h> -#include "DNA_armature_types.h" -#include "DNA_curve_types.h" #include "DNA_object_force.h" #include "DNA_object_types.h" -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" -#include "DNA_particle_types.h" #include "DNA_scene_types.h" -#include "BKE_bmesh.h" -#include "BKE_curve.h" #include "BKE_depsgraph.h" #include "BKE_DerivedMesh.h" -#include "BKE_displist.h" #include "BKE_global.h" -#include "BKE_lattice.h" -#include "BKE_main.h" -#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_object.h" #include "BKE_particle.h" @@ -280,33 +263,20 @@ void uiTemplateHeaderID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *pr #include "ED_object.h" -void do_modifier_panels(bContext *C, void *arg, int event) +static void modifiers_del(bContext *C, void *ob_v, void *md_v) { Scene *scene= CTX_data_scene(C); - Object *ob = CTX_data_active_object(C); + Object *ob= ob_v; + ReportList reports; - switch(event) { - case B_MODIFIER_REDRAW: - WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); - break; + BKE_reports_init(&reports, RPT_STORE); - case B_MODIFIER_RECALC: + if(ED_object_modifier_delete(&reports, ob_v, md_v)) { WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - object_handle_update(scene, ob); - // XXX countall(); - break; - } -} -static void modifiers_del(bContext *C, void *ob_v, void *md_v) -{ - ReportList reports; - - BKE_reports_init(&reports, RPT_STORE); - - if(ED_object_modifier_delete(&reports, ob_v, md_v)) ED_undo_push(C, "Delete modifier"); + } else uiPupMenuReports(C, &reports); @@ -315,12 +285,18 @@ static void modifiers_del(bContext *C, void *ob_v, void *md_v) static void modifiers_moveUp(bContext *C, void *ob_v, void *md_v) { + Scene *scene= CTX_data_scene(C); + Object *ob= ob_v; ReportList reports; BKE_reports_init(&reports, RPT_STORE); - if(ED_object_modifier_move_up(&reports, ob_v, md_v)) + if(ED_object_modifier_move_up(&reports, ob_v, md_v)) { + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + ED_undo_push(C, "Move modifier"); + } else uiPupMenuReports(C, &reports); @@ -329,12 +305,18 @@ static void modifiers_moveUp(bContext *C, void *ob_v, void *md_v) static void modifiers_moveDown(bContext *C, void *ob_v, void *md_v) { + Scene *scene= CTX_data_scene(C); + Object *ob= ob_v; ReportList reports; BKE_reports_init(&reports, RPT_STORE); - if(ED_object_modifier_move_down(&reports, ob_v, md_v)) + if(ED_object_modifier_move_down(&reports, ob_v, md_v)) { + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + ED_undo_push(C, "Move modifier"); + } else uiPupMenuReports(C, &reports); @@ -344,12 +326,17 @@ static void modifiers_moveDown(bContext *C, void *ob_v, void *md_v) static void modifiers_convertParticles(bContext *C, void *obv, void *mdv) { Scene *scene= CTX_data_scene(C); + Object *ob= obv; ReportList reports; BKE_reports_init(&reports, RPT_STORE); - if(ED_object_modifier_convert(&reports, scene, obv, mdv)) + if(ED_object_modifier_convert(&reports, scene, obv, mdv)) { + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + ED_undo_push(C, "Convert particles to mesh object(s)."); + } else uiPupMenuReports(C, &reports); @@ -359,12 +346,17 @@ static void modifiers_convertParticles(bContext *C, void *obv, void *mdv) static void modifiers_applyModifier(bContext *C, void *obv, void *mdv) { Scene *scene= CTX_data_scene(C); + Object *ob= obv; ReportList reports; BKE_reports_init(&reports, RPT_STORE); - if(ED_object_modifier_apply(&reports, scene, obv, mdv)) + if(ED_object_modifier_apply(&reports, scene, obv, mdv)) { + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + ED_undo_push(C, "Apply modifier"); + } else uiPupMenuReports(C, &reports); @@ -373,12 +365,17 @@ static void modifiers_applyModifier(bContext *C, void *obv, void *mdv) static void modifiers_copyModifier(bContext *C, void *ob_v, void *md_v) { + Scene *scene= CTX_data_scene(C); + Object *ob= ob_v; ReportList reports; BKE_reports_init(&reports, RPT_STORE); - if(ED_object_modifier_copy(&reports, ob_v, md_v)) + if(ED_object_modifier_copy(&reports, ob_v, md_v)) { + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); ED_undo_push(C, "Copy modifier"); + } else uiPupMenuReports(C, &reports); @@ -387,21 +384,27 @@ static void modifiers_copyModifier(bContext *C, void *ob_v, void *md_v) static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v) { + Scene *scene= CTX_data_scene(C); Object *ob = ob_v; ModifierData *md; int i, cageIndex = modifiers_getCageIndex(ob, NULL ); - for( i = 0, md=ob->modifiers.first; md; ++i, md=md->next ) - if( md == md_v ) { - if( i >= cageIndex ) + for(i = 0, md=ob->modifiers.first; md; ++i, md=md->next) { + if(md == md_v) { + if(i >= cageIndex) md->mode ^= eModifierMode_OnCage; break; } + } + + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); } static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v) { + Scene *scene= CTX_data_scene(C); Object *ob = ob_v; ModifierData *md = md_v; ModifierData *nmd = modifier_new(md->type); @@ -413,169 +416,56 @@ static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v) ob->partype = PAROBJECT; - ED_undo_push(C, "Modifier convert to real"); -} - -#if 0 -static void modifiers_clearHookOffset(bContext *C, void *ob_v, void *md_v) -{ - Object *ob = ob_v; - ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; - - if (hmd->object) { - Mat4Invert(hmd->object->imat, hmd->object->obmat); - Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); - ED_undo_push(C, "Clear hook offset"); - } -} - -static void modifiers_cursorHookCenter(bContext *C, void *ob_v, void *md_v) -{ - /* XXX - Object *ob = ob_v; - ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; + WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - if(G.vd) { - float *curs = give_cursor(); - float bmat[3][3], imat[3][3]; - - where_is_object(ob); - - Mat3CpyMat4(bmat, ob->obmat); - Mat3Inv(imat, bmat); - - curs= give_cursor(); - hmd->cent[0]= curs[0]-ob->obmat[3][0]; - hmd->cent[1]= curs[1]-ob->obmat[3][1]; - hmd->cent[2]= curs[2]-ob->obmat[3][2]; - Mat3MulVecfl(imat, hmd->cent); - - ED_undo_push(C, "Hook cursor center"); - }*/ -} - -static void modifiers_selectHook(bContext *C, void *ob_v, void *md_v) -{ - /* XXX ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; - - hook_select(hmd);*/ -} - -static void modifiers_reassignHook(bContext *C, void *ob_v, void *md_v) -{ - /* XXX ModifierData *md = md_v; - HookModifierData *hmd = (HookModifierData*) md; - float cent[3]; - int *indexar, tot, ok; - char name[32]; - - ok= hook_getIndexArray(&tot, &indexar, name, cent); - - if (!ok) { - uiPupMenuError(C, "Requires selected vertices or active Vertex Group"); - } else { - if (hmd->indexar) { - MEM_freeN(hmd->indexar); - } - - VECCOPY(hmd->cent, cent); - hmd->indexar = indexar; - hmd->totindex = tot; - }*/ -} - -static void modifiers_bindMeshDeform(bContext *C, void *ob_v, void *md_v) -{ - Scene *scene= CTX_data_scene(C); - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md_v; - Object *ob = (Object*)ob_v; - - if(mmd->bindcos) { - if(mmd->bindweights) MEM_freeN(mmd->bindweights); - if(mmd->bindcos) MEM_freeN(mmd->bindcos); - if(mmd->dyngrid) MEM_freeN(mmd->dyngrid); - if(mmd->dyninfluences) MEM_freeN(mmd->dyninfluences); - if(mmd->dynverts) MEM_freeN(mmd->dynverts); - mmd->bindweights= NULL; - mmd->bindcos= NULL; - mmd->dyngrid= NULL; - mmd->dyninfluences= NULL; - mmd->dynverts= NULL; - mmd->totvert= 0; - mmd->totcagevert= 0; - mmd->totinfluence= 0; - } - else { - DerivedMesh *dm; - int mode= mmd->modifier.mode; - - /* force modifier to run, it will call binding routine */ - mmd->needbind= 1; - mmd->modifier.mode |= eModifierMode_Realtime; - - if(ob->type == OB_MESH) { - dm= mesh_create_derived_view(scene, ob, 0); - dm->release(dm); - } - else if(ob->type == OB_LATTICE) { - lattice_calc_modifiers(scene, ob); - } - else if(ob->type==OB_MBALL) { - makeDispListMBall(scene, ob); - } - else if(ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - makeDispListCurveTypes(scene, ob, 0); - } - - mmd->needbind= 0; - mmd->modifier.mode= mode; - } -} - -void modifiers_explodeFacepa(bContext *C, void *arg1, void *arg2) -{ - ExplodeModifierData *emd=arg1; - - emd->flag |= eExplodeFlag_CalcFaces; -} - -void modifiers_explodeDelVg(bContext *C, void *arg1, void *arg2) -{ - ExplodeModifierData *emd=arg1; - emd->vgroup = 0; + ED_undo_push(C, "Modifier convert to real"); } -#endif -static int modifier_is_fluid_particles(ModifierData *md) +static int modifier_can_delete(ModifierData *md) { - if(md->type == eModifierType_ParticleSystem) { + // deletion over the deflection panel + // fluid particle modifier can't be deleted here + + if(md->type==eModifierType_Fluidsim) + return 0; + if(md->type==eModifierType_Collision) + return 0; + if(md->type==eModifierType_Surface) + return 0; + if(md->type == eModifierType_ParticleSystem) if(((ParticleSystemModifierData *)md)->psys->part->type == PART_FLUID) - return 1; - } - return 0; + return 0; + + return 1; } static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, int index, int cageIndex, int lastCageIndex) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); + PointerRNA ptr; uiBut *but; uiBlock *block; - uiLayout *column, *row, *result= NULL; + uiLayout *column, *row, *subrow, *result= NULL; int isVirtual = md->mode&eModifierMode_Virtual; - int x = 0, y = 0; // XXX , color = md->error?TH_REDALERT:TH_BUT_NEUTRAL; + // XXX short color = md->error?TH_REDALERT:TH_BUT_NEUTRAL; short width = 295, buttonWidth = width-120-10; char str[128]; + RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); + column= uiLayoutColumn(layout, 1); + uiLayoutSetContextPointer(column, "modifier", &ptr); /* rounded header */ /* XXX uiBlockSetCol(block, color); */ /* roundbox 4 free variables: corner-rounding, nop, roundbox type, shade */ - block= uiLayoutFreeBlock(uiLayoutBox(column)); - uiBlockSetHandleFunc(block, do_modifier_panels, NULL); + + row= uiLayoutRow(uiLayoutBox(column), 0); + block= uiLayoutGetBlock(row); + + subrow= uiLayoutRow(row, 0); + uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT); //uiDefBut(block, ROUNDBOX, 0, "", x-10, y-4, width, 25, NULL, 7.0, 0.0, // (!isVirtual && (md->mode&eModifierMode_Expanded))?3:15, 20, ""); @@ -584,27 +474,27 @@ static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, i /* open/close icon */ if (!isVirtual) { uiBlockSetEmboss(block, UI_EMBOSSN); - uiDefIconButBitI(block, ICONTOG, eModifierMode_Expanded, B_MODIFIER_REDRAW, ICON_TRIA_RIGHT, x-10, y-2, 20, 20, &md->mode, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Modifier"); + 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"); } uiBlockSetEmboss(block, UI_EMBOSS); if (isVirtual) { sprintf(str, "%s parent deform", md->name); - uiDefBut(block, LABEL, 0, str, x+10, y-1, width-110, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); + uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); - but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Make Real", x+width-100, y, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Convert virtual modifier to a real modifier"); + 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"); uiButSetFunc(but, modifiers_convertToReal, ob, md); } else { uiBlockBeginAlign(block); - uiDefBut(block, TEX, B_MODIFIER_REDRAW, "", x+10, y-1, buttonWidth-60, 19, md->name, 0.0, sizeof(md->name)-1, 0.0, 0.0, "Modifier name"); + uiDefBut(block, TEX, 0, "", 0, 0, buttonWidth-60, UI_UNIT_Y, md->name, 0.0, sizeof(md->name)-1, 0.0, 0.0, "Modifier name"); /* Softbody not allowed in this situation, enforce! */ if (((md->type!=eModifierType_Softbody && md->type!=eModifierType_Collision) || !(ob->pd && ob->pd->deflect)) && (md->type!=eModifierType_Surface)) { - uiDefIconButBitI(block, TOG, eModifierMode_Render, B_MODIFIER_RECALC, ICON_SCENE, x+10+buttonWidth-60, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering"); - but= uiDefIconButBitI(block, TOG, eModifierMode_Realtime, B_MODIFIER_RECALC, ICON_VIEW3D, x+10+buttonWidth-40, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display"); + uiDefIconButBitI(block, TOG, eModifierMode_Render, 0, ICON_SCENE, 0, 0, 19, UI_UNIT_Y,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering"); + 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"); if (mti->flags&eModifierTypeFlag_SupportsEditmode) { - uiDefIconButBitI(block, TOG, eModifierMode_Editmode, B_MODIFIER_RECALC, ICON_EDITMODE_HLT, x+10+buttonWidth-20, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode (only if enabled for display)"); + 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)"); } } uiBlockEndAlign(block); @@ -625,26 +515,28 @@ static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, i icon = ICON_BLANK1; } /* XXX uiBlockSetCol(block, color); */ - but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, icon, x+width-105, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Apply modifier to editing cage during Editmode"); + 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"); uiButSetFunc(but, modifiers_setOnCage, ob, md); /* XXX uiBlockSetCol(block, TH_AUTO); */ } + } + subrow= uiLayoutRow(row, 0); + uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT); + + if(!isVirtual) { /* XXX uiBlockSetCol(block, TH_BUT_ACTION); */ - but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_UP, x+width-75, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier up in stack"); + 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"); uiButSetFunc(but, modifiers_moveUp, ob, md); - but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_DOWN, x+width-75+20, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier down in stack"); + 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"); uiButSetFunc(but, modifiers_moveDown, ob, md); uiBlockSetEmboss(block, UI_EMBOSSN); - // deletion over the deflection panel - // fluid particle modifier can't be deleted here - if(md->type!=eModifierType_Fluidsim && md->type!=eModifierType_Collision && md->type!=eModifierType_Surface && !modifier_is_fluid_particles(md)) - { - but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_X, x+width-70+40, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Delete modifier"); + if(modifier_can_delete(md)) { + but = uiDefIconBut(block, BUT, 0, VICON_X, 0, 0, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Delete modifier"); uiButSetFunc(but, modifiers_del, ob, md); } /* XXX uiBlockSetCol(block, TH_AUTO); */ @@ -653,15 +545,11 @@ static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, i uiBlockSetEmboss(block, UI_EMBOSS); if(!isVirtual && (md->mode&eModifierMode_Expanded)) { - int cy = y - 8; - int lx = x + width - 60 - 15; uiLayout *box; box= uiLayoutBox(column); row= uiLayoutRow(box, 1); - y -= 18; - if (!isVirtual && (md->type!=eModifierType_Collision) && (md->type!=eModifierType_Surface)) { uiBlockSetButLock(block, object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE); /* only here obdata, the rest of modifiers is ob level */ @@ -670,13 +558,13 @@ static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, i if(!(G.f & G_PARTICLEEDIT)) { if(ELEM3(psys->part->draw_as, PART_DRAW_PATH, PART_DRAW_GR, PART_DRAW_OB) && psys->pathcache) { - but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Convert", lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Convert the current particles to a mesh object"); + but = uiDefBut(block, BUT, 0, "Convert", 0,0,60,19, 0, 0, 0, 0, 0, "Convert the current particles to a mesh object"); uiButSetFunc(but, modifiers_convertParticles, ob, md); } } } else{ - but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Apply", lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Apply the current modifier and remove from the stack"); + but = uiDefBut(block, BUT, 0, "Apply", 0,0,60,19, 0, 0, 0, 0, 0, "Apply the current modifier and remove from the stack"); uiButSetFunc(but, modifiers_applyModifier, ob, md); } @@ -684,16 +572,13 @@ static uiLayout *draw_modifier(uiLayout *layout, Object *ob, ModifierData *md, i uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE); if (md->type!=eModifierType_Fluidsim && md->type!=eModifierType_Softbody && md->type!=eModifierType_ParticleSystem && (md->type!=eModifierType_Cloth)) { - but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Copy", lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Duplicate the current modifier at the same position in the stack"); + 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"); uiButSetFunc(but, modifiers_copyModifier, ob, md); } } result= uiLayoutColumn(box, 0); block= uiLayoutFreeBlock(box); - - lx = x + 10; - cy = y + 10 - 1; } if (md->error) { @@ -886,7 +771,7 @@ static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short } if ((target != -1) && (owner != -1)) - uiDefIconBut(block, LABEL, B_NOP, ICON_ARROW_LEFTRIGHT, + uiDefIconBut(block, LABEL, 0, ICON_ARROW_LEFTRIGHT, iconx, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, ""); /* Owner-Space */ @@ -906,8 +791,9 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) bPoseChannel *pchan= get_active_posechannel(ob); bConstraintTypeInfo *cti; uiBlock *block; - uiLayout *result= NULL, *col, *box; + uiLayout *result= NULL, *col, *box, *row, *subrow; uiBut *but; + PointerRNA ptr; char typestr[32]; short width = 265; short proxy_protected, xco=0, yco=0; @@ -936,11 +822,19 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) uiBlockSetHandleFunc(block, do_constraint_panels, NULL); uiBlockSetFunc(block, constraint_active_func, ob, con); + RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr); + col= uiLayoutColumn(layout, 1); + uiLayoutSetContextPointer(col, "constraint", &ptr); + box= uiLayoutBox(col); + row= uiLayoutRow(box, 0); block= uiLayoutFreeBlock(box); - + + subrow= uiLayoutRow(row, 0); + uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_LEFT); + /* Draw constraint header */ uiBlockSetEmboss(block, UI_EMBOSSN); @@ -974,6 +868,9 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con) } // XXX uiBlockSetCol(block, TH_AUTO); + + subrow= uiLayoutRow(row, 0); + uiLayoutSetAlignment(subrow, UI_LAYOUT_ALIGN_RIGHT); /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */ if (proxy_protected) { diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index ce8bd7287f7..1eb867e19a0 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -87,6 +87,7 @@ void GROUP_OT_objects_remove_active(struct wmOperatorType *ot); /* object_modifier.c */ void OBJECT_OT_modifier_add(struct wmOperatorType *ot); void OBJECT_OT_multires_subdivide(struct wmOperatorType *ot); +void OBJECT_OT_modifier_mdef_bind(struct wmOperatorType *ot); /* editconstraint.c */ void OBJECT_OT_constraint_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 2e2c16ee6d6..e6b00fa7155 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -42,8 +42,10 @@ #include "BKE_curve.h" #include "BKE_context.h" #include "BKE_depsgraph.h" +#include "BKE_displist.h" #include "BKE_DerivedMesh.h" #include "BKE_global.h" +#include "BKE_lattice.h" #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_multires.h" @@ -396,6 +398,80 @@ void OBJECT_OT_multires_subdivide(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/************************ mdef bind operator *********************/ + +static int modifier_mdef_bind_poll(bContext *C) +{ + PointerRNA ptr= CTX_data_pointer_get(C, "modifier"); + return RNA_struct_is_a(ptr.type, &RNA_MeshDeformModifier); +} + +static int modifier_mdef_bind_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + PointerRNA ptr= CTX_data_pointer_get(C, "modifier"); + Object *ob= ptr.id.data; + MeshDeformModifierData *mmd= ptr.data; + + if(mmd->bindcos) { + if(mmd->bindweights) MEM_freeN(mmd->bindweights); + if(mmd->bindcos) MEM_freeN(mmd->bindcos); + if(mmd->dyngrid) MEM_freeN(mmd->dyngrid); + if(mmd->dyninfluences) MEM_freeN(mmd->dyninfluences); + if(mmd->dynverts) MEM_freeN(mmd->dynverts); + mmd->bindweights= NULL; + mmd->bindcos= NULL; + mmd->dyngrid= NULL; + mmd->dyninfluences= NULL; + mmd->dynverts= NULL; + mmd->totvert= 0; + mmd->totcagevert= 0; + mmd->totinfluence= 0; + } + else { + DerivedMesh *dm; + int mode= mmd->modifier.mode; + + /* force modifier to run, it will call binding routine */ + mmd->needbind= 1; + mmd->modifier.mode |= eModifierMode_Realtime; + + if(ob->type == OB_MESH) { + dm= mesh_create_derived_view(scene, ob, 0); + dm->release(dm); + } + else if(ob->type == OB_LATTICE) { + lattice_calc_modifiers(scene, ob); + } + else if(ob->type==OB_MBALL) { + makeDispListMBall(scene, ob); + } + else if(ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { + makeDispListCurveTypes(scene, ob, 0); + } + + mmd->needbind= 0; + mmd->modifier.mode= mode; + } + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_modifier_mdef_bind(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Mesh Deform Bind"; + ot->description = "Bind mesh to cage in mesh deform modifier."; + ot->idname= "OBJECT_OT_modifier_mdef_bind"; + + /* api callbacks */ + ot->poll= modifier_mdef_bind_poll; + ot->exec= modifier_mdef_bind_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + #if 0 static void modifiers_add(void *ob_v, int type) { @@ -469,3 +545,89 @@ static uiBlock *modifiers_add_menu(void *ob_v) } #endif +#if 0 +static void modifiers_clearHookOffset(bContext *C, void *ob_v, void *md_v) +{ + Object *ob = ob_v; + ModifierData *md = md_v; + HookModifierData *hmd = (HookModifierData*) md; + + if (hmd->object) { + Mat4Invert(hmd->object->imat, hmd->object->obmat); + Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); + ED_undo_push(C, "Clear hook offset"); + } +} + +static void modifiers_cursorHookCenter(bContext *C, void *ob_v, void *md_v) +{ + /* XXX + Object *ob = ob_v; + ModifierData *md = md_v; + HookModifierData *hmd = (HookModifierData*) md; + + if(G.vd) { + float *curs = give_cursor(); + float bmat[3][3], imat[3][3]; + + where_is_object(ob); + + Mat3CpyMat4(bmat, ob->obmat); + Mat3Inv(imat, bmat); + + curs= give_cursor(); + hmd->cent[0]= curs[0]-ob->obmat[3][0]; + hmd->cent[1]= curs[1]-ob->obmat[3][1]; + hmd->cent[2]= curs[2]-ob->obmat[3][2]; + Mat3MulVecfl(imat, hmd->cent); + + ED_undo_push(C, "Hook cursor center"); + }*/ +} + +static void modifiers_selectHook(bContext *C, void *ob_v, void *md_v) +{ + /* XXX ModifierData *md = md_v; + HookModifierData *hmd = (HookModifierData*) md; + + hook_select(hmd);*/ +} + +static void modifiers_reassignHook(bContext *C, void *ob_v, void *md_v) +{ + /* XXX ModifierData *md = md_v; + HookModifierData *hmd = (HookModifierData*) md; + float cent[3]; + int *indexar, tot, ok; + char name[32]; + + ok= hook_getIndexArray(&tot, &indexar, name, cent); + + if (!ok) { + uiPupMenuError(C, "Requires selected vertices or active Vertex Group"); + } else { + if (hmd->indexar) { + MEM_freeN(hmd->indexar); + } + + VECCOPY(hmd->cent, cent); + hmd->indexar = indexar; + hmd->totindex = tot; + }*/ +} + +void modifiers_explodeFacepa(bContext *C, void *arg1, void *arg2) +{ + ExplodeModifierData *emd=arg1; + + emd->flag |= eExplodeFlag_CalcFaces; +} + +void modifiers_explodeDelVg(bContext *C, void *arg1, void *arg2) +{ + ExplodeModifierData *emd=arg1; + emd->vgroup = 0; +} +#endif + + diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 9d8247522e1..cfee6a55152 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -101,6 +101,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_modifier_add); WM_operatortype_append(OBJECT_OT_multires_subdivide); + WM_operatortype_append(OBJECT_OT_modifier_mdef_bind); WM_operatortype_append(OBJECT_OT_constraint_add); } |