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 // ============================================================================= |
|
20 // This file is included one way or another in every source file of LDForge. |
|
21 // Stuff defined and included here is universally included. |
|
22 |
|
23 #ifndef COMMON_H |
|
24 #define COMMON_H |
|
25 |
|
26 #include <stdio.h> |
|
27 #include <stdlib.h> |
|
28 #include <assert.h> |
|
29 #include <vector> |
|
30 #include <stdint.h> |
|
31 #include <stdarg.h> |
|
32 #include "str.h" |
|
33 #include "config.h" |
|
34 #include "types.h" |
|
35 |
|
36 #define APPNAME "LDForge" |
|
37 |
|
38 #define VERSION_MAJOR 0 |
|
39 #define VERSION_MAJOR_STR "0" |
|
40 #define VERSION_MINOR 1 |
|
41 #define VERSION_MINOR_STR "1" |
|
42 |
|
43 // ============--- |
|
44 // #define RELEASE |
|
45 |
|
46 // Version string identifier |
|
47 static const str versionString = fmt ("%d.%d", VERSION_MAJOR, VERSION_MINOR); |
|
48 |
|
49 #ifdef __GNUC__ |
|
50 # define FORMAT_PRINTF(M,N) __attribute__ ((format (printf, M, N))) |
|
51 # define ATTR(N) __attribute__ ((N)) |
|
52 #else |
|
53 # define FORMAT_PRINTF(M,N) |
|
54 # define ATTR(N) |
|
55 #endif // __GNUC__ |
|
56 |
|
57 #ifdef WIN32 |
|
58 #define DIRSLASH "\\" |
|
59 #else // WIN32 |
|
60 #define DIRSLASH "/" |
|
61 #endif // WIN32 |
|
62 |
|
63 #ifdef RELEASE |
|
64 #define NDEBUG // remove asserts |
|
65 #endif // RELEASE |
|
66 |
|
67 #ifdef null |
|
68 #undef null |
|
69 #endif // null |
|
70 |
|
71 // Null pointer |
|
72 static const std::nullptr_t null = nullptr; |
|
73 |
|
74 // Main and edge color identifiers |
|
75 static const short maincolor = 16; |
|
76 static const short edgecolor = 24; |
|
77 |
|
78 static const bool yup = true; |
|
79 static const bool nope = false; |
|
80 |
|
81 class ForgeWindow; |
|
82 class LDObject; |
|
83 class bbox; |
|
84 class OpenFile; |
|
85 class QApplication; |
|
86 |
|
87 // ============================================================================= |
|
88 // Plural expression |
|
89 #define PLURAL(n) ((n != 1) ? "s" : "") |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // Shortcut for formatting |
|
93 #define PERFORM_FORMAT(in, out) \ |
|
94 va_list v; \ |
|
95 va_start (v, in); \ |
|
96 char* out = vdynformat (in, v, 256); \ |
|
97 va_end (v); |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // Shortcuts for stuffing vertices into printf-formatting. |
|
101 #define FMT_VERTEX "(%.3f, %.3f, %.3f)" |
|
102 #define FVERTEX(V) V.x, V.y, V.z |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // Templated clamp |
|
106 template<class T> static inline T clamp (T a, T min, T max) { |
|
107 return (a > max) ? max : (a < min) ? min : a; |
|
108 } |
|
109 |
|
110 // Templated minimum |
|
111 template<class T> static inline T min (T a, T b) { |
|
112 return (a < b) ? a : b; |
|
113 } |
|
114 |
|
115 // Templated maximum |
|
116 template<class T> static inline T max (T a, T b) { |
|
117 return (a > b) ? a : b; |
|
118 } |
|
119 |
|
120 // Templated absolute value |
|
121 template<class T> static inline T abs (T a) { |
|
122 return (a >= 0) ? a : -a; |
|
123 } |
|
124 |
|
125 // Quick QString to const char* conversion |
|
126 static inline const char* qchars (QString qstr) { |
|
127 return qstr.toStdString ().c_str (); |
|
128 } |
|
129 |
|
130 static const double pi = 3.14159265358979323846f; |
|
131 |
|
132 #ifdef IN_IDE_PARSER // KDevelop workaround |
|
133 // Current function name |
|
134 static const char* __func__ = ""; |
|
135 #endif // IN_IDE_PARSER |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 enum LogType { |
|
139 LOG_Normal, |
|
140 LOG_Warning, |
|
141 LOG_Error, |
|
142 LOG_Dev, |
|
143 }; |
|
144 |
|
145 // logf - universal access to the message log. Defined here so that I don't have |
|
146 // to include gui.h here and recompile everything every time that file changes. |
|
147 // logf is defined in main.cpp |
|
148 void logf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); |
|
149 void logf (LogType type, const char* fmtstr, ...) FORMAT_PRINTF (2, 3); |
|
150 void warnf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); |
|
151 void errf (const char* fmtstr, ...) FORMAT_PRINTF (1, 2); |
|
152 |
|
153 #ifndef RELEASE |
|
154 void devf (const char* fmtstr, ...); |
|
155 #else |
|
156 # define devf(...) |
|
157 #endif // RELEASE |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // Vertex at (0, 0, 0) |
|
161 extern const vertex g_origin; |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // Pointer to the OpenFile which is currently being edited by the user. |
|
165 extern OpenFile* g_curfile; |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // Pointer to the bounding box. |
|
169 extern bbox g_BBox; |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // Vector of all currently opened files. |
|
173 extern vector<OpenFile*> g_loadedFiles; |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // Pointer to the main application. |
|
177 extern const QApplication* g_app; |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // Identity matrix |
|
181 extern const matrix<3> g_identity; |
|
182 |
|
183 #endif // COMMON_H |
|