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/clip.h>
11 #include <msp/gl/matrix.h>
12 #include <msp/gl/rendermode.h>
13 #include <msp/gl/select.h>
14 #include <msp/gl/texture.h>
15 #include <msp/datafile/parser.h>
23 Layout3D::Layout3D(Layout &l):
25 catalogue(layout.get_catalogue()),
28 layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added));
29 layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed));
31 const set<Track *> <racks = layout.get_tracks();
32 for(set<Track *>::iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
38 while(!tracks.empty())
39 delete tracks.front();
42 void Layout3D::set_quality(unsigned q)
47 void Layout3D::add_track(Track3D &t)
52 void Layout3D::remove_track(Track3D &t)
54 list<Track3D *>::iterator i = find(tracks.begin(), tracks.end(), &t);
59 Track3D &Layout3D::get_track(const Track &t) const
61 for(list<Track3D *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
62 if(&(*i)->get_track()==&t)
65 throw KeyError("Unknown track");
68 Track3D *Layout3D::pick_track(float x, float y, float size) const
70 vector<GL::SelectRecord> select_buf;
71 GL::select_buffer(select_buf);
72 GL::render_mode(GL::SELECT);
75 GL::PushMatrix push_mat;
78 GL::ClipPlane(1, 0, x-size, 0).apply_to(0);
79 GL::ClipPlane(-1, 0, -x-size, 0).apply_to(1);
80 GL::ClipPlane(0, 1, y-size, 0).apply_to(2);
81 GL::ClipPlane(0, -1, -y-size, 0).apply_to(3);
86 GL::ClipPlane::disable(0);
87 GL::ClipPlane::disable(1);
88 GL::ClipPlane::disable(2);
89 GL::ClipPlane::disable(3);
91 GL::render_mode(GL::RENDER);
93 unsigned track_depth = numeric_limits<unsigned>::max();
94 for(vector<GL::SelectRecord>::iterator i=select_buf.begin(); i!=select_buf.end(); ++i)
95 if(i->min_depth<track_depth)
97 track = reinterpret_cast<Track3D *>(i->names.back());
98 track_depth = i->min_depth;
104 void Layout3D::track_added(Track &t)
106 new Track3D(*this, t);
109 void Layout3D::track_removed(Track &t)
111 for(list<Track3D *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
112 if(&(*i)->get_track()==&t)
119 } // namespace Marklin