X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fdesigner.cpp;h=d3932338a9edbbc23681f2afd164b7b0e45530ca;hb=8e3009751ee81e0e5312cae53ee844bdd9e49628;hp=92c2f25564b177918a80129fdd1a9b6a26778f88;hpb=258600f95f62ba4fbe745da4aebdd1a496af0050;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 92c2f25..d393233 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -6,8 +6,9 @@ Distributed under the GPL */ #include +#include #include -#include +#include #include #include #include @@ -33,6 +34,7 @@ Distributed under the GPL #include "manipulator.h" #include "measure.h" #include "selection.h" +#include "svgexporter.h" #include "toolbar.h" using namespace std; @@ -43,12 +45,14 @@ Application::RegApp Designer::reg; Designer::Designer(int argc, char **argv): window(1280, 960), + ui_res("marklin.res"), + root(ui_res, window), base_object(0), cur_route(0), mode(SELECT), - manipulator(*this, selection), + manipulator(*this, root, selection), measure(*this), - camera_ctl(window, camera), + camera_ctl(*this, root, camera), track_wrap(*this, selection) { window.set_title("Railway Designer"); @@ -69,6 +73,7 @@ Designer::Designer(int argc, char **argv): 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) { @@ -111,23 +116,21 @@ Designer::Designer(int argc, char **argv): pass->blend = &GL::Blend::alpha(); camera.set_up_direction(GL::Vector3(0, 0, 1)); - view_all(); + 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); + root.add(*statusbar); statusbar->set_size(window.get_width(), 20); statusbar->set_focusable(false); @@ -137,6 +140,8 @@ Designer::Designer(int argc, char **argv): overlay = new Overlay3D(window, camera, ui_res.get_default_font()); + camera_ctl.view_all(); + const Layout3D::TrackMap &tracks = layout_3d->get_tracks(); for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) update_track_icon(*i->second); @@ -145,7 +150,6 @@ Designer::Designer(int argc, char **argv): Designer::~Designer() { delete overlay; - delete root; delete pipeline; delete base_object; delete layout_3d; @@ -222,6 +226,12 @@ void Designer::rename_route() 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; @@ -245,7 +255,7 @@ void Designer::add_selection_to_route() 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; @@ -261,8 +271,11 @@ void Designer::tick() float dt = (t-last_tick)/Msp::Time::sec; last_tick = t; - window.get_display().tick(); - root->tick(); + if(mode==MANIPULATE_DONE) + mode = SELECT; + + window.tick(); + root.tick(); camera_ctl.tick(dt); for(list::iterator i=new_tracks.begin(); i!=new_tracks.end(); ++i) @@ -279,7 +292,12 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) 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) { @@ -364,6 +382,8 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t) 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) @@ -371,7 +391,7 @@ 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) { @@ -405,8 +425,6 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod) } } } - 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); } @@ -415,10 +433,9 @@ void Designer::pointer_motion(int x, int y) { 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); } } @@ -470,7 +487,7 @@ void Designer::render() GL::disable(GL::DEPTH_TEST); GL::Bind bind_blend(GL::Blend::alpha()); - root->render(); + root.render(); GL::Texture::unbind(); } @@ -479,6 +496,13 @@ void Designer::track_added(Track &trk) new_tracks.push_back(&trk); } +void Designer::track_removed(Track &trk) +{ + list::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; @@ -537,7 +561,7 @@ void Designer::manipulation_status(const string &status) void Designer::manipulation_done(bool) { - mode = SELECT; + mode = MANIPULATE_DONE; selection_changed(); } @@ -584,29 +608,10 @@ void Designer::route_name_accept(const string &text) cur_route->set_name(text); } -void Designer::view_all() +void Designer::svg_export_accept(const string &text) { - Point minp; - Point maxp; - - const Layout3D::TrackMap &tracks = layout_3d->get_tracks(); - for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) - { - Point tmin; - Point tmax; - i->second->get_bounds(0, tmin, tmax); - minp.x = min(minp.x, tmin.x); - minp.y = min(minp.y, tmin.y); - maxp.x = max(maxp.x, tmax.x); - maxp.y = max(maxp.y, tmax.y); - } - - float t = tan(camera.get_field_of_view()/2)*2; - float size = max((maxp.y-minp.y+0.1), (maxp.x-minp.x+0.1)/camera.get_aspect()); - float cam_dist = size/t+size*0.25; - Point center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2); - camera.set_position(GL::Vector3(center.x, center.y-cam_dist*0.5, cam_dist*0.866)); - camera.set_look_direction(GL::Vector3(0, 0.5, -0.866)); + SvgExporter svg_exp(*layout); + svg_exp.save(text); } string Designer::tooltip(int x, int y)