info-inventor
[Top] [All Lists]

Changing viewer ?

To: info-inventor@xxxxxxxxxxx
Subject: Changing viewer ?
From: Cyril ZEKSER <czekser@xxxxxxxxxxxxxx>
Date: Fri, 29 Dec 2000 13:57:09 +0100
Newsgroups: comp.graphics.api.inventor
Sender: owner-inventor@xxxxxxxxxxx
Hi all,

I want to change my viewer on the Fly, by pressing a key. I want to
switch from ExaminerViewer to FlyViewer.  But that doesn't seem to work.



-------------------------------------------------------------------------------------------------------------

Here's what I've coded :

static SoXtExaminerViewer * myViewer = NULL;
static SoXtFlyViewer * myFlyViewer = NULL;
static Widget myWindow = NULL;

<snip><snip>

// Callback func...
SbBool myAppChangeViewerCB( void* userData, XAnyEvent* anyEvent)
{
  SbBool handled = FALSE;
  SbBool fFlyViewer = myFlyViewer->isVisible();
  XKeyEvent * pKeyEvent;

  cout << " Entering in the callback " << endl;

  // Switching depending on XEvent type
 switch (anyEvent->type)
  {
    case KeyPress:
      pKeyEvent = (XKeyEvent*) anyEvent;
      cout << "   KeyPressed : " << pKeyEvent->keycode << " expecting "
<< 41 << endl;
      switch(pKeyEvent->keycode)
      {
        case 41:  // hack to get directly the code for F key (I didn't
find the correct define)
          if ( fFlyViewer )
          {
            cout << "     switching to Examiner " << endl;
            SoXt::hide( myWindow );
            myFlyViewer->hide( );
            myViewer->show();
            SoXt::show( myWindow );
          }
          else
          {
            cout << "     switching to Fly " << endl;
            SoXt::hide( myWindow );
            myViewer->hide();
            myFlyViewer->show();
            SoXt::show( myWindow );
          }
          handled = TRUE;
          break;
      }
      break;
    default:
      break;
  }

  return handled;
}


// Main function
int main(int argc, char *argv[] )
{
  ParseCmdLine(argc, argv);

  myWindow = SoXt::init( argv[0] );
  if (myWindow==NULL)
    exit(-1);

//  SoXtRenderArea *myViewer =  new SoXtRenderArea(myWindow);
  myViewer = new SoXtExaminerViewer( myWindow );
  myViewer->setDecoration(FALSE);
  myViewer->setViewing(FALSE);
  myViewer->setPopupMenuEnabled( TRUE );
  myViewer->setEventCallback( myAppChangeViewerCB, (void*)&myWindow );

  // Creation 2nd viewer (FlyMode)
  myFlyViewer = new SoXtFlyViewer( myWindow );
  myFlyViewer->setDecoration(FALSE);
  myFlyViewer->setTitle(argv[0]);
  myFlyViewer->setSceneGraph( gMonde.getRootNode() );
  myFlyViewer->setEventCallback( myAppChangeViewerCB, (void*)&myWindow
);

  // this is for differentiating the 2 viewers...
  myViewer->setGLRenderAction( new SoLineHighlightRenderAction );
  myFlyViewer->setGLRenderAction( new SoBoxHighlightRenderAction );
// Init World...
<snip>
-------------------------------------------------------------------------------------------------------------



In fact it seems that always the first viewer (myViewer) is hided then
showed (same way of highlighting).
What's wrong here ??

Regards

Cyril ZEKSER
VISIOSPACE.


<Prev in Thread] Current Thread [Next in Thread>
  • Changing viewer ?, Cyril ZEKSER <=