// IncSourceTestDlgDlg.cpp: 구현 파일 // #include "pch.h" #include "framework.h" #include "IncSourceTestDlg.h" #include "IncSourceTestDlgDlg.h" #include "DlgProxy.h" #include "afxdialogex.h" #include #ifdef _DEBUG #define new DEBUG_NEW #endif //template //std::wstring wstring_format(const std::wstring& format, Args ... args); template std::string string_format(const std::string& format, Args ... args) { size_t size = snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0' if (size <= 0) { throw std::runtime_error("Error during formatting."); } std::unique_ptr buf(new char[size]); snprintf(buf.get(), size, format.c_str(), args ...); return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside } } // 응용 프로그램 정보에 사용되는 CAboutDlg 대화 상자입니다. class CAboutDlg : public CDialogEx { public: CAboutDlg(); // 대화 상자 데이터입니다. #ifdef AFX_DESIGN_TIME enum { IDD = IDD_ABOUTBOX }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 지원입니다. // 구현입니다. protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // CIncSourceTestDlgDlg 대화 상자 IMPLEMENT_DYNAMIC(CIncSourceTestDlgDlg, CDialogEx); CIncSourceTestDlgDlg::CIncSourceTestDlgDlg(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_INCSOURCETESTDLG_DIALOG, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_pAutoProxy = nullptr; } CIncSourceTestDlgDlg::~CIncSourceTestDlgDlg() { // 이 대화 상자에 대한 자동화 프록시가 있을 경우 이 대화 상자에 대한 // 후방 포인터를 null로 설정하여 // 대화 상자가 삭제되었음을 알 수 있게 합니다. if (m_pAutoProxy != nullptr) m_pAutoProxy->m_pDialog = nullptr; } void CIncSourceTestDlgDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CIncSourceTestDlgDlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_CLOSE() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON_OPEN, &CIncSourceTestDlgDlg::OnBnClickedButtonOpen) END_MESSAGE_MAP() // CIncSourceTestDlgDlg 메시지 처리기 BOOL CIncSourceTestDlgDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 시스템 메뉴에 "정보..." 메뉴 항목을 추가합니다. // IDM_ABOUTBOX는 시스템 명령 범위에 있어야 합니다. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != nullptr) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 이 대화 상자의 아이콘을 설정합니다. 응용 프로그램의 주 창이 대화 상자가 아닐 경우에는 // 프레임워크가 이 작업을 자동으로 수행합니다. SetIcon(m_hIcon, TRUE); // 큰 아이콘을 설정합니다. SetIcon(m_hIcon, FALSE); // 작은 아이콘을 설정합니다. // TODO: 여기에 추가 초기화 작업을 추가합니다. return TRUE; // 포커스를 컨트롤에 설정하지 않으면 TRUE를 반환합니다. } void CIncSourceTestDlgDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialogEx::OnSysCommand(nID, lParam); } } // 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면 // 아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 애플리케이션의 경우에는 // 프레임워크에서 이 작업을 자동으로 수행합니다. void CIncSourceTestDlgDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트입니다. SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다. int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 아이콘을 그립니다. dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } // 사용자가 최소화된 창을 끄는 동안에 커서가 표시되도록 시스템에서 // 이 함수를 호출합니다. HCURSOR CIncSourceTestDlgDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } // 컨트롤러에서 해당 개체 중 하나를 계속 사용하고 있을 경우 // 사용자가 UI를 닫을 때 자동화 서버를 종료하면 안 됩니다. 이들 // 메시지 처리기는 프록시가 아직 사용 중인 경우 UI는 숨기지만, // UI가 표시되지 않아도 대화 상자는 // 남겨 둡니다. void CIncSourceTestDlgDlg::OnClose() { if (CanExit()) CDialogEx::OnClose(); } void CIncSourceTestDlgDlg::OnOK() { if (CanExit()) CDialogEx::OnOK(); } void CIncSourceTestDlgDlg::OnCancel() { if (CanExit()) CDialogEx::OnCancel(); } BOOL CIncSourceTestDlgDlg::CanExit() { // 프록시 개체가 계속 남아 있으면 자동화 컨트롤러에서는 // 이 애플리케이션을 계속 사용합니다. 대화 상자는 남겨 두지만 // 해당 UI는 숨깁니다. if (m_pAutoProxy != nullptr) { ShowWindow(SW_HIDE); return FALSE; } return TRUE; } void CIncSourceTestDlgDlg::OnBnClickedButtonOpen() { // TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다. TCHAR a2lExt[] = _T("*.a2l"); TCHAR a2lBaseFilter[] = _T("A2L file(*.A2L) | *.a2l;*.A2L | 모든파일(*.*) | *.* ||"); CFileDialog dlg(TRUE, a2lExt, NULL, OFN_HIDEREADONLY, a2lBaseFilter); if (dlg.DoModal() == IDOK) { std::wstring strPath = dlg.GetPathName().GetBuffer(); std::string strA2lPath; strA2lPath.assign(strPath.begin(), strPath.end()); loadA2lFile(strA2lPath.c_str()); } } void CIncSourceTestDlgDlg::loadA2lFile(std::string strFilePath) { std::string strLogData; bool bIsFileExist = false; try { bIsFileExist = std::filesystem::exists(strFilePath); } catch (const std::exception& error) { std::cout << "Failed to fetch the A2l test files. Error: " << error.what(); } a2l::A2lFile file; file.Filename(strFilePath.data()); const auto parse = file.ParseFile(); if (parse) std::cout << file.LastError() << " : " << strFilePath.data(); std::cout << file.Name() << (parse ? " : OK" : " : FAIL") << std::endl; AddLogString(strFilePath.data()); //if (file.A2lVersion().VersionNo == 1) // ; std::cout << file.A2lVersion().VersionNo << " : " << file.A2lVersion().VersionNo; AddLogString(string_format("file.A2lVersion().VersionNo : %d", file.A2lVersion().VersionNo)); //if (file.A2lVersion().UpgradeNo == 71) // ; std::cout << file.A2lVersion().UpgradeNo << " : " << file.A2lVersion().UpgradeNo; AddLogString(string_format("file.A2lVersion().UpgradeNo : %d", file.A2lVersion().UpgradeNo)); const auto& project = file.Project(); const auto& header = project.Header(); //EXPECT_FALSE(header.Comment.empty()); //EXPECT_FALSE(header.ProjectNo.empty()); //EXPECT_FALSE(header.VersionNo.empty()); std::cout << header.Comment << " : " << header.Comment; AddLogString(string_format("header.Comment : %s", header.Comment.c_str())); std::cout << header.ProjectNo << " : " << header.ProjectNo; AddLogString(string_format("header.ProjectNo : %s", header.ProjectNo.c_str())); std::cout << header.VersionNo << " : " << header.VersionNo; AddLogString(string_format("header.VersionNo : %s", header.VersionNo.c_str())); const auto& module_list = project.Modules(); //ASSERT_EQ(module_list.size(), 1); std::cout << module_list.size() << " : " << module_list.size(); AddLogString(string_format("module_list.size() : %d", module_list.size())); if (module_list.size() > 0) { const auto& module = module_list.cbegin()->second; //ASSERT_TRUE(module); //EXPECT_STREQ(module->Name().c_str(), "Example"); //EXPECT_FALSE(module->A2ml().empty()); AddLogString(string_format("module->Name() : %s", module->Name().c_str())); AddLogString(string_format("module->A2ml() : %s", module->A2ml().c_str())); AddLogString(""); const auto& modPar = module->ModPar(); AddLogString(string_format("modPar.Comment() : %s", modPar.Comment.c_str())); AddLogString(string_format("modPar.epk : %s", modPar.Epk.c_str())); AddLogString(string_format("modPar.addr_epk size : %d", modPar.AddressEpkList.size())); for (int i = 0; i < modPar.AddressEpkList.size(); i++) { AddLogString(string_format("modPar.addr_epk (%d) addr (0x%X)", i, modPar.AddressEpkList.at(i))); } AddLogString(string_format("modPar.memory layout size : %d", modPar.MemoryLayoutList.size())); /* for (int i = 0; i < modPar.MemoryLayoutList.size(); i++) { AddLogString(string_format("modPar.MemoryLayoutList (%d) addr (0x%X)", i, modPar.MemoryLayoutList.at(i))); } */ AddLogString(string_format("modPar.memory segment size : %d", modPar.MemorySegmentList.size())); for (int i = 0; i < modPar.MemorySegmentList.size(); i++) { AddLogString(string_format("(%d) modPar.Memory sement description=[%s] segment_type=[%d] memory_type=[%d] attribution=[%d] addr (0x%X) size(0x%X) offset_list=[%d] ifDataList=[%d]", i, modPar.MemorySegmentList.at(i).Description.c_str(), modPar.MemorySegmentList.at(i).SegmentType, modPar.MemorySegmentList.at(i).MemoryType, modPar.MemorySegmentList.at(i).Attribute, modPar.MemorySegmentList.at(i).Address, modPar.MemorySegmentList.at(i).Size, modPar.MemorySegmentList.at(i).OffsetList.size(), modPar.MemorySegmentList.at(i).IfDataList.size())); } AddLogString(""); const auto& modComm = module->ModCommon(); AddLogString(string_format("modComm.Comment() : %s", modComm.Comment.c_str())); AddLogString(string_format("modComm.Deposit : %d", modComm.Deposit)); AddLogString(string_format("modComm.ByteOrder : %d", modComm.ByteOrder)); AddLogString(string_format("modComm.AlignmentByte : %d", modComm.AlignmentByte)); AddLogString(string_format("modComm.AlignmentFloat16 : %d", modComm.AlignmentFloat16)); AddLogString(string_format("modComm.AlignmentFloat32 : %d", modComm.AlignmentFloat32)); AddLogString(string_format("modComm.AlignmentFloat64 : %d", modComm.AlignmentFloat64)); AddLogString(string_format("modComm.AlignmentInt64 : %d", modComm.AlignmentInt64)); AddLogString(string_format("modComm.AlignmentLong : %d", modComm.AlignmentLong)); AddLogString(string_format("modComm.AlignmentWord : %d", modComm.AlignmentWord)); AddLogString(""); for (const auto& [protocol, if_data] : module->IfDatas()) { a2l::IfDataBlock block(if_data); //EXPECT_TRUE(block.IsOk()) << block.LastError(); std::cout << block.AsString() << std::endl; AddLogString(string_format("IF_DATA : %s", block.Protocol().c_str())); AddLogString(string_format("block.ItemList().size() : %d", block.ItemList().size())); for (int i = 0; i < block.ItemList().size(); i++) { AddLogString(string_format("%d block.ItemList() : %s", i, block.ItemList()[i].BlockName.c_str())); AddLogString(string_format("block.ItemList()[i].ItemList.size() : %d", block.ItemList()[i].ItemList.size())); for (int j = 0; j < block.ItemList()[i].ItemList.size(); j++) { // check digit bool bIsDigit = true; if (j > 0) TRACE("asdf"); for (int cnt = 0; cnt < block.ItemList()[i].ItemList[j].Value.size(); cnt++) { //int value = std::isdigit(block.ItemList()[i].ItemList[j].Value.at(cnt)); //int alpha = std::isalpha(block.ItemList()[i].ItemList[j].Value.at(cnt)); //TRACE("[%c][%d][%d]\n", block.ItemList()[i].ItemList[j].Value.at(cnt), value, alpha); if (std::isdigit(block.ItemList()[i].ItemList[j].Value.at(cnt)) == 0) bIsDigit = false; } if (bIsDigit) AddLogString(string_format("%d : Address 0x%X (%d) : %s itemlist=%d", j, atoi(block.ItemList()[i].ItemList[j].Value.c_str()), atoi(block.ItemList()[i].ItemList[j].Value.c_str()), block.ItemList()[i].ItemList[j].BlockName.c_str(), block.ItemList()[i].ItemList[j].ItemList.size())); else AddLogString(string_format("%d : %s : %s itemlist=%d", j, block.ItemList()[i].ItemList[j].Value.c_str(), block.ItemList()[i].ItemList[j].BlockName.c_str(), block.ItemList()[i].ItemList[j].ItemList.size())); for (int k = 0; k < (block.ItemList()[i].ItemList[j].ItemList.size()); k++) { AddLogString(string_format(" %d : %s : %s", k, block.ItemList()[i].ItemList[j].ItemList[k].Value.c_str(), block.ItemList()[i].ItemList[j].ItemList[k].BlockName.c_str())); } } AddLogString(""); } //AddLogString(string_format("block.AsString() : %s", block.AsString().c_str())); AddLogString(""); } AddLogString(""); const auto& axis_list = module->AxisPtss(); //EXPECT_GT(axis_list.size(), 1); std::cout << "\t\tAXIS PTS" << std::endl; for (const auto& [pts_name, pts] : axis_list) { std::cout << pts_name << std::endl; } std::cout << std::endl; const auto& blob_list = module->Blobs(); //EXPECT_GT(blob_list.size(), 0); std::cout << "\t\tBLOB" << std::endl; for (const auto& [blob_name, blob] : blob_list) { std::cout << blob_name << " " << blob->Address() << std::endl; } std::cout << std::endl; AddLogString(""); const auto& characteristic_list = module->Characteristics(); //EXPECT_GT(characteristic_list.size(), 0); std::cout << "\t\tCHARACTERISTIC" << std::endl; AddLogString(string_format("chracteristics : %d", characteristic_list.size())); int i = 0; for (const auto& [char_name, characteristic] : characteristic_list) { std::cout << char_name << " " << characteristic->Description() << std::endl; AddLogString(string_format(" %d : %s", i, characteristic->Description().c_str())); } std::cout << std::endl; AddLogString(""); const auto& compu_method_list = module->CompuMethods(); //EXPECT_GT(compu_method_list.size(), 0); std::cout << "\t\tCOMPU METHOD" << std::endl; for (const auto& [method_name, method] : compu_method_list) { std::cout << method_name << " " << method->Description() << std::endl; } std::cout << std::endl; const auto& compu_tab_list = module->CompuTabs(); //EXPECT_GT(compu_tab_list.size(), 0); std::cout << "\t\tCOMPU TAB" << std::endl; for (const auto& [tab_name, tab] : compu_tab_list) { std::cout << tab_name << " " << tab->Description() << std::endl; } std::cout << std::endl; const auto& compu_vtab_list = module->CompuVtabs(); //EXPECT_GT(compu_vtab_list.size(), 0); std::cout << "\t\tCOMPU VTAB" << std::endl; for (const auto& [vtab_name, vtab] : compu_vtab_list) { std::cout << vtab_name << " " << vtab->Description() << std::endl; } std::cout << std::endl; const auto& compu_vtab_range_list = module->CompuVtabRanges(); //EXPECT_GT(compu_vtab_range_list.size(), 0); std::cout << "\t\tCOMPU VTAB RANGE" << std::endl; for (const auto& [range_name, range] : compu_vtab_range_list) { std::cout << range_name << " " << range->Description() << std::endl; } std::cout << std::endl; const auto& frame_list = module->Frames(); // EXPECT_GT(frame_list.size(), 0); No frames in file std::cout << "\t\tFRAME" << std::endl; for (const auto& [frame_name, frame] : frame_list) { std::cout << frame_name << " " << frame->Description() << std::endl; } std::cout << std::endl; const auto& func_list = module->Functions(); //EXPECT_GT(func_list.size(), 0); std::cout << "\t\tFUNCTION" << std::endl; for (const auto& [func_name, func] : func_list) { std::cout << func_name << " " << func->Description() << std::endl; } std::cout << std::endl; const auto& group_list = module->Groups(); //EXPECT_GT(group_list.size(), 0); std::cout << "\t\tGROUP" << std::endl; for (const auto& [group_name, group] : group_list) { std::cout << group_name << " " << group->Description() << std::endl; } std::cout << std::endl; const auto& instance_list = module->Instances(); //EXPECT_GT(instance_list.size(), 0); std::cout << "\t\tINSTANCE" << std::endl; for (const auto& [instance_name, instance] : instance_list) { std::cout << instance_name << " " << instance->Description() << std::endl; } std::cout << std::endl; AddLogString(""); const auto& meas_list = module->Measurements(); //EXPECT_GT(meas_list.size(), 0); std::cout << "\t\tMEASUREMENT" << std::endl; AddLogString(string_format("measurement : %d", meas_list.size())); i = 0; for (const auto& [meas_name, meas] : meas_list) { std::cout << meas_name << " " << meas->Description() << std::endl; AddLogString(string_format(" %d : %s", i, meas->Description().c_str())); } std::cout << std::endl; AddLogString(""); const auto& rec_list = module->RecordLayouts(); //EXPECT_GT(rec_list.size(), 0); std::cout << "\t\tRECORD LAYOUT" << std::endl; for (const auto& [rec_name, rec] : rec_list) { std::cout << rec_name << std::endl; } std::cout << std::endl; const auto& trans_list = module->Transformers(); //EXPECT_GT(trans_list.size(), 0); std::cout << "\t\tTRANSFORMER" << std::endl; for (const auto& [trans_name, trans] : trans_list) { std::cout << trans_name << std::endl; } std::cout << std::endl; const auto& taxis_list = module->TypedefAxiss(); //EXPECT_GT(taxis_list.size(), 0); std::cout << "\t\tTYPEDEF AXIS" << std::endl; for (const auto& [taxis_name, taxis] : taxis_list) { std::cout << taxis_name << std::endl; } std::cout << std::endl; const auto& tblob_list = module->TypedefBlobs(); //EXPECT_GT(tblob_list.size(), 0); std::cout << "\t\tTYPEDEF BLOB" << std::endl; for (const auto& [tblob_name, tblob] : tblob_list) { std::cout << tblob_name << std::endl; } std::cout << std::endl; const auto& tchar_list = module->TypedefCharacteristics(); //EXPECT_GT(tchar_list.size(), 0); std::cout << "\t\tTYPEDEF CHARACTERISTIC" << std::endl; for (const auto& [tchar_name, tchar] : tchar_list) { std::cout << tchar_name << std::endl; } std::cout << std::endl; const auto& tmeas_list = module->TypedefMeasurements(); //EXPECT_GT(tmeas_list.size(), 0); std::cout << "\t\tTYPEDEF MEASUREMENT" << std::endl; for (const auto& [tmeas_name, tmeas] : tmeas_list) { std::cout << tmeas_name << std::endl; } std::cout << std::endl; const auto& tstruct_list = module->TypedefStructures(); //EXPECT_GT(tstruct_list.size(), 0); std::cout << "\t\tTYPEDEF STRUCTURE" << std::endl; for (const auto& [tstruct_name, tstruct] : tstruct_list) { std::cout << tstruct_name << std::endl; } std::cout << std::endl; std::cout << std::endl; const auto& unit_list = module->Units(); //EXPECT_GT(unit_list.size(), 0); std::cout << "\t\tUNIT" << std::endl; for (const auto& [unit_name, unit] : unit_list) { std::cout << unit_name << std::endl; } std::cout << std::endl; a2l::A2mlBlock a2ml_block(module->A2ml()); const auto& a2ml = module->A2ml(); const auto a2ml_parse = a2ml_block.IsOk(); //EXPECT_TRUE(a2ml_parse) << a2ml_block.LastError(); /* const auto& block_list = a2ml_scanner.BlockList(); for (const auto& block : block_list) { std::cout << block.AsString() << std::endl; } */ } } void CIncSourceTestDlgDlg::AddLogString(std::string strMessage) { CListBox* pListBox = (CListBox*)GetDlgItem(IDC_LIST_DATA); std::wstring message_w; message_w.assign(strMessage.begin(), strMessage.end()); pListBox->AddString(message_w.c_str()); }