display.cpp

00001 /* 
00002 * <display.cpp>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Sebastien Cahon, Alexandru-Adrian Tantar
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 
00037 #include <iostream>
00038 #include <fstream>
00039 
00040 #include <X11/Xlib.h>
00041 
00042 #include "display.h"
00043 #include "node.h"
00044 #include "opt_route.h"
00045 
00046 #define BORDER 20
00047 #define RATIO 0.5
00048 
00049 #define screen_width 1024
00050 #define screen_height 768
00051 
00052 static const char * filename;
00053 
00054 /* Computed coordinates */
00055 static unsigned * X_new_coord, * Y_new_coord ;
00056 
00057 /* this variable will contain the handle to the returned graphics context. */
00058 static GC gc;
00059   
00060 /* this variable will contain the pointer to the Display structure */
00061 static Display* disp;
00062 
00063 /* this variable will store the ID of the newly created window. */
00064 static Window win;
00065 
00066 static int screen;
00067 
00068 /* Create a new backing pixmap of the appropriate size */
00069 
00070   /* Best tour */
00071   /*
00072   gdk_gc_set_line_attributes (gc, 2,  GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ;
00073 
00074   gdk_gc_set_foreground  (gc, & color_green) ;      
00075 
00076   for (int i = 0 ; i < (int) numNodes ; i ++) {
00077 
00078     gdk_draw_line (pixmap, gc,
00079                    X_new_coord [opt_route [i]],
00080                    Y_new_coord [opt_route [i]],
00081                    X_new_coord [opt_route [(i + 1) % numNodes]],
00082                    Y_new_coord [opt_route [(i + 1) % numNodes]]);
00083     
00084                    }*/
00085 
00086 void openMainWindow (const char * __filename) {
00087 
00088   filename = __filename;
00089 
00090   /* Map */
00091   int map_width = (int) (X_max - X_min);
00092   int map_height = (int) (Y_max - Y_min);
00093   int map_side = std :: max (map_width, map_height);
00094   
00095   /* Calculate the window's width and height. */
00096   int win_width = (int) (screen_width * RATIO * map_width / map_side);
00097   int win_height = (int) (screen_height * RATIO * map_height / map_side);
00098 
00099   /* Computing the coordinates */
00100   X_new_coord = new unsigned [numNodes];
00101   Y_new_coord = new unsigned [numNodes];
00102 
00103   for (unsigned i = 0; i < numNodes; i ++) {
00104     X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER);
00105     Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER);
00106   }
00107   
00108   /* Initialisation */
00109   XGCValues val ;
00110   
00111   disp = XOpenDisplay (NULL) ;
00112   screen = DefaultScreen (disp) ;
00113   win = XCreateSimpleWindow (disp, RootWindow (disp, screen), 0, 0, win_width + 2 * BORDER, win_height + 2 * BORDER, 2, BlackPixel (disp, screen), WhitePixel (disp, screen)) ;
00114   val.foreground = BlackPixel(disp, screen) ;
00115   val.background = WhitePixel(disp, screen) ;
00116   gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ; 
00117 
00118   XMapWindow (disp, win) ;
00119   XFlush (disp) ;
00120 
00121   while (true) {
00122     XClearWindow (disp, win) ;
00123 
00124     /* Vertices as circles */
00125     for (unsigned i = 1 ; i < numNodes ; i ++)
00126       XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ;
00127     
00128     /* New tour */
00129     std :: ifstream f (filename);
00130     if (f) {
00131       Route route;
00132       f >> route;
00133       f.close ();
00134       
00135       for (int i = 0; i < (int) numNodes; i ++) 
00136         XDrawLine (disp, win, gc,     
00137                    X_new_coord [route [i]],
00138                  Y_new_coord [route [i]],
00139                    X_new_coord [route [(i + 1) % numNodes]],
00140                    Y_new_coord [route [(i + 1) % numNodes]]);  
00141     }
00142     XFlush (disp) ;    
00143     sleep (1) ;
00144   }
00145 }

Generated on Mon Oct 8 11:16:45 2007 for ParadisEO-PEOMovingObjects by  doxygen 1.4.7