Merge pull request #229 from erwincoumans/master

add fileOpenDialog selector (Win/Mac/Linux), CMake remote CMAKE_INSTALL_PREFIX,fix support for dynamic loading of X11 functions
This commit is contained in:
erwincoumans
2014-08-31 13:01:22 -07:00
17 changed files with 268 additions and 59 deletions

View File

@@ -279,10 +279,10 @@ ENDIF()
IF(INSTALL_LIBS) IF(INSTALL_LIBS)
SET (LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) SET (LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
SET (LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE STRING "Library directory name") SET (LIB_DESTINATION "lib${LIB_SUFFIX}" CACHE STRING "Library directory name")
## the following are directories where stuff will be installed to ## the following are directories where stuff will be installed to
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/bullet/" CACHE PATH "The subdirectory to the header prefix") SET(INCLUDE_INSTALL_DIR "include/bullet/" CACHE PATH "The subdirectory to the header prefix")
SET(PKGCONFIG_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig/" CACHE STRING "Base directory for pkgconfig files") SET(PKGCONFIG_INSTALL_PREFIX "lib${LIB_SUFFIX}/pkgconfig/" CACHE STRING "Base directory for pkgconfig files")
IF(NOT WIN32) IF(NOT WIN32)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bullet.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/bullet.pc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bullet.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/bullet.pc @ONLY)
INSTALL( INSTALL(
@@ -309,7 +309,7 @@ list (APPEND BULLET_LIBRARIES LinearMath)
list (APPEND BULLET_LIBRARIES BulletCollision) list (APPEND BULLET_LIBRARIES BulletCollision)
list (APPEND BULLET_LIBRARIES BulletDynamics) list (APPEND BULLET_LIBRARIES BulletDynamics)
list (APPEND BULLET_LIBRARIES BulletSoftBody) list (APPEND BULLET_LIBRARIES BulletSoftBody)
set (BULLET_USE_FILE ${CMAKE_INSTALL_PREFIX}/${BULLET_CONFIG_CMAKE_PATH}/UseBullet.cmake) set (BULLET_USE_FILE ${BULLET_CONFIG_CMAKE_PATH}/UseBullet.cmake)
configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/BulletConfig.cmake.in configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/BulletConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/BulletConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/BulletConfig.cmake
@ONLY ESCAPE_QUOTES @ONLY ESCAPE_QUOTES

View File

@@ -19,7 +19,7 @@ subject to the following restrictions:
#if !defined(_WIN32) && !defined(__APPLE__) #if !defined(_WIN32) && !defined(__APPLE__)
//assume linux workaround //assume linux workaround
#include <pthread.h> //#include <pthread.h>
#endif #endif
//glut is C code, this global gDemoApplication links glut to the C++ demo //glut is C code, this global gDemoApplication links glut to the C++ demo
@@ -86,8 +86,8 @@ int glutmain(int argc, char **argv,int width,int height,const char* title,DemoAp
//Access pthreads as a workaround for a bug in Linux/Ubuntu //Access pthreads as a workaround for a bug in Linux/Ubuntu
//See https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642 //See https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642
int i=pthread_getconcurrency(); // int i=pthread_getconcurrency();
printf("pthread_getconcurrency()=%d\n",i); // printf("pthread_getconcurrency()=%d\n",i);
#endif #endif
glutInit(&argc, argv); glutInit(&argc, argv);

View File

@@ -181,6 +181,32 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
#include <string.h> #include <string.h>
void openURDFDemo(const char* filename)
{
if (sCurrentDemo)
{
sCurrentDemo->exitPhysics();
app->m_instancingRenderer->removeAllInstances();
delete sCurrentDemo;
sCurrentDemo=0;
}
app->m_parameterInterface->removeAllParameters();
ImportUrdfDemo* physicsSetup = new ImportUrdfDemo();
physicsSetup->setFileName(filename);
sCurrentDemo = new BasicDemo(app, physicsSetup);
if (sCurrentDemo)
{
sCurrentDemo->initPhysics();
}
}
void selectDemo(int demoIndex) void selectDemo(int demoIndex)
{ {
sCurrentDemoIndex = demoIndex; sCurrentDemoIndex = demoIndex;
@@ -329,6 +355,18 @@ struct GL3TexLoader : public MyTextureLoader
} }
}; };
void fileOpenCallback()
{
char filename[1024];
int len = app->m_window->fileOpenDialog(filename,1024);
if (len)
{
//todo(erwincoumans) check if it is actually URDF
//printf("file open:%s\n", filename);
openURDFDemo(filename);
}
}
extern float shadowMapWorldSize; extern float shadowMapWorldSize;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
@@ -476,6 +514,7 @@ int main(int argc, char* argv[])
*/ */
unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds(); unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds();
gui->registerFileOpenCallback(fileOpenCallback);
do do
{ {

View File

@@ -40,6 +40,7 @@ struct GwenInternalData
Gwen::Controls::TabButton* m_explorerPage; Gwen::Controls::TabButton* m_explorerPage;
Gwen::Controls::TreeControl* m_explorerTreeCtrl; Gwen::Controls::TreeControl* m_explorerTreeCtrl;
Gwen::Controls::MenuItem* m_viewMenu; Gwen::Controls::MenuItem* m_viewMenu;
class MyMenuItems* m_menuItems;
int m_curYposition; int m_curYposition;

View File

@@ -44,13 +44,23 @@ class MyMenuItems : public Gwen::Controls::Base
{ {
public: public:
MyMenuItems() :Gwen::Controls::Base(0) b3FileOpenCallback m_fileOpenCallback;
MyMenuItems() :Gwen::Controls::Base(0),m_fileOpenCallback(0)
{ {
} }
void myQuitApp( Gwen::Controls::Base* pControl ) void myQuitApp( Gwen::Controls::Base* pControl )
{ {
exit(0); exit(0);
} }
void fileOpen( Gwen::Controls::Base* pControl )
{
if (m_fileOpenCallback)
{
(*m_fileOpenCallback)();
}
}
}; };
struct MyTestMenuBar : public Gwen::Controls::MenuStrip struct MyTestMenuBar : public Gwen::Controls::MenuStrip
@@ -58,16 +68,19 @@ struct MyTestMenuBar : public Gwen::Controls::MenuStrip
Gwen::Controls::MenuItem* m_fileMenu; Gwen::Controls::MenuItem* m_fileMenu;
Gwen::Controls::MenuItem* m_viewMenu; Gwen::Controls::MenuItem* m_viewMenu;
MyMenuItems* m_menuItems;
MyTestMenuBar(Gwen::Controls::Base* pParent) MyTestMenuBar(Gwen::Controls::Base* pParent)
:Gwen::Controls::MenuStrip(pParent) :Gwen::Controls::MenuStrip(pParent)
{ {
// Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent ); // Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( pParent );
{ {
MyMenuItems* menuItems = new MyMenuItems; m_menuItems = new MyMenuItems;
m_fileMenu = AddItem( L"File" ); m_fileMenu = AddItem( L"File" );
m_fileMenu->GetMenu()->AddItem(L"Quit",menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::myQuitApp);
m_fileMenu->GetMenu()->AddItem(L"Open",m_menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::fileOpen);
m_fileMenu->GetMenu()->AddItem(L"Quit",m_menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::myQuitApp);
m_viewMenu = AddItem( L"View" ); m_viewMenu = AddItem( L"View" );
} }
@@ -142,6 +155,11 @@ void GwenUserInterface::setStatusBarMessage(const char* message, bool isLeft)
} }
} }
void GwenUserInterface::registerFileOpenCallback(b3FileOpenCallback callback)
{
m_data->m_menuItems->m_fileOpenCallback = callback;
}
void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float retinaScale) void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float retinaScale)
{ {
m_data->m_curYposition = 20; m_data->m_curYposition = 20;
@@ -157,6 +175,10 @@ void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float
MyTestMenuBar* menubar = new MyTestMenuBar(m_data->pCanvas); MyTestMenuBar* menubar = new MyTestMenuBar(m_data->pCanvas);
m_data->m_viewMenu = menubar->m_viewMenu; m_data->m_viewMenu = menubar->m_viewMenu;
m_data->m_menuItems = menubar->m_menuItems;
Gwen::Controls::StatusBar* bar = new Gwen::Controls::StatusBar(m_data->pCanvas); Gwen::Controls::StatusBar* bar = new Gwen::Controls::StatusBar(m_data->pCanvas);
m_data->m_rightStatusBar = new Gwen::Controls::Label( bar ); m_data->m_rightStatusBar = new Gwen::Controls::Label( bar );
m_data->m_rightStatusBar->SetWidth(width/2); m_data->m_rightStatusBar->SetWidth(width/2);

View File

@@ -5,7 +5,7 @@ struct GwenInternalData;
typedef void (*b3ComboBoxCallback) (int combobox, const char* item); typedef void (*b3ComboBoxCallback) (int combobox, const char* item);
typedef void (*b3ToggleButtonCallback)(int button, int state); typedef void (*b3ToggleButtonCallback)(int button, int state);
typedef void (*b3FileOpenCallback)();
class GwenUserInterface class GwenUserInterface
@@ -40,6 +40,8 @@ class GwenUserInterface
void setStatusBarMessage(const char* message, bool isLeft=true); void setStatusBarMessage(const char* message, bool isLeft=true);
void registerFileOpenCallback(b3FileOpenCallback callback);
GwenInternalData* getInternalData() GwenInternalData* getInternalData()
{ {
return m_data; return m_data;

View File

@@ -12,7 +12,7 @@ static bool enableConstraints = true;//false;
ImportUrdfDemo::ImportUrdfDemo() ImportUrdfDemo::ImportUrdfDemo()
{ {
sprintf(m_fileName,"r2d2.urdf");
} }
ImportUrdfDemo::~ImportUrdfDemo() ImportUrdfDemo::~ImportUrdfDemo()
@@ -21,7 +21,10 @@ ImportUrdfDemo::~ImportUrdfDemo()
} }
void ImportUrdfDemo::setFileName(const char* urdfFileName)
{
memcpy(m_fileName,urdfFileName,strlen(urdfFileName)+1);
}
#include "urdf/urdfdom/urdf_parser/include/urdf_parser/urdf_parser.h" #include "urdf/urdfdom/urdf_parser/include/urdf_parser/urdf_parser.h"
@@ -244,9 +247,20 @@ btMultiBody* URDF2BulletMultiBody(my_shared_ptr<const Link> link, GraphicsPhysic
localInertialTransform.setOrigin(inertiaLocalCOM); localInertialTransform.setOrigin(inertiaLocalCOM);
btQuaternion inertiaOrn((*link).inertial->origin.rotation.x,(*link).inertial->origin.rotation.y,(*link).inertial->origin.rotation.z,(*link).inertial->origin.rotation.w); btQuaternion inertiaOrn((*link).inertial->origin.rotation.x,(*link).inertial->origin.rotation.y,(*link).inertial->origin.rotation.z,(*link).inertial->origin.rotation.w);
btMatrix3x3 inertiaOrnMat(inertiaOrn); btMatrix3x3 inertiaOrnMat(inertiaOrn);
if (mass > 0 && (localInertiaDiagonal[0]==0.f || localInertiaDiagonal[1] == 0.f
|| localInertiaDiagonal[2] == 0.f))
{
b3Warning("Error: inertia should not be zero if mass is positive\n");
localInertiaDiagonal.setMax(btVector3(0.1,0.1,0.1));
localInertialTransform.setIdentity();//.setBasis(inertiaOrnMat);
}
else
{
localInertialTransform.setBasis(inertiaOrnMat*inertia2PrincipalAxis); localInertialTransform.setBasis(inertiaOrnMat*inertia2PrincipalAxis);
} }
} }
}
btTransform linkTransformInWorldSpace; btTransform linkTransformInWorldSpace;
int parentIndex = -1; int parentIndex = -1;
@@ -554,6 +568,8 @@ void URDFvisual2BulletCollisionShape(my_shared_ptr<const Link> link, GraphicsPhy
//create a joint if necessary //create a joint if necessary
if ((*link).parent_joint) if ((*link).parent_joint)
{ {
btAssert(pp);
btRigidBody* parentBody =pp->m_bulletRigidBody; btRigidBody* parentBody =pp->m_bulletRigidBody;
const Joint* pj = (*link).parent_joint.get(); const Joint* pj = (*link).parent_joint.get();
@@ -667,11 +683,11 @@ void ImportUrdfDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
m_dynamicsWorld->setGravity(gravity); m_dynamicsWorld->setGravity(gravity);
//int argc=0; //int argc=0;
const char* someFileName="r2d2.urdf";
char relativeFileName[1024]; char relativeFileName[1024];
b3FileUtils fu; b3FileUtils fu;
bool fileFound = fu.findFile(someFileName, relativeFileName, 1024); printf("m_fileName=%s\n", m_fileName);
bool fileFound = fu.findFile(m_fileName, relativeFileName, 1024);
@@ -773,6 +789,8 @@ void ImportUrdfDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
groundOrigin[upAxis]=-2.5; groundOrigin[upAxis]=-2.5;
start.setOrigin(groundOrigin); start.setOrigin(groundOrigin);
btRigidBody* body = createRigidBody(0,start,box); btRigidBody* body = createRigidBody(0,start,box);
//m_dynamicsWorld->removeRigidBody(body);
// m_dynamicsWorld->addRigidBody(body,2,1);
btVector3 color(0.5,0.5,0.5); btVector3 color(0.5,0.5,0.5);
gfxBridge.createRigidBodyGraphicsObject(body,color); gfxBridge.createRigidBodyGraphicsObject(body,color);
} }

View File

@@ -6,12 +6,16 @@
class ImportUrdfDemo : public CommonMultiBodySetup class ImportUrdfDemo : public CommonMultiBodySetup
{ {
char m_fileName[1024];
public: public:
ImportUrdfDemo(); ImportUrdfDemo();
virtual ~ImportUrdfDemo(); virtual ~ImportUrdfDemo();
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge); virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
virtual void stepSimulation(float deltaTime); virtual void stepSimulation(float deltaTime);
void setFileName(const char* urdfFileName);
}; };
#endif //IMPORT_URDF_SETUP_H #endif //IMPORT_URDF_SETUP_H

View File

@@ -81,7 +81,7 @@ public:
virtual void setWindowTitle(const char* title); virtual void setWindowTitle(const char* title);
int fileOpenDialog(char* filename, int maxNameLength);
}; };

View File

@@ -989,8 +989,48 @@ void MacOpenGLWindow::setRequestExit()
m_internalData->m_exitRequested = true; m_internalData->m_exitRequested = true;
} }
#include <string.h>
int MacOpenGLWindow::fileOpenDialog(char* filename, int maxNameLength)
{
//save/restore the OpenGL context, NSOpenPanel can mess it up
//http://stackoverflow.com/questions/13987148/nsopenpanel-breaks-my-sdl-opengl-app
NSOpenGLContext *foo = [NSOpenGLContext currentContext];
// get the url of a .txt file
NSOpenPanel * zOpenPanel = [NSOpenPanel openPanel];
NSArray * zAryOfExtensions = [NSArray arrayWithObject:@"urdf"];
[zOpenPanel setAllowedFileTypes:zAryOfExtensions];
NSInteger zIntResult = [zOpenPanel runModal];
[foo makeCurrentContext];
if (zIntResult == NSFileHandlingPanelCancelButton) {
NSLog(@"readUsingOpenPanel cancelled");
return 0;
}
NSURL *zUrl = [zOpenPanel URL];
if (zUrl)
{
//without the file://
NSString *myString = [zUrl absoluteString];
int slen = [myString length];
if (slen < maxNameLength)
{
const char *cfilename=[myString UTF8String];
//expect file:// at start of URL
const char* p = strstr(cfilename, "file://");
if (p==cfilename)
{
int actualLen = strlen(cfilename)-7;
memcpy(filename, cfilename+7,actualLen);
filename[actualLen]=0;
return actualLen;
}
}
}
return 0;
}

View File

@@ -137,6 +137,40 @@ void Win32OpenGLWindow::endRendering()
} }
int Win32OpenGLWindow::fileOpenDialog(char* fileName, int maxFileNameLength)
{
//wchar_t wideChars[1024];
OPENFILENAME ofn ;
ZeroMemory( &ofn , sizeof( ofn));
ofn.lStructSize = sizeof ( ofn );
ofn.hwndOwner = NULL ;
#ifdef UNICODE
WCHAR bla[1024];
ofn.lpstrFile = bla;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 1023;
ofn.lpstrFilter = L"URDF\0*.urdf\0";
#else
ofn.lpstrFile = fileName;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 1023;
//ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.lpstrFilter = "URDF\0*.urdf\0";
#endif
ofn.nFilterIndex =1;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir=NULL ;
ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
GetOpenFileName( &ofn );
return strlen(fileName);
//return 0;
}

View File

@@ -51,6 +51,8 @@ public:
virtual void endRendering(); virtual void endRendering();
virtual float getRetinaScale() const {return 1.f;} virtual float getRetinaScale() const {return 1.f;}
virtual int fileOpenDialog(char* fileName, int maxFileNameLength);
}; };

View File

@@ -64,6 +64,7 @@ static bool forceOpenGL3 = true;
#ifdef DYNAMIC_LOAD_X11_FUNCTIONS #ifdef DYNAMIC_LOAD_X11_FUNCTIONS
///our X11 function typedefs ///our X11 function typedefs
typedef int (*PFNXFREE)(void*); typedef int (*PFNXFREE)(void*);
typedef XErrorHandler (* PFNXSETERRORHANDLER) (XErrorHandler); typedef XErrorHandler (* PFNXSETERRORHANDLER) (XErrorHandler);
typedef int (* PFNXSYNC) (Display* a,Bool b); typedef int (* PFNXSYNC) (Display* a,Bool b);
@@ -74,6 +75,8 @@ typedef int (*PFNXMAPWINDOW) (Display*, Window);
typedef int (*PFNXSTORENAME) (Display* a,Window b,_Xconst char* c); typedef int (*PFNXSTORENAME) (Display* a,Window b,_Xconst char* c);
typedef int (*PFNXCLOSEDISPLAY) (Display* a); typedef int (*PFNXCLOSEDISPLAY) (Display* a);
typedef int (*PFNXDESTROYWINDOW) (Display* a,Window b); typedef int (*PFNXDESTROYWINDOW) (Display* a,Window b);
typedef int (*PFNXRAISEWINDOW) (Display* a, Window b);
#if NeedWidePrototypes #if NeedWidePrototypes
typedef KeySym* (*PFNXGETKEYBOARDMAPPING) (Display*,unsigned int,int,int*); typedef KeySym* (*PFNXGETKEYBOARDMAPPING) (Display*,unsigned int,int,int*);
typedef KeySym (*PFNXKEYCODETOKEYSYM) (Display* a,unsigned int b,int c); typedef KeySym (*PFNXKEYCODETOKEYSYM) (Display* a,unsigned int b,int c);
@@ -100,6 +103,7 @@ typedef Status (*PFNXGETWINDOWATTRIBUTES) (Display* a,Window b,XWindowAttributes
#define MyXMapWindow m_data->m_x11_XMapWindow #define MyXMapWindow m_data->m_x11_XMapWindow
#define MyXStoreName m_data->m_x11_XStoreName #define MyXStoreName m_data->m_x11_XStoreName
#define MyXDestroyWindow m_data->m_x11_XDestroyWindow #define MyXDestroyWindow m_data->m_x11_XDestroyWindow
#define MyXRaiseWindow m_data->m_x11_XRaiseWindow
#define MyXCloseDisplay m_data->m_x11_XCloseDisplay #define MyXCloseDisplay m_data->m_x11_XCloseDisplay
#define MyXKeycodeToKeysym m_data->m_x11_XKeycodeToKeysym #define MyXKeycodeToKeysym m_data->m_x11_XKeycodeToKeysym
#define MyXConvertCase m_data->m_x11_XConvertCase #define MyXConvertCase m_data->m_x11_XConvertCase
@@ -125,6 +129,7 @@ typedef Status (*PFNXGETWINDOWATTRIBUTES) (Display* a,Window b,XWindowAttributes
#define MyXMapWindow XMapWindow #define MyXMapWindow XMapWindow
#define MyXStoreName XStoreName #define MyXStoreName XStoreName
#define MyXDestroyWindow XDestroyWindow #define MyXDestroyWindow XDestroyWindow
#define MyXRaiseWindow XRaiseWindow
#define MyXCloseDisplay XCloseDisplay #define MyXCloseDisplay XCloseDisplay
#define MyXKeycodeToKeysym XKeycodeToKeysym #define MyXKeycodeToKeysym XKeycodeToKeysym
#define MyXConvertCase XConvertCase #define MyXConvertCase XConvertCase
@@ -167,6 +172,7 @@ struct InternalData2
PFNXSTORENAME m_x11_XStoreName; PFNXSTORENAME m_x11_XStoreName;
PFNXCLOSEDISPLAY m_x11_XCloseDisplay; PFNXCLOSEDISPLAY m_x11_XCloseDisplay;
PFNXDESTROYWINDOW m_x11_XDestroyWindow; PFNXDESTROYWINDOW m_x11_XDestroyWindow;
PFNXRAISEWINDOW m_x11_XRaiseWindow;
PFNXKEYCODETOKEYSYM m_x11_XKeycodeToKeysym; PFNXKEYCODETOKEYSYM m_x11_XKeycodeToKeysym;
PFNXGETKEYBOARDMAPPING m_x11_XGetKeyboardMapping; PFNXGETKEYBOARDMAPPING m_x11_XGetKeyboardMapping;
PFNXCONVERTCASE m_x11_XConvertCase; PFNXCONVERTCASE m_x11_XConvertCase;
@@ -225,7 +231,10 @@ struct InternalData2
missingFunc = ((m_x11_XCloseDisplay = (PFNXCLOSEDISPLAY) dlsym(m_x11_library,"XCloseDisplay"))==NULL) | missingFunc; missingFunc = ((m_x11_XCloseDisplay = (PFNXCLOSEDISPLAY) dlsym(m_x11_library,"XCloseDisplay"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XCloseDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);} if (missingFunc) { printf("Error: missing func XCloseDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XDestroyWindow = (PFNXDESTROYWINDOW) dlsym(m_x11_library,"XDestroyWindow"))==NULL) | missingFunc; missingFunc = ((m_x11_XDestroyWindow = (PFNXDESTROYWINDOW) dlsym(m_x11_library,"XDestroyWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XMapWindow in %s, exiting!\n", X11_LIBRARY); exit(0);} if (missingFunc) { printf("Error: missing func XDestroyWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XRaiseWindow = (PFNXRAISEWINDOW) dlsym(m_x11_library,"XRaiseWindow"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XRaiseWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XGetKeyboardMapping = (PFNXGETKEYBOARDMAPPING) dlsym(m_x11_library,"XGetKeyboardMapping"))==NULL) | missingFunc; missingFunc = ((m_x11_XGetKeyboardMapping = (PFNXGETKEYBOARDMAPPING) dlsym(m_x11_library,"XGetKeyboardMapping"))==NULL) | missingFunc;
if (missingFunc) { printf("Error: missing func XGetKeyboardMapping in %s, exiting!\n", X11_LIBRARY); exit(0);} if (missingFunc) { printf("Error: missing func XGetKeyboardMapping in %s, exiting!\n", X11_LIBRARY); exit(0);}
missingFunc = ((m_x11_XKeycodeToKeysym = (PFNXKEYCODETOKEYSYM) dlsym(m_x11_library,"XKeycodeToKeysym"))==NULL) | missingFunc; missingFunc = ((m_x11_XKeycodeToKeysym = (PFNXKEYCODETOKEYSYM) dlsym(m_x11_library,"XKeycodeToKeysym"))==NULL) | missingFunc;
@@ -959,4 +968,29 @@ b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback()
{ {
return m_data->m_keyboardCallback; return m_data->m_keyboardCallback;
} }
#include <stdio.h>
int X11OpenGLWindow::fileOpenDialog(char* filename, int maxNameLength)
{
int len = 0;
FILE * output = popen("zenity --file-selection --file-filter=\"*.urdf\" --file-filter=\"*.*\"","r");
if (output)
{
while( fgets(filename, maxNameLength-1, output) != NULL )
{
len=strlen(filename);
if (len>0)
{
filename[len-1]=0;
printf("file open (length=%d) = %s\n", len,filename);
}
}
pclose(output);
} else
{
printf("Error: fileOpenDialog no popen output, perhaps install zenity?\n");
}
MyXRaiseWindow(m_data->m_dpy, m_data->m_win);
return len;
}

View File

@@ -59,6 +59,7 @@ public:
virtual void setWindowTitle(const char* title); virtual void setWindowTitle(const char* title);
int fileOpenDialog(char* filename, int maxNameLength);
}; };

View File

@@ -110,6 +110,8 @@ class b3gWindowInterface
virtual float getRetinaScale() const =0; virtual float getRetinaScale() const =0;
virtual int fileOpenDialog(char* fileName, int maxFileNameLength) = 0;
}; };
#endif //B3G_WINDOW_INTERFACE_H #endif //B3G_WINDOW_INTERFACE_H

View File

@@ -16,11 +16,21 @@ struct b3FileUtils
bool findFile(const char* orgFileName, char* relativeFileName, int maxRelativeFileNameMaxLen) bool findFile(const char* orgFileName, char* relativeFileName, int maxRelativeFileNameMaxLen)
{ {
FILE* f=0;
f = fopen(orgFileName,"rb");
if (f)
{
//printf("original file found: [%s]\n", orgFileName);
sprintf(relativeFileName,"%s", orgFileName);
fclose(f);
return true;
}
const char* prefix[]={"","./","./data/","../data/","../../data/","../../../data/","../../../../data/"}; //printf("Trying various directories, relative to current working directory\n");
const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"};
int numPrefixes = sizeof(prefix)/sizeof(const char*); int numPrefixes = sizeof(prefix)/sizeof(const char*);
FILE* f=0; f=0;
bool fileFound = false; bool fileFound = false;
int result = 0; int result = 0;
@@ -79,11 +89,11 @@ struct b3FileUtils
path[len]=0; path[len]=0;
} else } else
{ {
#ifdef _WIN32 b3Assert(maxPathLength>0);
sprintf_s(path, maxPathLength,""); if (maxPathLength>0)
#else {
sprintf(path, ""); path[0] = 0;
#endif }
} }
} }