1 /* |
1 /* |
2 * LDForge: LDraw parts authoring CAD |
2 * LDForge: LDraw parts authoring CAD |
3 * Copyright (C) 2013 Santeri Piippo |
3 * Copyright (C) 2013 Santeri Piippo |
4 * |
4 * |
5 * This program is free software: you can redistribute it and/or modify |
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 |
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 |
7 * the Free Software Foundation, either version 3 of the License, or |
8 * (at your option) any later version. |
8 * (at your option) any later version. |
9 * |
9 * |
10 * This program is distributed in the hope that it will be useful, |
10 * This program is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. |
13 * GNU General Public License for more details. |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
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/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #include <math.h> |
19 #include <math.h> |
20 #include <locale.h> |
20 #include <locale.h> |
21 #include <qcolor.h> |
21 #include <QColor> |
22 #include "common.h" |
22 #include "common.h" |
23 #include "misc.h" |
23 #include "misc.h" |
24 #include "gui.h" |
24 #include "gui.h" |
25 #include "dialogs.h" |
25 #include "dialogs.h" |
26 #include "ui_rotpoint.h" |
26 #include "ui_rotpoint.h" |
78 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, |
78 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, |
79 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, |
79 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, |
80 }; |
80 }; |
81 |
81 |
82 // ============================================================================= |
82 // ============================================================================= |
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83 // ----------------------------------------------------------------------------- |
84 // ============================================================================= |
|
85 // Grid stuff |
84 // Grid stuff |
86 cfg (int, grid, Grid::Medium); |
85 cfg (int, grid, Grid::Medium); |
87 |
86 |
88 cfg (float, grid_coarse_x, 5.0f); |
87 cfg (float, grid_coarse_x, 5.0f); |
89 cfg (float, grid_coarse_y, 5.0f); |
88 cfg (float, grid_coarse_y, 5.0f); |
108 { "Fine", { &grid_fine_x, &grid_fine_y, &grid_fine_z, &grid_fine_angle }} |
107 { "Fine", { &grid_fine_x, &grid_fine_y, &grid_fine_z, &grid_fine_angle }} |
109 }; |
108 }; |
110 |
109 |
111 // ============================================================================= |
110 // ============================================================================= |
112 // Snap the given coordinate value on the current grid's given axis. |
111 // Snap the given coordinate value on the current grid's given axis. |
|
112 // ----------------------------------------------------------------------------- |
113 double Grid::snap (double in, const Grid::Config axis) { |
113 double Grid::snap (double in, const Grid::Config axis) { |
114 const double gridval = currentGrid().confs[axis]->value; |
114 const double gridval = currentGrid().confs[axis]->value; |
115 const long mult = abs (in / gridval); |
115 const long mult = abs (in / gridval); |
116 const bool neg = (in < 0); |
116 const bool neg = (in < 0); |
117 double out = mult * gridval; |
117 double out = mult * gridval; |
124 |
124 |
125 return out; |
125 return out; |
126 } |
126 } |
127 |
127 |
128 // ============================================================================= |
128 // ============================================================================= |
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
130 // ============================================================================= |
|
131 // Float to string. Removes trailing zeroes and is locale-independant. |
129 // Float to string. Removes trailing zeroes and is locale-independant. |
|
130 // TODO: Replace with QString::number() |
|
131 // ----------------------------------------------------------------------------- |
132 str ftoa (double num) { |
132 str ftoa (double num) { |
133 // Disable the locale first so that the decimal point will not |
133 // Disable the locale first so that the decimal point will not |
134 // turn into anything weird (like commas) |
134 // turn into anything weird (like commas) |
135 setlocale (LC_NUMERIC, "C"); |
135 setlocale (LC_NUMERIC, "C"); |
136 |
136 |
148 |
148 |
149 return rep; |
149 return rep; |
150 } |
150 } |
151 |
151 |
152 // ============================================================================= |
152 // ============================================================================= |
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
153 // TODO: I guess Qt must have something like this stashed somewhere? |
154 // ============================================================================= |
154 // ----------------------------------------------------------------------------- |
155 bool isNumber (const str& tok) { |
155 bool isNumber (const str& tok) { |
156 bool gotDot = false; |
156 bool gotDot = false; |
157 |
157 |
158 for (int i = 0; i < tok.length(); ++i) { |
158 for (int i = 0; i < tok.length(); ++i) { |
159 const qchar c = tok[i]; |
159 const qchar c = tok[i]; |
263 edit_rotpoint_x = ui.customX->value(); |
265 edit_rotpoint_x = ui.customX->value(); |
264 edit_rotpoint_y = ui.customY->value(); |
266 edit_rotpoint_y = ui.customY->value(); |
265 edit_rotpoint_z = ui.customZ->value(); |
267 edit_rotpoint_z = ui.customZ->value(); |
266 } |
268 } |
267 |
269 |
|
270 // ============================================================================= |
|
271 // ----------------------------------------------------------------------------- |
268 str join (initlist<StringFormatArg> vals, str delim) { |
272 str join (initlist<StringFormatArg> vals, str delim) { |
269 QStringList list; |
273 QStringList list; |
270 for (const StringFormatArg& arg : vals) |
274 for (const StringFormatArg& arg : vals) |
271 list << arg.value(); |
275 list << arg.value(); |
272 |
276 |
273 return list.join (delim); |
277 return list.join (delim); |
274 } |
278 } |
275 |
279 |
|
280 // ============================================================================= |
|
281 // TODO: I'm quite sure Qt has this covered as well. |
|
282 // ----------------------------------------------------------------------------- |
276 double atof (str val) { |
283 double atof (str val) { |
277 // Disable the locale while parsing the line or atof's behavior changes |
284 // Disable the locale while parsing the line or atof's behavior changes |
278 // between locales (i.e. fails to read decimals properly). That is |
285 // between locales (i.e. fails to read decimals properly). That is |
279 // quite undesired... |
286 // quite undesired... |
280 setlocale (LC_NUMERIC, "C"); |
287 setlocale (LC_NUMERIC, "C"); |