/****************************************************************************** Copyright (c) 1999 Unigraphics Solutions, Inc. Unpublished - All Rights Reserved *******************************************************************************/ /* UFUN includes */ #include #include #include #include #include #include /* Xm includes */ #include static Widget quit_pb, selection_pb; /* Local Functions */ static void create_custom_dialog( void ); static Widget create_pulldown_menu( Widget parent, char *menu_title, char menu_mnemonic); static void selection_cb ( Widget w, XtPointer client_data, XtPointer call_data ); static void file_quit_cb( Widget w, XtPointer client_data, XtPointer call_data ); static void call_end_dialog ( XtPointer call_data, XtIntervalId *id ); static int initialize_uf( void ); static Widget main_window = NULL; /* Defines */ #define UFUN_INITIALIZED (0) #define UFUN_NOT_INITIALIZED (1) void ufusr ( char *param, int *ret, int len) { int rcode; if (initialize_uf() == UFUN_NOT_INITIALIZED) return; create_custom_dialog( ); rcode = UF_UI_lock_ug_access(UF_UI_FROM_CUSTOM); if (rcode != UF_UI_LOCK_SET) UF_UI_set_status("Could not lock UG\n"); /* Launch the custom application into Unigraphics' event loop */ UF_UI_run_dialog( main_window ); XtDestroyWidget(main_window); rcode = UF_UI_unlock_ug_access(UF_UI_FROM_CUSTOM); if (rcode != UF_UI_LOCK_SET) UF_UI_set_status("Could not unlock UG\n"); UF_terminate(); } /************************************************************ * Build the User Interface and start the program. *************************************************************/ static void create_custom_dialog( void ) { Widget top_level; Widget menu_bar, dialog_shell; Widget file_menu; Position x_pos = 0, y_pos = 0; Arg args[ 10 ]; int n; /* Get the top level */ top_level = (Widget)UF_UI_get_default_parent(); /* Create the dialog shell in a convenient position */ UF_UI_get_DA1_coords( &x_pos, &y_pos ); n = 0; XtSetArg( args[ n ], XmNx, x_pos + 100 ); n++; XtSetArg( args[ n ], XmNy, y_pos + 50); n++; dialog_shell = XmCreateDialogShell( top_level, "UF_UI_dismiss_dialog_area_2 ", args, n ); /* Create the main window */ main_window = XtVaCreateWidget( "main_window", xmMainWindowWidgetClass, dialog_shell, NULL ); /* Create the main menu bar on the custom dialog */ menu_bar = XmCreateMenuBar( main_window, "menu_bar", NULL, 0 ); XtManageChild( menu_bar ); /* Create the items in the menu bar */ file_menu = create_pulldown_menu( menu_bar, "File", 'F'); XtManageChild( file_menu ); } /**************************************************************** * This routine is used to build the menus for the custom * application. * * INPUTS: * parent - Must be a valid widget. * menu_title - Title to be displayed. * menu_mnemonic - Mnemonic which can be used to initiate the menu * item. * * RETURNS: * XmMENU_PULLDOWN - menu * ******************************************************************/ static Widget create_pulldown_menu( Widget parent, char *menu_title, char menu_mnemonic) { Widget menu, cascade; XmString str; /* Do some error checking */ if ( parent == NULL ) { XtWarning( "create_pulldown_menu() - Must have a non-NULL parent widget. \n" ); return NULL; } if ( !XtIsObject(parent) || !XtIsWidget(parent) ) { XtWarning( "create_pulldown_menu() - An invalid parent widget was passed .\n" ); return NULL; } menu = XmCreatePulldownMenu( parent, "_pulldown", NULL, 0 ); /* Pulldown menus require a cascade button parent */ str = XmStringCreateSimple( menu_title ); cascade = XtVaCreateManagedWidget( menu_title, xmCascadeButtonGadgetClass, parent, XmNsubMenuId, menu, XmNlabelString, str, XmNmnemonic, menu_mnemonic, NULL ); XmStringFree( str ); selection_pb = XtVaCreateManagedWidget( "Selection", xmPushButtonGadgetClass, menu, NULL ); XtAddCallback( selection_pb, XmNactivateCallback, selection_cb, 0 ); quit_pb = XtVaCreateManagedWidget( "Quit", xmPushButtonGadgetClass, menu, NULL ); XtAddCallback( quit_pb, XmNactivateCallback, file_quit_cb, 0 ); return cascade; } /************************************************************** * Quit the custom application. * This routine is called when File->Quit is selected. ***************************************************************/ static void file_quit_cb( Widget w, XtPointer client_data, XtPointer call_data ) { int rcode; rcode = UF_UI_cancel_uf_dialog(UF_UI_FROM_CUSTOM); if (rcode == UF_UI_FAILURE) UF_UI_set_status("Can't cancel the current DA2 dialog"); /* Normally we check for lock status prior to calling */ /* UF_UI_cancel_uf_dialog, but we locked UG at the */ /* start of this application. Therefore, we can't */ /* really tell if the user has a UG/Open dialog up or */ /* not. Therefore, we just call */ /* UF_UI_cancel_uf_dialog and then end the application */ XtAppAddTimeOut(XtWidgetToApplicationContext(main_window), 10, (XtTimerCallbackProc) call_end_dialog, (XtPointer) NULL); } static void call_end_dialog ( XtPointer call_data, XtIntervalId *id ) { int rcode; char msg[132]; rcode = UF_UI_exit_dialog(); if (rcode != UF_UI_SUCCESS) { UF_get_fail_message(rcode,msg); UF_UI_set_status(msg); } } /* This is the function called when the Selection item is */ /* selected from the pulldown. */ static void selection_cb ( Widget w, XtPointer client_data, XtPointer call_data ) { UF_UI_selection_options_t opts; UF_UI_mask_t mask[5]; int count; int rcode, response; tag_p_t curve_tag_p; opts.other_options = 0; opts.reserved = NULL; opts.num_mask_triples = 5; opts.scope = UF_UI_SEL_SCOPE_WORK_PART; opts.mask_triples = mask; mask[0].object_type = UF_spline_type; mask[0].object_subtype = 0; mask[0].solid_type = 0; mask[1].object_type = UF_line_type; mask[1].object_subtype = 0; mask[1].solid_type = 0; mask[2].object_type = UF_solid_type; mask[2].object_subtype = 0; mask[2].solid_type = UF_UI_SEL_FEATURE_ANY_EDGE; mask[3].object_type = UF_circle_type; mask[3].object_subtype = 0; mask[3].solid_type = 0; mask[4].object_type = UF_conic_type; mask[4].object_subtype = UF_conic_ellipse_subtype; mask[4].solid_type = 0; /* Grey out access to the pulldown item selection */ XtSetSensitive(selection_pb, FALSE); rcode = UF_UI_select_by_class("select Lines", &opts, &response, &count, &curve_tag_p); if (rcode != 0) { UF_UI_set_status("Not allowed to bring up dialog at this time"); return; } XtSetSensitive(selection_pb, TRUE); /* Inform Unigraphics that it can dismiss this UG/Open dialog.*/ /* Because the lock wrappers are at the beginning and end of */ /* this program, we must call UF_UI_dismiss_dialog_area_2 now */ /* or else if the user selects any of the navigation buttons */ /* this dialog remains displayed. */ UF_UI_dismiss_dialog_area_2(); /* Do some more processing */ } static int initialize_uf( void ) { int uf_is_initialized; int initialize_rcode; uf_is_initialized = UF_is_initialized(); if( uf_is_initialized == 0 ) { initialize_rcode = UF_initialize(); if( initialize_rcode != 0 ) { printf("Could not initialize User Function\n"); return (UFUN_NOT_INITIALIZED); } } return (UFUN_INITIALIZED); } int ufusr_ask_unload(void) { return ( UF_UNLOAD_SEL_DIALOG ); }