3.1. Module: GlMapWindow
-Class Hierarchy
Fl_Gl_Window | +----GlMapWindow-Authorship
-Description
At a high level, this class is a window that displays a map given the filenames of input data. It is a subclass of Fltk class Fl_Gl_Window, which is a widget class that sets up a drawing area for OpenGL calls. The virtual method draw() must be implemented, in which OpenGL commands can be issused to display graphics. The Fltk Window method show() must be called by the user to display the GlMapWindow in the Fltk Window.-Implementation Details
Objects of STL class Vector are used to keep track of active windows and stored tiles. The data member "windows" is a vector of pointers to terrain_map_viewer objects. Each time a box is drawn inside the display area by the user, a pointer to a new terrain_map_viewer object is created and added to "windows". When the parent thumbnail_map_viewer is closed, kill_all_windows() is called and it closes all terrain maps in the "windows" vector by creating an iterator for "windows" and calling the hide() method on each terrain_map_viewer, which closes the Fltk window.-MethodsSince many or none of the tiles that make up a map sheet can be displayed at one time, a vector "tiles" is used to keep track of each DataAbstraction object that represents one of the mapsheet tiles. The data member "tiles" is a vector of DataAbstraction pointers, and mapsheet tiles can be added to it via the addTile() method. When draw() is called, an iterator for the vector is created and iterated through, extracting the data from each DataAbstraction object needed to draw the triangles for that mapsheet tile.
There are 4 double variables used to set the coordinate system of the display, minX, minY, maxX, and maxY. They are each initially set to 1.0. Whenever a tile is added, the maximum and minimum values for X and Y are obtained and compared to the current values for this window, updating if necessary.
GlMapWindow(int x, int y, int w, int h, int isThumbnail, char *label)
Description: This constructor creates a GlMapWindow with no added tiles.
Inputs: x and y are the coordinates of the upper left corner of the new window. w and h are the width and height of the window from x and y. isThumbnail indicates whether the map is the thumbnail for event-handling purposes. label is an optional label string that will be shown on the title bar.
Outputs: A new blank GlMapWindow will be created.
Assumptions: Data to be drawn will be added later.
Exceptions: If no tiles are added, then the display will be a black screen.
Known Bugs: None
draw()
Description: draw() is a virtual method defined in Fl_Gl_Window. OpenGL commands are issued in this method to draw the triangles that make up a terrain map. The method sets the coordinate system of the display area and then iterates through the vector of tiles, drawing each one.
Inputs: None
Outputs: Triangles based on the data from the input files are drawn to the GL display window.
Assumptions: If no input file has been displayed, one will get at least black window.
Exceptions: None.
Known Bugs:
handle(int event)
Description: handle is a method handler for Fltk events. It is called whenever a mouse or keyboard event occurs. It's inclusion is important so that the display can be redrawn when the window is moved.
Inputs: int event - The Fltk constant representing a specific event type (ie FL_PUSH See Fltk manual for a list of all events.)
- For ThumbNail Maps:
When a box is drawn, the coordinates are taken and a new display is created:
The map is redrawn for any other event.- For Terrain Maps:
The map is redrawn for any event.Outputs: The Gl Window's state is updated depending on the event that occurred.
Assumptions: If the event passed in is not recognized, then the GL Display is simply redrawn.
Exceptions:
Known Bugs: None
addTile( DataAbstraction *t )
Description: A pointer to a DataAbstraction object containing the data for one mapsheet tile to the vector of tiles to be displayed in this GlMapWindow. Looks at the maximum values for X,Y, and Z in order to extend the coordinate system if necessary.
Inputs: DataAbstraction *t - pointer to an object containing additional data to be drawn.
Outputs: The pointer to the new object is added to the vector "tiles". The values of minX, minY, minZ, maxX, maxY, and maxZ are updated if necessary.
Assumptions:
Exceptions: Null pointers will not be added.
Known Bugs: None
kill_all_windows()
Description: Iterates through the vector "windows", calling the hide() method from Fl_Window on each terrain_map_viewer.
Inputs: None.
Outputs: All terrain_map_viewer objects opened from this GlMapWindow are closed.
Assumptions:
Exceptions: Null pointers will not be closed.
Known Bugs: None
makeDisplay()
Description: Creates a new terrain_map_viewer after a region has been selected. Uses values of startx, starty, endx, and endy to compute the coordinate system for the new terrain_map_viewer.
Inputs: None.
Outputs: A new terrain_map_viewer is created and added to the vector of terrain maps associated with this GlMapWindow.
Assumptions:
Exceptions:
Known Bugs: None
draw_overlay()
Description: Overiddne virtual method in Fl_Gl_Window which is used to draw a box around the user-selected region of the thumbnail map.
Inputs: None.
Outputs: Based on the values of startx, starty, endx, and endy, an overlay rectangle is drawn to the window overlay.
Assumptions: The values of startx, starty, endx, and endy have been set to correct values. Caller knows whether or not the map to be drawn to is a thumbnail or a terrain map
Exceptions:
Known Bugs: None