X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Flayout.cpp;h=6042515962436807ebaae6ba2be60ca3b50dee05;hb=e621dd4120cb253417167b4295e436cee095ccb0;hp=2881e8d33c82ed23d8c5c6edcffa09e684b8f8fa;hpb=495c54e187ddbb7514c983e1829a69d82ccad5f3;p=r2c2.git diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index 2881e8d..6042515 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -1,11 +1,5 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include "layout.h" +#include "signal.h" #include "track.h" #include "vehicle.h" @@ -26,6 +20,8 @@ Layout3D::Layout3D(Layout &l): 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)); + layout.signal_signal_added.connect(sigc::mem_fun(this, &Layout3D::signal_added)); + layout.signal_signal_removed.connect(sigc::mem_fun(this, &Layout3D::signal_removed)); const set <racks = layout.get_tracks(); for(set::iterator i=ltracks.begin(); i!=ltracks.end(); ++i) @@ -58,10 +54,7 @@ void Layout3D::get_bounds(Vector &minp, Vector &maxp) const void Layout3D::add_track(Track3D &t) { - if(tracks.count(&t.get_track())) - throw KeyError("Duplicate track"); - - tracks[&t.get_track()] = &t; + insert_unique(tracks, &t.get_track(), &t); } void Layout3D::remove_track(Track3D &t) @@ -71,19 +64,12 @@ void Layout3D::remove_track(Track3D &t) Track3D &Layout3D::get_track(Track &t) const { - TrackMap::const_iterator i = tracks.find(&t); - if(i==tracks.end()) - throw KeyError("Unknown track"); - - return *i->second; + return *get_item(tracks, &t); } void Layout3D::add_vehicle(Vehicle3D &v) { - if(vehicles.count(&v.get_vehicle())) - throw KeyError("Duplicate vehicle"); - - vehicles[&v.get_vehicle()] = &v; + insert_unique(vehicles, &v.get_vehicle(), &v); } void Layout3D::remove_vehicle(Vehicle3D &v) @@ -93,11 +79,22 @@ void Layout3D::remove_vehicle(Vehicle3D &v) Vehicle3D &Layout3D::get_vehicle(Vehicle &v) const { - VehicleMap::const_iterator i = vehicles.find(&v); - if(i==vehicles.end()) - throw KeyError("Unknown vehicle"); + return *get_item(vehicles, &v); +} + +void Layout3D::add_signal(Signal3D &s) +{ + insert_unique(signals, &s.get_signal(), &s); +} + +void Layout3D::remove_signal(Signal3D &s) +{ + signals.erase(&s.get_signal()); +} - return *i->second; +Signal3D &Layout3D::get_signal(Signal &s) const +{ + return *get_item(signals, &s); } void Layout3D::track_added(Track &t) @@ -124,4 +121,16 @@ void Layout3D::vehicle_removed(Vehicle &v) delete i->second; } +void Layout3D::signal_added(Signal &s) +{ + new Signal3D(*this, s); +} + +void Layout3D::signal_removed(Signal &s) +{ + SignalMap::iterator i = signals.find(&s); + if(i!=signals.end()) + delete i->second; +} + } // namespace R2C2