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 "document.h" |
26 #include "document.h" |
27 #include "ui_rotpoint.h" |
27 #include "ui_rotpoint.h" |
28 #include "moc_misc.cpp" |
|
29 |
|
30 #include "misc/documentPointer.cc" |
28 #include "misc/documentPointer.cc" |
31 #include "misc/ringFinder.cc" |
29 #include "misc/ringFinder.cc" |
|
30 #include "misc/invokationDeferer.cc" |
32 |
31 |
33 // Prime number table. |
32 // Prime number table. |
34 const int g_primes[NUM_PRIMES] = |
33 const int g_primes[NUM_PRIMES] = |
35 { |
34 { |
36 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, |
35 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, |
37 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, |
36 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, |
38 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, |
37 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, |
39 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, |
38 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, |
40 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, |
39 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, |
41 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, |
40 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, |
42 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, |
41 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, |
43 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, |
42 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, |
83 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, |
82 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, |
84 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, |
83 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, |
85 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, |
84 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, |
86 }; |
85 }; |
87 |
86 |
88 static const int32 g_e10[] = |
87 static const long g_e10[] = |
89 { |
88 { |
90 1, |
89 1l, |
91 10, |
90 10l, |
92 100, |
91 100l, |
93 1000, |
92 1000l, |
94 10000, |
93 10000l, |
95 100000, |
94 100000l, |
96 1000000, |
95 1000000l, |
97 10000000, |
96 10000000l, |
98 100000000, |
97 100000000l, |
99 1000000000, |
98 1000000000l, |
100 }; |
99 }; |
101 |
100 |
102 // ============================================================================= |
101 // ============================================================================= |
103 // ----------------------------------------------------------------------------- |
102 // ----------------------------------------------------------------------------- |
104 // Grid stuff |
103 // Grid stuff |
105 cfg (Int, grid, Grid::Medium); |
104 cfg (Int, grid, Grid::Medium); |
106 cfg (Float, grid_coarse_x, 5.0f); |
105 cfg (Float, grid_coarse_x, 5.0f); |
107 cfg (Float, grid_coarse_y, 5.0f); |
106 cfg (Float, grid_coarse_y, 5.0f); |
108 cfg (Float, grid_coarse_z, 5.0f); |
107 cfg (Float, grid_coarse_z, 5.0f); |
109 cfg (Float, grid_coarse_angle, 45.0f); |
108 cfg (Float, grid_coarse_angle, 45.0f); |
110 cfg (Float, grid_medium_x, 1.0f); |
109 cfg (Float, grid_medium_x, 1.0f); |
111 cfg (Float, grid_medium_y, 1.0f); |
110 cfg (Float, grid_medium_y, 1.0f); |
112 cfg (Float, grid_medium_z, 1.0f); |
111 cfg (Float, grid_medium_z, 1.0f); |
113 cfg (Float, grid_medium_angle, 22.5f); |
112 cfg (Float, grid_medium_angle, 22.5f); |
114 cfg (Float, grid_fine_x, 0.1f); |
113 cfg (Float, grid_fine_x, 0.1f); |
115 cfg (Float, grid_fine_y, 0.1f); |
114 cfg (Float, grid_fine_y, 0.1f); |
116 cfg (Float, grid_fine_z, 0.1f); |
115 cfg (Float, grid_fine_z, 0.1f); |
117 cfg (Float, grid_fine_angle, 7.5f); |
116 cfg (Float, grid_fine_angle, 7.5f); |
118 cfg (Int, edit_rotpoint, 0); |
117 cfg (Int, edit_rotpoint, 0); |
119 cfg (Float, edit_rotpoint_x, 0.0f); // TODO: make a VertexConfig and use it here |
118 cfg (Vertex, edit_customrotpoint, g_origin); |
120 cfg (Float, edit_rotpoint_y, 0.0f); |
|
121 cfg (Float, edit_rotpoint_z, 0.0f); |
|
122 |
119 |
123 const gridinfo g_GridInfo[3] = |
120 const gridinfo g_GridInfo[3] = |
124 { |
121 { |
125 { "Coarse", { &grid_coarse_x, &grid_coarse_y, &grid_coarse_z, &grid_coarse_angle }}, |
122 { "Coarse", { &grid_coarse_x, &grid_coarse_y, &grid_coarse_z, &grid_coarse_angle }}, |
126 { "Medium", { &grid_medium_x, &grid_medium_y, &grid_medium_z, &grid_medium_angle }}, |
123 { "Medium", { &grid_medium_x, &grid_medium_y, &grid_medium_z, &grid_medium_angle }}, |
249 { |
246 { |
250 QDialog* dlg = new QDialog; |
247 QDialog* dlg = new QDialog; |
251 Ui::RotPointUI ui; |
248 Ui::RotPointUI ui; |
252 ui.setupUi (dlg); |
249 ui.setupUi (dlg); |
253 |
250 |
254 switch (edit_rotpoint) |
251 switch ((ERotationPoint) edit_rotpoint) |
255 { |
252 { |
256 case ObjectOrigin: |
253 case EObjectOrigin: |
257 ui.objectPoint->setChecked (true); |
254 ui.objectPoint->setChecked (true); |
258 break; |
255 break; |
259 |
256 |
260 case WorldOrigin: |
257 case EWorldOrigin: |
261 ui.worldPoint->setChecked (true); |
258 ui.worldPoint->setChecked (true); |
262 break; |
259 break; |
263 |
260 |
264 case CustomPoint: |
261 case ECustomPoint: |
265 ui.customPoint->setChecked (true); |
262 ui.customPoint->setChecked (true); |
266 break; |
263 break; |
267 } |
264 } |
268 |
265 |
269 ui.customX->setValue (edit_rotpoint_x); |
266 ui.customX->setValue (edit_customrotpoint.x()); |
270 ui.customY->setValue (edit_rotpoint_y); |
267 ui.customY->setValue (edit_customrotpoint.y()); |
271 ui.customZ->setValue (edit_rotpoint_z); |
268 ui.customZ->setValue (edit_customrotpoint.z()); |
272 |
269 |
273 if (!dlg->exec()) |
270 if (!dlg->exec()) |
274 return; |
271 return; |
275 |
272 |
276 edit_rotpoint = |
273 edit_rotpoint = |
277 (ui.objectPoint->isChecked()) ? ObjectOrigin : |
274 (ui.objectPoint->isChecked()) ? EObjectOrigin : |
278 (ui.worldPoint->isChecked()) ? WorldOrigin : |
275 (ui.worldPoint->isChecked()) ? EWorldOrigin : |
279 CustomPoint; |
276 ECustomPoint; |
280 |
277 |
281 edit_rotpoint_x = ui.customX->value(); |
278 edit_customrotpoint.x() = ui.customX->value(); |
282 edit_rotpoint_y = ui.customY->value(); |
279 edit_customrotpoint.y() = ui.customY->value(); |
283 edit_rotpoint_z = ui.customZ->value(); |
280 edit_customrotpoint.z() = ui.customZ->value(); |
284 } |
281 } |
285 |
282 |
286 // ============================================================================= |
283 // ============================================================================= |
287 // ----------------------------------------------------------------------------- |
284 // ----------------------------------------------------------------------------- |
288 QString join (initlist<StringFormatArg> vals, QString delim) |
285 QString join (initlist<StringFormatArg> vals, QString delim) |
300 void roundToDecimals (double& a, int decimals) |
297 void roundToDecimals (double& a, int decimals) |
301 { |
298 { |
302 assert (decimals >= 0 && decimals < (signed) (sizeof g_e10 / sizeof *g_e10)); |
299 assert (decimals >= 0 && decimals < (signed) (sizeof g_e10 / sizeof *g_e10)); |
303 a = round (a * g_e10[decimals]) / g_e10[decimals]; |
300 a = round (a * g_e10[decimals]) / g_e10[decimals]; |
304 } |
301 } |
305 |
|
306 // ============================================================================= |
|
307 // ----------------------------------------------------------------------------- |
|
308 InvokationDeferer* g_invokationDeferer = new InvokationDeferer(); |
|
309 |
|
310 InvokationDeferer::InvokationDeferer (QObject* parent) : QObject (parent) |
|
311 { |
|
312 connect (this, SIGNAL (functionAdded()), this, SLOT (invokeFunctions()), |
|
313 Qt::QueuedConnection); |
|
314 } |
|
315 |
|
316 void InvokationDeferer::addFunctionCall (InvokationDeferer::FunctionType func) |
|
317 { |
|
318 m_funcs << func; |
|
319 removeDuplicates (m_funcs); |
|
320 emit functionAdded(); |
|
321 } |
|
322 |
|
323 void InvokationDeferer::invokeFunctions() |
|
324 { |
|
325 for (FunctionType func : m_funcs) |
|
326 (*func)(); |
|
327 |
|
328 m_funcs.clear(); |
|
329 } |
|
330 |
|
331 void invokeLater (InvokationDeferer::FunctionType func) |
|
332 { |
|
333 g_invokationDeferer->addFunctionCall (func); |
|
334 } |
|