if(argc>1)
{
- layout->load(argv[1]);
+ DataFile::load(*layout, argv[1]);
const list<Track3D *> <racks=layout_3d->get_tracks();
for(list<Track3D *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
{
#include <GL/gl.h>
#include <msp/core/except.h>
#include <msp/core/getopt.h>
+#include <msp/fs/stat.h>
#include <msp/gbase/display.h>
#include <msp/gbase/window.h>
#include <msp/gl/immediate.h>
using namespace Marklin;
using namespace Msp;
-#include <iostream>
-
Engineer::Engineer(int argc, char **argv):
screen_w(1280),
screen_h(960),
const vector<string> &args=getopt.get_args();
if(args.empty())
throw UsageError("No layout given");
- layout.load(args.front());
+ DataFile::load(layout, args.front());
trfc_mgr=new TrafficManager(control, layout);
trfc_mgr->signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved));
+ if(FS::exists("engineer.state"))
+ DataFile::load(*trfc_mgr, "engineer.state");
const map<unsigned, Sensor *> &sensors=control.get_sensors();
for(map<unsigned, Sensor *>::const_iterator i=sensors.begin(); i!=sensors.end(); ++i)
Engineer::~Engineer()
{
+ trfc_mgr->save("engineer.state");
delete trfc_mgr;
}
main_panel->set_position(0, screen_h-main_panel->get_geometry().h);
main_panel->set_visible(true);
+ const list<Train *> &trains=trfc_mgr->get_trains();
+ int y=main_panel->get_geometry().y;
+ for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
+ {
+ TrainPanel *tpanel=new TrainPanel(*this, ui_res, **i);
+ root->add(*tpanel);
+ tpanel->set_position(0, y-tpanel->get_geometry().h);
+ train_panels.push_back(tpanel);
+ tpanel->set_visible(true);
+ y-=tpanel->get_geometry().h;
+ }
+
wnd->show();
Application::main();
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
Catalogue::Loader::Loader(Catalogue &c):
- cat(c)
+ DataFile::BasicLoader<Catalogue>(c)
{
add("locomotive", &Loader::locomotive);
add("track", &Loader::track);
}
-void Catalogue::Loader::locomotive(unsigned art_no)
+void Catalogue::Loader::locomotive(unsigned art_nr)
{
- map<unsigned, LocoType *>::iterator i=cat.locos.find(art_no);
- if(i!=cat.locos.end())
+ if(obj.locos.count(art_nr))
throw Exception("Duplicate locomotive number");
- RefPtr<LocoType> loco=new LocoType(art_no);
+ RefPtr<LocoType> loco=new LocoType(art_nr);
load_sub(*loco);
- unsigned art_nr=loco->get_article_number();
- cat.locos[art_nr]=loco.release();
+ obj.locos[art_nr]=loco.release();
}
-void Catalogue::Loader::track(unsigned art_no)
+void Catalogue::Loader::track(unsigned art_nr)
{
- map<unsigned, TrackType *>::iterator i=cat.tracks.find(art_no);
- if(i!=cat.tracks.end())
+ if(obj.tracks.count(art_nr))
throw Exception("Duplicate track number");
- RefPtr<TrackType> trk=new TrackType(art_no);
+ RefPtr<TrackType> trk=new TrackType(art_nr);
load_sub(*trk);
- unsigned art_nr=trk->get_article_number();
- cat.tracks[art_nr]=trk.release();
+ obj.tracks[art_nr]=trk.release();
}
} // namespace Marklin
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
class Catalogue
{
public:
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::BasicLoader<Catalogue>
{
public:
Loader(Catalogue &);
private:
- Catalogue &cat;
-
void locomotive(unsigned);
void track(unsigned);
};
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2008-2009 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
#include "constants.h"
using namespace std;
Distributed under the GPL
*/
-#include <fstream>
#include <msp/core/refptr.h>
#include <msp/datafile/parser.h>
+#include <msp/datafile/writer.h>
#include "catalogue.h"
#include "layout.h"
#include "tracktype.h"
namespace Marklin {
-Layout::Layout(Catalogue &c):
+Layout::Layout(const Catalogue &c):
catalogue(c)
{ }
(*i)->snap_to(**j, true);
}
-void Layout::load(const string &fn)
+void Layout::save(const string &fn)
{
- IO::File in(fn);
- IO::Buffered inb(in);
-
- filename=fn;
- DataFile::Parser parser(inb, fn);
- Loader loader(*this);
- loader.load(parser);
-
- check_links();
-
+ IO::BufferedFile out(fn, IO::M_WRITE);
+ DataFile::Writer writer(out);
+ if(!base.empty())
+ writer.write((DataFile::Statement("base"), base));
for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
- (*i)->check_slope();
-}
-
-int Layout::save(const string &fn)
-{
- ofstream out(fn.c_str());
+ {
+ DataFile::Statement st("track");
+ st.append((*i)->get_type().get_article_number());
+ (*i)->save(st.sub);
+ writer.write(st);
+ }
+ /*ofstream out(fn.c_str());
if(!out) return -1;
filename=fn;
out<<"};\n";
}
- return 0;
+ return 0;*/
}
Layout::Loader::Loader(Layout &l):
- layout(l)
+ DataFile::BasicLoader<Layout>(l)
{
add("base", &Layout::base);
add("track", &Loader::track);
}
+void Layout::Loader::finish()
+{
+ obj.check_links();
+
+ for(set<Track *>::iterator i=obj.tracks.begin(); i!=obj.tracks.end(); ++i)
+ (*i)->check_slope();
+}
+
void Layout::Loader::track(unsigned art_nr)
{
- TrackType &type=layout.catalogue.get_track(art_nr);
+ TrackType &type=obj.catalogue.get_track(art_nr);
RefPtr<Track> trk=new Track(type);
load_sub(*trk);
- layout.add_track(*trk.release());
+ obj.add_track(*trk.release());
}
} // namespace Marklin
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
class Layout
{
public:
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::BasicLoader<Layout>
{
public:
Loader(Layout &);
- Layout &get_object() { return layout; }
private:
- Layout &layout;
-
+ virtual void finish();
void track(unsigned);
};
private:
- Catalogue &catalogue;
- std::string filename;
+ const Catalogue &catalogue;
std::string base;
std::set<Track *> tracks;
//RouteSeq routes;
sigc::signal<void, Track &> signal_track_added;
sigc::signal<void, Track &> signal_track_removed;
- Layout(Catalogue &);
+ Layout(const Catalogue &);
~Layout();
+ const Catalogue &get_catalogue() const { return catalogue; }
const std::string &get_base() const { return base; }
const std::set<Track *> &get_tracks() const { return tracks; }
void add_track(Track &);
void remove_track(Track &);
void check_links();
- void load(const std::string &);
- int save(const std::string &);
+ void save(const std::string &);
};
} // namespace Marklin
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
LocoType::Loader::Loader(LocoType <):
- ltype(lt)
+ Msp::DataFile::BasicLoader<LocoType>(lt)
{
add("function", &Loader::function);
add("name", &LocoType::name);
void LocoType::Loader::function(unsigned i, const string &f)
{
- ltype.funcs[i]=f;
+ obj.funcs[i]=f;
}
} // namespace Marklin
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
class LocoType
{
public:
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::BasicLoader<LocoType>
{
- private:
- LocoType <ype;
-
public:
Loader(LocoType &);
- LocoType &get_object() const { return ltype; }
private:
void function(unsigned, const std::string &);
};
using namespace std;
using namespace Msp;
-#include <iostream>
-
namespace Marklin {
Track::Track(const TrackType &t):
return trk;
}
-/*******************
-** Track::Loader
-*/
+void Track::save(list<DataFile::Statement> &st) const
+{
+ st.push_back((DataFile::Statement("position"), pos.x, pos.y, pos.z));
+ st.push_back((DataFile::Statement("rotation"), rot));
+ st.push_back((DataFile::Statement("slope"), slope));
+ if(turnout_id)
+ st.push_back((DataFile::Statement("turnout_id"), turnout_id));
+ if(sensor_id)
+ st.push_back((DataFile::Statement("sensor_id"), sensor_id));
+ if(flex)
+ st.push_back((DataFile::Statement("flex"), true));
+}
+
Track::Loader::Loader(Track &t):
- track(t)
+ DataFile::BasicLoader<Track>(t)
{
add("position", &Loader::position);
add("rotation", &Track::rot);
void Track::Loader::position(float x, float y, float z)
{
- track.pos=Point(x, y, z);
+ obj.pos=Point(x, y, z);
}
} // namespace Marklin
class Track
{
public:
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::BasicLoader<Track>
{
- private:
- Track &track;
-
public:
Loader(Track &);
- Track &get_object() { return track; }
private:
void position(float, float, float);
};
won't have any links to other tracks, nor a turnout or sensor id.
*/
Track *copy() const;
+
+ void save(std::list<Msp::DataFile::Statement> &) const;
private:
// Direct copying not allowed due to links. See the copy() function.
TrackPart::Loader::Loader(TrackPart &p):
- part(p)
+ Msp::DataFile::BasicLoader<TrackPart>(p)
{
add("start", &Loader::start);
add("length", &TrackPart::length);
void TrackPart::Loader::finish()
{
- if(part.radius)
+ if(obj.radius)
{
- part.length*=M_PI/180;
- part.radius/=1000;
+ obj.length*=M_PI/180;
+ obj.radius/=1000;
}
else
- part.length/=1000;
+ obj.length/=1000;
- part.pos.x/=1000;
- part.pos.y/=1000;
- part.dir*=M_PI/180;
+ obj.pos.x/=1000;
+ obj.pos.y/=1000;
+ obj.dir*=M_PI/180;
}
void TrackPart::Loader::start(float x, float y, float d)
{
- part.pos=Point(x, y);
- part.dir=d;
+ obj.pos=Point(x, y);
+ obj.dir=d;
}
} // namespace Marklin
struct TrackPart
{
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::BasicLoader<TrackPart>
{
- private:
- TrackPart ∂
-
public:
Loader(TrackPart &);
- TrackPart &get_object() { return part; }
private:
virtual void finish();
-
void start(float, float, float);
};
TrackType::Loader::Loader(TrackType &t):
- ttype(t)
+ Msp::DataFile::BasicLoader<TrackType>(t)
{
add("description", &TrackType::description);
add("part", &Loader::part);
void TrackType::Loader::finish()
{
- ttype.collect_endpoints();
+ obj.collect_endpoints();
}
void TrackType::Loader::part()
{
TrackPart p;
load_sub(p);
- ttype.parts.push_back(p);
+ obj.parts.push_back(p);
}
} // namespace Marklin
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
class TrackType
{
public:
- class Loader: public Msp::DataFile::Loader
+ class Loader: public Msp::DataFile::BasicLoader<TrackType>
{
- private:
- TrackType &ttype;
-
public:
Loader(TrackType &);
- TrackType &get_object() { return ttype; }
private:
virtual void finish();
-
void part();
void position(float, float, float);
};
*/
#include <algorithm>
+#include <msp/datafile/writer.h>
#include <msp/time/utils.h>
+#include "catalogue.h"
#include "control.h"
#include "layout.h"
+#include "locotype.h"
#include "tracktype.h"
#include "trafficmanager.h"
#include "turnout.h"
(*i)->tick(t, dt);
}
+void TrafficManager::save(const string &fn) const
+{
+ IO::BufferedFile out(fn, IO::M_WRITE);
+ DataFile::Writer writer(out);
+ for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
+ {
+ const Locomotive &loco=(*i)->get_locomotive();
+ DataFile::Statement st("train");
+ st.append(loco.get_type().get_article_number());
+ st.append(loco.get_address());
+ (*i)->save(st.sub);
+ writer.write(st);
+ }
+}
+
void TrafficManager::turnout_route_changed(unsigned, Turnout *)
{
}
+
+TrafficManager::Loader::Loader(TrafficManager &tm):
+ DataFile::BasicLoader<TrafficManager>(tm)
+{
+ add("train", &Loader::train);
+}
+
+void TrafficManager::Loader::train(unsigned art_nr, unsigned addr)
+{
+ Locomotive *loco=new Locomotive(obj.layout.get_catalogue().get_locomotive(art_nr), obj.control, addr);
+ Train *trn=new Train(obj, *loco);
+ load_sub(*trn);
+}
+
} // namespace Marklin
class TrafficManager
{
+public:
+ class Loader: public Msp::DataFile::BasicLoader<TrafficManager>
+ {
+ public:
+ Loader(TrafficManager &);
+ private:
+ void train(unsigned, unsigned);
+ };
+
private:
Control &control;
Layout &layout;
const std::list<Train *> &get_trains() const { return trains; }
void add_train(Train *);
void tick();
+ void save(const std::string &) const;
private:
void turnout_route_changed(unsigned, Turnout *);
};
}
}
+void Train::save(list<DataFile::Statement> &st) const
+{
+ st.push_back((DataFile::Statement("name"), name));
+ st.push_back((DataFile::Statement("speed_scale"), speed_scale, speed_scale_weight));
+}
+
void Train::sensor_event(bool state, Sensor *sensor)
{
unsigned addr=sensor->get_address();
pos=cur_track->get_endpoint_position(cur_track_ep);
}
+
+Train::Loader::Loader(Train &t):
+ DataFile::BasicLoader<Train>(t)
+{
+ add("name", &Train::name);
+ add("speed_scale", &Train::speed_scale, &Train::speed_scale_weight);
+}
+
} // namespace Marklin
class Train: public sigc::trackable
{
+public:
+ class Loader: public Msp::DataFile::BasicLoader<Train>
+ {
+ public:
+ Loader(Train &);
+ };
+
private:
struct BlockRef
{
void place(Block *, unsigned);
bool free_block(Block *);
void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &);
+ void save(std::list<Msp::DataFile::Statement> &) const;
private:
void sensor_event(bool, Sensor *);
unsigned reserve_more();
Distributed under the GPL
*/
-#include <iostream>
#include <msp/time/timer.h>
#include <msp/time/units.h>
#include "command.h"