MainWindow::MainWindow(void):
wxFrame(NULL, wxID_ANY, wxString(wxT("CNC – øídicí systém")), wxDefaultPosition, wxSize(1000, 600), wxDEFAULT_FRAME_STYLE | wxMAXIMIZE)
{
	//Naètení ikony hlavního okna
	wxIcon icon(wxT("IDI_ICON1"), wxBITMAP_TYPE_ICO_RESOURCE);
	if(!icon.IsOk())
	{
		PostErrorMessage(wxT("Nepodaøilo ase naèíst ikonu hlavního okna"));
	}
	SetIcon(icon);
	//StatusBar
	statusBar = CreateStatusBar(4);
	statusBar->SetStatusText(wxT("Nepøipojeno k intepolátoru"), 0);
	statusBar->SetStatusText(wxT("Žádný program"), 1);
	statusBar->SetStatusText(wxT("Neznámá pozice"), 2);
	statusBar->SetStatusText(wxT("Stav neurèen"), 3);
	//Menu
	menu = new wxMenuBar;
	file = new wxMenu;
	file->Append(wxID_OPEN, wxT("Otevøít soubor s intrukcemi"), wxT("Otevøít soubor s programem"), false);
	file->Append(ID_OPEN_GCODE, wxT("Otevøít G-kód"), wxT("Otevøít soubor s programem"), false);
	file->Append(wxID_EXIT, wxT("&Konec"));
	menu->Append(file, wxT("&Soubor"));
	view = new wxMenu;
	view->Append(ID_RESETVIEW, wxT("Resetovat zobrazení drah"), wxT("Obnoví zobrazení"), false);
	view->Append(ID_RESETTRAJECTORY, wxT("Smazat stopu"), wxT("Smaže stopu nástroje"), false);
	view->Append(ID_TOGGLETRAJECTORY, wxT("Vypnout/zapnout stopu"), wxT(""), false);
	menu->Append(view, wxT("&Náhled"));
	SetMenuBar(menu);
	//Connect menus and buttons to the functions
	Connect(wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnOpen));
	Connect(ID_OPEN_GCODE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnOpenGcode));
	Connect(ID_RESETVIEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnViewReset));
	Connect(ID_RESETTRAJECTORY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnTrajectoryReset));
	Connect(ID_TOGGLETRAJECTORY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainWindow::OnTrajectoryToggle));
	//Toolbar
	toolbar = CreateToolBar();
	toolbar->SetToolBitmapSize(wxSize(48, 48));
	toolbar->AddSeparator();
	toolbar->AddTool(2, wxBitmap(wxT("IDB_STARTPROGRAM"), wxBITMAP_TYPE_BMP_RESOURCE), wxT("Spustit program"));
	toolbar->AddTool(3, wxBitmap(wxT("IDB_PAUSEPROGRAM"), wxBITMAP_TYPE_BMP_RESOURCE), wxT("Pozastavit program"));
	toolbar->AddTool(4, wxBitmap(wxT("IDB_STOPPROGRAM"), wxBITMAP_TYPE_BMP_RESOURCE), wxT("Zastavit program"));
	toolbar->Realize();
	toolbar->EnableTool(1, false);
	toolbar->EnableTool(3, false);
	toolbar->EnableTool(4, false);
	SetStatusBarPane(-1);
	//Connect icons to the function
	Connect(2, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(MainWindow::OnRunProgram));
	Connect(3, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(MainWindow::OnPauseProgram));
	Connect(4, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(MainWindow::OnStopProgram));

	//Splitter window
	topSplit = new wxSplitterWindow(this);
	//Content of the left
	leftPanel = new wxPanel(topSplit, 0, 0, 150, 150);
	//Content of the right
	downSplit = new wxSplitterWindow(topSplit);
	//Content of the downSplit
	middlePanel = new PreviewWindow(downSplit, 0, 0, 150, 150);
	rightPanel = new wxPanel(downSplit, 0, 0, 150, 150);
	//Split the windows
	topSplit->SplitVertically(leftPanel, downSplit, 250);
	downSplit->SplitVertically(middlePanel, rightPanel, -300);
	middlePanel->Reset();
	topSplit->SetSashGravity(0);
	downSplit->SetSashGravity(1);
	topSplit->SetMinimumPaneSize(150);
	downSplit->SetMinimumPaneSize(200);

	//Content of the right panel
	codeView = new wxTextCtrl(rightPanel, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_AUTO_SCROLL | wxTE_READONLY | wxTE_RICH2 | wxHSCROLL | wxTE_NOHIDESEL);
	wxBoxSizer *sizeRight = new wxBoxSizer(wxVERTICAL);
	sizeRight->Add(codeView, 1, wxEXPAND | wxALL, 0);
	rightPanel->SetSizer(sizeRight);

	//Set the font
	wxFont codeFont(15, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL, false);
	codeView->SetDefaultStyle(wxTextAttr(wxColour((unsigned long)(0)), wxNullColour, codeFont));
	
	//Initialization of USB - receivng messages obaout device state
	HWND hwnd = HWND(GetHWND());
	DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
    ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
    NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
    NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    NotificationFilter.dbcc_classguid = DEVICE_INTERFACE;
	if(!RegisterDeviceNotification(hwnd, (void*)(&NotificationFilter), DEVICE_NOTIFY_WINDOW_HANDLE))
	{
		wxString err;
		err << wxT("Chyba pøi incializaci notifikace pro zaøízení - chyba ")  << GetLastError();
		PostErrorMessage(err);
	}

	//Centre window
	Center();
	Maximize();
	middlePanel->Reset();
}
Пример #2
0
void DisView::OnPaint(wxPaintEvent &evt)
{
	wxPaintDC dc(this);
	// Initialize tools
	wxBrush infoBrush(wxSystemSettings::GetColour(wxSystemColour::wxSYS_COLOUR_INACTIVECAPTION), wxBRUSHSTYLE_SOLID);
	wxBrush arrowBrush(wxColour(0xF7, 0xEA, 0x59));
	wxBrush breakBrush(wxColour(0xFC, 0x0D, 0x00));
	wxFont infoFont(wxSystemSettings::GetFont(wxSystemFont::wxSYS_SYSTEM_FONT));
	wxFont codeFont(wxSystemSettings::GetFont(wxSystemFont::wxSYS_ANSI_FIXED_FONT));
	wxPen transparentPen(wxColour(), 0, wxPenStyle::wxPENSTYLE_TRANSPARENT);
	wxPen infoTextPen(wxSystemSettings::GetColour(wxSystemColour::wxSYS_COLOUR_INFOTEXT));
	wxPen codeTextPen = infoTextPen;
	dc.SetFont(infoFont);
	dc.SetPen(infoTextPen);

	// Initialize sizes
	wxRect clientRect(dc.GetSize());
	wxRect codeRect = clientRect;
	wxPoint infoCorner(20, dc.GetCharHeight() + 10);
	wxRect addressLabelRect(infoCorner.x, 0, 0, infoCorner.y);
	wxRect rawLabelRect = addressLabelRect;
	wxRect instrLabelRect = rawLabelRect;

	codeRect.SetTopLeft(infoCorner);
	addressLabelRect.SetWidth(dc.GetFontMetrics().averageWidth*16);
	rawLabelRect.Offset(addressLabelRect.GetWidth(), 0);
	rawLabelRect.SetWidth(dc.GetFontMetrics().averageWidth * 18);
	instrLabelRect.SetLeft(rawLabelRect.GetRight());
	instrLabelRect.SetRight(codeRect.GetRight());
	wxRect addressRect = addressLabelRect;
	wxRect rawRect = rawLabelRect;
	wxRect instrRect = instrLabelRect;
	addressRect.Offset(0, addressLabelRect.GetHeight());
	rawRect.Offset(0, rawRect.GetHeight());
	instrRect.Offset(0, instrRect.GetHeight());
	dc.SetFont(codeFont);
	_startingY = infoCorner.y;
	_lineHeight = dc.GetCharHeight();
	addressRect.SetHeight(_lineHeight);
	rawRect.SetHeight(_lineHeight);
	instrRect.SetHeight(_lineHeight);

	// Clear background
	//ClearBackground();

	// Paint info bars
	dc.SetBrush(infoBrush);
	dc.SetFont(infoFont);
	dc.SetPen(transparentPen);
	dc.DrawRectangle(0,0, dc.GetSize().GetWidth(), infoCorner.y);
	dc.DrawRectangle(0, infoCorner.y, infoCorner.x, clientRect.GetHeight()-infoCorner.y);
	dc.SetPen(infoTextPen);
	wxPoint labelVertCenterOffset(0,(addressLabelRect.GetHeight() - dc.GetCharHeight())/2);
	dc.DrawText(_("Address:"), addressLabelRect.GetLeftTop() + labelVertCenterOffset);
	dc.DrawText(_("Raw:"), rawLabelRect.GetLeftTop() + labelVertCenterOffset);
	dc.DrawText(_("Instruction:"), instrLabelRect.GetLeftTop() + labelVertCenterOffset);

	// Paint code section
	dc.SetFont(codeFont);
	dc.SetPen(codeTextPen);
	if (_emu->emu != NULL && _numberOfLines > 0)
	{

		unsigned int address = _startingLine;
		while (addressRect.GetBottom() < codeRect.GetBottom())
		{
			// Draw a line
			const char *raw;
			const char *instr;
			char size = _emu->emu->Disassemble(_emu->handle, address, &raw, &instr);

			if (address == _currentLine) // Draw currentLine icon
			{
				dc.SetBrush(arrowBrush);
				dc.SetPen(transparentPen);
				wxPoint arrowPoint(0, addressRect.GetTop()+2);
				dc.DrawRoundedRectangle(arrowPoint, wxSize(infoCorner.x, _lineHeight-4), 3);
				dc.DrawRectangle(addressRect);
				dc.DrawRectangle(rawRect);
				dc.DrawRectangle(instrRect);
				dc.SetPen(codeTextPen);
			}
			if (_emu->emu->IsBreakpoint(_emu->handle, address))
			{
				// Breakpoint
				wxPoint breakPoint(infoCorner.x / 2, addressRect.GetTop() + _lineHeight / 2);
				dc.SetBrush(breakBrush);
				dc.SetPen(transparentPen);
				dc.DrawCircle(breakPoint, _lineHeight / 2);
				dc.SetPen(codeTextPen);
			}

			dc.DrawText(wxString::Format("0x%08X", address), addressRect.GetLeftTop());
			dc.DrawText(raw, rawRect.GetLeftTop());
			dc.DrawText(instr, instrRect.GetLeftTop());

			address += size;
			address %= _numberOfLines;
			addressRect.Offset(0, addressRect.GetHeight());
			rawRect.Offset(0, rawRect.GetHeight());
			instrRect.Offset(0, instrRect.GetHeight());
		}
		_endingLine = address;
	}
	else {
		// Draw no emulator loaded text
		wxPoint centerCode(codeRect.GetBottomLeft());
		centerCode.y -= codeRect.GetHeight()/2;
		dc.DrawText(_("There is no emulator loaded"),centerCode);
	}
}