/* $Id$
-This file is part of the MSP Märklin suite
-Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
+This file is part of R²C²
+Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
-#include <algorithm>
-#include <limits>
-#include <msp/gl/clip.h>
-#include <msp/gl/matrix.h>
-#include <msp/gl/rendermode.h>
-#include <msp/gl/select.h>
-#include <msp/gl/texture.h>
-#include <msp/datafile/parser.h>
#include "layout.h"
#include "track.h"
#include "vehicle.h"
using namespace std;
using namespace Msp;
-namespace Marklin {
+namespace R2C2 {
Layout3D::Layout3D(Layout &l):
layout(l),
layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added));
layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed));
layout.signal_vehicle_added.connect(sigc::mem_fun(this, &Layout3D::vehicle_added));
+ layout.signal_vehicle_removed.connect(sigc::mem_fun(this, &Layout3D::vehicle_removed));
const set<Track *> <racks = layout.get_tracks();
for(set<Track *>::iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
return *i->second;
}
-Track3D *Layout3D::pick_track(float x, float y, float size) const
-{
- vector<GL::SelectRecord> select_buf;
- GL::select_buffer(select_buf);
- GL::render_mode(GL::SELECT);
-
- {
- GL::PushMatrix push_mat;
- GL::load_identity();
-
- GL::ClipPlane(1, 0, x-size, 0).apply_to(0);
- GL::ClipPlane(-1, 0, -x-size, 0).apply_to(1);
- GL::ClipPlane(0, 1, y-size, 0).apply_to(2);
- GL::ClipPlane(0, -1, -y-size, 0).apply_to(3);
- }
-
- scene.render(0);
-
- GL::ClipPlane::disable(0);
- GL::ClipPlane::disable(1);
- GL::ClipPlane::disable(2);
- GL::ClipPlane::disable(3);
-
- GL::render_mode(GL::RENDER);
- Track3D *track = 0;
- unsigned track_depth = numeric_limits<unsigned>::max();
- for(vector<GL::SelectRecord>::iterator i=select_buf.begin(); i!=select_buf.end(); ++i)
- if(i->min_depth<track_depth && !i->names.empty())
- {
- track = reinterpret_cast<Track3D *>(i->names.back());
- track_depth = i->min_depth;
- }
-
- return track;
-}
-
void Layout3D::add_vehicle(Vehicle3D &v)
{
if(vehicles.count(&v.get_vehicle()))
new Vehicle3D(*this, v);
}
-} // namespace Marklin
+void Layout3D::vehicle_removed(Vehicle &v)
+{
+ VehicleMap::iterator i = vehicles.find(&v);
+ if(i!=vehicles.end())
+ delete i->second;
+}
+
+} // namespace R2C2