int Key_K_CB( Togl *togl, int argc, const char *argv[] ) { if( dh == DRAW_HIERARCHY ) { if( which_pieces.Length() != 1 ) { // Go up the hierarchy int i; SWIFT_Array<SWIFT_BV*> new_which_pieces( which_pieces.Length() ); SWIFT_BV* parent; new_which_pieces.Set_Length( 0 ); parent = NULL; for( i = 0; i < which_pieces.Length(); i++ ) { if( uleaves && which_pieces[i]->Is_Leaf() && which_pieces[i]->Level() < level ) { new_which_pieces.Add( which_pieces[i] ); } else if( parent != which_pieces[i]->Parent() ) { parent = which_pieces[i]->Parent(); new_which_pieces.Add( parent ); } } level--; // Include the new leaves at this level if uleaves is false if( !uleaves ) { for( i = 0; i < num_leaves; i++ ) { if( leaves[i]->Level() == level ) { new_which_pieces.Add_Grow( leaves[i], 10 ); } } } which_pieces.Destroy(); which_pieces = new_which_pieces; new_which_pieces.Nullify(); } } else { // Show next convex piece and set text field char temp[80]; if( which_cps.Length() == 0 ) { which_cps.Set_Length( 1 ); which_cps[0] = 0; } else { which_cps[0] = (which_cps[0] == which_cps.Max_Length()-1 ? 0 : which_cps[0]+1); which_cps.Set_Length( 1 ); } sprintf( temp, "set which_cps %d", which_cps[0] ); Tcl_Eval( Togl_Interp( togl ), temp ); } Togl_PostRedisplay( togl ); return TCL_OK; }
int Key_J_CB( Togl *togl, int argc, const char *argv[] ) { if( dh == DRAW_HIERARCHY ) { int i, j; bool advanced = false; SWIFT_Array<SWIFT_BV*> new_which_pieces( 100 ); new_which_pieces.Set_Length( 0 ); for( i = 0; i < which_pieces.Length(); i++ ) { if( uleaves && which_pieces[i]->Is_Leaf() ) { // Keep this leaf new_which_pieces.Add_Grow( which_pieces[i], 10 ); } else { for( j = 0; j < which_pieces[i]->Num_Children(); j++ ) { new_which_pieces.Add_Grow( which_pieces[i]->Children()[j], 10 ); advanced = true; } } } if( advanced ) { level++; which_pieces.Destroy(); which_pieces = new_which_pieces; new_which_pieces.Nullify(); } } else { // Show previous convex piece and set text field char temp[80]; if( which_cps.Length() == 0 ) { which_cps.Set_Length( 1 ); which_cps[0] = 0; } else { which_cps[0] = (which_cps[0] == 0 ? which_cps.Max_Length()-1 : which_cps[0]-1); which_cps.Set_Length( 1 ); } sprintf( temp, "set which_cps %d", which_cps[0] ); Tcl_Eval( Togl_Interp( togl ), temp ); } Togl_PostRedisplay( togl ); return TCL_OK; }
int Convex_Pieces_CB( Togl *togl, int argc, const char *argv[] ) { if( argv[2][0] == 'A' || argv[2][0] == 'a' ) { // Want to draw all pieces int i; which_cps.Set_Length( which_cps.Max_Length() ); for( i = 0; i < which_cps.Length(); i++ ) { which_cps[i] = i; } } else { // Parse the string to determine which ones to draw long upper, lower; const char* str = argv[2]; char* endp; int i; SWIFT_Array<int> which_cps_back = which_cps; which_cps.Set_Length( 0 ); while( *str != '\0' && which_cps.Length() != which_cps.Max_Length() ) { if( isdigit( *str ) ) { // Read the next segment lower = strtol( str, &endp, 10 ); str = endp; if( lower < 0 ) { lower = 0; } if( lower >= which_cps.Max_Length() ) { lower = which_cps.Max_Length()-1; } upper = lower; if( *str == '-' ) { str++; if( isdigit( *str ) ) { upper = strtol( str, &endp, 10 ); str = endp; if( upper < 0 ) { upper = 0; } if( upper >= which_cps.Max_Length() ) { upper = which_cps.Max_Length()-1; } if( upper < lower ) { int j = lower; lower = upper; upper = j; } } else { cerr << "Error: Expecting number after '-'" << endl; which_cps = which_cps_back; break; } } // Save the segment for( i = lower; i <= upper && which_cps.Length() != which_cps.Max_Length(); i++ ) { which_cps.Add( i ); } // Done this segment if( *str == ',' ) { str++; } else { // Assume that we found the end of the list break; } } else { break; } } } Togl_PostRedisplay( t ); return TCL_OK; }