src/main.cc

changeset 557
04e140bdeb0b
child 564
79b23e02dcf1
equal deleted inserted replaced
556:5f4395ec5db0 557:04e140bdeb0b
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 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 "gui.h"
25 #include "document.h"
26 #include "misc.h"
27 #include "config.h"
28 #include "colors.h"
29 #include "types.h"
30 #include "primitives.h"
31 #include "gldraw.h"
32 #include "configDialog.h"
33 #include "dialogs.h"
34 #include "crashcatcher.h"
35
36 QList<LDDocument*> g_loadedFiles;
37 ForgeWindow* g_win = null;
38 const QApplication* g_app = null;
39 File g_file_stdout (stdout, File::Write);
40 File g_file_stderr (stderr, File::Write);
41 static str g_versionString, g_fullVersionString;
42
43 const vertex g_origin (0.0f, 0.0f, 0.0f);
44 const matrix g_identity ( {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
45
46 cfg (Bool, firststart, true);
47
48 // =============================================================================
49 // -----------------------------------------------------------------------------
50 int main (int argc, char* argv[])
51 { QApplication app (argc, argv);
52 app.setOrganizationName (APPNAME);
53 app.setApplicationName (APPNAME);
54 g_app = &app;
55
56 initCrashCatcher();
57 LDDocument::setCurrent (null);
58
59 // Load or create the configuration
60 if (!Config::load())
61 { log ("Creating configuration file...\n");
62
63 if (Config::save())
64 log ("Configuration file successfully created.\n");
65 else
66 log ("failed to create configuration file!\n");
67 }
68
69 LDPaths::initPaths();
70 initColors();
71 loadLogoedStuds();
72
73 ForgeWindow* win = new ForgeWindow;
74 newFile();
75 win->show();
76
77 // If this is the first start, get the user to configuration. Especially point
78 // them to the profile tab, it's the most important form to fill in.
79 if (firststart)
80 { (new ConfigDialog (ConfigDialog::ProfileTab))->exec();
81 firststart = false;
82 Config::save();
83 }
84
85 loadPrimitives();
86 return app.exec();
87 }
88
89 // =============================================================================
90 // -----------------------------------------------------------------------------
91 void doPrint (File& f, initlist<StringFormatArg> args)
92 { str msg = DoFormat (args);
93 f.write (msg.toUtf8());
94 f.flush();
95 }
96
97 // =============================================================================
98 // -----------------------------------------------------------------------------
99 void doPrint (FILE* fp, initlist<StringFormatArg> args)
100 { str msg = DoFormat (args);
101 fwrite (msg.toStdString().c_str(), 1, msg.length(), fp);
102 fflush (fp);
103 }
104
105 // =============================================================================
106 // -----------------------------------------------------------------------------
107 QString versionString()
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 versionMoniker()
123 {
124 #if BUILD_ID == BUILD_INTERNAL
125 return "Internal";
126 #elif BUILD_ID == BUILD_ALPHA
127 return "Alpha";
128 #elif BUILD_ID == BUILD_BETA
129 return "Beta";
130 #elif BUILD_ID == BUILD_RC
131 return fmt ("RC %1", RC_NUMBER);
132 #else
133 return "";
134 #endif // BUILD_ID
135 }
136
137 // =============================================================================
138 // -----------------------------------------------------------------------------
139 QString fullVersionString()
140 { return fmt ("v%1 %2", versionString(), versionMoniker());
141 }

mercurial