From 9e6dbfe685b1fb69b615acb1780fe20f6b2cef34 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 20 Oct 2013 14:58:59 +0300 Subject: [PATCH] Create track length map in ExtendTool constructor --- source/designer/extendtool.cpp | 34 +++++++++++++++++----------------- source/designer/extendtool.h | 3 +++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/source/designer/extendtool.cpp b/source/designer/extendtool.cpp index 2a66181..021f184 100644 --- a/source/designer/extendtool.cpp +++ b/source/designer/extendtool.cpp @@ -8,7 +8,8 @@ using namespace Msp; using namespace R2C2; ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set &objects): - Tool(d, k, m) + Tool(d, k, m), + max_preference(0) { for(set::const_iterator i=objects.begin(); i!=objects.end(); ++i) if(Track *t = dynamic_cast(*i)) @@ -24,6 +25,20 @@ ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const s done = true; set_status("No free endpoints"); } + + 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; + + types_by_length[parts.front().get_length()] = tt; + max_preference = max(max_preference, tt->get_autofit_preference()); + } } ExtendTool::~ExtendTool() @@ -154,23 +169,8 @@ void ExtendTool::finish() vector ExtendTool::create_straight(const Vector &start, const Angle &dir, float length, float limit) { - const Catalogue::ObjectMap &object_types = designer.get_catalogue().get_all(); - map types_by_length; - unsigned preference = 0; - 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; - - types_by_length[parts.front().get_length()] = tt; - preference = max(preference, tt->get_autofit_preference()); - } - vector lengths; + unsigned preference = max_preference; float removed = 0; while(length>limit) { diff --git a/source/designer/extendtool.h b/source/designer/extendtool.h index 69e184a..866d258 100644 --- a/source/designer/extendtool.h +++ b/source/designer/extendtool.h @@ -1,6 +1,7 @@ #ifndef EXTENDTOOL_H_ #define EXTENDTOOL_H_ +#include #include #include #include "libr2c2/object.h" @@ -10,6 +11,8 @@ class ExtendTool: public Tool { private: + std::map types_by_length; + unsigned max_preference; std::vector unlinked_endpoints; std::vector extend_tracks; -- 2.45.2