static int face_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_active_object(C); paintface_deselect_all_visible(ob, SEL_INVERT, TRUE); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op)) { View3D *v3d; ARegion *ar; RegionView3D *rv3d; Scene *scene= CTX_data_scene(C); Object *ob = CTX_data_active_object(C); /* no NULL check is needed, poll checks */ ED_view3d_context_user_region(C, &v3d, &ar); rv3d = ar->regiondata; if(ob) { Object *camera_old= (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : NULL; rv3d->persp= RV3D_CAMOB; v3d->camera= ob; if(v3d->scenelock) scene->camera= ob; if(camera_old != ob) /* unlikely but looks like a glitch when set to the same */ smooth_view(C, v3d, ar, camera_old, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens); WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS|NC_OBJECT|ND_DRAW, CTX_data_scene(C)); } return OPERATOR_FINISHED; }
static int poselib_rename_exec (bContext *C, wmOperator *op) { Object *ob= object_pose_armature_get(CTX_data_active_object(C)); bAction *act= (ob) ? ob->poselib : NULL; TimeMarker *marker; char newname[64]; /* check if valid poselib */ if (act == NULL) { BKE_report(op->reports, RPT_ERROR, "Object doesn't have PoseLib data"); return OPERATOR_CANCELLED; } /* get index (and pointer) of pose to remove */ marker= BLI_findlink(&act->markers, RNA_int_get(op->ptr, "pose")); if (marker == NULL) { BKE_report(op->reports, RPT_ERROR, "Invalid index for Pose"); return OPERATOR_CANCELLED; } /* get new name */ RNA_string_get(op->ptr, "name", newname); /* copy name and validate it */ BLI_strncpy(marker->name, newname, sizeof(marker->name)); BLI_uniquename(&act->markers, marker, "Pose", '.', offsetof(TimeMarker, name), sizeof(marker->name)); /* send notifiers for this - using keyframe editing notifiers, since action * may be being shown in anim editors as active action */ WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL); /* done */ return OPERATOR_FINISHED; }
static int mask_flood_fill_exec(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); Object *ob = CTX_data_active_object(C); PaintMaskFloodMode mode; float value; DerivedMesh *dm; PBVH *pbvh; PBVHNode **nodes; int totnode, i; mode = RNA_enum_get(op->ptr, "mode"); value = RNA_float_get(op->ptr, "value"); dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH); pbvh = dm->getPBVH(ob, dm); ob->sculpt->pbvh = pbvh; BLI_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode); sculpt_undo_push_begin("Mask flood fill"); for (i = 0; i < totnode; i++) { PBVHVertexIter vi; sculpt_undo_push_node(ob, nodes[i], SCULPT_UNDO_MASK); BLI_pbvh_vertex_iter_begin(pbvh, nodes[i], vi, PBVH_ITER_UNIQUE) { mask_flood_fill_set_elem(vi.mask, mode, value); } BLI_pbvh_vertex_iter_end; BLI_pbvh_node_mark_update(nodes[i]); if (BLI_pbvh_type(pbvh) == PBVH_GRIDS) multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED); }
/* Criteria: * 1) There must be an dopesheet/action editor, and it must be in a mode which uses actions... * OR * The NLA Editor is active (i.e. Animation Data panel -> new action) * 2) The associated AnimData block must not be in tweakmode */ static int action_new_poll(bContext *C) { Scene *scene = CTX_data_scene(C); /* Check tweakmode is off (as you don't want to be tampering with the action in that case) */ /* NOTE: unlike for pushdown, this operator needs to be run when creating an action from nothing... */ if (ED_operator_action_active(C)) { SpaceAction *saction = (SpaceAction *)CTX_wm_space_data(C); Object *ob = CTX_data_active_object(C); /* For now, actions are only for the active object, and on object and shapekey levels... */ if (saction->mode == SACTCONT_ACTION) { /* XXX: This assumes that actions are assigned to the active object in this mode */ if (ob) { if ((ob->adt == NULL) || (ob->adt->flag & ADT_NLA_EDIT_ON) == 0) return true; } } else if (saction->mode == SACTCONT_SHAPEKEY) { Key *key = BKE_key_from_object(ob); if (key) { if ((key->adt == NULL) || (key->adt->flag & ADT_NLA_EDIT_ON) == 0) return true; } } } else if (ED_operator_nla_active(C)) { if (!(scene->flag & SCE_NLA_EDIT_ON)) { return true; } } /* something failed... */ return false; }
bool ED_texture_context_check_others(const bContext *C) { /* We cannot rely on sbuts->texuser here, as it is NULL when in "old" tex handling, non-OTHERS tex context. */ Object *ob = CTX_data_active_object(C); /* object */ if (ob) { /* Tex force field. */ if (ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) { return true; } /* modifiers */ { bool check = false; modifiers_foreachTexLink(ob, texture_context_check_modifier_foreach, &check); if (check) { return true; } } } /* brush */ if (BKE_paint_brush(BKE_paint_get_active_from_context(C))) { return true; } return false; }
static int fluid_bake_exec(bContext *C, wmOperator *op) { if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), false)) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; }
static int pose_select_parent_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); bArmature *arm = (bArmature *)ob->data; bPoseChannel *pchan, *parent; /* Determine if there is an active bone */ pchan = CTX_data_active_pose_bone(C); if (pchan) { parent = pchan->parent; if ((parent) && !(parent->bone->flag & (BONE_HIDDEN_P | BONE_UNSELECTABLE))) { parent->bone->flag |= BONE_SELECTED; arm->act_bone = parent->bone; } else { return OPERATOR_CANCELLED; } } else { return OPERATOR_CANCELLED; } /* updates */ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob); if (arm->flag & ARM_HAS_VIZ_DEPS) { /* mask modifier ('armature' mode), etc. */ DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } return OPERATOR_FINISHED; }
static int sculpt_undo_restore_hidden(bContext *C, DerivedMesh *dm, SculptUndoNode *unode) { Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; int i; if (unode->maxvert) { MVert *mvert = ss->mvert; for (i = 0; i < unode->totvert; i++) { MVert *v = &mvert[unode->index[i]]; int uval = BLI_BITMAP_GET(unode->vert_hidden, i); BLI_BITMAP_MODIFY(unode->vert_hidden, i, v->flag & ME_HIDE); if (uval) v->flag |= ME_HIDE; else v->flag &= ~ME_HIDE; v->flag |= ME_VERT_PBVH_UPDATE; } } else if (unode->maxgrid && dm->getGridData) { BLI_bitmap **grid_hidden = dm->getGridHidden(dm); for (i = 0; i < unode->totgrid; i++) { SWAP(BLI_bitmap *, unode->grid_hidden[i], grid_hidden[unode->grids[i]]); } }
bool paint_curve_poll(bContext *C) { Object *ob = CTX_data_active_object(C); Paint *p; RegionView3D *rv3d = CTX_wm_region_view3d(C); SpaceImage *sima; if (rv3d && !(ob && ((ob->mode & OB_MODE_ALL_PAINT) != 0))) { return false; } sima = CTX_wm_space_image(C); if (sima && sima->mode != SI_MODE_PAINT) { return false; } p = BKE_paint_get_active_from_context(C); if (p && p->brush && (p->brush->flag & BRUSH_CURVE)) { return true; } return false; }
/* For the object with pose/action: create path curves for selected bones * This recalculates the WHOLE path within the pchan->pathsf and pchan->pathef range */ static int pose_calculate_paths_exec(bContext *C, wmOperator *op) { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); Scene *scene = CTX_data_scene(C); if (ELEM(NULL, ob, ob->pose)) return OPERATOR_CANCELLED; /* grab baking settings from operator settings */ { bAnimVizSettings *avs = &ob->pose->avs; PointerRNA avs_ptr; avs->path_sf = RNA_int_get(op->ptr, "start_frame"); avs->path_ef = RNA_int_get(op->ptr, "end_frame"); RNA_pointer_create(NULL, &RNA_AnimVizMotionPaths, avs, &avs_ptr); RNA_enum_set(&avs_ptr, "bake_location", RNA_enum_get(op->ptr, "bake_location")); } /* set up path data for bones being calculated */ CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones) { /* verify makes sure that the selected bone has a bone with the appropriate settings */ animviz_verify_motionpaths(op->reports, scene, ob, pchan); }
static int face_select_reveal_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); paintface_reveal(ob); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static int paint_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event) { int mode= RNA_boolean_get(op->ptr, "extend") ? 1:0; select_linked_tfaces(C, CTX_data_active_object(C), event->mval, mode); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
/* set the current pose as the restpose */ static int pose_visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); // must be active object, not edit-object /* don't check if editmode (should be done by caller) */ if (ob->type != OB_ARMATURE) return OPERATOR_CANCELLED; /* loop over all selected pchans * * TODO, loop over children before parents if multiple bones * at once are to be predictable*/ CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones) { float delta_mat[4][4]; /* chan_mat already contains the delta transform from rest pose to pose-mode pose * as that is baked into there so that B-Bones will work. Once we've set this as the * new raw-transform components, don't recalc the poses yet, otherwise IK result will * change, thus changing the result we may be trying to record. */ /* XXX For some reason, we can't use pchan->chan_mat here, gives odd rotation/offset (see T38251). * Using pchan->pose_mat and bringing it back in bone space seems to work as expected! */ BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, delta_mat); BKE_pchan_apply_mat4(pchan, delta_mat, true); }
void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey, int method) { Object *ob= CTX_data_active_object(C); wmJob *steve; ShaderPreview *sp; steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, "Shader Preview", WM_JOB_EXCL_RENDER); sp= MEM_callocN(sizeof(ShaderPreview), "shader preview"); /* customdata for preview thread */ sp->scene= CTX_data_scene(C); sp->owner= owner; sp->sizex= sizex; sp->sizey= sizey; sp->pr_method= method; sp->id = id; sp->parent= parent; sp->slot= slot; if(ob && ob->totcol) copy_v4_v4(sp->col, ob->col); else sp->col[0]= sp->col[1]= sp->col[2]= sp->col[3]= 1.0f; /* setup job */ WM_jobs_customdata(steve, sp, shader_preview_free); WM_jobs_timer(steve, 0.1, NC_MATERIAL, NC_MATERIAL); WM_jobs_callbacks(steve, common_preview_startjob, NULL, shader_preview_updatejob, NULL); WM_jobs_start(CTX_wm_manager(C), steve); }
static int vert_select_all_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_active_object(C); paintvert_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), true); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
/* Check if context data is suitable for the given absolute Keying Set */ short keyingset_context_ok_poll (bContext *C, KeyingSet *ks) { ScrArea *sa= CTX_wm_area(C); /* data retrieved from context depends on active editor */ if (sa == NULL) return 0; switch (sa->spacetype) { case SPACE_VIEW3D: { Object *obact= CTX_data_active_object(C); /* if in posemode, check if 'pose-channels' requested for in KeyingSet */ if ((obact && obact->pose) && (obact->mode & OB_MODE_POSE)) { /* check for posechannels */ } else { /* check for selected object */ } } break; } return 1; }
/* draw keyframe lines for timeline */ static void time_draw_keyframes(const bContext *C, ARegion *ar) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); View2D *v2d = &ar->v2d; bool onlysel = ((scene->flag & SCE_KEYS_NO_SELONLY) == 0); /* set this for all keyframe lines once and for all */ glLineWidth(1.0); /* draw grease pencil keyframes (if available) */ UI_ThemeColor(TH_TIME_GP_KEYFRAME); if (scene->gpd) { time_draw_idblock_keyframes(v2d, (ID *)scene->gpd, onlysel); } if (ob && ob->gpd) { time_draw_idblock_keyframes(v2d, (ID *)ob->gpd, onlysel); } /* draw scene keyframes first * - don't try to do this when only drawing active/selected data keyframes, * since this can become quite slow */ if (onlysel == 0) { /* set draw color */ UI_ThemeColorShade(TH_TIME_KEYFRAME, -50); time_draw_idblock_keyframes(v2d, (ID *)scene, onlysel); } /* draw keyframes from selected objects * - only do the active object if in posemode (i.e. showing only keyframes for the bones) * OR the onlysel flag was set, which means that only active object's keyframes should * be considered */ UI_ThemeColor(TH_TIME_KEYFRAME); if (ob && ((ob->mode == OB_MODE_POSE) || onlysel)) { /* draw keyframes for active object only */ time_draw_idblock_keyframes(v2d, (ID *)ob, onlysel); } else { bool active_done = false; /* draw keyframes from all selected objects */ CTX_DATA_BEGIN (C, Object *, obsel, selected_objects) { /* last arg is 0, since onlysel doesn't apply here... */ time_draw_idblock_keyframes(v2d, (ID *)obsel, 0); /* if this object is the active one, set flag so that we don't draw again */ if (obsel == ob) active_done = true; } CTX_DATA_END; /* if active object hasn't been done yet, draw it... */ if (ob && (active_done == 0)) time_draw_idblock_keyframes(v2d, (ID *)ob, 0); }
static int face_select_hide_exec(bContext *C, wmOperator *op) { const bool unselected = RNA_boolean_get(op->ptr, "unselected"); Object *ob = CTX_data_active_object(C); paintface_hide(ob, unselected); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static int paint_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) { const bool select = !RNA_boolean_get(op->ptr, "deselect"); view3d_operator_needs_opengl(C); paintface_select_linked(C, CTX_data_active_object(C), event->mval, select); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; }
static int make_regular_poll(bContext *C) { Object *ob; if (ED_operator_editlattice(C)) return 1; ob = CTX_data_active_object(C); return (ob && ob->type == OB_LATTICE); }
/* Temporary wrapper for driver operators for buttons to make it easier to create * such drivers by rerouting all paths through the active object instead so that * they will get picked up by the dependency system. * * < C: context pointer - for getting active data * <> ptr: RNA pointer for property's datablock. May be modified as result of path remapping. * < prop: RNA definition of property to add for * * > returns: MEM_alloc'd string representing the path to the property from the given PointerRNA */ static char *get_driver_path_hack(bContext *C, PointerRNA *ptr, PropertyRNA *prop) { ID *id = (ID *)ptr->id.data; ScrArea *sa = CTX_wm_area(C); /* get standard path which may be extended */ char *basepath = RNA_path_from_ID_to_property(ptr, prop); char *path = basepath; /* in case no remapping is needed */ /* Remapping will only be performed in the Properties Editor, as only this * restricts the subspace of options to the 'active' data (a manageable state) */ // TODO: watch out for pinned context? if ((sa) && (sa->spacetype == SPACE_BUTS)) { Object *ob = CTX_data_active_object(C); if (ob && id) { /* only id-types which can be remapped to go through objects should be considered */ switch (GS(id->name)) { case ID_TE: /* textures */ { Material *ma = give_current_material(ob, ob->actcol); Tex *tex = give_current_material_texture(ma); /* assumes: texture will only be shown if it is active material's active texture it's ok */ if ((ID *)tex == id) { char name_esc_ma[(sizeof(ma->id.name) - 2) * 2]; char name_esc_tex[(sizeof(tex->id.name) - 2) * 2]; BLI_strescape(name_esc_ma, ma->id.name + 2, sizeof(name_esc_ma)); BLI_strescape(name_esc_tex, tex->id.name + 2, sizeof(name_esc_tex)); /* create new path */ // TODO: use RNA path functions to construct step by step instead? // FIXME: maybe this isn't even needed anymore... path = BLI_sprintfN("material_slots[\"%s\"].material.texture_slots[\"%s\"].texture.%s", name_esc_ma, name_esc_tex, basepath); /* free old one */ MEM_freeN(basepath); } break; } } /* fix RNA pointer, as we've now changed the ID root by changing the paths */ if (basepath != path) { /* rebase provided pointer so that it starts from object... */ RNA_pointer_create(&ob->id, ptr->type, ptr->data, ptr); } } } /* the path should now have been corrected for use */ return path; }
static int brush_select_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); ToolSettings *toolsettings = CTX_data_tool_settings(C); Paint *paint = NULL; int tool, paint_mode = RNA_enum_get(op->ptr, "paint_mode"); int create_missing = RNA_boolean_get(op->ptr, "create_missing"); int toggle = RNA_boolean_get(op->ptr, "toggle"); const char *tool_name = "Brush"; size_t tool_offset; if (paint_mode == OB_MODE_ACTIVE) { Object *ob = CTX_data_active_object(C); if (ob) { /* select current paint mode */ paint_mode = ob->mode & OB_MODE_ALL_PAINT; } else { return OPERATOR_CANCELLED; } } switch (paint_mode) { case OB_MODE_SCULPT: paint = &toolsettings->sculpt->paint; tool_offset = offsetof(Brush, sculpt_tool); tool = RNA_enum_get(op->ptr, "sculpt_tool"); RNA_enum_name_from_value(brush_sculpt_tool_items, tool, &tool_name); break; case OB_MODE_VERTEX_PAINT: paint = &toolsettings->vpaint->paint; tool_offset = offsetof(Brush, vertexpaint_tool); tool = RNA_enum_get(op->ptr, "vertex_paint_tool"); RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name); break; case OB_MODE_WEIGHT_PAINT: paint = &toolsettings->wpaint->paint; /* vertexpaint_tool is used for weight paint mode */ tool_offset = offsetof(Brush, vertexpaint_tool); tool = RNA_enum_get(op->ptr, "weight_paint_tool"); RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name); break; case OB_MODE_TEXTURE_PAINT: paint = &toolsettings->imapaint.paint; tool_offset = offsetof(Brush, imagepaint_tool); tool = RNA_enum_get(op->ptr, "texture_paint_tool"); RNA_enum_name_from_value(brush_image_tool_items, tool, &tool_name); break; default: /* invalid paint mode */ return OPERATOR_CANCELLED; } return brush_generic_tool_set(bmain, paint, tool, tool_offset, paint_mode, tool_name, create_missing, toggle); }
static int ED_operator_rigidbody_con_active_poll(bContext *C) { if (ED_operator_object_active_editable(C)) { Object *ob = CTX_data_active_object(C); return (ob && ob->rigidbody_constraint); } else return 0; }
/* 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 fluid_bake_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); // XXX TODO redraw, escape, non-blocking, .. if(!fluidsimBake(C, op->reports, ob)) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; }
static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); Object *obact = CTX_data_active_object(C); unsigned int paintcol = vpaint_get_current_col(scene->toolsettings->vpaint); vpaint_fill(obact, paintcol); ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views return OPERATOR_FINISHED; }
static int buttons_shading_context(const bContext *C, int mainb) { Object *ob = CTX_data_active_object(C); if (ELEM(mainb, BCONTEXT_MATERIAL, BCONTEXT_WORLD, BCONTEXT_TEXTURE)) return 1; if (mainb == BCONTEXT_DATA && ob && ELEM(ob->type, OB_LAMP, OB_CAMERA)) return 1; return 0; }
static int fluid_bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { /* only one bake job at a time */ if (WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_SIM_FLUID)) return OPERATOR_CANCELLED; if (!fluidsimBake(C, op->reports, CTX_data_active_object(C), true)) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; }
static int vertex_color_smooth_exec(bContext *C, wmOperator *UNUSED(op)) { Object *obact = CTX_data_active_object(C); if (ED_vpaint_smooth(obact)) { ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views return OPERATOR_FINISHED; } else { return OPERATOR_CANCELLED; } }