/*****************************************************************************\ FILE : UgSymbDefCreate.c PURPOSE : Pro/TOOLKIT User Guide Example - creation of symbol definition 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 /*---------------------------Function Prototypes-----------------------------*/ Prodtl_note * UserFreeNoteSetup(); Prodtl_entity * UserLineSetup (); ProError UserSymbDefItemAdd (); /*================================================================*\ Function that programmatically adds a symbol definition to the drawing \*================================================================*/ ProError UserSymbDefCreate() { int status; ProMdl p_draw; int symdef_id; double pos[3], end1[3], end2[3]; Prodtl_note *p_note; Prodtl_entity *p_line; ProFileName WMSGFIL = {'m','s','g','_','u','g','d','w','g','.','t','x','t','\0'}; /*------------------------------------------------------------*\ Get the current model \*------------------------------------------------------------*/ status = ProMdlCurrentGet(&p_draw); ERROR_CHECK("UserSymbDefCreate","ProMdlCurrentGet",status); if (status != PRO_TK_NO_ERROR) return (status); /*------------------------------------------------------------*\ Create a dummy symbol definition called EXAMPLE, and gets its identifier. \*------------------------------------------------------------*/ symdef_id = UserDefinitionCreate (p_draw, "EXAMPLE"); ERROR_CHECK("UserSymbDefCreate","UserDefinitionCreate",(symdef_id<0)); if (symdef_id<0) return (PRO_TK_GENERAL_ERROR); /*------------------------------------------------------------*\ Set up a structure for a note at the center or the symbol, and center justify it. \*------------------------------------------------------------*/ pos[0] = pos[1] = pos[2] =0.0; p_note = UserFreeNoteSetup (p_draw, pos, "EXAMPLE", 0, NULL); p_note->attributes ^= PRODTL_NOTE_H_JUSTIF_CENTER; /*------------------------------------------------------------*\ Add the note to the symbol. \*------------------------------------------------------------*/ status = UserSymbDefItemAdd (p_draw, symdef_id, (Prodtl_item*)p_note); ERROR_CHECK("UserSymbDefCreate","UserSymbDefItemAdd",(status<0)); if (status != PRO_TK_NO_ERROR) return (status); /*------------------------------------------------------------*\ Set up a structure for a line. \*------------------------------------------------------------*/ end1[0] = end1[1] = end1[2] = 0.0; end2[0] = end2[1] = end2[2] = 0.0; end1[1] = end2[1]= -10.0; end1[0] = -40.0; end2[0] = 40.0; p_line = UserLineSetup (p_draw, end1, end2); /*------------------------------------------------------------*\ Add the line to the symbol. \*------------------------------------------------------------*/ status = UserSymbDefItemAdd (p_draw, symdef_id, (Prodtl_item*)p_line); ERROR_CHECK("UserSymbDefCreate","UserSymbDefItemAdd",(status<0)); if (status<0) return (PRO_TK_GENERAL_ERROR); return (PRO_TK_NO_ERROR); } /*================================================================*\ Function that sets up a dummy symbol definition with the specified name \*================================================================*/ int UserDefinitionCreate ( ProMdl p_draw, ProCharName name) { Prodtl_sym_def *p_symdef; /*------------------------------------------------------------*\ Claim and initialize the C structure. \*------------------------------------------------------------*/ p_symdef = (Prodtl_sym_def*) calloc (1, sizeof(Prodtl_sym_def)); p_symdef->type = PRODTL_SYM_DEFINITION; p_symdef->id = -1; p_symdef->attributes = PRODTL_SYM_DEF_HGT_FIXED; p_symdef->ref_text_ent_id = -1; p_symdef->ref_text_line = -1; p_symdef->ref_text_index = -1; /*------------------------------------------------------------*\ Set the name. \*------------------------------------------------------------*/ p_symdef->name_and_path_size = 1; ProStringToWstring (p_symdef->name_and_path[0], name); /*------------------------------------------------------------*\ Set the attachment type to be FREE. \*------------------------------------------------------------*/ p_symdef->n_attaches = 1; p_symdef->attach_array[0].type = PRODTL_SYM_DEF_ATT_FREE; p_symdef->attach_array[0].point[0] = 0.0; p_symdef->attach_array[0].point[1] = 0.0; p_symdef->attach_array[0].point[2] = 0.0; /*------------------------------------------------------------*\ Create the symbol definition. \*------------------------------------------------------------*/ return (prodtl_create ((Prohandle) p_draw, NULL, (Prodtl_item*)p_symdef)); } /*================================================================*\ Function that adds a given detail item to a specified symbol definition \*================================================================*/ ProError UserSymbDefItemAdd ( ProMdl p_draw, int symdef_id, Prodtl_item *p_item) { int status; int dtlitem_id; Prodtl_item *p_symdef; /*------------------------------------------------------------*\ Get a pointer to the symbol definition. \*------------------------------------------------------------*/ status = prodtl_get_item ((Prohandle) p_draw, NULL, PRODTL_SYM_DEFINITION, symdef_id, 0, &p_symdef); ERROR_CHECK("UserSymbDefItemAdd","prodtl_get_item",(status <0)); if (status < 0) return (status); /*------------------------------------------------------------*\ Add the item to it. \*------------------------------------------------------------*/ dtlitem_id = prodtl_create ((Prohandle)p_draw, p_symdef, p_item); ERROR_CHECK("UserSymbDefItemAdd","prodtl_create",(dtlitem_id <0)); if (dtlitem_id <0) return (PRO_TK_GENERAL_ERROR); return (PRO_TK_NO_ERROR); }