Overview

The step2iges application is a simple wrapper around the igeslib library. The source code below shows the basic structure of the program.

#include <igeslib.h>

static void usage (const char * name) 
{  
    fprintf (stderr, "Usage: %s [options] <stpfile>\n", name);
    exit (1);
}


#define NEXT_ARG(i,argc,argv) ((i<argc)? argv[i++]: 0)

int main (int argc, char ** argv)
{
    int i=1;
    int write_defaults = 1;
    char * outfile = 0;
    char * arg;

    ROSE.quiet(1);
 
    igeslib_force_load();
    igeslib_create_builtin_schemas();

    /* must have at least two args */
    if (argc < 2) usage(argv[0]);

    /* get remaining keyword arguments */
    while ((arg=NEXT_ARG(i,argc,argv)) != 0)
    {
	/* command line options */
 	if (!strcmp (arg, "-o")) 
	{	
	    outfile = NEXT_ARG(i,argc,argv);
	    if (!outfile) {
		fprintf (stderr, "option: -o <file>\n");
		exit (1);
	    }
	}
	else if (!strcmp (arg, "-nonulls")) 
	{	
	    write_defaults = 0;
	}

	else break;
    }

    if (!arg) {
	fprintf (stderr, "ERROR: missing input file name\n");
	usage(argv[0]);
    }

    while (arg)
    {
	// STEP to IGES
	//RoseDesign * d = ROSE.findDesign(arg);
	RoseDesign * d = ROSE.useDesign(arg);
	RoseCursor objs;
	if (!d) {
	    return 0;
	}

	objs.traverse(d);
	objs.domain(ROSE_DOMAIN(igs_iges_file));

	igs_iges_file * f = ROSE_CAST(igs_iges_file,objs.next());
	if (!f) f = pnewIn(d) igs_iges_file;

	if (outfile && *outfile)
	{
	    // use path given by user
	    f->write(outfile, write_defaults);
	}
	else
	{
	    // Do current directory, same as the other direction
	    RoseStringObject igsname (
		rose_expand_path (0, d->name(), "igs")
		);

	    f->write(igsname, write_defaults);
	}

	outfile = 0;  /* only save the first as outfile */
	arg = NEXT_ARG(i,argc,argv);
    }

    return 0;
}