]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/designer.cpp
A couple of minor temporary fixes
[r2c2.git] / source / designer / designer.cpp
index 86fc3494a424508b20ad93de6c685db00cc8ecbd..2002bd987910a7d28893ba32b1efd15db0671e39 100644 (file)
@@ -28,6 +28,7 @@ Distributed under the GPL
 #include <msp/time/utils.h>
 #include "libr2c2/route.h"
 #include "libr2c2/tracktype.h"
+#include "libr2c2/zone.h"
 #include "3d/path.h"
 #include "designer.h"
 #include "input.h"
@@ -39,6 +40,8 @@ Distributed under the GPL
 #include "svgexporter.h"
 #include "trackbar.h"
 #include "trackproperties.h"
+#include "zonebar.h"
+#include "zoneproperties.h"
 
 using namespace std;
 using namespace R2C2;
@@ -52,6 +55,7 @@ Designer::Designer(int argc, char **argv):
        root(ui_res, window),
        base_object(0),
        cur_route(0),
+       cur_zone(0),
        mode(SELECT),
        manipulator(*this, root, selection),
        measure(*this),
@@ -91,8 +95,6 @@ Designer::Designer(int argc, char **argv):
        }
 
        // Setup OpenGL
-       GL::enable(GL_CULL_FACE);
-
        pipeline = new GL::Pipeline(window.get_width(), window.get_height(), false);
        pipeline->set_camera(&camera);
        pipeline->add_renderable_for_pass(layout_3d->get_scene(), 0);
@@ -130,6 +132,7 @@ Designer::Designer(int argc, char **argv):
        toolbars.push_back(new Layoutbar(*this));
        toolbars.push_back(new Trackbar(*this));
        toolbars.push_back(new Routebar(*this));
+       toolbars.push_back(new Zonebar(*this));
        for(vector<Toolbar *>::iterator i=toolbars.begin(); i!=toolbars.end(); ++i)
        {
                root.add(**i);
@@ -159,6 +162,8 @@ Designer::Designer(int argc, char **argv):
 
 Designer::~Designer()
 {
+       for(vector<Toolbar *>::iterator i=toolbars.begin(); i!=toolbars.end(); ++i)
+               delete *i;
        delete overlay;
        delete pipeline;
        delete base_object;
@@ -249,6 +254,22 @@ void Designer::flatten_tracks()
        manipulator.flatten();
 }
 
+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;
+       cur_zone = 0;
+       if(cur_route)
+               show_route(*cur_route);
+       else
+               clear_paths();
+}
+
 void Designer::rename_route()
 {
        if(mode!=SELECT || !cur_route)
@@ -258,33 +279,60 @@ void Designer::rename_route()
        input->signal_accept.connect(sigc::mem_fun(this, &Designer::route_name_accept));
 }
 
-void Designer::svg_export()
+void Designer::add_selection_to_route()
 {
-       InputDialog *input = new InputDialog(*this, "SVG export", FS::basepart(filename)+".svg");
-       input->signal_accept.connect(sigc::mem_fun(this, &Designer::svg_export_accept));
+       if(!cur_route)
+               return;
+
+       try
+       {
+               cur_route->add_tracks(selection.get_tracks());
+       }
+       catch(const Exception &e)
+       {
+               lbl_status->set_text(e.what());
+       }
+
+       show_route(*cur_route);
 }
 
-void Designer::edit_route(Route *r)
+void Designer::edit_zone(Zone *z)
 {
-       cur_route = r;
-       show_route(r);
+       cur_zone = z;
+       cur_route = 0;
+       if(cur_zone)
+               show_zone(*cur_zone);
+       else
+               clear_paths();
 }
 
-void Designer::add_selection_to_route()
+void Designer::zone_properties()
 {
-       if(!cur_route)
+       if(!cur_zone)
+               return;
+
+       ZoneProperties *zone_prop = new ZoneProperties(*cur_zone);
+       root.add(*zone_prop);
+       const GLtk::Geometry &root_geom = root.get_geometry();
+       const GLtk::Geometry &dlg_geom = zone_prop->get_geometry();
+       zone_prop->set_position((root_geom.w-dlg_geom.w)/2, (root_geom.h-dlg_geom.h)/2);
+}
+
+void Designer::add_selection_to_zone()
+{
+       if(!cur_zone)
                return;
 
        try
        {
-               cur_route->add_tracks(selection.get_tracks());
+               cur_zone->add_tracks(selection.get_tracks());
        }
        catch(const Exception &e)
        {
                lbl_status->set_text(e.what());
        }
 
-       show_route(cur_route);
+       show_zone(*cur_zone);
 }
 
 Point Designer::map_pointer_to_ground(int x, int y)
@@ -395,7 +443,12 @@ void Designer::key_press(unsigned key, unsigned mod, wchar_t)
        else if(key==Msp::Input::KEY_E)
                manipulator.even_slope();
        else if(key==Msp::Input::KEY_A)
-               add_selection_to_route();
+       {
+               if(cur_route)
+                       add_selection_to_route();
+               else if(cur_zone)
+                       add_selection_to_zone();
+       }
        else if(key==Msp::Input::KEY_C)
                connect_tracks();
        else if(key==Msp::Input::KEY_V)
@@ -485,7 +538,6 @@ void Designer::render()
        else
        {
                pipeline->render_all();
-               GL::enable(GL_CULL_FACE);
                {
                        GL::Bind bind_blend(GL::Blend::alpha());
                        overlay->render(0);
@@ -502,11 +554,11 @@ void Designer::render()
        GL::matrix_mode(GL::MODELVIEW);
        GL::load_identity();
 
-       GL::disable(GL::DEPTH_TEST);
-
        GL::Bind bind_blend(GL::Blend::alpha());
        root.render();
+       // XXX Should fix GLtk so these would not be needed
        GL::Texture::unbind();
+       glColor3f(1.0, 1.0, 1.0);
 }
 
 void Designer::track_added(Track &trk)
@@ -649,28 +701,44 @@ string Designer::tooltip(int x, int y)
        return string();
 }
 
-void Designer::show_route(const Route *route)
+void Designer::clear_paths()
 {
        const set<Track *> &ltracks = layout->get_tracks();
        for(set<Track *>::iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
        {
                Track3D &t3d = layout_3d->get_track(**i);
-               if(route && route->has_track(**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);
-               }
+               t3d.get_path().set_mask(0);
+       }
+}
+
+void Designer::show_route(const Route &route)
+{
+       clear_paths();
+
+       const set<Track *> &rtracks = route.get_tracks();
+       for(set<Track *>::iterator i=rtracks.begin(); i!=rtracks.end(); ++i)
+       {
+               Track3D &t3d = layout_3d->get_track(**i);
+               t3d.get_path().set_color(GL::Color(0.5, 0.8, 1.0));
+               int path = -1;
+               if(unsigned tid = (*i)->get_turnout_id())
+                       path = route.get_turnout(tid);
+               if(path>=0)
+                       t3d.get_path().set_path(path);
                else
-                       t3d.get_path().set_mask(0);
+                       t3d.get_path().set_mask((*i)->get_type().get_paths());
+       }
+}
+
+void Designer::show_zone(const Zone &zone)
+{
+       clear_paths();
+
+       const Zone::TrackSet &ztracks = zone.get_tracks();
+       for(Zone::TrackSet::const_iterator i=ztracks.begin(); i!=ztracks.end(); ++i)
+       {
+               Track3D &t3d = layout_3d->get_track(**i);
+               t3d.get_path().set_color(GL::Color(0.8, 1.0, 0.5));
+               t3d.get_path().set_mask((*i)->get_type().get_paths());
        }
 }