spot
A polygon is stored as a sequence of points and graphically displayed as a sequence of line segments connecting these points.
The computation of a polygon’s area and of the number of counts which are enclosed within a polygon’s perimeter need algorithms’ developments and will be tackled in a different project.
To simplify the code, the drawing of a polygon will be performed as long as the mouse’s button is pressed down. As soon as it is released, the drawing will be considered as done. Don’t forget to only store the polygon’s points when the current point is different from the previous one.
To better grasp the overall flow of events when a mouse event is triggered, here is the method call sequence:
You can browse the documentation of Visu2D to better grok this mechanism.
Create the files polygon.h and polygon.cpp. The list of points will be stored in a std::vector of Point during the mouse’s movement.
Update the cmt/requirements file to know about the polygon.cpp file.
Overload the methods of the Shape class which aren’t suitable for the Polygon class. As for the drawEllipse method used in a previous session, the method drawLine allowing to draw a line segment is documented in Qt.
In the bool Polygon::ModifyEndShape() method, add the first corner of the polygon at the end of the std::vector in order to have a closed polygon.
Complete the method Selection::AllocateShape(SHAPE_TYPE type)
Add a button in WFrame for the polygon. An icon is provided by Polygon.bmp
Update the statistics in DrawQt if it hasn’t been done already.
Update the read/write methods for the polygon.
Warning
For those who already tackled the ``operator overloading`` project
The Polygon holds parameters which are different than the other shapes. During the writing/reading of this shape, it will be unavoidable to detect when you are dealing with such a special shape. To call a specific method of Polygon with your Shape object, you will have to resort to cast this object into a Polygon:
Shape *s = ...;
Polygon *poly = static_cast<Polygon*>(s);