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 
00089   filename = __filename;
00090 
00091   /* Map */
00092   int map_width = (int) (X_max - X_min);
00093   int map_height = (int) (Y_max - Y_min);
00094   int map_side = std :: max (map_width, map_height);
00095 
00096   /* Calculate the window's width and height. */
00097   int win_width = (int) (screen_width * RATIO * map_width / map_side);
00098   int win_height = (int) (screen_height * RATIO * map_height / map_side);
00099 
00100   /* Computing the coordinates */
00101   X_new_coord = new unsigned [numNodes];
00102   Y_new_coord = new unsigned [numNodes];
00103 
00104   for (unsigned i = 0; i < numNodes; i ++)
00105     {
00106       X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER);
00107       Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER);
00108     }
00109 
00110   /* Initialisation */
00111   XGCValues val ;
00112 
00113   disp = XOpenDisplay (NULL) ;
00114   screen = DefaultScreen (disp) ;
00115   win = XCreateSimpleWindow (disp, RootWindow (disp, screen), 0, 0, win_width + 2 * BORDER, win_height + 2 * BORDER, 2, BlackPixel (disp, screen), WhitePixel (disp, screen)) ;
00116   val.foreground = BlackPixel(disp, screen) ;
00117   val.background = WhitePixel(disp, screen) ;
00118   gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ;
00119 
00120   XMapWindow (disp, win) ;
00121   XFlush (disp) ;
00122 
00123   while (true)
00124     {
00125       XClearWindow (disp, win) ;
00126 
00127       /* Vertices as circles */
00128       for (unsigned i = 1 ; i < numNodes ; i ++)
00129         XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ;
00130 
00131       /* New tour */
00132       std :: ifstream f (filename);
00133       if (f)
00134         {
00135           Route route;
00136           f >> route;
00137           f.close ();
00138 
00139           for (int i = 0; i < (int) numNodes; i ++)
00140             XDrawLine (disp, win, gc,
00141                        X_new_coord [route [i]],
00142                        Y_new_coord [route [i]],
00143                        X_new_coord [route [(i + 1) % numNodes]],
00144                        Y_new_coord [route [(i + 1) % numNodes]]);
00145         }
00146       XFlush (disp) ;
00147       sleep (1) ;
00148     }
00149 }

Generated on Thu Mar 13 15:55:03 2008 for ParadisEO-PEO-ParallelanddistributedEvolvingObjects by  doxygen 1.4.7