X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fextendtool.cpp;h=8698fd52e6aabc048b348d49b796a06c236fb3e2;hb=b860a56bd9bc8894311c02d7673f379beff3220b;hp=021f184a8fb89a4393a9b8dfa6525691ad0da426;hpb=9e6dbfe685b1fb69b615acb1780fe20f6b2cef34;p=r2c2.git diff --git a/source/designer/extendtool.cpp b/source/designer/extendtool.cpp index 021f184..8698fd5 100644 --- a/source/designer/extendtool.cpp +++ b/source/designer/extendtool.cpp @@ -22,23 +22,22 @@ ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const s if(unlinked_endpoints.empty()) { - done = true; set_status("No free endpoints"); + set_done(false); } - const Catalogue::ObjectMap &object_types = designer.get_catalogue().get_all(); - for(Catalogue::ObjectMap::const_iterator i=object_types.begin(); i!=object_types.end(); ++i) - if(const TrackType *tt = dynamic_cast(i->second)) - { - const vector &parts = tt->get_parts(); - if(parts.size()!=1) - continue; - if(parts.front().is_curved() || parts.front().is_dead_end()) - continue; + list track_types = designer.get_catalogue().get_list(); + for(list::iterator i=track_types.begin(); i!=track_types.end(); ++i) + { + const vector &parts = (*i)->get_parts(); + if(parts.size()!=1) + continue; + if(parts.front().is_curved() || parts.front().is_dead_end()) + continue; - types_by_length[parts.front().get_length()] = tt; - max_preference = max(max_preference, tt->get_autofit_preference()); - } + types_by_length[parts.front().get_length()] = *i; + max_preference = max(max_preference, (*i)->get_autofit_preference()); + } } ExtendTool::~ExtendTool() @@ -52,7 +51,7 @@ ExtendTool::~ExtendTool() void ExtendTool::connect() { - float limit = designer.get_layout().get_catalogue().get_gauge()/10; + float limit; Track *start_track = 0; Track *end_track = 0; @@ -62,6 +61,7 @@ void ExtendTool::connect() for(vector::const_iterator i=unlinked_endpoints.begin(); i!=unlinked_endpoints.end(); ++i) { start_sn = (*i)->get_snap_node(i->entry()); + limit = (*i)->get_type().get_gauge()/10; for(vector::const_iterator j=i; ++j!=unlinked_endpoints.end(); ) { @@ -83,6 +83,8 @@ void ExtendTool::connect() if(gap<0) continue; + start_track = i->track(); + end_track = j->track(); ok = true; } @@ -93,6 +95,7 @@ void ExtendTool::connect() if(!ok) { set_status("No aligned endpoints found"); + set_done(false); return; } @@ -101,6 +104,7 @@ void ExtendTool::connect() if(extend_tracks.empty()) { set_status("No connection possible"); + set_done(false); return; } @@ -139,20 +143,20 @@ void ExtendTool::pointer_motion() delete *i; extend_tracks = trks; - map counts; + map counts; length = 0; for(vector::iterator i=extend_tracks.begin(); i!=extend_tracks.end(); ++i) { length += (*i)->get_type().get_total_length(); - ++counts[(*i)->get_type().get_article_number()]; + ++counts[&(*i)->get_type()]; } string detail; - for(map::const_iterator i=counts.begin(); i!=counts.end(); ++i) + for(map::const_iterator i=counts.begin(); i!=counts.end(); ++i) { if(!detail.empty()) detail += ", "; - detail += format("%dx %s", i->second, i->first); + detail += format("%dx %s", i->second, i->first->get_article_number()); } signal_status.emit(format("Extend: %.0fmm (%s)", length*1000, detail)); @@ -162,9 +166,12 @@ void ExtendTool::pointer_motion() void ExtendTool::finish() { - for(vector::const_iterator i=unlinked_endpoints.begin(); i!=unlinked_endpoints.end(); ++i) - if(extend_tracks.front()->link_to(**i)) - break; + if(!extend_tracks.empty()) + { + for(vector::const_iterator i=unlinked_endpoints.begin(); i!=unlinked_endpoints.end(); ++i) + if(extend_tracks.front()->link_to(**i)) + break; + } } vector ExtendTool::create_straight(const Vector &start, const Angle &dir, float length, float limit)