using namespace R2C2;
ExtendTool::ExtendTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objects):
- Tool(d, k, m)
+ Tool(d, k, m),
+ max_preference(0)
{
for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
if(Track *t = dynamic_cast<Track *>(*i))
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<const TrackType *>(i->second))
+ {
+ const vector<TrackPart> &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()
vector<Track *> ExtendTool::create_straight(const Vector &start, const Angle &dir, float length, float limit)
{
- const Catalogue::ObjectMap &object_types = designer.get_catalogue().get_all();
- map<float, const TrackType *> 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<const TrackType *>(i->second))
- {
- const vector<TrackPart> &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<float> lengths;
+ unsigned preference = max_preference;
float removed = 0;
while(length>limit)
{
#ifndef EXTENDTOOL_H_
#define EXTENDTOOL_H_
+#include <map>
#include <set>
#include <vector>
#include "libr2c2/object.h"
class ExtendTool: public Tool
{
private:
+ std::map<float, const R2C2::TrackType *> types_by_length;
+ unsigned max_preference;
std::vector<R2C2::TrackIter> unlinked_endpoints;
std::vector<R2C2::Track *> extend_tracks;