1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013, 2014 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #include <QApplication> |
|
20 #include <QMessageBox> |
|
21 #include <QAbstractButton> |
|
22 #include <QFile> |
|
23 #include <QTextStream> |
|
24 #include <QDir> |
|
25 #include "gui.h" |
|
26 #include "document.h" |
|
27 #include "misc.h" |
|
28 #include "config.h" |
|
29 #include "colors.h" |
|
30 #include "types.h" |
|
31 #include "primitives.h" |
|
32 #include "gldraw.h" |
|
33 #include "configDialog.h" |
|
34 #include "dialogs.h" |
|
35 #include "crashcatcher.h" |
|
36 |
|
37 QList<LDDocument*> g_loadedFiles; |
|
38 ForgeWindow* g_win = null; |
|
39 static QString g_versionString, g_fullVersionString; |
|
40 |
|
41 const Vertex g_origin (0.0f, 0.0f, 0.0f); |
|
42 const Matrix g_identity ({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); |
|
43 |
|
44 cfg (Bool, firststart, true); |
|
45 |
|
46 // ============================================================================= |
|
47 // ----------------------------------------------------------------------------- |
|
48 int main (int argc, char* argv[]) |
|
49 { |
|
50 QApplication app (argc, argv); |
|
51 app.setOrganizationName (APPNAME); |
|
52 app.setApplicationName (APPNAME); |
|
53 initCrashCatcher(); |
|
54 LDDocument::setCurrent (null); |
|
55 |
|
56 // Load or create the configuration |
|
57 if (!Config::load()) |
|
58 { |
|
59 log ("Creating configuration file...\n"); |
|
60 |
|
61 if (Config::save()) |
|
62 log ("Configuration file successfully created.\n"); |
|
63 else |
|
64 log ("failed to create configuration file!\n"); |
|
65 } |
|
66 |
|
67 LDPaths::initPaths(); |
|
68 initColors(); |
|
69 ForgeWindow* win = new ForgeWindow; |
|
70 newFile(); |
|
71 win->show(); |
|
72 |
|
73 // If this is the first start, get the user to configuration. Especially point |
|
74 // them to the profile tab, it's the most important form to fill in. |
|
75 if (firststart) |
|
76 { |
|
77 (new ConfigDialog (ConfigDialog::ProfileTab))->exec(); |
|
78 firststart = false; |
|
79 Config::save(); |
|
80 } |
|
81 |
|
82 loadPrimitives(); |
|
83 return app.exec(); |
|
84 } |
|
85 |
|
86 // ============================================================================= |
|
87 // ----------------------------------------------------------------------------- |
|
88 void doPrint (QFile& f, QList<StringFormatArg> args) |
|
89 { |
|
90 QString msg = DoFormat (args); |
|
91 f.write (msg.toUtf8()); |
|
92 f.flush(); |
|
93 } |
|
94 |
|
95 // ============================================================================= |
|
96 // ----------------------------------------------------------------------------- |
|
97 void doPrint (FILE* fp, QList<StringFormatArg> args) |
|
98 { |
|
99 QString msg = DoFormat (args); |
|
100 fwrite (msg.toStdString().c_str(), 1, msg.length(), fp); |
|
101 fflush (fp); |
|
102 } |
|
103 |
|
104 // ============================================================================= |
|
105 // ----------------------------------------------------------------------------- |
|
106 QString versionString() |
|
107 { |
|
108 if (g_versionString.length() == 0) |
|
109 { |
|
110 #if VERSION_PATCH == 0 |
|
111 g_versionString = fmt ("%1.%2", VERSION_MAJOR, VERSION_MINOR); |
|
112 #else |
|
113 g_versionString = fmt ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); |
|
114 #endif // VERSION_PATCH |
|
115 } |
|
116 |
|
117 return g_versionString; |
|
118 } |
|
119 |
|
120 // ============================================================================= |
|
121 // ----------------------------------------------------------------------------- |
|
122 QString fullVersionString() |
|
123 { |
|
124 #if BUILD_ID != BUILD_RELEASE && defined (GIT_DESCRIBE) |
|
125 return GIT_DESCRIBE; |
|
126 #else |
|
127 return "v" + versionString(); |
|
128 #endif |
|
129 } |
|