- for(vector<MTrack>::iterator j=tracks.begin(); (j!=tracks.end() && !snapped); ++j)
- if(j->track->snap_to(**i, false))
- snapped = &*j;
- }
-
- if(snapped)
- {
- float da = snapped->track->get_rotation()-snapped->rot;
- float c = cos(da);
- float s = sin(da);
- const Point &sp = snapped->track->get_position();
- for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
- {
- if(&*i==snapped)
- continue;
-
- Point dp(i->pos.x-snapped->pos.x, i->pos.y-snapped->pos.y, 0);
- i->track->set_position(Point(sp.x+c*dp.x-s*dp.y, sp.y+s*dp.x+c*dp.y, sp.z));
- i->track->set_rotation(i->rot+da);
- }
- }
- }
- else if(mode==ROTATE)
- {
- float a = atan2(gpointer.y-center.y, gpointer.x-center.x);
- angle += a-rot_origin;
- rot_origin = a;
-
- wrap_rot = angle;
- for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
- {
- float c = cos(angle);
- float s = sin(angle);
- i->track->set_position(Point(center.x+c*i->pos.x-s*i->pos.y, center.y+s*i->pos.x+c*i->pos.y, center.z*i->pos.z));
- i->track->set_rotation(angle+i->rot);
- }
- }
- else if(mode==ELEVATE)
- {
- float dz = (y-elev_origin)/1000.;
-
- signal_status.emit(format("Elevation: %+.0fmm (%.0fmm)", dz*1000, (center.z+dz)*1000));
-
- wrap_pos.z = center.z+dz;
- for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
- i->track->set_position(Point(center.x+i->pos.x, center.y+i->pos.y, center.z+i->pos.z+dz));
-
- for(set<Track *>::iterator i=neighbors.begin(); i!=neighbors.end(); ++i)
- (*i)->check_slope();
- }
-}
-
-void Manipulator::render()
-{
- glPushMatrix();
- glTranslatef(wrap_pos.x, wrap_pos.y, wrap_pos.z);
- glRotatef(wrap_rot*180/M_PI, 0, 0, 1);
-
- glLineWidth(2);
- glColor4f(0, 1, 0, 0.5);
- for(list<TrackWrap>::iterator i=wrap.begin(); i!=wrap.end(); ++i)
- {
- glPushMatrix();
- glTranslatef(i->pos.x, i->pos.y, i->pos.z);
- glRotatef(i->rot*180/M_PI, 0, 0, 1);
-
- glBegin(GL_LINE_LOOP);
- glVertex2f(-i->width/2, -i->height/2);
- glVertex2f(i->width/2, -i->height/2);
- glVertex2f(i->width/2, i->height/2);
- glVertex2f(-i->width/2, i->height/2);
- glEnd();
-
- glPopMatrix();
- }
-
- glPopMatrix();
-}
-
-/*** private ***/
-
-void Manipulator::selection_changed()
-{
- if(mode)
- cancel();
-
- tracks.clear();
- const set<Track *> &stracks = selection.get_tracks();
- tracks.insert(tracks.end(), stracks.begin(), stracks.end());
-
- update_neighbors();
- update_wrap();
-}
-
-void Manipulator::update_wrap()
-{
- wrap.clear();
- float min_x = 0, max_x = 0;
- float min_y = 0, max_y = 0;
- float min_z = 0;
- for(vector<MTrack>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
- {
- Track3D &t3d = designer.get_layout_3d()->get_track(*i->track);
-
- TrackWrap tw;
- float min_area = 100;
- for(float a=0; a<M_PI; a+=0.01)
- {
- Point minp, maxp;
- t3d.get_bounds(a, minp, maxp);
- float area = (maxp.x-minp.x)*(maxp.y-minp.y);
- if(area<min_area)
- {
- float c = cos(a);
- float s = sin(a);
- float x = (minp.x+maxp.x)/2;
- float y = (minp.y+maxp.y)/2;
- tw.pos = Point(c*x-s*y, s*x+c*y, minp.z);
- tw.rot = a;
- tw.width = maxp.x-minp.x+0.01;
- tw.height = maxp.y-minp.y+0.01;
-
- min_area = area;
- }
- }
-
- if(i==tracks.begin())
- {
- min_x = max_x = tw.pos.x;
- min_y = max_y = tw.pos.y;
- min_z = tw.pos.z;