/*****************************************************************************\ FILE : UgTableCreate.c PURPOSE : Pro/TOOLKIT User Guide Example - drawing table creation HISTORY.. DATE BUILD AUTHOR MODIFICATIONS 04-Dec-97 H-02-02 Philippe $$1 Created 24-Dec-97 H-03-34 dmp $$2 added display argument to drawing functions \*****************************************************************************/ /*-------------------------- Pro/Develop includes ---------------------------*/ #include #include /*-------------------------- Pro/Toolkit includes ---------------------------*/ #include #include #include /*-------------------------- Application includes ---------------------------*/ #include /*-----------------------Global Declarations---------------------------------*/ static ProLine line1, line2; static wchar_t *line_array[] = {line1, line2}; typedef struct { ProMdl p_draw; int table_id; int last_row; } FeatVisitData; /*-----------------------Function Prototypes--------------------------------*/ ProError UserPointVisitAction(); ProError UserFeatVisitAction (); ProError UserPointsAdd (); ProError UserRowAdd (); /*================================================================*\ Function that creates a table of datum points \*================================================================*/ ProError UserTableCreate() { int status; ProMdl p_draw, p_model; Pro_Draw_Table table; int button, table_id, first_view; Pro_object_info info; ProCharLine line; ProCharName name; ProCharName type; ProFileName WMSGFIL = {'m','s','g','_','u','g','d','w','g','.','t','x','t','\0'}; /*------------------------------------------------------------*\ Get the current model \*------------------------------------------------------------*/ status = ProMdlCurrentGet(&p_draw); ERROR_CHECK("UserTableCreate","ProMdlCurrentGet",status); if (status != PRO_TK_NO_ERROR) return(status); /*------------------------------------------------------------*\ Get the pointer to the first model in the drawing. \*------------------------------------------------------------*/ first_view = prodrw_get_first_view_id ( p_draw); ERROR_CHECK("UserTableCreate","prodrw_get_first_view_id", (first_view < 0)); if (first_view < 0) return (PRO_TK_E_NOT_FOUND); p_model = prodrw_get_view_model ((Prohandle) p_draw, first_view); /*------------------------------------------------------------*\ Ask the user to position the table. \*------------------------------------------------------------*/ status = UserPickPosition (WMSGFIL,"Pick upper left corner of table", table.origin); ERROR_CHECK("UserTableCreate","UserPickPosition",status); if (status != PRO_TK_NO_ERROR) return(status); /*------------------------------------------------------------*\ Number of rows and columns \*------------------------------------------------------------*/ table.ncols = 5; table.nrows = 2; /*------------------------------------------------------------*\ Set the text justification to CENTER. \*------------------------------------------------------------*/ table.justify[0] = 0; table.justify[1] = 0; table.justify[2] = 0; table.justify[3] = 0; table.justify[4] = 0; /*------------------------------------------------------------*\ Set the row height and width to be specified in numbers of characters. \*------------------------------------------------------------*/ table.col_row_type = PRO_INTEGER_TYPE; /*------------------------------------------------------------*\ Set the column widths. \*------------------------------------------------------------*/ table.col_width[0] = 6; table.col_width[1] = 6; table.col_width[2] = 10; table.col_width[3] = 10; table.col_width[4] = 10; /*------------------------------------------------------------*\ Set the row heights. \*------------------------------------------------------------*/ table.row_height[0] = 2; table.row_height[1] = 1; /*------------------------------------------------------------*\ Create the table. \*------------------------------------------------------------*/ table_id = prodrw_create_table ((Prohandle) p_draw, &table, PRO_B_TRUE); ERROR_CHECK("UserTableCreate","prodrw_create_table",(table_id<0)); if (table_id<0) return (PRO_TK_GENERAL_ERROR); /*------------------------------------------------------------*\ Merge all the cells in the top row. \*------------------------------------------------------------*/ status = prodrw_merge_table_cells ((Prohandle) p_draw, table_id, 1, 1, 1, 5, PRO_B_TRUE); ERROR_CHECK("UserTableCreate","prodrw_merge_table_cells",(status<0)); if (status<0) return (PRO_TK_GENERAL_ERROR); /*------------------------------------------------------------*\ Put the heading in the top row: Datum Points Model : \*------------------------------------------------------------*/ ProStringToWstring (line1, "Datum Points"); prodb_get_object_info (p_model, &info); ProWstringToString (name, info.name); ProWstringToString (type, info.type); sprintf (line, "Model : %s.%s", name, type); ProStringToWstring (line2, line); prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 1, 1, 2, line_array); /*------------------------------------------------------------*\ Put headings in the second row: Feat Name X Y Z \*------------------------------------------------------------*/ ProStringToWstring (line1, "Feat"); prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 1, 2, 1, line_array); ProStringToWstring (line1, "Name"); prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 2, 2, 1, line_array); ProStringToWstring (line1, "X"); prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 3, 2, 1, line_array); ProStringToWstring (line1, "Y"); prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 4, 2, 1, line_array); ProStringToWstring (line1, "Z"); prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 5, 2, 1, line_array); /*------------------------------------------------------------*\ Add rows describing the datum points in the model. \*------------------------------------------------------------*/ status = UserPointsAdd ((Prohandle) p_draw, (Prohandle) p_model, table_id); ERROR_CHECK("UserTableCreate","UserPointsList",status); return (status); } /*================================================================*\ Function that adds datums points in a specified model to a specified drawing table \*================================================================*/ ProError UserPointsAdd ( ProMdl p_draw, ProMdl p_model, int table_id) { int status; int n_feats, *feats,f, n_pnts,p, *pnts; int last_row; ProName wname; double xyz[3]; last_row = 2; /*-------------------------------------------------------------*\ For each feature in the model... \*-------------------------------------------------------------*/ n_feats = prodb_get_feature_ids ((Prohandle) p_model, PRO_REGULAR_FEATURE, &feats); ERROR_CHECK("UserPointsAdd","prodb_get_feature_ids",(n_feats <0)); if (n_feats <0) return(PRO_TK_E_NOT_FOUND); for (f = 0; f < n_feats; f++) { /*--------------------------------------------------------*\ For each datum point in the feature... \*--------------------------------------------------------*/ n_pnts = prodb_get_feature_dtm_points ((Prohandle) p_model, feats[f], &pnts); ERROR_CHECK("UserPointsAdd","prodb_get_feature_dtm_points", (n_feats <0)); if (n_pnts<0) return(PRO_TK_E_NOT_FOUND); for (p = 0; p < n_pnts; p++) { /*----------------------------------------------------*\ Get the name of the datum point. \*----------------------------------------------------*/ status = prodb_get_element_name ((Prohandle) p_model, SEL_3D_PNT, pnts[p], wname); ERROR_CHECK("UserPointsAdd","prodb_get_element_name", (status <0)); if (status <0) return(PRO_TK_GENERAL_ERROR); /*----------------------------------------------------*\ Get the position of the datum point. \*----------------------------------------------------*/ status = prodb_eval_xyz_dtm_point ((Prohandle) p_model, pnts[p], xyz); ERROR_CHECK("UserPointsAdd","prodb_eval_xyz_dtm_point", (status <0)); if (status <0) return(PRO_TK_GENERAL_ERROR); /*----------------------------------------------------*\ If this is the first in the feature, just add the description to the row. \*----------------------------------------------------*/ if (p==0) { status = UserRowAdd ((Prohandle) p_draw, table_id, last_row, feats[f], wname, xyz); ERROR_CHECK("UserPointsAdd","UserRowAdd",status); } /*----------------------------------------------------*\ Otherwise, add the description, but with no feature identifier, and merge the first cell in this row with the cell above. \*----------------------------------------------------*/ else { UserRowAdd ((Prohandle) p_draw, table_id, last_row, -1, wname, xyz); ERROR_CHECK("UserPointsAdd","UserRowAdd",status); prodrw_merge_table_cells ((Prohandle) p_draw, table_id, last_row-p+1, 1, last_row+1, 1, PRO_B_TRUE); } last_row++; } } return (PRO_TK_NO_ERROR); } /*================================================================*\ Function to add a new table row for a specified datum point \*================================================================*/ ProError UserRowAdd ( ProMdl p_draw, int table_id, int last_row, int feature, ProName wname, ProPoint3d pos) { int status; ProCharLine str; /*------------------------------------------------------------*\ Add an empty row after the last row. \*------------------------------------------------------------*/ status = prodrw_add_table_row ((Prohandle) p_draw, table_id, last_row++, 1.0, PRO_B_TRUE); ERROR_CHECK("UserRowAdd","prodrw_add_table_row",(status == 0)); if (status == 0) return (PRO_TK_GENERAL_ERROR); /*----------------------------------------------------------------*\ If a feature identifier is specified, write it to the first column. \*----------------------------------------------------------------*/ if (feature > -1) { sprintf (str, "%d", feature); ProStringToWstring (line1, str); status = prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 1, last_row, 1, line_array); ERROR_CHECK("UserRowAdd","prodrw_write_cell_in_table",(status == 0)); if (status == 0) return (PRO_TK_GENERAL_ERROR); } /*------------------------------------------------------------*\ Write the datum point id to the first column. \*------------------------------------------------------------*/ memcpy (line1, wname, 80 * sizeof (wchar_t)); status = prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 2, last_row, 1, line_array); ERROR_CHECK("UserRowAdd","prodrw_write_cell_in_table",(status == 0)); if (status == 0) return (PRO_TK_GENERAL_ERROR); /*------------------------------------------------------------*\ Write the X, Y, and Z coordinates to the second, third, and fourth columns. \*------------------------------------------------------------*/ sprintf (str, "%5.3f", pos[0]); ProStringToWstring (line1, str); status = prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 3, last_row, 1, line_array); ERROR_CHECK("UserRowAdd","prodrw_write_cell_in_table",(status == 0)); if (status == 0) return (PRO_TK_GENERAL_ERROR); sprintf (str, "%5.3f", pos[1]); ProStringToWstring (line1, str); status = prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 4, last_row, 1, line_array); ERROR_CHECK("UserRowAdd","prodrw_write_cell_in_table",(status == 0)); if (status == 0) return (PRO_TK_GENERAL_ERROR); sprintf (str, "%5.3f", pos[2]); ProStringToWstring (line1, str); status = prodrw_write_cell_in_table ((Prohandle) p_draw, table_id, 5, last_row, 1, line_array); ERROR_CHECK("UserRowAdd","prodrw_write_cell_in_table",(status == 0)); if (status == 0) return (PRO_TK_GENERAL_ERROR); return (PRO_TK_NO_ERROR); }