}
}
-void Zonebar::zone_renamed(Zone &zone, const string &group, const string &, unsigned)
+void Zonebar::zone_renamed(Zone &zone, const string &)
{
+ const string &group = zone.get_group();
const set<Zone *> &lzones = designer.get_layout().get_all<Zone>();
set<string> group_names;
for(set<Zone *>::const_iterator i=lzones.begin(); i!=lzones.end(); ++i)
private:
void track_chain_added(R2C2::TrackChain &);
void track_chain_removed(R2C2::TrackChain &);
- void zone_renamed(R2C2::Zone &, const std::string &, const std::string &, unsigned);
+ void zone_renamed(R2C2::Zone &, const std::string &);
void group_selected(unsigned);
void number_selected(unsigned);
void delete_zone_clicked();
#include <algorithm>
+#include <msp/strings/format.h>
#include <msp/time/units.h>
#include "block.h"
#include "driver.h"
delete sensor;
}
+void Block::set_name(const string &)
+{
+ throw logic_error("Block names can't be set");
+}
+
void Block::on_track_added(Track &track)
{
track.set_block(this);
void Block::determine_id()
{
+ string n;
if(sensor_addr)
+ {
id = 0x1000|sensor_addr;
+ n = format("Sensor %d", sensor_addr);
+ }
else if(turnout_addr)
+ {
id = 0x2000|turnout_addr;
+ n = format("Turnout %d", turnout_addr);
+ }
else if(endpoints.size()==2)
{
unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1;
unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1;
id = 0x10000 | id1;
}
+
+ if(n.empty())
+ n = format("Block %x", id);
+
+ name = n;
+ signal_name_changed.emit(name);
}
Block(Layout &, Track &);
~Block();
+ virtual void set_name(const std::string &);
+
private:
virtual void on_track_added(Track &);
virtual Validity check_validity(Track &) const;
layout.remove(*this);
}
-void Route::set_name(const string &n)
-{
- name = n;
- signal_name_changed.emit(name);
-}
-
void Route::set_temporary(bool t)
{
temporary = t;
Route::Loader::Loader(Route &r):
DataFile::ObjectLoader<Route>(r)
{
- add("name", &Route::name);
+ add("name", &Loader::name);
add("turnout", &Loader::turnout);
}
}
}
+void Route::Loader::name(const string &n)
+{
+ obj.name = n;
+}
+
void Route::Loader::turnout(unsigned id, unsigned path)
{
turnouts[id] = path;
Loader(Route &);
private:
virtual void finish();
+ void name(const std::string &);
void turnout(unsigned, unsigned);
};
- sigc::signal<void, const std::string &> signal_name_changed;
-
private:
- std::string name;
bool temporary;
TurnoutMap turnouts;
Route(Layout &);
~Route();
- void set_name(const std::string &);
- const std::string &get_name() const { return name; }
void set_temporary(bool);
bool is_temporary() const { return temporary; }
void update_turnouts();
#include "track.h"
#include "trackchain.h"
+using namespace std;
+
namespace R2C2 {
TrackChain::TrackChain(Layout &l):
layout.signal_object_removed.connect(sigc::mem_fun(this, &TrackChain::object_removed));
}
+void TrackChain::set_name(const string &n)
+{
+ name = n;
+ signal_name_changed.emit(name);
+}
+
void TrackChain::add_track(Track &track)
{
if(tracks.count(&track))
};
public:
+ sigc::signal<void, const std::string &> signal_name_changed;
sigc::signal<void, Track &> signal_track_added;
sigc::signal<void, Track &> signal_track_removed;
Layout &layout;
+ std::string name;
TrackSet tracks;
TrackIter ends[2];
public:
virtual ~TrackChain() { }
+ virtual void set_name(const std::string &);
+ const std::string &get_name() const { return name; }
+
void add_track(Track &);
void add_tracks(const TrackSet &);
protected:
#include <msp/strings/format.h>
+#include <msp/strings/regex.h>
#include "block.h"
#include "layout.h"
#include "track.h"
layout.remove(*this);
}
+void Zone::set_name(const string &n)
+{
+ Regex r_name("(.+) ([^ ]+) ([1-9][0-9]*)");
+ RegMatch m = r_name.match(n);
+ if(!m)
+ throw invalid_argument("Zone::set_name");
+
+ set_name(m[1].str, m[2].str, lexical_cast<unsigned>(m[3].str));
+}
+
void Zone::set_name(const string &g, const string &q, unsigned n)
{
group = g;
qualifier = q;
number = n;
- signal_name_changed.emit(group, qualifier, number);
-}
-
-string Zone::get_name() const
-{
- string result = group;
+ string full_name = group;
if(!qualifier.empty())
{
- result += ' ';
- result += qualifier;
+ full_name += ' ';
+ full_name += qualifier;
}
if(number)
- result += format(" %d", number);
- return result;
+ full_name += format(" %d", number);
+ TrackChain::set_name(full_name);
}
void Zone::save(list<DataFile::Statement> &st) const
void block(unsigned);
};
- sigc::signal<void, const std::string &, const std::string &, unsigned> signal_name_changed;
-
private:
std::string group;
std::string qualifier;
Zone(Layout &);
~Zone();
+ virtual void set_name(const std::string &);
void set_name(const std::string &, const std::string &, unsigned);
const std::string &get_group() const { return group; }
const std::string &get_qualifier() const { return qualifier; }
unsigned get_number() const { return number; }
- std::string get_name() const;
void save(std::list<Msp::DataFile::Statement> &) const;
};