73 QTranslator translator{&mainWindow}; |
73 QTranslator translator{&mainWindow}; |
74 LibrariesModel libraries{&mainWindow}; |
74 LibrariesModel libraries{&mainWindow}; |
75 QStringList recentlyOpenedFiles; |
75 QStringList recentlyOpenedFiles; |
76 ColorTable colorTable; |
76 ColorTable colorTable; |
77 gl::RenderPreferences renderPreferences; |
77 gl::RenderPreferences renderPreferences; |
|
78 gl::build_preferences user_gl_build_preferences; |
78 MessageLog messageLog; |
79 MessageLog messageLog; |
79 ToolWidgets toolWidgets{ |
80 ToolWidgets toolWidgets{ |
80 .circleToolOptions = new CircleToolOptionsWidget{&mainWindow}, |
81 .circleToolOptions = new CircleToolOptionsWidget{&mainWindow}, |
81 }; |
82 }; |
82 }; |
83 }; |
174 fn(&info, modelSpecificData); |
175 fn(&info, modelSpecificData); |
175 } |
176 } |
176 }); |
177 }); |
177 } |
178 } |
178 |
179 |
|
180 static void rebuild_polygons_for_all_models(MainState* state) |
|
181 { |
|
182 forEachModel(&state->documents, [](const void*, const ModelData* data){ |
|
183 if (data->canvas != nullptr) { |
|
184 data->canvas->build(); |
|
185 data->canvas->update(); |
|
186 } |
|
187 }); |
|
188 } |
|
189 |
179 static void updateRenderPreferences(MainState* state) |
190 static void updateRenderPreferences(MainState* state) |
180 { |
191 { |
181 forEachModel(&state->documents, [state](const void*, const ModelData* data){ |
192 forEachModel(&state->documents, [state](const void*, const ModelData* data){ |
182 if (data->canvas != nullptr) { |
193 if (data->canvas != nullptr) { |
183 data->canvas->setRenderPreferences(state->renderPreferences); |
|
184 data->canvas->setLayerEnabled(data->axesLayer.get(), state->renderPreferences.drawAxes); |
194 data->canvas->setLayerEnabled(data->axesLayer.get(), state->renderPreferences.drawAxes); |
|
195 data->canvas->update(); |
185 } |
196 } |
186 }); |
197 }); |
187 state->mainWindow.setRenderStyle(state->renderPreferences.style); |
198 state->mainWindow.setRenderStyle(state->renderPreferences.style); |
188 state->mainWindow.actionDrawAxes->setChecked(state->renderPreferences.drawAxes); |
199 state->mainWindow.actionDrawAxes->setChecked(state->renderPreferences.drawAxes); |
189 state->mainWindow.actionWireframe->setChecked(state->renderPreferences.wireframe); |
200 state->mainWindow.actionWireframe->setChecked(state->renderPreferences.wireframe); |
190 } |
201 } |
191 |
202 |
|
203 static gl::build_preferences load_gl_build_preferences_from_settings() |
|
204 { |
|
205 return gl::build_preferences{ |
|
206 .mainColor = setting<Setting::MainColor>(), |
|
207 .backgroundColor = setting<Setting::BackgroundColor>(), |
|
208 }; |
|
209 } |
|
210 |
192 static gl::RenderPreferences loadRenderPreferences() |
211 static gl::RenderPreferences loadRenderPreferences() |
193 { |
212 { |
194 return gl::RenderPreferences{ |
213 return gl::RenderPreferences{ |
195 .style = setting<Setting::RenderStyle>(), |
214 .style = setting<Setting::RenderStyle>(), |
196 .mainColor = setting<Setting::MainColor>(), |
|
197 .backgroundColor = setting<Setting::BackgroundColor>(), |
|
198 .selectedColor = setting<Setting::SelectedColor>(), |
215 .selectedColor = setting<Setting::SelectedColor>(), |
199 .lineThickness = setting<Setting::LineThickness>(), |
216 .lineThickness = setting<Setting::LineThickness>(), |
200 .lineAntiAliasing = setting<Setting::LineAntiAliasing>(), |
217 .lineAntiAliasing = setting<Setting::LineAntiAliasing>(), |
201 .drawAxes = setting<Setting::DrawAxes>(), |
218 .drawAxes = setting<Setting::DrawAxes>(), |
202 .wireframe = setting<Setting::Wireframe>(), |
219 .wireframe = setting<Setting::Wireframe>(), |
325 state->documents.setModelPayload(modelId, data); |
342 state->documents.setModelPayload(modelId, data); |
326 QObject::connect( |
343 QObject::connect( |
327 data->tools.get(), |
344 data->tools.get(), |
328 &EditTools::modelAction, |
345 &EditTools::modelAction, |
329 std::bind(executeAction, model, std::placeholders::_1)); |
346 std::bind(executeAction, model, std::placeholders::_1)); |
330 data->canvas->setRenderPreferences(state->renderPreferences); |
347 data->canvas->render_preferences = &state->renderPreferences; |
|
348 data->canvas->build_preferences = &state->user_gl_build_preferences; |
331 QObject::connect( |
349 QObject::connect( |
332 data->tools.get(), |
350 data->tools.get(), |
333 &EditTools::newStatusText, |
351 &EditTools::newStatusText, |
334 [&state](const QString& newStatusText) { |
352 [&state](const QString& newStatusText) { |
335 state->mainWindow.statusBar()->showMessage(newStatusText); |
353 state->mainWindow.statusBar()->showMessage(newStatusText); |
386 |
404 |
387 static void restoreSettings(MainState* state) |
405 static void restoreSettings(MainState* state) |
388 { |
406 { |
389 state->recentlyOpenedFiles = setting<Setting::RecentFiles>(); |
407 state->recentlyOpenedFiles = setting<Setting::RecentFiles>(); |
390 state->renderPreferences = loadRenderPreferences(); |
408 state->renderPreferences = loadRenderPreferences(); |
|
409 state->user_gl_build_preferences = load_gl_build_preferences_from_settings(); |
391 state->libraries.restoreFromSettings(); |
410 state->libraries.restoreFromSettings(); |
392 updateRecentlyOpenedDocumentsMenu(state); |
411 updateRecentlyOpenedDocumentsMenu(state); |
393 state->colorTable = loadColors(&state->libraries); |
412 state->colorTable = loadColors(&state->libraries); |
394 updateRenderPreferences(state); |
413 updateRenderPreferences(state); |
|
414 rebuild_polygons_for_all_models(state); |
395 state->mainWindow.mdiArea->setViewMode(setting<Setting::ViewMode>()); |
415 state->mainWindow.mdiArea->setViewMode(setting<Setting::ViewMode>()); |
396 state->mainWindow.retranslateUi(&state->mainWindow); |
416 state->mainWindow.retranslateUi(&state->mainWindow); |
397 state->mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>()); |
417 state->mainWindow.setToolButtonStyle(setting<Setting::ToolButtonStyle>()); |
398 } |
418 } |
399 |
419 |