BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/IO/Qt_widget.h
Go to the documentation of this file.
00001 // Copyright (c) 2002-2004  INRIA Sophia-Antipolis (France).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Qt_widget/include/CGAL/IO/Qt_widget.h $
00016 // $Id: Qt_widget.h 36699 2007-02-28 17:43:49Z fcacciola $
00017 // 
00018 //
00019 // Author(s)     : Laurent Rineau
00020 
00021 #ifndef CGAL_QT_WIDGET_H
00022 #define CGAL_QT_WIDGET_H
00023 
00024 #include <CGAL/basic.h>
00025 #include <CGAL/Simple_cartesian.h>
00026 #include <CGAL/intersections.h>
00027 //temporary, should remove next line!!
00028 #include <CGAL/Triangle_2_Iso_rectangle_2_intersection.h>
00029 #include <CGAL/IO/Color.h>
00030 
00031 #include <vector>
00032 #include <list>
00033 #include <map>
00034 #include <cmath>
00035 
00036 #include <qwidget.h>
00037 #include <qpainter.h>
00038 #include <qcolor.h>
00039 #include <qpixmap.h>
00040 #include <qprinter.h>
00041 
00042 #include <CGAL/auto_link/CGALQt.h>
00043 
00044 namespace CGAL {
00045 
00046 class Qt_widget_layer;
00047 enum PointStyle { PIXEL, CROSS, PLUS, CIRCLE, DISC, RECT, BOX };
00048 
00049 class Qt_widget : public QWidget {
00050   Q_OBJECT
00051 public:
00052   // constructor
00053   Qt_widget(QWidget *parent = 0, const char *name = 0);
00054   // destructor
00055   ~Qt_widget() {};
00056 
00057   // initialization of coordinates system
00058   void set_window(const double x_min,
00059                   const double x_max, 
00060                   const double y_min, 
00061                   const double y_max,
00062                   bool const_ranges = false);
00063   void zoom(double ratio);
00064   void zoom(double ratio, double xc, double yc);
00065   void set_x_scale(const double xscale){ xscal = xscale; }
00066   void set_y_scale(const double yscale){ yscal = yscale; }
00067 
00068   void move_center(const double distx, const double disty);
00069   void set_center(const double x, const double y);
00070 
00071   // painting system
00072   inline QPainter& get_painter() { return (*painter); };
00073   inline QPixmap& get_pixmap() { return (*pixmap); };
00074   inline QWMatrix& get_matrix() { return (*matrix); };
00075   void lock() { ++Locked; };
00076   void unlock() { if (Locked>0) --Locked; do_paint(); };
00077   void do_paint() { if (Locked==0) repaint(FALSE); };
00078 
00079   virtual QSize sizeHint() const {return QSize(geometry().width(),
00080                                         geometry().height());} 
00081   
00082   // properties
00083   // ~~~~~~~~~~
00084   // color
00085   QColor color() const;
00086   void setColor(const QColor c);
00087   // backGroundColor
00088   QColor backgroundColor() const;
00089   void setBackgroundColor(const QColor& c);
00090   // fillColor
00091   QColor fillColor() const;
00092   void setFillColor(const QColor c);
00093   // isFilled
00094   bool isFilled() const;
00095   void setFilled(const bool f);
00096   // lineWidth
00097   uint lineWidth() const;
00098   void setLineWidth(const uint i);
00099   // pointSize
00100   uint pointSize() const;
00101   void setPointSize(const uint i);
00102   // pointStyle
00103   typedef CGAL::PointStyle PointStyle;
00104   PointStyle pointStyle() const;
00105   void setPointStyle(const PointStyle s);
00106   // rasterOp
00107   RasterOp rasterOp() {return painter->rasterOp();}
00108   void setRasterOp(const RasterOp r) {painter->setRasterOp(r);}
00109 
00110   // CGAL version of setFooColor
00111   // used by the manipulators system
00112   // DO NOT USE THESE THREE UNDOCUMENTED FUNCTIONS !!
00113   inline void setColor(const Color c)
00114     { setColor(CGAL2Qt_Color(c)); };
00115   inline void setBackgroundColor(const Color c)
00116     { setBackgroundColor(CGAL2Qt_Color(c)); };
00117   inline void setFillColor(const Color c)
00118     { setFillColor(CGAL2Qt_Color(c)); };
00119 
00120   // set pen() color to c, cf. manipulators below for setting
00121   // backgroundColor and fillColor
00122   Qt_widget& operator<<(const Color& c);
00123   // set point style
00124   Qt_widget& operator<<(const PointStyle& ps);
00125   // clear the Widget, fill it with backgroundColor()
00126   void clear();
00127 
00128   // coordinates system
00129   // ~~~~~~~~~~~~~~~~~~
00130   // real world coordinates
00131   double x_real(int x) const;
00132   double y_real(int y) const;
00133   template <class FT>
00134   void x_real(int, FT&) const;
00135   template <class FT>
00136   void y_real(int y, FT&) const;
00137 
00138 
00139   double x_real_dist(double d) const;
00140   double y_real_dist(double d) const;
00141 
00142 
00143   // pixel coordinates
00144   int x_pixel(double x) const;
00145   int y_pixel(double y) const;
00146   int x_pixel_dist(double d) const;
00147   int y_pixel_dist(double d) const;
00148 
00149   inline double x_min() const { return xmin; };
00150   inline double y_min() const { return ymin; };
00151   inline double x_max() const { return xmax; };
00152   inline double y_max() const { return ymax; };
00153 
00154   inline double x_scal() { return xscal; }
00155   inline double y_scal() { return yscal; }
00156 
00157   void new_object(CGAL::Object obj) { emit(new_cgal_object(obj)); };
00158   
00159   //layers
00160   
00161   void attach(Qt_widget_layer *layer);
00162   
00163   
00164   // remove a layer from the list of displayable scenes
00165   void detach(Qt_widget_layer* s);
00166 
00167 signals:
00168   void s_mousePressEvent(QMouseEvent *e);
00169   void s_mouseReleaseEvent(QMouseEvent *e);
00170   void s_mouseMoveEvent(QMouseEvent *e);
00171   void s_paintEvent(QPaintEvent *e);
00172   void s_resizeEvent(QResizeEvent *e);
00173   void s_wheelEvent(QWheelEvent *e);
00174   void s_mouseDoubleClickEvent(QMouseEvent *e);
00175   void s_keyPressEvent(QKeyEvent *e);
00176   void s_keyReleaseEvent(QKeyEvent *e);
00177   void s_enterEvent(QEvent *e);
00178   void s_leaveEvent(QEvent *e);
00179   void s_event(QEvent *e);
00180   
00181   void custom_redraw(); //deprecated:  if user want to draw something
00182                         //after layers replaced by redraw_on_front
00183   void redraw_on_front(); //called by redraw at the end
00184   void redraw_on_back();  //called by redraw at the beginning
00185 
00186 
00187   void new_cgal_object(CGAL::Object);   //this signal is emited every time an
00188                                         //attached tool constructed an object
00189 
00190   void rangesChanged(); 
00191   // triggered when ranges (xmin, xmax, ymin,...) are changed
00192 
00193 public slots:
00194   void print_to_ps();
00195   virtual void redraw();
00196 
00197 // backward-compatibility with CGAL-2.4, back() and forth() are
00198 // deprecated, as well as add_to_history() or clear_history().
00199 signals:
00200   void internal_back();
00201   void internal_forth();
00202   void internal_add_to_history();
00203   void internal_clear_history();
00204 public slots:
00205   bool back() { emit(internal_back()); return true; }
00206   bool forth() { emit(internal_forth()); return true; }
00207 public:
00208   void add_to_history() { emit(internal_add_to_history()); }
00209   void clear_history() { emit(internal_clear_history()); }
00210 
00211 protected:
00212   void paintEvent(QPaintEvent *e);
00213   void resizeEvent(QResizeEvent *e);
00214   void showEvent(QShowEvent *e);
00215   void mousePressEvent(QMouseEvent *e);
00216   void mouseReleaseEvent(QMouseEvent *e);
00217   void mouseMoveEvent(QMouseEvent *e);
00218   void wheelEvent(QWheelEvent *e);
00219   void mouseDoubleClickEvent(QMouseEvent *e);
00220   void keyPressEvent(QKeyEvent *e);
00221   void keyReleaseEvent(QKeyEvent *e);
00222   void enterEvent(QEvent *e);
00223   void leaveEvent(QEvent *e);
00224   bool event(QEvent *e);
00225 
00226 
00227 private:
00228   // private functions
00229   // ~~~~~~~~~~~~~~~~~
00230 
00231   void resize_pixmap();
00232   // resize properly the pixmap size, saving then restoring the
00233   // painter properties
00234 
00235   void    set_scales(); 
00236   // set xscal and yscal. Update ranges if const_ranges is false.
00237 
00238   // color types convertors
00239   static QColor CGAL2Qt_Color(Color c);
00240   static Color Qt2CGAL_color(QColor c);
00241 
00242   void attach_standard(Qt_widget_layer *layer);
00243   bool is_standard_active();
00244   bool does_standard_eat_events();
00245   friend class Qt_widget_standard_toolbar;
00246 
00247 
00248   // private member datas
00249   // ~~~~~~~~~~~~~~~~~~~~
00250   bool    set_scales_to_be_done;
00251   // this flag is set when the widget is not visible and should
00252   // postpone the set_scales() call.
00253 
00254   unsigned int Locked;
00255   // point style and size
00256   uint        _pointSize;
00257   PointStyle  _pointStyle;
00258 
00259   QPixmap     *pixmap;  // the pixmap on which paints the painter
00260   QPainter    *painter; // the painter
00261   QPrinter    *printer; // the printer
00262   QWMatrix    *matrix;  // the world matrix
00263 
00264   QBrush      savedBrush; // saved brush, to be able to restore it on
00265   // setFilled(true)
00266 
00267   double    xmin, xmax, ymin, ymax; // real dimensions
00268   double    xmin_old, xmax_old, ymin_old, ymax_old;
00269             //backup ranges for resize
00270   double    xscal, yscal; // scales int/double
00271   bool      constranges; // tell if the ranges should be const
00272 
00273   //for layers
00274   std::list<Qt_widget_layer*>   qt_layers;
00275   std::list<Qt_widget_layer*> qt_standard_layers;
00276 };//end Qt_widget class
00277 
00278 // manipulators
00279 // ~~~~~~~~~~~~
00280 // single manipulators
00281 inline
00282 Qt_widget& operator<<(Qt_widget& w, Qt_widget& (*m)(Qt_widget&))
00283 {
00284   return m(w);
00285 };
00286 
00287 // w << noFill << ... stop the filling of geometrical object
00288 inline
00289 Qt_widget& noFill(Qt_widget& w)
00290 {
00291   w.setFilled(false);
00292   return w;
00293 }
00294 
00295 // manipulators with one argument
00296 template <class Param>
00297 struct Qt_widgetManip {
00298   Qt_widget& (*f)(Qt_widget&, Param);
00299   Param p;
00300   Qt_widgetManip(Qt_widget& (*ff)(Qt_widget&, Param),
00301                  Param pp) : f(ff), p(pp) {}
00302 };
00303 
00304 // usage: w << manip(Param) f ...
00305 template <class Param>
00306 Qt_widget& operator<<(Qt_widget& w, Qt_widgetManip<Param> m)
00307 {
00308   return m.f(w, m.p);
00309 }
00310 
00311 #define CGAL_QTWIDGET_MANIP(param,function) \
00312 inline \
00313 Qt_widget& __Qt_widgetManip##function##Aux (Qt_widget& w, param p) \
00314 { w.set##function(p); return w; } \
00315 inline \
00316 Qt_widgetManip<param> function(param p) \
00317 { return Qt_widgetManip<param>( __Qt_widgetManip##function##Aux, p); }
00318 
00319 // w << BackgroundColor(c) << ... sets the background color
00320 CGAL_QTWIDGET_MANIP( Color, BackgroundColor )
00321 
00322 // w << FillColor(c) << ... sets the fill color
00323 CGAL_QTWIDGET_MANIP( Color, FillColor )
00324 
00325 // w << LineWidth(i) << ... sets lines width
00326 CGAL_QTWIDGET_MANIP( unsigned int, LineWidth )
00327 
00328 // w << PointSize(i) << ... sets points size
00329 CGAL_QTWIDGET_MANIP( unsigned int, PointSize )
00330 
00331 // color types convertors
00332 // ~~~~~~~~~~~~~~~~~~~~~~
00333 inline
00334 QColor Qt_widget::CGAL2Qt_Color(Color c)
00335 {
00336   return QColor(c.red(), c.green(), c.blue());
00337 }
00338 
00339 inline
00340 Color Qt_widget::Qt2CGAL_color(QColor c)
00341 {
00342   return Color(c.red(),c.green(),c.blue());
00343 }
00344 
00345 // properties
00346 // ~~~~~~~~~~
00347 inline
00348 QColor Qt_widget::color() const
00349 {
00350   return painter->pen().color();
00351 };
00352 
00353 
00354 inline
00355 void Qt_widget::setColor(const QColor c)
00356 {
00357   QPen p=get_painter().pen();
00358   p.setColor(c);
00359   get_painter().setPen(p);
00360 }
00361 
00362 inline
00363 QColor Qt_widget::backgroundColor() const
00364 {
00365   return painter->backgroundColor();
00366 }
00367 
00368 inline
00369 void Qt_widget::setBackgroundColor(const QColor& c)
00370 {
00371   QWidget::setPaletteBackgroundColor(c);
00372   get_painter().setBackgroundColor(c);
00373   clear();
00374 }
00375 
00376 inline
00377 QColor Qt_widget::fillColor() const
00378 {
00379   return painter->brush().color();
00380 }
00381 
00382 inline
00383 void Qt_widget::setFillColor(const QColor c)
00384 {
00385   setFilled(true);
00386   get_painter().setBrush(c);
00387 }
00388 
00389 inline
00390 bool Qt_widget::isFilled() const
00391 {
00392   return( painter->brush().style()==Qt::NoBrush );
00393 }
00394 
00395 inline
00396 void Qt_widget::setFilled(const bool f)
00397 {
00398   if (f)
00399     painter->setBrush(savedBrush);
00400   else
00401     {
00402       savedBrush=painter->brush();
00403       painter->setBrush(QBrush());
00404     };
00405 }
00406 
00407 inline
00408 uint Qt_widget::lineWidth() const
00409 {
00410   return( painter->pen().width());
00411 }
00412 
00413 inline
00414 void Qt_widget::setLineWidth(const unsigned int i)
00415 {
00416   QPen p=get_painter().pen();
00417   p.setWidth(i);
00418   get_painter().setPen(p);
00419 }
00420 
00421 inline
00422 uint Qt_widget::pointSize() const
00423 {
00424   return _pointSize;
00425 }
00426 
00427 inline
00428 void Qt_widget::setPointSize(const unsigned int i)
00429 {
00430   _pointSize=i;
00431 }
00432 
00433 inline
00434 PointStyle Qt_widget::pointStyle() const
00435 {
00436   return _pointStyle;
00437 }
00438 
00439 inline
00440 void Qt_widget::setPointStyle(const PointStyle ps)
00441 {
00442   _pointStyle=ps;
00443 }
00444 
00445 // drawing methods
00446 // ~~~~~~~~~~~~~~~
00447 
00448 template <class R>
00449 Qt_widget& operator<<(Qt_widget& w, const Point_2<R>& p)
00450 {
00451   int x = w.x_pixel(CGAL::to_double(p.x()));
00452   int y = w.y_pixel(CGAL::to_double(p.y()));
00453 
00454   uint size=w.pointSize();
00455   PointStyle ps=w.pointStyle();
00456 
00457   switch (ps)
00458   {
00459     case PIXEL:
00460     {
00461        w.get_painter().drawPoint(x,y);
00462        break;
00463     }
00464     case CROSS:
00465     {
00466        w.get_painter().drawLine(x-size/2, y-size/2, x+size/2, y+size/2);
00467        w.get_painter().drawLine(x-size/2, y+size/2, x+size/2, y-size/2);
00468        break;
00469     }
00470     case PLUS:
00471     {
00472        w.get_painter().drawLine(x, y-size/2, x, y+size/2);
00473        w.get_painter().drawLine(x-size/2, y, x+size/2, y);
00474        break;
00475     }
00476     case CIRCLE:
00477     {
00478        QBrush old_brush=w.get_painter().brush();
00479        w.get_painter().setBrush(QBrush());
00480        w.get_painter().drawEllipse(x-size/2, y-size/2, size, size);
00481        w.get_painter().setBrush(old_brush);
00482        break;
00483     }
00484     case DISC:
00485     {
00486        QBrush old_brush=w.get_painter().brush();
00487        w.get_painter().setBrush(w.get_painter().pen().color());
00488        w.get_painter().drawEllipse(x-size/2, y-size/2, size, size);
00489        w.get_painter().setBrush(old_brush);
00490        break;
00491     }
00492     case RECT:
00493     {
00494       QBrush old_brush=w.get_painter().brush();
00495       w.get_painter().setBrush(QBrush());
00496       w.get_painter().drawRect(x-size/2, y-size/2, size, size);
00497       w.get_painter().setBrush(old_brush);
00498       break;
00499     }
00500     case BOX:
00501     {
00502       QBrush old_brush=w.get_painter().brush();
00503       w.get_painter().setBrush(w.get_painter().pen().color());
00504       w.get_painter().drawRect(x-size/2, y-size/2, size, size);
00505       w.get_painter().setBrush(old_brush);
00506       break;
00507     }
00508   };
00509   w.do_paint();
00510   return w;
00511 }
00512 
00513 #ifdef CGAL_SEGMENT_2_H
00514 template <class R>
00515 Qt_widget& operator<<(Qt_widget& w, const Segment_2<R>& s)
00516 {
00517   typedef Simple_cartesian<double> RT;
00518 
00519   double xr1, yr1, xr2, yr2;
00520   double scs_x, scs_y, sct_x, sct_y;
00521   scs_x = CGAL::to_double(s.source().x());
00522   scs_y = CGAL::to_double(s.source().y());
00523   sct_x = CGAL::to_double(s.target().x());
00524   sct_y = CGAL::to_double(s.target().y());
00525 
00526   xr1 = w.x_real(0); xr2 = w.x_real(w.geometry().width());
00527   //next condition true if is outside on the X axes
00528   if((scs_x < xr1 && sct_x < xr1) ||
00529      (scs_x > xr2 && sct_x > xr2))
00530     return w;
00531   else{
00532     yr2 = w.y_real(0); yr1 = w.y_real(w.geometry().height());
00533     //next condition true if is outside on the Y axes
00534     if((scs_y < yr1 && sct_y < yr1) ||
00535        (scs_y > yr2 && sct_y > yr2))
00536       return w;
00537   }
00538   
00539   //if is here, the segment intersect the screen boundaries or is inside
00540   int x1, y1, x2, y2;
00541   Segment_2<RT>  sr;
00542   sr = Segment_2<RT>(Point_2<RT>(scs_x, scs_y), Point_2<RT>(sct_x, sct_y));
00543   //next condition true if the segment is inside
00544   if(!(scs_x >= xr1 && scs_x <= xr2 &&
00545      sct_x >= xr1 && sct_x <= xr2 && 
00546      scs_y >= yr1 && scs_y <= yr2 &&
00547      sct_y >= yr1 && sct_y <= yr2))
00548     {
00549     Iso_rectangle_2<RT> r = Iso_rectangle_2<RT>(Point_2<RT>(xr1, yr1),
00550                                               Point_2<RT>(xr2, yr2));
00551     CGAL::Object obj = CGAL::intersection(r, sr);  
00552     if (const Point_2<RT> *p = object_cast<Point_2<RT> >(&obj)){
00553       return w << *p;
00554     }
00555     else if (const Segment_2<RT> *s = object_cast<Segment_2<RT> >(&obj)) {
00556       sr = *s;
00557     }
00558     else {
00559       CGAL_assertion(obj.is_empty());
00560       return w;
00561     }
00562   }
00563   x1 = w.x_pixel(CGAL::to_double(sr.source().x()));
00564   x2 = w.x_pixel(CGAL::to_double(sr.target().x()));
00565   y1 = w.y_pixel(CGAL::to_double(sr.source().y()));
00566   y2 = w.y_pixel(CGAL::to_double(sr.target().y()));
00567   w.get_painter().drawLine(x1, y1, x2, y2);
00568   w.do_paint();
00569   return w;
00570 }
00571 #endif // CGAL_SEGMENT_2_H
00572 
00573 #ifdef CGAL_LINE_2_H
00574 
00575 template <class R>
00576 Qt_widget& operator<<(Qt_widget& w, const Line_2<R>& l)
00577 {
00578   typedef Simple_cartesian<double> Rep;
00579   typedef Point_2<Rep> Point;
00580 
00581   const Point_2<R>
00582     p1=l.point(),
00583     p2=p1+l.direction().vector();
00584 
00585   const Point
00586     p1d=Point(CGAL::to_double(p1.x()),CGAL::to_double(p1.y())),
00587     p2d=Point(CGAL::to_double(p2.x()),CGAL::to_double(p2.y()));
00588 
00589   double
00590     x1=w.x_min(),
00591     y1=w.y_min(),
00592     x2=w.x_max(),
00593     y2=w.y_max();
00594 
00595   const double
00596     dx=p1d.x()-p2d.x(),
00597     dy=p1d.y()-p2d.y();
00598 
00599   if (dx==0 && dy==0) return w;
00600 
00601   if (std::fabs(dx)>std::fabs(dy))
00602     {
00603       y1=p1d.y()+(x1-p1d.x())*dy/dx;
00604       y2=p1d.y()+(x2-p1d.x())*dy/dx;
00605     }
00606   else
00607     {
00608       x1=p1d.x()+(y1-p1d.y())*dx/dy;
00609       x2=p1d.x()+(y2-p1d.y())*dx/dy;
00610     }
00611 
00612   w.get_painter().drawLine(w.x_pixel(x1),w.y_pixel(y1),
00613                        w.x_pixel(x2),w.y_pixel(y2));
00614   return w;
00615 }
00616 
00617 #endif // CGAL_LINE_2_H
00618 
00619 #ifdef CGAL_RAY_2_H
00620 template <class R>
00621 Qt_widget& operator<<(Qt_widget& w, const Ray_2<R>& r)
00622 {
00623   typedef Simple_cartesian<double> Rep;
00624   typedef Point_2<Rep> Point;
00625 
00626   const Point_2<R>
00627     p1=r.point(0),
00628     p2=r.point(1);
00629 
00630   const Point
00631     p1d=Point(CGAL::to_double(p1.x()),CGAL::to_double(p1.y())),
00632     p2d=Point(CGAL::to_double(p2.x()),CGAL::to_double(p2.y()));
00633 
00634 
00635   const double
00636     dx=p1d.x()-p2d.x(),
00637     dy=p1d.y()-p2d.y();
00638 
00639   if (dx==0 && dy==0) return w;
00640 
00641   double x,y;
00642 
00643   if (std::fabs(dx)>std::fabs(dy))
00644     {
00645       if (p1d.x()<p2d.x())
00646         x = w.x_max();
00647       else
00648         x = w.x_min();
00649       y=p1d.y()+(x-p1d.x())*dy/dx;
00650     }
00651   else
00652     {
00653       if (p1d.y()<p2d.y())
00654         y = w.y_max();
00655       else
00656         y = w.y_min();
00657       x=p1d.x()+(y-p1d.y())*dx/dy;
00658     }
00659   w.get_painter().drawLine(w.x_pixel(p1d.x()),w.y_pixel(p1d.y()),
00660                        w.x_pixel(x),w.y_pixel(y));
00661   return w;
00662 
00663 }
00664 #endif //CGAL_RAY_2_H
00665 
00666 #ifdef CGAL_TRIANGLE_2_H
00667 template< class R >
00668 Qt_widget&
00669 operator<<(Qt_widget& w, const Triangle_2<R>& t)
00670 {
00671   CGAL::Iso_rectangle_2<R> r( Point_2<R>(w.x_real(0), w.y_real(0)), 
00672                               Point_2<R>(w.x_real(w.geometry().width()), 
00673                               w.y_real(w.geometry().height())));
00674   CGAL::Object obj = CGAL::intersection(t, r);
00675   Point_2<R> pi;
00676   Segment_2<R> si;
00677   Triangle_2<R> ti;
00678   typedef Point_2<R> Point;
00679   std::vector<Point> vi;
00680   if(CGAL::assign(pi, obj))
00681     w << pi;
00682   if(CGAL::assign(si, obj))
00683     w << si;
00684   if(CGAL::assign(ti, obj))
00685   {
00686     QPointArray array(3);
00687     array[0] = QPoint(w.x_pixel(CGAL::to_double(t.vertex(0).x())), 
00688                                 w.y_pixel(CGAL::to_double(t.vertex(0).y())));
00689     array[1] = QPoint(w.x_pixel(CGAL::to_double(t.vertex(1).x())), 
00690                                 w.y_pixel(CGAL::to_double(t.vertex(1).y())));
00691     array[2] = QPoint(w.x_pixel(CGAL::to_double(t.vertex(2).x())), 
00692                                 w.y_pixel(CGAL::to_double(t.vertex(2).y())));
00693     w.get_painter().drawPolygon(array);
00694   }   
00695   if(CGAL::assign(vi, obj)){
00696     QPointArray array(int(vi.size()));
00697     typename std::vector<Point>::const_iterator it = vi.begin();
00698     int pos = 0;
00699     while(it != vi.end()){
00700       array[pos] = QPoint(w.x_pixel(CGAL::to_double((*it).x())), 
00701                           w.y_pixel(CGAL::to_double((*it).y())));
00702       pos++;
00703       it++;
00704     }  
00705   w.get_painter().drawPolygon(array);
00706   }
00707   w.do_paint();
00708 
00709   return w;}
00710 #endif
00711 
00712 #ifdef CGAL_CIRCLE_2_H
00713 template < class R>
00714 Qt_widget& operator<<(Qt_widget& w, const Circle_2<R>& c)
00715 {
00716   int 
00717     cx=w.x_pixel(CGAL::to_double(c.center().x())),
00718     cy=w.y_pixel(CGAL::to_double(c.center().y())),
00719     rx=w.x_pixel_dist((std::sqrt(CGAL::to_double(c.squared_radius())))),
00720     ry=w.y_pixel_dist((std::sqrt(CGAL::to_double(c.squared_radius()))));
00721 
00722   w.get_painter().drawEllipse(cx-rx,cy-ry,2*rx,2*ry);
00723   w.do_paint();
00724   return w;
00725 }
00726 #endif // CGAL_CIRCLE_2_H
00727 
00728 #ifdef CGAL_ISO_RECTANGLE_2_H
00729 template< class R >
00730 Qt_widget&
00731 operator<<(Qt_widget& w, const Iso_rectangle_2<R>& r)
00732 {
00733   int xmin = w.x_pixel(CGAL::to_double(r.xmin()));
00734   int ymin = w.y_pixel(CGAL::to_double(r.ymin()));
00735   int xmax = w.x_pixel(CGAL::to_double(r.xmax()));
00736   int ymax = w.y_pixel(CGAL::to_double(r.ymax()));
00737   w.get_painter().drawRect(xmin,ymin,xmax-xmin,ymax-ymin);
00738   w.do_paint();
00739   return w;
00740 }
00741 #endif // CGAL_ISO_RECTANGLE_2_H
00742 
00743 #ifdef CGAL_BBOX_2_H
00744 Qt_widget& operator<<(Qt_widget& w, const Bbox_2& r);
00745 // see Qt_widget for the implementation of this non-template function
00746 #endif // CGAL_BBOX_2_H
00747 
00748 // templated x_real and y_real
00749 
00750 template <class FT>
00751 void Qt_widget::x_real(int x, FT& return_t) const
00752 {
00753   if(xscal<1)
00754     return_t = static_cast<FT>(xmin+(int)(x/xscal));
00755   else{
00756     return_t = static_cast<FT>(xmin+x/xscal);
00757   }
00758 }
00759 
00760 template <class FT>
00761 void Qt_widget::y_real(int y, FT& return_t) const
00762 {
00763     if(yscal<1)
00764       return_t = static_cast<FT>(ymax-(int)(y/yscal));
00765     else{
00766       return_t = static_cast<FT>(ymax-y/yscal);
00767   }  
00768 }
00769 
00770 } // namespace CGAL
00771 
00772 #endif // CGAL_QT_WIDGET_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines