00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00055 static unsigned * X_new_coord, * Y_new_coord ;
00056
00057
00058 static GC gc;
00059
00060
00061 static Display* disp;
00062
00063
00064 static Window win;
00065
00066 static int screen;
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 void openMainWindow (const char * __filename)
00087 {
00088
00089 filename = __filename;
00090
00091
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
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
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
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
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
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 }