BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/IO/Qt_widget_rotation_layer.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_rotation_layer.h $
00016 // $Id: Qt_widget_rotation_layer.h 39778 2007-08-08 15:59:25Z spion $
00017 // 
00018 //
00019 // Author(s)     : Radu Ursu
00020 
00021 #ifndef CGAL_QT_WIDGET_ROTATION_LAYER_H
00022 #define CGAL_QT_WIDGET_ROTATION_LAYER_H
00023 
00024 #include <cstdio>
00025 #include <CGAL/Simple_cartesian.h>
00026 #include <CGAL/IO/pixmaps/hand.xpm>
00027 #include <CGAL/IO/pixmaps/holddown.xpm>
00028 #include <CGAL/IO/Qt_widget.h>
00029 #include <CGAL/IO/Qt_widget_layer.h>
00030 #include <qrect.h>
00031 #include <qcursor.h>
00032 
00033 typedef CGAL::Simple_cartesian<double>    SCD;
00034 typedef CGAL::Point_2<SCD>                Point;
00035 typedef CGAL::Vector_2<SCD>               Vector;
00036 typedef CGAL::Direction_2<SCD>            Direction;
00037 typedef CGAL::Aff_transformation_2<SCD>   Transformation;
00038 
00039 namespace CGAL {
00040 
00041 class Qt_widget_rotation_layer : public Qt_widget_layer
00042 {
00043 public:
00044   Qt_widget_rotation_layer(QObject* parent = 0, const char* name = 0)
00045     : Qt_widget_layer(parent, name), wasrepainted(true), on_first(false){};
00046 
00047 private:
00048   QCursor oldcursor;
00049 
00050   void draw(){
00051     wasrepainted = true;
00052   };
00053 /*
00054   void timerEvent( QTimerEvent *)
00055   {
00056     if(on_first)
00057       widget->setCursor(QCursor( 
00058               QPixmap( (const char**)holddown_xpm)));
00059     else
00060       widget->setCursor(QCursor( 
00061               QPixmap( (const char**)hand_xpm)));
00062   }
00063 */
00064   bool is_pure(Qt::ButtonState s){
00065     if((s & Qt::ControlButton) ||
00066        (s & Qt::ShiftButton) ||
00067        (s & Qt::AltButton))
00068       return 0;
00069     else
00070       return 1;
00071   }
00072 
00073   void mousePressEvent(QMouseEvent *e)
00074   {
00075     if(e->button() == Qt::LeftButton 
00076        && is_pure(e->state()))
00077     {
00078       widget->setCursor(QCursor( QPixmap( (const char**)holddown_xpm)));
00079       if (!on_first){
00080               first_x = e->x();
00081               first_y = e->y();
00082               on_first = true;
00083       }
00084       
00085       Point end_point[4] = {Point(11, 25), Point(11, 25), 
00086         Point(11, 25), Point(11, 25)};
00087       for(int i=0; i<4; i++)
00088         end_point[i] = (*t)(end_point[i]);
00089       //Point_2 first_line_end1(11, 25), first_line_end2(11, 0);
00090       //Point_2 second_line_end1(25, 0), second_line_end2(25, 13);
00091       //first_line_end1 = (*t)(first_arrow_end);
00092       //second_arrow_end = (*t)(second_arrow_end);
00093       
00094       //save the initial raster mode
00095       RasterOp old = widget->rasterOp();        
00096       widget->setRasterOp(XorROP);
00097       widget->lock();
00098       *widget << CGAL::WHITE;
00099       widget->get_painter().drawLine(11, 0, 11, 25);
00100       widget->get_painter().drawLine(0, 13, 25, 13);
00101       widget->get_painter().drawLine(11, 0, 9, 5);
00102       widget->get_painter().drawLine(11, 0, 13, 5);
00103       widget->get_painter().drawLine(25, 13, 20, 11);
00104       widget->get_painter().drawLine(25, 13, 20, 15);
00105       *widget << CGAL::RED;
00106 
00107       widget->unlock();
00108       widget->setRasterOp(old);
00109 
00110     }
00111   };
00112 
00113   void mouseReleaseEvent(QMouseEvent *e)
00114   {
00115     if(e->button() == Qt::LeftButton
00116        && is_pure(e->state()))
00117     {
00118       /*
00119       double x, y, xfirst2, yfirst2;
00120       widget->x_real(e->x(), x);
00121       widget->y_real(e->y(), y);
00122       widget->x_real(first_x, xfirst2);
00123       widget->y_real(first_y, yfirst2);
00124                         
00125       double    xmin, xmax, ymin, ymax, distx, disty;
00126       if(x < xfirst2) {xmin = x; xmax = xfirst2;}
00127       else {xmin = xfirst2; xmax = x;};
00128       if(y < yfirst2) {ymin = y; ymax = yfirst2;}
00129       else {ymin = yfirst2; ymax = y;};
00130       distx = xfirst2 - x;
00131       disty = yfirst2 - y;
00132       widget->move_center(distx, disty);
00133       
00134       */
00135       /*
00136       //(*t) = tprim * (*t);
00137       on_first = false;
00138 
00139 
00140       */
00141       double xc = widget->x_min() + (widget->x_max() - widget->x_min())/2;
00142       double yc = widget->y_min() + (widget->y_max() - widget->y_min())/2;
00143       Transformation tprim(CGAL::ROTATION, Direction(xc+0.0001, yc+0.0001), 1, 100);
00144       //Transformation tprim(CGAL::TRANSLATION, Vector(-0.5, 0));
00145       //Transformation tprim(CGAL::SCALING, 1.2);
00146       (*t) = (*t) * tprim;
00147       on_first = false;
00148       widget->setCursor(QCursor( QPixmap( (const char**)hand_xpm)));
00149       widget->redraw();
00150     }
00151   }
00152   /*
00153   void mouseMoveEvent(QMouseEvent *e)
00154   {
00155     char tempc1[130], tempc2[40];
00156     double xcoord, ycoord;
00157     if(on_first)
00158     {
00159       int x = e->x();
00160       int y = e->y();
00161       //save the initial raster mode
00162       RasterOp old = widget->rasterOp();        
00163       widget->setRasterOp(XorROP);
00164       widget->lock();
00165         *widget << CGAL::GRAY;
00166       if(!wasrepainted) {
00167         widget->x_real(x2 - first_x, xcoord);
00168         widget->x_real(y2 - first_y, ycoord);
00169         std::sprintf(tempc1, " dx=%20.6f", xcoord);
00170         std::sprintf(tempc2, ", dy=%20.6f", ycoord);
00171         strcat(tempc1, tempc2);
00172         widget->get_painter().drawLine(first_x, first_y, x2, y2);
00173         *widget << CGAL::GREEN;
00174         widget->get_painter().drawText(x2, y2, tempc1, 49);
00175         *widget << CGAL::GRAY;
00176       }
00177       widget->x_real(x - first_x, xcoord);
00178       widget->x_real(y - first_y, ycoord);
00179       std::sprintf(tempc1, " dx=%20.6f", xcoord);
00180       std::sprintf(tempc2, ", dy=%20.6f", ycoord);
00181       strcat(tempc1, tempc2);
00182       widget->get_painter().drawLine(first_x, first_y, x, y);
00183       *widget << CGAL::GREEN;
00184       widget->get_painter().drawText(x, y, tempc1, 49);
00185       widget->unlock();
00186       widget->setRasterOp(old);
00187 
00188       //save the last coordinates to redraw the screen
00189       x2 = x;
00190       y2 = y;
00191       wasrepainted = false;
00192     }
00193   };
00194 */
00195   void activating()
00196   {
00197     t = widget->get_transformation();
00198     oldcursor = widget->cursor();
00199     widget->setCursor(QCursor( QPixmap( (const char**)hand_xpm)));
00200     wasrepainted = true;
00201 //        startTimer( 100 );
00202   };
00203 
00204   void deactivating()
00205   {
00206     widget->setCursor(oldcursor);
00207 //    killTimers();
00208   };
00209 
00210   int             first_x, first_y;
00211   int             x2, y2;
00212   bool            wasrepainted;
00213   bool            on_first;
00214   Transformation  *t;
00215 };//end class 
00216 
00217 } // namespace CGAL
00218 
00219 #endif // CGAL_QT_WIDGET_ROTATION_LAYER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines