3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
10 #include <msp/gl/rendermode.h>
11 #include <msp/gl/select.h>
12 #include <msp/gl/texture.h>
13 #include <msp/datafile/parser.h>
21 Layout3D::Layout3D(Layout &l):
23 catalogue(layout.get_catalogue()),
26 layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added));
27 layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed));
32 while(!tracks.empty())
33 delete tracks.front();
36 void Layout3D::set_quality(unsigned q)
41 void Layout3D::add_track(Track3D &t)
46 void Layout3D::remove_track(Track3D &t)
48 list<Track3D *>::iterator i = find(tracks.begin(), tracks.end(), &t);
53 Track3D &Layout3D::get_track(const Track &t) const
55 for(list<Track3D *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
56 if(&(*i)->get_track()==&t)
59 throw KeyError("Unknown track");
62 Track3D *Layout3D::pick_track(float x, float y, float size) const
64 vector<GL::SelectRecord> select_buf;
65 GL::select_buffer(select_buf);
66 GL::render_mode(GL::SELECT);
76 glClipPlane(GL_CLIP_PLANE0, clip);
77 glEnable(GL_CLIP_PLANE0);
81 glClipPlane(GL_CLIP_PLANE1, clip);
82 glEnable(GL_CLIP_PLANE1);
87 glClipPlane(GL_CLIP_PLANE2, clip);
88 glEnable(GL_CLIP_PLANE2);
92 glClipPlane(GL_CLIP_PLANE3, clip);
93 glEnable(GL_CLIP_PLANE3);
99 glDisable(GL_CLIP_PLANE0);
100 glDisable(GL_CLIP_PLANE1);
101 glDisable(GL_CLIP_PLANE2);
102 glDisable(GL_CLIP_PLANE3);
104 GL::render_mode(GL::RENDER);
106 unsigned track_depth = numeric_limits<unsigned>::max();
107 for(vector<GL::SelectRecord>::iterator i=select_buf.begin(); i!=select_buf.end(); ++i)
108 if(i->min_depth<track_depth)
110 track = reinterpret_cast<Track3D *>(i->names.back());
111 track_depth = i->min_depth;
117 void Layout3D::track_added(Track &t)
119 new Track3D(*this, t);
122 void Layout3D::track_removed(Track &t)
124 for(list<Track3D *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
125 if(&(*i)->get_track()==&t)
132 } // namespace Marklin