X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fdesigner.cpp;h=511c901b5d5b3c70aa9ef086f775ff4ca72cf302;hb=74f8c3beba5a6947a523119e3f26cf745725b511;hp=6ae9c0726c45701a5915adc9f852d9fdc1b75e66;hpb=a34ddfcc90e80188545fdd2c6bbca8dfba7f1ad0;p=r2c2.git diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 6ae9c07..511c901 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -17,6 +17,7 @@ #include #include #include "libr2c2/route.h" +#include "libr2c2/terrain.h" #include "libr2c2/tracktype.h" #include "libr2c2/zone.h" #include "3d/path.h" @@ -35,6 +36,7 @@ #include "selection.h" #include "slopetool.h" #include "svgexporter.h" +#include "terraintool.h" #include "trackbar.h" #include "zonebar.h" #include "zoneproperties.h" @@ -47,25 +49,28 @@ Designer::Designer(int argc, char **argv): window(1280, 960), keyboard(window), mouse(window), - ui_res("r2c2.res"), + ui_res("data/r2c2.res"), root(ui_res, &window, &keyboard, &mouse), base_object(0), cur_route(0), cur_zone(0), mode(TOOL), sel_wrap(selection), - cur_tool(0) + cur_tool(0), + keep_status(0) { window.set_title("Railway Designer"); window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Designer::exit), 0)); // Setup catalogue and layout - DataFile::load(catalogue, "tracks.dat"); + catalogue.add_source("data/Märklin/H0"); cat_layout_3d = new Layout3D(catalogue.get_layout()); layout = new Layout(catalogue); + layout->get_clock().set_current_time(12*Time::hour); layout_3d = new Layout3D(*layout); + layout_3d->tick(); if(argc>1) { @@ -343,6 +348,7 @@ void Designer::tick() cur_tool->update_selection(selection); use_select_tool(); } + keep_status = 0; window.tick(); root.tick(); @@ -428,6 +434,12 @@ void Designer::key_press(unsigned key) svg_export(); else if(key==Msp::Input::KEY_P) object_properties(); + else if(key==Msp::Input::KEY_TAB) + { + Object *obj = selection.get_object(); + if(Terrain *terrain = dynamic_cast(obj)) + use_tool(new TerrainTool(*this, keyboard, mouse, *terrain)); + } } template @@ -456,8 +468,10 @@ void Designer::use_tool(Tool *tool) cur_tool = tool; cur_tool->signal_status.connect(sigc::mem_fun(this, &Designer::tool_status)); - tool_status(cur_tool->get_status()); + if(keep_status<2) + tool_status(tool->get_status()); mode = TOOL; + keep_status = 1; } void Designer::use_select_tool() @@ -472,7 +486,7 @@ void Designer::button_press(unsigned btn) if(mode==CATALOGUE) { - Object *obj; + Object *obj = 0; if(btn==1) obj = pick_object(pointer); @@ -506,7 +520,7 @@ Object *Designer::pick_object(const Vector &pointer) const GL::Vector3 &cpos = view.get_camera().get_position(); GL::Vector4 cray = view.get_camera().unproject(GL::Vector4(pointer.x, pointer.y, 0, 0)); - return view.get_layout().get_layout().pick(Ray(cpos, Vector(cray))); + return view.get_layout().get_layout().pick(Ray(cpos, cray.slice<3>(0))); } void Designer::update_object_icon(Object &obj) @@ -524,8 +538,9 @@ void Designer::update_object_icon(Object &obj) overlay->add_graphic(obj3d, "trackcircuit"); overlay->set_label(obj3d, lexical_cast(saddr)); } - else if(unsigned taddr = track->get_turnout_address()) + else if(track->get_type().is_turnout()) { + unsigned taddr = track->get_turnout_address(); if(taddr<0x800) { overlay->add_graphic(obj3d, "turnout"); @@ -548,6 +563,8 @@ void Designer::update_object_icon(Object &obj) void Designer::tool_status(const string &status) { lbl_status->set_text(status); + if(keep_status==1) + keep_status = 2; } void Designer::object_properties_response(int) @@ -575,16 +592,25 @@ string Designer::tooltip(int x, int y) if(Object *obj = pick_object(Vector(x*2.0f/rgeom.w-1.0f, y*2.0f/rgeom.h-1.0f, 0))) { const ObjectType &otype = obj->get_type(); - string info = format("%d %s", otype.get_article_number(), otype.get_description()); + string info = format("%d %s", otype.get_article_number(), otype.get_name()); if(Track *track = dynamic_cast(obj)) { if(mode!=CATALOGUE && abs(track->get_tilt()).radians()>1e-4) info += format(" (slope %.1f%%)", abs(tan(track->get_tilt())*100)); - if(track->get_turnout_address()) + if(track->get_type().is_turnout()) info += format(" (turnout %d)", track->get_turnout_address()); else if(track->get_sensor_address()) info += format(" (sensor %d)", track->get_sensor_address()); } + if(mode==CATALOGUE) + { + const string &descr = otype.get_description(); + if(!descr.empty()) + { + info += '\n'; + info += otype.get_description(); + } + } return info; } @@ -608,8 +634,9 @@ void Designer::show_route(const Route &route) Track3D &t3d = layout_3d->get_3d(**i); Path3D *path = new Path3D(t3d); path->set_color(GL::Color(0.5, 0.8, 1.0)); - if(unsigned taddr = (*i)->get_turnout_address()) - path->set_path(route.get_turnout(taddr)); + if((*i)->get_type().is_turnout()) + path->set_path(route.get_turnout((*i)->get_turnout_address())); + highlight_paths.push_back(path); } } @@ -623,5 +650,6 @@ void Designer::show_zone(const Zone &zone) Track3D &t3d = layout_3d->get_3d(**i); Path3D *path = new Path3D(t3d); path->set_color(GL::Color(0.8, 1.0, 0.5)); + highlight_paths.push_back(path); } }