/******************************************************************************
             Copyright (c) 1999 Unigraphics Solutions, Inc.
TEXT ENCLOSED within delete markers will be REMOVED @<DEL>@

*******************************************************************************/
/*

The following example requires an open, blank part. The code
creates a block and a rectangular slot.  The code then changes the
retangular slot to a ball end slot.  The the code adds thru faces to the
slot.

*/

#include <stdio.h>
#include <uf_modl.h>
#include <uf.h>
#include <uf_curve.h>
#include <uf_csys.h>
#include <uf_defs.h>
#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
static int report( char *file, int line, char *call, int irc)
{
    if (irc)
    {
        char    messg[133];
        printf("%s, line %d:  %s\n", file, line, call);
        (UF_get_fail_message(irc, messg)) ?
            printf("    returned a %d\n", irc) :
            printf("    returned error %d:  %s\n", irc, messg);
    }
    return(irc);
}
static void do_ugopen_api(void)
{
  tag_t block_tag, placement_face, thru_face1 = NULL_TAG,
thru_face2 = NULL_TAG, slot_feature;
  tag_t new_thru_faces[2];
  double origin[3]={0.0,0.0,0.0};
  double x_direction[3]={1.0,0.0,0.0};
  double direction[3]={0.0,0.0,1.0};
  double location[3]={150,12.5,150};
  int num_faces = 2;
  char *edge_lens[3]={"300.0","25.0","150.0"};
  char *width="1.0";
  char *depth="5.0";
  char *distance="2.0";
  UF_MODL_slot_type_e_t new_slot_type = UF_BALL_END_SLOT;
  uf_list_p_t uflist;
  /* Create a block and put a retangular slot in it. */
  UF_CALL(UF_MODL_create_block1(UF_NULLSIGN,
                                origin,
                                edge_lens,
                                &block_tag));
  UF_CALL(UF_MODL_create_list(&uflist));
  UF_CALL(UF_MODL_ask_feat_faces(block_tag,
                                 &uflist));
  UF_CALL(UF_MODL_ask_list_item(uflist,
                                0,
                                &placement_face));
  UF_CALL(UF_MODL_ask_list_item(uflist,
                                2,
                                &new_thru_faces[0]));
  UF_CALL(UF_MODL_ask_list_item(uflist,
                                5,
                                &new_thru_faces[1]));
  UF_MODL_delete_list(&uflist);
  UF_CALL(UF_MODL_create_rect_slot(location,
                                   direction,
                                   x_direction,
                                   width,
                                   depth,
                                   distance,
                                   placement_face,
                                   thru_face1,
                                   thru_face2,
                                   &slot_feature));
  /* Change the slot from a retangular to ball end. */
  if(UF_CALL(UF_MODL_edit_slot_type(slot_feature,
                                    new_slot_type)))
  {
     /* error check */
  }
  /* Add thru faces. */
  if(UF_CALL(UF_MODL_add_thru_faces(slot_feature,
                                    num_faces,
                                    new_thru_faces)))
  {
     /* error check */
  }
  /* Trigger update */
  if(UF_CALL(UF_MODL_update()))
  {
     /* error check */
  }
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
    if (!UF_CALL(UF_initialize()))
    {
        do_ugopen_api();
        UF_CALL(UF_terminate());
    }
}
int ufusr_ask_unload(void)
{
    return (UF_UNLOAD_IMMEDIATELY);
}

