1 #include "libr2c2/layout.h"
9 MoveTool::MoveTool(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &o):
10 Manipulator(d, k, m, o),
11 origin(ground_pointer)
13 for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
15 unsigned nls = i->object->get_n_link_slots();
16 unsigned nsn = i->object->get_n_snap_nodes();
19 if(!o.count(i->object->get_link(j)))
20 boundaries.push_back(Boundary(&*i, j));
22 boundaries.push_back(Boundary(&*i, j));
25 snap_targets = designer.get_layout().get_all<Object>();
26 for(ObjectArray::const_iterator i=objects.begin(); i!=objects.end(); ++i)
27 snap_targets.erase(i->object);
30 void MoveTool::pointer_motion()
32 Vector offset = center+ground_pointer-origin;
33 for(vector<MObject>::iterator i=objects.begin(); i!=objects.end(); ++i)
35 i->object->set_position(offset+i->original_position);
36 i->object->set_rotation(i->original_rotation);
39 float limit = designer.get_camera_controller().get_view_scale()/100.0f;
41 for(list<Boundary>::iterator i=boundaries.begin(); (!snapped && i!=boundaries.end()); ++i)
43 for(set<Object *>::const_iterator j=snap_targets.begin(); (!snapped && j!=snap_targets.end()); ++j)
44 if((*i)->snap_to(**j, (i->limit>0 ? max(i->limit, limit) : limit)))
50 Angle da = snapped->object->get_rotation()-snapped->original_rotation;
51 Transform trans = Transform::rotation(da, Vector(0, 0, 1));
52 const Vector &sp = snapped->object->get_position();
53 for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
58 i->object->set_position(sp+trans.transform(i->original_position-snapped->original_position));
59 i->object->set_rotation(i->original_rotation+da);
65 MoveTool::Boundary::Boundary(MObject *o, unsigned i):
70 if(Track *track = dynamic_cast<Track *>(object->object))
71 limit = track->get_type().get_gauge();