/*****************************************************************************\ FILE : UgGroupCreate.c PURPOSE : Pro/TOOLKIT User Guide Example - Create a draft group HISTORY.. DATE BUILD AUTHOR MODIFICATIONS 04-Dec-97 H-02-02 Philippe $$1 Created \*****************************************************************************/ /*-------------------------- Pro/Develop includes ---------------------------*/ #include #include /*-------------------------- Pro/Toolkit includes ---------------------------*/ #include #include #include /*-------------------------- Application includes ---------------------------*/ #include /*-------------------------- Global Definitions ---------------------------*/ ProError UserGroupMake (); /*================================================================*\ FUNCTION : UserGroupCreate PURPOSE : Create a group draft entity - interface function \*================================================================*/ ProError UserGroupCreate() { int status; ProMdl p_draw; ProName wname; Select3d *items; int n_items; ProFileName WMSGFIL = {'m','s','g','_','u','g','d','w','g','.','t','x','t','\0'}; /*------------------------------------------------------------*\ Get the current model \*------------------------------------------------------------*/ status = ProMdlCurrentGet(&p_draw); ERROR_CHECK("UserViewCreate","ProMdlCurrentGet",status); /*------------------------------------------------------------*\ Get the group name from the user. \*------------------------------------------------------------*/ status = ProMessageDisplay(WMSGFIL, "USER %0s", "Enter group name [QUIT] : "); ERROR_CHECK("UserGroupCreate","ProMessageDisplay",status); status = ProMessageStringRead(PRO_NAME_SIZE, wname); ERROR_CHECK("UserGroupCreate","ProMessageStringRead",status); if (status != PRO_TK_NO_ERROR) return(status); /*------------------------------------------------------------*\ Ask the user to select notes and draft entities. \*------------------------------------------------------------*/ status = ProMessageDisplay (WMSGFIL, "USER %0s", "Select notes and entities for group"); ERROR_CHECK("UserGroupCreate","ProMessageDisplay",status); n_items = pro_select ("any_note,draft_ent", -1, &items, NULL, NULL); ERROR_CHECK("UserGroupCreate","pro_select",(n_items <= 0)); /*------------------------------------------------------------*\ Create the group if the user selected enough draft entities. \*------------------------------------------------------------*/ if (n_items < 0) return(PRO_TK_GENERAL_ERROR); else if (n_items == 0) return(PRO_TK_USER_ABORT); else if (n_items == 1) return(PRO_TK_NOT_VALID); status = UserGroupMake (p_draw, wname, n_items, items); ERROR_CHECK("UserGroupCreate","UserGroupMake", status); return (status); } /*================================================================*\ FUNCTION : UserGroupMake PURPOSE : Create a group draft entity - core function \*================================================================*/ ProError UserGroupMake ( ProMdl p_draw, ProName wname, int n_items, Select3d *items) { int status; int i, n_notes, n_ents, note_index, ent_index; Prodtl_group group; /*------------------------------------------------------------*\ Initialize the group C structure. \*------------------------------------------------------------*/ memset (&group, '\0', sizeof(Prodtl_group)); group.type = PRODTL_DRAFT_GROUP; group.id = -1; /*------------------------------------------------------------*\ Set the group name. \*------------------------------------------------------------*/ ProUtilWstrcpy (group.name, wname); /*------------------------------------------------------------*\ Find out how many notes and entities. \*------------------------------------------------------------*/ n_notes = n_ents = 0; for (i = 0; i < n_items; i++) { if (items[i].sel_type == DTL_USER_NOTE) n_notes++; else if (items[i].sel_type == DTL_DRAFT_ENT) n_ents++; } if ((n_notes==0) && (n_ents==0)) return (PRO_TK_NOT_VALID); /*------------------------------------------------------------*\ Claim the arrays for the entity identifiers, and set the array indexes to be used by notes and entities. \*------------------------------------------------------------*/ note_index = ent_index = 0; if (n_notes && n_ents) { group.n_elem_types = 2; group.group_elems =(Prodtl_group_elems*) calloc (2, sizeof(Prodtl_group_elems)); group.group_elems[0].type = PRODTL_NOTE; group.group_elems[0].ids = (int*) calloc (n_notes, sizeof(int)); group.group_elems[1].type = PRODTL_ENTITY; group.group_elems[1].ids = (int*) calloc (n_ents, sizeof(int)); ent_index = 1; } else { group.n_elem_types = 1; group.group_elems =(Prodtl_group_elems*) calloc (1, sizeof(Prodtl_group_elems)); if (n_notes) { group.group_elems[0].type = PRODTL_NOTE; group.group_elems[0].ids = (int*) calloc (n_notes, sizeof(int)); } else { group.group_elems[0].type = PRODTL_ENTITY; group.group_elems[0].ids = (int*) calloc (n_ents, sizeof(int)); } } /*------------------------------------------------------------*\ Copy the note and entity identifiers into the structure. \*------------------------------------------------------------*/ n_notes = n_ents = 0; for (i = 0; i < n_items; i++) { if (items[i].sel_type == DTL_USER_NOTE) { group.group_elems[note_index].ids[n_notes] = items[i].selected_id; group.group_elems[note_index].n_ids = ++n_notes; } else if (items[i].sel_type == DTL_DRAFT_ENT) { group.group_elems[ent_index].ids[n_ents] = items[i].selected_id; group.group_elems[ent_index].n_ids = ++n_ents; } } group.attributes = PRODTL_GROUP_DISPLAYED; /*----------------------------------------------------------------*\ Put the group into the drawing. \*----------------------------------------------------------------*/ status = prodtl_create ((Prohandle) p_draw, NULL, (Prodtl_item*)&group); ERROR_CHECK("UserGroupMake","prodtl_create",(status < 0)); if (status < 0) return(PRO_TK_GENERAL_ERROR); return(PRO_TK_NO_ERROR); }