2: Establish geometric elements:
The AutoCAD font contour consists of a collection of arcs and polynomous lines (a curve formed by several points sequentially connected), and the arcs and polysemous lines have some of the same properties and methods, such as drawing, if further development, Related lines and colors, etc., to abstract these public properties and methods to form base classes.
First form three-dimensional point structure and packages to it:
Struct Readshx_API Myxyz
{
Double X;
Double Y;
Double Z;
}
Class Readshx_API CMYXYZ: Public Myxyz
{
PUBLIC:
CMYXYZ () {x = 0; y = 0; z = 0;};
CMYXYZ (MYXYZ XYZ) {this-> x = xyz.x; this-> y = xyz.y; this-> z = xyz.z;};
CMYXYZ (Double X, Double Y, Double Z) {this-> x = x; this-> y = y; this-> z = z;};
Virtual ~ cmyxyz () {};
Operator myxyz () const {return myxyz (* this);
Const CMYXYZ & OPERATOR = (Myxyz & XYZ) {this-> x = xyz.x; this-> y = xyz.y; this-> z = xyz.z; return * this;};
}
The point data is represented by Double and uses a three-dimensional point to facilitate the reuse of the structure more extensive, and CMYXYZ is derived from the MYXYZ structure, which can easily manage the MYXYZ structure, such as using a MYXYZ structure in all parameters. You can directly apply the CMYXYZ class object instead, CMYXYZ (Myxyz XYZ) declares that the copy constructor of the class makes two CMYXZ class objects to assign each other, such as:
Myxyz xyz1;
XYZ1.X = 0;
XYZ1.Y = 1;
XYZ1.Z = 2;
CMYXYZ XYZ2 = XYZ1;
The last line of operation uses CMYXYZ (Myxyz XYZ); function, note that this operation does not use the const cmyxyz & operator = (Myxyz & xyz) function, this function is used outside of initialization, such as XYZ2 has declared, then I am executing XYZ2 = XYZ1; Operation, is defined using the overload equal sign, of course, if there is no overload equal sign, the copy constructor will also be used. CMYXYZ (Double X, Double Y, Double Z); Constructor is used for temporary point objects as parameters, such as Line (CMYXYZ (0, 0), CMYXYZ (100, 100, 0)); this is not necessary to declare two in advance Point, operator myxyz () const; operation transforms the CMYXYZ object into a Myxyz object, with this operator transformation, you can assign CMYXYZ directly to the Myxyz object.
The above constructor and the operator are widely used in mode C , and I hope the reader can understand it in depth.
Declare the geometrical element base class
Class Readshx_API CMYBASE
{
protected:
CMYBASE () {};
PUBLIC:
Virtual int GETTYPE () = 0;
Virtual Int Draw (long Ldevice) = 0;
Virtual ~ cmybase () {};
The constructor of the CMYBASE class declares that the protection type prevents the user from creating a CMYBASE object directly, making it only to derive other classes.
And the pure virtual function Virtual int gettype () = 0; and Virtual Int Draw (long Ldevice) = 0; guarantees that all classes derived from the CMYBase class must overload these two member functions to get a geometric element (such as This geometric element is a polycycle or a arc) and draws on the specified device. Note that the description of the device in Virtual Int Draw (Long Ldevice) = 0 uses a simple LONG type instead of HDC or CDC, which is also considered to be extended by the interface, such as the program may not find HDC in other operating systems. Definition, therefore only uses a long-type parameter description device properties, which can enhance the HDC or CDC pointer to the LONG number incoming parameters in the Windows operating system.
In the multi-sense line class, there must be a list of a multi-ray line vertex pointer. The list is implemented in the standard C Template library (STL), so that you can easily add an element to the list, and traverse the list.
The way to use List is usually like this:
#pragma Warning (Disable: 4786)
#pragma Warning (Disable: 4251)
#pragma Warning (Disable: 4273)
/ / The above three lines are to remove some warnings that are prone to using the STL process, pay attention to the role of the STL including the file.
#include
Using namespace std;
Typedef List
As for the specific usage method, see the next source:
#define isarc 1
#define ispolyln 2
#define isshape 3
// Declare an arc class
Class Readshx_API CMYBASE
{
protected:
CMYBASE () {};
PUBLIC:
Virtual int GETTYPE () = 0;
Virtual Int Draw (long Ldevice) = 0;
Virtual ~ cmybase () {};
}
Class Readshx_API CMYARC: Public CMYBASE
{
PUBLIC:
Virtual Int Draw (long Ldevice);
Cmyarc (Myxyz I_PC, Myxyz I_PS, MYXYZ I_PE);
Virtual Int gettype () {return isarc;};
CMYARC () {};
Virtual ~ cmyarc () {};
MYXYZ M_PC;
MYXYZ M_PS;
MYXYZ M_PE;
}
TYPEDEF LIST
// Declare a polycycle line class
Class Readshx_API CMYPOLYLN: Public CMYBASE
{
PUBLIC:
Virtual Int Draw (long Ldevice);
Virtual int GETTYPE () {Return ispolyln;
Virtual Int Addpoint (Myxyz * PXYZ);
CMYPOLYLN () {m_polyln.clear ();
Virtual ~ cmypolyln ();
MyPOLYLN M_POLYLN;
}
// Declare a word type, actually a collection of geometric objects
Class Readshx_API Cshape: Public CMYBASE {
PUBLIC:
Virtual Int Draw (long Ldevice);
Virtual int gettype () {return isshape;
Cshape () {m_list.clear ();
Virtual ~ cshape ();
List
}