// TypeSet.cpp: Implementation of the ctypeset class./////
#include "stdafx.h" #include "../inc/typeset.h"// Usage example void testtypeset (HDC DC) {// declare a plate object ctypeset typeset; // set the sheet object size TypeSet.m_desktop.m_dheight = 9999; TypeSet.m_desktop.m_dwidth = 100; // Declare a row element object cMaterial massial; // Set the size of the sample element object size Material.setsize (20, 99); // Add Enter the sheet object TypeSet.Add (& Material) ); // Continue to add Material.SetSize (99, 80); typeSet.Add (& Material); Material.Setsize (10, 60); typeSet.Add (& Material); Material.Setsize (50, 20); typeSet.Add (& matial); // Added, make a sampling typeSet.go (); // Drainage, output list
//// construction / destruction // # Define ZERO 0.00001
CMaterial :: CMaterial () {m_dHeight = 100; m_dWidth = 100; m_dX = 0; m_dY = 0; m_bUsed = FALSE; m_bSeletcted = FALSE; m_bRotated = FALSE; m_iIndex = 0;} CMaterial :: CMaterial (double dWidth, double dHeight ) {SetSize (dWidth, dHeight); m_dX = 0; m_dY = 0; m_bUsed = FALSE; m_bSeletcted = FALSE; m_bRotated = FALSE; m_iIndex = 0;} CMaterial :: CMaterial (CMaterial * pMaterial) {m_dX = pMaterial-> m_dX ; m_dY = pMaterial-> m_dY; m_dHeight = pMaterial-> m_dHeight; m_dWidth = pMaterial-> m_dWidth; m_bUsed = pMaterial-> m_bUsed; m_bSeletcted = pMaterial-> m_bSeletcted; m_bRotated = pMaterial-> m_bRotated; m_iIndex = pMaterial-> m_iIndex; } void CMaterial :: SetSize (double dWidth, double dHeight) {m_dHeight = dHeight; m_dWidth = dWidth;!} void CMaterial :: Rotated () {m_bRotated = m_bRotated; double dA = m_dHeight; m_dHeight = m_dWidth; m_dWidth = dA;} CMATERIAL: :: ~ cmaterial () {} //// Construction / destruction ////
Ctypeset :: ctypeset () {clear ();
CTypeset :: ~ ctypeset () {clear ();
Void ctypeset :: clear () {list
Void ctypeset :: add (cMaTerial * pmaterial) {cMaterial * p = new cMaterial (pMaterial); p-> m_iindex = m_ICURINDEX; M_MATERIALLIST.INSERT (m_materialial means (), p); m_ICURINDEX ;}
Void ctypeset :: sort () {list
double CTypeset :: Typeset (double dStartX, double dStartY, double dStartHei, double dStartWid, list
IF (m_materialList.empty ()) Return 0; for (iter = m_materialialList.begin (); it! = m_materialialList.end (); ore ) {if (* ip) -> m_bused! = false) Continue; if ( (* iter) -> m_dwidth <(* ip) -> m_dheight) {MessageBox (NULL, "Error", "Error", MB_OK); Return 0;}
// Find a plate that can be put into the largest plate // If the sheet can be placed in IF ((DHEIGHT> (* iper) && (dwidth> (* iTer) -> m_dheight-zero) && ((DHEIGHT> (* iper) -> m_dheight-zero) && (DWidth> (* i) -> m_dwidth-zero)) {if (dstartx
(* iTer) -> setused (true); // Sampling
// Put the remaining area, calculate the remaining area DAREA1 = TypeSet (DSTARTX (* iTER) -> m_dwidth, dstarty, dHEight - (* ip) -> m_dwidth, (* ip) -> m_dheight, & list1); DRESTAREA1 = DHEIGHT * DWIDTH-DAREA1 - (* iter) -> getarea (); DRESTAREA1 = DRESTAREA1 / (DHEIGHT * DWIDTH); // Remaining area ratio
// Restore the sheet state of the sheet just exhausted, then placed in the figure to continue the drain, calculate the remaining area IF (DSTARTX
SetStatus (& List1, False); tmpunit = (* iter) -> Copy (); tmpunit-> rotated (); Darea2 = TypeSet (DSTARTX TMPUNIT-> M_DWIDTH, DSTARTY, DHEIGHT-TMPUNIT-> m_dwidth, tmpunit-> m_dheight , & List2); DRESTAREA2 = DHEIGHT * dwidth-Darea2-TmpUnit-> getarea (); DRESTAREA2 = DRESTAREA2 / (DHEIGHT * DWIDTH); // Remaining area rate} else if ((DHEIGHT> (* iper) -> m_dwidth-zero ) && (dwidth> (* i) -> m_dheight-zero)) // If the sheet can only be placed in {IF (DSTARTX
DRESTAREA2 = DRESTAREA1 10; // No longer attempt to vertical, set the remaining area} else if ((DHEIGHT> (* iper) -> m_dheight-zero) && (dwidth> (* iTer) -> m_dwidth- ZERO)) // If the sheet can only be placed in {IF (DSTARTX
(* iTer) -> setused (true); // Stroking TMPUNIT = (* iter) -> Copy (); tmpunit-> rotated (); Darea2 = Typeset (DSTARTX TMPUNIT-> m_dwidth, dstarty, DHEIGHT-TMPUNIT-> M_DWIDTH, TMPUNIT-> m_dheight, & list2); DRESTAREA2 = DHEIGHT * DWIDTAREA2 = DHEIGHT * dwidth-Darea2-TmpUnit-> getarea (); DRESTAREA2 = DRESTAREA2 / (DHEIGHT * DWIDTH); // Remaining area rate
DRESTAREA1 = DRESTAREA2 10; // No longer try to settle, set the lavert place area} else continue;
// Record the optimized sampling sequence cMaterial * TMP = NULL; if (DRESTAREA1
delete tmpunit;} double next_x, next_y, next_len, next_wid; next_x = dStartX; next_y = dStartY tmp-> m_dHeight; next_len = dHeight; next_wid = dStartWid-tmp-> m_dHeight; if (next_wid> ZERO) // plate also The remaining {// Continue to discharge a line DAREA = DAREA TYPESET (next_x, next_y, next_len, next_wid, & list1); // Record the Sampling Sequence SetStatus (& List1, True); for (iter1 = List1.begin (); iTer1! = List1.end (); item1 ) {pList-> INSERT (PLIST-> End (), (* iter1));} list1.clear ();} return darea;} return 0;} void cMaterial :: setused BOOL Buses {m_bused = bused;}
Void ctypeset :: setStatus (list
CMATERIAL * CMATERIAL :: COPY () {cMaTerial * P = new cMaterial (this); return p;}
// TypeSet.h: interface for the ctypeset.////
#if! defined (AFX_TYPESET_H___46213FAE_D2D6_42A6_B801_41D9109CD0FB__included _) # define afX_TYPESET_H__46213FAE_D2D6_42A6_B801_41D9109CD0FB__included_
# if m onc (disable: 4251) #Pragma Warning (Disable: 4251) #nclude #include
#ifdef typeseetlib_exports # define typesetd (DLLEXPORT) #ELSE # define typesetd (DLLIMPORT) #ENDIF
TypeSetlib_API Void TestTypeset (HDC DC);
class TYPESETLIB_API CMaterial {public: virtual CMaterial * Copy (); virtual void SetUsed (BOOL bUsed); virtual void Rotated (); virtual void SetSize (double dWidth, double dHeight); virtual double GetArea () {return m_dHeight * m_dWidth;} CMaterial (); CMaterial (CMaterial * pMaterial); CMaterial (double dWidth, double dHeight); virtual ~ CMaterial (); double m_dHeight, m_dWidth; double m_dX, m_dY; BOOL m_bUsed; BOOL m_bSeletcted; BOOL m_bRotated; int m_iIndex;}; class TYPESETLIB_API CTypeset {public: virtual double Go (); virtual void Add (CMaterial * pMaterial); CTypeset (); virtual ~ CTypeset (); list