(4) develop a simple CAD circle and rectangle step by step

Source: Internet
Author: User

(1) The Circle parameter, the center of the circle and the point above the circle, that is, the two parameters can draw a circle

As follows:

 

Class ccreateline: Public ccomand
{
Public:
Ccreateline ();
Virtual ~ Ccreateline ();
Public:

Void onlbuttondown (uint nflags, cposition POS );
Void onmousemove (uint nflags, cposition POS );
Void onrbuttondown (uint nflags, cposition POS );

 
PRIVATE:
Cposition m_begin;
Cposition m_end;
Ceraseline m_erase_line; // draw a rubber band

};

 

 

Ccreatecircle: ccreatecircle ()
{
M_nstep = 1;
C_refresh = g_refresh;

}

Ccreatecircle ::~ Ccreatecircle ()
{

}

Void ccreatecircle: onlbuttondown (uint nflags, cposition POS)
{

Switch (m_nstep)
{

Case 1: // output prompt information
{
M_erase_line.setbegin (POS );//////

Cposition center = Pos;
// G_pdoc-> drawflag (true, POs, & center); // draw a flag
M_end = m_begin = center;

M_nstep ++;
Break;

}

Case 2:
{
M_erase_line.setbegin (POS );

CDC * PDC = g_pview-> getdc ();
cposition center2 = Pos;
// g_pdoc-> drawflag (true, POs, & center2 ); // draw the mark
ccircle * ccircel1 = new ccircle (m_begin, center2);
g_pdoc-> m_solid.add (ccircel1 );
m_nstep = 1; // reset
g_pview-> releasedc (PDC);
break;

}< br> default:
break;
}< br>
}

void ccreatecircle: onmousemove (uint nflags, cposition POS)
{< br> cposition center2;
// g_pdoc-> drawflag (true, POs, & center2);
switch (m_nstep)
{< br> case 2:
m_erase_line.setend (POS);
If (c_refresh! = G_refresh)
{< br> m_end = m_begin;
c_refresh = g_refresh;
}< br> CDC * PDC = g_pview-> getdc ();

Ccircle * ccircel1 = new ccircle (m_begin, m_end );
Ccircel1-> drawsolid (PDC, drag );
Delete ccircel1;

Ccircle * ccircel2 = new ccircle (m_begin, POS); // portrait leather Line, Last
Ccircel2-> drawsolid (PDC, normal );
Delete ccircel2;

M_end = Pos;
 

G_pview-> releasedc (PDC );
 
Break;
}
}

Void ccreatecircle: onrbuttondown (uint nflags, cposition POS)
{
CDC * PDC = g_pview-> getdc ();

Ccircle * ccircel2 = new ccircle (m_begin, POS); // portrait leather Line, Last
Ccircel2-> drawsolid (PDC, back );
Delete ccircel2;

G_pview-> releasedc (PDC );

M_nstep = 1;
}

 

(2) Draw a rectangle. The upper left corner and the lower right corner of the circle can be determined by two parameters.

The following command is used to draw a circle:

 

Class ccreaterect: Public ccomand
{
Public:
Ccreaterect ();
Virtual ~ Ccreaterect ();
Public:
Void onlbuttondown (uint nflags, cposition POS );
Void onmousemove (uint nflags, cposition POS );
Void onrbuttondown (uint nflags, cposition POS );
PRIVATE:
Cposition m_begin;
Cposition m_end;

};

 

Ccreaterect: ccreaterect ()
{
M_nstep = 1;
C_refresh = g_refresh;

}

Ccreaterect ::~ Ccreaterect ()
{

}

Void ccreaterect: onlbuttondown (uint nflags, cposition POS)
{

Switch (m_nstep)
{

Case 1: // output prompt information
{

Cposition center = Pos;
// G_pdoc-> drawflag (true, POs, & center); // draw a flag
M_end = m_begin = center;

m_nstep ++;
break;

}< br>
case 2:
{< br> CDC * PDC = g_pview-> getdc ();
cposition center2 = Pos;
// g_pdoc-> drawflag (true, POs, & center2); // draw the mark
ccrect * ccircel1 = new ccrect (m_begin, m_end);
g_pdoc-> m_solid.add (ccircel1 );
m_nstep = 1; // reset
g_pview-> releasedc (PDC);
break;

}< br> default:
break;
}< br>
}

Void ccreaterect: onmousemove (uint nflags, cposition POS)
{

Switch (m_nstep)
{
Case 2:

If (c_refresh! = G_refresh)
{
M_end = m_begin;
C_refresh = g_refresh;
}
CDC * PDC = g_pview-> getdc ();

Ccrect * ccircel1 = new ccrect (m_begin, m_end );
Ccircel1-> drawsolid (PDC, drag );
Delete ccircel1;

Ccrect * ccircel2 = new ccrect (m_begin, POS); // portrait leather Line, Last
Ccircel2-> drawsolid (PDC, normal );
Delete ccircel2;

M_end = Pos;
 

G_pview-> releasedc (PDC );
 
Break;
}
}

Void ccreaterect: onrbuttondown (uint nflags, cposition POS)
{
CDC * PDC = g_pview-> getdc ();

Ccrect * ccircel2 = new ccrect (m_begin, POS); // portrait leather Line, Last
Ccircel2-> drawsolid (PDC, back );
Delete ccircel2;

G_pview-> releasedc (PDC );

M_nstep = 1;
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.