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:
@@ -279,10 +279,10 @@ ENDIF()
|
||||
|
||||
IF(INSTALL_LIBS)
|
||||
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
|
||||
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/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(INCLUDE_INSTALL_DIR "include/bullet/" CACHE PATH "The subdirectory to the header prefix")
|
||||
SET(PKGCONFIG_INSTALL_PREFIX "lib${LIB_SUFFIX}/pkgconfig/" CACHE STRING "Base directory for pkgconfig files")
|
||||
IF(NOT WIN32)
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bullet.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/bullet.pc @ONLY)
|
||||
INSTALL(
|
||||
@@ -309,7 +309,7 @@ list (APPEND BULLET_LIBRARIES LinearMath)
|
||||
list (APPEND BULLET_LIBRARIES BulletCollision)
|
||||
list (APPEND BULLET_LIBRARIES BulletDynamics)
|
||||
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
|
||||
${CMAKE_CURRENT_BINARY_DIR}/BulletConfig.cmake
|
||||
@ONLY ESCAPE_QUOTES
|
||||
|
||||
@@ -68,4 +68,4 @@ IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES DEBUG_POSTFIX "_Debug")
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
|
||||
SET_TARGET_PROPERTIES(AppBasicDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
|
||||
|
||||
@@ -19,7 +19,7 @@ subject to the following restrictions:
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
//assume linux workaround
|
||||
#include <pthread.h>
|
||||
//#include <pthread.h>
|
||||
#endif
|
||||
|
||||
//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
|
||||
//See https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642
|
||||
|
||||
int i=pthread_getconcurrency();
|
||||
printf("pthread_getconcurrency()=%d\n",i);
|
||||
// int i=pthread_getconcurrency();
|
||||
// printf("pthread_getconcurrency()=%d\n",i);
|
||||
#endif
|
||||
|
||||
glutInit(&argc, argv);
|
||||
|
||||
@@ -181,6 +181,32 @@ static void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
|
||||
#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)
|
||||
{
|
||||
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;
|
||||
int main(int argc, char* argv[])
|
||||
@@ -476,7 +514,8 @@ int main(int argc, char* argv[])
|
||||
*/
|
||||
unsigned long int prevTimeInMicroseconds = clock.getTimeMicroseconds();
|
||||
|
||||
|
||||
gui->registerFileOpenCallback(fileOpenCallback);
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ struct GwenInternalData
|
||||
Gwen::Controls::TabButton* m_explorerPage;
|
||||
Gwen::Controls::TreeControl* m_explorerTreeCtrl;
|
||||
Gwen::Controls::MenuItem* m_viewMenu;
|
||||
class MyMenuItems* m_menuItems;
|
||||
|
||||
int m_curYposition;
|
||||
|
||||
|
||||
@@ -44,13 +44,23 @@ class MyMenuItems : public Gwen::Controls::Base
|
||||
{
|
||||
public:
|
||||
|
||||
MyMenuItems() :Gwen::Controls::Base(0)
|
||||
b3FileOpenCallback m_fileOpenCallback;
|
||||
|
||||
MyMenuItems() :Gwen::Controls::Base(0),m_fileOpenCallback(0)
|
||||
{
|
||||
}
|
||||
void myQuitApp( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
void fileOpen( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
if (m_fileOpenCallback)
|
||||
{
|
||||
(*m_fileOpenCallback)();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct MyTestMenuBar : public Gwen::Controls::MenuStrip
|
||||
@@ -58,17 +68,20 @@ struct MyTestMenuBar : public Gwen::Controls::MenuStrip
|
||||
|
||||
Gwen::Controls::MenuItem* m_fileMenu;
|
||||
Gwen::Controls::MenuItem* m_viewMenu;
|
||||
MyMenuItems* m_menuItems;
|
||||
|
||||
MyTestMenuBar(Gwen::Controls::Base* pParent)
|
||||
: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->GetMenu()->AddItem(L"Quit",menuItems,(Gwen::Event::Handler::Function)&MyMenuItems::myQuitApp);
|
||||
m_viewMenu = AddItem( L"View" );
|
||||
|
||||
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" );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
m_data->m_rightStatusBar = new Gwen::Controls::Label( bar );
|
||||
m_data->m_rightStatusBar->SetWidth(width/2);
|
||||
|
||||
@@ -5,7 +5,7 @@ struct GwenInternalData;
|
||||
|
||||
typedef void (*b3ComboBoxCallback) (int combobox, const char* item);
|
||||
typedef void (*b3ToggleButtonCallback)(int button, int state);
|
||||
|
||||
typedef void (*b3FileOpenCallback)();
|
||||
|
||||
|
||||
class GwenUserInterface
|
||||
@@ -40,6 +40,8 @@ class GwenUserInterface
|
||||
|
||||
void setStatusBarMessage(const char* message, bool isLeft=true);
|
||||
|
||||
void registerFileOpenCallback(b3FileOpenCallback callback);
|
||||
|
||||
GwenInternalData* getInternalData()
|
||||
{
|
||||
return m_data;
|
||||
|
||||
@@ -12,7 +12,7 @@ static bool enableConstraints = true;//false;
|
||||
|
||||
ImportUrdfDemo::ImportUrdfDemo()
|
||||
{
|
||||
|
||||
sprintf(m_fileName,"r2d2.urdf");
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
@@ -71,7 +74,7 @@ struct URDF_LinkInformation
|
||||
btRigidBody* m_bulletRigidBody;
|
||||
virtual ~URDF_LinkInformation()
|
||||
{
|
||||
printf("~\n");
|
||||
printf("~\n");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -239,12 +242,23 @@ btMultiBody* URDF2BulletMultiBody(my_shared_ptr<const Link> link, GraphicsPhysic
|
||||
btMatrix3x3 inertia2PrincipalAxis;
|
||||
inertiaMat.diagonalize(inertia2PrincipalAxis,threshold,maxSteps);
|
||||
localInertiaDiagonal.setValue(inertiaMat[0][0],inertiaMat[1][1],inertiaMat[2][2]);
|
||||
|
||||
btVector3 inertiaLocalCOM((*link).inertial->origin.position.x,(*link).inertial->origin.position.y,(*link).inertial->origin.position.z);
|
||||
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);
|
||||
btMatrix3x3 inertiaOrnMat(inertiaOrn);
|
||||
localInertialTransform.setBasis(inertiaOrnMat*inertia2PrincipalAxis);
|
||||
|
||||
btVector3 inertiaLocalCOM((*link).inertial->origin.position.x,(*link).inertial->origin.position.y,(*link).inertial->origin.position.z);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
btTransform linkTransformInWorldSpace;
|
||||
@@ -403,30 +417,30 @@ btMultiBody* URDF2BulletMultiBody(my_shared_ptr<const Link> link, GraphicsPhysic
|
||||
|
||||
if (shape)//compoundShape->getNumChildShapes()>0)
|
||||
{
|
||||
btMultiBodyLinkCollider* col= new btMultiBodyLinkCollider(mb, linkIndex-1);
|
||||
col->setCollisionShape(shape);
|
||||
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
tr = linkTransformInWorldSpace;
|
||||
//if we don't set the initial pose of the btCollisionObject, the simulator will do this
|
||||
//when syncing the btMultiBody link transforms to the btMultiBodyLinkCollider
|
||||
|
||||
//tr.setOrigin(local_origin[0]);
|
||||
//tr.setRotation(btQuaternion(quat[0],quat[1],quat[2],quat[3]));
|
||||
col->setWorldTransform(tr);
|
||||
|
||||
btMultiBodyLinkCollider* col= new btMultiBodyLinkCollider(mb, linkIndex-1);
|
||||
col->setCollisionShape(shape);
|
||||
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
tr = linkTransformInWorldSpace;
|
||||
//if we don't set the initial pose of the btCollisionObject, the simulator will do this
|
||||
//when syncing the btMultiBody link transforms to the btMultiBodyLinkCollider
|
||||
|
||||
//tr.setOrigin(local_origin[0]);
|
||||
//tr.setRotation(btQuaternion(quat[0],quat[1],quat[2],quat[3]));
|
||||
col->setWorldTransform(tr);
|
||||
|
||||
bool isDynamic = true;
|
||||
short collisionFilterGroup = isDynamic? short(btBroadphaseProxy::DefaultFilter) : short(btBroadphaseProxy::StaticFilter);
|
||||
short collisionFilterMask = isDynamic? short(btBroadphaseProxy::AllFilter) : short(btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
|
||||
|
||||
world->addCollisionObject(col,collisionFilterGroup,collisionFilterMask);
|
||||
|
||||
btVector3 color(0.0,0.0,0.5);
|
||||
gfxBridge.createCollisionObjectGraphicsObject(col,color);
|
||||
btScalar friction = 0.5f;
|
||||
|
||||
col->setFriction(friction);
|
||||
|
||||
world->addCollisionObject(col,collisionFilterGroup,collisionFilterMask);
|
||||
|
||||
btVector3 color(0.0,0.0,0.5);
|
||||
gfxBridge.createCollisionObjectGraphicsObject(col,color);
|
||||
btScalar friction = 0.5f;
|
||||
|
||||
col->setFriction(friction);
|
||||
|
||||
if (parentIndex>=0)
|
||||
{
|
||||
@@ -554,6 +568,8 @@ void URDFvisual2BulletCollisionShape(my_shared_ptr<const Link> link, GraphicsPhy
|
||||
//create a joint if necessary
|
||||
if ((*link).parent_joint)
|
||||
{
|
||||
btAssert(pp);
|
||||
|
||||
btRigidBody* parentBody =pp->m_bulletRigidBody;
|
||||
|
||||
const Joint* pj = (*link).parent_joint.get();
|
||||
@@ -667,11 +683,11 @@ void ImportUrdfDemo::initPhysics(GraphicsPhysicsBridge& gfxBridge)
|
||||
|
||||
m_dynamicsWorld->setGravity(gravity);
|
||||
//int argc=0;
|
||||
const char* someFileName="r2d2.urdf";
|
||||
char relativeFileName[1024];
|
||||
|
||||
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;
|
||||
start.setOrigin(groundOrigin);
|
||||
btRigidBody* body = createRigidBody(0,start,box);
|
||||
//m_dynamicsWorld->removeRigidBody(body);
|
||||
// m_dynamicsWorld->addRigidBody(body,2,1);
|
||||
btVector3 color(0.5,0.5,0.5);
|
||||
gfxBridge.createRigidBodyGraphicsObject(body,color);
|
||||
}
|
||||
@@ -787,4 +805,4 @@ void ImportUrdfDemo::stepSimulation(float deltaTime)
|
||||
//the maximal coordinates/iterative MLCP solver requires a smallish timestep to converge
|
||||
m_dynamicsWorld->stepSimulation(deltaTime,10,1./240.);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
|
||||
class ImportUrdfDemo : public CommonMultiBodySetup
|
||||
{
|
||||
char m_fileName[1024];
|
||||
|
||||
public:
|
||||
ImportUrdfDemo();
|
||||
virtual ~ImportUrdfDemo();
|
||||
|
||||
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
|
||||
virtual void stepSimulation(float deltaTime);
|
||||
|
||||
void setFileName(const char* urdfFileName);
|
||||
};
|
||||
|
||||
#endif //IMPORT_URDF_SETUP_H
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
|
||||
virtual void setWindowTitle(const char* title);
|
||||
|
||||
|
||||
int fileOpenDialog(char* filename, int maxNameLength);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -989,8 +989,48 @@ void MacOpenGLWindow::setRequestExit()
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
virtual void endRendering();
|
||||
|
||||
virtual float getRetinaScale() const {return 1.f;}
|
||||
|
||||
virtual int fileOpenDialog(char* fileName, int maxFileNameLength);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ static bool forceOpenGL3 = true;
|
||||
#ifdef DYNAMIC_LOAD_X11_FUNCTIONS
|
||||
|
||||
///our X11 function typedefs
|
||||
|
||||
typedef int (*PFNXFREE)(void*);
|
||||
typedef XErrorHandler (* PFNXSETERRORHANDLER) (XErrorHandler);
|
||||
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 (*PFNXCLOSEDISPLAY) (Display* a);
|
||||
typedef int (*PFNXDESTROYWINDOW) (Display* a,Window b);
|
||||
typedef int (*PFNXRAISEWINDOW) (Display* a, Window b);
|
||||
|
||||
#if NeedWidePrototypes
|
||||
typedef KeySym* (*PFNXGETKEYBOARDMAPPING) (Display*,unsigned int,int,int*);
|
||||
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 MyXStoreName m_data->m_x11_XStoreName
|
||||
#define MyXDestroyWindow m_data->m_x11_XDestroyWindow
|
||||
#define MyXRaiseWindow m_data->m_x11_XRaiseWindow
|
||||
#define MyXCloseDisplay m_data->m_x11_XCloseDisplay
|
||||
#define MyXKeycodeToKeysym m_data->m_x11_XKeycodeToKeysym
|
||||
#define MyXConvertCase m_data->m_x11_XConvertCase
|
||||
@@ -125,6 +129,7 @@ typedef Status (*PFNXGETWINDOWATTRIBUTES) (Display* a,Window b,XWindowAttributes
|
||||
#define MyXMapWindow XMapWindow
|
||||
#define MyXStoreName XStoreName
|
||||
#define MyXDestroyWindow XDestroyWindow
|
||||
#define MyXRaiseWindow XRaiseWindow
|
||||
#define MyXCloseDisplay XCloseDisplay
|
||||
#define MyXKeycodeToKeysym XKeycodeToKeysym
|
||||
#define MyXConvertCase XConvertCase
|
||||
@@ -167,6 +172,7 @@ struct InternalData2
|
||||
PFNXSTORENAME m_x11_XStoreName;
|
||||
PFNXCLOSEDISPLAY m_x11_XCloseDisplay;
|
||||
PFNXDESTROYWINDOW m_x11_XDestroyWindow;
|
||||
PFNXRAISEWINDOW m_x11_XRaiseWindow;
|
||||
PFNXKEYCODETOKEYSYM m_x11_XKeycodeToKeysym;
|
||||
PFNXGETKEYBOARDMAPPING m_x11_XGetKeyboardMapping;
|
||||
PFNXCONVERTCASE m_x11_XConvertCase;
|
||||
@@ -225,7 +231,10 @@ struct InternalData2
|
||||
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);}
|
||||
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;
|
||||
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;
|
||||
@@ -959,4 +968,29 @@ b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback()
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
|
||||
virtual void setWindowTitle(const char* title);
|
||||
|
||||
int fileOpenDialog(char* filename, int maxNameLength);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -110,6 +110,8 @@ class b3gWindowInterface
|
||||
|
||||
virtual float getRetinaScale() const =0;
|
||||
|
||||
virtual int fileOpenDialog(char* fileName, int maxFileNameLength) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //B3G_WINDOW_INTERFACE_H
|
||||
@@ -16,11 +16,21 @@ struct b3FileUtils
|
||||
|
||||
bool findFile(const char* orgFileName, char* relativeFileName, int maxRelativeFileNameMaxLen)
|
||||
{
|
||||
|
||||
const char* prefix[]={"","./","./data/","../data/","../../data/","../../../data/","../../../../data/"};
|
||||
FILE* f=0;
|
||||
f = fopen(orgFileName,"rb");
|
||||
if (f)
|
||||
{
|
||||
//printf("original file found: [%s]\n", orgFileName);
|
||||
sprintf(relativeFileName,"%s", orgFileName);
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
//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*);
|
||||
|
||||
FILE* f=0;
|
||||
f=0;
|
||||
bool fileFound = false;
|
||||
int result = 0;
|
||||
|
||||
@@ -79,11 +89,11 @@ struct b3FileUtils
|
||||
path[len]=0;
|
||||
} else
|
||||
{
|
||||
#ifdef _WIN32
|
||||
sprintf_s(path, maxPathLength,"");
|
||||
#else
|
||||
sprintf(path, "");
|
||||
#endif
|
||||
b3Assert(maxPathLength>0);
|
||||
if (maxPathLength>0)
|
||||
{
|
||||
path[0] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,4 +113,4 @@ struct b3FileUtils
|
||||
*/
|
||||
|
||||
};
|
||||
#endif //B3_FILE_UTILS_H
|
||||
#endif //B3_FILE_UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user