source: trunk/tmdmcreator/src/main.cpp @ 40

Revision 21, 4.3 KB checked in by lucsch, 11 years ago (diff)
  • TmDmCreator is now working (supports language selection)
  • Adding swisstopo data model definition
Line 
1/***************************************************************************
2 TmDmCreator
3 Create SQL code for ToolMap project
4 -------------------
5 copyright            : (C) 2013 CREALP Lucien Schreiber
6 email                : lucien.schreiber at crealp dot vs dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 *                                                                         *
11 *   This program is free software; you can redistribute it and/or modify  *
12 *   it under the terms of the GNU General Public License as published by  *
13 *   the Free Software Foundation; either version 2 of the License, or     *
14 *   (at your option) any later version.                                   *
15 *                                                                         *
16 ***************************************************************************/
17#include "wx/wxprec.h"
18#ifdef __BORLANDC__
19#pragma hdrstop
20#endif
21#ifndef WX_PRECOMP
22#include "wx/wx.h"
23#endif
24
25#include <wx/app.h>
26#include <wx/cmdline.h>
27#include <wx/dir.h>
28#include <wx/filename.h>
29#include "tmdmcreator.h"
30
31
32static const wxCmdLineEntryDesc cmdLineDesc[] =
33{
34    { wxCMD_LINE_SWITCH, "h", "help", "show this help message",
35        wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
36    { wxCMD_LINE_SWITCH, "v", "verbose", "Be more verbose" },
37    { wxCMD_LINE_SWITCH, "t", "toolmap", "toolmap output (default is SQL)" },
38    { wxCMD_LINE_SWITCH, "o", "overwrite", "overwrite output" },
39    { wxCMD_LINE_OPTION, "l", "language", "language column (default is 0)", wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL},
40    { wxCMD_LINE_PARAM, NULL, NULL, "[base structure sql file]"},
41    { wxCMD_LINE_PARAM, NULL, NULL, "[user structure sql file]"},
42    { wxCMD_LINE_PARAM, NULL, NULL, "[user content txt file]"},
43    { wxCMD_LINE_PARAM, NULL, NULL, "[result file]"},
44    { wxCMD_LINE_NONE }
45};
46
47
48
49void PrintArray(const wxArrayString & array, const wxString & msg = wxEmptyString){
50    if (msg != wxEmptyString) {
51        wxPrintf(msg + _T("\n"));
52    }
53    for (unsigned int i = 0; i< array.GetCount(); i++) {
54        wxPrintf(array[i] + _T("\n"));
55    }
56}
57
58
59
60int main(int argc, char **argv){
61    // debugging string for OSX
62    // this is needed for viewing string content with Xcode !!
63    wxString myTest = _T("Test debugging");
64    myTest.ToUTF8().data();
65    myTest.Len();
66   
67    wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
68    wxInitializer initializer;
69    if ( !initializer ){
70        fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
71        return -1;
72    }
73   
74    wxString myLogoTxt = _T("*\n* TmDmCreator \n* Create SQL file for ToolMap projects \n* (c) Copyright 2013 Lucien Schreiber - CREALP . All Rights Reserved. \n*\n");
75    wxCmdLineParser parser(cmdLineDesc, argc, argv);
76    parser.SetLogo(myLogoTxt);
77    if (parser.Parse() != 0) {
78        return 0;
79    }
80   
81    // cmd line is correct !!
82    wxPrintf(myLogoTxt);
83   
84    bool bVerbose = parser.Found("verbose");
85    bool bToolMap = parser.Found("toolmap");
86    long myLanguage = 0;
87    if(parser.Found("language", &myLanguage) == true) {
88        wxPrintf(_("Using language column: %ld\n"), myLanguage);
89    }
90    if (parser.Found("overwrite") && wxFileExists(parser.GetParam(3))) {
91        wxRemoveFile(parser.GetParam(3));
92    }
93   
94    if (bToolMap == true) {
95        wxPrintf(_("Exporting to ToolMap project not supported for now!\n"));
96        return 0;
97    }
98   
99    wxASSERT(parser.GetParamCount() == 4);
100    TmDmCreator myCreator;
101    myCreator.SetBaseSQL(wxFileName(parser.GetParam(0)));
102    myCreator.SetUserSQL(wxFileName(parser.GetParam(1)));
103    myCreator.SetUserContent(wxFileName(parser.GetParam(2)));
104    myCreator.SetOutSQL(wxFileName(parser.GetParam(3)));
105   
106    wxArrayString myErrors;
107    if (myCreator.CheckFiles(myErrors) == false) {
108        if (bVerbose == true) {
109            PrintArray(myErrors);
110        }
111        wxPrintf(_("Error while checking files, aborting!\n"));
112        return 0;
113    }
114   
115    if (myCreator.ProcessFiles(myErrors, myLanguage) == false) {
116        if (bVerbose == true) {
117            PrintArray(myErrors);
118        }
119        wxPrintf(_("Error processing files, aborting\n"));
120        return 0;
121    }
122   
123    wxPrintf(_("Processing succeed!\n"));
124    return 0;
125}
Note: See TracBrowser for help on using the repository browser.