X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fmanipulator.cpp;h=64cbbd4ac68e70745512f4ce56e96809c17f9e0e;hb=897f9bae5f647bae43e9786796eb9ea18325ec17;hp=029bbbad8890eb74854c53721b9f661fa6bb9d5d;hpb=45ec6f645ff2c303700711e96421c75acf33db1a;p=r2c2.git diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index 029bbba..64cbbd4 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -7,9 +7,7 @@ Distributed under the GPL #include #include -#include #include -#include "3d/layout.h" #include "libmarklin/tracktype.h" #include "designer.h" #include "manipulator.h" @@ -22,7 +20,6 @@ using namespace Msp; Manipulator::Manipulator(Designer &d, Selection &s): designer(d), selection(s), - wrap_rot(0), mode(NONE), angle(0) { @@ -105,7 +102,7 @@ void Manipulator::flatten() for(set::iterator i=neighbors.begin(); i!=neighbors.end(); ++i) (*i)->check_slope(); - update_wrap(); + update_tracks(); } void Manipulator::even_slope(bool smooth) @@ -192,7 +189,7 @@ void Manipulator::even_slope(bool smooth) for(set::iterator i=neighbors.begin(); i!=neighbors.end(); ++i) (*i)->check_slope(); - update_wrap(); + update_tracks(); } void Manipulator::cancel() @@ -201,7 +198,6 @@ void Manipulator::cancel() return; mode = NONE; - wrap_pos = center; for(vector::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)); @@ -212,7 +208,6 @@ void Manipulator::cancel() (*i)->check_slope(); angle = 0; - wrap_rot = 0; signal_done.emit(false); } @@ -224,7 +219,6 @@ void Manipulator::button_press(int, int, float, float, unsigned btn) else if(mode) { mode = NONE; - update_wrap(); angle = 0; for(set::iterator i=neighbors.begin(); i!=neighbors.end(); ++i) @@ -243,9 +237,7 @@ void Manipulator::button_press(int, int, float, float, unsigned btn) j->track->snap_to(**i, true); } - for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) - i->rot = i->track->get_rotation(); - + update_tracks(); update_neighbors(); signal_done.emit(true); @@ -260,11 +252,10 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy) if(mode==MOVE) { Point delta(gpointer.x-move_origin.x, gpointer.y-move_origin.y, 0); - - wrap_pos = Point(center.x+delta.x, center.y+delta.y, center.z); + Point offset(center.x+delta.x, center.y+delta.y, center.z); for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - i->track->set_position(Point(wrap_pos.x+i->pos.x, wrap_pos.y+i->pos.y, wrap_pos.z+i->pos.z)); + i->track->set_position(Point(offset.x+i->pos.x, offset.y+i->pos.y, offset.z+i->pos.z)); i->track->set_rotation(i->rot); } @@ -305,12 +296,11 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy) angle += a-rot_origin; rot_origin = a; - wrap_rot = angle; for(vector::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_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); } } @@ -320,7 +310,6 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy) signal_status.emit(format("Elevation: %+.0fmm (%.0fmm)", dz*1000, (center.z+dz)*1000)); - wrap_pos.z = center.z+dz; for(vector::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)); @@ -329,33 +318,6 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy) } } -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::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(); -} - void Manipulator::selection_changed() { if(mode) @@ -366,71 +328,37 @@ void Manipulator::selection_changed() tracks.insert(tracks.end(), stracks.begin(), stracks.end()); update_neighbors(); - update_wrap(); + update_tracks(); } -void Manipulator::update_wrap() +void Manipulator::update_tracks() { - wrap.clear(); - float min_x = 0, max_x = 0; - float min_y = 0, max_y = 0; - float min_z = 0; + Point minp, maxp; for(vector::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; atrack->get_type().get_endpoints().size(); + for(unsigned j=0; jtrack->get_endpoint_position(j); + if(i==tracks.begin() && j==0) + minp = maxp = p; + else { - 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; + minp.x = min(minp.x, p.x); + maxp.x = max(maxp.x, p.x); + minp.y = min(minp.y, p.y); + maxp.y = max(maxp.y, p.y); + minp.z = min(minp.z, p.z); } } - - if(i==tracks.begin()) - { - min_x = max_x = tw.pos.x; - min_y = max_y = tw.pos.y; - min_z = tw.pos.z; - } - else - { - min_x = min(min_x, tw.pos.x); - max_x = max(max_x, tw.pos.x); - min_y = min(min_y, tw.pos.y); - max_y = max(max_y, tw.pos.y); - min_z = min(min_z, tw.pos.z); - } - wrap.push_back(tw); } - center = Point((min_x+max_x)/2, (min_y+max_y)/2, min_z); - wrap_pos = center; - wrap_rot = 0; + center = Point((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, minp.z); for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { const Point &tp = i->track->get_position(); i->pos = Point(tp.x-center.x, tp.y-center.y, tp.z-center.z); - } - for(list::iterator i=wrap.begin(); i!=wrap.end(); ++i) - { - i->pos.x -= center.x; - i->pos.y -= center.y; - i->pos.z -= center.z; + i->rot = i->track->get_rotation(); } }