From bb26ce924e30e232cd2cd25cd44fb41ff342b736 Mon Sep 17 00:00:00 2001 From: Radu Ursu Date: Thu, 17 Jan 2002 16:50:38 +0000 Subject: [PATCH] renamed --- .../include/CGAL/IO/Qt_widget_get_polygon.h | 128 ++++++++++++++++ .../include/CGAL/IO/Qt_widget_get_segment.h | 116 ++++++++++++++ .../CGAL/IO/Qt_widget_get_simple_polygon.h | 145 ++++++++++++++++++ 3 files changed, 389 insertions(+) create mode 100644 Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_polygon.h create mode 100644 Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_segment.h create mode 100644 Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_simple_polygon.h 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 new file mode 100644 index 00000000000..9653dfacaf3 --- /dev/null +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_polygon.h @@ -0,0 +1,128 @@ +// ============================================================================ +// +// Copyright (c) 1997-2000 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------------- +// +// file : include/CGAL/IO/Qt_Widget_Get_polygon.h +// package : QT_window +// author(s) : Laurent Rineau +// release : +// release_date : +// +// coordinator : Laurent Rineau +// +// ============================================================================ + +#ifndef CGAL_QT_WINDOW_GET_POLYGON_H +#define CGAL_QT_WINDOW_GET_POLYGON_H + +#include +#include +#include + +namespace CGAL { + +template +class Qt_widget_get_polygon : public Qt_widget_tool +{ +public: + typedef typename Polygon::Point_2 Point_2; + typedef typename Polygon::FT FT; + + Qt_widget_get_polygon() + : active(false), lastx(0), lasty(0), num_points(0), poly(), + qpoints(0), qpoints_old(0) {}; + + void mousePressEvent(QMouseEvent *e) + { + if(e->button() == Qt::LeftButton) + { + FT + x=static_cast(widget->x_real(e->x())), + y=static_cast(widget->y_real(e->y())); + poly.push_back(Point_2(x,y)); + qpoints.putPoints(num_points, 1, e->x(), e->y()); + qpoints_old.putPoints(num_points, 1, e->x(), e->y()); + ++num_points; + active=true; + widget->setMouseTracking(TRUE); + return; + }; + if(e->button() == Qt::RightButton) + { + if (active) + { + RasterOp old_rasterop=widget->rasterOp(); + widget->painter().setRasterOp(NotROP); + widget->painter().drawPolyline(qpoints_old); + widget->setRasterOp(old_rasterop); + widget->do_paint(); + FT + x=static_cast(widget->x_real(e->x())), + y=static_cast(widget->y_real(e->y())); + poly.push_back(Point_2(x, y)); + widget->new_object(make_object(poly)); + + // TODO: have we something better to clear a polygon? + while(!poly.is_empty()) + poly.erase(--poly.vertices_end()); + + qpoints.resize(0); + qpoints_old.resize(0); + num_points=0; + active=false; + }; + }; + }; + + void mouseMoveEvent(QMouseEvent *e) + { + if (active) + { + int + x=(e->pos()).x(), + y=(e->pos()).y(); + if ((lastx != x) || (lasty != y)) { + widget->lock(); + RasterOp old_rasterop=widget->rasterOp(); + widget->painter().setRasterOp(NotROP); + qpoints.putPoints(num_points,1,x,y); + widget->painter().drawPolyline(qpoints); + // Erase old polyline + widget->painter().drawPolyline(qpoints_old); + widget->setRasterOp(old_rasterop); + widget->unlock(); + lastx= x; + lasty= y; + qpoints_old.putPoints(num_points,1,x,y); + } + } + }; + void attaching() + { + oldcursor = widget->cursor(); + widget->setCursor(crossCursor); + }; + + void detaching() + { + widget->setCursor(oldcursor); + }; + +protected: + bool active; + int lastx, lasty; + int num_points; + Polygon poly; + QPointArray qpoints; + QPointArray qpoints_old; +}; + +} // namespace CGAL + +#endif // CGAL_QT_WINDOW_GET_POLYGON_H 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 new file mode 100644 index 00000000000..e22e7ddcc60 --- /dev/null +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_segment.h @@ -0,0 +1,116 @@ +// ============================================================================ +// +// Copyright (c) 1997-2000 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------------- +// +// file : include/CGAL/IO/Qt_Window_Get_segment.h +// package : QT_window +// author(s) : Ursu Radu +// release : +// release_date : +// +// coordinator : Laurent Rineau +// +// ============================================================================ + +#ifndef CGAL_QT_WINDOW_GET_SEGMENT_H +#define CGAL_QT_WINDOW_GET_SEGMENT_H + +#include +#include + +#ifndef CGAL_QT_WINDOW_GET_POINT_BUTTON +#define CGAL_QT_WINDOW_GET_POINT_BUTTON Qt::LeftButton +#endif + + +namespace CGAL { + +template +class Qt_widget_get_segment : public Qt_widget_tool +{ +public: + typedef Point_2 Point; + typedef Segment_2 Segment; + typedef typename R::FT FT; + + Qt_widget_get_segment() {}; + +private: + void mousePressEvent(QMouseEvent *e) + { + if(e->button() == CGAL_QT_WINDOW_GET_POINT_BUTTON) + { + FT + x=static_cast(widget->x_real(e->x())), + y=static_cast(widget->y_real(e->y())); + x1 = x; + y1 = y; + x2 = x; + y2 = y; + firstpoint = TRUE; + } + }; + + void mouseMoveEvent(QMouseEvent *e) + { + + if(firstpoint==TRUE) + { + + FT + x=static_cast(widget->x_real(e->x())), + y=static_cast(widget->y_real(e->y())); + RasterOp old = widget->rasterOp(); //save the initial raster mode + + widget->setRasterOp(XorROP); + widget->lock(); + *widget << CGAL::GREEN; + *widget << Segment(Point(x1,y1),Point(x2,y2)); + *widget << Segment(Point(x1,y1),Point(x,y)); + widget->unlock(); + widget->setRasterOp(old); + + //save the last coordinates to redraw the screen + x2 = x; + y2 = y; + } + }; + void mouseReleaseEvent(QMouseEvent *e) + { + if(e->button() == CGAL_QT_WINDOW_GET_POINT_BUTTON) + { + FT + x=static_cast(widget->x_real(e->x())), + y=static_cast(widget->y_real(e->y())); + if(x1!=x || y1!=y) + widget->new_object(make_object(Segment(Point(x1,y1),Point(x,y)))); + firstpoint = FALSE; + } + } + + void attaching() + { + oldcursor = widget->cursor(); + widget->setCursor(crossCursor); + }; + + void detaching() + { + widget->setCursor(oldcursor); + //widget->setMouseTracking(FALSE); + }; + + FT x1, y1; + FT x2, y2; + bool firstpoint; +};//end class + +} // namespace CGAL + +#endif // CGAL_QT_WINDOW_GET_SEGMENT_H diff --git a/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_simple_polygon.h b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_simple_polygon.h new file mode 100644 index 00000000000..fb644b96344 --- /dev/null +++ b/Packages/Qt_widget/include/CGAL/IO/Qt_widget_get_simple_polygon.h @@ -0,0 +1,145 @@ +// ============================================================================ +// +// Copyright (c) 1997-2000 The CGAL Consortium +// +// This software and related documentation is part of an INTERNAL release +// of the Computational Geometry Algorithms Library (CGAL). It is not +// intended for general use. +// +// ---------------------------------------------------------------------------- +// +// file : include/CGAL/IO/Qt_Window_Get_polygon.h +// package : QT_window +// author(s) : Laurent Rineau && Radu Ursu +// release : +// release_date : +// +// coordinator : Laurent Rineau +// +// ============================================================================ + +#ifndef CGAL_QT_WIDGET_GET_SIMPLE_POLYGON_H +#define CGAL_QT_WIDGET_GET_SIMPLE_POLYGON_H + +#include +#include +#include + + +namespace CGAL { + +template +class Qt_widget_get_simple_polygon : public Qt_widget_tool +{ +public: + typedef typename Polygon::Point_2 Point_2; + typedef typename Polygon::FT FT; + + Qt_widget_get_simple_polygon() + : active(false), lastx(0), lasty(0), num_points(0), poly(), + qpoints(0), qpoints_old(0) {}; + + void mousePressEvent(QMouseEvent *e) + { + if(e->button() == Qt::LeftButton) + { + FT + x=static_cast(widget->x_real(e->x())), + y=static_cast(widget->y_real(e->y())); + poly.push_back(Point_2(x,y)); + if (!poly.is_simple()) + poly.erase(--poly.vertices_end()); + else { + qpoints.putPoints(num_points, 1, e->x(), e->y()); + qpoints_old.putPoints(num_points, 1, e->x(), e->y()); + ++num_points; + active=true; + widget->setMouseTracking(TRUE); + } + return; + }; + if(e->button() == Qt::RightButton) + { + if (active) + { + RasterOp old_rasterop=widget->rasterOp(); + widget->painter().setRasterOp(NotROP); + widget->painter().drawPolyline(qpoints_old); + widget->setRasterOp(old_rasterop); + widget->do_paint(); + FT + x=static_cast(widget->x_real(e->x())), + y=static_cast(widget->y_real(e->y())); + + + widget->new_object(make_object(poly)); + + // TODO: have we something better to clear a polygon? + while(!poly.is_empty()) + poly.erase(--poly.vertices_end()); + + qpoints.resize(0); + qpoints_old.resize(0); + num_points=0; + active=false; + }; + }; + }; + + void mouseMoveEvent(QMouseEvent *e) + { + if (active) + { + int + x=(e->pos()).x(), + y=(e->pos()).y(); + if ((lastx != x) || (lasty != y)) { + widget->lock(); + RasterOp old_rasterop=widget->rasterOp(); + widget->painter().setRasterOp(NotROP); + qpoints.putPoints(num_points,1,x,y); + widget->painter().drawPolyline(qpoints); + // Erase old polyline + widget->painter().drawPolyline(qpoints_old); + widget->setRasterOp(old_rasterop); + widget->unlock(); + lastx= x; + lasty= y; + qpoints_old.putPoints(num_points,1,x,y); + } + } + }; + void attaching() + { + oldcursor = widget->cursor(); + widget->setCursor(crossCursor); + }; + + void detaching() + { + //erasing the old polygon if exists one + RasterOp old_rasterop=widget->rasterOp(); + widget->painter().setRasterOp(NotROP); + widget->painter().drawPolyline(qpoints_old); + widget->setRasterOp(old_rasterop); + widget->do_paint(); + poly.erase(poly.vertices_begin(), poly.vertices_end()); + qpoints.resize(0); + qpoints_old.resize(0); + num_points=0; + active=false; + widget->setCursor(oldcursor); + }; + +protected: + bool active; + int lastx, lasty; + int num_points; + Polygon poly; + QPointArray qpoints; + QPointArray qpoints_old; +}; + +} // namespace CGAL + +#endif // CGAL_QT_WINDOW_GET_POLYGON_H