static void rna_KeyingSet_paths_remove(KeyingSet *keyingset, ReportList *reports, PointerRNA *ksp_ptr) { KS_Path *ksp = ksp_ptr->data; /* if data is valid, call the API function for this */ if ((keyingset && ksp) == false) { BKE_report(reports, RPT_ERROR, "Keying set path could not be removed"); return; } /* remove the active path from the KeyingSet */ BKE_keyingset_free_path(keyingset, ksp); RNA_POINTER_INVALIDATE(ksp_ptr); /* the active path number will most likely have changed */ /* TODO: we should get more fancy and actually check if it was removed, but this will do for now */ keyingset->active_path = 0; }
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 mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event) { Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BKE_editmesh_from_object(obedit); int ret; if (em->bm->totedgesel == 0) { BKE_report(op->reports, RPT_ERROR, "Selected edges/faces required"); return OPERATOR_CANCELLED; } /* if the properties are set or there is no rv3d, * skip model and exec immediately */ if ((CTX_wm_region_view3d(C) == NULL) || (RNA_struct_property_is_set(op->ptr, "plane_co") && RNA_struct_property_is_set(op->ptr, "plane_no"))) { return mesh_bisect_exec(C, op); } ret = WM_gesture_straightline_invoke(C, op, event); if (ret & OPERATOR_RUNNING_MODAL) { View3D *v3d = CTX_wm_view3d(C); wmGesture *gesture = op->customdata; BisectData *opdata; opdata = MEM_mallocN(sizeof(BisectData), "inset_operator_data"); opdata->mesh_backup = EDBM_redo_state_store(em); opdata->is_first = true; gesture->userdata = opdata; /* misc other vars */ G.moving = G_TRANSFORM_EDIT; opdata->twtype = v3d->twtype; v3d->twtype = 0; /* initialize modal callout */ ED_area_headerprint(CTX_wm_area(C), IFACE_("LMB: Click and drag to draw cut line")); } return ret; }
static int object_hook_reset_exec(bContext *C, wmOperator *op) { PointerRNA ptr= CTX_data_pointer_get_type(C, "modifier", &RNA_HookModifier); int num= RNA_enum_get(op->ptr, "modifier"); Object *ob=NULL; HookModifierData *hmd=NULL; if (ptr.data) { /* if modifier context is available, use that */ ob = ptr.id.data; hmd= ptr.data; } else { /* use the provided property */ ob = CTX_data_edit_object(C); hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num); } if (!ob || !hmd) { BKE_report(op->reports, RPT_ERROR, "Couldn't find hook modifier"); return OPERATOR_CANCELLED; } /* reset functionality */ if(hmd->object) { bPoseChannel *pchan= get_pose_channel(hmd->object->pose, hmd->subtarget); if(hmd->subtarget[0] && pchan) { float imat[4][4], mat[4][4]; /* calculate the world-space matrix for the pose-channel target first, then carry on as usual */ mul_m4_m4m4(mat, pchan->pose_mat, hmd->object->obmat); invert_m4_m4(imat, mat); mul_serie_m4(hmd->parentinv, imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); } else { invert_m4_m4(hmd->object->imat, hmd->object->obmat); mul_serie_m4(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL); } } DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; }
static int action_layer_prev_exec(bContext *C, wmOperator *op) { AnimData *adt = ED_actedit_animdata_from_context(C); NlaTrack *act_track; NlaTrack *nlt; Scene *scene = CTX_data_scene(C); float ctime = BKE_scene_frame_get(scene); /* Sanity Check */ if (adt == NULL) { BKE_report(op->reports, RPT_ERROR, "Internal Error: Could not find Animation Data/NLA Stack to use"); return OPERATOR_CANCELLED; } /* Get active track */ act_track = BKE_nlatrack_find_tweaked(adt); /* If there is no active track, that means we are using the active action... */ if (act_track) { /* Active Track - Start from the one below it */ nlt = act_track->prev; } else { /* Active Action - Use the top-most track */ nlt = adt->nla_tracks.last; } /* Find previous action and hook it up */ for (; nlt; nlt = nlt->prev) { NlaStrip *strip = action_layer_get_nlastrip(&nlt->strips, ctime); if (strip) { action_layer_switch_strip(adt, act_track, adt->actstrip, nlt, strip); break; } } /* Update the action that this editor now uses * NOTE: The calls above have already handled the usercount/animdata side of things */ actedit_change_action(C, adt->action); return OPERATOR_FINISHED; }
static int create_navmesh_exec(bContext *C, wmOperator *op) { Scene* scene= CTX_data_scene(C); LinkNode* obs= NULL; Base* navmeshBase= NULL; CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { if (base->object->type == OB_MESH) { if (base->object->body_type==OB_BODY_TYPE_NAVMESH) { if (!navmeshBase || base == scene->basact) { navmeshBase= base; } } else { BLI_linklist_append(&obs, (void*)base->object); } } } CTX_DATA_END; if (obs) { struct recast_polyMesh *pmesh= NULL; struct recast_polyMeshDetail *dmesh= NULL; int nverts= 0, ntris= 0; int *tris= 0; float *verts= NULL; createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris); BLI_linklist_free(obs, NULL); buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh); createRepresentation(C, pmesh, dmesh, navmeshBase); MEM_freeN(verts); MEM_freeN(tris); return OPERATOR_FINISHED; } else { BKE_report(op->reports, RPT_ERROR, "No mesh objects found"); return OPERATOR_CANCELLED; } }
/* returns 0 on error, 1 on success. executes and finishes a bmesh operator */ bool EDBM_op_finish(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const bool do_report) { const char *errmsg; BMO_op_finish(em->bm, bmop); if (BMO_error_get(em->bm, &errmsg, NULL)) { BMEditMesh *emcopy = em->emcopy; if (do_report) { BKE_report(op->reports, RPT_ERROR, errmsg); } EDBM_mesh_free(em); *em = *emcopy; MEM_freeN(emcopy); em->emcopyusers = 0; em->emcopy = NULL; /* when copying, tessellation isn't to for faster copying, * but means we need to re-tessellate here */ if (em->looptris == NULL) { BKE_editmesh_tessface_calc(em); } return false; } else { em->emcopyusers--; if (em->emcopyusers < 0) { printf("warning: em->emcopyusers was less than zero.\n"); } if (em->emcopyusers <= 0) { BKE_editmesh_free(em->emcopy); MEM_freeN(em->emcopy); em->emcopy = NULL; } return true; } }
static int outliner_action_set_exec(bContext *C, wmOperator *op) { SpaceOops *soops = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; bAction *act; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); /* get action to use */ act = BLI_findlink(&CTX_data_main(C)->action, RNA_enum_get(op->ptr, "action")); if (act == NULL) { BKE_report(op->reports, RPT_ERROR, "No valid action to add"); return OPERATOR_CANCELLED; } else if (act->idroot == 0) { /* hopefully in this case (i.e. library of userless actions), the user knows what they're doing... */ BKE_reportf(op->reports, RPT_WARNING, "Action '%s' does not specify what datablocks it can be used on " "(try setting the 'ID Root Type' setting from the Datablocks Editor " "for this action to avoid future problems)", act->id.name + 2); } /* perform action if valid channel */ if (datalevel == TSE_ANIM_DATA) outliner_do_id_set_operation(soops, datalevel, &soops->tree, (ID *)act, actionset_id_cb); else if (idlevel == ID_AC) outliner_do_id_set_operation(soops, idlevel, &soops->tree, (ID *)act, actionset_id_cb); else return OPERATOR_CANCELLED; /* set notifier that things have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Set action"); /* done */ return OPERATOR_FINISHED; }
static int start_avi(Scene *scene, RenderData *rd, int rectx, int recty, ReportList *reports) { int x, y; char name[256]; AviFormat format; int quality; double framerate; (void)scene; /* unused */ filepath_avi(name, rd); x = rectx; y = recty; quality = rd->im_format.quality; framerate = (double) rd->frs_sec / (double) rd->frs_sec_base; avi = MEM_mallocN(sizeof(AviMovie), "avimovie"); if (rd->im_format.imtype != R_IMF_IMTYPE_AVIJPEG) format = AVI_FORMAT_AVI_RGB; else format = AVI_FORMAT_MJPEG; if (AVI_open_compress(name, avi, 1, format) != AVI_ERROR_NONE) { BKE_report(reports, RPT_ERROR, "Cannot open or start AVI movie file"); MEM_freeN(avi); avi = NULL; return 0; } AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x); AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &y); AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &quality); AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &framerate); avi->interlace = 0; avi->odd_fields = 0; /* avi->interlace = rd->mode & R_FIELDS; */ /* avi->odd_fields = (rd->mode & R_ODDFIELD) ? 1 : 0; */ printf("Created avi: %s\n", name); return 1; }
static void rna_KeyingSet_paths_clear(KeyingSet *keyingset, ReportList *reports) { /* if data is valid, call the API function for this */ if (keyingset) { KS_Path *ksp, *kspn; /* free each path as we go to avoid looping twice */ for (ksp = keyingset->paths.first; ksp; ksp = kspn) { kspn = ksp->next; BKE_keyingset_free_path(keyingset, ksp); } /* reset the active path, since there aren't any left */ keyingset->active_path = 0; } else { BKE_report(reports, RPT_ERROR, "Keying set paths could not be removed"); } }
/* Write a frame to the output file */ static int write_video_frame(RenderData *rd, AVFrame* frame, ReportList *reports) { int outsize = 0; int ret, success= 1; AVCodecContext* c = video_stream->codec; frame->pts = rd->cfra - rd->sfra; if (rd->mode & R_FIELDS) { frame->top_field_first = ((rd->mode & R_ODDFIELD) != 0); } outsize = avcodec_encode_video(c, video_buffer, video_buffersize, frame); if (outsize != 0) { AVPacket packet; av_init_packet(&packet); if (c->coded_frame->pts != AV_NOPTS_VALUE) { packet.pts = av_rescale_q(c->coded_frame->pts, c->time_base, video_stream->time_base); fprintf(stderr, "Video Frame PTS: %d\n", (int)packet.pts); } else { fprintf(stderr, "Video Frame PTS: not set\n"); } if (c->coded_frame->key_frame) packet.flags |= AV_PKT_FLAG_KEY; packet.stream_index = video_stream->index; packet.data = video_buffer; packet.size = outsize; ret = av_interleaved_write_frame(outfile, &packet); } else { ret = 0; } if (ret != 0) { success= 0; BKE_report(reports, RPT_ERROR, "Error writing frame."); } return success; }
static int knifeproject_exec(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); Scene *scene = CTX_data_scene(C); Object *obedit = CTX_data_edit_object(C); BMEditMesh *em = BKE_editmesh_from_object(obedit); const bool cut_through = RNA_boolean_get(op->ptr, "cut_through"); LinkNode *polys = NULL; CTX_DATA_BEGIN (C, Object *, ob, selected_objects) { if (ob != obedit) { polys = knifeproject_poly_from_object(ar, scene, ob, polys); } } CTX_DATA_END; if (polys) { EDBM_mesh_knife(C, polys, true, cut_through); /* select only tagged faces */ BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false); /* not essential, but switch out of vertex mode since the * selected regions wont be nicely isolated after flushing. * note: call after de-select to avoid selection flushing */ EDBM_selectmode_disable(scene, em, SCE_SELECT_VERTEX, SCE_SELECT_EDGE); BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, true, false, BM_ELEM_TAG); BM_mesh_select_mode_flush(em->bm); BLI_linklist_freeN(polys); return OPERATOR_FINISHED; } else { BKE_report(op->reports, RPT_ERROR, "No other selected objects found to use for projection"); return OPERATOR_CANCELLED; } }
int ED_object_modifier_move_up(ReportList *reports, Object *ob, ModifierData *md) { if(md->prev) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); if(mti->type!=eModifierTypeType_OnlyDeform) { ModifierTypeInfo *nmti = modifierType_getInfo(md->prev->type); if(nmti->flags&eModifierTypeFlag_RequiresOriginalData) { BKE_report(reports, RPT_WARNING, "Cannot move above a modifier requiring original data"); return 0; } } BLI_remlink(&ob->modifiers, md); BLI_insertlink(&ob->modifiers, md->prev->prev, md); } return 1; }
static ARegionType *region_type_find(ReportList *reports, int space_type, int region_type) { SpaceType *st; ARegionType *art; st = BKE_spacetype_from_id(space_type); for (art = (st) ? st->regiontypes.first : NULL; art; art = art->next) { if (art->regionid == region_type) break; } /* region type not found? abort */ if (art == NULL) { BKE_report(reports, RPT_ERROR, "Region not found in space type"); return NULL; } return art; }
int ED_object_modifier_move_down(ReportList *reports, Object *ob, ModifierData *md) { if(md->next) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); if(mti->flags&eModifierTypeFlag_RequiresOriginalData) { ModifierTypeInfo *nmti = modifierType_getInfo(md->next->type); if(nmti->type!=eModifierTypeType_OnlyDeform) { BKE_report(reports, RPT_WARNING, "Cannot move beyond a non-deforming modifier"); return 0; } } BLI_remlink(&ob->modifiers, md); BLI_insertlink(&ob->modifiers, md->next, md); } return 1; }
/* add new layer - wrapper around API */ static int gp_layer_add_exec(bContext *C, wmOperator *op) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); /* if there's no existing Grease-Pencil data there, add some */ if (gpd_ptr == NULL) { BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); return OPERATOR_CANCELLED; } if (*gpd_ptr == NULL) *gpd_ptr = gpencil_data_addnew(DATA_("GPencil")); /* add new layer now */ gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), 1); /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); return OPERATOR_FINISHED; }
static Base *rna_Object_local_view_property_helper( bScreen *sc, View3D *v3d, Object *ob, ReportList *reports, Scene **r_scene) { if (v3d->localvd == NULL) { BKE_report(reports, RPT_ERROR, "Viewport not in local view"); return NULL; } wmWindow *win = ED_screen_window_find(sc, G_MAIN->wm.first); ViewLayer *view_layer = WM_window_get_active_view_layer(win); Base *base = BKE_view_layer_base_find(view_layer, ob); if (base == NULL) { BKE_reportf( reports, RPT_WARNING, "Object %s not in view layer %s", ob->id.name + 2, view_layer->name); } if (r_scene) { *r_scene = win->scene; } return base; }
static wmKeyMapItem *rna_KeyMap_item_new_from_item(wmKeyMap *km, ReportList *reports, wmKeyMapItem *kmi_src, bool head) { /* wmWindowManager *wm = CTX_wm_manager(C); */ if ((km->flag & KEYMAP_MODAL) == (kmi_src->idname[0] != '\0')) { BKE_report(reports, RPT_ERROR, "Can not mix modal/non-modal items"); return NULL; } /* create keymap item */ wmKeyMapItem *kmi = WM_keymap_add_item_copy(km, kmi_src); if (head) { BLI_remlink(&km->items, kmi); BLI_addhead(&km->items, kmi); } return kmi; }
int ED_object_gpencil_modifier_copy(ReportList *reports, Object *ob, GpencilModifierData *md) { GpencilModifierData *nmd; const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type); GpencilModifierType type = md->type; if (mti->flags & eGpencilModifierTypeFlag_Single) { if (BKE_gpencil_modifiers_findByType(ob, type)) { BKE_report(reports, RPT_WARNING, "Only one modifier of this type is allowed"); return 0; } } nmd = BKE_gpencil_modifier_new(md->type); BKE_gpencil_modifier_copyData(md, nmd); BLI_insertlinkafter(&ob->greasepencil_modifiers, md, nmd); BKE_gpencil_modifier_unique_name(&ob->greasepencil_modifiers, nmd); return 1; }
/* no libraries for now */ void packAll(Main *bmain, ReportList *reports, bool verbose) { Image *ima; VFont *vfont; bSound *sound; int tot = 0; for (ima = bmain->image.first; ima; ima = ima->id.next) { if (BKE_image_has_packedfile(ima) == false && ima->id.lib == NULL) { if (ima->source == IMA_SRC_FILE) { BKE_image_packfiles(reports, ima, ID_BLEND_PATH(bmain, &ima->id)); tot ++; } else if (BKE_image_is_animated(ima) && verbose) { BKE_reportf(reports, RPT_WARNING, "Image '%s' skipped, movies and image sequences not supported", ima->id.name + 2); } } } for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) { if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == false) { vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name); tot ++; } } for (sound = bmain->sound.first; sound; sound = sound->id.next) { if (sound->packedfile == NULL && sound->id.lib == NULL) { sound->packedfile = newPackedFile(reports, sound->name, bmain->name); tot++; } } if (tot > 0) BKE_reportf(reports, RPT_INFO, "Packed %d files", tot); else if (verbose) BKE_report(reports, RPT_INFO, "No new files have been packed"); }
static int create_orientation_exec(bContext *C, wmOperator *op) { char name[MAX_NAME]; int use = RNA_boolean_get(op->ptr, "use"); int overwrite = RNA_boolean_get(op->ptr, "overwrite"); int use_view = RNA_boolean_get(op->ptr, "use_view"); RNA_string_get(op->ptr, "name", name); if (use && !CTX_wm_view3d(C)) { BKE_report(op->reports, RPT_ERROR, "Create Orientation's 'use' parameter only valid in a 3DView context"); return OPERATOR_CANCELLED; } BIF_createTransformOrientation(C, op->reports, name, use_view, use, overwrite); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C)); WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C)); return OPERATOR_FINISHED; }
/* When no longer needed, duplilist should be freed with Object.free_duplilist */ void rna_Object_create_duplilist(Object *ob, ReportList *reports, Scene *sce) { if (!(ob->transflag & OB_DUPLI)) { BKE_report(reports, RPT_ERROR, "Object does not have duplis"); return; } /* free duplilist if a user forgets to */ if (ob->duplilist) { BKE_reportf(reports, RPT_WARNING, "Object.dupli_list has not been freed"); free_object_duplilist(ob->duplilist); ob->duplilist= NULL; } if(G.rendering) dupli_render_particle_set(sce, ob, 0, 1); ob->duplilist= object_duplilist(sce, ob); if(G.rendering) dupli_render_particle_set(sce, ob, 0, 0); /* ob->duplilist should now be freed with Object.free_duplilist */ }
static int actkeys_sample_exec(bContext *C, wmOperator *op) { bAnimContext ac; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) { BKE_report(op->reports, RPT_ERROR, "Not implemented"); return OPERATOR_PASS_THROUGH; } /* sample keyframes */ sample_action_keys(&ac); /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); return OPERATOR_FINISHED; }
static int actkeys_copy_exec(bContext *C, wmOperator *op) { bAnimContext ac; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* copy keyframes */ if (ac.datatype == ANIMCONT_GPENCIL) { // FIXME... } else { if (copy_action_keys(&ac)) { BKE_report(op->reports, RPT_ERROR, "No keyframes copied to keyframes copy/paste buffer"); return OPERATOR_CANCELLED; } } return OPERATOR_FINISHED; }
/* copied from Mesh_getFromObject and adapted to RNA interface */ static Mesh *rna_Object_to_mesh(Object *object, ReportList *reports, bool preserve_all_data_layers, Depsgraph *depsgraph) { /* TODO(sergey): Make it more re-usable function, de-duplicate with * rna_Main_meshes_new_from_object. */ switch (object->type) { case OB_FONT: case OB_CURVE: case OB_SURF: case OB_MBALL: case OB_MESH: break; default: BKE_report(reports, RPT_ERROR, "Object does not have geometry data"); return NULL; } return BKE_object_to_mesh(depsgraph, object, preserve_all_data_layers); }
/* unlink datablock - wrapper around API */ static int gp_data_unlink_exec(bContext *C, wmOperator *op) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); if (gpd_ptr == NULL) { BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); return OPERATOR_CANCELLED; } else { /* just unlink datablock now, decreasing its user count */ bGPdata *gpd = (*gpd_ptr); id_us_min(&gpd->id); *gpd_ptr = NULL; } /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); return OPERATOR_FINISHED; }
/* add new datablock - wrapper around API */ static int gp_data_add_exec(bContext *C, wmOperator *op) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); if (gpd_ptr == NULL) { BKE_report(op->reports, RPT_ERROR, "Nowhere for Grease Pencil data to go"); return OPERATOR_CANCELLED; } else { /* decrement user count and add new datablock */ bGPdata *gpd = (*gpd_ptr); id_us_min(&gpd->id); *gpd_ptr = gpencil_data_addnew("GPencil"); } /* notifiers */ WM_event_add_notifier(C, NC_SCREEN | ND_GPENCIL | NA_EDITED, NULL); // XXX need a nicer one that will work return OPERATOR_FINISHED; }
/* generic exec for clear-transform operators */ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, void (*clear_func)(Object *), const char default_ksName[]) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); KeyingSet *ks; /* sanity checks */ if (ELEM(NULL, clear_func, default_ksName)) { BKE_report(op->reports, RPT_ERROR, "Programming error: missing clear transform func or Keying Set Name"); return OPERATOR_CANCELLED; } /* get KeyingSet to use */ ks = ANIM_get_keyingset_for_autokeying(scene, default_ksName); /* operate on selected objects only if they aren't in weight-paint mode * (so that object-transform clearing won't be applied at same time as bone-clearing) */ CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { if (!(ob->mode & OB_MODE_WEIGHT_PAINT)) { /* run provided clearing function */ clear_func(ob); ED_autokeyframe_object(C, scene, ob, ks); /* tag for updates */ DAG_id_tag_update(&ob->id, OB_RECALC_OB); } } CTX_DATA_END; /* this is needed so children are also updated */ DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); return OPERATOR_FINISHED; }
/* unlike VIEW3D_OT_view_selected this is for framing a render and not * meant to take into account vertex/bone selection for eg. */ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); /* can be NULL */ Object *camera_ob = v3d ? v3d->camera : scene->camera; float r_co[3]; /* the new location to apply */ float r_scale; /* only for ortho cameras */ if (camera_ob == NULL) { BKE_report(op->reports, RPT_ERROR, "No active camera"); return OPERATOR_CANCELLED; } /* this function does all the important stuff */ if (BKE_camera_view_frame_fit_to_scene(scene, v3d, camera_ob, r_co, &r_scale)) { ObjectTfmProtectedChannels obtfm; float obmat_new[4][4]; if ((camera_ob->type == OB_CAMERA) && (((Camera *)camera_ob->data)->type == CAM_ORTHO)) { ((Camera *)camera_ob->data)->ortho_scale = r_scale; } copy_m4_m4(obmat_new, camera_ob->obmat); copy_v3_v3(obmat_new[3], r_co); /* only touch location */ BKE_object_tfm_protected_backup(camera_ob, &obtfm); BKE_object_apply_mat4(camera_ob, obmat_new, true, true); BKE_object_tfm_protected_restore(camera_ob, &obtfm, OB_LOCK_SCALE | OB_LOCK_ROT4D); /* notifiers */ DAG_id_tag_update(&camera_ob->id, OB_RECALC_OB); WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, camera_ob); return OPERATOR_FINISHED; } else { return OPERATOR_CANCELLED; } }
static int start_avi(void *context_v, Scene *UNUSED(scene), RenderData *rd, int rectx, int recty, ReportList *reports, bool preview, const char *suffix) { int x, y; char name[256]; AviFormat format; int quality; double framerate; AviMovie *avi = context_v; filepath_avi(name, rd, preview, suffix); x = rectx; y = recty; quality = rd->im_format.quality; framerate = (double) rd->frs_sec / (double) rd->frs_sec_base; if (rd->im_format.imtype != R_IMF_IMTYPE_AVIJPEG) format = AVI_FORMAT_AVI_RGB; else format = AVI_FORMAT_MJPEG; if (AVI_open_compress(name, avi, 1, format) != AVI_ERROR_NONE) { BKE_report(reports, RPT_ERROR, "Cannot open or start AVI movie file"); return 0; } AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x); AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &y); AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &quality); AVI_set_compress_option(avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &framerate); avi->interlace = 0; avi->odd_fields = 0; /* avi->interlace = rd->mode & R_FIELDS; */ /* avi->odd_fields = (rd->mode & R_ODDFIELD) ? 1 : 0; */ printf("Created avi: %s\n", name); return 1; }