command(format("request(%d, view, control, force)", id));
}
+void CentralStation::remove_loco(unsigned addr)
+{
+ unsigned id = map_address(locos, loco_addr, addr);
+ if(id)
+ command(format("release(%d, view, control)", id));
+}
+
void CentralStation::set_loco_speed(unsigned addr, unsigned speed)
{
if(speed && halted)
turnout.bits = type.get_state_bits();
}
+void CentralStation::remove_turnout(unsigned addr)
+{
+ remove_accessory(addr);
+}
+
void CentralStation::set_turnout(unsigned addr, unsigned state)
{
set_accessory_state(addr, MagnetAccessory::TURNOUT, state);
add_accessory(addr, MagnetAccessory::SIGNAL, MagnetAccessory::SEMAPHORE_HOME);
}
+void CentralStation::remove_signal(unsigned addr)
+{
+ remove_accessory(addr);
+}
+
void CentralStation::set_signal(unsigned addr, unsigned state)
{
set_accessory_state(addr, MagnetAccessory::SIGNAL, state);
}
}
+void CentralStation::remove_accessory(unsigned addr)
+{
+ unsigned id = map_address(accessories, accessory_addr, addr);
+ if(id)
+ command(format("release(%d, view, control)", id));
+}
+
void CentralStation::set_accessory_state(unsigned addr, MagnetAccessory::Type type, unsigned state)
{
unsigned id = map_address(accessories, accessory_addr, addr);
}
}
+void CentralStation::remove_sensor(unsigned)
+{
+}
+
bool CentralStation::get_sensor(unsigned addr) const
{
SensorMap::const_iterator i = sensors.find(addr);
virtual unsigned get_protocol_speed_steps(const std::string &) const;
virtual void add_loco(unsigned, const std::string &, const VehicleType &);
+ virtual void remove_loco(unsigned);
virtual void set_loco_speed(unsigned, unsigned);
virtual void set_loco_reverse(unsigned, bool);
virtual void set_loco_function(unsigned, unsigned, bool);
virtual void add_turnout(unsigned, const TrackType &);
+ virtual void remove_turnout(unsigned);
virtual void set_turnout(unsigned, unsigned);
virtual unsigned get_turnout(unsigned) const;
virtual void add_signal(unsigned, const SignalType &);
+ virtual void remove_signal(unsigned);
virtual void set_signal(unsigned, unsigned);
virtual unsigned get_signal(unsigned) const;
private:
MagnetAccessory &add_accessory(unsigned, MagnetAccessory::Type, MagnetAccessory::Symbol);
+ void remove_accessory(unsigned);
void set_accessory_state(unsigned, MagnetAccessory::Type, unsigned);
unsigned get_accessory_state(unsigned, MagnetAccessory::Type) const;
void accessory_state_changed(const MagnetAccessory &) const;
public:
virtual void add_sensor(unsigned);
+ virtual void remove_sensor(unsigned);
virtual void set_sensor(unsigned, bool) { }
virtual bool get_sensor(unsigned) const;
virtual const char *enumerate_protocols(unsigned) const = 0;
virtual unsigned get_protocol_speed_steps(const std::string &) const = 0;
virtual void add_loco(unsigned, const std::string &, const VehicleType &) = 0;
+ virtual void remove_loco(unsigned) = 0;
virtual void set_loco_speed(unsigned, unsigned) = 0;
virtual void set_loco_reverse(unsigned, bool) = 0;
virtual void set_loco_function(unsigned, unsigned, bool) = 0;
virtual void add_turnout(unsigned, const TrackType &) = 0;
+ virtual void remove_turnout(unsigned) = 0;
virtual void set_turnout(unsigned, unsigned) = 0;
virtual unsigned get_turnout(unsigned) const = 0;
virtual void add_signal(unsigned, const SignalType &) = 0;
+ virtual void remove_signal(unsigned) = 0;
virtual void set_signal(unsigned, unsigned) = 0;
virtual unsigned get_signal(unsigned) const = 0;
virtual void add_sensor(unsigned) = 0;
+ virtual void remove_sensor(unsigned) = 0;
virtual void set_sensor(unsigned, bool) = 0;
virtual bool get_sensor(unsigned) const = 0;
virtual const char *enumerate_protocols(unsigned) const;
virtual unsigned get_protocol_speed_steps(const std::string &) const;
virtual void add_loco(unsigned, const std::string &, const VehicleType &) { }
+ virtual void remove_loco(unsigned) { }
virtual void set_loco_speed(unsigned, unsigned);
virtual void set_loco_reverse(unsigned, bool);
virtual void set_loco_function(unsigned, unsigned, bool);
virtual void add_turnout(unsigned, const TrackType &);
+ virtual void remove_turnout(unsigned) { }
virtual void set_turnout(unsigned, unsigned);
virtual unsigned get_turnout(unsigned) const;
virtual void add_signal(unsigned, const SignalType &) { }
+ virtual void remove_signal(unsigned) { }
virtual void set_signal(unsigned, unsigned) { }
virtual unsigned get_signal(unsigned) const { return 0; }
virtual void add_sensor(unsigned) { }
+ virtual void remove_sensor(unsigned) { }
virtual void set_sensor(unsigned, bool);
virtual bool get_sensor(unsigned) const;
}
}
+void Intellibox::remove_loco(unsigned addr)
+{
+ locos.erase(addr);
+}
+
void Intellibox::set_loco_speed(unsigned addr, unsigned speed)
{
Locomotive &loco = locos[addr];
add_turnout(addr, type.get_state_bits(), false);
}
+void Intellibox::remove_turnout(unsigned addr)
+{
+ turnouts.erase(addr);
+}
+
void Intellibox::add_turnout(unsigned addr, unsigned bits, bool signal)
{
if(!turnouts.count(addr))
add_turnout(addr, 1, true);
}
+void Intellibox::remove_signal(unsigned addr)
+{
+ remove_turnout(addr);
+}
+
void Intellibox::set_signal(unsigned addr, unsigned state)
{
set_turnout(addr, state);
}
}
+void Intellibox::remove_sensor(unsigned addr)
+{
+ sensors.erase(addr);
+ update_sensors = true;
+}
+
bool Intellibox::get_sensor(unsigned addr) const
{
map<unsigned, Sensor>::const_iterator i = sensors.find(addr);
virtual const char *enumerate_protocols(unsigned) const;
virtual unsigned get_protocol_speed_steps(const std::string &) const;
virtual void add_loco(unsigned, const std::string &, const VehicleType &);
+ virtual void remove_loco(unsigned);
virtual void set_loco_speed(unsigned, unsigned);
virtual void set_loco_reverse(unsigned, bool);
virtual void set_loco_function(unsigned, unsigned, bool);
virtual void add_turnout(unsigned, const TrackType &);
+ virtual void remove_turnout(unsigned);
private:
void add_turnout(unsigned, unsigned, bool);
void turnout_state_changed(unsigned, const Turnout &) const;
virtual unsigned get_turnout(unsigned) const;
virtual void add_signal(unsigned, const SignalType &);
+ virtual void remove_signal(unsigned);
virtual void set_signal(unsigned, unsigned);
virtual unsigned get_signal(unsigned) const;
public:
virtual void add_sensor(unsigned);
+ virtual void remove_sensor(unsigned);
virtual void set_sensor(unsigned, bool) { }
virtual bool get_sensor(unsigned) const;
Sensor::~Sensor()
{
+ if(layout.has_driver() && address)
+ layout.get_driver().remove_sensor(address);
layout.remove(*this);
}
void Sensor::set_address(unsigned a)
{
+ Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0);
+ if(driver && address)
+ driver->remove_sensor(address);
address = a;
- if(layout.has_driver())
- layout.get_driver().add_sensor(address);
+ if(driver && address)
+ driver->add_sensor(address);
}
void Sensor::tick(const Time::TimeDelta &dt)
Signal::~Signal()
{
+ if(layout.has_driver() && address)
+ layout.get_driver().remove_sensor(address);
layout.remove(*this);
}
void Signal::set_address(unsigned a)
{
+ Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0);
+
+ if(driver && address)
+ driver->remove_signal(address);
address = a;
-
- if(layout.has_driver() && address)
- layout.get_driver().add_signal(address, type);
+ if(driver && address)
+ driver->add_signal(address, type);
}
void Signal::set_position(const Vector &p)
Track::~Track()
{
break_links();
+ if(layout.has_driver() && turnout_id)
+ layout.get_driver().remove_turnout(turnout_id);
layout.remove(*this);
}
if(!i)
throw invalid_argument("Track::set_turnout_id");
+ Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0);
+
+ if(driver && turnout_id)
+ driver->remove_turnout(turnout_id);
turnout_id = i;
layout.create_blocks(*this);
layout.update_routes();
- if(layout.has_driver() && turnout_id)
- layout.get_driver().add_turnout(turnout_id, type);
+ if(driver && turnout_id)
+ driver->add_turnout(turnout_id, type);
}
void Track::set_sensor_id(unsigned i)