41#pragma region Constructors and destructors
62#pragma endregion Constructors and destructors
67#pragma region Drawing functions
76 HDC hdc = BeginPaint(
m_hWnd, &ps);
77 Gdiplus::Graphics graphics(hdc);
78 graphics.Clear(Gdiplus::Color::White);
83 const int w = pBitmap->GetWidth();
84 const int h = pBitmap->GetHeight();
89 GetClientRect(
m_hWnd, &rectClient);
90 const int nClientWidth = rectClient.right - rectClient.left;
91 const int nClientHeight = rectClient.bottom - rectClient.top;
95 const UINT margin = 20;
97 const float xscale = float(nClientWidth - 2*margin)/w;
98 const float yscale = float(nClientHeight - 2*margin)/h;
99 const float scale = min(min(xscale, yscale), 1);
103 Gdiplus::Rect rectDest;
105 rectDest.Width = (int)std::floor(scale*w);
106 rectDest.Height = (int)std::floor(scale*h);
108 rectDest.X = max(margin, (nClientWidth - rectDest.Width)/2);
109 rectDest.Y = max(margin, (nClientHeight - rectDest.Height)/2);
113 graphics.DrawImage(pBitmap, rectDest);
119#pragma endregion Drawing functions
124#pragma region Menu functions
151#pragma endregion Menu functions
205template void CMain::Generate<CBubbleSortMin>();
206template void CMain::Generate<CBubbleSortMax>();
207template void CMain::Generate<CBubbleSort>();
230template void CMain::GeneratePowerOf2<COddEvenSort>();
231template void CMain::GeneratePowerOf2<CBitonicSort>();
232template void CMain::GeneratePowerOf2<CPairwiseSort>();
275 const std::string strDetails =
"of size " + strSize +
" and depth " + strDepth;
281 bool bUnknown =
false;
287 s =
"Sorting network verification is Co-NP-complete.";
288 s +=
" This may take a long time. Are you sure you want to proceed?";
290 const int id = MessageBox(
nullptr, s.c_str(),
"Verify", MB_ICONQUESTION | MB_YESNO);
294 else bUnknown =
true;
298 s =
"This is a " + strInputs +
"-input sorting network " + strDetails +
".";
299 nIcon = MB_ICONINFORMATION;
303 s =
"This is a " + strInputs +
"-input comparator network " + strDetails +
".";
304 nIcon = MB_ICONINFORMATION;
308 s =
"This is a " + strInputs +
"-input comparator network " + strDetails +
309 " that is not a sorting network.";
310 nIcon = MB_ICONERROR;
316 s +=
" It is in First Normal Form.";
317 else s +=
" It is not in First Normal Form.";
323 result = nUnused > 0;
325 const std::string strUnused = std::to_string(nUnused);
327 s +=
" There are " + (nUnused == 0?
"no": strUnused) +
" redundant comparators.";
332 MessageBox(
nullptr, s.c_str(),
"Verify", nIcon | MB_OK);
343 case eDrawStyle::Vertical:
348 case eDrawStyle::Horizontal:
Interface for Batcher's bitonic sorting network.
Interface for the bubblesort sorting network.
Interface for the main class CMain.
Interface for CDialogBox.
UINT CeilLog2(const UINT n)
Ceiling of log base 2.
bool IsPowerOf2(const UINT n)
Power of 2 test.
Header for useful helper functions.
Interface for Batcher's odd-even sorting network.
Interface for the pairwise sorting network.
void CreateFileMenu(HMENU hParent)
Create File menu.
HRESULT Load(HWND hwnd, CComparatorNetwork *pNet, std::wstring &wstrName)
Load comparator network.
HRESULT ExportImage(const eExport t, HWND hwnd, CRenderableComparatorNet *pNet, std::wstring &wstrName)
Export.
void CreateGenerateMenu(HMENU hParent)
Create Generate menu.
ULONG_PTR InitGDIPlus()
Initialize GDI+.
void CreateHelpMenu(HMENU hParent)
Create Help menu.
void CreateViewMenu(HMENU hParent)
Create View menu.
Interface for some helpful Windows-specific functions.
#define IDM_FILE_EXPORT_PNG
Menu id for Export PNG.
#define IDM_FILE_VERIFY
Menu id for Verify.
#define IDM_FILE_EXPORT_TEX
Menu id for Export TeX.
#define IDM_VIEW_HORIZONTAL
Menu id for horizontal view.
#define IDM_FILE_EXPORT_SVG
Menu id for Export SVG.
#define IDM_VIEW_VERTICAL
Menu id for vertical view.
const UINT GetDepth() const
Get depth.
const bool FirstNormalForm() const
Test for first normal form.
const UINT GetSize() const
Get size.
const UINT GetNumInputs() const
Get number of inputs.
void SetDrawStyle(const eDrawStyle)
Set drawing style.
void CreateMenus()
Create menus.
std::wstring m_wstrName
File name.
CMain(const HWND)
Constructor.
void Draw()
Draw comparator network to bitmap.
void Read()
Read comparator network from file.
void GeneratePowerOf2()
Generate sorting network.
ULONG_PTR m_gdiplusToken
GDI+ token.
HRESULT Export(const eExport)
Export image file.
eDrawStyle m_eDrawStyle
Drawing style.
void EnableMenus()
Enable menus.
HMENU m_hMenuBar
Handle to the menu bar.
Gdiplus::Bitmap * GetBitmap()
Get pointer to bitmap.
void Generate()
Generate sorting network.
void OnPaint()
Paint the client area of the window.
CSortingNetwork * m_pSortingNetwork
Pointer to the sorting network.
bool Verify()
Verify that comparator network sorts.
HWND m_hWnd
Window handle.
Gdiplus::Bitmap * GetBitmap()
Get bitmap pointer.
void Draw(const eDrawStyle)
Draw to a Gdiplus::Bitmap.
const UINT GetUnused() const
Get number of unused comparators.
bool sorts()
Does it sort?