X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fmanipulator.cpp;h=720309bd8dc4b773374b7120fd09195685464d91;hb=7e27b311e33beda1746eb63e0945633f262427f6;hp=aad20a084b84bcd0511192e25d2f7fb087502821;hpb=283542ae424b94786652fbf0c67b883b63a8e7a0;p=r2c2.git diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index aad20a0..720309b 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -1,6 +1,6 @@ /* $Id$ -This file is part of the MSP Märklin suite +This file is part of R²C² Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -8,21 +8,24 @@ Distributed under the GPL #include #include #include -#include "libmarklin/tracktype.h" +#include "libr2c2/tracktype.h" #include "designer.h" #include "manipulator.h" #include "selection.h" using namespace std; -using namespace Marklin; +using namespace R2C2; using namespace Msp; -Manipulator::Manipulator(Designer &d, Selection &s): +Manipulator::Manipulator(Designer &d, Graphics::EventSource &es, Selection &s): designer(d), + event_source(es), selection(s), mode(NONE), angle(0) { + event_source.signal_button_press.connect(sigc::mem_fun(this, &Manipulator::button_press)); + event_source.signal_pointer_motion.connect(sigc::mem_fun(this, &Manipulator::pointer_motion)); selection.signal_changed.connect(sigc::mem_fun(this, &Manipulator::selection_changed)); } @@ -56,12 +59,26 @@ void Manipulator::start_elevate() mode = ELEVATE; } -void Manipulator::start_extend() +bool Manipulator::start_extend() { if(mode) cancel(); - mode = EXTEND; + bool ok = false; + const set &stracks = selection.get_tracks(); + for(set::const_iterator i=stracks.begin(); (!ok && i!=stracks.end()); ++i) + { + const vector &links = (*i)->get_links(); + for(vector::const_iterator j=links.begin(); (!ok && j!=links.end()); ++j) + ok = !*j; + } + + if(ok) + mode = EXTEND; + else + signal_status.emit("No free endpoints"); + + return ok; } void Manipulator::duplicate() @@ -208,7 +225,7 @@ void Manipulator::connect() return; } - float limit = 0.001; + float limit = designer.get_layout().get_catalogue().get_gauge()/10; Track *track1 = tracks.front().track; Point pos1; @@ -306,11 +323,14 @@ void Manipulator::cancel() signal_done.emit(false); } -void Manipulator::button_press(int, int, float, float, unsigned btn) +void Manipulator::button_press(int, int, unsigned btn, unsigned) { + if(!mode) + return; + if(btn==3) cancel(); - else if(btn==1 && mode) + else if(btn==1) { Mode m = mode; mode = NONE; @@ -350,10 +370,10 @@ void Manipulator::button_press(int, int, float, float, unsigned btn) } } -void Manipulator::pointer_motion(int, int y, float gx, float gy) +void Manipulator::pointer_motion(int x, int y) { pointer_y = y; - gpointer = Point(gx, gy, 0); + gpointer = designer.map_pointer_to_ground(x, event_source.get_height()-1-y); if(mode==MOVE) { @@ -366,6 +386,8 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy) } const set <racks = designer.get_layout().get_tracks(); + float limit = max(designer.get_layout().get_catalogue().get_gauge(), + designer.get_camera_controller().get_view_scale()*5/event_source.get_height()); MTrack *snapped = 0; for(set::const_iterator i=ltracks.begin(); (i!=ltracks.end() && !snapped); ++i) { @@ -375,7 +397,7 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy) if(!ok) continue; for(vector::iterator j=tracks.begin(); (j!=tracks.end() && !snapped); ++j) - if(j->track->snap_to(**i, false)) + if(j->track->snap_to(**i, false, limit)) snapped = &*j; } @@ -439,8 +461,8 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy) float ep_dir = i->track->get_endpoint_direction(j); float c = cos(ep_dir); float s = sin(ep_dir); - float dx = gx-ep_pos.x; - float dy = gy-ep_pos.y; + float dx = gpointer.x-ep_pos.x; + float dy = gpointer.y-ep_pos.y; float len = dx*c+dy*s; if(len Manipulator::create_straight(const Marklin::Point &start, float dir, float length, float limit) +vector Manipulator::create_straight(const R2C2::Point &start, float dir, float length, float limit) { const Catalogue::TrackMap &track_types = designer.get_catalogue().get_tracks(); std::map types_by_length;