Code:
double knuckled_profile_report::make_table(double offest)
{ int irc, n_rows, n_cols, num_sections, i, j, shift_row; double pt[3];
UF_TABNOT_section_prefs_t tabnote_section_prefs, tabnote_section_prefs_save;
UF_TABNOT_cell_prefs_t tabnote_cell_prefs, tabnote_cell_prefs_save;
tag_t work_view_tag, wcs_tag, m_tag, csys_tag;
int mpi[100]; double mpr[70]; char rp[27+1], dp[27+1];
UF_ATTR_value_t attr_val; char sval[UF_ATTR_MAX_STRING_LEN+1];
double box[6], ymin, ymax; try
{
irc=UF_DRF_ask_preferences(mpi, mpr, rp, dp);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_CSYS_ask_wcs(&wcs_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_CSYS_create_matrix(matrix, &m_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_CSYS_create_temp_csys(map(0.0,-offest,pt), m_tag, &csys_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_ask_default_section_prefs(&tabnote_section_prefs);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
tabnote_section_prefs_save=tabnote_section_prefs;
tabnote_section_prefs.attach_point = UF_TABNOT_attach_point_t(UF_TABNOT_attach_point_top_left);
tabnote_section_prefs.max_height = 0L;
irc=UF_TABNOT_ask_default_cell_prefs(&tabnote_cell_prefs);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
tabnote_cell_prefs_save=tabnote_cell_prefs;
tabnote_cell_prefs.is_vertical = false;
tabnote_cell_prefs.nm_fit_methods = 2;
tabnote_cell_prefs.fit_methods[0] = UF_TABNOT_fit_method_t(UF_TABNOT_fit_method_auto_size_row);
tabnote_cell_prefs.fit_methods[1] = UF_TABNOT_fit_method_t(UF_TABNOT_fit_method_auto_size_col);
tabnote_cell_prefs.format = UF_TABNOT_format_t(UF_TABNOT_format_text);
tabnote_cell_prefs.horiz_just = UF_TABNOT_just_t(UF_TABNOT_just_left);
tabnote_cell_prefs.vert_just = UF_TABNOT_just_t(UF_TABNOT_just_middle);
if(flag_table_line_color)
tabnote_cell_prefs.bottom_line_cfw[0]=tabnote_cell_prefs.right_line_cfw[0]=table_line_color;
if(flag_table_line_font)
tabnote_cell_prefs.bottom_line_cfw[1]=tabnote_cell_prefs.right_line_cfw[1]=table_line_font;
if(flag_table_line_width)
tabnote_cell_prefs.bottom_line_cfw[2]=tabnote_cell_prefs.right_line_cfw[2]=table_line_width;
tabnote_cell_prefs.text_height = mpr[44];
if(flag_table_text_height) tabnote_cell_prefs.text_height=table_text_height;
if(flag_table_text_color) tabnote_cell_prefs.text_color=table_text_color;
if(flag_table_text_width) tabnote_cell_prefs.text_density=table_text_width;
irc=UF_TABNOT_set_default_section_prefs(&tabnote_section_prefs);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_set_default_cell_prefs(&tabnote_cell_prefs);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_CSYS_set_wcs(csys_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_create(&tabnote_section_prefs, pt, &tabnote_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_enable_automatic_update(false);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_ask_nm_rows(tabnote_tag, &n_rows);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
for(i=0; i<n_rows; i++)
{ tag_t row_tag;
irc=UF_TABNOT_ask_nth_row(tabnote_tag, 0, &row_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_remove_row(row_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
irc=UF_TABNOT_ask_nm_columns(tabnote_tag, &n_cols);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
for(i=0; i<n_cols; i++)
{ tag_t col_tag;
irc=UF_TABNOT_ask_nth_column(tabnote_tag, 0, &col_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_remove_column(col_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
n_rows=1+((int)segments.size()<table_number_of_rows?(int)segments.size():table_number_of_rows);
i=segments.size()/(n_rows-1);
n_cols=5*( (double)segments.size()/(n_rows-1)-i > 0 ? i+1 : i );
for(i=0; i<n_rows; i++)
{ tag_t row_tag;
irc=UF_TABNOT_create_row(10.0, &row_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_add_row(tabnote_tag, row_tag, 0);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
for(i=0; i<n_cols; i++)
{ tag_t col_tag;
irc=UF_TABNOT_create_column(10.0, &col_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_add_column(tabnote_tag, col_tag, 0);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
std::vector < std::vector <tag_t> > vvcells;
vvcells.reserve(n_rows);
for(i=0; i<n_rows; i++)
{ std::vector <tag_t> vbuff; tag_t row_tag;
irc=UF_TABNOT_ask_nth_row(tabnote_tag, i, &row_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
for (j=0; j<n_cols; j++)
{ tag_t col_tag, cell_tag;
irc=UF_TABNOT_ask_nth_column(tabnote_tag, j, &col_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_ask_cell_at_row_col(row_tag, col_tag, &cell_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
vbuff.push_back(cell_tag);
}
vvcells.push_back(vbuff);
}
for(i=0; i<(int)vvcells.at(0).size(); i++)
{
if(1 == i%5)
{
irc=UF_TABNOT_set_cell_text(vvcells[0][i], "Distance Base");
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
if(3 == i%5)
{
irc=UF_TABNOT_set_cell_text(vvcells[0][i], "Distance Top");
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
if(4 == i%5)
{
irc=UF_TABNOT_set_cell_text(vvcells[0][i], "Knuckle Angle");
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
irc=UF_TABNOT_set_cell_prefs(vvcells[0][i], &tabnote_cell_prefs);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
int txt_prec=-1; bool txt_tr_zer=true;
if(flag_table_text_precision) txt_prec = table_text_precision;
if(flag_table_text_keep_trail_zeroes) txt_tr_zer = table_text_keep_trail_zeroes;
for(i=1, j=1, shift_row=-5; i<(int)table_segments.size(); i++, j++)
{
if((i-1)%(n_rows-1) == 0) { shift_row+=5; j=1; }
irc=UF_TABNOT_set_cell_text(vvcells[j][shift_row+0], table_segments[i].get_index().c_str());
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_set_cell_text(vvcells[j][shift_row+1], table_segments[i].get_dist_base(txt_prec, txt_tr_zer).c_str());
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_set_cell_text(vvcells[j][shift_row+2], table_segments[i].get_index().c_str());
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_set_cell_text(vvcells[j][shift_row+3], table_segments[i].get_dist_top(txt_prec, txt_tr_zer).c_str());
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_set_cell_text(vvcells[j][shift_row+4], table_segments[i].get_angle().c_str());
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
if(flag_table_line_color)
{
irc=UF_OBJ_set_color(tabnote_tag, table_line_color);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
if(flag_table_line_font)
{
irc=UF_OBJ_set_font(tabnote_tag, table_line_font);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
if(flag_table_line_width)
{
irc=UF_OBJ_set_line_width(tabnote_tag, table_line_width);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
if(flag_table_text_layer)
{
irc=UF_OBJ_set_layer(tabnote_tag, table_text_layer);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
irc=UF_TABNOT_enable_automatic_update(true);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_DRAW_update_tabnot(tabnote_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_CSYS_set_wcs(wcs_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_ask_nm_sections(tabnote_tag, &num_sections);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
attr_val.type=UF_ATTR_string; attr_val.value.string = sval;
strcpy(sval, value_attribute_mk_type_tabnote);
for(i=0; i<num_sections; i++)
{ tag_t section_tag;
irc=UF_TABNOT_ask_nth_section(tabnote_tag, i, §ion_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
tabnote_sections.push_back(section_tag);
irc=UF_ATTR_assign(section_tag, name_attribute_mk_type, attr_val);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
}
irc=UF_VIEW_ask_work_view(&work_view_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_VIEW_convert_to_model(work_view_tag, tabnote_tag);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_set_default_section_prefs(&tabnote_section_prefs_save);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_TABNOT_set_default_cell_prefs(&tabnote_cell_prefs_save);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
irc=UF_MODL_ask_bounding_box (tabnote_sections[0], box);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
ymin=box[1]; ymax=box[4];
for(i=1; i<num_sections; i++)
{
irc=UF_MODL_ask_bounding_box (tabnote_sections[i], box);
if(irc) throw ug_err(THIS_FILE, __LINE__, irc);
if(box[1] < ymin) ymin=box[1];
if(box[4] > ymax) ymax=box[4];
}
}
catch(base_err &e) { e.trace(THIS_FILE, __LINE__); throw; }
catch(...) { base_err e(THIS_FILE, __LINE__, "System error"); throw e; }
return ymax-ymin;
}