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