static int disconnect_hair_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); Object *ob= ED_object_context(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= NULL; int all = RNA_boolean_get(op->ptr, "all"); if (!ob) return OPERATOR_CANCELLED; if (all) { for (psys=ob->particlesystem.first; psys; psys=psys->next) { disconnect_hair(scene, ob, psys); } } else { psys = ptr.data; disconnect_hair(scene, ob, psys); } DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob); return OPERATOR_FINISHED; }
static int surface_slot_add_exec(bContext *C, wmOperator *UNUSED(op)) { DynamicPaintModifierData *pmd = NULL; Object *cObject = ED_object_context(C); DynamicPaintCanvasSettings *canvas; DynamicPaintSurface *surface; /* Make sure we're dealing with a canvas */ pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint); if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED; canvas = pmd->canvas; surface = dynamicPaint_createNewSurface(canvas, CTX_data_scene(C)); if (!surface) return OPERATOR_CANCELLED; /* set preview for this surface only and set active */ canvas->active_sur = 0; for (surface = surface->prev; surface; surface = surface->prev) { surface->flags &= ~MOD_DPAINT_PREVIEW; canvas->active_sur++; } return OPERATOR_FINISHED; }
/* * Bake Dynamic Paint image sequence surface */ static int dynamicPaint_initBake(struct bContext *C, struct wmOperator *op) { DynamicPaintModifierData *pmd = NULL; DynamicPaintCanvasSettings *canvas; Object *ob = ED_object_context(C); int status = 0; double timer = PIL_check_seconds_timer(); DynamicPaintSurface *surface; /* * Get modifier data */ pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint); if (!pmd) { BKE_report(op->reports, RPT_ERROR, "Bake failed: no Dynamic Paint modifier found"); return 0; } /* Make sure we're dealing with a canvas */ canvas = pmd->canvas; if (!canvas) { BKE_report(op->reports, RPT_ERROR, "Bake failed: invalid canvas"); return 0; } surface = get_activeSurface(canvas); /* Set state to baking and init surface */ canvas->error[0] = '\0'; canvas->flags |= MOD_DPAINT_BAKING; G.is_break = FALSE; /* reset blender_test_break*/ /* Bake Dynamic Paint */ status = dynamicPaint_bakeImageSequence(C, surface, ob); /* Clear bake */ canvas->flags &= ~MOD_DPAINT_BAKING; WM_cursor_restore(CTX_wm_window(C)); dynamicPaint_freeSurfaceData(surface); /* Bake was successful: * Report for ended bake and how long it took */ if (status) { /* Format time string */ char time_str[30]; double time = PIL_check_seconds_timer() - timer; BLI_timestr(time, time_str); /* Show bake info */ BKE_reportf(op->reports, RPT_INFO, "Bake complete! (%s)", time_str); } else { if (strlen(canvas->error)) { /* If an error occurred */ BKE_reportf(op->reports, RPT_ERROR, "Bake failed: %s", canvas->error); } else { /* User canceled the bake */ BKE_report(op->reports, RPT_WARNING, "Baking canceled!"); } } return status; }
static int connect_hair_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); Object *ob= ED_object_context(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= NULL; const bool all = RNA_boolean_get(op->ptr, "all"); bool any_connected = false; if (!ob) return OPERATOR_CANCELLED; if (all) { for (psys=ob->particlesystem.first; psys; psys=psys->next) { any_connected |= connect_hair(scene, ob, psys); } } else { psys = ptr.data; any_connected |= connect_hair(scene, ob, psys); } if (!any_connected) { BKE_report(op->reports, RPT_ERROR, "Can't disconnect hair if particle system modifier is disabled"); return OPERATOR_CANCELLED; } DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob); return OPERATOR_FINISHED; }
static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op)) { DynamicPaintModifierData *pmd = NULL; Object *obj_ctx = ED_object_context(C); DynamicPaintCanvasSettings *canvas; DynamicPaintSurface *surface; int id = 0; /* Make sure we're dealing with a canvas */ pmd = (DynamicPaintModifierData *)modifiers_findByType(obj_ctx, eModifierType_DynamicPaint); if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED; canvas = pmd->canvas; surface = canvas->surfaces.first; /* find active surface and remove it */ for (; surface; surface = surface->next) { if (id == canvas->active_sur) { canvas->active_sur -= 1; dynamicPaint_freeSurface(surface); break; } id++; } dynamicPaint_resetPreview(canvas); DAG_id_tag_update(&obj_ctx->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obj_ctx); return OPERATOR_FINISHED; }
/* can be called with C == NULL */ static EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Object *ob; EnumPropertyItem *item = NULL, item_tmp = {0}; int totitem = 0; if (C == NULL) { return DummyRNA_NULL_items; } ob = ED_object_context(C); /* check that the action exists */ if (ob) { Group *group = NULL; int i = 0; while ((group = BKE_group_object_find(group, ob))) { item_tmp.identifier = item_tmp.name = group->id.name + 2; /* item_tmp.icon = ICON_ARMATURE_DATA; */ item_tmp.value = i; RNA_enum_item_add(&item, &totitem, &item_tmp); i++; } } RNA_enum_item_end(&item, &totitem); *free = 1; return item; }
static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); Scene *scene = CTX_data_scene(C); int mode_orig; if (!scene || !ob) return OPERATOR_CANCELLED; mode_orig = ob->mode; object_remove_particle_system(scene, ob); /* possible this isn't the active object * object_remove_particle_system() clears the mode on the last psys */ if (mode_orig & OB_MODE_PARTICLE_EDIT) { if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) { if (scene->basact && scene->basact->object == ob) { WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL); } } } WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob); WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); return OPERATOR_FINISHED; }
static int shape_key_move_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); Key *key = BKE_key_from_object(ob); const int type = RNA_enum_get(op->ptr, "type"); const int totkey = key->totkey; const int act_index = ob->shapenr - 1; int new_index; switch (type) { case KB_MOVE_TOP: /* Replace the ref key only if we're at the top already (only for relative keys) */ new_index = (ELEM(act_index, 0, 1) || key->type == KEY_NORMAL) ? 0 : 1; break; case KB_MOVE_BOTTOM: new_index = totkey - 1; break; case KB_MOVE_UP: case KB_MOVE_DOWN: default: new_index = (totkey + act_index + type) % totkey; break; } if (!BKE_keyblock_move(ob, act_index, new_index)) { return OPERATOR_CANCELLED; } DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); return OPERATOR_FINISHED; }
static int type_toggle_exec(bContext *C, wmOperator *op) { Object *cObject = ED_object_context(C); Scene *scene = CTX_data_scene(C); DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint); int type = RNA_enum_get(op->ptr, "type"); if (!pmd) return OPERATOR_CANCELLED; /* if type is already enabled, toggle it off */ if (type == MOD_DYNAMICPAINT_TYPE_CANVAS && pmd->canvas) { dynamicPaint_freeCanvas(pmd); } else if (type == MOD_DYNAMICPAINT_TYPE_BRUSH && pmd->brush) { dynamicPaint_freeBrush(pmd); } /* else create a new type */ else { if (!dynamicPaint_createType(pmd, type, scene)) return OPERATOR_CANCELLED; } /* update dependency */ DAG_id_tag_update(&cObject->id, OB_RECALC_DATA); DAG_relations_tag_update(CTX_data_main(C)); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, cObject); return OPERATOR_FINISHED; }
static int shape_key_move_poll(bContext *C) { /* Same as shape_key_mode_exists_poll above, but ensure we have at least two shapes! */ Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; Key *key = BKE_key_from_object(ob); return (ob && !ob->id.lib && data && !data->lib && ob->mode != OB_MODE_EDIT && key && key->totkey > 1); }
/* find the correct active object per context * note: context can be NULL when called from a enum with PROP_ENUM_NO_CONTEXT */ Object *ED_object_active_context(bContext *C) { Object *ob= NULL; if (C) { ob= ED_object_context(C); if (!ob) ob= CTX_data_active_object(C); } return ob; }
static int shape_key_add_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob = ED_object_context(C); const bool from_mix = RNA_boolean_get(op->ptr, "from_mix"); ED_object_shape_key_add(C, scene, ob, from_mix); return OPERATOR_FINISHED; }
static int shape_key_mode_exists_poll(bContext *C) { Object *ob = ED_object_context(C); ID *data = (ob) ? ob->data : NULL; /* same as shape_key_mode_poll */ return (ob && !ob->id.lib && data && !data->lib && ob->mode != OB_MODE_EDIT) && /* check a keyblock exists */ (BKE_keyblock_from_object(ob) != NULL); }
static int object_lod_remove_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); int index = RNA_int_get(op->ptr, "index"); if (!BKE_object_lod_remove(ob, index)) return OPERATOR_CANCELLED; WM_event_add_notifier(C, NC_OBJECT | ND_LOD, CTX_wm_view3d(C)); return OPERATOR_FINISHED; }
static int shape_key_add_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); const bool from_mix = RNA_boolean_get(op->ptr, "from_mix"); ED_object_shape_key_add(C, ob, from_mix); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); DAG_relations_tag_update(CTX_data_main(C)); return OPERATOR_FINISHED; }
static int object_lod_add_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); #ifdef WITH_GAMEENGINE BKE_object_lod_add(ob); #else (void)ob; #endif return OPERATOR_FINISHED; }
/* * Bake Dynamic Paint image sequence surface */ static int dynamicpaint_bake_exec(struct bContext *C, struct wmOperator *op) { DynamicPaintModifierData *pmd = NULL; DynamicPaintCanvasSettings *canvas; Object *ob = ED_object_context(C); Scene *scene = CTX_data_scene(C); DynamicPaintSurface *surface; /* * Get modifier data */ pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint); if (!pmd) { BKE_report(op->reports, RPT_ERROR, "Bake failed: no Dynamic Paint modifier found"); return OPERATOR_CANCELLED; } /* Make sure we're dealing with a canvas */ canvas = pmd->canvas; if (!canvas) { BKE_report(op->reports, RPT_ERROR, "Bake failed: invalid canvas"); return OPERATOR_CANCELLED; } surface = get_activeSurface(canvas); /* Set state to baking and init surface */ canvas->error[0] = '\0'; canvas->flags |= MOD_DPAINT_BAKING; DynamicPaintBakeJob *job = MEM_mallocN(sizeof(DynamicPaintBakeJob), "DynamicPaintBakeJob"); job->bmain = CTX_data_main(C); job->scene = scene; job->ob = ob; job->canvas = canvas; job->surface = surface; wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Dynamic Paint Bake", WM_JOB_PROGRESS, WM_JOB_TYPE_DPAINT_BAKE); WM_jobs_customdata_set(wm_job, job, dpaint_bake_free); WM_jobs_timer(wm_job, 0.1, NC_OBJECT | ND_MODIFIER, NC_OBJECT | ND_MODIFIER); WM_jobs_callbacks(wm_job, dpaint_bake_startjob, NULL, NULL, dpaint_bake_endjob); WM_set_locked_interface(CTX_wm_manager(C), true); /* Bake Dynamic Paint */ WM_jobs_start(CTX_wm_manager(C), wm_job); return OPERATOR_FINISHED; }
static int shape_key_mirror_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); int totmirr = 0, totfail = 0; bool use_topology = RNA_boolean_get(op->ptr, "use_topology"); if (!object_shape_key_mirror(C, ob, &totmirr, &totfail, use_topology)) return OPERATOR_CANCELLED; ED_mesh_report_mirror(op, totmirr, totfail); return OPERATOR_FINISHED; }
static int objects_add_active_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); int single_group_index = RNA_enum_get(op->ptr, "group"); Group *single_group = group_object_active_find_index(ob, single_group_index); Group *group; bool is_cycle = false; bool updated = false; if (ob == NULL) return OPERATOR_CANCELLED; /* now add all selected objects to the group(s) */ for (group = bmain->group.first; group; group = group->id.next) { if (single_group && group != single_group) continue; if (!BKE_group_object_exists(group, ob)) continue; /* for recursive check */ BKE_main_id_tag_listbase(&bmain->group, true); CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { if (group_link_early_exit_check(group, base->object)) continue; if (base->object->dup_group != group && !check_group_contains_object_recursive(group, base->object)) { BKE_group_object_add(group, base->object, scene, base); updated = true; } else { is_cycle = true; } } CTX_DATA_END; } if (is_cycle) BKE_report(op->reports, RPT_WARNING, "Skipped some groups because of cycle detected"); if (!updated) return OPERATOR_CANCELLED; DAG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL); return OPERATOR_FINISHED; }
static int particle_system_add_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= ED_object_context(C); Scene *scene = CTX_data_scene(C); if (!scene || !ob) return OPERATOR_CANCELLED; object_add_particle_system(scene, ob, NULL); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob); WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); return OPERATOR_FINISHED; }
/* XXX C can be zero */ static Object *get_poselib_object (bContext *C) { ScrArea *sa; /* sanity check */ if (C == NULL) return NULL; sa = CTX_wm_area(C); if (sa && (sa->spacetype == SPACE_BUTS)) return ED_object_context(C); else return object_pose_armature_get(CTX_data_active_object(C)); }
/* matches logic with ED_operator_posemode_context() */ Object *ED_pose_object_from_context(bContext *C) { ScrArea *sa = CTX_wm_area(C); Object *ob; /* since this call may also be used from the buttons window, we need to check for where to get the object */ if (sa && sa->spacetype == SPACE_BUTS) { ob = ED_object_context(C); } else { ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); } return ob; }
static int shape_key_clear_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); Key *key = BKE_key_from_object(ob); KeyBlock *kb = BKE_keyblock_from_object(ob); if (!key || !kb) return OPERATOR_CANCELLED; for (kb = key->block.first; kb; kb = kb->next) kb->curval = 0.0f; DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); return OPERATOR_FINISHED; }
static int pose_de_select_all_exec(bContext *C, wmOperator *op) { int action = RNA_enum_get(op->ptr, "action"); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_context(C); bArmature *arm = ob->data; int multipaint = scene->toolsettings->multipaint; if (action == SEL_TOGGLE) { action = CTX_DATA_COUNT(C, selected_pose_bones) ? SEL_DESELECT : SEL_SELECT; } /* Set the flags */ CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pose_bones) { /* select pchan only if selectable, but deselect works always */ switch (action) { case SEL_SELECT: if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) pchan->bone->flag |= BONE_SELECTED; break; case SEL_DESELECT: pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); break; case SEL_INVERT: if (pchan->bone->flag & BONE_SELECTED) { pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); } else if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) { pchan->bone->flag |= BONE_SELECTED; } break; } } CTX_DATA_END; WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, NULL); /* weightpaint or mask modifiers need depsgraph updates */ if (multipaint || (arm->flag & ARM_HAS_VIZ_DEPS)) { DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } return OPERATOR_FINISHED; }
/* can be called with C == NULL */ static EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { Object *ob; EnumPropertyItem *item = NULL, item_tmp = {0}; int totitem = 0; if (C == NULL) { return DummyRNA_NULL_items; } ob = ED_object_context(C); /* check that the object exists */ if (ob) { Group *group; int i = 0, count = 0; /* if 2 or more groups, add option to add to all groups */ group = NULL; while ((group = BKE_group_object_find(group, ob))) count++; if (count >= 2) { item_tmp.identifier = item_tmp.name = "All Groups"; item_tmp.value = INT_MAX; /* this will give NULL on lookup */ RNA_enum_item_add(&item, &totitem, &item_tmp); RNA_enum_item_add_separator(&item, &totitem); } /* add groups */ group = NULL; while ((group = BKE_group_object_find(group, ob))) { item_tmp.identifier = item_tmp.name = group->id.name + 2; /* item_tmp.icon = ICON_ARMATURE_DATA; */ item_tmp.value = i; RNA_enum_item_add(&item, &totitem, &item_tmp); i++; } } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
static int pose_de_select_all_exec(bContext *C, wmOperator *op) { int action = RNA_enum_get(op->ptr, "action"); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_context(C); bArmature *arm = ob->data; int multipaint = scene->toolsettings->multipaint; if (action == SEL_TOGGLE) { action = CTX_DATA_COUNT(C, selected_pose_bones) ? SEL_DESELECT : SEL_SELECT; } /* Set the flags */ CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pose_bones) { pose_do_bone_select(pchan, action); }
static int objects_add_active_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); int group_object_index = RNA_enum_get(op->ptr, "group"); int is_cycle = FALSE; if (ob) { Group *group = group_object_active_find_index(ob, group_object_index); /* now add all selected objects from the group */ if (group) { /* for recursive check */ tag_main_lb(&bmain->group, TRUE); CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { if (group_link_early_exit_check(group, base->object)) continue; if (base->object->dup_group != group && !check_group_contains_object_recursive(group, base->object)) { BKE_group_object_add(group, base->object, scene, base); } else { is_cycle = TRUE; } } CTX_DATA_END; if (is_cycle) { BKE_report(op->reports, RPT_WARNING, "Skipped some groups because of cycle detected"); } DAG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL); return OPERATOR_FINISHED; } } return OPERATOR_CANCELLED; }
static int output_toggle_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); Scene *scene = CTX_data_scene(C); DynamicPaintSurface *surface; DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint); int output= RNA_enum_get(op->ptr, "output"); /* currently only 1/0 */ if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED; surface = get_activeSurface(pmd->canvas); /* if type is already enabled, toggle it off */ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { int exists = dynamicPaint_outputLayerExists(surface, ob, output); const char *name; if (output == 0) name = surface->output_name; else name = surface->output_name2; /* Vertex Color Layer */ if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) { if (!exists) ED_mesh_color_add(C, scene, ob, ob->data, name, 1); else ED_mesh_color_remove_named(C, ob, ob->data, name); } /* Vertex Weight Layer */ else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { if (!exists) { ED_vgroup_add_name(ob, name); } else { bDeformGroup *defgroup = defgroup_find_name(ob, name); if (defgroup) ED_vgroup_delete(ob, defgroup); } } } return OPERATOR_FINISHED; }
/* starting point and step size could be optional */ static int shape_key_retime_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); Key *key = BKE_key_from_object(ob); KeyBlock *kb = BKE_keyblock_from_object(ob); float cfra = 0.0f; if (!key || !kb) { return OPERATOR_CANCELLED; } for (kb = key->block.first; kb; kb = kb->next) { kb->pos = cfra; cfra += 0.1f; } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); return OPERATOR_FINISHED; }
static int shape_key_remove_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Object *ob = ED_object_context(C); bool changed = false; if (RNA_boolean_get(op->ptr, "all")) { changed = ED_object_shape_key_remove_all(bmain, ob); } else { changed = ED_object_shape_key_remove(bmain, ob); } if (changed) { DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); return OPERATOR_FINISHED; } else { return OPERATOR_CANCELLED; } }