/* Remove and free the given F-Modifier from the given stack */ int remove_fmodifier (ListBase *modifiers, FModifier *fcm) { FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); /* sanity check */ if (fcm == NULL) return 0; /* free modifier's special data (stored inside fcm->data) */ if (fcm->data) { if (fmi && fmi->free_data) fmi->free_data(fcm); /* free modifier's data (fcm->data) */ MEM_freeN(fcm->data); } /* remove modifier from stack */ if (modifiers) { BLI_freelinkN(modifiers, fcm); return 1; } else { // XXX this case can probably be removed some day, as it shouldn't happen... printf("remove_fmodifier() - no modifier stack given\n"); MEM_freeN(fcm); return 0; } }
static int poselib_remove_exec(bContext *C, wmOperator *op) { Object *ob = get_poselib_object(C); bAction *act = (ob) ? ob->poselib : NULL; TimeMarker *marker; int marker_index; FCurve *fcu; PropertyRNA *prop; /* check if valid poselib */ if (act == NULL) { BKE_report(op->reports, RPT_ERROR, "Object does not have pose lib data"); return OPERATOR_CANCELLED; } prop = RNA_struct_find_property(op->ptr, "pose"); if (RNA_property_is_set(op->ptr, prop)) { marker_index = RNA_property_enum_get(op->ptr, prop); } else { marker_index = act->active_marker - 1; } /* get index (and pointer) of pose to remove */ marker = BLI_findlink(&act->markers, marker_index); if (marker == NULL) { BKE_reportf(op->reports, RPT_ERROR, "Invalid pose specified %d", marker_index); return OPERATOR_CANCELLED; } /* remove relevant keyframes */ for (fcu = act->curves.first; fcu; fcu = fcu->next) { BezTriple *bezt; unsigned int i; if (fcu->bezt) { for (i = 0, bezt = fcu->bezt; i < fcu->totvert; i++, bezt++) { /* check if remove */ if (IS_EQF(bezt->vec[1][0], (float)marker->frame)) { delete_fcurve_key(fcu, i, 1); break; } } } } /* remove poselib from list */ BLI_freelinkN(&act->markers, marker); /* fix active pose number */ act->active_marker = 0; /* 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; }
// XXX find some header to put this in! void free_anim_copybuf (void) { tAnimCopybufItem *aci, *acn; /* free each buffer element */ for (aci= animcopybuf.first; aci; aci= acn) { acn= aci->next; /* free keyframes */ if (aci->bezt) MEM_freeN(aci->bezt); /* free RNA-path */ if (aci->rna_path) MEM_freeN(aci->rna_path); /* free ourself */ BLI_freelinkN(&animcopybuf, aci); } /* restore initial state */ animcopybuf.first= animcopybuf.last= NULL; animcopy_firstframe= 999999999.0f; animcopy_lastframe= -999999999.0f; }
void clip_delete_track(bContext *C, MovieClip *clip, MovieTrackingTrack *track) { MovieTracking *tracking= &clip->tracking; MovieTrackingStabilization *stab= &tracking->stabilization; int has_bundle= 0, update_stab= 0; if(track==tracking->act_track) tracking->act_track= NULL; if(track==stab->rot_track) { stab->rot_track= NULL; update_stab= 1; } /* handle reconstruction display in 3d viewport */ if(track->flag&TRACK_HAS_BUNDLE) has_bundle= 1; BKE_tracking_free_track(track); BLI_freelinkN(&tracking->tracks, track); WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip); if(update_stab) { tracking->stabilization.ok= 0; DAG_id_tag_update(&clip->id, 0); WM_event_add_notifier(C, NC_MOVIECLIP|ND_DISPLAY, clip); } if(has_bundle) WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL); }
/* Evaluate the chain starting from the nominated bone */ static void splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime) { tSplineIK_Tree *tree; /* for each pose-tree, execute it if it is spline, otherwise just free it */ while ((tree = pchan_root->siktree.first) != NULL) { int i; /* walk over each bone in the chain, calculating the effects of spline IK * - the chain is traversed in the opposite order to storage order (i.e. parent to children) * so that dependencies are correct */ for (i = tree->chainlen - 1; i >= 0; i--) { bPoseChannel *pchan = tree->chain[i]; splineik_evaluate_bone(tree, scene, ob, pchan, i, ctime); } /* free the tree info specific to SplineIK trees now */ if (tree->chain) MEM_freeN(tree->chain); if (tree->free_points) MEM_freeN(tree->points); /* free this tree */ BLI_freelinkN(&pchan_root->siktree, tree); } }
static int remove_active_keyingset_exec (bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); KeyingSet *ks; /* verify the Keying Set to use: * - use the active one * - return error if it doesn't exist */ if (scene->active_keyingset == 0) { BKE_report(op->reports, RPT_ERROR, "No active Keying Set to remove"); return OPERATOR_CANCELLED; } else ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1); /* free KeyingSet's data, then remove it from the scene */ BKE_keyingset_free(ks); BLI_freelinkN(&scene->keyingsets, ks); /* the active one should now be the previously second-to-last one */ scene->active_keyingset--; /* send notifiers */ WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL); return OPERATOR_FINISHED; }
static void undo_stack_push_end(UndoStack *stack) { UndoElem *uel; uintptr_t totmem, maxmem; if(U.undomemory != 0) { /* limit to maximum memory (afterwards, we can't know in advance) */ totmem= 0; maxmem= ((uintptr_t)U.undomemory)*1024*1024; uel= stack->elems.last; while(uel) { totmem+= uel->undosize; if(totmem>maxmem) break; uel= uel->prev; } if(uel) { while(stack->elems.first!=uel) { UndoElem *first= stack->elems.first; undo_elem_free(stack, first); BLI_freelinkN(&stack->elems, first); } } } }
/* Remove the active bone-group */ void BKE_pose_remove_group(Object *ob) { bPose *pose = (ob) ? ob->pose : NULL; bActionGroup *grp = NULL; bPoseChannel *pchan; /* sanity checks */ if (ELEM(NULL, ob, pose)) return; if (pose->active_group <= 0) return; /* get group to remove */ grp = BLI_findlink(&pose->agroups, pose->active_group - 1); if (grp) { /* adjust group references (the trouble of using indices!): * - firstly, make sure nothing references it * - also, make sure that those after this item get corrected */ for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->agrp_index == pose->active_group) pchan->agrp_index = 0; else if (pchan->agrp_index > pose->active_group) pchan->agrp_index--; } /* now, remove it from the pose */ BLI_freelinkN(&pose->agroups, grp); pose->active_group--; if (pose->active_group < 0 || pose->agroups.first == NULL) { pose->active_group = 0; } } }
static int remove_active_ks_path_exec (bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); KeyingSet *ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1); /* if there is a KeyingSet, find the nominated path to remove */ if (ks) { KS_Path *ksp= BLI_findlink(&ks->paths, ks->active_path-1); if (ksp) { /* NOTE: sync this code with BKE_keyingset_free() */ { /* free RNA-path info */ MEM_freeN(ksp->rna_path); /* free path itself */ BLI_freelinkN(&ks->paths, ksp); } /* the active path should now be the previously second-to-last active one */ ks->active_path--; } else { BKE_report(op->reports, RPT_ERROR, "No active Keying Set Path to remove"); return OPERATOR_CANCELLED; } } else { BKE_report(op->reports, RPT_ERROR, "No active Keying Set to remove a path from"); return OPERATOR_CANCELLED; } return OPERATOR_FINISHED; }
/* This function frees any MEM_calloc'ed copy/paste buffer data */ void ANIM_fcurves_copybuf_free(void) { tAnimCopybufItem *aci, *acn; /* free each buffer element */ for (aci = animcopybuf.first; aci; aci = acn) { acn = aci->next; /* free keyframes */ if (aci->bezt) MEM_freeN(aci->bezt); /* free RNA-path */ if (aci->rna_path) MEM_freeN(aci->rna_path); /* free ourself */ BLI_freelinkN(&animcopybuf, aci); } /* restore initial state */ BLI_listbase_clear(&animcopybuf); animcopy_firstframe = 999999999.0f; animcopy_lastframe = -999999999.0f; }
void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced) { BArc *arc, *next_arc; for (arc = graph->arcs.first; arc; arc = next_arc) { next_arc = arc->next; if (arc->head == node_replaced) { arc->head = node_src; node_replaced->degree--; node_src->degree++; } if (arc->tail == node_replaced) { arc->tail = node_src; node_replaced->degree--; node_src->degree++; } if (arc->head == arc->tail) { node_src->degree -= 2; graph->free_arc(arc); BLI_freelinkN(&graph->arcs, arc); } } if (node_replaced->degree == 0) { BLI_removeNode(graph, node_replaced); } }
/* Remove the given KeyingSetInfo from the list of type infos, and also remove the builtin set if appropriate */ void ANIM_keyingset_info_unregister (Main *bmain, KeyingSetInfo *ksi) { KeyingSet *ks, *ksn; /* find relevant builtin KeyingSets which use this, and remove them */ // TODO: this isn't done now, since unregister is really only used atm when we // reload the scripts, which kindof defeats the purpose of "builtin"? for (ks= builtin_keyingsets.first; ks; ks= ksn) { ksn = ks->next; /* remove if matching typeinfo name */ if (strcmp(ks->typeinfo, ksi->idname) == 0) { Scene *scene; BKE_keyingset_free(ks); BLI_remlink(&builtin_keyingsets, ks); for(scene= bmain->scene.first; scene; scene= scene->id.next) BLI_remlink_safe(&scene->keyingsets, ks); MEM_freeN(ks); } } /* free the type info */ BLI_freelinkN(&keyingset_type_infos, ksi); }
/* Remove the given bone-group (expects 'virtual' index (+1 one, used by active_group etc.)) * index might be invalid ( < 1), in which case it will be find from grp. */ void BKE_pose_remove_group(bPose *pose, bActionGroup *grp, const int index) { bPoseChannel *pchan; int idx = index; if (idx < 1) { idx = BLI_findindex(&pose->agroups, grp) + 1; } BLI_assert(idx > 0); /* adjust group references (the trouble of using indices!): * - firstly, make sure nothing references it * - also, make sure that those after this item get corrected */ for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->agrp_index == idx) pchan->agrp_index = 0; else if (pchan->agrp_index > idx) pchan->agrp_index--; } /* now, remove it from the pose */ BLI_freelinkN(&pose->agroups, grp); if (pose->active_group >= idx) { pose->active_group--; if (pose->active_group < 0 || BLI_listbase_is_empty(&pose->agroups)) { pose->active_group = 0; } } }
static void task_scheduler_clear(TaskScheduler *scheduler, TaskPool *pool) { Task *task, *nexttask; size_t done = 0; BLI_mutex_lock(&scheduler->queue_mutex); /* free all tasks from this pool from the queue */ for (task = scheduler->queue.first; task; task = nexttask) { nexttask = task->next; if (task->pool == pool) { if (task->free_taskdata) MEM_freeN(task->taskdata); BLI_freelinkN(&scheduler->queue, task); done++; } } BLI_mutex_unlock(&scheduler->queue_mutex); /* notify done */ task_pool_num_decrease(pool, done); }
void BLI_removeArc(BGraph *graph, BArc *arc) { if (graph->free_arc) { graph->free_arc(arc); } BLI_freelinkN(&graph->arcs, arc); }
static int remove_keyingset_button_exec (bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); KeyingSet *ks = NULL; PropertyRNA *prop= NULL; PointerRNA ptr; char *path = NULL; short success= 0; int index=0; /* verify the Keying Set to use: * - use the active one for now (more control over this can be added later) * - return error if it doesn't exist */ if (scene->active_keyingset == 0) { BKE_report(op->reports, RPT_ERROR, "No active Keying Set to remove property from"); return OPERATOR_CANCELLED; } else ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1); /* try to add to keyingset using property retrieved from UI */ memset(&ptr, 0, sizeof(PointerRNA)); uiAnimContextProperty(C, &ptr, &prop, &index); if (ptr.data && prop) { path= RNA_path_from_ID_to_property(&ptr, prop); if (path) { KS_Path *ksp; /* try to find a path matching this description */ ksp= BKE_keyingset_find_destination(ks, ptr.id.data, ks->name, path, index, KSP_GROUP_KSNAME); if (ksp) { /* just free it... */ MEM_freeN(ksp->rna_path); BLI_freelinkN(&ks->paths, ksp); success= 1; } /* free temp path used */ MEM_freeN(path); } } if (success) { /* send updates */ ED_anim_dag_flush_update(C); /* for now, only send ND_KEYS for KeyingSets */ WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL); } return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED; }
static void free_iconfile_list(struct ListBase *list) { IconFile *ifile = NULL, *next_ifile = NULL; for (ifile = list->first; ifile; ifile = next_ifile) { next_ifile = ifile->next; BLI_freelinkN(list, ifile); } }
static wmKeyMap *wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap) { wmKeyMap *km; int expanded = 0; /* remove previous keymap in list, we will replace it */ km = WM_keymap_list_find(lb, defaultmap->idname, defaultmap->spaceid, defaultmap->regionid); if(km) { expanded = (km->flag & (KEYMAP_EXPANDED|KEYMAP_CHILDREN_EXPANDED)); WM_keymap_free(km); BLI_freelinkN(lb, km); } /* copy new keymap from an existing one */ if(usermap && !(usermap->flag & KEYMAP_DIFF)) { /* for compatibiltiy with old user preferences with non-diff keymaps we override the original entirely */ wmKeyMapItem *kmi, *orig_kmi; km = wm_keymap_copy(usermap); /* try to find corresponding id's for items */ for(kmi=km->items.first; kmi; kmi=kmi->next) { orig_kmi = wm_keymap_find_item_equals(defaultmap, kmi); if(!orig_kmi) orig_kmi = wm_keymap_find_item_equals_result(defaultmap, kmi); if(orig_kmi) kmi->id = orig_kmi->id; else kmi->id = -(km->kmi_id++); } km->flag |= KEYMAP_UPDATE; /* update again to create diff */ } else km = wm_keymap_copy(defaultmap); /* add addon keymap items */ if(addonmap) wm_keymap_addon_add(km, addonmap); /* tag as being user edited */ if(usermap) km->flag |= KEYMAP_USER_MODIFIED; km->flag |= KEYMAP_USER|expanded; /* apply user changes of diff keymap */ if(usermap && (usermap->flag & KEYMAP_DIFF)) wm_keymap_patch(km, usermap); /* add to list */ BLI_addtail(lb, km); return km; }
/* delete the active gp-layer */ void gpencil_layer_delete(bGPdata *gpd, bGPDlayer *gpl) { /* error checking */ if (ELEM(NULL, gpd, gpl)) return; /* free layer */ free_gpencil_frames(gpl); BLI_freelinkN(&gpd->layers, gpl); }
static void remove_tagged_functions(void) { for (TimedFunction *timed_func = GlobalTimer.funcs.first; timed_func;) { TimedFunction *next = timed_func->next; if (timed_func->tag_removal) { clear_user_data(timed_func); BLI_freelinkN(&GlobalTimer.funcs, timed_func); } timed_func = next; } }
static void write_history(void) { struct RecentFile *recent, *next_recent; char name[FILE_MAX]; const char *user_config_dir; FILE *fp; int i; /* no write history for recovered startup files */ if (G.main->name[0] == 0) return; /* will be NULL in background mode */ user_config_dir = BLI_get_folder_create(BLENDER_USER_CONFIG, NULL); if (!user_config_dir) return; BLI_make_file_string("/", name, user_config_dir, BLENDER_HISTORY_FILE); recent = G.recent_files.first; /* refresh recent-files.txt of recent opened files, when current file was changed */ if (!(recent) || (BLI_path_cmp(recent->filepath, G.main->name) != 0)) { fp = BLI_fopen(name, "w"); if (fp) { /* add current file to the beginning of list */ recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile"); recent->filepath = BLI_strdup(G.main->name); BLI_addhead(&(G.recent_files), recent); /* write current file to recent-files.txt */ fprintf(fp, "%s\n", recent->filepath); recent = recent->next; i = 1; /* write rest of recent opened files to recent-files.txt */ while ((i < U.recent_files) && (recent)) { /* this prevents to have duplicities in list */ if (BLI_path_cmp(recent->filepath, G.main->name) != 0) { fprintf(fp, "%s\n", recent->filepath); recent = recent->next; } else { next_recent = recent->next; MEM_freeN(recent->filepath); BLI_freelinkN(&(G.recent_files), recent); recent = next_recent; } i++; } fclose(fp); } /* also update most recent files on System */ GHOST_addToSystemRecentFiles(G.main->name); } }
/* delete the given frame from a layer */ void gpencil_layer_delframe(bGPDlayer *gpl, bGPDframe *gpf) { /* error checking */ if (ELEM(NULL, gpl, gpf)) return; /* free the frame and its data */ free_gpencil_strokes(gpf); BLI_freelinkN(&gpl->frames, gpf); gpl->actframe = NULL; }
void WM_keyconfig_free(wmKeyConfig *keyconf) { wmKeyMap *km; while((km= keyconf->keymaps.first)) { WM_keymap_free(km); BLI_freelinkN(&keyconf->keymaps, km); } MEM_freeN(keyconf); }
static void rna_RenderEngine_unregister(Main *UNUSED(bmain), StructRNA *type) { RenderEngineType *et= RNA_struct_blender_type_get(type); if(!et) return; RNA_struct_free_extension(type, &et->ext); BLI_freelinkN(&R_engines, et); RNA_struct_free(&BLENDER_RNA, type); }
static void undo_stack_push_begin(UndoStack *stack, const char *name, UndoRestoreCb restore, UndoFreeCb free) { UndoElem *uel; int nr; /* Undo push is split up in begin and end, the reason is that as painting * happens more tiles/nodes are added to the list, and at the very end we * know how much memory the undo used to remove old undo elements */ /* remove all undos after (also when stack->current==NULL) */ while(stack->elems.last != stack->current) { uel= stack->elems.last; undo_elem_free(stack, uel); BLI_freelinkN(&stack->elems, uel); } /* make new */ stack->current= uel= MEM_callocN(sizeof(UndoElem), "undo file"); uel->restore= restore; uel->free= free; BLI_addtail(&stack->elems, uel); /* name can be a dynamic string */ strncpy(uel->name, name, MAXUNDONAME-1); /* limit amount to the maximum amount*/ nr= 0; uel= stack->elems.last; while(uel) { nr++; if(nr==U.undosteps) break; uel= uel->prev; } if(uel) { while(stack->elems.first!=uel) { UndoElem *first= stack->elems.first; undo_elem_free(stack, first); BLI_freelinkN(&stack->elems, first); } } }
void bone_free(bArmature *arm, EditBone *bone) { if (arm->act_edbone == bone) arm->act_edbone = NULL; if (bone->prop) { IDP_FreeProperty(bone->prop); MEM_freeN(bone->prop); } BLI_freelinkN(arm->edbo, bone); }
void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi) { if(BLI_findindex(&keymap->items, kmi) != -1) { if(kmi->ptr) { WM_operator_properties_free(kmi->ptr); MEM_freeN(kmi->ptr); } BLI_freelinkN(&keymap->items, kmi); WM_keyconfig_update_tag(keymap, kmi); } }
static void rna_GPencil_stroke_remove(bGPDframe *frame, ReportList *reports, PointerRNA *stroke_ptr) { bGPDstroke *stroke = stroke_ptr->data; if (BLI_findindex(&frame->strokes, stroke) == -1) { BKE_report(reports, RPT_ERROR, "Stroke not found in grease pencil frame"); return; } BLI_freelinkN(&frame->strokes, stroke); RNA_POINTER_INVALIDATE(stroke_ptr); WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL); }
/* only this runs inside thread */ static void preview_startjob(void *data, short *stop, short *do_update, float *progress) { PreviewJob *pj = data; PreviewJobAudio *previewjb; BLI_mutex_lock(pj->mutex); previewjb = pj->previews.first; BLI_mutex_unlock(pj->mutex); while (previewjb) { PreviewJobAudio *preview_next; bSound *sound = previewjb->sound; BKE_sound_read_waveform(sound, stop); if (*stop || G.is_break) { BLI_mutex_lock(pj->mutex); previewjb = previewjb->next; BLI_mutex_unlock(pj->mutex); while (previewjb) { sound = previewjb->sound; /* make sure we cleanup the loading flag! */ BLI_spin_lock(sound->spinlock); sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING; BLI_spin_unlock(sound->spinlock); BLI_mutex_lock(pj->mutex); previewjb = previewjb->next; BLI_mutex_unlock(pj->mutex); } BLI_mutex_lock(pj->mutex); BLI_freelistN(&pj->previews); pj->total = 0; pj->processed = 0; BLI_mutex_unlock(pj->mutex); break; } BLI_mutex_lock(pj->mutex); preview_next = previewjb->next; BLI_freelinkN(&pj->previews, previewjb); previewjb = preview_next; pj->processed++; *progress = (pj->total > 0) ? (float)pj->processed / (float)pj->total : 1.0f; *do_update = true; BLI_mutex_unlock(pj->mutex); } }
/* Helper function for armature separating - remove certain bones from the given armature * sel: remove selected bones from the armature, otherwise the unselected bones are removed * (ob is not in editmode) */ static void separate_armature_bones(Object *ob, short sel) { bArmature *arm = (bArmature *)ob->data; bPoseChannel *pchan, *pchann; EditBone *curbone; /* make local set of editbones to manipulate here */ ED_armature_to_edit(ob); /* go through pose-channels, checking if a bone should be removed */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchann) { pchann = pchan->next; curbone = editbone_name_exists(arm->edbo, pchan->name); /* check if bone needs to be removed */ if ( (sel && (curbone->flag & BONE_SELECTED)) || (!sel && !(curbone->flag & BONE_SELECTED)) ) { EditBone *ebo; bPoseChannel *pchn; /* clear the bone->parent var of any bone that had this as its parent */ for (ebo = arm->edbo->first; ebo; ebo = ebo->next) { if (ebo->parent == curbone) { ebo->parent = NULL; ebo->temp = NULL; /* this is needed to prevent random crashes with in ED_armature_from_edit */ ebo->flag &= ~BONE_CONNECTED; } } /* clear the pchan->parent var of any pchan that had this as its parent */ for (pchn = ob->pose->chanbase.first; pchn; pchn = pchn->next) { if (pchn->parent == pchan) pchn->parent = NULL; } /* free any of the extra-data this pchan might have */ BKE_pose_channel_free(pchan); BKE_pose_channels_hash_free(ob->pose); /* get rid of unneeded bone */ bone_free(arm, curbone); BLI_freelinkN(&ob->pose->chanbase, pchan); } } /* exit editmode (recalculates pchans too) */ ED_armature_from_edit(ob); ED_armature_edit_free(ob); }