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 filename = __filename;
00089
00090
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
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
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
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
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
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 }