X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fmeasure.cpp;h=937856c55bcce61a5baaae44c21d33907d3a9947;hb=100c7f252e145f095205c55a178ab57bb8da7e75;hp=f0d64e2f4d893b91da0a9bd7af60b65dc8e0ebdf;hpb=e214fd389b9819eac0379cfb78e0f446e267b839;p=r2c2.git diff --git a/source/designer/measure.cpp b/source/designer/measure.cpp index f0d64e2..937856c 100644 --- a/source/designer/measure.cpp +++ b/source/designer/measure.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "designer.h" #include "3d/layout.h" #include "measure.h" @@ -9,78 +11,81 @@ using namespace std; using namespace R2C2; using namespace Msp; -Measure::Measure(Designer &d): - designer(d), - state(NONE), +Measure::Measure(Designer &d, Input::Keyboard &k, Input::Mouse &m): + Tool(d, k, m), + start_pinned(false), mesh((GL::COLOR4_UBYTE, GL::VERTEX3)) -{ } - -void Measure::start() { - state = STARTING; update_mesh(); + + designer.get_layout_3d().get_scene().add(*this); +} + +Measure::~Measure() +{ + designer.get_layout_3d().get_scene().remove(*this); } -void Measure::button_press(float gx, float gy, unsigned btn) +void Measure::back() { - if(!state) - return; + if(start_pinned) + { + start_pinned = false; + update_mesh(); + } + else + set_done(true); +} +void Measure::key_press(unsigned key) +{ + if(key==Input::KEY_ESC) + back(); + else + Tool::key_press(key); +} + +void Measure::button_press(unsigned btn) +{ if(btn==1) { - ssnap.position = Vector(gx, gy, 0); - ssnap.rotation = Angle::zero(); - snap_to_tracks(ssnap); + start.position = ground_pointer; + start.rotation = Angle::zero(); + snap_to_tracks(start); - state = ACTIVE; + start_pinned = true; } else if(btn==3) - { - if(state==ACTIVE) - { - state = STARTING; - update_mesh(); - } - else - { - state = NONE; - signal_done.emit(); - } - } + back(); } -void Measure::pointer_motion(float gx, float gy) +void Measure::pointer_motion() { - if(!state) - return; - - Snap sn = ssnap; - sn.position = Vector(gx, gy, 0); + Snap sn = start; + sn.position = ground_pointer; snap_to_tracks(sn); - pointer = sn.position; + ground_pointer = sn.position; - if(state!=STARTING) + if(start_pinned) { - Vector delta = rotated_vector(pointer-ssnap.position, -ssnap.rotation); + Vector delta = rotated_vector(ground_pointer-start.position, -start.rotation); par_dist = delta.x; perp_dist = delta.y; - adiff = wrap_balanced(sn.rotation-ssnap.rotation+Angle::half_turn()); + adiff = wrap_balanced(sn.rotation-start.rotation+Angle::half_turn()); update_mesh(); - signal_changed.emit(); + string info = format("Par %.1fmm - Perp %.1fmm - Total %.1fmm - Angle %.1f°", par_dist*1000, perp_dist*1000, delta.norm()*1000, adiff.degrees()); + signal_status.emit(info); } } void Measure::render(GL::Renderer &renderer, const GL::Tag &) const { - if(state==NONE) - return; - GL::Renderer::Push push(renderer); - const Vector &pos = (state==ACTIVE ? ssnap.position : pointer); + const Vector &pos = (start_pinned ? start.position : ground_pointer); renderer.matrix_stack() *= GL::Matrix::translation(pos); mesh.draw(renderer); @@ -101,17 +106,17 @@ void Measure::update_mesh() } bld.end(); - if(state==ACTIVE) + if(start_pinned) { - float c = cos(ssnap.rotation); - float s = sin(ssnap.rotation); + float c = cos(start.rotation); + float s = sin(start.rotation); bld.begin(GL::QUAD_STRIP); bld.vertex(0, 0, 0); bld.vertex(0, 0, 0.01); bld.vertex(c*par_dist, s*par_dist, 0); bld.vertex(c*par_dist, s*par_dist, 0.01); - bld.vertex(pointer.x-ssnap.position.x, pointer.y-ssnap.position.y, 0); - bld.vertex(pointer.x-ssnap.position.x, pointer.y-ssnap.position.y, 0.01); + bld.vertex(ground_pointer.x-start.position.x, ground_pointer.y-start.position.y, 0); + bld.vertex(ground_pointer.x-start.position.x, ground_pointer.y-start.position.y, 0.01); bld.vertex(0, 0, 0); bld.vertex(0, 0, 0.01); bld.end();