mirror of https://github.com/CGAL/cgal
This version of Qt_widget knows how to use rotations.
This is achieved using Aff_transformation_2 of CGAL. x_real, y_real, x_pixel, y_pixel in all kind of versions (templated or not) are deprecated. xy_real, xy_pixel version were added. added a new rotation layer in the standard toolbar, but is only experimental. The only operator that is working well with rotations is the point output operator. The others are not modified. It is more complicated for geometric entities that intersects the boundaaries of the screen. I will do it one by one in time. I will update demos as soon as I make it work with all the ouput operators.
This commit is contained in:
parent
94af5b5d05
commit
0cf9c47d5f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <qpixmap.h>
|
||||
#include <qprinter.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> SCD;
|
||||
typedef CGAL::Aff_transformation_2<SCD> 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 <class FT>
|
||||
|
|
@ -145,6 +151,8 @@ public:
|
|||
void x_real(int, Gmpq&) const;
|
||||
void y_real(int, Gmpq&) const;
|
||||
#endif
|
||||
template <class FT>
|
||||
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_widget_layer*> qt_layers;
|
||||
|
|
@ -458,8 +475,9 @@ void Qt_widget::setPointStyle(const PointStyle ps)
|
|||
template <class R>
|
||||
Qt_widget& operator<<(Qt_widget& w, const Point_2<R>& 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 <class FT>
|
||||
void Qt_widget::x_real(int x, FT& return_t) const
|
||||
{
|
||||
double temp_x = static_cast<double>(x);
|
||||
double xnew = xmin + temp_x/xscal;
|
||||
CGAL::Point_2<SCD> p1(xnew, 1);
|
||||
p1 = (t->inverse())(p1);
|
||||
|
||||
if(xscal<1)
|
||||
return_t = static_cast<FT>(xmin+(int)(x/xscal));
|
||||
return_t = static_cast<FT>((int)(p1.x()));
|
||||
else{
|
||||
#ifdef CGAL_USE_GMP
|
||||
CGAL_Rational r = simplest_rational_in_interval<CGAL_Rational>(
|
||||
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<FT>(CGAL::to_double(r));
|
||||
#else
|
||||
return_t = static_cast<FT>(xmin+x/xscal);
|
||||
return_t = static_cast<FT>(p1.x());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class FT>
|
||||
void Qt_widget::y_real(int y, FT& return_t) const
|
||||
{
|
||||
if(yscal<1)
|
||||
return_t = static_cast<FT>(ymax-(int)(y/yscal));
|
||||
else{
|
||||
double temp_y = static_cast<double>(y);
|
||||
double ynew = ymax - temp_y/yscal;
|
||||
CGAL::Point_2<SCD> p1(1, ynew);
|
||||
p1 = (t->inverse())(p1);
|
||||
|
||||
if(yscal<1)
|
||||
return_t = static_cast<FT>((int)(p1.y()));
|
||||
else{
|
||||
#ifdef CGAL_USE_GMP
|
||||
CGAL_Rational r = simplest_rational_in_interval<CGAL_Rational>(
|
||||
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<FT>(CGAL::to_double(r));
|
||||
#else
|
||||
return_t = static_cast<FT>(ymax-y/yscal);
|
||||
return_t = static_cast<FT>(p1.y());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class FT>
|
||||
void Qt_widget::xy_real(int x, int y,
|
||||
FT& x_result, FT& y_result) const
|
||||
{
|
||||
double temp_x = static_cast<double>(x);
|
||||
double xnew = xmin + temp_x/xscal;
|
||||
double temp_y = static_cast<double>(y);
|
||||
double ynew = ymax - temp_y/yscal;
|
||||
CGAL::Point_2<SCD> p1(xnew, ynew);
|
||||
p1 = (t->inverse())(p1);
|
||||
|
||||
if(xscal<1)
|
||||
x_result = static_cast<FT>((int)(p1.x()));
|
||||
else{
|
||||
#ifdef CGAL_USE_GMP
|
||||
CGAL_Rational r = simplest_rational_in_interval<CGAL_Rational>(
|
||||
p1.x() - (1/xscal)/2,
|
||||
p1.x() + (1/xscal)/2);
|
||||
x_result = static_cast<FT>(CGAL::to_double(r));
|
||||
#else
|
||||
x_result = static_cast<FT>(p1.x());
|
||||
#endif
|
||||
}
|
||||
|
||||
if(yscal<1)
|
||||
y_result = static_cast<FT>((int)(p1.y()));
|
||||
else{
|
||||
#ifdef CGAL_USE_GMP
|
||||
CGAL_Rational r = simplest_rational_in_interval<CGAL_Rational>(
|
||||
p1.y() - (1/yscal)/2,
|
||||
p1.y() + (1/yscal)/2);
|
||||
y_result = static_cast<FT>(CGAL::to_double(r));
|
||||
#else
|
||||
y_result = static_cast<FT>(p1.y());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
#endif // CGAL_QT_WIDGET_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);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 <cstdio>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/pixmaps/hand.xpm>
|
||||
#include <CGAL/IO/pixmaps/holddown.xpm>
|
||||
#include <CGAL/IO/Qt_widget.h>
|
||||
#include <CGAL/IO/Qt_widget_layer.h>
|
||||
#include <qrect.h>
|
||||
#include <qcursor.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> SCD;
|
||||
typedef CGAL::Point_2<SCD> Point;
|
||||
typedef CGAL::Vector_2<SCD> Vector;
|
||||
typedef CGAL::Direction_2<SCD> Direction;
|
||||
typedef CGAL::Aff_transformation_2<SCD> 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
|
||||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
/* XPM */
|
||||
extern const char *rotation_xpm[];
|
||||
extern const char *rotation_small_xpm[];
|
||||
|
||||
|
||||
|
|
@ -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<double>(x);
|
||||
double xnew = xmin + temp_x/xscal;
|
||||
CGAL::Point_2<SCD> p1(xnew, 1);
|
||||
p1 = (t->inverse())(p1);
|
||||
return_t = simplest_rational_in_interval<Gmpq>(
|
||||
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<double>(y);
|
||||
double ynew = ymax - temp_y/yscal;
|
||||
CGAL::Point_2<SCD> p1(1, ynew);
|
||||
p1 = (t->inverse())(p1);
|
||||
return_t = simplest_rational_in_interval<Gmpq>(
|
||||
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<double>(x);
|
||||
double xnew = xmin + temp_x/xscal;
|
||||
CGAL::Point_2<SCD> 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<double>(y);
|
||||
double ynew = ymax - temp_y/yscal;
|
||||
CGAL::Point_2<SCD> 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<int>((x-xmin)*xscal+0.5) );
|
||||
CGAL::Point_2<SCD> p1(x, 1);
|
||||
p1 = (*t)(p1);
|
||||
return( static_cast<int>((p1.x() - xmin)*xscal));
|
||||
}
|
||||
|
||||
int Qt_widget::y_pixel(double y) const
|
||||
{
|
||||
return( - static_cast<int>((y-ymax)*yscal+0.5) );
|
||||
CGAL::Point_2<SCD> p1(1, y);
|
||||
p1 = (*t)(p1);
|
||||
return( static_cast<int>((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<SCD> p1(x, y);
|
||||
p1 = (*t)(p1);
|
||||
x_result = static_cast<int>((p1.x() - xmin)*xscal);
|
||||
y_result = static_cast<int>((ymax - p1.y())*yscal);
|
||||
}
|
||||
|
||||
|
||||
int Qt_widget::x_pixel_dist(double d) const
|
||||
{
|
||||
if (d>0)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include <CGAL/IO/pixmaps/back.xpm>
|
||||
#include <CGAL/IO/pixmaps/forward.xpm>
|
||||
#include <CGAL/IO/pixmaps/mouse_coord.xpm>
|
||||
#include <CGAL/IO/pixmaps/rotation.xpm>
|
||||
|
||||
#include <qbuttongroup.h>
|
||||
#include <qiconset.h>
|
||||
|
|
@ -48,6 +49,7 @@
|
|||
#include <CGAL/IO/Qt_widget_focus.h>
|
||||
#include <CGAL/IO/Qt_widget_zoomrect.h>
|
||||
#include <CGAL/IO/Qt_widget_handtool.h>
|
||||
#include <CGAL/IO/Qt_widget_rotation_layer.h>
|
||||
#include <CGAL/IO/Qt_widget_show_mouse_coordinates.h>
|
||||
|
||||
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<QToolButton*>(button_group->find(i));
|
||||
if( tBt != 0)
|
||||
tBt->setOn(false);
|
||||
|
||||
nolayerBt->setOn(true);
|
||||
id = 0;
|
||||
}
|
||||
else
|
||||
QToolButton* tBt =
|
||||
static_cast<QToolButton*>(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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
"................................",
|
||||
"................................",
|
||||
"................................",
|
||||
"................................",
|
||||
"............ ..........",
|
||||
".......... .........",
|
||||
".... ... ......... .......",
|
||||
".... .. ............. ......",
|
||||
".... ............... .....",
|
||||
".... ................. .....",
|
||||
".... ............... ....",
|
||||
".... ................. ...",
|
||||
".... .................... ...",
|
||||
".... ...................... ...",
|
||||
"........................... ...",
|
||||
"........................... ...",
|
||||
"........................... ...",
|
||||
"........................... ...",
|
||||
"........................... ...",
|
||||
"........................... ...",
|
||||
".......................... ...",
|
||||
".......................... ....",
|
||||
"......................... .....",
|
||||
"........................ .....",
|
||||
"...................... ......",
|
||||
"..................... .......",
|
||||
"........... .........",
|
||||
"........... ...........",
|
||||
"................................",
|
||||
"................................",
|
||||
"................................",
|
||||
"................................"
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue