]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/designer.cpp
Add a variant of Route::find that takes a set of tracks
[r2c2.git] / source / designer / designer.cpp
index c9c045af2e253d9091d89cefa964b17618b12a58..7fbab1fd4cdd705abfdfe877f6de8603ffcf544a 100644 (file)
@@ -79,22 +79,26 @@ 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_path_scene(), "unlit");
+       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();
@@ -126,6 +130,8 @@ Designer::Designer(int argc, char **argv):
        const list<Track3D *> &tracks = layout_3d->get_tracks();
        for(list<Track3D *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                update_track_icon(**i);
+
+       edit_route(0);
 }
 
 Designer::~Designer()
@@ -199,9 +205,18 @@ void Designer::set_sensor_id()
        }
 }
 
-void Designer::edit_route(Route &r)
+void Designer::rename_route()
 {
-       cur_route = &r;
+       if(!cur_route)
+               return;
+
+       InputDialog *input = new InputDialog(*this, "Route name", cur_route->get_name());
+       input->signal_accept.connect(sigc::mem_fun(this, &Designer::route_name_accept));
+}
+
+void Designer::edit_route(Route *r)
+{
+       cur_route = r;
        show_route(r);
 }
 
@@ -221,7 +236,7 @@ void Designer::add_selection_to_route()
                IO::print("%s\n", e.what());
        }
 
-       show_route(*cur_route);
+       show_route(cur_route);
 }
 
 Point Designer::map_pointer_coords(int x, int y)
@@ -419,9 +434,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)
        {
@@ -431,14 +444,13 @@ void Designer::render()
        else
        {
                pipeline->render_all();
-               layout_3d->get_endpoint_scene().render();
-               if(cur_route)
-                       layout_3d->get_path_scene().render();
                GL::enable(GL_CULL_FACE);
-               GL::disable(GL::DEPTH_TEST);
-               overlay->render(0);
-               GL::enable(GL::DEPTH_TEST);
+               {
+                       GL::Bind bind_blend(GL::Blend::alpha());
+                       overlay->render(0);
+               }
 
+               GL::Bind bind_depth(GL::DepthTest::lequal());
                manipulator.render();
                if(mode==MEASURE)
                        measure.render();
@@ -452,7 +464,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)
@@ -484,8 +498,11 @@ void Designer::update_track_icon(Track3D &track)
        }
        else if(unsigned tid = track.get_track().get_turnout_id())
        {
-               overlay->add_graphic(track, "turnout");
-               overlay->set_label(track, lexical_cast(tid));
+               if(tid<0x800)
+               {
+                       overlay->add_graphic(track, "turnout");
+                       overlay->set_label(track, lexical_cast(tid));
+               }
        }
 }
 
@@ -537,6 +554,12 @@ void Designer::sensor_id_accept(const string &text)
        }
 }
 
+void Designer::route_name_accept(const string &text)
+{
+       if(cur_route)
+               cur_route->set_name(text);
+}
+
 void Designer::view_all()
 {
        Point minp;
@@ -582,20 +605,19 @@ string Designer::tooltip(int x, int y)
        return string();
 }
 
-void Designer::show_route(const Route &route)
+void Designer::show_route(const Route *route)
 {
        const set<Track *> &ltracks = layout->get_tracks();
-       const set<const Track *> &rtracks = route.get_tracks();
        for(set<Track *>::iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
        {
                Track3D &t3d = layout_3d->get_track(**i);
-               if(rtracks.count(*i))
+               if(route && route->get_tracks().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);
+                               int path = (tid ? route->get_turnout(tid) : -1);
                                if(path>=0)
                                        t3d.get_path().set_path(path);
                                else