From f1c81a199a7e17789d8b1f9404730420eb492021 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 9 Jan 2014 11:08:17 +0100 Subject: Cleanup: Remove tabs in empty lines, use bool when possible instead of int, and mark const values/parameters as such. --- source/blender/editors/gpencil/gpencil_edit.c | 367 +++++++++++++------------- 1 file changed, 184 insertions(+), 183 deletions(-) (limited to 'source/blender/editors/gpencil') diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 715b771b4a8..138eb81df16 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -27,8 +27,6 @@ * \ingroup edgpencil */ - - #include #include #include @@ -37,7 +35,6 @@ #include "MEM_guardedalloc.h" - #include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_rand.h" @@ -85,6 +82,7 @@ #include "gpencil_intern.h" + /* ************************************************ */ /* Context Wrangling... */ @@ -94,7 +92,7 @@ bGPdata **gpencil_data_get_pointers(const bContext *C, PointerRNA *ptr) ID *screen_id = (ID *)CTX_wm_screen(C); Scene *scene = CTX_data_scene(C); ScrArea *sa = CTX_wm_area(C); - + /* if there's an active area, check if the particular editor may * have defined any special Grease Pencil context for editing... */ @@ -103,7 +101,7 @@ bGPdata **gpencil_data_get_pointers(const bContext *C, PointerRNA *ptr) case SPACE_VIEW3D: /* 3D-View */ { Object *ob = CTX_data_active_object(C); - + /* TODO: we can include other data-types such as bones later if need be... */ /* just in case no active/selected object */ @@ -117,7 +115,7 @@ bGPdata **gpencil_data_get_pointers(const bContext *C, PointerRNA *ptr) case SPACE_NODE: /* Nodes Editor */ { SpaceNode *snode = (SpaceNode *)CTX_wm_space_data(C); - + /* return the GP data for the active node block/node */ if (snode && snode->nodetree) { /* for now, as long as there's an active node tree, default to using that in the Nodes Editor */ @@ -131,7 +129,7 @@ bGPdata **gpencil_data_get_pointers(const bContext *C, PointerRNA *ptr) case SPACE_SEQ: /* Sequencer */ { SpaceSeq *sseq = (SpaceSeq *)CTX_wm_space_data(C); - + /* for now, Grease Pencil data is associated with the space (actually preview region only) */ /* XXX our convention for everything else is to link to data though... */ if (ptr) RNA_pointer_create(screen_id, &RNA_SpaceSequenceEditor, sseq, ptr); @@ -140,7 +138,7 @@ bGPdata **gpencil_data_get_pointers(const bContext *C, PointerRNA *ptr) case SPACE_IMAGE: /* Image/UV Editor */ { SpaceImage *sima = (SpaceImage *)CTX_wm_space_data(C); - + /* for now, Grease Pencil data is associated with the space... */ /* XXX our convention for everything else is to link to data though... */ if (ptr) RNA_pointer_create(screen_id, &RNA_SpaceImageEditor, sima, ptr); @@ -150,23 +148,23 @@ bGPdata **gpencil_data_get_pointers(const bContext *C, PointerRNA *ptr) { SpaceClip *sc = (SpaceClip *)CTX_wm_space_data(C); MovieClip *clip = ED_space_clip_get_clip(sc); - + if (clip) { if (sc->gpencil_src == SC_GPENCIL_SRC_TRACK) { MovieTrackingTrack *track = BKE_tracking_track_get_active(&clip->tracking); - + if (!track) return NULL; - + if (ptr) RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, ptr); - + return &track->gpd; } else { if (ptr) RNA_id_pointer_create(&clip->id, ptr); - + return &clip->gpd; } } @@ -176,7 +174,7 @@ bGPdata **gpencil_data_get_pointers(const bContext *C, PointerRNA *ptr) return NULL; } } - + /* just fall back on the scene's GP data */ if (ptr) RNA_id_pointer_create((ID *)scene, ptr); return (scene) ? &scene->gpd : NULL; @@ -219,7 +217,7 @@ static int gp_add_poll(bContext *C) 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; @@ -227,14 +225,14 @@ static int gp_data_add_exec(bContext *C, wmOperator *op) else { /* decrement user count and add new datablock */ bGPdata *gpd = (*gpd_ptr); - + id_us_min(&gpd->id); *gpd_ptr = gpencil_data_addnew(DATA_("GPencil")); } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -245,7 +243,7 @@ void GPENCIL_OT_data_add(wmOperatorType *ot) ot->idname = "GPENCIL_OT_data_add"; ot->description = "Add new Grease Pencil datablock"; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_data_add_exec; ot->poll = gp_add_poll; @@ -257,7 +255,7 @@ void GPENCIL_OT_data_add(wmOperatorType *ot) static int gp_data_unlink_poll(bContext *C) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); - + /* if we have access to some active data, make sure there's a datablock before enabling this */ return (gpd_ptr && *gpd_ptr); } @@ -267,7 +265,7 @@ static int gp_data_unlink_poll(bContext *C) 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; @@ -275,14 +273,14 @@ static int gp_data_unlink_exec(bContext *C, wmOperator *op) 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; } @@ -293,7 +291,7 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot) ot->idname = "GPENCIL_OT_data_unlink"; ot->description = "Unlink active Grease Pencil datablock"; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_data_unlink_exec; ot->poll = gp_data_unlink_poll; @@ -305,7 +303,7 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot) 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"); @@ -313,13 +311,13 @@ static int gp_layer_add_exec(bContext *C, wmOperator *op) } 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; } @@ -330,7 +328,7 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot) ot->idname = "GPENCIL_OT_layer_add"; ot->description = "Add new Grease Pencil layer for the active Grease Pencil datablock"; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_layer_add_exec; ot->poll = gp_add_poll; @@ -342,7 +340,7 @@ static int gp_actframe_delete_poll(bContext *C) { bGPdata *gpd = gpencil_data_get_active(C); bGPDlayer *gpl = gpencil_layer_getactive(gpd); - + /* only if there's an active layer with an active frame */ return (gpl && gpl->actframe); } @@ -354,7 +352,7 @@ static int gp_actframe_delete_exec(bContext *C, wmOperator *op) bGPdata *gpd = gpencil_data_get_active(C); bGPDlayer *gpl = gpencil_layer_getactive(gpd); bGPDframe *gpf = gpencil_layer_getframe(gpl, CFRA, 0); - + /* if there's no existing Grease-Pencil data there, add some */ if (gpd == NULL) { BKE_report(op->reports, RPT_ERROR, "No grease pencil data"); @@ -364,13 +362,13 @@ static int gp_actframe_delete_exec(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_ERROR, "No active frame to delete"); return OPERATOR_CANCELLED; } - + /* delete it... */ gpencil_layer_delframe(gpl, gpf); - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -381,7 +379,7 @@ void GPENCIL_OT_active_frame_delete(wmOperatorType *ot) ot->idname = "GPENCIL_OT_active_frame_delete"; ot->description = "Delete the active frame for the active Grease Pencil datablock"; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_actframe_delete_exec; ot->poll = gp_actframe_delete_poll; @@ -447,7 +445,7 @@ static void gp_strokepoint_convertcoords(bContext *C, bGPDstroke *gps, bGPDspoin Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); - + if (gps->flag & GP_STROKE_3DSPACE) { /* directly use 3d-coordinates */ copy_v3_v3(p3d, &pt->x); @@ -455,7 +453,7 @@ static void gp_strokepoint_convertcoords(bContext *C, bGPDstroke *gps, bGPDspoin else { const float *fp = ED_view3d_cursor3d_get(scene, v3d); float mvalf[2]; - + /* get screen coordinate */ if (gps->flag & GP_STROKE_2DSPACE) { int mvali[2]; @@ -473,7 +471,7 @@ static void gp_strokepoint_convertcoords(bContext *C, bGPDstroke *gps, bGPDspoin mvalf[1] = (float)pt->y / 100.0f * ar->winy; } } - + /* convert screen coordinate to 3d coordinates * - method taken from editview.c - mouse_cursor() */ @@ -489,7 +487,7 @@ typedef struct tGpTimingData { int mode; int frame_range; /* Number of frames evaluated for path animation */ int start_frame, end_frame; - int realtime; /* A bool, actually, will overwrite end_frame in case of Original or CustomGap timing... */ + bool realtime; /* Will overwrite end_frame in case of Original or CustomGap timing... */ float gap_duration, gap_randomness; /* To be used with CustomGap mode*/ int seed; @@ -507,12 +505,12 @@ typedef struct tGpTimingData { } tGpTimingData; /* init point buffers for timing data */ -static void _gp_timing_data_set_nbr(tGpTimingData *gtd, int nbr) +static void _gp_timing_data_set_nbr(tGpTimingData *gtd, const int nbr) { float *tmp; BLI_assert(nbr > gtd->num_points); - + /* distances */ tmp = gtd->dists; gtd->dists = MEM_callocN(sizeof(float) * nbr, __func__); @@ -520,7 +518,7 @@ static void _gp_timing_data_set_nbr(tGpTimingData *gtd, int nbr) memcpy(gtd->dists, tmp, sizeof(float) * gtd->num_points); MEM_freeN(tmp); } - + /* times */ tmp = gtd->times; gtd->times = MEM_callocN(sizeof(float) * nbr, __func__); @@ -533,7 +531,8 @@ static void _gp_timing_data_set_nbr(tGpTimingData *gtd, int nbr) } /* add stroke point to timing buffers */ -static void gp_timing_data_add_point(tGpTimingData *gtd, double stroke_inittime, float time, float delta_dist) +static void gp_timing_data_add_point(tGpTimingData *gtd, const double stroke_inittime, const float time, + const float delta_dist) { if (time < 0.0f) { /* This is a gap, negative value! */ @@ -546,10 +545,10 @@ static void gp_timing_data_add_point(tGpTimingData *gtd, double stroke_inittime, gtd->times[gtd->cur_point] = (((float)(stroke_inittime - gtd->inittime)) + time); gtd->tot_time = (gtd->times[gtd->cur_point]); } - + gtd->tot_dist += delta_dist; gtd->dists[gtd->cur_point] = gtd->tot_dist; - + gtd->cur_point++; } @@ -559,11 +558,12 @@ static void gp_timing_data_add_point(tGpTimingData *gtd, double stroke_inittime, #define MIN_TIME_DELTA 0.02f /* Loop over next points to find the end of the stroke, and compute */ -static int gp_find_end_of_stroke_idx(tGpTimingData *gtd, RNG *rng, int idx, int nbr_gaps, int *nbr_done_gaps, - float tot_gaps_time, float delta_time, float *next_delta_time) +static int gp_find_end_of_stroke_idx(tGpTimingData *gtd, RNG *rng, const int idx, const int nbr_gaps, + int *nbr_done_gaps, const float tot_gaps_time, const float delta_time, + float *next_delta_time) { int j; - + for (j = idx + 1; j < gtd->num_points; j++) { if (gtd->times[j] < 0) { gtd->times[j] = -gtd->times[j]; @@ -582,16 +582,16 @@ static int gp_find_end_of_stroke_idx(tGpTimingData *gtd, RNG *rng, int idx, int } else { float delta, min, max; - + /* This code ensures that if the first gaps have been shorter than average gap_duration, * next gaps will tend to be longer (i.e. try to recover the lateness), and vice-versa! */ delta = delta_time - (gtd->gap_duration * (*nbr_done_gaps)); - + /* Clamp min between [-gap_randomness, 0.0], with lower delta giving higher min */ min = -gtd->gap_randomness - delta; CLAMP(min, -gtd->gap_randomness, 0.0f); - + /* Clamp max between [0.0, gap_randomness], with lower delta giving higher max */ max = gtd->gap_randomness - delta; CLAMP(max, 0.0f, gtd->gap_randomness); @@ -639,11 +639,11 @@ static void gp_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd, RNG *rn } static void gp_stroke_path_animation_add_keyframes(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, - Curve *cu, tGpTimingData *gtd, RNG *rng, float time_range, - int nbr_gaps, float tot_gaps_time) + Curve *cu, tGpTimingData *gtd, RNG *rng, const float time_range, + const int nbr_gaps, const float tot_gaps_time) { /* Use actual recorded timing! */ - float time_start = (float)gtd->start_frame; + const float time_start = (float)gtd->start_frame; float last_valid_time = 0.0f; int end_stroke_idx = -1, start_stroke_idx = 0; @@ -671,11 +671,11 @@ static void gp_stroke_path_animation_add_keyframes(ReportList *reports, PointerR /* This one should *never* be negative! */ end_stroke_time = time_start + ((gtd->times[end_stroke_idx] + delta_time) / gtd->tot_time * time_range); } - + /* Simple proportional stuff... */ cu->ctime = gtd->dists[i] / gtd->tot_dist * cu->pathlen; cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range); - + /* And now, the checks about timing... */ if (i == start_stroke_idx) { /* If first point of a stroke, be sure it's enough ahead of last valid keyframe, and @@ -726,43 +726,43 @@ static void gp_stroke_path_animation(bContext *C, ReportList *reports, Curve *cu PointerRNA ptr; PropertyRNA *prop = NULL; int nbr_gaps = 0, i; - + if (gtd->mode == GP_STROKECONVERT_TIMING_NONE) return; - + /* gap_duration and gap_randomness are in frames, but we need seconds!!! */ gtd->gap_duration = FRA2TIME(gtd->gap_duration); gtd->gap_randomness = FRA2TIME(gtd->gap_randomness); - + /* Enable path! */ cu->flag |= CU_PATH; cu->pathlen = gtd->frame_range; - + /* Get RNA pointer to read/write path time values */ RNA_id_pointer_create((ID *)cu, &ptr); prop = RNA_struct_find_property(&ptr, "eval_time"); - + /* Ensure we have an F-Curve to add keyframes to */ act = verify_adt_action((ID *)cu, TRUE); fcu = verify_fcurve(act, NULL, &ptr, "eval_time", 0, TRUE); - + if (G.debug & G_DEBUG) { printf("%s: tot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); for (i = 0; i < gtd->num_points; i++) { printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]); } } - + if (gtd->mode == GP_STROKECONVERT_TIMING_LINEAR) { float cfra; - + /* Linear extrapolation! */ fcu->extend = FCURVE_EXTRAPOLATE_LINEAR; - + cu->ctime = 0.0f; cfra = (float)gtd->start_frame; insert_keyframe_direct(reports, ptr, prop, fcu, cfra, INSERTKEY_FAST); - + cu->ctime = cu->pathlen; if (gtd->realtime) { cfra += (float)TIME2FRA(gtd->tot_time); /* Seconds to frames */ @@ -776,36 +776,36 @@ static void gp_stroke_path_animation(bContext *C, ReportList *reports, Curve *cu /* Use actual recorded timing! */ RNG *rng = BLI_rng_new(0); float time_range; - + /* CustomGaps specific */ float tot_gaps_time = 0.0f; - + /* Pre-process gaps, in case we don't want to keep their original timing */ if (gtd->mode == GP_STROKECONVERT_TIMING_CUSTOMGAP) { gp_stroke_path_animation_preprocess_gaps(gtd, rng, &nbr_gaps, &tot_gaps_time); } - + if (gtd->realtime) { time_range = (float)TIME2FRA(gtd->tot_time); /* Seconds to frames */ } else { time_range = (float)(gtd->end_frame - gtd->start_frame); } - + if (G.debug & G_DEBUG) { printf("GP Stroke Path Conversion: Starting keying!\n"); } - + gp_stroke_path_animation_add_keyframes(reports, ptr, prop, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time); BLI_rng_free(rng); } - + /* As we used INSERTKEY_FAST mode, we need to recompute all curve's handles now */ calchandles_fcurve(fcu); - + if (G.debug & G_DEBUG) { printf("%s: \ntot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time); for (i = 0; i < gtd->num_points; i++) { @@ -813,33 +813,33 @@ static void gp_stroke_path_animation(bContext *C, ReportList *reports, Curve *cu } printf("\n\n"); } - + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); - + /* send updates */ DAG_id_tag_update(&cu->id, 0); } #undef MIN_TIME_DELTA -#define GAP_DFAC 0.05f +#define GAP_DFAC 0.01f #define WIDTH_CORR_FAC 0.1f #define BEZT_HANDLE_FAC 0.3f /* convert stroke to 3d path */ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curve *cu, rctf *subrect, Nurb **curnu, - float minmax_weights[2], float rad_fac, int stitch, tGpTimingData *gtd) + float minmax_weights[2], const float rad_fac, bool stitch, tGpTimingData *gtd) { bGPDspoint *pt; Nurb *nu = (curnu) ? *curnu : NULL; BPoint *bp, *prev_bp = NULL; - const int do_gtd = (gtd->mode != GP_STROKECONVERT_TIMING_NONE); + const bool do_gtd = (gtd->mode != GP_STROKECONVERT_TIMING_NONE); int i, old_nbp = 0; /* create new 'nurb' or extend current one within the curve */ if (nu) { old_nbp = nu->pntsu; - + /* If stitch, the first point of this stroke is already present in current nu. * Else, we have to add to additional points to make the zero-radius link between strokes. */ @@ -847,7 +847,7 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv } else { nu = (Nurb *)MEM_callocN(sizeof(Nurb), "gpstroke_to_path(nurb)"); - + nu->pntsu = gps->totpoints; nu->pntsv = 1; nu->orderu = 2; /* point-to-point! */ @@ -856,10 +856,10 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv nu->resolu = cu->resolu; nu->resolv = cu->resolv; nu->knotsu = NULL; - + nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "bpoints"); - - stitch = FALSE; /* Security! */ + + stitch = false; /* Security! */ } if (do_gtd) { @@ -885,7 +885,7 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv prev_bp = nu->bp + old_nbp - 2; } bp = nu->bp + old_nbp - 1; - + /* XXX We do this twice... Not sure it's worth to bother about this! */ gp_strokepoint_convertcoords(C, gps, gps->points, p, subrect); if (prev_bp) { @@ -894,7 +894,7 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv else { interp_v3_v3v3(p1, bp->vec, p, GAP_DFAC); } - + if (gps->totpoints > 1) { /* XXX We do this twice... Not sure it's worth to bother about this! */ gp_strokepoint_convertcoords(C, gps, gps->points + 1, next_p, subrect); @@ -903,7 +903,7 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv else { interp_v3_v3v3(p2, p, bp->vec, GAP_DFAC); } - + /* First point */ bp++; copy_v3_v3(bp->vec, p1); @@ -919,7 +919,7 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv } gp_timing_data_add_point(gtd, gtd->inittime, delta_time, len_v3v3((bp - 1)->vec, p1)); } - + /* Second point */ bp++; copy_v3_v3(bp->vec, p2); @@ -936,13 +936,13 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv } gp_timing_data_add_point(gtd, gps->inittime, delta_time, len_v3v3(p1, p2)); } - + old_nbp += 2; } if (old_nbp && do_gtd) { prev_bp = nu->bp + old_nbp - 1; } - + /* add points */ for (i = (stitch) ? 1 : 0, pt = gps->points + ((stitch) ? 1 : 0), bp = nu->bp + old_nbp; i < gps->totpoints; @@ -950,12 +950,12 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv { float p3d[3]; float width = pt->pressure * gpl->thickness * WIDTH_CORR_FAC; - + /* get coordinates to add at */ gp_strokepoint_convertcoords(C, gps, pt, p3d, subrect); copy_v3_v3(bp->vec, p3d); bp->vec[3] = 1.0f; - + /* set settings */ bp->f1 = SELECT; bp->radius = width * rad_fac; @@ -967,14 +967,14 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv else if (bp->weight > minmax_weights[1]) { minmax_weights[1] = bp->weight; } - + /* Update timing data */ if (do_gtd) { gp_timing_data_add_point(gtd, gps->inittime, pt->time, (prev_bp) ? len_v3v3(prev_bp->vec, p3d) : 0.0f); } prev_bp = bp; } - + /* add nurb to curve */ if (!curnu || !*curnu) { BLI_addtail(&cu->nurb, nu); @@ -982,7 +982,7 @@ static void gp_stroke_to_path(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curv if (curnu) { *curnu = nu; } - + BKE_nurb_knot_calc_u(nu); } @@ -990,10 +990,10 @@ static int gp_camera_view_subrect(bContext *C, rctf *subrect) { View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); - + if (v3d) { RegionView3D *rv3d = ar->regiondata; - + /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { Scene *scene = CTX_data_scene(C); @@ -1001,21 +1001,21 @@ static int gp_camera_view_subrect(bContext *C, rctf *subrect) return 1; } } - + return 0; } /* convert stroke to 3d bezier */ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Curve *cu, rctf *subrect, Nurb **curnu, - float minmax_weights[2], float rad_fac, int stitch, tGpTimingData *gtd) + float minmax_weights[2], const float rad_fac, bool stitch, tGpTimingData *gtd) { bGPDspoint *pt; Nurb *nu = (curnu) ? *curnu : NULL; BezTriple *bezt, *prev_bezt = NULL; int i, tot, old_nbezt = 0; float p3d_cur[3], p3d_prev[3], p3d_next[3]; - const int do_gtd = (gtd->mode != GP_STROKECONVERT_TIMING_NONE); - + const bool do_gtd = (gtd->mode != GP_STROKECONVERT_TIMING_NONE); + /* create new 'nurb' or extend current one within the curve */ if (nu) { old_nbezt = nu->pntsu; @@ -1027,14 +1027,14 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu } else { nu = (Nurb *)MEM_callocN(sizeof(Nurb), "gpstroke_to_bezier(nurb)"); - + nu->pntsu = gps->totpoints; nu->resolu = 12; nu->resolv = 12; nu->type = CU_BEZIER; nu->bezt = (BezTriple *)MEM_callocN(gps->totpoints * sizeof(BezTriple), "bezts"); - - stitch = FALSE; /* Security! */ + + stitch = false; /* Security! */ } if (do_gtd) { @@ -1065,7 +1065,7 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu copy_v3_v3(bezt->vec[2], h2); pt++; } - + /* Create "link points" */ /* About "zero-radius" point interpolations: * - If we have at least two points in current curve (most common case), we linearly extrapolate @@ -1078,7 +1078,7 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu else { float h1[3], h2[3], p1[3], p2[3]; float delta_time; - + prev_bezt = NULL; if (old_nbezt > 1 && gps->prev && gps->prev->totpoints > 1) { /* Only use last curve segment if previous stroke was not a single-point one! */ @@ -1097,15 +1097,15 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu else { interp_v3_v3v3(p2, p3d_cur, bezt->vec[1], GAP_DFAC); } - + /* Second handle of last point */ interp_v3_v3v3(h2, bezt->vec[1], p1, BEZT_HANDLE_FAC); copy_v3_v3(bezt->vec[2], h2); - + /* First point */ interp_v3_v3v3(h1, p1, bezt->vec[1], BEZT_HANDLE_FAC); interp_v3_v3v3(h2, p1, p2, BEZT_HANDLE_FAC); - + bezt++; copy_v3_v3(bezt->vec[0], h1); copy_v3_v3(bezt->vec[1], p1); @@ -1113,7 +1113,7 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu bezt->h1 = bezt->h2 = HD_FREE; bezt->f1 = bezt->f2 = bezt->f3 = SELECT; minmax_weights[0] = bezt->radius = bezt->weight = 0.0f; - + if (do_gtd) { if (prev_bezt) { delta_time = gtd->tot_time + (gtd->tot_time - gtd->times[gtd->cur_point - 1]) * GAP_DFAC; @@ -1123,11 +1123,11 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu } gp_timing_data_add_point(gtd, gtd->inittime, delta_time, len_v3v3((bezt - 1)->vec[1], p1)); } - + /* Second point */ interp_v3_v3v3(h1, p2, p1, BEZT_HANDLE_FAC); interp_v3_v3v3(h2, p2, p3d_cur, BEZT_HANDLE_FAC); - + bezt++; copy_v3_v3(bezt->vec[0], h1); copy_v3_v3(bezt->vec[1], p2); @@ -1135,7 +1135,7 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu bezt->h1 = bezt->h2 = HD_FREE; bezt->f1 = bezt->f2 = bezt->f3 = SELECT; minmax_weights[0] = bezt->radius = bezt->weight = 0.0f; - + if (do_gtd) { /* This negative delta_time marks the gap! */ if (tot > 1) { @@ -1146,7 +1146,7 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu } gp_timing_data_add_point(gtd, gps->inittime, delta_time, len_v3v3(p1, p2)); } - + old_nbezt += 2; copy_v3_v3(p3d_prev, p2); } @@ -1154,30 +1154,30 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu if (old_nbezt && do_gtd) { prev_bezt = nu->bezt + old_nbezt - 1; } - + /* add points */ for (i = stitch ? 1 : 0, bezt = nu->bezt + old_nbezt; i < tot; i++, pt++, bezt++) { float h1[3], h2[3]; float width = pt->pressure * gpl->thickness * WIDTH_CORR_FAC; - + if (i || old_nbezt) { interp_v3_v3v3(h1, p3d_cur, p3d_prev, BEZT_HANDLE_FAC); } else { interp_v3_v3v3(h1, p3d_cur, p3d_next, -BEZT_HANDLE_FAC); } - + if (i < tot - 1) { interp_v3_v3v3(h2, p3d_cur, p3d_next, BEZT_HANDLE_FAC); } else { interp_v3_v3v3(h2, p3d_cur, p3d_prev, -BEZT_HANDLE_FAC); } - + copy_v3_v3(bezt->vec[0], h1); copy_v3_v3(bezt->vec[1], p3d_cur); copy_v3_v3(bezt->vec[2], h2); - + /* set settings */ bezt->h1 = bezt->h2 = HD_FREE; bezt->f1 = bezt->f2 = bezt->f3 = SELECT; @@ -1190,23 +1190,23 @@ static void gp_stroke_to_bezier(bContext *C, bGPDlayer *gpl, bGPDstroke *gps, Cu else if (bezt->weight > minmax_weights[1]) { minmax_weights[1] = bezt->weight; } - + /* Update timing data */ if (do_gtd) { gp_timing_data_add_point(gtd, gps->inittime, pt->time, prev_bezt ? len_v3v3(prev_bezt->vec[1], p3d_cur) : 0.0f); } - + /* shift coord vects */ copy_v3_v3(p3d_prev, p3d_cur); copy_v3_v3(p3d_cur, p3d_next); - + if (i + 2 < tot) { gp_strokepoint_convertcoords(C, gps, pt + 2, p3d_next, subrect); } - + prev_bezt = bezt; } - + /* must calculate handles or else we crash */ BKE_nurb_handles_calc(nu); @@ -1239,7 +1239,7 @@ static void gp_stroke_finalize_curve_endpoints(Curve *cu) bp[i].weight = bp[i].radius = 0.0f; } } - + /* end */ nu = cu->nurb.last; i = nu->pntsu - 1; @@ -1263,13 +1263,13 @@ static void gp_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2 const float delta = minmax_weights[0]; float fac; int i; - + /* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */ if (IS_EQF(delta, minmax_weights[1])) fac = 1.0f; else fac = 1.0f / (minmax_weights[1] - delta); - + for (nu = cu->nurb.first; nu; nu = nu->next) { if (nu->bezt) { BezTriple *bezt = nu->bezt; @@ -1287,8 +1287,8 @@ static void gp_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2 } /* convert a given grease-pencil layer to a 3d-curve representation (using current view if appropriate) */ -static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bGPDlayer *gpl, int mode, - int norm_weights, float rad_fac, int link_strokes, tGpTimingData *gtd) +static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bGPDlayer *gpl, const int mode, + const bool norm_weights, const float rad_fac, const bool link_strokes, tGpTimingData *gtd) { struct Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); @@ -1302,11 +1302,11 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG /* camera framing */ rctf subrect, *subrect_ptr = NULL; - + /* error checking */ if (ELEM3(NULL, gpd, gpl, gpf)) return; - + /* only convert if there are any strokes on this layer's frame to convert */ if (gpf->strokes.first == NULL) return; @@ -1315,7 +1315,7 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG if (gp_camera_view_subrect(C, &subrect)) { subrect_ptr = &subrect; } - + /* init the curve object (remove rotation and get curve data from it) * - must clear transforms set on object, as those skew our results */ @@ -1324,30 +1324,30 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG base_new = BKE_scene_base_add(scene, ob); cu->flag |= CU_3D; - + gtd->inittime = ((bGPDstroke *)gpf->strokes.first)->inittime; - + /* add points to curve */ for (gps = gpf->strokes.first; gps; gps = gps->next) { /* Detect new strokes created because of GP_STROKE_BUFFER_MAX reached, * and stitch them to previous one. */ int stitch = FALSE; - + if (prev_gps) { bGPDspoint *pt1 = prev_gps->points + prev_gps->totpoints - 1; bGPDspoint *pt2 = gps->points; - + if ((pt1->x == pt2->x) && (pt1->y == pt2->y)) { stitch = TRUE; } } - + /* Decide whether we connect this stroke to previous one */ if (!(stitch || link_strokes)) { nu = NULL; } - + switch (mode) { case GP_STROKECONVERT_PATH: gp_stroke_to_path(C, gpl, gps, cu, subrect_ptr, &nu, minmax_weights, rad_fac, stitch, gtd); @@ -1367,7 +1367,7 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG if (link_strokes) { gp_stroke_finalize_curve_endpoints(cu); } - + /* Update curve's weights, if needed */ if (norm_weights && ((minmax_weights[0] > 0.0f) || (minmax_weights[1] < 1.0f))) { gp_stroke_norm_curve_weights(cu, minmax_weights); @@ -1392,25 +1392,26 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG /* Check a GP layer has valid timing data! Else, most timing options are hidden in the operator. * op may be NULL. */ -static int gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOperator *op) +static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOperator *op) { Scene *scene = CTX_data_scene(C); bGPDframe *gpf = NULL; bGPDstroke *gps = NULL; bGPDspoint *pt; double base_time, cur_time, prev_time = -1.0; - int i, valid = TRUE; - + int i; + bool valid = true; + if (!gpl || !(gpf = gpencil_layer_getframe(gpl, CFRA, 0)) || !(gps = gpf->strokes.first)) - return FALSE; - + return false; + do { base_time = cur_time = gps->inittime; if (cur_time <= prev_time) { - valid = FALSE; + valid = false; break; } - + prev_time = cur_time; for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { cur_time = base_time + (double)pt->time; @@ -1418,17 +1419,17 @@ static int gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOper * so it's the only case where equality is allowed! */ if ((i && cur_time <= prev_time) || (cur_time < prev_time)) { - valid = FALSE; + valid = false; break; } prev_time = cur_time; } - + if (!valid) { break; } } while ((gps = gps->next)); - + if (op) { RNA_boolean_set(op->ptr, "use_timing_data", valid); } @@ -1440,7 +1441,7 @@ static void gp_convert_set_end_frame(struct Main *UNUSED(main), struct Scene *UN { int start_frame = RNA_int_get(ptr, "start_frame"); int end_frame = RNA_int_get(ptr, "end_frame"); - + if (end_frame <= start_frame) { RNA_int_set(ptr, "end_frame", start_frame + 1); } @@ -1470,25 +1471,25 @@ static int gp_convert_layer_exec(bContext *C, wmOperator *op) bGPdata *gpd = gpencil_data_get_active(C); bGPDlayer *gpl = gpencil_layer_getactive(gpd); Scene *scene = CTX_data_scene(C); - int mode = RNA_enum_get(op->ptr, "type"); - int norm_weights = RNA_boolean_get(op->ptr, "use_normalize_weights"); - float rad_fac = RNA_float_get(op->ptr, "radius_multiplier"); - int link_strokes = RNA_boolean_get(op->ptr, "use_link_strokes"); - int valid_timing; + const int mode = RNA_enum_get(op->ptr, "type"); + const bool norm_weights = RNA_boolean_get(op->ptr, "use_normalize_weights"); + const float rad_fac = RNA_float_get(op->ptr, "radius_multiplier"); + const bool link_strokes = RNA_boolean_get(op->ptr, "use_link_strokes"); + bool valid_timing; tGpTimingData gtd; - + /* check if there's data to work with */ if (gpd == NULL) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data to work on"); return OPERATOR_CANCELLED; } - + if (!RNA_property_is_set(op->ptr, prop) && !gp_convert_check_has_valid_timing(C, gpl, op)) { BKE_report(op->reports, RPT_WARNING, "Current Grease Pencil strokes have no valid timing data, most timing options will be hidden!"); } valid_timing = RNA_property_boolean_get(op->ptr, prop); - + gtd.mode = RNA_enum_get(op->ptr, "timing_mode"); /* Check for illegal timing mode! */ if (!valid_timing && !ELEM(gtd.mode, GP_STROKECONVERT_TIMING_NONE, GP_STROKECONVERT_TIMING_LINEAR)) { @@ -1498,11 +1499,11 @@ static int gp_convert_layer_exec(bContext *C, wmOperator *op) if (!link_strokes) { gtd.mode = GP_STROKECONVERT_TIMING_NONE; } - + /* grab all relevant settings */ gtd.frame_range = RNA_int_get(op->ptr, "frame_range"); gtd.start_frame = RNA_int_get(op->ptr, "start_frame"); - gtd.realtime = valid_timing ? RNA_boolean_get(op->ptr, "use_realtime") : FALSE; + gtd.realtime = valid_timing ? RNA_boolean_get(op->ptr, "use_realtime") : false; gtd.end_frame = RNA_int_get(op->ptr, "end_frame"); gtd.gap_duration = RNA_float_get(op->ptr, "gap_duration"); gtd.gap_randomness = RNA_float_get(op->ptr, "gap_randomness"); @@ -1512,10 +1513,10 @@ static int gp_convert_layer_exec(bContext *C, wmOperator *op) gtd.dists = gtd.times = NULL; gtd.tot_dist = gtd.tot_time = gtd.gap_tot_time = 0.0f; gtd.inittime = 0.0; - + /* perform conversion */ gp_layer_to_curve(C, op->reports, gpd, gpl, mode, norm_weights, rad_fac, link_strokes, >d); - + /* free temp memory */ if (gtd.dists) { MEM_freeN(gtd.dists); @@ -1525,11 +1526,11 @@ static int gp_convert_layer_exec(bContext *C, wmOperator *op) MEM_freeN(gtd.times); gtd.times = NULL; } - + /* notifiers */ WM_event_add_notifier(C, NC_OBJECT | NA_ADDED, NULL); WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); - + /* done */ return OPERATOR_FINISHED; } @@ -1539,11 +1540,11 @@ static bool gp_convert_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop) const char *prop_id = RNA_property_identifier(prop); int link_strokes = RNA_boolean_get(ptr, "use_link_strokes"); int timing_mode = RNA_enum_get(ptr, "timing_mode"); - int realtime = RNA_boolean_get(ptr, "use_realtime"); + bool realtime = RNA_boolean_get(ptr, "use_realtime"); float gap_duration = RNA_float_get(ptr, "gap_duration"); float gap_randomness = RNA_float_get(ptr, "gap_randomness"); int valid_timing = RNA_boolean_get(ptr, "use_timing_data"); - + /* Always show those props */ if (strcmp(prop_id, "type") == 0 || strcmp(prop_id, "use_normalize_weights") == 0 || @@ -1552,7 +1553,7 @@ static bool gp_convert_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop) { return true; } - + /* Never show this prop */ if (strcmp(prop_id, "use_timing_data") == 0) return FALSE; @@ -1561,7 +1562,7 @@ static bool gp_convert_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop) /* Only show when link_stroke is true */ if (strcmp(prop_id, "timing_mode") == 0) return true; - + if (timing_mode != GP_STROKECONVERT_TIMING_NONE) { /* Only show when link_stroke is true and stroke timing is enabled */ if (strcmp(prop_id, "frame_range") == 0 || @@ -1569,24 +1570,24 @@ static bool gp_convert_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop) { return true; } - + /* Only show if we have valid timing data! */ if (valid_timing && strcmp(prop_id, "use_realtime") == 0) return true; - - /* Only show if realtime or valid_timing is FALSE! */ + + /* Only show if realtime or valid_timing is false! */ if ((!realtime || !valid_timing) && strcmp(prop_id, "end_frame") == 0) return true; - + if (valid_timing && timing_mode == GP_STROKECONVERT_TIMING_CUSTOMGAP) { /* Only show for custom gaps! */ if (strcmp(prop_id, "gap_duration") == 0) return true; - + /* Only show randomness for non-null custom gaps! */ if (strcmp(prop_id, "gap_randomness") == 0 && (gap_duration > 0.0f)) return true; - + /* Only show seed for randomize action! */ if (strcmp(prop_id, "seed") == 0 && (gap_duration > 0.0f) && (gap_randomness > 0.0f)) return true; @@ -1613,35 +1614,35 @@ static void gp_convert_ui(bContext *C, wmOperator *op) void GPENCIL_OT_convert(wmOperatorType *ot) { PropertyRNA *prop; - + /* identifiers */ ot->name = "Convert Grease Pencil"; ot->idname = "GPENCIL_OT_convert"; ot->description = "Convert the active Grease Pencil layer to a new Curve Object"; - + /* callbacks */ ot->invoke = WM_menu_invoke; ot->exec = gp_convert_layer_exec; ot->poll = gp_convert_poll; ot->ui = gp_convert_ui; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", prop_gpencil_convertmodes, 0, "Type", "Which type of curve to convert to"); - + RNA_def_boolean(ot->srna, "use_normalize_weights", TRUE, "Normalize Weight", "Normalize weight (set from stroke width)"); RNA_def_float(ot->srna, "radius_multiplier", 1.0f, 0.0f, 1000.0f, "Radius Fac", "Multiplier for the points' radii (set from stroke width)", 0.0f, 10.0f); RNA_def_boolean(ot->srna, "use_link_strokes", TRUE, "Link Strokes", "Whether to link strokes with zero-radius sections of curves"); - + prop = RNA_def_enum(ot->srna, "timing_mode", prop_gpencil_convert_timingmodes, GP_STROKECONVERT_TIMING_FULL, "Timing Mode", "How to use timing data stored in strokes"); RNA_def_enum_funcs(prop, rna_GPConvert_mode_items); - + RNA_def_int(ot->srna, "frame_range", 100, 1, 10000, "Frame Range", "The duration of evaluation of the path control curve", 1, 1000); RNA_def_int(ot->srna, "start_frame", 1, 1, 100000, "Start Frame", @@ -1651,7 +1652,7 @@ void GPENCIL_OT_convert(wmOperatorType *ot) prop = RNA_def_int(ot->srna, "end_frame", 250, 1, 100000, "End Frame", "The end frame of the path control curve (if Realtime is not set)", 1, 100000); RNA_def_property_update_runtime(prop, gp_convert_set_end_frame); - + RNA_def_float(ot->srna, "gap_duration", 0.0f, 0.0f, 10000.0f, "Gap Duration", "Custom Gap mode: (Average) length of gaps, in frames " "(Note: Realtime value, will be scaled if Realtime is not set)", 0.0f, 1000.0f); @@ -1659,7 +1660,7 @@ void GPENCIL_OT_convert(wmOperatorType *ot) "Custom Gap mode: Number of frames that gap lengths can vary", 0.0f, 1000.0f); RNA_def_int(ot->srna, "seed", 0, 0, 1000, "Random Seed", "Custom Gap mode: Random generator seed", 0, 100); - + /* Note: Internal use, this one will always be hidden by UI code... */ prop = RNA_def_boolean(ot->srna, "use_timing_data", FALSE, "Has Valid Timing", "Whether the converted Grease Pencil layer has valid timing data (internal use)"); -- cgit v1.2.3