Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation text segment extending #14

Merged
merged 5 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/rt/geom.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@ struct txt_seg {
int ref_pt; /** reference point */
int rel_pos; /** flag describing position relative to ref_pt */
struct bu_vls label;
fastf_t txt_size; /** text size */
fastf_t txt_rot_angle; /** text rotation angle */
};

/**
Expand Down
8 changes: 6 additions & 2 deletions src/libged/typein/typein.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,9 @@ static const char *p_annot[] = {
"Enter X, Y for the text placement: ",
"Enter Y: ",
"Enter relative horizontal position (1->left, 2->center, 3->right): ",
"Enter relative vertical position (1->bottom, 2->middle, 3->top): "
"Enter relative vertical position (1->bottom, 2->middle, 3->top): ",
"Enter text size: ",
"Enter text angle: "
};


Expand Down Expand Up @@ -3295,6 +3297,8 @@ annot_in(struct ged *gedp, const char **cmd_argvs, struct rt_db_internal *intern
tsg->ref_pt = 0;
bu_vls_init(&tsg->label);
bu_vls_strcpy(&tsg->label, cmd_argvs[6]);
tsg->txt_size = atof(cmd_argvs[11]);
tsg->txt_rot_angle = atof(cmd_argvs[12]);

BU_ALLOC(lsg, struct line_seg);
lsg->magic = CURVE_LSEG_MAGIC;
Expand Down Expand Up @@ -3607,7 +3611,7 @@ ged_in_core(struct ged *gedp, int argc, const char *argv[])
menu = p_joint;
fn_in = joint_in;
} else if (BU_STR_EQUAL(argv[2], "annot")) {
nvals = 3 + 1+ 2 + 2;
nvals = 3 + 1 + 2 + 2 + 2;
menu = p_annot;
fn_in = annot_in;
} else if (BU_STR_EQUAL(argv[2], "script")) {
Expand Down
28 changes: 22 additions & 6 deletions src/librt/primitives/annot/annot.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ant_label_dimensions(struct txt_seg* tsg, hpoint_t ref_pt, fastf_t* length, fast
VSET(bmin, INFINITY, INFINITY, INFINITY);
VSET(bmax, -INFINITY, -INFINITY, -INFINITY);

bv_vlist_2string(&vhead, &RTG.rtg_vlfree, tsg->label.vls_str, ref_pt[0], ref_pt[1], 5, 0);
bv_vlist_2string(&vhead, &RTG.rtg_vlfree, tsg->label.vls_str, ref_pt[0], ref_pt[1], tsg->txt_size, tsg->txt_rot_angle);
bv_vlist_bbox(&vhead, &bmin, &bmax, NULL, NULL);

*length = bmax[0] - ref_pt[0];
Expand Down Expand Up @@ -453,7 +453,7 @@ seg_to_vlist(struct bu_list *vlfree, struct bu_list *vhead, const struct bg_tess
}
ant_pos_adjs(tsg, annot_ip);
V2ADD2(pt, V, annot_ip->verts[tsg->ref_pt]);
bv_vlist_2string(vhead, &RTG.rtg_vlfree, tsg->label.vls_str, pt[0], pt[1], 5, 0);
bv_vlist_2string(vhead, &RTG.rtg_vlfree, tsg->label.vls_str, pt[0], pt[1], tsg->txt_size, tsg->txt_rot_angle);
break;
case CURVE_CARC_MAGIC:
{
Expand Down Expand Up @@ -951,6 +951,12 @@ rt_annot_import5(struct rt_db_internal *ip, const struct bu_external *ep, const
bu_vls_init(&tsg->label);
bu_vls_strcpy(&tsg->label, (const char*)ptr);
ptr += bu_vls_strlen(&tsg->label) + 1;
bu_cv_ntohd((unsigned char*)&scan, ptr, 1);
tsg->txt_size = scan; /* double to fastf_t */
ptr += SIZEOF_NETWORK_DOUBLE;
bu_cv_ntohd((unsigned char*)&scan, ptr, 1);
tsg->txt_rot_angle = scan; /* double to fastf_t */
ptr += SIZEOF_NETWORK_DOUBLE;
annot_ip->ant.segments[seg_no] = (void *)tsg;
break;
case CURVE_CARC_MAGIC:
Expand Down Expand Up @@ -1089,11 +1095,11 @@ rt_annot_export5(struct bu_external *ep, const struct rt_db_internal *ip, double
break;
case ANN_TSEG_MAGIC:
tseg = (struct txt_seg*)lng;
/* magic + ref_pt + pt_rel_pos + label->vls_str length + 1 for the null terminator*/
ep->ext_nbytes += 3 * SIZEOF_NETWORK_LONG + bu_vls_strlen(&tseg->label) + 1;
/* magic + pt_rel_pos + (double) txt_size + (double) txt_rot_angle + label->vls_str length + 1 for the null terminator */
ep->ext_nbytes += 3 * SIZEOF_NETWORK_LONG + 2 * SIZEOF_NETWORK_DOUBLE + bu_vls_strlen(&tseg->label) + 1;
break;
case CURVE_CARC_MAGIC:
/* magic + start + end + orientation + center_is_left + (double)radius*/
/* magic + start + end + orientation + center_is_left + (double)radius */
ep->ext_nbytes += 5 * SIZEOF_NETWORK_LONG + SIZEOF_NETWORK_DOUBLE;
break;
case CURVE_NURB_MAGIC:
Expand Down Expand Up @@ -1181,6 +1187,12 @@ rt_annot_export5(struct bu_external *ep, const struct rt_db_internal *ip, double
bu_strlcpy((char *)cp, bu_vls_addr(&tseg->label), bu_vls_strlen(&tseg->label) + 1);

cp += bu_vls_strlen(&tseg->label) + 1;
scan = tseg->txt_size;
bu_cv_htond(cp, (unsigned char*)&scan, 1);
cp += SIZEOF_NETWORK_DOUBLE;
scan = tseg->txt_rot_angle;
bu_cv_htond(cp, (unsigned char*)&scan, 1);
cp += SIZEOF_NETWORK_DOUBLE;
break;
case CURVE_CARC_MAGIC:
cseg = (struct carc_seg *)lng;
Expand Down Expand Up @@ -1347,6 +1359,10 @@ rt_annot_describe(struct bu_vls *str, const struct rt_db_internal *ip, int verbo
bu_vls_strcat(str, buf);
sprintf(buf, "\tLabel text: %s\n", bu_vls_addr(&tsg->label));
bu_vls_strcat(str, buf);
sprintf(buf, "\tText size: %.1f\n", tsg->txt_size);
bu_vls_strcat(str, buf);
sprintf(buf, "\tText rotation angle: %.1f\n", tsg->txt_rot_angle);
bu_vls_strcat(str, buf);
break;
case CURVE_CARC_MAGIC:
csg = (struct carc_seg *)annot_ip->ant.segments[seg_no];
Expand Down Expand Up @@ -1677,7 +1693,7 @@ ant_to_tcl_list(struct bu_vls *vls, struct rt_ant *ant)
{
struct txt_seg *tsg = (struct txt_seg *)ant->segments[j];
ant_check_pos(tsg, &rel_pos);
bu_vls_printf(vls, " { label %s ref_pt %d position %s }", bu_vls_addr(&tsg->label), tsg->ref_pt, rel_pos);
bu_vls_printf(vls, " { label %s ref_pt %d position %s txt_size %.25g txt_rot_angle %.25g }", bu_vls_addr(&tsg->label), tsg->ref_pt, rel_pos, tsg->txt_size, tsg->txt_rot_angle);
}
break;
case CURVE_CARC_MAGIC:
Expand Down