Project

General

Profile

Revision 2eaafff2

ID2eaafff20f1014a2a7998573e21437aedd65eb45
Parent 962cda83
Child 9491b3e2

Added by Alex Zirbel about 12 years ago

Added maps and menus in scoutsim.

Menu options for about, quit, clear, and viewing different maps.

View differences:

scout/scoutsim/src/sim_frame.cpp
47 47

  
48 48
#include "sim_frame.h"
49 49

  
50
#include <stdio.h>
51

  
50 52
#include <ros/package.h>
51 53
#include <cstdlib>
52 54
#include <ctime>
53 55

  
54
#define DEFAULT_BG_R 0x45
55
#define DEFAULT_BG_G 0x56
56
#define DEFAULT_BG_B 0xff
56
using namespace std;
57 57

  
58 58
namespace scoutsim
59 59
{
60

  
61
    SimFrame::SimFrame(wxWindow* parent)
60
    SimFrame::SimFrame(wxWindow* parent, string map_name)
62 61
        : wxFrame(parent, wxID_ANY, wxT("ScoutSim"), wxDefaultPosition,
63 62
                  wxSize(500, 500), wxDEFAULT_FRAME_STYLE & ~wxRESIZE_BORDER)
64 63
          , frame_count(0)
65 64
          , id_counter(0)
66 65
    {
66
        std::cout << "Constructing sim frame." << std::endl;
67

  
67 68
        srand(time(NULL));
68 69

  
69 70
        update_timer = new wxTimer(this);
......
74 75
        Connect(wxEVT_PAINT, wxPaintEventHandler(SimFrame::onPaint),
75 76
                NULL, this);
76 77

  
77
        nh.setParam("background_r", DEFAULT_BG_R);
78
        nh.setParam("background_g", DEFAULT_BG_G);
79
        nh.setParam("background_b", DEFAULT_BG_B);
80

  
81 78
        std::string scouts[SCOUTSIM_NUM_SCOUTS] = 
82 79
        {
83 80
            "scout.png"
......
92 89
            scout_images[i].SetMaskColour(255, 255, 255);
93 90
        }
94 91

  
92
        /// @todo This should change.
95 93
        meter = scout_images[0].GetHeight();
96 94

  
97
        path_bitmap = wxBitmap(GetSize().GetWidth(), GetSize().GetHeight());
98
        path_dc.SelectObject(path_bitmap);
95
        base_map_name = map_name;
96
        display_map_name = ros::package::getPath("scoutsim") + "/maps/" + map_name + ".bmp";
99 97
        clear();
100 98

  
101 99
        clear_srv = nh.advertiseService("clear",
......
110 108
        ROS_INFO("Starting scoutsim with node name %s",
111 109
                 ros::this_node::getName().c_str()) ;
112 110

  
111
        wxMenu *menuFile = new wxMenu;
112
        menuFile->Append(ID_ABOUT, _("&About"));
113
        menuFile->AppendSeparator();
114
        menuFile->Append(ID_QUIT, _("E&xit"));
115

  
116
        wxMenu *menuSim = new wxMenu;
117
        menuSim->Append(ID_CLEAR, _("&Clear"));
118

  
119
        wxMenu *menuView = new wxMenu;
120
        menuView->Append(ID_MAP, _("&Map"));
121
        menuView->Append(ID_LINES, _("&Lines"));
122

  
123
        wxMenuBar *menuBar = new wxMenuBar;
124
        menuBar->Append(menuFile, _("&File"));
125
        menuBar->Append(menuSim, _("&Sim"));
126
        menuBar->Append(menuView, _("&View"));
127

  
128
        SetMenuBar(menuBar);
129

  
113 130
        width_in_meters = GetSize().GetWidth() / meter;
114 131
        height_in_meters = GetSize().GetHeight() / meter;
115 132
        spawnScout("", width_in_meters / 2.0, height_in_meters / 2.0, 0);
......
188 205
        return real_name;
189 206
    }
190 207

  
191
    void SimFrame::clear()
208
    void SimFrame::onQuit(wxCommandEvent& WXUNUSED(event))
209
    {
210
        Close(true);
211
    }
212

  
213
    void SimFrame::onAbout(wxCommandEvent& WXUNUSED(event))
214
    {
215
        wxMessageBox(_("Scoutsim is the simulator the Colony Project's scout robot.\n"
216
                       "\nThe Colony Project is a part of the Carnegie Mellon\n"
217
                       "Robotics Club. Our goal is to use cooperative low-cost\n"
218
                       "robots to solve challenging problems."),
219
                     _("About Scoutsim"),
220
                     wxOK | wxICON_INFORMATION, this );
221
    }
222

  
223
    void SimFrame::onClear(wxCommandEvent& WXUNUSED(event))
192 224
    {
193
        int r = DEFAULT_BG_R;
194
        int g = DEFAULT_BG_G;
195
        int b = DEFAULT_BG_B;
225
        clear();
226
    }
196 227

  
197
        nh.param("background_r", r, r);
198
        nh.param("background_g", g, g);
199
        nh.param("background_b", b, b);
228
    void SimFrame::showMap(wxCommandEvent& WXUNUSED(event))
229
    {
230
        display_map_name = ros::package::getPath("scoutsim") + "/maps/" +
231
                           base_map_name + ".bmp";
232
        clear();
233
    }
200 234

  
201
        path_dc.SetBackground(wxBrush(wxColour(r, g, b)));
235
    void SimFrame::showLines(wxCommandEvent& WXUNUSED(event))
236
    {
237
        display_map_name = ros::package::getPath("scoutsim") + "/maps/" +
238
                           base_map_name + "_lines.bmp";
239
        clear();
240
    }
241

  
242
    void SimFrame::clear()
243
    {
244
        path_dc.SetBackground(wxBrush(wxColour(100, 100, 100)));
202 245
        path_dc.Clear();
246

  
247
        path_bitmap.LoadFile(wxString::FromAscii(display_map_name.c_str()));
248
        path_dc.SelectObject(path_bitmap);
249
        SetSize(wxSize(path_bitmap.GetWidth(), path_bitmap.GetHeight()));
203 250
    }
204 251

  
205 252
    void SimFrame::onUpdate(wxTimerEvent& evt)

Also available in: Unified diff