Revision: 8835
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8835&view=rev
Author:   natepak
Date:     2010-07-27 14:49:44 +0000 (Tue, 27 Jul 2010)

Log Message:
-----------
Added a pop-up menu for the tree browser

Modified Paths:
--------------
    code/gazebo/branches/wx/server/wx/SimulationFrame.cc
    code/gazebo/branches/wx/server/wx/SimulationFrame.hh

Modified: code/gazebo/branches/wx/server/wx/SimulationFrame.cc
===================================================================
--- code/gazebo/branches/wx/server/wx/SimulationFrame.cc        2010-07-26 
19:48:56 UTC (rev 8834)
+++ code/gazebo/branches/wx/server/wx/SimulationFrame.cc        2010-07-27 
14:49:44 UTC (rev 8835)
@@ -1,7 +1,9 @@
 #include <wx/aui/aui.h>
-#include <wx/treectrl.h>
+#include <stack>
 
 #include "propgrid/propgrid.h"
+#include "OgreCamera.hh"
+#include "CameraManager.hh"
 #include "World.hh"
 #include "Entity.hh"
 #include "Model.hh"
@@ -46,6 +48,7 @@
   this->propGrid->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( 
SimulationFrame::OnPropertyChanged), NULL, this);
 
   Connect(this->treeCtrl->GetId(), wxEVT_COMMAND_TREE_SEL_CHANGED, 
wxTreeEventHandler(SimulationFrame::OnTreeClick), NULL, this); 
+  this->treeCtrl->Connect(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, 
wxTreeEventHandler(SimulationFrame::OnTreeRightClick), NULL, this);
 
 
   this->MakeToolbar();
@@ -67,6 +70,7 @@
  Simulator::Instance()->ConnectPauseSignal( 
boost::bind(&SimulationFrame::OnPause, this, _1) );
 
  World::Instance()->ConnectAddEntitySignal( 
boost::bind(&SimulationFrame::AddEntityCB, this, _1) );
+ World::Instance()->ConnectDeleteEntitySignal( 
boost::bind(&SimulationFrame::DeleteEntityCB, this, _1) );
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -123,6 +127,43 @@
 }
 
 
////////////////////////////////////////////////////////////////////////////////
+// Delete entity callback
+void SimulationFrame::DeleteEntityCB(const std::string &name)
+{
+  this->treeCtrl->Delete( this->FindTreeItem(name) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Find an item in a tree
+wxTreeItemId SimulationFrame::FindTreeItem(const std::string &name)
+{
+  std::stack<wxTreeItemId> items;
+
+  if (this->treeCtrl->GetRootItem().IsOk())
+    items.push(this->treeCtrl->GetRootItem());
+
+  while (!items.empty())
+  {
+    wxTreeItemId next = items.top();
+    items.pop();
+
+    if (next != this->treeCtrl->GetRootItem() && 
+       ((EntityTreeItemData*)this->treeCtrl->GetItemData(next))->name == name)
+      return next;
+
+    wxTreeItemIdValue cookie;
+    wxTreeItemId nextChild = this->treeCtrl->GetFirstChild(next, cookie);
+    while (nextChild.IsOk())
+    {
+      items.push(nextChild);
+      nextChild = this->treeCtrl->GetNextSibling(nextChild);
+    }
+  }
+
+  return wxTreeItemId();
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void SimulationFrame::OnPause(bool pause)
 {
   if (pause)
@@ -291,6 +332,46 @@
 }
 
 
////////////////////////////////////////////////////////////////////////////////
+// Callback when an entity in the tree is clicked
+void SimulationFrame::OnTreeRightClick(wxTreeEvent &event)
+{
+  EntityTreeItemData *data = 
(EntityTreeItemData*)this->treeCtrl->GetItemData(event.GetItem());
+
+  if (data->name != "World")
+  {
+    wxMenu mnu;
+    mnu.Append(0,  wxT("Move to"));
+    mnu.Append(1,  wxT("Modify"));
+    mnu.Append(2,  wxT("Delete"));
+    mnu.Connect(wxEVT_COMMAND_MENU_SELECTED, 
(wxObjectEventFunction)&SimulationFrame::OnTreePopupClick, NULL, this);
+    PopupMenu(&mnu);
+  }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// When a popup menu item has been click in the tree widget
+void SimulationFrame::OnTreePopupClick( wxCommandEvent &event )
+{
+  EntityTreeItemData *data = 
(EntityTreeItemData*)this->treeCtrl->GetItemData(this->treeCtrl->GetSelection());
+
+  Entity *ent = World::Instance()->GetEntityByName(data->name);
+
+  if (ent)
+  {
+    if (event.GetId() == 0)
+    {
+      OgreCamera *cam = CameraManager::Instance()->GetActiveCamera();
+      if (cam)
+        cam->MoveToEntity(ent);
+    }
+    else if (event.GetId() == 1)
+      World::Instance()->SetSelectedEntity(ent);
+    else if (event.GetId() == 2)
+      World::Instance()->DeleteEntity(data->name);
+  }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 // On property changed event callback
 void SimulationFrame::OnPropertyChanged(wxPropertyGridEvent &event)
 {

Modified: code/gazebo/branches/wx/server/wx/SimulationFrame.hh
===================================================================
--- code/gazebo/branches/wx/server/wx/SimulationFrame.hh        2010-07-26 
19:48:56 UTC (rev 8834)
+++ code/gazebo/branches/wx/server/wx/SimulationFrame.hh        2010-07-27 
14:49:44 UTC (rev 8835)
@@ -1,11 +1,10 @@
 #include <wx/wx.h>
+#include <wx/treectrl.h>
 
 class wxAuiManager;
 class wxAuiManagerEvent;
 class wxPropertyGrid;
 class wxPropertyGridEvent;
-class wxTreeCtrl;
-class wxTreeEvent;
 
 namespace gazebo
 {
@@ -37,16 +36,25 @@
 
     private: void OnTreeClick(wxTreeEvent &event);
 
+    /// \brief Callback when an entity in the tree is clicked
+    private: void OnTreeRightClick(wxTreeEvent &event);
+
+    /// \brief When a popup menu item has been click in the tree widget
+    private: void OnTreePopupClick( wxCommandEvent &event );
+
     private: void OnPropertyChanged(wxPropertyGridEvent &event);
 
     /// \brief Make the toolbar
     private: void MakeToolbar();
 
-    // \brief Add entity CB
+    /// \brief Add entity CB
     private: void AddEntityCB(const Entity *entity);
 
+    /// \brief Delete entity CB
+    private: void DeleteEntityCB(const std::string &name);
+    /// \brief Find an item in a tree
+    private: wxTreeItemId FindTreeItem(const std::string &name);
 
-
     private: RenderPanel *renderPanel;
     private: TimePanel *timePanel;
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to