diff --git a/.gitattributes b/.gitattributes index 14594266fb8..d3f295c0e78 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1605,6 +1605,7 @@ Packages/Qt_widget/include/CGAL/IO/pixmaps/optimal_convex.xpm -text Packages/Qt_widget/include/CGAL/IO/pixmaps/point.xpm -text Packages/Qt_widget/include/CGAL/IO/pixmaps/points.xpm -text Packages/Qt_widget/include/CGAL/IO/pixmaps/polygon.xpm -text +Packages/Qt_widget/include/CGAL/IO/pixmaps/rotation.xpm -text Packages/Qt_widget/include/CGAL/IO/pixmaps/show_polygon.xpm -text Packages/Qt_widget/include/CGAL/IO/pixmaps/triangulation.xpm -text Packages/Qt_widget/include/CGAL/IO/pixmaps/voronoi.xpm -text diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h index 2d86fe12660..0f4e9fe0158 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget.h @@ -19,7 +19,7 @@ // $Revision$ $Date$ // $Name$ // -// Author(s) : Laurent Rineau +// Author(s) : Laurent Rineau && Radu Ursu #ifndef CGAL_QT_WIDGET_H #define CGAL_QT_WIDGET_H @@ -48,6 +48,9 @@ #include #include +typedef CGAL::Simple_cartesian SCD; +typedef CGAL::Aff_transformation_2 Transformation; + namespace CGAL { class Qt_widget_layer; @@ -135,6 +138,9 @@ public: // coordinates system // ~~~~~~~~~~~~~~~~~~ // real world coordinates + // x_real, y_real are deprecated + // as soon as rotations are used, those functions are not good. + // users should use only xy_real double x_real(int x) const; double y_real(int y) const; template @@ -145,6 +151,8 @@ public: void x_real(int, Gmpq&) const; void y_real(int, Gmpq&) const; #endif + template + void xy_real(int, int, FT&, FT&) const; double x_real_dist(double d) const; double y_real_dist(double d) const; @@ -153,6 +161,8 @@ public: // pixel coordinates int x_pixel(double x) const; int y_pixel(double y) const; + void xy_pixel(const double x, const double y, + int &x_result, int &y_result) const; int x_pixel_dist(double d) const; int y_pixel_dist(double d) const; @@ -218,6 +228,10 @@ public: void add_to_history() { emit(internal_add_to_history()); } void clear_history() { emit(internal_clear_history()); } + Transformation* get_transformation(){return t;}; + void set_transformation(const Transformation &newt){(*t) = newt;}; + + protected: void paintEvent(QPaintEvent *e); void resizeEvent(QResizeEvent *e); @@ -279,6 +293,9 @@ private: //backup ranges for resize double xscal, yscal; // scales int/double bool constranges; // tell if the ranges should be const + Transformation *t; //this transformation is used to perform mainly + //rotations. It is initialised in the constructor. + //this will remove xscal, yscal in the future //for layers std::list qt_layers; @@ -458,8 +475,9 @@ void Qt_widget::setPointStyle(const PointStyle ps) template Qt_widget& operator<<(Qt_widget& w, const Point_2& p) { - int x = w.x_pixel(CGAL::to_double(p.x())); - int y = w.y_pixel(CGAL::to_double(p.y())); + int x, y; + w.xy_pixel(CGAL::to_double(p.x()), + CGAL::to_double(p.y()), x, y); uint size=w.pointSize(); PointStyle ps=w.pointStyle(); @@ -752,42 +770,94 @@ Qt_widget& operator<<(Qt_widget& w, const Bbox_2& r); // see Qt_widget for the implementation of this non-template function #endif // CGAL_BBOX_2_H -// templated x_real and y_real - +// templated x_real and y_real keeped for backward compatibility +// as soon as someone use rotations, this functions are not good +// users should only use xy_real/xy_pixel template void Qt_widget::x_real(int x, FT& return_t) const { + double temp_x = static_cast(x); + double xnew = xmin + temp_x/xscal; + CGAL::Point_2 p1(xnew, 1); + p1 = (t->inverse())(p1); + if(xscal<1) - return_t = static_cast(xmin+(int)(x/xscal)); + return_t = static_cast((int)(p1.x())); else{ #ifdef CGAL_USE_GMP CGAL_Rational r = simplest_rational_in_interval( - xmin+x/xscal-(x/xscal-(x-1)/xscal)/2, - xmin+x/xscal+((x+1)/xscal-x/xscal)/2); + p1.x() - (1/xscal)/2, + p1.x() + (1/xscal)/2); return_t = static_cast(CGAL::to_double(r)); #else - return_t = static_cast(xmin+x/xscal); + return_t = static_cast(p1.x()); #endif } } + template void Qt_widget::y_real(int y, FT& return_t) const { - if(yscal<1) - return_t = static_cast(ymax-(int)(y/yscal)); - else{ + double temp_y = static_cast(y); + double ynew = ymax - temp_y/yscal; + CGAL::Point_2 p1(1, ynew); + p1 = (t->inverse())(p1); + + if(yscal<1) + return_t = static_cast((int)(p1.y())); + else{ #ifdef CGAL_USE_GMP CGAL_Rational r = simplest_rational_in_interval( - ymax - y/yscal-(y/yscal-(y-1)/yscal)/2, - ymax - y/yscal+((y+1)/yscal-y/yscal)/2); + p1.y() - (1/yscal)/2, + p1.y() + (1/yscal)/2); return_t = static_cast(CGAL::to_double(r)); #else - return_t = static_cast(ymax-y/yscal); + return_t = static_cast(p1.y()); #endif - } + } } +template +void Qt_widget::xy_real(int x, int y, + FT& x_result, FT& y_result) const +{ + double temp_x = static_cast(x); + double xnew = xmin + temp_x/xscal; + double temp_y = static_cast(y); + double ynew = ymax - temp_y/yscal; + CGAL::Point_2 p1(xnew, ynew); + p1 = (t->inverse())(p1); + + if(xscal<1) + x_result = static_cast((int)(p1.x())); + else{ +#ifdef CGAL_USE_GMP + CGAL_Rational r = simplest_rational_in_interval( + p1.x() - (1/xscal)/2, + p1.x() + (1/xscal)/2); + x_result = static_cast(CGAL::to_double(r)); +#else + x_result = static_cast(p1.x()); +#endif + } + + if(yscal<1) + y_result = static_cast((int)(p1.y())); + else{ +#ifdef CGAL_USE_GMP + CGAL_Rational r = simplest_rational_in_interval( + p1.y() - (1/yscal)/2, + p1.y() + (1/yscal)/2); + y_result = static_cast(CGAL::to_double(r)); +#else + y_result = static_cast(p1.y()); +#endif + } +} + + + } // namespace CGAL #endif // CGAL_QT_WIDGET_H diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_focus.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_focus.h index 2c4c2d76f12..57fb5ae9a9d 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_focus.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_focus.h @@ -114,8 +114,7 @@ private: && is_pure(e->state())) { double x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); widget->set_center(x, y); } }; diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_circle.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_circle.h index 68f9c3e17b7..b1be3a76845 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_circle.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_circle.h @@ -69,8 +69,7 @@ protected: && is_pure(e->state())) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); x1 = x; y1 = y; x2 = x; @@ -78,8 +77,7 @@ protected: firstpoint = true; } else if(e->button() == CGAL_QT_WIDGET_GET_POINT_BUTTON){ FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); widget->new_object(make_object(Circle(Point(x1,y1), squared_distance(Point(x1, y1), Point(x,y))))); firstpoint = false; @@ -134,8 +132,7 @@ protected: if(firstpoint==TRUE) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); QColor old_color = widget->color(); RasterOp old_raster = widget->rasterOp();//save the initial raster mode widget->setRasterOp(XorROP); diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_iso_rectangle.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_iso_rectangle.h index 36dbedbb631..d5b455b4737 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_iso_rectangle.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_iso_rectangle.h @@ -82,10 +82,8 @@ protected: } else { if((e->x() != first_x) && (e->y() != first_y)) { RT x, y, xfirst2, yfirst2; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); - widget->x_real(first_x, xfirst2); - widget->y_real(first_y, yfirst2); + widget->xy_real(e->x(), e->y(), x, y); + widget->xy_real(first_x, first_y, xfirst2, yfirst2); RT xmin, xmax, ymin, ymax; if(x < xfirst2) {xmin = x; xmax = xfirst2;} else {xmin = xfirst2; xmax = x;}; diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_line.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_line.h index ec89d91d2e9..4812fd232e8 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_line.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_line.h @@ -67,8 +67,7 @@ protected: && is_pure(e->state())) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); x1 = x; y1 = y; x2 = x; @@ -77,8 +76,7 @@ protected: } else if(e->button() == CGAL_QT_WIDGET_GET_POINT_BUTTON && is_pure(e->state())){ FT x, y; - widget->x_real(e->x(), x), - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); if(x1!=x || y1!=y) { widget->new_object(make_object(Line(Point(x1,y1),Point(x,y)))); firstpoint = FALSE; @@ -129,8 +127,7 @@ protected: if(firstpoint) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); RasterOp old_raster = widget->rasterOp();//save the initial raster mode QColor old_color = widget->color(); widget->setRasterOp(XorROP); diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_point.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_point.h index 5e539db820d..22c1b3aec59 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_point.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_point.h @@ -60,8 +60,7 @@ protected: && is_pure(e->state())) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); widget->new_object(make_object(Point(x, y))); } }; diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_polygon.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_polygon.h index 02c1b2dee45..7e2d30b5380 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_polygon.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_polygon.h @@ -81,9 +81,7 @@ protected: if(e->button() == Qt::LeftButton && is_pure(e->state())) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); - + widget->xy_real(e->x(), e->y(), x, y); if(!active) { active=true; @@ -156,9 +154,7 @@ protected: if (active) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); - + widget->xy_real(e->x(), e->y(), x, y); rubber = Point_2(x, y); widget->lock(); RasterOp old_rasterop=widget->rasterOp(); diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_segment.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_segment.h index 07e9e5dc96a..3af3202ee65 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_segment.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_segment.h @@ -64,8 +64,7 @@ protected: && is_pure(e->state())) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); x1 = x; y1 = y; x2 = x; @@ -74,8 +73,7 @@ protected: } else if(e->button() == CGAL_QT_WIDGET_GET_POINT_BUTTON && is_pure(e->state())){ FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); if(x1!=x || y1!=y) { widget->new_object( make_object(Segment(Point(x1,y1),Point(x,y)))); @@ -127,8 +125,7 @@ protected: if(firstpoint) { FT x, y; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); + widget->xy_real(e->x(), e->y(), x, y); RasterOp old_raster = widget->rasterOp();//save the initial raster mode QColor old_color = widget->color(); widget->setRasterOp(XorROP); diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h index af10b81e3c1..50d79c8eb2a 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_handtool.h @@ -93,11 +93,9 @@ private: { widget->setCursor(QCursor( QPixmap( (const char**)hand_xpm))); double x, y, xfirst2, yfirst2; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); - widget->x_real(first_x, xfirst2); - widget->y_real(first_y, yfirst2); - + widget->xy_real(e->x(), e->y(), x, y); + widget->xy_real(first_x, first_y, xfirst2, yfirst2); + double xmin, xmax, ymin, ymax, distx, disty; if(x < xfirst2) {xmin = x; xmax = xfirst2;} else {xmin = xfirst2; xmax = x;}; @@ -123,8 +121,7 @@ private: widget->lock(); *widget << CGAL::GRAY; if(!wasrepainted) { - widget->x_real(x2 - first_x, xcoord); - widget->x_real(y2 - first_y, ycoord); + widget->xy_real(x2 - first_x, y2 - first_y, xcoord, ycoord); CGAL_CLIB_STD::sprintf(tempc1, " dx=%20.6f", xcoord); CGAL_CLIB_STD::sprintf(tempc2, ", dy=%20.6f", ycoord); strcat(tempc1, tempc2); @@ -133,8 +130,7 @@ private: widget->get_painter().drawText(x2, y2, tempc1, 49); *widget << CGAL::GRAY; } - widget->x_real(x - first_x, xcoord); - widget->x_real(y - first_y, ycoord); + widget->xy_real(x - first_x, y - first_y, xcoord, ycoord); CGAL_CLIB_STD::sprintf(tempc1, " dx=%20.6f", xcoord); CGAL_CLIB_STD::sprintf(tempc2, ", dy=%20.6f", ycoord); strcat(tempc1, tempc2); diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_rotation_layer.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_rotation_layer.h new file mode 100644 index 00000000000..5b0bda5cce2 --- /dev/null +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_rotation_layer.h @@ -0,0 +1,223 @@ +// Copyright (c) 1997-2000 Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), +// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg +// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; version 2.1 of the License. +// See the file LICENSE.LGPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $Source$ +// $Revision$ $Date$ +// $Name$ +// +// Author(s) : Radu Ursu + +#ifndef CGAL_QT_WIDGET_ROTATION_LAYER_H +#define CGAL_QT_WIDGET_ROTATION_LAYER_H + + +#include +#include +#include +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian SCD; +typedef CGAL::Point_2 Point; +typedef CGAL::Vector_2 Vector; +typedef CGAL::Direction_2 Direction; +typedef CGAL::Aff_transformation_2 Transformation; + +namespace CGAL { + +class Qt_widget_rotation_layer : public Qt_widget_layer +{ +public: + Qt_widget_rotation_layer(QObject* parent = 0, const char* name = 0) + : Qt_widget_layer(parent, name), wasrepainted(true), on_first(false){}; + +private: + QCursor oldcursor; + + void draw(){ + wasrepainted = true; + }; +/* + void timerEvent( QTimerEvent *) + { + if(on_first) + widget->setCursor(QCursor( + QPixmap( (const char**)holddown_xpm))); + else + widget->setCursor(QCursor( + QPixmap( (const char**)hand_xpm))); + } +*/ + bool is_pure(Qt::ButtonState s){ + if((s & Qt::ControlButton) || + (s & Qt::ShiftButton) || + (s & Qt::AltButton)) + return 0; + else + return 1; + } + + void mousePressEvent(QMouseEvent *e) + { + if(e->button() == Qt::LeftButton + && is_pure(e->state())) + { + widget->setCursor(QCursor( QPixmap( (const char**)holddown_xpm))); + if (!on_first){ + first_x = e->x(); + first_y = e->y(); + on_first = true; + } + + Point end_point[4] = {Point(11, 25), Point(11, 25), + Point(11, 25), Point(11, 25)}; + for(int i=0; i<4; i++) + end_point[i] = (*t)(end_point[i]); + //Point_2 first_line_end1(11, 25), first_line_end2(11, 0); + //Point_2 second_line_end1(25, 0), second_line_end2(25, 13); + //first_line_end1 = (*t)(first_arrow_end); + //second_arrow_end = (*t)(second_arrow_end); + + //save the initial raster mode + RasterOp old = widget->rasterOp(); + widget->setRasterOp(XorROP); + widget->lock(); + *widget << CGAL::WHITE; + widget->get_painter().drawLine(11, 0, 11, 25); + widget->get_painter().drawLine(0, 13, 25, 13); + widget->get_painter().drawLine(11, 0, 9, 5); + widget->get_painter().drawLine(11, 0, 13, 5); + widget->get_painter().drawLine(25, 13, 20, 11); + widget->get_painter().drawLine(25, 13, 20, 15); + *widget << CGAL::RED; + + widget->unlock(); + widget->setRasterOp(old); + + } + }; + + void mouseReleaseEvent(QMouseEvent *e) + { + if(e->button() == Qt::LeftButton + && is_pure(e->state())) + { + /* + double x, y, xfirst2, yfirst2; + widget->x_real(e->x(), x); + widget->y_real(e->y(), y); + widget->x_real(first_x, xfirst2); + widget->y_real(first_y, yfirst2); + + double xmin, xmax, ymin, ymax, distx, disty; + if(x < xfirst2) {xmin = x; xmax = xfirst2;} + else {xmin = xfirst2; xmax = x;}; + if(y < yfirst2) {ymin = y; ymax = yfirst2;} + else {ymin = yfirst2; ymax = y;}; + distx = xfirst2 - x; + disty = yfirst2 - y; + widget->move_center(distx, disty); + + */ + /* + //(*t) = tprim * (*t); + on_first = false; + + + */ + double xc = widget->x_min() + (widget->x_max() - widget->x_min())/2; + double yc = widget->y_min() + (widget->y_max() - widget->y_min())/2; + Transformation tprim(CGAL::ROTATION, Direction(xc+0.0001, yc+0.0001), 1, 100); + //Transformation tprim(CGAL::TRANSLATION, Vector(-0.5, 0)); + //Transformation tprim(CGAL::SCALING, 1.2); + (*t) = (*t) * tprim; + on_first = false; + widget->setCursor(QCursor( QPixmap( (const char**)hand_xpm))); + widget->redraw(); + } + } + /* + void mouseMoveEvent(QMouseEvent *e) + { + char tempc1[130], tempc2[40]; + double xcoord, ycoord; + if(on_first) + { + int x = e->x(); + int y = e->y(); + //save the initial raster mode + RasterOp old = widget->rasterOp(); + widget->setRasterOp(XorROP); + widget->lock(); + *widget << CGAL::GRAY; + if(!wasrepainted) { + widget->x_real(x2 - first_x, xcoord); + widget->x_real(y2 - first_y, ycoord); + CGAL_CLIB_STD::sprintf(tempc1, " dx=%20.6f", xcoord); + CGAL_CLIB_STD::sprintf(tempc2, ", dy=%20.6f", ycoord); + strcat(tempc1, tempc2); + widget->get_painter().drawLine(first_x, first_y, x2, y2); + *widget << CGAL::GREEN; + widget->get_painter().drawText(x2, y2, tempc1, 49); + *widget << CGAL::GRAY; + } + widget->x_real(x - first_x, xcoord); + widget->x_real(y - first_y, ycoord); + CGAL_CLIB_STD::sprintf(tempc1, " dx=%20.6f", xcoord); + CGAL_CLIB_STD::sprintf(tempc2, ", dy=%20.6f", ycoord); + strcat(tempc1, tempc2); + widget->get_painter().drawLine(first_x, first_y, x, y); + *widget << CGAL::GREEN; + widget->get_painter().drawText(x, y, tempc1, 49); + widget->unlock(); + widget->setRasterOp(old); + + //save the last coordinates to redraw the screen + x2 = x; + y2 = y; + wasrepainted = false; + } + }; +*/ + void activating() + { + t = widget->get_transformation(); + oldcursor = widget->cursor(); + widget->setCursor(QCursor( QPixmap( (const char**)hand_xpm))); + wasrepainted = true; +// startTimer( 100 ); + }; + + void deactivating() + { + widget->setCursor(oldcursor); +// killTimers(); + }; + + int first_x, first_y; + int x2, y2; + bool wasrepainted; + bool on_first; + Transformation *t; +};//end class + +} // namespace CGAL + +#endif // CGAL_QT_WIDGET_ROTATION_LAYER_H diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_show_mouse_coordinates.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_show_mouse_coordinates.h index 26a7a24e20f..174c2377397 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_show_mouse_coordinates.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_show_mouse_coordinates.h @@ -47,8 +47,7 @@ public: { QString s("x=%1 y=%2"); double xcoord, ycoord; - widget->x_real(e->x(), xcoord); - widget->y_real(e->y(), ycoord); + widget->xy_real(e->x(), e->y(), xcoord, ycoord); qmw.statusBar()->message(s.arg(xcoord, -20, 'g', 15). arg(ycoord, -20,'g', 15)); diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h index a0bea5fd544..fa30e15df00 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_standard_toolbar.h @@ -69,13 +69,13 @@ private: void fill_toolbar(QMainWindow *mw); private: - Qt_widget *widget; - Qt_widget_history *history; - QButtonGroup* button_group; + Qt_widget *widget; + Qt_widget_history *history; + QButtonGroup* button_group; // this group has no parent and is destroyed manually in the // destructor - QToolButton* nolayerBt; + QToolButton* nolayerBt; };//end class };//end namespace diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h index be896cb6858..88f0326cade 100644 --- a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_zoomrect.h @@ -84,11 +84,9 @@ private: { if((e->x() != first_x) && (e->y() != first_y)) { double x, y, xfirst2, yfirst2; - widget->x_real(e->x(), x); - widget->y_real(e->y(), y); - widget->x_real(first_x, xfirst2); - widget->y_real(first_y, yfirst2); - + widget->xy_real(e->x(), e->y(), x, y); + widget->xy_real(first_x, first_y, xfirst2, yfirst2); + double xmin, xmax, ymin, ymax; if(x < xfirst2) {xmin = x; xmax = xfirst2;} else {xmin = xfirst2; xmax = x;}; diff --git a/Packages/Qt_widget/include/CGAL/IO/pixmaps/rotation.xpm b/Packages/Qt_widget/include/CGAL/IO/pixmaps/rotation.xpm new file mode 100644 index 00000000000..9a19315f1a6 --- /dev/null +++ b/Packages/Qt_widget/include/CGAL/IO/pixmaps/rotation.xpm @@ -0,0 +1,5 @@ +/* XPM */ +extern const char *rotation_xpm[]; +extern const char *rotation_small_xpm[]; + + diff --git a/Packages/Qt_widget/src/CGALQt/Qt_widget.C b/Packages/Qt_widget/src/CGALQt/Qt_widget.C index da356b59727..673d4a02ba5 100644 --- a/Packages/Qt_widget/src/CGALQt/Qt_widget.C +++ b/Packages/Qt_widget/src/CGALQt/Qt_widget.C @@ -41,6 +41,7 @@ Qt_widget::Qt_widget(QWidget *parent, const char *name) : xmax_old = xmax = 1; ymin_old = ymin = -1; ymax_old = ymax = 1; + t = new Transformation(); constranges=false; set_scales(); emit(rangesChanged()); @@ -404,40 +405,60 @@ void Qt_widget::zoom(double ratio) ymin + (ymax - ymin) / 2 ); } +// the methods x_real, y_real, x_pixel, y_pixel +// are all deprecated. As soon as someone use rotations +// this functions are not good enough +// Users should use from now on xy_pixel, xy_real + #ifdef CGAL_USE_GMP void Qt_widget::x_real(int x, Gmpq& return_t) const { + double temp_x = static_cast(x); + double xnew = xmin + temp_x/xscal; + CGAL::Point_2 p1(xnew, 1); + p1 = (t->inverse())(p1); return_t = simplest_rational_in_interval( - xmin+x/xscal-(1/xscal)/2, - xmin+x/xscal+(1/xscal)/2); + p1.x() - (1/xscal)/2, + p1.x() + (1/xscal)/2); } void Qt_widget::y_real(int y, Gmpq& return_t) const { + double temp_y = static_cast(y); + double ynew = ymax - temp_y/yscal; + CGAL::Point_2 p1(1, ynew); + p1 = (t->inverse())(p1); return_t = simplest_rational_in_interval( - ymax - y/yscal-(1/yscal)/2, - ymax - y/yscal+(1/yscal)/2); + p1.y() - (1/yscal)/2, + p1.y() + (1/yscal)/2); } #endif + double Qt_widget::x_real(int x) const { + double temp_x = static_cast(x); + double xnew = xmin + temp_x/xscal; + CGAL::Point_2 p1(xnew, 1); + p1 = (t->inverse())(p1); if(xscal<1) - return(xmin+(int)(x/xscal)); + return (int)(p1.x()); else - return (xmin+x/xscal); + return p1.x(); } double Qt_widget::y_real(int y) const { - if(yscal<1) - return(ymax-(int)(y/yscal)); - else - return (ymax-y/yscal); + double temp_y = static_cast(y); + double ynew = ymax - temp_y/yscal; + CGAL::Point_2 p1(1, ynew); + p1 = (t->inverse())(p1); + if(yscal<1) + return (int)(p1.y()); + else + return p1.y(); } - - double Qt_widget::x_real_dist(double d) const { return(d/xscal); @@ -450,14 +471,28 @@ double Qt_widget::y_real_dist(double d) const int Qt_widget::x_pixel(double x) const { - return( static_cast((x-xmin)*xscal+0.5) ); + CGAL::Point_2 p1(x, 1); + p1 = (*t)(p1); + return( static_cast((p1.x() - xmin)*xscal)); } int Qt_widget::y_pixel(double y) const { - return( - static_cast((y-ymax)*yscal+0.5) ); + CGAL::Point_2 p1(1, y); + p1 = (*t)(p1); + return( static_cast((ymax - p1.y())*yscal)); } +void Qt_widget::xy_pixel(const double x, const double y, + int &x_result, int &y_result) const +{ + CGAL::Point_2 p1(x, y); + p1 = (*t)(p1); + x_result = static_cast((p1.x() - xmin)*xscal); + y_result = static_cast((ymax - p1.y())*yscal); +} + + int Qt_widget::x_pixel_dist(double d) const { if (d>0) diff --git a/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C b/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C index 069c9c6a519..0fa06b98526 100644 --- a/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C +++ b/Packages/Qt_widget/src/CGALQt/Qt_widget_standard_toolbar.C @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,7 @@ #include #include #include +#include #include namespace CGAL { @@ -80,25 +82,29 @@ namespace CGAL { new Qt_widget_zoomrect(this, "zoomrectlayer"); Qt_widget_handtool* handtoollayer = new Qt_widget_handtool(this, "handtoollayer"); + Qt_widget_rotation_layer* rotationlayer = + new Qt_widget_rotation_layer(this, "rotation_layer"); Qt_widget_show_mouse_coordinates* showcoordlayer = 0; // created below widget->attach_standard(focuslayer); widget->attach_standard(zoomrectlayer); widget->attach_standard(handtoollayer); + widget->attach_standard(rotationlayer); focuslayer->deactivate(); zoomrectlayer->deactivate(); handtoollayer->deactivate(); + rotationlayer->deactivate(); if (mw) - { - mw->statusBar(); - showcoordlayer = - new Qt_widget_show_mouse_coordinates(*mw, this, + { + mw->statusBar(); + showcoordlayer = + new Qt_widget_show_mouse_coordinates(*mw, this, "showcoordlayer"); - widget->attach_standard(showcoordlayer); - showcoordlayer->does_eat_events = false; - widget->setMouseTracking(true); - } + widget->attach_standard(showcoordlayer); + showcoordlayer->does_eat_events = false; + widget->setMouseTracking(true); + } const QPixmap p1(arrow_small_xpm), p2(arrow_xpm); const QIconSet arrow_pixmap(p1, p2); @@ -109,6 +115,9 @@ namespace CGAL { const QPixmap p5(forward_small_xpm), p6(forward_xpm); const QIconSet forward_pixmap(p5, p6); + const QPixmap p7(rotation_small_xpm), p8(rotation_xpm); + const QIconSet rotation_pixmap(p7, p8); + QToolButton* backBt = new QToolButton(this, "History Back"); backBt->setIconSet(back_pixmap); backBt->setTextLabel("History Back"); @@ -145,18 +154,22 @@ namespace CGAL { nolayerBt->setIconSet(arrow_pixmap); nolayerBt->setTextLabel("Deactivate Standard Layer"); - QToolButton* zoomrectBt = new QToolButton(this, "focus on region"); + QToolButton* zoomrectBt = new QToolButton(this, "focus_on_region_layer"); zoomrectBt->setPixmap(QPixmap(zoomin_rect_xpm )); zoomrectBt->setTextLabel("Focus on region"); - QToolButton* focusBt = new QToolButton(this, "focus"); + QToolButton* focusBt = new QToolButton(this, "focuslayer"); focusBt->setPixmap(QPixmap(focus_xpm )); focusBt->setTextLabel("Focus on point"); - QToolButton* handtoolBt = new QToolButton(this, "handtool"); + QToolButton* handtoolBt = new QToolButton(this, "handlayer"); handtoolBt->setPixmap(QPixmap(hand_xpm )); handtoolBt->setTextLabel("Pan tool"); + QToolButton* rotationBt = new QToolButton(this, "rotation_layer"); + rotationBt->setIconSet(rotation_pixmap); + rotationBt->setTextLabel("Rotation tool.(EXPERIMENTAL!!!)"); + addSeparator(); QToolButton* showcoordBt = new QToolButton(this, "mouse"); @@ -171,12 +184,13 @@ namespace CGAL { QToolButton* const button_group_list[] = { nolayerBt, zoomrectBt, focusBt, - handtoolBt }; - for(int i=0; i<4; ++i) - { - button_group_list[i]->setToggleButton(true); - button_group->insert(button_group_list[i]); - } + handtoolBt, + rotationBt}; + for(int i=0; i<5; ++i) + { + button_group_list[i]->setToggleButton(true); + button_group->insert(button_group_list[i]); + } button_group->setExclusive(true); connect(button_group, SIGNAL(clicked(int)), this, SLOT(group_clicked(int))); @@ -192,6 +206,8 @@ namespace CGAL { focuslayer, SLOT(stateChanged(int))); connect(handtoolBt, SIGNAL(stateChanged(int)), handtoollayer, SLOT(stateChanged(int))); + connect(rotationBt, SIGNAL(stateChanged(int)), + rotationlayer, SLOT(stateChanged(int))); connect(showcoordBt, SIGNAL(stateChanged(int)), showcoordlayer, SLOT(stateChanged(int))); @@ -219,19 +235,17 @@ namespace CGAL { // button_group.id(nolayerBt)==0. if( i == id ) - { - if( i == 0) return; - // nolayer is on and cannot be set off like that. + { + if( i == 0) return; + // nolayer is on and cannot be set off like that. - QToolButton* tBt = - static_cast(button_group->find(i)); - if( tBt != 0) - tBt->setOn(false); - - nolayerBt->setOn(true); - id = 0; - } - else + QToolButton* tBt = + static_cast(button_group->find(i)); + if( tBt != 0) + tBt->setOn(false); + nolayerBt->setOn(true); + id = 0; + } else id = i; } @@ -260,3 +274,4 @@ namespace CGAL { #include "Qt_widget_standard_toolbar.moc" #endif + diff --git a/Packages/Qt_widget/src/CGALQt/Qt_widget_xpm_icons.C b/Packages/Qt_widget/src/CGALQt/Qt_widget_xpm_icons.C index 8c8882fab64..a0b51614e40 100644 --- a/Packages/Qt_widget/src/CGALQt/Qt_widget_xpm_icons.C +++ b/Packages/Qt_widget/src/CGALQt/Qt_widget_xpm_icons.C @@ -2106,3 +2106,69 @@ const char * demoicon_xpm[] = { "oooooooooooooooo" }; + +/* XPM */ +const char *rotation_small_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 16 2 1", +" c opaque", +". c None", +/* pixels */ +"................", +"....... .....", +"..... ....", +".. . .... ...", +".. . ...... ..", +".. ........ ..", +".. ...... ..", +".. ........ ..", +"........... ...", +"........... ...", +".......... ....", +"........ ....", +"...... ......", +"...... ........", +"................", +"................" +}; + +/* XPM */ +static char *rotation_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 2 1", +" c opaque", +". c None", +/* pixels */ +"................................", +"................................", +"................................", +"................................", +"............ ..........", +".......... .........", +".... ... ......... .......", +".... .. ............. ......", +".... ............... .....", +".... ................. .....", +".... ............... ....", +".... ................. ...", +".... .................... ...", +".... ...................... ...", +"........................... ...", +"........................... ...", +"........................... ...", +"........................... ...", +"........................... ...", +"........................... ...", +".......................... ...", +".......................... ....", +"......................... .....", +"........................ .....", +"...................... ......", +"..................... .......", +"........... .........", +"........... ...........", +"................................", +"................................", +"................................", +"................................" +};