00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <iostream>
00025 #include <fstream>
00026
00027 #include <X11/Xlib.h>
00028
00029 #include "display.h"
00030 #include "node.h"
00031 #include "opt_route.h"
00032
00033 #define BORDER 20
00034 #define RATIO 0.5
00035
00036 #define screen_width 1024
00037 #define screen_height 768
00038
00039 static const char * filename;
00040
00041
00042 static unsigned * X_new_coord, * Y_new_coord ;
00043
00044
00045 static GC gc;
00046
00047
00048 static Display* disp;
00049
00050
00051 static Window win;
00052
00053 static int screen;
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 void openMainWindow (const char * __filename) {
00074
00075 filename = __filename;
00076
00077
00078 int map_width = (int) (X_max - X_min);
00079 int map_height = (int) (Y_max - Y_min);
00080 int map_side = std :: max (map_width, map_height);
00081
00082
00083 int win_width = (int) (screen_width * RATIO * map_width / map_side);
00084 int win_height = (int) (screen_height * RATIO * map_height / map_side);
00085
00086
00087 X_new_coord = new unsigned [numNodes];
00088 Y_new_coord = new unsigned [numNodes];
00089
00090 for (unsigned i = 0; i < numNodes; i ++) {
00091 X_new_coord [i] = (unsigned) (win_width * (1.0 - (X_coord [i] - X_min) / map_width) + BORDER);
00092 Y_new_coord [i] = (unsigned) (win_height * (1.0 - (Y_coord [i] - Y_min) / map_height) + BORDER);
00093 }
00094
00095
00096 XGCValues val ;
00097
00098 disp = XOpenDisplay (NULL) ;
00099 screen = DefaultScreen (disp) ;
00100 win = XCreateSimpleWindow (disp, RootWindow (disp, screen), 0, 0, win_width + 2 * BORDER, win_height + 2 * BORDER, 2, BlackPixel (disp, screen), WhitePixel (disp, screen)) ;
00101 val.foreground = BlackPixel(disp, screen) ;
00102 val.background = WhitePixel(disp, screen) ;
00103 gc = XCreateGC (disp, win, GCForeground | GCBackground, & val) ;
00104
00105 XMapWindow (disp, win) ;
00106 XFlush (disp) ;
00107
00108 while (true) {
00109 XClearWindow (disp, win) ;
00110
00111
00112 for (unsigned i = 1 ; i < numNodes ; i ++)
00113 XDrawArc (disp, win, gc, X_new_coord [i] - 1, Y_new_coord [i] - 1, 3, 3, 0, 364 * 64) ;
00114
00115
00116 std :: ifstream f (filename);
00117 if (f) {
00118 Route route;
00119 f >> route;
00120 f.close ();
00121
00122 for (int i = 0; i < (int) numNodes; i ++)
00123 XDrawLine (disp, win, gc,
00124 X_new_coord [route [i]],
00125 Y_new_coord [route [i]],
00126 X_new_coord [route [(i + 1) % numNodes]],
00127 Y_new_coord [route [(i + 1) % numNodes]]);
00128 }
00129 XFlush (disp) ;
00130 sleep (1) ;
00131 }
00132 }