X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fdesigner.cpp;h=eb2af23d06f48884927fc7ce1ccc1e4d440349c8;hb=1f9af43b6ab300693c044b431e95b25422b36507;hp=9e99a1d99d4b20c7e91ebf9e6db49bb5d4232db4;hpb=17c219cff8f859978ec1274786319478cc99450c;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 9e99a1d..eb2af23 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -25,7 +25,9 @@ Distributed under the GPL #include #include #include +#include "libmarklin/route.h" #include "libmarklin/tracktype.h" +#include "3d/path.h" #include "designer.h" #include "input.h" #include "manipulator.h" @@ -77,22 +79,25 @@ Designer::Designer(int argc, char **argv): } // Setup OpenGL - GL::enable(GL::DEPTH_TEST); - GL::enable(GL::BLEND); - GL::blend_func(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA); GL::enable(GL_CULL_FACE); pipeline = new GL::Pipeline(window.get_width(), window.get_height(), false); pipeline->set_camera(&camera); - pipeline->add_renderable(layout_3d->get_scene()); + pipeline->add_renderable_for_pass(layout_3d->get_scene(), 0); if(base_object) - pipeline->add_renderable(*base_object); + pipeline->add_renderable_for_pass(*base_object, 0); + pipeline->add_renderable_for_pass(layout_3d->get_endpoint_scene(), "unlit"); light.set_position(0, -0.259, 0.966, 0); lighting.attach(0, light); - GL::PipelinePass *pass = &pipeline->add_pass(GL::Tag()); + GL::PipelinePass *pass = &pipeline->add_pass(0); pass->lighting = &lighting; + pass->depth_test = &GL::DepthTest::lequal(); + + pass = &pipeline->add_pass("unlit"); + pass->depth_test = &GL::DepthTest::lequal(); + pass->blend = &GL::Blend::alpha(); camera.set_up_direction(GL::Vector3(0, 0, 1)); view_all(); @@ -165,7 +170,7 @@ void Designer::new_track() void Designer::set_turnout_id() { Track *track = selection.get_track(); - if(selection.size()==1 && track->get_type().get_n_paths()>1) + if(selection.size()==1 && track->get_type().is_turnout()) { InputDialog *input = new InputDialog(*this, "Turnout ID", lexical_cast(track->get_turnout_id())); input->signal_accept.connect(sigc::mem_fun(this, &Designer::turnout_id_accept)); @@ -179,7 +184,7 @@ void Designer::set_sensor_id() int id = -1; for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { - if((*i)->get_type().get_n_paths()==1) + if(!(*i)->get_type().is_turnout()) ok = true; if(static_cast((*i)->get_sensor_id())!=id) { @@ -199,7 +204,11 @@ void Designer::set_sensor_id() void Designer::edit_route(Route &r) { + if(!cur_route) + pipeline->add_renderable_for_pass(layout_3d->get_path_scene(), "unlit"); + cur_route = &r; + show_route(r); } void Designer::add_selection_to_route() @@ -217,6 +226,8 @@ void Designer::add_selection_to_route() { IO::print("%s\n", e.what()); } + + show_route(*cur_route); } Point Designer::map_pointer_coords(int x, int y) @@ -354,9 +365,8 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod) Track3D *ctrack = pick_track(x, y); if(ctrack) { - Track *track = ctrack->get_track().copy(); + Track *track = new Track(*layout, ctrack->get_track().get_type()); track->set_position(ground); - layout->add_track(*track); selection.clear(); selection.add_track(track); @@ -415,9 +425,7 @@ void Designer::apply_camera() void Designer::render() { - GL::clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT); - GL::enable(GL::DEPTH_TEST); - GL::Texture::unbind(); + GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT); if(mode==CATALOGUE) { @@ -427,29 +435,10 @@ void Designer::render() else { pipeline->render_all(); - layout_3d->get_endpoint_scene().render(); GL::enable(GL_CULL_FACE); - GL::disable(GL::DEPTH_TEST); overlay->render(0); - GL::enable(GL::DEPTH_TEST); - /*if(cur_route) - { - glColor4f(0.5, 0.8, 1.0, 1.0); - const set &rtracks = cur_route->get_tracks(); - const map &turnouts = cur_route->get_turnouts(); - for(set::const_iterator i=rtracks.begin(); i!=rtracks.end(); ++i) - { - unsigned path = 0; - if(unsigned tid=(*i)->get_turnout_id()) - { - map::const_iterator j = turnouts.find(tid); - if(j!=turnouts.end()) - path = j->second; - } - layout_3d->get_track(**i).render_path(path); - } - }*/ + GL::Bind bind_depth(GL::DepthTest::lequal()); manipulator.render(); if(mode==MEASURE) measure.render(); @@ -463,7 +452,9 @@ void Designer::render() GL::disable(GL::DEPTH_TEST); + GL::Bind bind_blend(GL::Blend::alpha()); root->render(); + GL::Texture::unbind(); } Track3D *Designer::pick_track(int x, int y) @@ -592,3 +583,30 @@ string Designer::tooltip(int x, int y) return string(); } + +void Designer::show_route(const Route &route) +{ + const set <racks = layout->get_tracks(); + const set &rtracks = route.get_tracks(); + for(set::iterator i=ltracks.begin(); i!=ltracks.end(); ++i) + { + Track3D &t3d = layout_3d->get_track(**i); + if(rtracks.count(*i)) + { + t3d.get_path().set_color(GL::Color(0.5, 0.8, 1.0)); + if((*i)->get_type().is_turnout()) + { + unsigned tid = (*i)->get_turnout_id(); + int path = (tid ? route.get_turnout(tid) : -1); + if(path>=0) + t3d.get_path().set_path(path); + else + t3d.get_path().set_mask((*i)->get_type().get_paths()); + } + else + t3d.get_path().set_path(0); + } + else + t3d.get_path().set_mask(0); + } +}