/* $Id$
-This file is part of the MSP Märklin suite
+This file is part of R²C²
Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <signal.h>
+#include <algorithm>
#include <cmath>
-#include <GL/gl.h>
+#include <msp/fs/utils.h>
#include <msp/gl/blend.h>
#include <msp/gl/framebuffer.h>
#include <msp/gl/matrix.h>
#include <msp/strings/utils.h>
#include <msp/time/units.h>
#include <msp/time/utils.h>
-#include "libmarklin/route.h"
-#include "libmarklin/tracktype.h"
+#include "libr2c2/route.h"
+#include "libr2c2/tracktype.h"
#include "3d/path.h"
#include "designer.h"
#include "input.h"
#include "manipulator.h"
#include "measure.h"
#include "selection.h"
+#include "svgexporter.h"
#include "toolbar.h"
using namespace std;
-using namespace Marklin;
+using namespace R2C2;
using namespace Msp;
Application::RegApp<Designer> Designer::reg;
Designer::Designer(int argc, char **argv):
window(1280, 960),
+ ui_res("r2c2.res"),
+ root(ui_res, window),
base_object(0),
cur_route(0),
mode(SELECT),
- manipulator(*this, selection),
+ manipulator(*this, root, selection),
measure(*this),
+ camera_ctl(*this, root, camera),
track_wrap(*this, selection)
{
window.set_title("Railway Designer");
layout_3d = new Layout3D(*layout);
layout->signal_track_added.connect(sigc::mem_fun(this, &Designer::track_added));
+ layout->signal_track_removed.connect(sigc::mem_fun(this, &Designer::track_removed));
if(argc>1)
{
camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
// Setup UI
- DataFile::load(ui_res, "marklin.res");
- root = new GLtk::Root(ui_res, window);
- root->signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press));
- root->signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press));
- root->signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion));
- root->signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip));
+ root.signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press));
+ root.signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press));
+ root.signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion));
+ root.signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip));
toolbar = new Toolbar(*this);
- root->add(*toolbar);
+ root.add(*toolbar);
toolbar->set_position(0, window.get_height()-toolbar->get_geometry().h);
toolbar->set_focusable(false);
- GLtk::Panel *statusbar = new GLtk::Panel(ui_res);
- root->add(*statusbar);
+ GLtk::Panel *statusbar = new GLtk::Panel;
+ root.add(*statusbar);
statusbar->set_size(window.get_width(), 20);
statusbar->set_focusable(false);
- lbl_status = new GLtk::Label(ui_res);
+ lbl_status = new GLtk::Label;
statusbar->add(*lbl_status);
lbl_status->set_geometry(GLtk::Geometry(20, 2, 300, 16));
overlay = new Overlay3D(window, camera, ui_res.get_default_font());
- camera_ctl = new CameraController(*this, *root, camera);
- camera_ctl->view_all();
+ camera_ctl.view_all();
const Layout3D::TrackMap &tracks = layout_3d->get_tracks();
for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
Designer::~Designer()
{
- delete camera_ctl;
delete overlay;
- delete root;
delete pipeline;
delete base_object;
delete layout_3d;
input->signal_accept.connect(sigc::mem_fun(this, &Designer::route_name_accept));
}
+void Designer::svg_export()
+{
+ InputDialog *input = new InputDialog(*this, "SVG export", FS::basepart(filename)+".svg");
+ input->signal_accept.connect(sigc::mem_fun(this, &Designer::svg_export_accept));
+}
+
void Designer::edit_route(Route *r)
{
cur_route = r;
show_route(cur_route);
}
-Point Designer::map_pointer_coords(int x, int y)
+Point Designer::map_pointer_to_ground(int x, int y)
{
float xf = x*2.0/window.get_width()-1.0;
float yf = y*2.0/window.get_height()-1.0;
float dt = (t-last_tick)/Msp::Time::sec;
last_tick = t;
- window.get_display().tick();
- root->tick();
- camera_ctl->tick(dt);
+ if(mode==MANIPULATE_DONE)
+ mode = SELECT;
+
+ window.tick();
+ root.tick();
+ camera_ctl.tick(dt);
for(list<Track *>::iterator i=new_tracks.begin(); i!=new_tracks.end(); ++i)
layout_3d->get_track(**i).get_path().set_mask(0);
key = Input::key_from_sys(key);
mod = Input::mod_from_sys(mod);
- if(key==Msp::Input::KEY_N)
+ if(key==Msp::Input::KEY_N && (mod&Input::MOD_SHIFT))
+ {
+ manipulator.start_extend();
+ mode = MANIPULATE;
+ }
+ else if(key==Msp::Input::KEY_N)
new_track();
else if(key==Msp::Input::KEY_G)
{
add_selection_to_route();
else if(key==Msp::Input::KEY_C)
manipulator.connect();
+ else if(key==Msp::Input::KEY_V)
+ svg_export();
}
void Designer::button_press(int x, int y, unsigned btn, unsigned mod)
y = window.get_height()-y-1;
mod = Input::mod_from_sys(mod);
- Point ground = map_pointer_coords(x, y);
+ Point ground = map_pointer_to_ground(x, y);
if(mode==CATALOGUE)
{
}
}
}
- else if(mode==MANIPULATE)
- manipulator.button_press(x, y, ground.x, ground.y, btn);
else if(mode==MEASURE)
measure.button_press(x, y, ground.x, ground.y, btn);
}
{
y = window.get_height()-y-1;
- if(!root->get_child_at(x, y))
+ if(!root.get_child_at(x, y))
{
- Point ground = map_pointer_coords(x, y);
- manipulator.pointer_motion(x, y, ground.x, ground.y);
+ Point ground = map_pointer_to_ground(x, y);
measure.pointer_motion(x, y, ground.x, ground.y);
}
}
GL::disable(GL::DEPTH_TEST);
GL::Bind bind_blend(GL::Blend::alpha());
- root->render();
+ root.render();
GL::Texture::unbind();
}
new_tracks.push_back(&trk);
}
+void Designer::track_removed(Track &trk)
+{
+ list<Track *>::iterator i = find(new_tracks.begin(), new_tracks.end(), &trk);
+ if(i!=new_tracks.end())
+ new_tracks.erase(i);
+}
+
Track3D *Designer::pick_track(int x, int y)
{
Layout3D *l = layout_3d;
void Designer::manipulation_done(bool)
{
- mode = SELECT;
+ mode = MANIPULATE_DONE;
selection_changed();
}
cur_route->set_name(text);
}
+void Designer::svg_export_accept(const string &text)
+{
+ SvgExporter svg_exp(*layout);
+ svg_exp.save(text);
+}
+
string Designer::tooltip(int x, int y)
{
if(Track3D *t3d = pick_track(x, y))