// Note: This file defaults to use as library routines. // With the proper #define it also has a sample main() #include #include #include #include #include #include #include #include #include #include "tcltk.h" #include "tkinventor.h" /*************************************************************************** T K S E N S O R C A L L B A C K ***************************************************************************/ static void tkSensorCallback(void *, SoSensor *) { // This is our inventor timer function. All it does is check for tk events. tcltk_checkEvents(); } // An inventor timer, that gets set to go off at regular intervals. // We use this timer to check for tk events. SoTimerSensor *tkinventor_timer=NULL; /*************************************************************************** T K I N V E N T O R _ O N ***************************************************************************/ void tkinventor_on(float interval) { // Create the timer if no one has done it yet. if (tkinventor_timer==NULL) tkinventor_timer=new SoTimerSensor(tkSensorCallback, NULL); // Did we change the frequency to check tk events? 0.0 flags no change if (interval>0) { tkinventor_timer->unschedule(); tkinventor_timer->setInterval(interval); } // Schedule the timer to be active tkinventor_timer->schedule(); } /*************************************************************************** T K I N V E N T O R _ O F F ***************************************************************************/ void tkinventor_off(void) { if (tkinventor_timer==NULL) tkinventor_timer=new SoTimerSensor(tkSensorCallback, NULL); // Temporarily turn off the inventor timer that check tk events tkinventor_timer->unschedule(); } #ifdef TKINVENTOR_MAIN SoMaterial *myMaterial = new SoMaterial; SoCone *myCone = new SoCone; // Some tcl callback commands int green(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { myMaterial->diffuseColor.setValue(0,1,0); return TCL_OK; } int blue(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { myMaterial->diffuseColor.setValue(0,0,1); return TCL_OK; } int red(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { myMaterial->diffuseColor.setValue(1,0,0); return TCL_OK; } int cone(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { if (argc>1) myCone->height.setValue(atof(argv[1])); return TCL_OK; } // The tcl interpretor created by tcltk_init() extern Tcl_Interp *tclInterp; /*************************************************************************** M A I N ***************************************************************************/ main(int, char **argv) { // Do inventor stuff to create a simple scene Widget myWindow = SoXt::init(argv[0]); if (myWindow == NULL) exit(1); SoSeparator *root = new SoSeparator; root->ref(); myMaterial->diffuseColor.setValue(1.,0.,0.); root->addChild(myMaterial); root->addChild(myCone); SoXtExaminerViewer *myViewer = new SoXtExaminerViewer(myWindow); myViewer->setSceneGraph(root); myViewer->setTitle("Examiner Viewer"); myViewer->show(); SoXt::show(myWindow); // Initialize tcl/tk tcltk_init(); // Turn on tk events within inventors event queue tkinventor_on(); // Create some custom tcl commands for our application Tcl_CreateCommand(tclInterp, "red", red, NULL, (void (*)(void *)) NULL); Tcl_CreateCommand(tclInterp, "green", green, NULL, (void (*)(void *)) NULL); Tcl_CreateCommand(tclInterp, "blue", blue, NULL, (void (*)(void *)) NULL); Tcl_CreateCommand(tclInterp, "cone", cone, NULL, (void (*)(void *)) NULL); // Enable tcl command line tcltk_enableTtyInput(); // Start the inventor main loop SoXt::mainLoop(); } #endif