Due: Wednesday 6 December 2006, 2:00pm
Monday, December 4: It was pointed out today that this assignment does not specify whether or not Polygons should be saved in "world coordinates" or "polygon coordinates." You may assume either.
Monday, December 4: The link to the to optional survey at the end of the assignment was incorrect, and has now been fixed.
Wednesday, November 29: We've figured out how you can do this assignment while working on the lab windows machines. The details appear at the bottom of the "Getting Started" section.
In this assignment, you will finish building a graphical polygon editor. You will begin by understanding the various classes in the skeleton system we provide you, and then you will design and implement two new classes to complete the system. Completing this assignment will require you to become familiar with some concepts in user interface programming, but it will not require you to understand any particular toolkit. You must do this assignment with the same partner you had for HW6.
Either you or your partner should begin this assignment by downloading hw7.tgz, unpacking it with tar -xvzf hw7.tgz, and copying the files to a polyedit working directory. This package contains six files which you will need to do this assignment (Makefile, Main.cpp, Graphics.h, Graphics.cpp, Controller.h, and Controller.cpp). When the files in hw7.tgz are placed in the same directory with the files Point.h, Point.cpp, Polygon.h, and Polygon.cpp from HW6, you should be able to compile and run a skeleton version of the system that opens a black window but does little else. Once you get this working, commit this skeleton version to your subversion repository.
Note the following:
The skeleton program we provide you explains how it should operate. The program takes one or two arguments, an optional input file name followed by a mandatory output file name. When the program starts normally, the following text is printed to the terminal:
--------- polyedit: A polygon editor ---------- Usage: polyedit [InFile] OutFile Polyedit allows you to view and create polygons. If "InFile" is specified, a polygon is read from that file. If the program exits as defined below, the current polygon is written to "OutFile" The following commands are available while Polyedit is running: Mouse Commands Left Button Click: Add a point to the current polygon Right Button Drag: Move the polygon around the screen Keyboard Commands 'c' : Clears the current polygon 'Esc': Exits the program and writes the polygon to OutFile ------------------------------------------------
Your goal is to make polyedit behave as defined above. You will do this by creating two new classes, MyController and MovablePolygon, as described below. You will not be allowed to make edits to the other files, except for minor changes to Main.cpp and the Polygon class, as described below.
Note that the file format is nothing special. It is simply the format input and output by operator<< and operator>> for Polygons which appeared in HW6. If you'd like to test out a working version of this program, you may download the following files to a Linux machine and try them out.
Your next step should be seeking to understand the code we have provided you. You'll discover most of what you need to know by looking at the main function in Main.cpp and the header files for the two new classes Controller and Graphics.
As mentioned above, the ability to drag a polygon around the screen introduces a significant complication to our system. If polygons never moved, then receiving points from AddPointCmd and drawing them with DrawLine would be a simple matter. Because polygons can move, your program must be aware of two different coordinate systems, "world coordinates" and "polygon coordinates."
In order to handle these two different coordinate systems, you must create a new subclass of Polygon called MovablePolygon. This class will separate these two coordinate systems, and your controller will use this class instead of Polygon. You will need to modify Polygon slightly in order to make your subclass, but you are only allowed to declare/define one new method. Also, you are not allowed to change the name, arguments, or return values of any existing Polygon method. Apart from these constraints, you may design and implement MovablePolygon in any way that you wish.
Note: This method of separating out different coordinate systems is a simplified version of the way most graphical user interfaces work.
Take some time to think about how MyController and MovablePolygon should work with each other and work with your partner to design an interface for MovablePolygon. It may be best for each person to implement one class. In that case, it may be possible for each person to work somewhat independently of the other. MyController can use Polygon until MovablePolygon is ready, and everything except DragCmd should work. A unit test for MovablePolygon can suffice until the pieces are put together.
If you don't know where to begin with MovablePolygon, consider keeping a separate origin in the class. The DragCmd can update this origin and other methods can translate between the two coordinate systems.
To give you a sense of how complicated each class needs to be, here's a rundown of the sample solution:
Both team members should consider filling out this optional survey once the rest of the assignment is turned in. The survey gives you an opportunity to express your feelings about how work was shared on HW6 and HW7. It also gives you an opportunity to let us know when you can come to an exam review session.
Your solutions should be
Use the standard turn-in instructions described here. You should turn in all files required to build and run polyedit, plus a readme.txt file if you have anything to report.