using namespace R2C2;
ExtendTool::ExtendTool(Designer &d, Input::Mouse &m, const set<Object *> &objects):
- Tool(d, m),
- accepted(false)
+ Tool(d, m)
{
for(set<Object *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
if(Track *t = dynamic_cast<Track *>(*i))
extend_tracks.front()->link_to(*start_track);
extend_tracks.back()->link_to(*end_track);
- accepted = true;
- set_done();
+ set_done(true);
}
-void ExtendTool::button_press(unsigned btn)
+void ExtendTool::pointer_motion()
{
- if(btn==1)
- {
- for(vector<TrackIter>::const_iterator i=unlinked_endpoints.begin(); i!=unlinked_endpoints.end(); ++i)
- if(extend_tracks.front()->link_to(**i))
- break;
- accepted = true;
- set_done();
- }
- else if(btn==3)
- set_done();
-}
-
-void ExtendTool::axis_motion(unsigned axis, float value, float rel)
-{
- Tool::axis_motion(axis, value, rel);
-
Vector pos;
Angle dir;
float length = 0;
}
}
+void ExtendTool::finish()
+{
+ for(vector<TrackIter>::const_iterator i=unlinked_endpoints.begin(); i!=unlinked_endpoints.end(); ++i)
+ if(extend_tracks.front()->link_to(**i))
+ break;
+}
+
vector<Track *> ExtendTool::create_straight(const Vector &start, const Angle &dir, float length, float limit)
{
const Catalogue::TrackMap &track_types = designer.get_catalogue().get_tracks();
private:
std::vector<R2C2::TrackIter> unlinked_endpoints;
std::vector<R2C2::Track *> extend_tracks;
- bool accepted;
public:
ExtendTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
void connect();
- virtual void button_press(unsigned);
- virtual void axis_motion(unsigned, float, float);
-
private:
+ virtual void pointer_motion();
+ virtual void finish();
+
std::vector<R2C2::Track *> create_straight(const R2C2::Vector &, const R2C2::Angle &, float, float);
public:
using namespace Msp;
Manipulator::Manipulator(Designer &d, Input::Mouse &m, const set<Object *> &objs):
- Tool(d, m),
- accepted(false)
+ Tool(d, m)
{
set<Object *> pending = objs;
while(!pending.empty())
}
}
-void Manipulator::button_press(unsigned btn)
+void Manipulator::finish()
{
- if(btn==3)
- set_done();
- else if(btn==1)
+ set<Object *> object_set;
+ for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
+ object_set.insert(i->object);
+ for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
{
- set<Object *> object_set;
- for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
- object_set.insert(i->object);
- for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
- {
- unsigned nls = i->object->get_n_link_slots();
- for(unsigned j=0; j<nls; ++j)
- if(Object *link = i->object->get_link(j))
- if(!object_set.count(link))
- i->object->break_link(j);
- }
-
- const set<Track *> <racks = designer.get_layout().get_all<Track>();
- for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
- {
- bool ok = true;
- for(vector<MObject>::iterator j=objects.begin(); (j!=objects.end() && ok); ++j)
- ok = (j->object!=*i);
- if(!ok) continue;
+ unsigned nls = i->object->get_n_link_slots();
+ for(unsigned j=0; j<nls; ++j)
+ if(Object *link = i->object->get_link(j))
+ if(!object_set.count(link))
+ i->object->break_link(j);
+ }
- for(vector<MObject>::iterator j=objects.begin(); j!=objects.end(); ++j)
- j->object->link_to(**i);
- }
+ const set<Track *> <racks = designer.get_layout().get_all<Track>();
+ for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
+ {
+ bool ok = true;
+ for(vector<MObject>::iterator j=objects.begin(); (j!=objects.end() && ok); ++j)
+ ok = (j->object!=*i);
+ if(!ok) continue;
- accepted = true;
- set_done();
+ for(vector<MObject>::iterator j=objects.begin(); j!=objects.end(); ++j)
+ j->object->link_to(**i);
}
}
ObjectArray objects;
R2C2::Vector center;
- bool accepted;
public:
Manipulator(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
virtual ~Manipulator();
private:
- virtual void button_press(unsigned);
+ virtual void finish();
};
#endif
update_mesh();
}
else
- {
- done = true;
- signal_done.emit();
- }
+ set_done(true);
}
}
-void Measure::axis_motion(unsigned axis, float x, float y)
+void Measure::pointer_motion()
{
- Tool::axis_motion(axis, x, y);
-
Snap sn = start;
sn.position = ground_pointer;
snap_to_tracks(sn);
float get_perpendicular_distance() const { return perp_dist; }
const R2C2::Angle &get_angle_difference() const { return adiff; }
+private:
virtual void button_press(unsigned);
- virtual void axis_motion(unsigned, float, float);
+ virtual void pointer_motion();
+public:
virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const;
private:
void update_mesh();
snap_targets.erase(i->object);
}
-void MoveTool::axis_motion(unsigned axis, float value, float rel)
+void MoveTool::pointer_motion()
{
- Manipulator::axis_motion(axis, value, rel);
-
Vector offset = center+ground_pointer-origin;
for(vector<MObject>::iterator i=objects.begin(); i!=objects.end(); ++i)
{
public:
MoveTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
- virtual void axis_motion(unsigned, float, float);
+ virtual void pointer_motion();
};
#endif
origin(Geometry::atan2(ground_pointer.y-center.y, ground_pointer.x-center.x))
{ }
-void RotateTool::axis_motion(unsigned axis, float value, float rel)
+void RotateTool::pointer_motion()
{
- Manipulator::axis_motion(axis, value, rel);
-
Angle a = Geometry::atan2(ground_pointer.y-center.y, ground_pointer.x-center.x);
angle += a-origin;
origin = a;
public:
RotateTool(Designer &, Msp::Input::Mouse &, const std::set<R2C2::Object *> &);
- virtual void axis_motion(unsigned, float, float);
+ virtual void pointer_motion();
};
#endif
if(!dynamic_cast<Track *>(*i) || (*i)->get_n_link_slots()!=2)
{
set_status("Must have linear tracks only");
- set_done();
+ set_done(false);
return;
}
Tool::Tool(Designer &d, Input::Mouse &mouse):
designer(d),
- done(false)
+ done(false),
+ accepted(false)
{
mouse.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::button_press), false));
mouse.signal_axis_motion.connect(sigc::bind_return(sigc::mem_fun(this, &Tool::axis_motion), false));
signal_status.emit(status);
}
-void Tool::set_done()
+void Tool::set_done(bool a)
{
+ accepted = a;
done = true;
signal_done.emit();
}
+void Tool::button_press(unsigned btn)
+{
+ if(btn==1)
+ {
+ finish();
+ set_done(true);
+ }
+ else if(btn==3)
+ set_done(false);
+}
+
void Tool::axis_motion(unsigned axis, float value, float)
{
if(axis==0)
else if(axis==1)
pointer.y = value;
ground_pointer = designer.map_pointer_to_ground(pointer);
+
+ pointer_motion();
}
R2C2::Vector ground_pointer;
std::string status;
bool done;
+ bool accepted;
Tool(Designer &, Msp::Input::Mouse &);
public:
protected:
void set_status(const std::string &);
- void set_done();
+ void set_done(bool);
public:
const std::string &get_status() const { return status; }
bool is_done() const { return done; }
- virtual void button_press(unsigned) { }
+protected:
+ virtual void button_press(unsigned);
virtual void axis_motion(unsigned, float, float);
+ virtual void pointer_motion() { }
+ virtual void finish() { }
+public:
virtual void update_selection(Selection &) const { }
};