PageRenderTime 78ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/Sources/TOOLS_EXTERNAL/EXT_DBF_2_DBC/CANDBConverterDlg.cpp

https://github.com/nowaydoso/busmaster
C++ | 461 lines | 217 code | 57 blank | 187 comment | 26 complexity | 7ea702bc3c717a0e4a89743e0cab7bed MD5 | raw file
  1. /*
  2. * This program is free software: you can redistribute it and/or modify
  3. * it under the terms of the GNU Lesser General Public License as published by
  4. * the Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Lesser General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Lesser General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * \file CANDBConverterDlg.cpp
  17. * \brief Implementation file for the CAboutDlg class.
  18. * \author RBIN/EBS1 - Padmaja A
  19. * \copyright Copyright (c) 2011, Robert Bosch Engineering and Business Solutions. All rights reserved.
  20. *
  21. * Implementation file for the CAboutDlg class.
  22. */
  23. /**
  24. * \file CANDBConverterDlg.cpp
  25. * \brief Implementation file for the CCANDBConverterDlg class.
  26. * \authors RBIN/EBS1 - Mahesh B S
  27. * \date 17.11.2004 Created
  28. * \copyright Copyright &copy; 2011, Robert Bosch Engineering and Business Solutions. All rights reserved.
  29. */
  30. #include "stdafx.h"
  31. #include "CANDBConverter.h"
  32. #include "CANDBConverterDlg.h"
  33. #include "Converter.h"
  34. #ifdef _DEBUG
  35. #define new DEBUG_NEW
  36. #undef THIS_FILE
  37. static char THIS_FILE[] = __FILE__;
  38. #endif
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CAboutDlg dialog used for App About
  41. class CAboutDlg : public CDialog
  42. {
  43. public:
  44. CAboutDlg();
  45. // Dialog Data
  46. //{{AFX_DATA(CAboutDlg)
  47. enum { IDD = IDD_ABOUTBOX };
  48. //}}AFX_DATA
  49. // ClassWizard generated virtual function overrides
  50. //{{AFX_VIRTUAL(CAboutDlg)
  51. protected:
  52. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  53. //}}AFX_VIRTUAL
  54. // Implementation
  55. protected:
  56. //{{AFX_MSG(CAboutDlg)
  57. virtual BOOL OnInitDialog();
  58. //}}AFX_MSG
  59. DECLARE_MESSAGE_MAP()
  60. };
  61. /**
  62. * \brief CAboutDlg constructor
  63. * \param[in] None
  64. * \param[out] None
  65. * \return None
  66. * \authors
  67. * \date
  68. */
  69. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  70. {
  71. //{{AFX_DATA_INIT(CAboutDlg)
  72. //}}AFX_DATA_INIT
  73. }
  74. /**
  75. * \brief DoDataExchange Function
  76. * \param[in] CDataExchange*
  77. * \param[out] None
  78. * \return void
  79. * \authors
  80. * \date
  81. */
  82. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  83. {
  84. CDialog::DoDataExchange(pDX);
  85. //{{AFX_DATA_MAP(CAboutDlg)
  86. //}}AFX_DATA_MAP
  87. }
  88. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  89. //{{AFX_MSG_MAP(CAboutDlg)
  90. //}}AFX_MSG_MAP
  91. END_MESSAGE_MAP()
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CCANDBConverterDlg dialog
  94. /**
  95. * \brief CCANDBConverterDlg Constructor
  96. * \param[in] CDataExchange*
  97. * \param[out] None
  98. * \return void
  99. * \authors
  100. * \date
  101. */
  102. CCANDBConverterDlg::CCANDBConverterDlg(CWnd* pParent /*=NULL*/)
  103. : CDialog(CCANDBConverterDlg::IDD, pParent)
  104. {
  105. //{{AFX_DATA_INIT(CCANDBConverterDlg)
  106. // NOTE: the ClassWizard will add member initialization here
  107. //}}AFX_DATA_INIT
  108. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  109. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  110. }
  111. /**
  112. * \brief DoDataExchange Function
  113. * \param[in] CDataExchange*
  114. * \param[out] None
  115. * \return void
  116. * \authors
  117. * \date
  118. */
  119. void CCANDBConverterDlg::DoDataExchange(CDataExchange* pDX)
  120. {
  121. CDialog::DoDataExchange(pDX);
  122. //{{AFX_DATA_MAP(CCANDBConverterDlg)
  123. // NOTE: the ClassWizard will add DDX and DDV calls here
  124. //}}AFX_DATA_MAP
  125. }
  126. BEGIN_MESSAGE_MAP(CCANDBConverterDlg, CDialog)
  127. //{{AFX_MSG_MAP(CCANDBConverterDlg)
  128. ON_WM_SYSCOMMAND()
  129. ON_WM_PAINT()
  130. ON_WM_QUERYDRAGICON()
  131. ON_BN_CLICKED(IDC_CANOE_BROWSE_BTN, OnCanoeBrowseBtn)
  132. ON_BN_CLICKED(IDC_CANMON_BROWSE_BTN, OnCanmonBrowseBtn)
  133. ON_BN_CLICKED(IDC_CONVERT_BTN, OnConvertBtn)
  134. //}}AFX_MSG_MAP
  135. END_MESSAGE_MAP()
  136. /////////////////////////////////////////////////////////////////////////////
  137. // CCANDBConverterDlg message handlers
  138. /**
  139. * \brief OnInitDialog Function, Called once when the dialog box is created
  140. * \param[in] None
  141. * \param[out] None
  142. * \return BOOL, TRUE if dialog has to create otherwise FALSE
  143. * \authors
  144. * \date
  145. */
  146. BOOL CCANDBConverterDlg::OnInitDialog()
  147. {
  148. CDialog::OnInitDialog();
  149. // Add "About..." menu item to system menu.
  150. // IDM_ABOUTBOX must be in the system command range.
  151. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  152. ASSERT(IDM_ABOUTBOX < 0xF000);
  153. CMenu* pSysMenu = GetSystemMenu(FALSE);
  154. if (pSysMenu != NULL)
  155. {
  156. CString strAboutMenu;
  157. strAboutMenu.LoadString(IDS_ABOUTBOX);
  158. if (!strAboutMenu.IsEmpty())
  159. {
  160. pSysMenu->AppendMenu(MF_SEPARATOR);
  161. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  162. }
  163. }
  164. // Set the icon for this dialog. The framework does this automatically
  165. // when the application's main window is not a dialog
  166. SetIcon(m_hIcon, TRUE); // Set big icon
  167. SetIcon(m_hIcon, FALSE); // Set small icon
  168. // TODO: Add extra initialization here
  169. SetDlgItemText(IDC_RESULT_STATIC,"Choose files for conversion");
  170. return TRUE; // return TRUE unless you set the focus to a control
  171. }
  172. /**
  173. * \brief OnSysCommand Function used to handle the ON_WM_SYSCOMMAND
  174. * \param[in] UINT, ID of the command
  175. LPARAM, lparam of the message
  176. * \param[out] None
  177. * \return void
  178. * \authors
  179. * \date
  180. */
  181. void CCANDBConverterDlg::OnSysCommand(UINT nID, LPARAM lParam)
  182. {
  183. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  184. {
  185. CAboutDlg dlgAbout;
  186. dlgAbout.DoModal();
  187. }
  188. else
  189. {
  190. CDialog::OnSysCommand(nID, lParam);
  191. }
  192. }
  193. // If you add a minimize button to your dialog, you will need the code below
  194. // to draw the icon. For MFC applications using the document/view model,
  195. // this is automatically done for you by the framework.
  196. /**
  197. * \brief OnPaint Message to handle WM_PAINT message
  198. * \param[in] void
  199. * \param[out]
  200. * \return void
  201. * \authors
  202. * \date
  203. */
  204. void CCANDBConverterDlg::OnPaint()
  205. {
  206. if (IsIconic())
  207. {
  208. CPaintDC dc(this); // device context for painting
  209. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  210. // Center icon in client rectangle
  211. int cxIcon = GetSystemMetrics(SM_CXICON);
  212. int cyIcon = GetSystemMetrics(SM_CYICON);
  213. CRect rect;
  214. GetClientRect(&rect);
  215. int x = (rect.Width() - cxIcon + 1) / 2;
  216. int y = (rect.Height() - cyIcon + 1) / 2;
  217. // Draw the icon
  218. dc.DrawIcon(x, y, m_hIcon);
  219. }
  220. else
  221. {
  222. CDialog::OnPaint();
  223. }
  224. }
  225. // The system calls this to obtain the cursor to display while the user drags
  226. // the minimized window.
  227. /**
  228. * \brief OnQueryDragIcon to return the icon of the Dialog
  229. * \param[in] None
  230. * \param[out] None
  231. * \return HCURSOR
  232. * \authors
  233. * \date
  234. */
  235. HCURSOR CCANDBConverterDlg::OnQueryDragIcon()
  236. {
  237. return (HCURSOR) m_hIcon;
  238. }
  239. /**
  240. * \brief OnCanoeBrowseBtn is the Handler of ON_BN_CLICKED message for IDC_CANOE_BROWSE_BTN
  241. * \param[in] None
  242. * \param[out] None
  243. * \return void
  244. * \authors
  245. * \date
  246. */
  247. void CCANDBConverterDlg::OnCanoeBrowseBtn()
  248. {
  249. // Create a file open dlg to select the output file
  250. CFileDialog fileDlg(FALSE,"dbc",NULL,OFN_OVERWRITEPROMPT,"Output Database Files(*.dbc)|*.dbc||",this);
  251. fileDlg.m_ofn.lpstrTitle = "Select output database file"; // set the title of dlg
  252. // if OK clicked, display the path name in the edit box
  253. if(fileDlg.DoModal() == IDOK)
  254. {
  255. SetDlgItemText(IDC_CANOE_EDIT,fileDlg.GetPathName());
  256. }
  257. else // if cancelled, clear the edit box
  258. {
  259. SetDlgItemText(IDC_CANOE_EDIT,"");
  260. }
  261. }
  262. /**
  263. * \brief OnCanmonBrowseBtn is the Handler of ON_BN_CLICKED message for IDC_CANMON_BROWSE_BTN
  264. * \param[in] None
  265. * \param[out] None
  266. * \return void
  267. * \authors
  268. * \date
  269. */
  270. void CCANDBConverterDlg::OnCanmonBrowseBtn()
  271. {
  272. // Create a file save dialog box to select the input file
  273. CFileDialog fileDlg(TRUE,"dbf",NULL,OFN_OVERWRITEPROMPT|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST,"Input Database Files(*.dbf)|*.dbf||",this);
  274. fileDlg.m_ofn.lpstrTitle = "Select input database file"; // set the title
  275. // if OK clicked, set the path name of input file in the edit box and enable the convert
  276. // button
  277. if(fileDlg.DoModal() == IDOK)
  278. {
  279. SetDlgItemText(IDC_CANMON_EDIT,fileDlg.GetPathName());
  280. SetDlgItemText(IDC_CANOE_EDIT,"");
  281. GetDlgItem(IDC_CONVERT_BTN)->EnableWindow(TRUE);
  282. SetDlgItemText(IDC_RESULT_STATIC,"Ready for conversion");
  283. }
  284. else // else clear the edit box and disable the convert button
  285. {
  286. SetDlgItemText(IDC_CANMON_EDIT,"");
  287. GetDlgItem(IDC_CONVERT_BTN)->EnableWindow(FALSE);
  288. SetDlgItemText(IDC_RESULT_STATIC,"Choose files for conversion");
  289. }
  290. }
  291. /**
  292. * \brief OnCanmonBrowseBtn is the Handler of ON_BN_CLICKED message for IDC_CONVERT_BTN.
  293. This function converts the CANoe Database to BUSMASTER Database
  294. * \param[in] None
  295. * \param[out] None
  296. * \return void
  297. * \authors
  298. * \date
  299. */
  300. void CCANDBConverterDlg::OnConvertBtn()
  301. {
  302. CString sCanoeFilePath,sCanMonFilePath;
  303. CString sExtension;
  304. // Get the input path name from the dialog box
  305. GetDlgItemText(IDC_CANMON_EDIT,sCanMonFilePath);
  306. sExtension = sCanMonFilePath.Right(3);
  307. sExtension.MakeLower();
  308. // validate extension, if invalid clear the edit box
  309. // and disable the convert button
  310. if(sExtension != "dbf")
  311. {
  312. AfxMessageBox("Invalid input file");
  313. SetDlgItemText(IDC_CANMON_EDIT,"");
  314. GetDlgItem(IDC_CONVERT_BTN)->EnableWindow(FALSE);
  315. return;
  316. }
  317. // Get output file path name
  318. GetDlgItemText(IDC_CANOE_EDIT,sCanoeFilePath);
  319. // if no output file selected, prompt user whether a default file should
  320. // be created
  321. if(sCanoeFilePath == "")
  322. {
  323. if(AfxMessageBox("No output file selected.\nDo you want a default file created?",MB_YESNO) == IDYES)
  324. {
  325. sCanoeFilePath = sCanMonFilePath.Left(sCanMonFilePath.GetLength()-4);
  326. sCanoeFilePath += ".dbc";
  327. SetDlgItemText(IDC_CANOE_EDIT,sCanoeFilePath);
  328. }
  329. else
  330. {
  331. return;
  332. }
  333. }
  334. // if non-null path selected for output file
  335. // validate extension,if invalid clear the edit box
  336. else
  337. {
  338. sExtension = sCanoeFilePath.Right(3);
  339. sExtension.MakeLower();
  340. if(sExtension != "dbc")
  341. {
  342. AfxMessageBox("Invalid ouput file");
  343. SetDlgItemText(IDC_CANOE_EDIT,"");
  344. }
  345. }
  346. // create a converter module and pass the file names to the conversion module
  347. CConverter *pConverter = new CConverter;
  348. if(pConverter == NULL)
  349. {
  350. AfxMessageBox("Error: Insufficient memory");
  351. return;
  352. }
  353. else
  354. {
  355. INT nRetVal = pConverter->Convert(sCanMonFilePath,sCanoeFilePath);
  356. // display final result
  357. SetDlgItemText(IDC_RESULT_STATIC, pConverter->GetResultString());
  358. if(nRetVal != 0)
  359. {
  360. SetDlgItemText(IDC_EDIT_LOGPATH, pConverter->m_omLogFilePath);
  361. }
  362. delete pConverter;
  363. }
  364. }
  365. /**
  366. * \brief OnInitDialog Function, Called once when the CAboutDlg dialog box is created
  367. * \param[in] None
  368. * \param[out]
  369. * \return BOOL, TRUE if dialog has to create otherwise FALSE
  370. * \authors
  371. * \date
  372. */
  373. BOOL CAboutDlg::OnInitDialog()
  374. {
  375. CDialog::OnInitDialog();
  376. // TODO: Add extra initialization here
  377. CString sVer,sCopyright;
  378. TCHAR sPath[MAX_PATH];
  379. DWORD dwVerInfoSize;
  380. DWORD dwHandle;
  381. LPVOID pVerInfo = NULL;
  382. LPTSTR pCopyright;
  383. LPTSTR pCompanyName;
  384. LPTSTR pProductName;
  385. LPTSTR pProductVer;
  386. UINT uLen;
  387. ::GetModuleFileName(NULL,sPath,MAX_PATH);
  388. dwVerInfoSize = ::GetFileVersionInfoSize(sPath,&dwHandle);
  389. pVerInfo = (LPVOID) new BYTE[dwVerInfoSize];
  390. ::GetFileVersionInfo(sPath,dwHandle,dwVerInfoSize,pVerInfo);
  391. // language code page = US English
  392. VerQueryValue(pVerInfo,_T("\\StringFileInfo\\040904b0\\LegalCopyright"),(LPVOID*)&pCopyright,&uLen);
  393. VerQueryValue(pVerInfo,_T("\\StringFileInfo\\040904b0\\CompanyName"),(LPVOID*)&pCompanyName,&uLen);
  394. VerQueryValue(pVerInfo,_T("\\StringFileInfo\\040904b0\\ProductName"),(LPVOID*)&pProductName,&uLen);
  395. VerQueryValue(pVerInfo,_T("\\StringFileInfo\\040904b0\\ProductVersion"),(LPVOID*)&pProductVer,&uLen);
  396. sVer.Format("%s %s",pProductName,pProductVer);
  397. sCopyright.Format("%s\n%s",pCopyright,pCompanyName);
  398. delete pVerInfo;
  399. pVerInfo = NULL;
  400. SetDlgItemText(IDC_VERSION_STATIC,sVer);
  401. SetDlgItemText(IDC_COPYRIGHT_STATIC,sCopyright);
  402. return TRUE; // return TRUE unless you set the focus to a control
  403. // EXCEPTION: OCX Property Pages should return FALSE
  404. }