/* copy the given F-Modifiers to the buffer, returning whether anything was copied or not * assuming that the buffer has been cleared already with free_fmodifiers_copybuf() * - active: only copy the active modifier */ short ANIM_fmodifiers_copy_to_buf(ListBase *modifiers, short active) { short ok = 1; /* sanity checks */ if (ELEM(NULL, modifiers, modifiers->first)) return 0; /* copy the whole list, or just the active one? */ if (active) { FModifier *fcm = find_active_fmodifier(modifiers); if (fcm) { FModifier *fcmN = copy_fmodifier(fcm); BLI_addtail(&fmodifier_copypaste_buf, fcmN); } else ok = 0; } else copy_fmodifiers(&fmodifier_copypaste_buf, modifiers); /* did we succeed? */ return ok; }
/* Main Driver Management API calls: * Add a new driver for the specified property on the given ID block or replace an existing one * with the driver + driver-curve data from the buffer */ bool ANIM_paste_driver( ReportList *reports, ID *id, const char rna_path[], int array_index, short UNUSED(flag)) { PointerRNA id_ptr, ptr; PropertyRNA *prop; FCurve *fcu; /* validate pointer first - exit if failure */ RNA_id_pointer_create(id, &id_ptr); if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) { BKE_reportf( reports, RPT_ERROR, "Could not paste driver, as RNA path is invalid for the given ID (ID = %s, path = %s)", id->name, rna_path); return 0; } /* if the buffer is empty, cannot paste... */ if (channeldriver_copypaste_buf == NULL) { BKE_report(reports, RPT_ERROR, "Paste driver: no driver to paste"); return 0; } /* create Driver F-Curve, but without data which will be copied across... */ fcu = verify_driver_fcurve(id, rna_path, array_index, -1); if (fcu) { /* copy across the curve data from the buffer curve * NOTE: this step needs care to not miss new settings */ /* keyframes/samples */ fcu->bezt = MEM_dupallocN(channeldriver_copypaste_buf->bezt); fcu->fpt = MEM_dupallocN(channeldriver_copypaste_buf->fpt); fcu->totvert = channeldriver_copypaste_buf->totvert; /* modifiers */ copy_fmodifiers(&fcu->modifiers, &channeldriver_copypaste_buf->modifiers); /* extrapolation mode */ fcu->extend = channeldriver_copypaste_buf->extend; /* the 'juicy' stuff - the driver */ fcu->driver = fcurve_copy_driver(channeldriver_copypaste_buf->driver); } /* done */ return (fcu != NULL); }