2008-12-09 17:26:51 +08:00
# include <osgWidget/VncClient>
2011-10-26 20:29:38 +08:00
# include <osgDB/Registry>
2008-10-31 20:03:44 +08:00
# include <osgViewer/Viewer>
# include <osgViewer/ViewerEventHandlers>
2008-11-03 23:58:02 +08:00
class EscapeHandler : public osgGA : : GUIEventHandler
2008-10-31 21:59:32 +08:00
{
2008-11-03 23:58:02 +08:00
public :
2017-10-16 16:49:47 +08:00
2008-11-03 23:58:02 +08:00
EscapeHandler ( ) { }
2008-10-31 21:59:32 +08:00
2008-11-03 23:58:02 +08:00
bool handle ( const osgGA : : GUIEventAdapter & ea , osgGA : : GUIActionAdapter & aa )
2008-10-31 21:59:32 +08:00
{
2008-11-03 23:58:02 +08:00
if ( ea . getHandled ( ) ) return false ;
2008-10-31 21:59:32 +08:00
2008-11-03 23:58:02 +08:00
switch ( ea . getEventType ( ) )
2008-10-31 21:59:32 +08:00
{
2008-11-03 23:58:02 +08:00
case ( osgGA : : GUIEventAdapter : : KEYUP ) :
2008-10-31 21:59:32 +08:00
{
2008-11-03 23:58:02 +08:00
if ( ea . getKey ( ) = = osgGA : : GUIEventAdapter : : KEY_Escape )
{
osgViewer : : View * view = dynamic_cast < osgViewer : : View * > ( & aa ) ;
if ( view ) view - > getViewerBase ( ) - > setDone ( true ) ;
2017-10-16 16:49:47 +08:00
2008-11-03 23:58:02 +08:00
return true ;
}
2018-09-11 19:29:40 +08:00
break ;
2008-10-31 21:59:32 +08:00
}
2008-11-03 23:58:02 +08:00
default :
return false ;
}
return false ;
2008-10-31 21:59:32 +08:00
}
2008-11-03 23:58:02 +08:00
} ;
2008-10-31 21:59:32 +08:00
2008-11-03 23:58:02 +08:00
int main ( int argc , char * * argv )
{
osg : : ArgumentParser arguments ( & argc , argv ) ;
2017-10-16 16:49:47 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --login <url> <username> <password> " , " Provide authentication information for http file access. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --password <password> " , " Provide password for any vnc url on command line not mentioned in --login. " ) ;
osgViewer : : Viewer viewer ( arguments ) ;
2008-10-31 21:59:32 +08:00
2008-12-09 19:05:04 +08:00
osgWidget : : GeometryHints hints ( osg : : Vec3 ( 0.0f , 0.0f , 0.0f ) ,
2008-12-08 01:02:30 +08:00
osg : : Vec3 ( 1.0f , 0.0f , 0.0f ) ,
osg : : Vec3 ( 0.0f , 0.0f , 1.0f ) ,
2008-12-09 17:26:51 +08:00
osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ,
2008-12-08 01:02:30 +08:00
osgWidget : : GeometryHints : : RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO ) ;
2008-10-31 20:03:44 +08:00
2008-12-08 01:02:30 +08:00
osg : : ref_ptr < osg : : Group > group = new osg : : Group ;
2008-10-31 20:03:44 +08:00
2011-10-26 20:29:38 +08:00
std : : string password ;
while ( arguments . read ( " --password " , password ) )
{
}
2017-11-27 18:32:02 +08:00
std : : string url , username ;
2017-10-16 16:49:47 +08:00
while ( arguments . read ( " --login " , url , username , password ) )
{
osgDB : : Registry : : instance ( ) - > getOrCreateAuthenticationMap ( ) - > addAuthenticationDetails (
url ,
new osgDB : : AuthenticationDetails ( username , password )
) ;
}
2017-10-12 23:21:10 +08:00
2008-12-08 01:02:30 +08:00
for ( int i = 1 ; i < arguments . argc ( ) ; + + i )
2008-11-03 23:58:02 +08:00
{
2008-12-08 01:02:30 +08:00
if ( ! arguments . isOption ( i ) )
{
2011-10-26 20:29:38 +08:00
std : : string hostname = arguments [ i ] ;
if ( ! password . empty ( ) )
{
2017-11-27 18:32:02 +08:00
osgDB : : AuthenticationMap * authenticationMap = osgDB : : Registry : : instance ( ) - > getOrCreateAuthenticationMap ( ) ;
2017-10-16 16:49:47 +08:00
const osgDB : : AuthenticationDetails * details = authenticationMap - > getAuthenticationDetails ( hostname ) ;
if ( details = = NULL )
{
authenticationMap - > addAuthenticationDetails ( hostname , new osgDB : : AuthenticationDetails ( " " , password ) ) ;
}
2011-10-26 20:29:38 +08:00
}
2008-12-08 01:02:30 +08:00
osg : : ref_ptr < osgWidget : : VncClient > vncClient = new osgWidget : : VncClient ;
if ( vncClient - > connect ( arguments [ i ] , hints ) )
2017-10-16 16:49:47 +08:00
{
2008-12-08 01:02:30 +08:00
group - > addChild ( vncClient . get ( ) ) ;
2017-10-16 16:49:47 +08:00
2008-12-08 01:02:30 +08:00
hints . position . x ( ) + = 1.1f ;
}
}
2008-11-03 23:58:02 +08:00
}
2008-12-08 01:02:30 +08:00
viewer . setSceneData ( group . get ( ) ) ;
2008-10-31 20:03:44 +08:00
viewer . addEventHandler ( new osgViewer : : StatsHandler ) ;
2008-12-08 01:02:30 +08:00
2008-11-03 23:58:02 +08:00
// add a custom escape handler, but disable the standard viewer one to enable the vnc images to handle
// the escape without it getting caught by the viewer.
2018-09-11 19:29:40 +08:00
viewer . addEventHandler ( new EscapeHandler ) ;
2008-10-31 21:59:32 +08:00
viewer . setKeyEventSetsDone ( 0 ) ;
2008-10-31 20:03:44 +08:00
return viewer . run ( ) ;
}