Revision: 8827
http://playerstage.svn.sourceforge.net/playerstage/?rev=8827&view=rev
Author: natepak
Date: 2010-07-21 22:23:22 +0000 (Wed, 21 Jul 2010)
Log Message:
-----------
Move improvements to the wx gui
Modified Paths:
--------------
code/gazebo/branches/wx/Media/materials/textures/box_create_blue.png
code/gazebo/branches/wx/Media/materials/textures/control_end_blue.png
code/gazebo/branches/wx/Media/materials/textures/control_pause_blue.png
code/gazebo/branches/wx/Media/materials/textures/control_play_blue.png
code/gazebo/branches/wx/Media/materials/textures/cylinder_create_blue.png
code/gazebo/branches/wx/Media/materials/textures/sphere_create_blue.png
code/gazebo/branches/wx/cmake/SearchForStuff.cmake
code/gazebo/branches/wx/server/Simulator.cc
code/gazebo/branches/wx/server/Simulator.hh
code/gazebo/branches/wx/server/main.cc
code/gazebo/branches/wx/server/rendering/Image.cc
code/gazebo/branches/wx/server/rendering/Image.hh
code/gazebo/branches/wx/server/rendering/OgreCreator.cc
code/gazebo/branches/wx/server/wx/CMakeLists.txt
code/gazebo/branches/wx/server/wx/RenderPanel.cc
code/gazebo/branches/wx/server/wx/RenderPanel.hh
code/gazebo/branches/wx/server/wx/SimulationApp.cc
code/gazebo/branches/wx/server/wx/SimulationApp.hh
code/gazebo/branches/wx/server/wx/SimulationFrame.cc
code/gazebo/branches/wx/server/wx/SimulationFrame.hh
Added Paths:
-----------
code/gazebo/branches/wx/server/wx/TimePanel.cc
code/gazebo/branches/wx/server/wx/TimePanel.hh
Modified: code/gazebo/branches/wx/Media/materials/textures/box_create_blue.png
===================================================================
(Binary files differ)
Modified: code/gazebo/branches/wx/Media/materials/textures/control_end_blue.png
===================================================================
(Binary files differ)
Modified:
code/gazebo/branches/wx/Media/materials/textures/control_pause_blue.png
===================================================================
(Binary files differ)
Modified: code/gazebo/branches/wx/Media/materials/textures/control_play_blue.png
===================================================================
(Binary files differ)
Modified:
code/gazebo/branches/wx/Media/materials/textures/cylinder_create_blue.png
===================================================================
(Binary files differ)
Modified:
code/gazebo/branches/wx/Media/materials/textures/sphere_create_blue.png
===================================================================
(Binary files differ)
Modified: code/gazebo/branches/wx/cmake/SearchForStuff.cmake
===================================================================
--- code/gazebo/branches/wx/cmake/SearchForStuff.cmake 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/cmake/SearchForStuff.cmake 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -339,7 +339,7 @@
########################################
# Find wxWidgets
-find_package(wxWidgets COMPONENTS base core gl)
+find_package(wxWidgets)
if (NOT wxWidgets_FOUND)
BUILD_ERROR ("wxWidgets not found. See the following website:
http://www.wxwidgets.org")
endif (NOT wxWidgets_FOUND)
Modified: code/gazebo/branches/wx/server/Simulator.cc
===================================================================
--- code/gazebo/branches/wx/server/Simulator.cc 2010-07-18 20:14:30 UTC (rev
8826)
+++ code/gazebo/branches/wx/server/Simulator.cc 2010-07-21 22:23:22 UTC (rev
8827)
@@ -121,6 +121,7 @@
this->startTime = this->GetWallTime();
this->gazeboConfig=new gazebo::GazeboConfig();
this->pause = false;
+
}
////////////////////////////////////////////////////////////////////////////////
@@ -406,7 +407,7 @@
////////////////////////////////////////////////////////////////////////////////
/// Main simulation loop, when this loop ends the simulation finish
-void Simulator::MainLoop()
+void Simulator::Run()
{
this->state = RUN;
@@ -419,14 +420,51 @@
this->physicsThread = new boost::thread(
boost::bind(&Simulator::PhysicsLoop, this));
- // Update the gui
- while (!this->userQuit)
+ if (this->gui)
+ this->gui->Run();
+ else
{
- currTime = this->GetWallTime();
- if ( currTime - lastTime > 1.0/freq)
+ while (!this->userQuit)
{
- lastTime = this->GetWallTime();
+ currTime = this->GetWallTime();
+ if ( currTime - lastTime > 1.0/freq)
+ {
+ lastTime = this->GetWallTime();
+ this->GraphicsUpdate();
+ currTime = this->GetWallTime();
+ if (currTime - lastTime < 1/freq)
+ {
+ Time sleepTime = ( Time(1.0/freq) - (currTime - lastTime));
+ timeSpec.tv_sec = sleepTime.sec;
+ timeSpec.tv_nsec = sleepTime.nsec;
+
+ nanosleep(&timeSpec, NULL);
+ }
+ }
+ else
+ {
+ Time sleepTime = ( Time(1.0/freq) - (currTime - lastTime));
+ timeSpec.tv_sec = sleepTime.sec;
+ timeSpec.tv_nsec = sleepTime.nsec;
+ nanosleep(&timeSpec, NULL);
+ }
+ }
+ }
+
+ this->physicsThread->join();
+}
+
+void Simulator::GraphicsUpdate()
+{
+ // Update the gui
+ //while (!this->userQuit)
+ //{
+ //currTime = this->GetWallTime();
+ //if ( currTime - lastTime > 1.0/freq)
+ //{
+ //lastTime = this->GetWallTime();
+
if (this->gui)
this->gui->Update();
@@ -436,12 +474,12 @@
World::Instance()->GraphicsUpdate();
}
- currTime = this->GetWallTime();
+ //currTime = this->GetWallTime();
World::Instance()->ProcessEntitiesToLoad();
World::Instance()->ProcessEntitiesToDelete();
- if (currTime - lastTime < 1/freq)
+ /*if (currTime - lastTime < 1/freq)
{
Time sleepTime = ( Time(1.0/freq) - (currTime - lastTime));
timeSpec.tv_sec = sleepTime.sec;
@@ -457,9 +495,9 @@
timeSpec.tv_nsec = sleepTime.nsec;
nanosleep(&timeSpec, NULL);
}
- }
+ */
+ //}
- this->physicsThread->join();
}
////////////////////////////////////////////////////////////////////////////////
Modified: code/gazebo/branches/wx/server/Simulator.hh
===================================================================
--- code/gazebo/branches/wx/server/Simulator.hh 2010-07-18 20:14:30 UTC (rev
8826)
+++ code/gazebo/branches/wx/server/Simulator.hh 2010-07-21 22:23:22 UTC (rev
8827)
@@ -88,8 +88,10 @@
public: void Fini( );
/// \brief Main simulation loop, when this loop ends the simulation finish
- public: void MainLoop();
+ public: void Run();
+ public: void GraphicsUpdate();
+
/// \brief Gets the local configuration for this computer
public: GazeboConfig *GetGazeboConfig() const;
Modified: code/gazebo/branches/wx/server/main.cc
===================================================================
--- code/gazebo/branches/wx/server/main.cc 2010-07-18 20:14:30 UTC (rev
8826)
+++ code/gazebo/branches/wx/server/main.cc 2010-07-21 22:23:22 UTC (rev
8827)
@@ -297,8 +297,8 @@
// Initialize the simulator
try
{
+ gazebo::Simulator::Instance()->SetPaused(optPaused);
gazebo::Simulator::Instance()->Init();
- gazebo::Simulator::Instance()->SetPaused(optPaused);
}
catch (gazebo::GazeboError e)
{
@@ -311,7 +311,7 @@
// Main loop of the simulator
try
{
- gazebo::Simulator::Instance()->MainLoop();
+ gazebo::Simulator::Instance()->Run();
}
catch (gazebo::GazeboError e)
{
Modified: code/gazebo/branches/wx/server/rendering/Image.cc
===================================================================
--- code/gazebo/branches/wx/server/rendering/Image.cc 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/server/rendering/Image.cc 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -103,26 +103,25 @@
{
closedir(dir);
- std::string fullName = (((*piter)+"/")+filename);
- //std::cout << "searching file[" << fullName << "]\n";
+ this->fullName = (((*piter)+"/")+filename);
// if file exist
- if (stat(fullName.c_str(), &st) == 0)
+ if (stat(this->fullName.c_str(), &st) == 0)
{
- FREE_IMAGE_FORMAT fifmt =
FreeImage_GetFIFFromFilename(fullName.c_str());
+ FREE_IMAGE_FORMAT fifmt =
FreeImage_GetFIFFromFilename(this->fullName.c_str());
if (this->bitmap)
FreeImage_Unload(this->bitmap);
this->bitmap = NULL;
if (fifmt == FIF_PNG)
- this->bitmap = FreeImage_Load(fifmt, fullName.c_str(),
PNG_DEFAULT);
+ this->bitmap = FreeImage_Load(fifmt, this->fullName.c_str(),
PNG_DEFAULT);
else if (fifmt == FIF_JPEG)
- this->bitmap = FreeImage_Load(fifmt, fullName.c_str(),
JPEG_DEFAULT);
+ this->bitmap = FreeImage_Load(fifmt, this->fullName.c_str(),
JPEG_DEFAULT);
else if (fifmt == FIF_BMP)
- this->bitmap = FreeImage_Load(fifmt, fullName.c_str(),
BMP_DEFAULT);
+ this->bitmap = FreeImage_Load(fifmt, this->fullName.c_str(),
BMP_DEFAULT);
else
{
- gzerr(5) << "Unknown image format[" << fullName << "]\n";
+ gzerr(5) << "Unknown image format[" << this->fullName << "]\n";
return -1;
}
@@ -395,3 +394,12 @@
{
return this->bitmap != NULL;
}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the full filename of the image
+std::string Image::GetFilename() const
+{
+ return this->fullName;
+}
+
+
Modified: code/gazebo/branches/wx/server/rendering/Image.hh
===================================================================
--- code/gazebo/branches/wx/server/rendering/Image.hh 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/server/rendering/Image.hh 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -86,10 +86,15 @@
/// \brief Returns whether this is a valid image
public: bool Valid() const;
+ /// \brief Get the full filename of the image
+ public: std::string GetFilename() const;
+
/// Count the number of images created. Used for initialising free image
private: static int count;
private: FIBITMAP *bitmap;
+
+ private: std::string fullName;
};
}
Modified: code/gazebo/branches/wx/server/rendering/OgreCreator.cc
===================================================================
--- code/gazebo/branches/wx/server/rendering/OgreCreator.cc 2010-07-18
20:14:30 UTC (rev 8826)
+++ code/gazebo/branches/wx/server/rendering/OgreCreator.cc 2010-07-21
22:23:22 UTC (rev 8827)
@@ -374,8 +374,6 @@
if (wxWindow)
{
//XSync(fl_display, false);
-
- std::cout << "OgreCreator::CreateWindow1\n";
win = OgreCreator::CreateWindow( wxWindow->GetOgreHandle(), width, height);
if (win)
@@ -393,7 +391,6 @@
if (!Simulator::Instance()->GetRenderEngineEnabled())
return NULL;
- std::cout << "OgreCreator::CreateWindow2\n";
Ogre::StringVector paramsVector;
Ogre::NameValuePairList params;
Ogre::RenderWindow *window = NULL;
Modified: code/gazebo/branches/wx/server/wx/CMakeLists.txt
===================================================================
--- code/gazebo/branches/wx/server/wx/CMakeLists.txt 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/server/wx/CMakeLists.txt 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -3,11 +3,13 @@
set (sources SimulationApp.cc
SimulationFrame.cc
RenderPanel.cc
+ TimePanel.cc
)
set (headers SimulationApp.hh
SimulationFrame.hh
RenderPanel.hh
+ TimePanel.hh
)
LIST_TO_STRING(GAZEBO_CFLAGS "${gazeboserver_cflags}")
Modified: code/gazebo/branches/wx/server/wx/RenderPanel.cc
===================================================================
--- code/gazebo/branches/wx/server/wx/RenderPanel.cc 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/server/wx/RenderPanel.cc 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -9,6 +9,8 @@
#include <GL/glx.h>
#endif
+#include "World.hh"
+#include "Events.hh"
#include "UserCamera.hh"
#include "RenderPanel.hh"
@@ -19,10 +21,11 @@
////////////////////////////////////////////////////////////////////////////////
// Constructor
RenderPanel::RenderPanel(wxWindow *parent)
- : wxControl(parent, wxID_ANY, wxDefaultPosition, wxSize(800,600),
wxSUNKEN_BORDER, wxDefaultValidator)
+ : wxControl(parent, wxID_ANY, wxDefaultPosition, wxSize(320,240),
wxSUNKEN_BORDER, wxDefaultValidator)
{
- std::cout << "RenderPanel::Constructor\n";
this->userCamera = NULL;
+ this->cursorState = "default";
+ this->currMaker = NULL;
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( RenderPanel::OnMouseEvent ),
NULL, this );
Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( RenderPanel::OnMouseEvent
), NULL, this );
@@ -34,6 +37,7 @@
Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( RenderPanel::OnMouseEvent ),
NULL, this );
Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( RenderPanel::OnMouseEvent
), NULL, this );
+ Events::ConnectCreateEntitySignal( boost::bind(&RenderPanel::CreateEntity,
this, _1) );
}
////////////////////////////////////////////////////////////////////////////////
@@ -76,8 +80,6 @@
str << wid;// << ':';
handle = str.str();
- std::cout << "HANDLE[" << handle << "]\n";
-
#elif defined(__WXMAC__)
handle = Ogre::StringConverter::toString((size_t)(GetHandle()));
#else
@@ -92,6 +94,7 @@
{
this->mouseEvent.pos.Set( event.GetX(), event.GetY() );
+
if (event.LeftDown() || event.MiddleDown() || event.RightDown())
this->mouseEvent.pressPos = this->mouseEvent.pos;
@@ -101,8 +104,23 @@
this->mouseEvent.dragging = event.Dragging();
- this->userCamera->HandleMouseEvent(this->mouseEvent);
+ if (this->currMaker)
+ {
+ if (event.LeftDown())
+ this->currMaker->MousePushCB(this->mouseEvent);
+ else if (event.LeftUp())
+ this->currMaker->MouseReleaseCB(this->mouseEvent);
+ else if (event.Dragging())
+ this->currMaker->MouseDragCB(this->mouseEvent);
+
+ if (this->currMaker->IsActive())
+ return;
+ }
+ else
+ this->userCamera->HandleMouseEvent(this->mouseEvent);
+
+
this->mouseEvent.prevPos = this->mouseEvent.pos;
}
@@ -194,3 +212,35 @@
this->userCamera->Init();
this->userCamera->SetWorldPose(pose);
}
+
+void RenderPanel::CreateEntity(std::string name)
+{
+ if (this->currMaker)
+ this->currMaker->Stop();
+
+ //this->SetCursorState("create");
+
+ if (name.size() > 0)
+ World::Instance()->SetSelectedEntity(NULL);
+
+ if (name == "box")
+ this->currMaker = &this->boxMaker;
+ else if (name == "cylinder")
+ this->currMaker = &this->cylinderMaker;
+ else if (name == "sphere")
+ this->currMaker = &this->sphereMaker;
+ else if (name == "pointlight")
+ this->currMaker = &this->pointLightMaker;
+ else if (name == "spotlight")
+ this->currMaker = &this->spotLightMaker;
+ else if (name == "directionallight")
+ this->currMaker = &this->directionalLightMaker;
+ else
+ {
+ this->currMaker = NULL;
+ //this->SetCursorState("default");
+ }
+
+ if (this->currMaker)
+ this->currMaker->Start();
+}
Modified: code/gazebo/branches/wx/server/wx/RenderPanel.hh
===================================================================
--- code/gazebo/branches/wx/server/wx/RenderPanel.hh 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/server/wx/RenderPanel.hh 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -2,6 +2,14 @@
#define RENDERPANEL_HH
#include <wx/wx.h>
+
+#include "SphereMaker.hh"
+#include "BoxMaker.hh"
+#include "CylinderMaker.hh"
+#include "PointLightMaker.hh"
+#include "SpotLightMaker.hh"
+#include "DirectionalLightMaker.hh"
+
#include "MouseEvent.hh"
namespace gazebo
@@ -32,9 +40,21 @@
/// \brief Create the camera
public: void CreateCamera();
+ private: void CreateEntity(std::string name);
+
private: UserCamera *userCamera;
private: MouseEvent mouseEvent;
+
+ private: EntityMaker *currMaker;
+ private: std::string cursorState;
+
+ private: CylinderMaker cylinderMaker;
+ private: BoxMaker boxMaker;
+ private: SphereMaker sphereMaker;
+ private: PointLightMaker pointLightMaker;
+ private: SpotLightMaker spotLightMaker;
+ private: DirectionalLightMaker directionalLightMaker;
};
}
Modified: code/gazebo/branches/wx/server/wx/SimulationApp.cc
===================================================================
--- code/gazebo/branches/wx/server/wx/SimulationApp.cc 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/server/wx/SimulationApp.cc 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -1,5 +1,6 @@
#include "SimulationFrame.hh"
#include "SimulationApp.hh"
+#include "Simulator.hh"
using namespace gazebo;
@@ -17,16 +18,13 @@
for (int i=0; i < argc; i++)
local_argv[i] = strdup(wxString(argv[i]).mb_str());
- std::cout << "Entry\n";
wxEntryStart(argc, local_argv);
wxTheApp->OnInit();
-
- this->eventThread = new boost::thread(boost::bind(&SimulationApp::EventLoop,
this));
-
- std::cout << "Done with Entry\n";
}
-void SimulationApp::EventLoop()
+////////////////////////////////////////////////////////////////////////////////
+// Run the gui
+void SimulationApp::Run()
{
wxTheApp->OnRun();
}
@@ -42,19 +40,28 @@
/// On Init
bool SimulationApp::OnInit()
{
- std::cout << "On Init\n";
this->frame = new SimulationFrame(NULL);
this->frame->Show();
this->SetTopWindow(this->frame);
+ //Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(SimulationApp::OnIdle) );
+ Connect( this->timer.GetId(), wxEVT_TIMER,
wxTimerEventHandler(SimulationApp::OnIdle), NULL, this );
+ this->timer.Start(33);
+
this->frame->CreateCameras();
return true;
}
+void SimulationApp::OnIdle(wxTimerEvent &evt)
+{
+ Simulator::Instance()->GraphicsUpdate();
+}
+
////////////////////////////////////////////////////////////////////////////////
/// Initalize the gui
void SimulationApp::Update()
{
+ this->frame->Update();
}
////////////////////////////////////////////////////////////////////////////////
Modified: code/gazebo/branches/wx/server/wx/SimulationApp.hh
===================================================================
--- code/gazebo/branches/wx/server/wx/SimulationApp.hh 2010-07-18 20:14:30 UTC
(rev 8826)
+++ code/gazebo/branches/wx/server/wx/SimulationApp.hh 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -1,5 +1,4 @@
-#include <wx/app.h>
-#include <boost/thread.hpp>
+#include <wx/wx.h>
namespace gazebo
{
@@ -15,20 +14,24 @@
/// \brief Init the simulation app
public: void Init();
- public: void EventLoop();
public: bool OnInit();
/// \brief Update the gui
public: void Update();
+ /// \brief Run the gui
+ public: void Run();
+
+ public: void OnIdle(wxTimerEvent &evt);
+
/// \brief Save the gui params in xml format
public: void Save(std::string &prefix, std::ostream &stream);
private: SimulationFrame *frame;
- /// Thread in which to run the gui
- private: boost::thread *eventThread;
+ private: wxTimer timer;
+
};
DECLARE_APP(SimulationApp)
Modified: code/gazebo/branches/wx/server/wx/SimulationFrame.cc
===================================================================
--- code/gazebo/branches/wx/server/wx/SimulationFrame.cc 2010-07-18
20:14:30 UTC (rev 8826)
+++ code/gazebo/branches/wx/server/wx/SimulationFrame.cc 2010-07-21
22:23:22 UTC (rev 8827)
@@ -1,4 +1,9 @@
+#include <wx/aui/aui.h>
+
+#include "Events.hh"
+#include "Image.hh"
#include "RenderPanel.hh"
+#include "TimePanel.hh"
#include "SimulationFrame.hh"
#include "Simulator.hh"
@@ -19,42 +24,164 @@
menuBar->Append( fileMenu, _("&File") );
SetMenuBar( menuBar );
- //CreateStatusBar();
- wxBoxSizer *vsizer = new wxBoxSizer(wxVERTICAL);
- wxBoxSizer *hsizer = new wxBoxSizer(wxHORIZONTAL);
+ this->renderPanel = new RenderPanel(this);
+ this->timePanel = new TimePanel(this);
- this->panel = new RenderPanel(this);
+ this->toolbar = NULL;
+#if !defined(__WXMAC__)
+ Image image;
- hsizer->Add(100, 0, 0);
- hsizer->Add( this->panel, 1, wxEXPAND, 0);
+ image.Load("control_play_blue.png");
+ wxBitmap play_bitmap(wxString::FromAscii(image.GetFilename().c_str()),
wxBITMAP_TYPE_PNG);
- vsizer->Add(hsizer,1,wxALIGN_LEFT | wxEXPAND);
- this->SetSizer(vsizer);
+ image.Load("control_pause_blue.png");
+ wxBitmap pause_bitmap(wxString::FromAscii(image.GetFilename().c_str()),
wxBITMAP_TYPE_PNG);
+
+ image.Load("control_end_blue.png");
+ wxBitmap step_bitmap(wxString::FromAscii(image.GetFilename().c_str()),
wxBITMAP_TYPE_PNG);
+
+
+ image.Load("sphere_create_blue.png");
+ wxBitmap sphere_bitmap(wxString::FromAscii(image.GetFilename().c_str()),
wxBITMAP_TYPE_PNG);
+
+ image.Load("box_create_blue.png");
+ wxBitmap box_bitmap(wxString::FromAscii(image.GetFilename().c_str()),
wxBITMAP_TYPE_PNG);
+
+ image.Load("cylinder_create_blue.png");
+ wxBitmap cylinder_bitmap(wxString::FromAscii(image.GetFilename().c_str()),
wxBITMAP_TYPE_PNG);
+
+ this->toolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxNO_BORDER|wxTB_HORIZONTAL);
+ this->toolbar->Connect( wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(
SimulationFrame::OnToolClicked), NULL , this );
+
+ this->toolbar->AddCheckTool(PLAY, wxT("Play"), play_bitmap, wxNullBitmap,
wxT("Play the simulation"));
+ this->toolbar->AddCheckTool(PAUSE, wxT("Pause"), pause_bitmap, wxNullBitmap,
wxT("Pause the simulation"));
+ this->toolbar->AddCheckTool(STEP, wxT("Step"), step_bitmap, wxNullBitmap,
wxT("Step the simulation"));
+ this->toolbar->AddSeparator();
+
+ this->toolbar->AddCheckTool(BOX, wxT("Box"), box_bitmap, wxNullBitmap,
wxT("Create a box"));
+ this->toolbar->AddCheckTool(SPHERE, wxT("Sphere"), sphere_bitmap,
wxNullBitmap, wxT("Create a sphere"));
+ this->toolbar->AddCheckTool(CYLINDER, wxT("Cylinder"), cylinder_bitmap,
wxNullBitmap, wxT("Create a cylinder"));
+ this->toolbar->Realize();
+
+#endif
+
+ this->auiManager = new wxAuiManager(this);
+ this->auiManager->AddPane(this->renderPanel,
wxAuiPaneInfo().CenterPane().Name(wxT("Render")));
+ this->auiManager->AddPane(this->timePanel,
wxAuiPaneInfo().RightDockable(false).LeftDockable(false).Bottom().Name(wxT("Time")).Caption(wxT("Time")));
+
+ if (this->toolbar)
+ this->auiManager->AddPane(this->toolbar,
wxAuiPaneInfo().ToolbarPane().RightDockable(false).LeftDockable(false).MinSize(100,30).Top().Name(wxT("Tools")).Caption(wxT("Tools")));
+ this->auiManager->Update();
+
+ this->auiManager->Update();
+
+ Simulator::Instance()->ConnectPauseSignal(
boost::bind(&SimulationFrame::OnPause, this, _1) );
}
////////////////////////////////////////////////////////////////////////////////
// Destructor
SimulationFrame::~SimulationFrame()
{
+ this->auiManager->UnInit();
+ delete this->auiManager;
}
////////////////////////////////////////////////////////////////////////////////
// Create the cameras
void SimulationFrame::CreateCameras()
{
- this->panel->CreateCamera();
+ this->renderPanel->CreateCamera();
}
////////////////////////////////////////////////////////////////////////////////
void SimulationFrame::Init()
{
- this->panel->Init();
+ this->renderPanel->Init();
+ this->OnPause(Simulator::Instance()->IsPaused());
}
////////////////////////////////////////////////////////////////////////////////
+void SimulationFrame::OnPause(bool pause)
+{
+ if (pause)
+ {
+ this->toolbar->ToggleTool(PLAY, false);
+ this->toolbar->ToggleTool(PAUSE, true);
+ }
+ else
+ {
+ this->toolbar->ToggleTool(PLAY, true);
+ this->toolbar->ToggleTool(PAUSE, false);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Update the frame
+void SimulationFrame::Update()
+{
+ this->timePanel->Update();
+}
+
+////////////////////////////////////////////////////////////////////////////////
void SimulationFrame::OnQuit(wxCommandEvent &event)
{
Simulator::Instance()->SetUserQuit();
Close(true);
}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimulationFrame::OnToolClicked( wxCommandEvent &event )
+{
+ int id = event.GetId();
+
+ if (id == PLAY)
+ {
+ this->toolbar->ToggleTool(PAUSE, false);
+ this->toolbar->ToggleTool(STEP, false);
+ Simulator::Instance()->SetPaused(false);
+ }
+ else if (id == PAUSE)
+ {
+ this->toolbar->ToggleTool(PLAY, false);
+ this->toolbar->ToggleTool(STEP, false);
+ Simulator::Instance()->SetPaused(true);
+ }
+ else if (id == STEP)
+ {
+ this->toolbar->ToggleTool(PLAY, false);
+ this->toolbar->ToggleTool(STEP, false);
+ Simulator::Instance()->SetStepInc( true );
+ }
+ else if (id == BOX)
+ {
+ this->toolbar->ToggleTool(SPHERE, false);
+ this->toolbar->ToggleTool(CYLINDER, false);
+
+ if (this->toolbar->GetToolState(BOX))
+ Events::createEntitySignal("box");
+ else
+ Events::createEntitySignal("");
+ }
+ else if (id == SPHERE)
+ {
+ this->toolbar->ToggleTool(BOX, false);
+ this->toolbar->ToggleTool(CYLINDER, false);
+
+ if (this->toolbar->GetToolState(SPHERE))
+ Events::createEntitySignal("sphere");
+ else
+ Events::createEntitySignal("");
+ }
+ else if (id == CYLINDER)
+ {
+ this->toolbar->ToggleTool(BOX, false);
+ this->toolbar->ToggleTool(SPHERE, false);
+
+ if (this->toolbar->GetToolState(CYLINDER))
+ Events::createEntitySignal("cylinder");
+ else
+ Events::createEntitySignal("");
+ }
+
+}
Modified: code/gazebo/branches/wx/server/wx/SimulationFrame.hh
===================================================================
--- code/gazebo/branches/wx/server/wx/SimulationFrame.hh 2010-07-18
20:14:30 UTC (rev 8826)
+++ code/gazebo/branches/wx/server/wx/SimulationFrame.hh 2010-07-21
22:23:22 UTC (rev 8827)
@@ -1,11 +1,16 @@
#include <wx/wx.h>
+class wxAuiManager;
+
namespace gazebo
{
class RenderPanel;
+ class TimePanel;
class SimulationFrame : public wxFrame
{
+ enum ToolbarButtons {PLAY, PAUSE, STEP, BOX, SPHERE, CYLINDER};
+
public: SimulationFrame(wxWindow *parent);
public: virtual ~SimulationFrame();
@@ -14,8 +19,18 @@
public: void Init();
+ public: void Update();
+
+ private: void OnPause(bool pause);
+
private: void OnQuit(wxCommandEvent &event);
- private: RenderPanel *panel;
+ private: void OnToolClicked( wxCommandEvent &event );
+
+ private: RenderPanel *renderPanel;
+ private: TimePanel *timePanel;
+
+ private: wxAuiManager *auiManager;
+ private: wxToolBar *toolbar;
};
}
Added: code/gazebo/branches/wx/server/wx/TimePanel.cc
===================================================================
--- code/gazebo/branches/wx/server/wx/TimePanel.cc
(rev 0)
+++ code/gazebo/branches/wx/server/wx/TimePanel.cc 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -0,0 +1,143 @@
+#include <wx/sizer.h>
+#include <wx/evtloop.h>
+
+#include "Simulator.hh"
+#include "TimePanel.hh"
+
+using namespace gazebo;
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Constructor
+TimePanel::TimePanel( wxWindow *parent )
+ : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(200,40),
wxTAB_TRAVERSAL)
+{
+ wxBoxSizer *boxSizer1 = new wxBoxSizer(wxHORIZONTAL);
+ wxBoxSizer *boxSizer2 = new wxBoxSizer(wxHORIZONTAL);
+ wxBoxSizer *boxSizer3 = new wxBoxSizer(wxHORIZONTAL);
+ wxBoxSizer *boxSizer4 = new wxBoxSizer(wxHORIZONTAL);
+ wxBoxSizer *boxSizer5 = new wxBoxSizer(wxHORIZONTAL);
+
+ this->percentRealTimeText = new wxStaticText( this, wxID_ANY, wxT("% Real
Time:"), wxDefaultPosition, wxDefaultSize, 0);
+ this->percentRealTimeText->Wrap(-1);
+ boxSizer2->Add(this->percentRealTimeText, 0, wxALL |
wxALIGN_CENTER_VERTICAL, 5);
+
+ this->percentRealTimeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
+ boxSizer2->Add(this->percentRealTimeCtrl, 1, wxALL|wxALIGN_CENTER_VERTICAL,
5);
+
+ boxSizer1->Add(boxSizer2, 1, wxEXPAND, 5);
+
+
+ this->simTimeText = new wxStaticText( this, wxID_ANY, wxT("Sim Time:"),
wxDefaultPosition, wxDefaultSize, 0);
+ this->simTimeText->Wrap(-1);
+ boxSizer3->Add(this->simTimeText, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
+
+ this->simTimeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
+ boxSizer3->Add(this->simTimeCtrl, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
+
+ boxSizer1->Add(boxSizer3, 1, wxEXPAND, 5);
+
+
+ this->realTimeText = new wxStaticText( this, wxID_ANY, wxT("Real Time:"),
wxDefaultPosition, wxDefaultSize, 0);
+ this->realTimeText->Wrap(-1);
+ boxSizer4->Add(this->realTimeText, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
+
+ this->realTimeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
+ boxSizer4->Add(this->realTimeCtrl, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
+
+ boxSizer1->Add(boxSizer4, 1, wxEXPAND, 5);
+
+
+ this->pauseTimeText = new wxStaticText( this, wxID_ANY, wxT("Pause Time:"),
wxDefaultPosition, wxDefaultSize, 0);
+ this->pauseTimeText->Wrap(-1);
+ boxSizer5->Add(this->pauseTimeText, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
+
+ this->pauseTimeCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
+ boxSizer5->Add(this->pauseTimeCtrl, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
+
+ boxSizer1->Add(boxSizer5, 1, wxEXPAND, 5);
+
+ this->SetSizer(boxSizer1);
+ this->Layout();
+
+ this->lastUpdateTime = 0;
+ this->statusUpdatePeriod = 0.05;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Destructor
+TimePanel::~TimePanel()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Update the time panel
+void TimePanel::Update()
+{
+ //while (wxEventLoop::GetActive()->Pending())
+ //wxEventLoop::GetActive()->Dispatch();
+
+ if (Simulator::Instance()->GetRealTime() - this->lastUpdateTime >
this->statusUpdatePeriod)
+ {
+ Time simTime = Simulator::Instance()->GetSimTime();
+ Time realTime = Simulator::Instance()->GetRealTime();
+ Time percent;
+
+ if (realTime < this->statusUpdatePeriod )
+ {
+ percent = ( simTime / realTime);
+ this->percentLastRealTime =0;
+ this->percentLastSimTime = 0;
+ }
+ else
+ {
+ percent = ((simTime - this->percentLastSimTime) /
+ (realTime - this->percentLastRealTime)).Double();
+
+ this->percentLastRealTime = realTime;
+ this->percentLastSimTime = simTime;
+ }
+
+ wxString simSuffix;
+ wxString realSuffix;
+
+ double simDbl = simTime.Double();
+ if (simDbl > 31536000)
+ simSuffix << simDbl/31536000 << wxT("\tdys");
+ else if (simDbl > 86400)
+ simSuffix << simDbl / 86400 << wxT("\tdys");
+ else if (simDbl > 3600)
+ simSuffix << simDbl/3600 << wxT("\thrs");
+ else if (simDbl > 999)
+ simSuffix << simDbl/60 << wxT("\tmin");
+ else
+ simSuffix << simDbl << wxT("\tsec");
+
+ double realDbl = realTime.Double();
+ if (realDbl > 31536000)
+ realSuffix << realDbl/31536000 << wxT("\tdys");
+ else if (realDbl > 86400)
+ realSuffix << realDbl/86400 << wxT("\tdys");
+ else if (realDbl > 3600)
+ realSuffix << realDbl/3600 << wxT("\thrs");
+ else if (realDbl > 999)
+ realSuffix << realDbl/60 << wxT("\tmin");
+ else
+ realSuffix << realDbl << wxT("\tsec");
+
+ wxString str;
+
+ str.Printf(wxT("%f"), percent.Double());
+ this->percentRealTimeCtrl->SetValue( str );
+
+ this->simTimeCtrl->SetValue(simSuffix);
+ this->realTimeCtrl->SetValue(realSuffix);
+
+ str.Printf(wxT("%f sec"), Simulator::Instance()->GetPauseTime().Double());
+ this->pauseTimeCtrl->SetValue(str);
+
+ this->lastUpdateTime = Simulator::Instance()->GetRealTime();
+ }
+
+}
Added: code/gazebo/branches/wx/server/wx/TimePanel.hh
===================================================================
--- code/gazebo/branches/wx/server/wx/TimePanel.hh
(rev 0)
+++ code/gazebo/branches/wx/server/wx/TimePanel.hh 2010-07-21 22:23:22 UTC
(rev 8827)
@@ -0,0 +1,35 @@
+#ifndef TIME_PANEL_HH
+#define TIME_PANEL_HH
+
+#include <wx/panel.h>
+#include <wx/stattext.h>
+#include <wx/textctrl.h>
+
+#include "Time.hh"
+namespace gazebo
+{
+ class TimePanel : public wxPanel
+ {
+ public: TimePanel( wxWindow *parent );
+ public: virtual ~TimePanel();
+
+ public: void Update();
+
+ private: wxStaticText *percentRealTimeText;
+ private: wxTextCtrl *percentRealTimeCtrl;
+
+ private: wxStaticText *simTimeText;
+ private: wxTextCtrl *simTimeCtrl;
+
+ private: wxStaticText *realTimeText;
+ private: wxTextCtrl *realTimeCtrl;
+
+ private: wxStaticText *pauseTimeText;
+ private: wxTextCtrl *pauseTimeCtrl;
+
+ private: Time lastUpdateTime,statusUpdatePeriod;
+ private: Time percentLastRealTime, percentLastSimTime;
+ };
+}
+
+#endif
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit