Graphics.UsingTheDougSceneCommand - lordmundi/wikidoctest GitHub Wiki

Using the Scene Tcl Commands

« Using the doug display command | EDGE User’s Guide | Using the doug view command »

EDGE provides an extensive tcl scripting ability to DSP.

The doug.scene command can be used to manipulate or query elements in a scene, such as retrieving a list of lights.

Simple Directions

The doug.scene commands are best explained via examples. The following example commands should illustrate most of the usage:

doug.scene get -cameras -match search_str
doug.scene get -cameras -nomatch search_str
doug.scene get -models 
doug.scene get -lights 
doug.scene get -systems
doug.scene get -controls
doug.scene get -mapper
doug.scene get -nodes 
doug.scene get -nodes -nosort
doug.scene get -cameras -models -match search_str 
doug.scene get -cameras -models -match_case search_str 
doug.scene get -modified (returns all nodes that have changed since the last 'doug.scene sync' call)
doug.scene sync

What's really going on

If the above examples are not enough info, or you need more information about a particular option, the source code implementing the doug.scene command is below:

[Show DOUG_SCENE_cmd source code][4]

int
DOUG_SCENE_cmd( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] )
{
#if 0
doug.scene get -cameras -match search_str
doug.scene get -cameras -nomatch search_str
doug.scene get -models 
doug.scene get -lights 
doug.scene get -systems
doug.scene get -controls
doug.scene get -mapper
doug.scene get -nodes 
doug.scene get -nodes -nosort
doug.scene get -cameras -models -match search_str 
doug.scene get -cameras -models -match_case search_str 
doug.scene get -modified (returns all nodes that have changed since the last 'doug.scene sync' call)

doug.scene sync

/* NOT DONE */
doug.scene get -flags
doug.scene set -flags "~WIRE"

#endif
    char *cmd;
    char *opt;
    int  i, j, k, num_find;
    int return_size;
    int match_types = 0;
    char match_str[200];
    char nomatch_str[200];
    int match_case = 0;
    int nomatch_case = 0;
	int nosort = 0;
	static int *name_lens = 0;
	static int *name_ids = 0;
	static char *match_list = 0;
	static int *sync_ids = 0;
	DSS_NODE *pn;

	if( !name_lens )
	{
		int max_ret = 0;
		name_lens = (int*)malloc( sizeof(int) * DSV_scene->node_count );
		name_ids = (int*)malloc( sizeof(int) * DSV_scene->node_count );

		/* DETERMINE STRLEN OF EACH NODE-NAME AND THE MAXIMUM SIZE THE RETURN STRING WOULD BE */
		for( i = 0; i < DSV_scene->node_count; i++ )
		{
			name_lens[i] = strlen(DSV_scene->node_list[i].name);
			max_ret += name_lens[i] + 1;
		}
		max_ret += 10;
		match_list = (char*)malloc( sizeof(char) * max_ret );
		sync_ids = (int*)malloc( sizeof(int) * DSV_scene->node_count );
		memset( sync_ids, 0, sizeof(int) * DSV_scene->node_count );
	}

    Tcl_ResetResult( interp );

    cmd = Tcl_GetString( objv[i=1] );
    i++;

    match_str[0] = 0;
    nomatch_str[0] = 0;
    if( !strcmp( cmd, "get" ) )
    {
        while( i < objc )
        {
            opt = Tcl_GetString( objv[i] );
            i++;

            if( !DSF_strcmpi( opt, "-flags" ) )
            {
                /* NOT DONE */
            }
            else if( !DSF_strcmpi( opt, "-cameras" ) )
            {
                match_types |= DSD_IS_CAMERA;
            }
			else if( !DSF_strcmpi( opt, "-modified" ) )
			{
				match_list[0] = 0;
				pn = DSV_scene->node_list;
				for( k = j = 0; j < DSV_scene->node_count; j++, pn++ )
				{
					if( DSV_scene->processed_id[j] != sync_ids[j] )
					{
						strcpy( match_list+k, pn->name );
						k += name_lens[j];
						match_list[k] = ' '; k += 1;
					}
				}
				if( k )
					match_list[k-1] = 0;
				Tcl_SetResult( interp, match_list, TCL_VOLATILE );
			}
            else if( !DSF_strcmpi( opt, "-lights" ) )
            {
                match_types |= DSD_IS_LIGHT;
            }
            else if( !DSF_strcmpi( opt, "-models" ) )
            {
                match_types |= DSD_IS_MODEL;
            }
            else if( !DSF_strcmpi( opt, "-systems" ) )
            {
                match_types |= DSD_IS_SYSTEM;
            }
            else if( !DSF_strcmpi( opt, "-controls" ) )
            {
                match_types |= DSD_IS_CONTROL;
            }
            else if( !DSF_strcmpi( opt, "-nodes" ) )
            {
                match_types |= DSD_IS_CAMERA | DSD_IS_MODEL | DSD_IS_SYSTEM | DSD_IS_LIGHT | DSD_IS_CONTROL;
            }
			else if( !DSF_strcmpi( opt, "-nosort" ) )
			{
				nosort = 1;
			}
            else if( !DSF_strcmpi( opt, "-match" ) )
            {
                strcpy( match_str, Tcl_GetString( objv[i] ) );
                for( j = 0; j < strlen(match_str); j++ )
                    match_str[j] = toupper(match_str[j]);
                i++;
            }
            else if( !DSF_strcmpi( opt, "-nomatch" ) )
            {
                strcpy( nomatch_str, Tcl_GetString( objv[i] ) );
                for( j = 0; j < strlen(nomatch_str); j++ )
                    nomatch_str[j] = toupper(nomatch_str[j]);
                i++;
            }
            else if( !DSF_strcmpi( opt, "-match_case" ) )
            {
                match_case = 1;
                strcpy( match_str, Tcl_GetString( objv[i] ) );
                i++;
            }
            else if( !DSF_strcmpi( opt, "-nomatch_case" ) )
            {
                nomatch_case = 1;
                strcpy( nomatch_str, Tcl_GetString( objv[i] ) );
                i++;
            }
        }

        if( match_types )
        {
            if( !match_case )
            {
                for( i = 0; i < strlen(match_str); i++ )
                    match_str[i] = toupper( match_str[i] );
            }
            if( !nomatch_case )
            {
                for( i = 0; i < strlen(nomatch_str); i++ )
                    nomatch_str[i] = toupper( nomatch_str[i] );
            }
            for( num_find = j = 0; j < DSV_scene->node_count; j++ )
            {
                if( DSV_scene->node_list[j].type & match_types )
                {
                    if(  DOUG_match( match_str, match_case, DSV_scene->node_list[j].name )
                    &&  ((nomatch_str[0]==0) || !DOUG_match( nomatch_str, nomatch_case, DSV_scene->node_list[j].name )))
                    {
                        name_ids[num_find] = j;
                        num_find += 1;
                    }
                }
            }

            /* SORT ANY MATCHED NAMES AND RETURN */
			if( num_find && !nosort )
				qsort( name_ids, num_find, sizeof(int), MyNodeNameCmp );

			/* APPEND EACH NAME TO LIST */
            match_list[0] = 0;
            for( i = j = 0; j < num_find; j++ )
            {
				strcpy( match_list+i, DSV_scene->node_list[name_ids[j]].name );
				i += name_lens[name_ids[j]];
				match_list[i] = ' '; i += 1;
            }
			if( i )
				match_list[i-1] = 0;
            Tcl_SetResult( interp, match_list, TCL_VOLATILE );
        }
    }
	else if( !strcmp( cmd, "sync" ) )
	{
		for( j = 0; j < DSV_scene->node_count; j++ )
			sync_ids[j] = DSV_scene->processed_id[j];
	}
    return TCL_OK;
}

« Using the doug display command | EDGE User’s Guide | Using the doug view command »

[4]: javascript:toggleObj('togglecode_id0','hide','Show DOUG_SCENE_cmd source code','Show DOUG_SCENE_cmd source code','')