src/main.cc

Sat, 22 Aug 2015 13:04:58 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 22 Aug 2015 13:04:58 +0300
branch
scripting
changeset 942
afbd122f3eff
parent 923
e15a577a0bfe
permissions
-rw-r--r--

Commit work on scripting

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
844
11587d419d2f - changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents: 790
diff changeset
3 * Copyright (C) 2013, 2014 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include <QApplication>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <QMessageBox>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <QAbstractButton>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QFile>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QTextStream>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QDir>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "mainWindow.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "ldDocument.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "miscallenous.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "configuration.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "colors.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "basics.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "primitives.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "glRenderer.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "configDialog.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "dialogs.h"
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 #include "crashCatcher.h"
922
81887a77baa0 - more work on scripting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
36 #include "script/parser.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 MainWindow* g_win = null;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 784
diff changeset
39 static QString g_versionString, g_fullVersionString;
857
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
40 static bool g_IsExiting (false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
42 const Vertex Origin (0.0f, 0.0f, 0.0f);
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
43 const Matrix IdentityMatrix ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44
852
cbd89b33f70d - down with all these unnecessary semicolons!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 850
diff changeset
45 CFGENTRY (Bool, FirstStart, true)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 //
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 int main (int argc, char* argv[])
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 {
923
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
51 QFile fp ("script.txt");
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
52 if (fp.open (QIODevice::ReadOnly))
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
53 {
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
54 Script::Parser parser (QString::fromLocal8Bit (fp.readAll()));
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
55 try
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
56 {
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
57 parser.parse();
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
58 QFile fp2 ("script.out.txt");
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
59
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
60 if (fp2.open (QIODevice::WriteOnly))
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
61 {
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
62 fp2.write (parser.preprocessedScript().toLocal8Bit(),
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
63 parser.preprocessedScript().length());
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
64 }
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
65 }
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
66 catch (Script::ParseError e)
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
67 {
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
68 print ("error: %1: %2\n", parser.state().lineNumber, e.message());
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
69 }
e15a577a0bfe - now parses to tokens
Teemu Piippo <crimsondusk64@gmail.com>
parents: 922
diff changeset
70 }
922
81887a77baa0 - more work on scripting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
71 return 0;
81887a77baa0 - more work on scripting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
72
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 QApplication app (argc, argv);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 app.setOrganizationName (APPNAME);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 app.setApplicationName (APPNAME);
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 845
diff changeset
76 InitCrashCatcher();
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 845
diff changeset
77 Config::Initialize();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 // Load or create the configuration
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 845
diff changeset
80 if (not Config::Load())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 print ("Creating configuration file...\n");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 845
diff changeset
84 if (Config::Save())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 print ("Configuration file successfully created.\n");
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 else
882
2f3cc8e045d5 - fixed compilation on windows
Teemu Piippo <crimsondusk64@gmail.com>
parents: 864
diff changeset
87 Critical ("Failed to create configuration file!\n");
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 LDPaths::initPaths();
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
91 InitColors();
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
92 LoadPrimitives();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 MainWindow* win = new MainWindow;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 newFile();
769
8bb3bed44570 - improved shared pointer behavior, still not there yet
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
95 win->show();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 // If this is the first start, get the user to configuration. Especially point
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 // them to the profile tab, it's the most important form to fill in.
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
99 if (cfg::FirstStart)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 (new ConfigDialog (ConfigDialog::ProfileTab))->exec();
850
a3d72b0e916d - changed configuration entry name from minuscule camelCase to majuscule CamelCase. reasoning for this being that these variables are globals.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 848
diff changeset
102 cfg::FirstStart = false;
848
68410477c8bb - refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 845
diff changeset
103 Config::Save();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105
864
34033bc2ffb6 - ldforge can now open files from command-line input
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
106 // Process the command line
34033bc2ffb6 - ldforge can now open files from command-line input
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
107 for (int arg = 1; arg < argc; ++arg)
34033bc2ffb6 - ldforge can now open files from command-line input
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
108 OpenMainModel (QString::fromLocal8Bit (argv[arg]));
34033bc2ffb6 - ldforge can now open files from command-line input
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
109
857
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
110 int result = app.exec();
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
111 g_IsExiting = true;
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
112 return result;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 }
857
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
114
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
115 bool IsExiting()
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
116 {
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
117 return g_IsExiting;
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
118 }
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
119
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
120 void Exit()
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
121 {
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
122 g_IsExiting = true;
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
123 exit (EXIT_SUCCESS);
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
124 }

mercurial