3 This file is part of R²C²
4 Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
17 Layout3D::Layout3D(Layout &l):
19 catalogue(layout.get_catalogue())
21 // South, 15° from zenith
22 sun.set_position(0, -0.259, 0.966, 0);
23 lighting.attach(0, sun);
25 layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added));
26 layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed));
27 layout.signal_vehicle_added.connect(sigc::mem_fun(this, &Layout3D::vehicle_added));
28 layout.signal_vehicle_removed.connect(sigc::mem_fun(this, &Layout3D::vehicle_removed));
30 const set<Track *> <racks = layout.get_tracks();
31 for(set<Track *>::iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
37 while(!tracks.empty())
38 delete tracks.begin()->second;
39 while(!vehicles.empty())
40 delete vehicles.begin()->second;
43 void Layout3D::get_bounds(Vector &minp, Vector &maxp) const
45 minp = maxp = Vector();
47 for(TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
51 i->second->get_bounds(0, tmin, tmax);
52 minp.x = min(minp.x, tmin.x);
53 minp.y = min(minp.y, tmin.y);
54 maxp.x = max(maxp.x, tmax.x);
55 maxp.y = max(maxp.y, tmax.y);
59 void Layout3D::add_track(Track3D &t)
61 if(tracks.count(&t.get_track()))
62 throw KeyError("Duplicate track");
64 tracks[&t.get_track()] = &t;
67 void Layout3D::remove_track(Track3D &t)
69 tracks.erase(&t.get_track());
72 Track3D &Layout3D::get_track(Track &t) const
74 TrackMap::const_iterator i = tracks.find(&t);
76 throw KeyError("Unknown track");
81 void Layout3D::add_vehicle(Vehicle3D &v)
83 if(vehicles.count(&v.get_vehicle()))
84 throw KeyError("Duplicate vehicle");
86 vehicles[&v.get_vehicle()] = &v;
89 void Layout3D::remove_vehicle(Vehicle3D &v)
91 vehicles.erase(&v.get_vehicle());
94 Vehicle3D &Layout3D::get_vehicle(Vehicle &v) const
96 VehicleMap::const_iterator i = vehicles.find(&v);
98 throw KeyError("Unknown vehicle");
103 void Layout3D::track_added(Track &t)
105 new Track3D(*this, t);
108 void Layout3D::track_removed(Track &t)
110 TrackMap::iterator i = tracks.find(&t);
115 void Layout3D::vehicle_added(Vehicle &v)
117 new Vehicle3D(*this, v);
120 void Layout3D::vehicle_removed(Vehicle &v)
122 VehicleMap::iterator i = vehicles.find(&v);
123 if(i!=vehicles.end())