3 #include <msp/strings/format.h>
4 #include "libr2c2/tracktype.h"
6 #include "manipulator.h"
13 Manipulator::Manipulator(Designer &d, Input::Keyboard &k, Input::Mouse &m, const set<Object *> &objs):
16 set<Object *> pending = objs;
17 while(!pending.empty())
19 for(set<Object *>::iterator i=pending.begin(); i!=pending.end(); )
21 if((*i)->get_parent() && pending.count((*i)->get_parent()))
25 objects.push_back(*i);
31 Geometry::BoundingBox<float, 3> bbox;
32 for(vector<MObject>::iterator i=objects.begin(); i!=objects.end(); ++i)
33 bbox = bbox|i->object->get_bounding_box();
35 const Vector &minp = bbox.get_minimum_point();
36 const Vector &maxp = bbox.get_maximum_point();
38 center = (minp+maxp)/2.0f;
40 for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
42 i->original_position = i->object->get_position()-center;
43 i->original_rotation = i->object->get_rotation();
47 Manipulator::~Manipulator()
51 for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
53 i->object->set_position(center+i->original_position);
54 i->object->set_rotation(i->original_rotation);
59 void Manipulator::finish()
61 set<Object *> object_set;
62 for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
63 object_set.insert(i->object);
64 for(ObjectArray::iterator i=objects.begin(); i!=objects.end(); ++i)
66 unsigned nls = i->object->get_n_link_slots();
67 for(unsigned j=0; j<nls; ++j)
68 if(Object *link = i->object->get_link(j))
69 if(!object_set.count(link))
70 i->object->break_link(j);
73 const set<Track *> <racks = designer.get_layout().get_all<Track>();
74 for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
77 for(vector<MObject>::iterator j=objects.begin(); (j!=objects.end() && ok); ++j)
81 for(vector<MObject>::iterator j=objects.begin(); j!=objects.end(); ++j)
82 j->object->link_to(**i);
87 Manipulator::MObject::MObject(Object *o):
89 original_position(object->get_position()),
90 original_rotation(object->get_rotation())