]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/manipulator.cpp
Compute deterministic IDs for blocks
[r2c2.git] / source / designer / manipulator.cpp
index 1f21430737c6c2f7d9dcda85869c02cddd1847da..09d32fd8bfdeb782aff9d514c449528a234b012d 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the GPL
 #include <algorithm>
 #include <cmath>
 #include <GL/gl.h>
+#include <msp/strings/formatter.h>
 #include "3d/layout.h"
 #include "libmarklin/tracktype.h"
 #include "designer.h"
@@ -18,8 +19,6 @@ using namespace std;
 using namespace Marklin;
 using namespace Msp;
 
-#include <iostream>
-
 Manipulator::Manipulator(Designer &d):
        designer(d),
        selection(0),
@@ -327,10 +326,7 @@ void Manipulator::pointer_motion(int, int y, float gx, float gy)
        {
                float dz = (y-elev_origin)/1000.;
 
-               ostringstream ss;
-               ss.precision(3);
-               ss<<"Elevation: "<<dz*1000<<"mm ("<<(center.z+dz)*1000<<"mm)";
-               signal_status.emit(ss.str());
+               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)
@@ -391,6 +387,7 @@ 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);
@@ -408,7 +405,7 @@ void Manipulator::update_wrap()
                                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+maxp.z)/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;
@@ -421,6 +418,7 @@ void Manipulator::update_wrap()
                {
                        min_x = max_x = tw.pos.x;
                        min_y = max_y = tw.pos.y;
+                       min_z = tw.pos.z;
                }
                else
                {
@@ -428,22 +426,24 @@ void Manipulator::update_wrap()
                        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, 0);
+       center = Point((min_x+max_x)/2, (min_y+max_y)/2, min_z);
        wrap_pos = center;
        wrap_rot = 0;
        for(vector<MTrack>::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);
+               i->pos = Point(tp.x-center.x, tp.y-center.y, tp.z-center.z);
        }
        for(list<TrackWrap>::iterator i=wrap.begin(); i!=wrap.end(); ++i)
        {
                i->pos.x -= center.x;
                i->pos.y -= center.y;
+               i->pos.z -= center.z;
        }
 }