References:
/usr/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/doc/X_srgp.txt /usr/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/include/srgp.h /usr/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/include/srgp_sphigs.h /usr/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/include/srgppublic.h Program examples in Chapter 2The assignment:
Part 1.
One main modification to Lab 2b will be to add a (global?) data
structure to hold all the information about what is drawn in the drawing area.
This could be an array of records, with each record containing the type of the
object (an integer code?), the color, the number of vertices,
and a vertex list (an array in SRGP). It may be useful to keep track of
the number of objects drawn in a (global?) variable. (A linked list of records
might be more space-efficient, as would linked lists of vertices.)
So whenever you draw an new object you also add its data to array of objects
(i.e. add code to do this in DoPoints(), DoPolyline(), etc.).
To "save your picture", simply write the information in the data
structure to a file in some convenient format (there will be a similar
reading procedure to read in a saved picture at initialization).
Part 2.
To "undo", simply redraw the last object in background (white?),
remove it from the data structure, then redraw everything else (in its
own color) to fix up "holes" caused by erasing overlapping objects.
Part 3.
To "clear", re-initialize the data structure after
drawing a white rectangle over the drawing area.
Part 4.
To delete an object, the user will select the "Delete" command,
then click
the mouse near (e.g. within 3 pixels) a vertex of the object (vertices of an
ellipse are vertices of its bounding rectangle), or click within an object's
extent rectangle
(which must be calculated for polypoints, polylines, and polygons;
a rectangle is its own extent, and the bounding rectangle of an ellipse is
its extent). (It would be useful to the
user to see the target vertices drawn as small red squares in XOR mode;
once a vertex is picked, they can be re-drawn in XOR mode to erase them.)
Once a vertex is picked by clicking on it with the mouse, the program will
then perform pick correlation, traversing the data structure and stopping at
the first object with a vertex close to the mouse position -- this is the
object to be erased (as in "undo"). It will be useful in Lab 2d to have a
CorrelateDrawingArea()
function that returns the index of the picked object
in the array of objects. With that index, you can re-draw that object in
background, then move the objects with higher index down one slot in the
array, and re-draw the entire array.
Hints:
A (Re-) DrawStruct procedure that draws all objects in the data structure may
be useful. It is probably easiest to clear the drawing window, then redraw
everything in the data structure of objects. For this purpose, it may be useful
to have a procedure
DrawObject(object obj, (DRAW/ERASE) mode )
that will
set the color appropriately depending on the mode, using a switch statement to
draw an object of appropriate type (as in the main program of Lab 2b), and
restore the original foreground color. Redraw could be automatic after undo
or erase, or it could be a user option.
There are demo programs in the lab2c directory of the class account, lab2c.sample account, lab2c.sample2 (that use "pick targets" and extents respectively for picking; they are my versions of the program) and some sample data files for them (data1, data2, data3), and Demo_Paint (a fairly complete student program with one sample data file dpdata1) -- see the README file for information about using those programs to save data files.
Additional Features
(1 pt each, except as noted):
1) Use linked lists for the data structure and for lists of vertices.
2) Allow the user to remove a single vertex of a polypoint,
polyline or polygon;
adding a vertex is more difficult and worth 2 points.
3) Allow the user to move a single vertex of a polypoint,
polyline or polygon.
4) Show the vertex moving in 3) by rubber-banding -- i.e.
show the polyline or polygon being deformed.
5) Allow the user to click anywhere on an object to pick it,
not just at vertex.
6) Allow the user to save a picture to a data file and retrieve
pictures from data files at any time
(the user should be able to choose which file) as in the
Demo_Paint program.
7) Implement a "bring-to-front" option: once the user has picked
an object,
that object comes to the front of any other objects that may have covered
it. Similarly do a "put-to-back" option.
8) Implement a "change-color" option (select an object,
then change its color).
9) Make Delete efficient: only redraw (on an offscreen canvas
those objects
whose extent intersects the extent of the deleted object, then copyPixel
that canvas to the deleted object's extent).
10) Implement the undo as an "undo-operation" feature that is an
undo-redo:
doing undo twice restores the original picture. Undo-ing an erase should
also restore the original picture. Or you could have both an undo and a
redo operation. This becomes harder the more extra credit you do.
11) Implement Cut, Copy, and Paste operations:
the Cut and Copy operations
put a copy of the picked object in a special "clipboard" object structure
(and Cut also then Deletes it from the screen and the array); Paste will
draw the object saved in the clipboard at the point clicked on by the
user and put it in the array of objects.
n) Any other features you can think of -- approved by instructor.
What to turn in or demo:
Since much of this lab is interactive, part of the grading will be
based on a demonstration of your program.
Turn in or do the following items from the
Computer Science Lab Report Format:
1. (1 point) The Basic Information (your name, class, section,
assignment number, and date) can be on a separate cover sheet or as
(highlighted) comments at the top of your main program file.
2. (1 point) The Problem Statement is a brief description of
The assignment: above. Note: the problem statement can (and should)
be in a comment at the top of your main program file.
3. & 4. (4 points) Describe the file format and the data
structure for storing the primitives of the drawing.
5. (4 points)
Just describe the Algorithm(s) for important new
procedures (e.g. PickCorrelate)
9. Any Extra Credit items.
11. (5 points) Include all Program Listings.
These listings should show good style,
be appropriately commented, have the new parts
highlighted, and include handwritten explanations if it helps the
reader's understanding of the code.
Also include a screen "snapshot" showing your menu layout.
13. & 14. (15 points) Do "demos" of your program,
showing that it exhibits the correct functionality for all parts.
No writeup is necessary for this part, but
include at least one sample drawing that your program can produce.
15. Include a description of any Known Bugs if needed.
You may be able to gain back lost points by a careful analysis of
what went wrong and possible fixes.
16. This is optional (and no points usually),
but it is useful to think about Possible Improvements.
Obviously there are many for this program.
17. Comments on the lab assignment are also optional
(and again, no points usually), but appreciated!
Important Note: You may discuss algorithms with other students, but the program and lab report should be your own work.