/*****************************************************************************\ FILE : UgSymbInstCreate.c PURPOSE : Pro/TOOLKIT User Guide Example - create a symbol instance 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 that adds a symbol instance to the drawing, and displays it \*================================================================*/ ProError UserInstanceCreate ( ProMdl p_draw, Prodtl_sym_inst *p_inst) { int status; int id; id = prodtl_create ((Prohandle)p_draw, NULL, (Prodtl_item*)p_inst); ERROR_CHECK("UserInstaceCreate","prodtl_create",(id < 0)); if (id < 0) return (PRO_TK_GENERAL_ERROR); status = prodtl_display ((Prohandle)p_draw, PRODTL_SYM_INSTANCE, id, PRODTL_SHOW); ERROR_CHECK("UserInstaceCreate","prodtl_display",(status < 0)); if (status <= 0) return(PRO_TK_GENERAL_ERROR); return (PRO_TK_NO_ERROR); } /*================================================================*\ Function that returns the pointer of a drawing view, given its identifier \*================================================================*/ char *UserViewGet ( ProMdl p_draw, int view_id) { Object_element subject, *refs; subject.type = SEL_VIEW_ENTITY; subject.ptr = NULL; subject.id = view_id; if (pro_element_info ((Prohandle) p_draw, &subject, PRO_IDENTIFY, -1, &refs) < 1) return (NULL); return (refs[0].ptr); } /*================================================================*\ Function that builds the data structure for a symbol instance with FREE attachment (at a specified screen coordinate) \*================================================================*/ Prodtl_sym_inst *UserInstanceSetup ( ProMdl p_draw, int symdef_id, double pos[]) { int view_id; int sheet_num; Prodtl_sym_inst *p_inst; p_inst = (Prodtl_sym_inst*) calloc (1, sizeof(Prodtl_sym_inst)); p_inst->type = PRODTL_SYM_INSTANCE; p_inst->id = -1; p_inst->attributes = PRODTL_SYM_INST_DISPLAYED; p_inst->color.type = PTC_COLOR_DEFAULT; p_inst->definition_id = symdef_id; p_inst->attach_on_def_type = PRODTL_SYM_DEF_ATT_FREE; /*------------------------------------------------------------*\ Set the attachment to be FREE. \*------------------------------------------------------------*/ p_inst->leader.text_attach.type = PRODTL_ATT_TYPE_FREE; /*------------------------------------------------------------*\ Set the view to be the OVERLAY view (the main one for the sheet). \*------------------------------------------------------------*/ sheet_num = prodrw_get_current_sheet((Prohandle) p_draw); ERROR_CHECK("UserInstanceSetup","prodrw_get_current_sheet", (sheet_num <0)); view_id = prodrw_get_overlay_view_id((Prohandle) p_draw, sheet_num); ERROR_CHECK("UserInstanceSetup","prodrw_get_overlay_view_id",(view_id<0)); p_inst->leader.text_attach.att_geom.view_ptr = UserViewGet (p_draw, view_id); /*------------------------------------------------------------*\ Set the position, in screen coordinates. \*------------------------------------------------------------*/ ProUtilVectorCopy (pos, p_inst->leader.text_attach.att_geom.select_pnt); return (p_inst); } /*================================================================*\ Function that gets the identifier of the symbol definition for a given symbol instance. \*================================================================*/ int UserDefinitionIDGet ( ProMdl p_draw, int inst_id) { Prodtl_sym_inst *p_inst; if (prodtl_get_item ((Prohandle) p_draw, NULL, PRODTL_SYM_INSTANCE, inst_id, 0, (Prodtl_item**) &p_inst) < 0) return (-1); return (p_inst->definition_id); } /*================================================================*\ Function that copies a selected symbol instance to a new (free) instance \*================================================================*/ ProError UserSymbInstCopy() { int status; ProMdl p_draw; int defn_id; Select3d *sel; ProPoint3d pos; Prodtl_sym_inst *p_inst; ProFileName WMSGFIL = {'m','s','g','_','u','g','d','w','g','.','t','x','t','\0'}; /*------------------------------------------------------------*\ Get the current model \*------------------------------------------------------------*/ status = ProMdlCurrentGet(&p_draw); ERROR_CHECK("UserSymbInstCopy","ProMdlCurrentGet",status); if (status != PRO_TK_NO_ERROR) return(status); /*------------------------------------------------------------*\ Select a symbol instance. \*------------------------------------------------------------*/ ProMessageDisplay(WMSGFIL, "USER %0s", "Select a symbol instance"); while (pro_select ("dtl_symbol", 1, &sel, NULL, NULL)) { /*--------------------------------------------------------*\ Get the identifier of the corresponding symbol definition. \*--------------------------------------------------------*/ defn_id = UserDefinitionIDGet (p_draw, sel[0].selected_id); ERROR_CHECK("UserSymbInstCopy","UserDefinitionIDGet", (defn_id < 0)); if (defn_id < 0) return (PRO_TK_GENERAL_ERROR); /*--------------------------------------------------------*\ Get the position for the new instance. \*--------------------------------------------------------*/ status = UserPickPosition(WMSGFIL, "Pick the position of the new instance.", pos); ERROR_CHECK("UserSymbInstCopy","UserPickPosition",status); if (status != PRO_TK_NO_ERROR) return(status); /*--------------------------------------------------------*\ Set up the data structure for the new symbol instance. \*--------------------------------------------------------*/ p_inst = UserInstanceSetup (p_draw, defn_id, pos); /*--------------------------------------------------------*\ Add it to the drawing and display it. \*--------------------------------------------------------*/ status = UserInstanceCreate (p_draw, p_inst); ERROR_CHECK("UserSymbInstCopy","UserInstanceCreate",status); if (status != PRO_TK_NO_ERROR) return (status); } return (PRO_TK_NO_ERROR); }