11 #include "FormVertexBuilder.h"
12 #include "FullScreenPanel.h"
14 #include <Qt5Utility/QGui.h>
16 #include <QMessageBox>
17 #include <QFileDialog>
18 #include <QPrintDialog>
19 #include <QPrintPreviewDialog>
21 #include "BuildInfo.h"
23 #include "PostprocLibrary.h"
24 #include "SampleShapeBuilder.h"
25 #include "ShaderLibrary.h"
26 #include "QGVAboutDlg.h"
28 #include "FormCustomShader.h"
29 #include "FormPyScript.h"
30 #include "MatcapSelectDlg.h"
31 #include "EnvmapSelectDlg.h"
32 #include "FileDlgUtil.h"
33 #include "MaterialPresetDlg.h"
37 QColor ToQColor(const lgr::color4f& c)
39 int r = lm::clamp(0, (int)(c.r() * 255.0f), 255);
40 int g = lm::clamp(0, (int)(c.g() * 255.0f), 255);
41 int b = lm::clamp(0, (int)(c.b() * 255.0f), 255);
42 int a = lm::clamp(0, (int)(c.a() * 255.0f), 255);
44 return QColor(r, g, b, a);
49 FormMain::FormMain(QWidget *parent)
53 , m_CustomShaderDlg(NULL)
55 , m_MatPresetDlg(NULL)
59 ui.widgetObjectList->setMainForm(this);
60 ui.widgetCamera->setMainForm(this);
62 m_EnableAllFeatures = false;
63 m_LastFocusedDockDlg = NULL;
67 setWindowTitle("QtGeoViewer");
70 InitializeStatusBar();
72 InitializeCoordinateCombobox();
73 Initialize2DViewSrcCombobox();
74 InitializeEventFilter();
79 ApplyGeomStateFromGUI();
80 SyncShaderSettingsToGUI();
83 ui.toolBar_View->setVisible( ui.actionWindow_ToolBarView->isChecked() );
85 UpdateViewTypeFromMenu();
89 ui.widgetObjectList->RebuildObjectList();
93 InitializeAnimation();
95 InitializeFromConfigFiles();
104 m_InitRect.translate(pos());
111 FormMain::~FormMain()
116 void FormMain::LoadLastWinPos(void)
118 QString file = PathInfo::GetPosConfigFilePath();
119 QSettings conf(file, QSettings::IniFormat);
122 v = conf.value("main/WindowPos");
125 QRect r = v.toRect();
133 move(QPoint(dl, dt));
136 v = conf.value("main/WinState");
140 setWindowState(Qt::WindowMaximized);
144 void FormMain::SaveWinPos(void)
146 QString file = PathInfo::GetPosConfigFilePath();
147 QSettings conf(file, QSettings::IniFormat);
149 conf.setValue("main/WinState", isMaximized());
151 if (isMaximized() || isMinimized())
153 setWindowState(Qt::WindowNoState);
154 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
160 conf.setValue("main/WindowPos", r);
163 void FormMain::HideFeatures(void)
165 bool b = m_EnableAllFeatures;
167 ui.actionVertexBuilder->setVisible(b);
168 ui.menuPrintRoot->menuAction()->setVisible(b);
169 ui.actionShadowmap->setVisible(b);
170 ui.actionEnvmap->setVisible(b);
171 ui.actionShaderCustom->setVisible(b);
172 ui.actionWindowCustomShader->setVisible(b);
173 ui.actionPyScript->setVisible(b);
174 ui.actionConsole->setVisible(b);
175 ui.actionReleaseShader->setVisible(b);
178 void FormMain::InitializeEventFilter(void)
180 ui.editEnvMap->installEventFilter(this);
181 ui.editMatcap->installEventFilter(this);
183 ui.editCurrentTexName->installEventFilter(this);
184 ui.editCurrentMatNormalMap->installEventFilter(this);
185 ui.editMatCapEachMaterial->installEventFilter(this);
187 ui.colorAmbient->installEventFilter(this);
188 ui.colorEmission->installEventFilter(this);
189 ui.colorDiffuse->installEventFilter(this);
190 ui.colorSpecular->installEventFilter(this);
193 void FormMain::InitDataBinding(void)
195 InitializeVisiblStateMenu();
196 InitializeUVStateMenu();
197 InitializeTexStateMenu();
198 InitializeSceneStateMenu();
199 InitializeGeomStateMenu();
200 InitializeCursorMenu();
202 SyncViewSettingsFromGUI();
203 m_Binder_Scene.UpdateAllData();
204 m_Binder_UVConfig.UpdateAllData();
205 m_Binder_TexConfig.UpdateAllData();
206 SyncTexConfigToData();
209 void FormMain::InitializeVisiblStateMenu(void)
211 DataBinderMap& dbmap = m_Binder_ViewConfig;
213 View3DConfig& cfg_3d = m_View3d.m_Config;
215 dbmap.AddBinder(new MenuBinder(ui.actionDrawFace , &cfg_3d.m_DrawFace ));
216 dbmap.AddBinder(new MenuBinder(ui.actionDrawWire , &cfg_3d.m_DrawWire ));
217 dbmap.AddBinder(new MenuBinder(ui.actionFlatShading , &cfg_3d.m_EnableFlatShade ));
218 dbmap.AddBinder(new MenuBinder(ui.actionVertexColor , &cfg_3d.m_EnableVertexColor ));
219 dbmap.AddBinder(new MenuBinder(ui.actionVertexColor_0_1 , &cfg_3d.m_VertColorTo01 ));
220 dbmap.AddBinder(new MenuBinder(ui.actionEnableTexture3D , &cfg_3d.m_EnableTexture ));
221 dbmap.AddBinder(new MenuBinder(ui.actionDrawBBox , &cfg_3d.m_DrawBBox ));
222 dbmap.AddBinder(new MenuBinder(ui.actionFaceVBO , &cfg_3d.m_EnableFaceVBO ));
223 dbmap.AddBinder(new MenuBinder(ui.actionVidTopMost , &cfg_3d.m_ShowVidTopMost ));
224 dbmap.AddBinder(new MenuBinder(ui.actionDrawBBoxRange , &cfg_3d.m_DrawBBoxRange ));
225 dbmap.AddBinder(new MenuBinder(ui.actionWireDispList , &cfg_3d.m_EnableWireDispList ));
226 dbmap.AddBinder(new MenuBinder(ui.actionMultisample , &cfg_3d.m_EnableMultisample ));
227 dbmap.AddBinder(new MenuBinder(ui.actionCoverageTransparent , &cfg_3d.m_EnableCoverageTrans ));
228 dbmap.AddBinder(new MenuBinder(ui.actionSeparateSpecular , &cfg_3d.m_SeparateSpecular ));
229 dbmap.AddBinder(new MenuBinder(ui.actionShowSelVertCoord , &cfg_3d.m_ShowSelVertCoord ));
230 dbmap.AddBinder(new MenuBinder(ui.actionHighlightSelected , &cfg_3d.m_HighlightSelected ));
231 dbmap.AddBinder(new MenuBinder(ui.actionHighlightSelectedWire , &cfg_3d.m_HighlightSelectedWire ));
232 dbmap.AddBinder(new MenuBinder(ui.actionFixMaterialSilver , &cfg_3d.m_UseFixMaterial ));
233 dbmap.AddBinder(new MenuBinder(ui.actionShadowmapBuffer , &cfg_3d.m_DrawShadowmapBuf ));
234 dbmap.AddBinder(new MenuBinder(ui.actionEnableLighting , &cfg_3d.m_EnableLighting ));
235 dbmap.AddBinder(new MenuBinder(ui.actionEnableCulling , &cfg_3d.m_EnableCullFace ));
236 dbmap.AddBinder(new MenuBinder(ui.actionDrawVid , &cfg_3d.m_DrawVid ));
237 dbmap.AddBinder(new MenuBinder(ui.actionDrawVertNormal , &cfg_3d.m_DrawVertNormal ));
238 dbmap.AddBinder(new MenuBinder(ui.actionDrawVert , &cfg_3d.m_DrawVert ));
239 dbmap.AddBinder(new MenuBinder(ui.actionWireVBO , &cfg_3d.m_EnableWireVBO ));
240 dbmap.AddBinder(new MenuBinder(ui.actionIndexColorMode , &cfg_3d.m_IndexMaterial ));
241 dbmap.AddBinder(new MenuBinder(ui.actionFBMaterial , &cfg_3d.m_FBMaterial ));
242 dbmap.AddBinder(new MenuBinder(ui.actionDrawMiniAxis , &cfg_3d.m_DrawMiniAxis ));
243 dbmap.AddBinder(new MenuBinder(ui.actionDrawLookPos , &cfg_3d.m_DrawLookPos ));
244 dbmap.AddBinder(new MenuBinder(ui.actionDrawLightPos , &cfg_3d.m_DrawLightPosition ));
245 dbmap.AddBinder(new MenuBinder(ui.actionDrawGround , &cfg_3d.m_DrawGround ));
246 dbmap.AddBinder(new MenuBinder(ui.actionDrawFid , &cfg_3d.m_DrawFid ));
247 dbmap.AddBinder(new MenuBinder(ui.actionCameraRecords , &cfg_3d.m_DrawCameraRecord ));
248 dbmap.AddBinder(new MenuBinder(ui.actionDrawAxis , &cfg_3d.m_DrawAxis ));
249 dbmap.AddBinder(new MenuBinder(ui.actionDoubleSideShading , &cfg_3d.m_DoubleSideShading ));
250 dbmap.AddBinder(new MenuBinder(ui.actionDirectionalLight , &cfg_3d.m_LightIsDirectional ));
251 dbmap.AddBinder(new MenuBinder(ui.actionCullFrontOrBack , &cfg_3d.m_CullAngle_F ));
252 dbmap.AddBinder(new MenuBinder(ui.actionHighlightMaterial , &cfg_3d.m_HighlightMaterial ));
253 dbmap.AddBinder(new MenuBinder(ui.actionCloseVert , &cfg_3d.m_ShowCloseVertInfo ));
254 dbmap.AddBinder(new MenuBinder(ui.actionCameraRange , &cfg_3d.m_DrawRenderRange ));
255 dbmap.AddBinder(new MenuBinder(ui.actionRenderTime , &cfg_3d.m_ShowRenderTime ));
256 dbmap.AddBinder(new MenuBinder(ui.actionUseFixTexture , &cfg_3d.m_UseFixTexture ));
257 dbmap.AddBinder(new MenuBinder(ui.actionShowSelVertIdx , &cfg_3d.m_ShowSelVertIdx ));
258 dbmap.AddBinder(new MenuBinder(ui.actionShowMeshBound , &cfg_3d.m_ShowMeshBound ));
259 dbmap.AddBinder(new MenuBinder(ui.actionPickTransparent , &cfg_3d.m_PickTransparent ));
260 dbmap.AddBinder(new MenuBinder(ui.actionDrawPolylineLenWhl , &cfg_3d.m_DrawPolylineLenWhl ));
261 dbmap.AddBinder(new MenuBinder(ui.actionDrawPolylineLen , &cfg_3d.m_DrawPolylineLen ));
262 dbmap.AddBinder(new MenuBinder(ui.actionDrawPolylineIdx , &cfg_3d.m_DrawPolylineIdx ));
263 dbmap.AddBinder(new MenuBinder(ui.actionDrawPolyline , &cfg_3d.m_DrawPolyline ));
264 dbmap.AddBinder(new MenuBinder(ui.actionDrawBone , &cfg_3d.m_DrawBone ));
265 dbmap.AddBinder(new MenuBinder(ui.actionShowMeasure , &cfg_3d.m_DrawCameraMeasure ));
266 dbmap.AddBinder(new MenuBinder(ui.actionFlipMouseMR , &cfg_3d.m_FlipMouseMR ));
267 dbmap.AddBinder(new MenuBinder(ui.actionSyncLightToCamera , &cfg_3d.m_SyncLightTocamera ));
269 for (GuiBinder& binder : dbmap.m_BinderMap)
271 MenuBinder* mb = dynamic_cast<MenuBinder*>(&binder);
274 QAction* a = mb->GetMenu();
277 SIGNAL(triggered(bool)),
279 SLOT(actionVisibleStates_Triggered(bool)));
284 void FormMain::InitializeUVStateMenu(void)
286 DataBinderMap& dbmap = m_Binder_UVConfig;
288 dbmap.AddBinder(new MenuBinder(ui.actionUVRepeat , &m_View2d.m_RepeatTexture ));
289 dbmap.AddBinder(new MenuBinder(ui.actionUseFixTexture2D , &m_View2d.m_UseFixTexute ));
290 dbmap.AddBinder(new MenuBinder(ui.actionShowVertex2d , &m_View2d.m_DrawVerts ));
291 dbmap.AddBinder(new MenuBinder(ui.actionShowImage2d , &m_View2d.m_EnableTexture ));
293 for (GuiBinder& binder : dbmap.m_BinderMap)
295 MenuBinder* mb = dynamic_cast<MenuBinder*>(&binder);
298 QAction* a = mb->GetMenu();
301 SIGNAL(triggered(bool)),
303 SLOT(actionVisibleStatesUV_Triggered(bool)));
308 void FormMain::InitializeTexStateMenu(void)
310 DataBinderMap& dbmap = m_Binder_TexConfig;
312 static bool t = false;
314 dbmap.AddBinder(new MenuBinder(ui.actionUVFlipY , &m_Scene.m_TextureTransform.m_FlipY ));
315 dbmap.AddBinder(new MenuBinder(ui.actionTextureCompress , &m_Scene.m_TexConfig.m_EnableCompress ));
317 for (GuiBinder& binder : dbmap.m_BinderMap)
319 MenuBinder* mb = dynamic_cast<MenuBinder*>(&binder);
322 QAction* a = mb->GetMenu();
325 SIGNAL(triggered(bool)),
327 SLOT(actionVisibleStatesTex_Triggered(bool)));
332 void FormMain::on_actionTextureMipmap_toggled(bool b)
334 m_Scene.m_TexConfig.m_SampleMode = gl::TexSampleMode::Mipmap;
338 void FormMain::on_actionTextureLinear_toggled(bool b)
340 m_Scene.m_TexConfig.m_SampleMode = gl::TexSampleMode::Linear;
344 void FormMain::on_actionTextureNearest_toggled(bool b)
346 m_Scene.m_TexConfig.m_SampleMode = gl::TexSampleMode::Nearest;
350 void FormMain::SyncTexConfigToGUI(bool silent)
352 gl::TexSampleMode mode = m_Scene.m_TexConfig.m_SampleMode;
356 SetActioncheck(ui.actionTextureMipmap, true, false);
357 SetActioncheck(ui.actionTextureLinear, true, false);
358 SetActioncheck(ui.actionTextureNearest, true, false);
362 if (mode == gl::TexSampleMode::Mipmap)
363 a = ui.actionTextureMipmap;
364 else if (mode == gl::TexSampleMode::Linear)
365 a = ui.actionTextureLinear;
366 else if (mode == gl::TexSampleMode::Nearest)
367 a = ui.actionTextureNearest;
369 SetActioncheck(a, silent, true);
372 void FormMain::SetActioncheck(QAction* a, bool silent, bool check)
376 a->blockSignals(true);
378 a->setChecked(check);
381 a->blockSignals(false);
384 void FormMain::SyncTexConfigToData(void)
386 if (ui.actionTextureMipmap->isChecked())
387 m_Scene.m_TexConfig.m_SampleMode = gl::TexSampleMode::Mipmap;
388 else if (ui.actionTextureLinear->isChecked())
389 m_Scene.m_TexConfig.m_SampleMode = gl::TexSampleMode::Linear;
390 else if (ui.actionTextureNearest->isChecked())
391 m_Scene.m_TexConfig.m_SampleMode = gl::TexSampleMode::Nearest;
394 void FormMain::InitializeSceneStateMenu(void)
396 DataBinderMap& dbmap = m_Binder_Scene;
398 dbmap.AddBinder(new CheckboxBinder( ui.checkEnvMap , &m_Scene.m_EnvImg.m_VisibleEnvSphere ));
399 dbmap.AddBinder(new CheckboxBinder( ui.checkEnvReflection , &m_Scene.m_EnvImg.m_IsEnableReflection ));
400 dbmap.AddBinder(new CheckboxBinder( ui.checkShadowEnabled , &m_Scene.m_ShadowConfig.m_EnableShadow ));
401 dbmap.AddBinder(new CheckboxBinder( ui.checkSoftShadow , &m_Scene.m_ShadowConfig.m_EnableSoftShadow ));
403 for (GuiBinder& binder : dbmap.m_BinderMap)
405 CheckboxBinder* mb = dynamic_cast<CheckboxBinder*>(&binder);
408 QCheckBox* c = mb->GetCheckBox();
411 SIGNAL(toggled(bool)),
413 SLOT(actionSceneStates_Toggled(bool)));
418 void FormMain::InitializeCursorMenu(void)
420 DataBinderMap& dbmap = m_Binder_Cursor;
422 Cursor3D& cursor = m_Scene.m_Cursor3d;
423 dbmap.AddBinder(new MenuBinder( ui.actionShowCursor , &cursor.ShowCursor ));
424 dbmap.AddBinder(new MenuBinder( ui.actionCursorToDepth , &cursor.CursorDepth ));
425 dbmap.AddBinder(new MenuBinder( ui.actionCursorCoord , &cursor.ShowCoord ));
426 dbmap.AddBinder(new MenuBinder( ui.actionCheckBaryCoord , &cursor.CheckBaryCoord ));
427 dbmap.AddBinder(new MenuBinder( ui.actionSelectCloseMat , &cursor.SelCloseMat ));
428 dbmap.AddBinder(new MenuBinder( ui.actionCursorAxis , &cursor.ShowAxis ));
429 dbmap.AddBinder(new MenuBinder( ui.actionMeasure , &cursor.ShowMeasure ));
430 dbmap.AddBinder(new MenuBinder( ui.actionMeasureLen , &cursor.ShowMeasureLen ));
431 dbmap.AddBinder(new MenuBinder( ui.actionMeasureXYZ , &cursor.ShowMeasureXYZ ));
432 dbmap.AddBinder(new MenuBinder( ui.actionRecordStroke , &cursor.RecordStroke ));
433 dbmap.AddBinder(new MenuBinder( ui.actionShowStrokeLength , &cursor.ShowStrokeLen ));
434 dbmap.AddBinder(new MenuBinder( ui.actionTransparentStroke , &cursor.TranspStorke ));
436 for (GuiBinder& binder : dbmap.m_BinderMap)
438 MenuBinder* mb = dynamic_cast<MenuBinder*>(&binder);
441 QAction* a = mb->GetMenu();
444 SIGNAL(triggered(bool)),
446 SLOT(actionCursorMenuStates_Toggled(bool)));
452 void FormMain::InitializeGeomStateMenu(void)
454 AddGeomStateAction( ui.actionCentering );
455 AddGeomStateAction( ui.actionAutoResize );
458 void FormMain::AddGeomStateAction(const QAction* action)
462 SIGNAL(triggered(bool)),
464 SLOT(actionGeomStates_Triggered(bool)));
468 void FormMain::InitializeGLView(void)
470 ui.GLWidgetMain->setMouseTracking(true);
471 ui.GLWidgetUV->setMouseTracking(true);
473 ui.GLWidgetMain->SetViewer(&m_View3d);
474 m_View3d.m_Widgets = &m_Widgets;
475 m_View3d.RegisterScene(&m_Scene);
476 m_View3d.InitializeView(ui.GLWidgetMain);
478 ui.GLWidgetUV->SetViewer(&m_View2d);
479 m_View2d.m_Widgets = &m_Widgets;
480 m_View2d.RegisterScene(&m_Scene);
481 m_View2d.InitializeView(ui.GLWidgetUV);
483 m_Widgets.AddWidget(ui.GLWidgetMain);
484 m_Widgets.AddWidget(ui.GLWidgetUV);
486 // OpenGL
\82Ì
\83\8a\83X
\83g
\82Ì
\8b¤
\97L
\89»
489 m_ContextShare.BeginDrawTop();
491 m_Scene.Initialize();
493 m_ContextShare.EndDrawTop();
497 SIGNAL(SelectedObjectChanged(int, int)),
498 SLOT(View3D_SelectedObjectChanged(int, int)));
501 SIGNAL(SelectedMatChanged(int)),
502 SLOT(View3D_SelectedMatChanged(int)));
505 SIGNAL(CameraMoved(void)),
506 SLOT(View3D_CameraMoved(void)));
509 SIGNAL(StatusTipChanged(QString)),
510 SLOT(View3D_StatusTipChanged(QString)));
513 SIGNAL(SequenceStepped(int)),
514 SLOT(View3D_SequenceStepped(int)));
517 SIGNAL(CursorMoved()),
518 SLOT(View3D_CursorMoved()));
521 // OpenGL
\82Ì
\83\8a\83X
\83g
\82Ì
\8b¤
\97L
\89»
522 void FormMain::SetContextShare(void)
524 ui.GLWidgetUV->makeCurrent();
525 m_ContextShare.AddContext( GetDC((HWND)ui.GLWidgetUV->winId()) , wglGetCurrentContext() );
526 ui.GLWidgetUV->doneCurrent();
528 ui.GLWidgetMain->makeCurrent();
529 m_ContextShare.AddContext( GetDC((HWND)ui.GLWidgetUV->winId()) , wglGetCurrentContext() );
530 ui.GLWidgetMain->doneCurrent();
532 m_ContextShare.MakeShare();
535 void FormMain::InitializeCoordinateCombobox(void)
537 ui.comboCoordinate->blockSignals(true);
538 ui.comboCoordinate->addItem("Yup RH"); // RUF
539 ui.comboCoordinate->addItem("Zup RH"); // FRU
540 ui.comboCoordinate->addItem("Xup RH"); // UFR
541 ui.comboCoordinate->addItem("Yup LH"); // RUB
542 ui.comboCoordinate->addItem("Zup LH"); // BRU
543 ui.comboCoordinate->addItem("Xup LH"); // UBR
544 ui.comboCoordinate->blockSignals(false);
547 void FormMain::Initialize2DViewSrcCombobox(void)
549 ui.combo2DViewSrcType->blockSignals(true);
550 ui.combo2DViewSrcType->addItem("Color");
551 ui.combo2DViewSrcType->addItem("Normal");
552 ui.combo2DViewSrcType->blockSignals(false);
555 void FormMain::InitializeStatusBar(void)
557 m_StatusBar0 = new QLabel(this);
558 m_StatusBar1 = new QLabel(this);
559 ui.statusBar->addWidget(m_StatusBar0, 1);
560 ui.statusBar->addWidget(m_StatusBar1, 0);
562 m_StatusBar0->setText("");
564 m_StatusBar1->setMinimumWidth(290);
565 m_StatusBar1->setText("");
568 void FormMain::InitializeFromConfigFiles(void)
570 if (!InitializeConfig(PathInfo::GetGuiConfigFilePath()))
572 InitializeConfig(PathInfo::GetDefaultGuiConfigFilePath());
575 ui.widgetCamera->OpenCameraFile(PathInfo::GetCameraLogFilePath());
577 if (!LoadWindowLayout(PathInfo::GetWindowLayoutConfigFilePath()))
579 LoadWindowLayout(PathInfo::GetDefaultWindowLayoutConfigFilePath());
582 if (!QGui::LoadGUIState(this, PathInfo::GetLayoutConfigFilePath()))
584 QGui::LoadGUIState(this, PathInfo::GetDefaultLayoutConfigFilePath());
588 void FormMain::LoadDefaultConfig(void)
590 InitializeConfig(PathInfo::GetDefaultGuiConfigFilePath());
591 QGui::LoadGUIState(this, PathInfo::GetDefaultLayoutConfigFilePath());
592 LoadWindowLayout(PathInfo::GetDefaultWindowLayoutConfigFilePath());
595 void FormMain::SaveConfig(void)
597 PathInfo::CreateConfiDirIfNotExist();
599 SaveConfigFile(PathInfo::GetGuiConfigFilePath());
601 m_View3d.m_CameraRecord.SaveCamera(PathInfo::GetCameraLogFilePath().toLocal8Bit().data());
603 QGui::SaveGUIState(this, PathInfo::GetLayoutConfigFilePath());
605 SaveWindowLayout(PathInfo::GetWindowLayoutConfigFilePath());
608 bool FormMain::InitializeConfig(QString path)
610 View3DConfig& config_3d = m_View3d.m_Config;
613 cfg.m_Config3D = &config_3d;
614 cfg.m_Scene = &m_Scene;
616 if (!cfg.LoadConfigT(path.toLocal8Bit().data()))
619 ui.actionUVAutoFit->setChecked(cfg.m_AutFitUVView);
621 ui.comboCoordinate->setCurrentIndex(cfg.m_CoordType);
623 CreateRecentFilesMenu(cfg.m_RecentFiles);
625 m_Binder_ViewConfig.UpdateAllGUI(true);
626 m_Binder_UVConfig.UpdateAllGUI(true);
627 m_Binder_Scene.UpdateAllGUI(true);
628 m_Binder_Cursor.UpdateAllGUI(true);
629 m_Binder_TexConfig.UpdateAllGUI(true);
630 SyncTexConfigToGUI(true);
632 ApplyGeomStateDataoToGUI();
634 SyncViewSettingsFromGUI();
635 m_Binder_UVConfig.UpdateAllData();
636 m_Binder_TexConfig.UpdateAllData();
637 SyncTexConfigToData();
638 SyncShaderSettingsToGUI();
640 ui.widgetIOOption->setConfig(m_Scene.m_IOConfig);
644 m_EnableAllFeatures = cfg.m_EnableAllFeatures;
649 void FormMain::SaveConfigFile(QString path)
652 cfg.m_Config3D = &m_View3d.m_Config;
653 cfg.m_Scene = &m_Scene;
655 ui.widgetIOOption->getConfig(m_Scene.m_IOConfig);
657 cfg.m_EnableAllFeatures = m_EnableAllFeatures;
659 cfg.m_AutFitUVView = ui.actionUVAutoFit ->isChecked();
661 cfg.m_CoordType = ui.comboCoordinate->currentIndex();
663 CreateRecentFilesFromMenu(cfg.m_RecentFiles);
665 cfg.SaveConfigT(path.toLocal8Bit().data());
669 void FormMain::InitializeSubDlg(void)
673 SIGNAL(currentColorChanged(const QColor &)),
675 SLOT(WireOverlayColorChanged(const QColor &)));
677 &m_DiffuseColorSelDlg,
678 SIGNAL(currentColorChanged(const QColor &)),
680 SLOT(FaceDiffuseColorChanged(const QColor &)));
683 SIGNAL(currentColorChanged(const QColor &)),
685 SLOT(BGColorChanged(const QColor &)));
687 &m_SelMatColorSelDlg,
688 SIGNAL(currentColorChanged(const QColor &)),
690 SLOT(SelMatColorChanged(const QColor &)));
692 m_SelMatColorWidget = NULL;
694 m_ViewConfigDlg.InitializeConfigDlg(&m_View3d.m_Config);
697 SIGNAL(ConfigChanged()),
699 SLOT(ConfigChangedDlg_ConfigChanged()));
701 m_CrossSectionDlg.InitializeConfigDlg(&m_View3d);
704 SIGNAL(ConfigChanged()),
706 SLOT(CrossSectionDlg_ConfigChanged()));
709 void FormMain::InitializeAnimation(void)
715 SLOT(OnAnimationTimerUpdated()));
716 m_AnimationTimer.setInterval(20);
719 void FormMain::InitializeMenu(void)
721 m_AGroup_Window = new QActionGroup(this);
722 m_AGroup_Window->setExclusive(true);
723 m_AGroup_Window->addAction( ui.actionWindow_3DView );
724 m_AGroup_Window->addAction( ui.actionWindow_UVView );
725 m_AGroup_Window->addAction( ui.actionWindows_DualView );
727 m_AGroup_Shader = new QActionGroup(this);
728 m_AGroup_Shader->setExclusive(true);
729 m_AGroup_Shader->addAction( ui.actionShaderDefault );
730 m_AGroup_Shader->addAction( ui.actionShaderPhong );
731 m_AGroup_Shader->addAction( ui.actionShaderCustom );
732 m_AGroup_Shader->addAction( ui.actionNormalColor );
733 m_AGroup_Shader->addAction( ui.actionDepthColor );
734 m_AGroup_Shader->addAction( ui.actionShadowmap );
735 m_AGroup_Shader->addAction( ui.actionEnvmap );
736 m_AGroup_Shader->addAction( ui.actionIntegrateShader );
737 m_AGroup_Shader->addAction( ui.actionMatcapShader );
739 m_AGroup_PProc = new QActionGroup(this);
740 m_AGroup_PProc->addAction( ui.actionPostProcNone );
741 m_AGroup_PProc->addAction( ui.actionPostProcAntialias );
742 m_AGroup_PProc->addAction( ui.actionPostProcBorder );
743 m_AGroup_PProc->addAction( ui.actionPostProcDepthLayerColor );
744 m_AGroup_PProc->addAction( ui.actionPostProcDepthColor );
745 m_AGroup_PProc->addAction( ui.actionPostProcDepthOfField );
747 m_AGroup_Texture = new QActionGroup(this);
748 m_AGroup_Texture->addAction( ui.actionTextureMipmap );
749 m_AGroup_Texture->addAction( ui.actionTextureNearest );
750 m_AGroup_Texture->addAction( ui.actionTextureLinear );
753 void FormMain::InitContextMenu(void)
755 ui.widgetObjectList->RegisterContextMenu();
758 void FormMain::ProcArguments(void)
760 QStringList args = QApplication::arguments();
761 for (int i = 1; i < args.size(); ++i)
764 OpenGeomFileToLast(s);
768 void FormMain::closeEvent(QCloseEvent *e)
776 m_ViewConfigDlg.close();
777 m_CrossSectionDlg.close();
778 m_FullscreenPanel.close();
780 if (m_CustomShaderDlg != NULL)
781 m_CustomShaderDlg->close();
782 if (m_PyScriptDlg != NULL)
783 m_PyScriptDlg->close();
785 if (m_MatcapDlg != NULL)
786 m_MatcapDlg->close();
787 if (m_EnvmapDlg != NULL)
788 m_EnvmapDlg->close();
789 if (m_MatPresetDlg != NULL)
790 m_MatPresetDlg->close();
792 m_ContextShare.BeginDrawTop();
793 m_Scene.FinalizeScene();
794 m_ContextShare.EndDrawTop();
798 bool FormMain::eventFilter(QObject * filterobj, QEvent * filterevt)
800 if (filterobj == ui.editEnvMap)
802 if (filterevt->type() == QEvent::DragEnter)
803 return AcceptDropFilterIfUrl(filterevt);
805 if (filterevt->type() == QEvent::Drop)
806 return OnDropFile_editEnvMap(filterevt);
808 else if (filterobj == ui.editMatcap)
810 if (filterevt->type() == QEvent::DragEnter)
811 return AcceptDropFilterIfUrl(filterevt);
813 if (filterevt->type() == QEvent::Drop)
814 return OnDropFile_editMatcap(filterevt);
816 else if (filterobj == ui.editMatCapEachMaterial)
818 if (filterevt->type() == QEvent::DragEnter)
819 return AcceptDropFilterIfUrl(filterevt);
821 if (filterevt->type() == QEvent::Drop)
822 return OnDropFile_editMatcapEachMat(filterevt);
824 else if (filterobj == ui.editCurrentTexName)
826 if (filterevt->type() == QEvent::DragEnter)
827 return AcceptDropFilterIfUrl(filterevt);
829 if (filterevt->type() == QEvent::Drop)
830 return OnDropFile_editCurrentTexName(filterevt);
832 else if (filterobj == ui.editCurrentMatNormalMap)
834 if (filterevt->type() == QEvent::DragEnter)
835 return AcceptDropFilterIfUrl(filterevt);
837 if (filterevt->type() == QEvent::Drop)
838 return OnDropFile_editCurrentMatNormalMap(filterevt);
840 else if (filterobj == ui.colorAmbient)
842 if (filterevt->type() == QEvent::MouseButtonPress)
843 return colorAmbient_OnButtonDown(filterevt);
845 else if (filterobj == ui.colorEmission)
847 if (filterevt->type() == QEvent::MouseButtonPress)
848 return colorEmission_OnButtonDown(filterevt);
850 else if (filterobj == ui.colorDiffuse)
852 if (filterevt->type() == QEvent::MouseButtonPress)
853 return colorDiffuse_OnButtonDown(filterevt);
855 else if (filterobj == ui.colorSpecular)
857 if (filterevt->type() == QEvent::MouseButtonPress)
858 return colorSpecular_OnButtonDown(filterevt);
861 return QMainWindow::eventFilter(filterobj, filterevt);
864 bool FormMain::OnDropFile_editEnvMap(QEvent * filterevt)
866 QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
873 bool FormMain::OnDropFile_editMatcap(QEvent * filterevt)
875 QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
877 LoadMatcapImage(path);
882 bool FormMain::OnDropFile_editMatcapEachMat(QEvent * filterevt)
884 QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
886 LoadMatcapImageForCurrentMat(path);
891 bool FormMain::OnDropFile_editCurrentTexName(QEvent * filterevt)
893 QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
895 LoadCurSelMatTexture(TextureType::Color, path);
900 bool FormMain::OnDropFile_editCurrentMatNormalMap(QEvent * filterevt)
902 QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
904 LoadCurSelMatTexture(TextureType::Normal, path);
909 bool FormMain::AcceptDropFilterIfUrl(QEvent * filterevt)
911 QDragEnterEvent* e = dynamic_cast<QDragEnterEvent*>(filterevt);
915 if (e->mimeData()->hasUrls())
916 e->acceptProposedAction();
921 QString FormMain::GetFirstLoadableImagePathFromDragEvent(QEvent* filterevt)
923 QDropEvent* e = dynamic_cast<QDropEvent*>(filterevt);
927 if (!e->mimeData()->hasUrls())
930 QList<QUrl> urls = e->mimeData()->urls();
931 for (QUrl& url : urls)
933 QString path = url.toLocalFile();
934 if (IsSupportedTextureExt(path))
941 bool FormMain::colorAmbient_OnButtonDown(QEvent * filterevt)
943 QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
944 if (e->buttons() == Qt::LeftButton)
945 ChangeMatlemColor(ui.colorAmbient);
949 bool FormMain::colorEmission_OnButtonDown(QEvent * filterevt)
951 QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
952 if (e->buttons() == Qt::LeftButton)
953 ChangeMatlemColor(ui.colorEmission);
957 bool FormMain::colorDiffuse_OnButtonDown(QEvent * filterevt)
959 QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
960 if (e->buttons() == Qt::LeftButton)
961 ChangeMatlemColor(ui.colorDiffuse);
965 bool FormMain::colorSpecular_OnButtonDown(QEvent * filterevt)
967 QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
968 if (e->buttons() == Qt::LeftButton)
969 ChangeMatlemColor(ui.colorSpecular);
973 void FormMain::ChangeMatlemColor(QWidget* col_widget)
975 lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
979 lgr::color4f* col = NULL;
980 if (col_widget == ui.colorAmbient ) col = &mat->m_Ambient ;
981 if (col_widget == ui.colorEmission ) col = &mat->m_Emission ;
982 if (col_widget == ui.colorDiffuse ) col = &mat->m_Diffuse ;
983 if (col_widget == ui.colorSpecular ) col = &mat->m_Specular ;
985 lgr::color4f src = *col;
987 QColor dc = ToQColor(*col);
989 m_SelMatColorWidget = col_widget;
991 m_SelMatColorSelDlg.setOption(QColorDialog::ShowAlphaChannel);
992 m_SelMatColorSelDlg.setCurrentColor(dc);
993 if (m_SelMatColorSelDlg.exec() == QDialog::Rejected)
996 SetColorPalleteBG(col_widget, dc);
1001 void FormMain::CenteringSplitter(void)
1003 int w = ui.splitter->width();
1007 ui.splitter->setSizes(s);
1010 void FormMain::updateView_All(void)
1016 void FormMain::updateView_2D(void)
1018 ui.GLWidgetUV->update();
1021 void FormMain::updateView_3D(void)
1023 ui.GLWidgetMain->update();
1026 void FormMain::on_actionOpen_triggered()
1028 FileDlgFilterList exts;
1029 exts.Add( "Wavefront" , "obj" );
1030 exts.Add( "STL" , "stl" );
1031 exts.Add( "PLY" , "ply" );
1032 exts.Add( "Metasequoia" , "mqo" );
1033 exts.Add( "Pmd" , "pmd" );
1034 exts.Add( "Collada" , "dae" );
1035 exts.Add( "DirectX" , "x" );
1037 QString filter = FileDlgUtil::ExtListToDlgFilter("Geometry", exts);
1038 QString title = "Open file";
1039 QString fileName = GetFilePathFromOpenDlg(title, filter);
1041 if (fileName.isEmpty())
1044 if (IsResetSceneOnBeforeLoadFile())
1047 if (OpenGeomFileToLast(fileName))
1051 void FormMain::on_actionExit_triggered()
1056 void FormMain::actionVisibleStates_Triggered(bool checked)
1058 QAction* a = dynamic_cast<QAction*>(QObject::sender());
1061 if (a == ui.actionIndexColorMode)
1063 ui.actionFixMaterialSilver->setChecked(false);
1064 ui.actionFBMaterial->setChecked(false);
1066 else if (a == ui.actionFixMaterialSilver)
1068 ui.actionIndexColorMode->setChecked(false);
1069 ui.actionFBMaterial->setChecked(false);
1071 else if (a == ui.actionFBMaterial)
1073 ui.actionFixMaterialSilver->setChecked(false);
1074 ui.actionIndexColorMode->setChecked(false);
1078 SyncViewSettingsFromGUI();
1082 void FormMain::SyncViewSettingsFromGUI(void)
1084 m_Binder_ViewConfig.UpdateAllData();
1086 QAction* menu = GetMenuFromShader(m_View3d.m_Config.m_ShaderMode);
1088 menu->setChecked(true);
1091 QAction* FormMain::GetMenuFromShader(ShaderType type)
1093 switch(m_View3d.m_Config.m_ShaderMode)
1095 case ShaderType::Phong : return ui.actionShaderPhong;
1096 case ShaderType::Custom : return ui.actionShaderCustom;
1097 case ShaderType::NormalColor: return ui.actionNormalColor;
1098 case ShaderType::DepthColor : return ui.actionDepthColor;
1099 case ShaderType::Shadowmap : return ui.actionShadowmap;
1100 case ShaderType::Envmap : return ui.actionEnvmap;
1101 case ShaderType::Integrate : return ui.actionIntegrateShader;
1102 case ShaderType::Matcap : return ui.actionMatcapShader;
1103 case ShaderType::Default : return ui.actionShaderDefault;
1111 bool FormMain::SaveWindowLayout(const QString& filepath)
1113 WindowConfig config;
1115 config.m_MainWinLeft = geometry().x();
1116 config.m_MainWinTop = geometry().y();
1117 config.m_MainWinWidth = geometry().width();
1118 config.m_MainWinHeight = geometry().height();
1119 config.m_IsMaximized = isMaximized();
1121 return config.SaveConfig(filepath.toLocal8Bit().data());
1124 bool FormMain::LoadWindowLayout(const QString& filepath)
1126 WindowConfig config;
1127 if (!config.LoadConfig(filepath.toLocal8Bit().data()))
1130 if (config.m_IsMaximized)
1133 int l = config.m_MainWinLeft;
1134 int t = config.m_MainWinTop;
1135 int w = config.m_MainWinWidth;
1136 int h = config.m_MainWinHeight;
1137 setGeometry(l, t, w, h);
1142 void FormMain::actionVisibleStatesUV_Triggered(bool)
1144 m_Binder_UVConfig.UpdateAllData();
1148 void FormMain::actionVisibleStatesTex_Triggered(bool)
1150 m_Binder_TexConfig.UpdateAllData();
1154 void FormMain::actionSceneStates_Toggled(bool)
1156 m_Binder_Scene.UpdateAllData();
1160 void FormMain::on_actionWindow_ToolBarView_triggered(bool checked)
1162 ui.toolBar_View->setVisible( ui.actionWindow_ToolBarView->isChecked() );
1165 void FormMain::on_actionToolBar_Options_toggled(bool checked)
1167 ui.toolBar_Option->setVisible(checked);
1170 void FormMain::on_actionToolBar_Operation_toggled(bool checked)
1172 ui.toolBar_Operation->setVisible(checked);
1175 void FormMain::on_actionCameraDist_triggered()
1177 m_View3d.AdjustCameraDistAuto();
1180 void FormMain::on_actionCameraFront_triggered()
1182 m_View3d.MoveCaemraTo(ViewPoint::Front);
1185 void FormMain::on_actionCameraBack_triggered()
1187 m_View3d.MoveCaemraTo(ViewPoint::Back);
1190 void FormMain::on_actionCameraLeft_triggered()
1192 m_View3d.MoveCaemraTo(ViewPoint::Left);
1195 void FormMain::on_actionCameraRight_triggered()
1197 m_View3d.MoveCaemraTo(ViewPoint::Right);
1200 void FormMain::on_actionCameraTop_triggered()
1202 m_View3d.MoveCaemraTo(ViewPoint::Top);
1205 void FormMain::on_actionCameraBottom_triggered()
1207 m_View3d.MoveCaemraTo(ViewPoint::Bottom);
1210 void FormMain::on_actionCameraPers_triggered()
1212 m_View3d.MoveCaemraTo(ViewPoint::Perse);
1215 void FormMain::on_actionCameraLookOrigin_triggered()
1217 m_View3d.MoveLookPosToOrigin();
1220 void FormMain::on_actionCameraLookCenter_triggered()
1222 m_View3d.MoveLookPosToCenter();
1225 void FormMain::on_actionWindow_3DView_triggered(bool checked)
1227 UpdateViewTypeFromMenu();
1230 void FormMain::on_actionWindows_DualView_triggered(bool checked)
1232 UpdateViewTypeFromMenu();
1235 void FormMain::on_actionWindow_UVView_triggered(bool checked)
1237 UpdateViewTypeFromMenu();
1240 void FormMain::UpdateViewTypeFromMenu(void)
1242 if (ui.actionWindows_DualView->isChecked())
1244 ui.frameView3D->setVisible(true);
1245 ui.frameView2D->setVisible(true);
1247 // TODO:
\89¼.
\8bN
\93®
\8e\9e\82É
\83r
\83\85\81[
\82ð1:1
\82É
\90Ý
\92è
\82Å
\82«
\82È
\82¢
\96â
\91è
\82Ì
\89¼
\91Î
\89\9e.
1248 static bool firsttime = true;
1252 CenteringSplitter();
1255 if (ui.actionWindow_3DView->isChecked())
1257 ui.frameView3D->setVisible(true);
1258 ui.frameView2D->setVisible(false);
1260 if (ui.actionWindow_UVView->isChecked())
1262 ui.frameView3D->setVisible(false);
1263 ui.frameView2D->setVisible(true);
1267 void FormMain::on_actionWindowMaterialList_triggered()
1269 ShowAndActivateAndRaise(ui.dockMaterial);
1270 ui.listMaterial->setFocus();
1273 void FormMain::on_actionWindowObjectList_triggered()
1275 ShowAndActivateAndRaise(ui.dockObject);
1276 ui.widgetObjectList->focusList();
1279 void FormMain::on_actionWindowCameraList_triggered()
1281 ShowAndActivateAndRaise(ui.dockCamera);
1282 ui.widgetCamera->focusList();
1285 void FormMain::on_actionWindowScenePanel_triggered()
1287 ShowAndActivateAndRaise(ui.dockScene);
1290 void FormMain::on_actionCursorPanel_triggered()
1292 ShowAndActivateAndRaise(ui.dockCursor);
1295 void FormMain::on_actionIOOptionPanel_triggered()
1297 ShowAndActivateAndRaise(ui.dockIOOption);
1300 void FormMain::on_listMaterial_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
1302 MeshBuf* mbuf = m_Scene.GetSelOrFirstMeshbuf();
1306 int idx = ui.listMaterial->currentRow();
1307 mbuf->SetSelMatIdx(idx);
1308 OnChangedSelectedMaterial();
1312 void FormMain::ShowAndActivateAndRaise(QDockWidget* widget)
1314 widget->setVisible(true);
1315 widget->activateWindow();
1319 void FormMain::OnChangedSelectedMaterial(void)
1326 ui.editCurrentTexName->clear();
1328 GeomTextureSet* ts = m_Scene.GetSelectedTexture();
1331 ui.editCurrentTexName->setText("");
1332 ui.editMatCapEachMaterial->setText("");
1336 QString name_c, name_n;
1338 gl::GlTexture* tex_c = ts->GetTexColor();
1340 name_c = QString::fromLocal8Bit(tex_c->GetName().c_str());
1342 gl::GlTexture* tex_n = ts->GetTexNormal();
1344 name_n = QString::fromLocal8Bit(tex_n->GetName().c_str());
1346 ui.editCurrentTexName->setText(name_c);
1347 ui.editCurrentMatNormalMap->setText(name_n);
1349 MatcapImage& matcap = ts->TexMatcap;
1350 ui.editMatCapEachMaterial->setText(matcap.GetName());
1353 lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
1356 SetColorPalleteBG(ui.colorAmbient , ToQColor(mat->m_Ambient));
1357 SetColorPalleteBG(ui.colorEmission , ToQColor(mat->m_Emission));
1358 SetColorPalleteBG(ui.colorDiffuse , ToQColor(mat->m_Diffuse));
1359 SetColorPalleteBG(ui.colorSpecular , ToQColor(mat->m_Specular));
1360 SetMatShininessSliderPos(mat->m_Shininess);
1364 QColor w(255, 255, 255);
1365 SetColorPalleteBG( ui.colorAmbient , w );
1366 SetColorPalleteBG( ui.colorEmission , w );
1367 SetColorPalleteBG( ui.colorDiffuse , w );
1368 SetColorPalleteBG( ui.colorSpecular , w );
1369 SetMatShininessSliderPos(0);
1375 void FormMain::SetMatShininessSliderPos(float shininess)
1377 int val_max = ui.sliderShininess->maximum();
1378 int slider_pos = (int)(shininess * (float)val_max / 200.0f);
1379 slider_pos = (lm::min)(val_max, slider_pos);
1380 ui.sliderShininess->blockSignals(true);
1381 ui.sliderShininess->setValue(slider_pos);
1382 ui.sliderShininess->blockSignals(false);
1383 ui.labelShininessVal->setText(QString::number(shininess, 'f', 2));
1386 void FormMain::keyPressEvent(QKeyEvent *e)
1389 if (m.Flag_C() && e->key() == Qt::Key_Tab)
1395 void FormMain::FocusNextSubDlg(void)
1397 std::vector<QDockWidget*> widgets;
1399 if (ui.dockObject ->isVisible()) widgets.push_back( ui.dockObject );
1400 if (ui.dockCamera ->isVisible()) widgets.push_back( ui.dockCamera );
1401 if (ui.dockScene ->isVisible()) widgets.push_back( ui.dockScene );
1402 if (ui.dockMaterial ->isVisible()) widgets.push_back( ui.dockMaterial );
1404 if (widgets.empty())
1407 QDockWidget* next_widget = NULL;
1409 for (size_t i = 0; i < widgets.size(); ++i)
1411 if (widgets[i] == m_LastFocusedDockDlg)
1413 next_widget = widgets[(i + 1) % widgets.size()];
1418 if (next_widget == NULL)
1419 next_widget = widgets.front();
1421 m_LastFocusedDockDlg = next_widget;
1423 next_widget->activateWindow();
1424 next_widget->raise();
1425 next_widget->setFocus();
1428 void FormMain::dragEnterEvent(QDragEnterEvent* e)
1430 if (e->mimeData()->hasUrls())
1431 e->acceptProposedAction();
1434 void FormMain::dropEvent(QDropEvent* e)
1436 if (e->mimeData()->hasUrls())
1438 QList<QUrl> urls = e->mimeData()->urls();
1440 std::vector<QString> geom_files;
1442 for (QUrl& url : urls)
1444 QString path = url.toLocalFile();
1445 if (FormatType::IsGeomFileExt(path))
1446 geom_files.push_back(path);
1449 if (!geom_files.empty())
1451 if (IsResetSceneOnBeforeLoadFile())
1454 for (QString& f : geom_files)
1456 if (OpenGeomFileToLast(f))
1461 for (QUrl& url : urls)
1463 QString path = url.toLocalFile();
1465 if (IsSupportedTextureExt(path))
1467 DropTextureFile(path, e->pos());
1471 if (IsCameraFile(path))
1473 ui.widgetCamera->OpenCameraFile(path);
1480 bool FormMain::IsResetSceneOnBeforeLoadFile(void) const
1482 if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
1488 //!
\83I
\83u
\83W
\83F
\83N
\83g
\82É
\89æ
\91\9c\82ð
\83h
\83\8d\83b
\83v
\82³
\82ê
\82½
\8fê
\8d\87\82Í
\82»
\82Ì
\83}
\83e
\83\8a\83A
\83\8b\82Ì
\83J
\83\89\81[
\83e
\83N
\83X
\83`
\83\83\82ð
\83Z
\83b
\83g
1489 //!
\89½
\82à
\96³
\82¢
\8fê
\8f\8a\82É
\83h
\83\8d\83b
\83v
\82³
\82ê
\82é
\82Æ
\83f
\83t
\83H
\83\8b\83g
\83e
\83N
\83X
\83`
\83\83\82ð
\83Z
\83b
\83g
1490 void FormMain::DropTextureFile(const QString& path, const QPoint& pos)
1492 std::string fname = path.toLocal8Bit().data();
1494 QPoint pl = ui.GLWidgetMain->mapFrom(this, pos);
1496 PickedMeshSubface picked;
1497 m_View3d.BeginRender();
1498 bool suc = m_View3d.PickFace2D(picked, pl.x(), pl.y());
1499 m_View3d.EndRender();
1503 m_View3d.BeginRender();
1504 MeshBuf* mbuf = picked.mbuf;
1505 lib_geo::BaseFace& f = mbuf->m_Mesh.m_Faces[picked.subf.fid];
1506 GeomTextureSet* ts = mbuf->GetTexture(f.m_MatIdx);
1509 std::string fp = path.toLocal8Bit().data();
1511 QString name_qs = QFileInfo(path).fileName();
1512 std::string name = name_qs.toLocal8Bit().data();
1514 mbuf->ReleaseTextureUnit(ts, TextureType::Color);
1515 gl::GlTexture* tex = mbuf->GetInitTexture(fp, name, m_Scene.m_TexConfig);
1516 ts->SetTextureUnit(TextureType::Color, tex);
1518 m_View3d.EndRender();
1522 m_ContextShare.BeginDrawTop();
1523 m_Scene.LoadDefaultMatTexture(fname);
1524 m_ContextShare.EndDrawTop();
1530 bool FormMain::OpenGeomFileToLast(const QString& path)
1532 ui.widgetIOOption->getConfig(m_Scene.m_IOConfig);
1534 m_ContextShare.BeginDrawTop();
1539 m_Scene.ImportFileAutoFmt(path);
1541 catch(const FileLoadErrorException& ex)
1544 msg += "Failed Load ";
1545 msg += path + "\n\n";
1546 msg += QString::fromLocal8Bit(ex.what());
1548 QMessageBox::warning(this, "", msg);
1552 m_ContextShare.EndDrawTop();
1555 ui.widgetObjectList->OnDoneAddGeom();
1557 ResetSequenceSliderRange();
1564 AddRecentFile(path);
1569 void FormMain::ClearAllObjects(void)
1571 m_ContextShare.BeginDrawTop();
1573 m_Scene.ClearObjects();
1575 m_ContextShare.EndDrawTop();
1577 m_View3d.ClearRenderMap();
1579 ui.widgetObjectList->ClearTree();
1580 RefreshObjectSelectState();
1586 bool FormMain::IsCameraFile(const QString& path) const
1588 QFileInfo fInfo( path );
1589 QString ext = fInfo.suffix().toLower();
1590 return (ext == "camera");
1594 void FormMain::actionGeomStates_Triggered(bool)
1596 ApplyGeomStateFromGUI();
1598 m_Scene.UpdateTransform();
1603 void FormMain::ApplyGeomStateFromGUI(void)
1605 m_Scene.m_Config.m_EnableAutoCentering = ui.actionCentering->isChecked();
1606 m_Scene.m_Config.m_EnableAutoReisze = ui.actionAutoResize->isChecked();
1609 void FormMain::ApplyGeomStateDataoToGUI(void)
1611 ui.actionAutoResize ->setChecked( m_Scene.m_Config.m_EnableAutoReisze );
1612 ui.actionCentering ->setChecked( m_Scene.m_Config.m_EnableAutoCentering );
1614 ui.widgetObjectList->applyConfig();
1617 void FormMain::on_actionGeomClear_triggered()
1623 void FormMain::on_actionUVFitView_triggered()
1629 void FormMain::on_actionSelObjectDelete_triggered()
1631 DeleteSelectedObject();
1634 void FormMain::RebuildAllGLBuf(void)
1636 ui.GLWidgetMain->makeCurrent();
1637 std::vector<MeshBuf*> mv = m_Scene.GetCurSelMeshes();
1638 for (MeshBuf* m : mv)
1640 m_View3d.ReleaseRenderbuffer(m);
1642 ui.GLWidgetMain->doneCurrent();
1647 void FormMain::on_actionShowOnlySelected_triggered()
1649 ShowObjectOnlySelected();
1653 void FormMain::on_actionAddSample_triggered()
1655 SampleShapeBuilder::CreateSphere(m_Scene);
1656 ui.widgetObjectList->OnDoneAddGeom();
1658 ResetSequenceSliderRange();
1663 void FormMain::on_actionAddGroundPlane_triggered()
1665 SampleShapeBuilder::CreateGroundPlane(m_Scene);
1666 ui.widgetObjectList->OnDoneAddGeom();
1668 ResetSequenceSliderRange();
1673 void FormMain::on_actionShaderDefault_triggered(bool)
1675 ChangeShaderMenuMain(ShaderType::Default);
1678 void FormMain::on_actionShaderPhong_triggered(bool)
1680 ChangeShaderMenuMain(ShaderType::Phong);
1683 void FormMain::on_actionShaderCustom_triggered(bool)
1685 ChangeShaderMenuMain(ShaderType::Custom);
1688 void FormMain::on_actionNormalColor_triggered(bool)
1690 ChangeShaderMenuMain(ShaderType::NormalColor);
1693 void FormMain::on_actionDepthColor_triggered(bool)
1695 ChangeShaderMenuMain(ShaderType::DepthColor);
1698 void FormMain::on_actionShadowmap_triggered(bool)
1700 ChangeShaderMenuMain(ShaderType::Shadowmap);
1703 void FormMain::on_actionEnvmap_triggered(bool)
1705 ChangeShaderMenuMain(ShaderType::Envmap);
1708 void FormMain::on_actionIntegrateShader_triggered(bool)
1710 ChangeShaderMenuMain(ShaderType::Integrate);
1713 void FormMain::on_actionMatcapShader_triggered(bool)
1715 ChangeShaderMenuMain(ShaderType::Matcap);
1718 void FormMain::SyncShaderSettingsToGUI(void)
1720 ChangeShaderMenuMain(m_View3d.m_Config.m_ShaderMode);
1723 void FormMain::ChangeShaderMenuMain(ShaderType type)
1725 m_View3d.m_Config.m_ShaderMode = type;
1729 void FormMain::CreateSampleTextureMain(SampleTextureBuilder::TextureType tex_type)
1731 m_ContextShare.BeginDrawTop();
1732 m_Scene.CreateSampleTexture(tex_type);
1733 m_ContextShare.EndDrawTop();
1738 bool FormMain::IsAutUVFit(void) const
1740 return ui.actionUVAutoFit->isChecked();
1744 void FormMain::RefreshObjectSelectState(void)
1746 ui.widgetObjectList->SetPrimayrSelectObjectToScene();
1753 void FormMain::RebuildMatList(void)
1755 MeshBuf* mbuf = m_Scene.GetSelOrFirstMeshbuf();
1757 QListWidget* list_mat = ui.listMaterial;
1759 list_mat->blockSignals(true);
1764 const lib_geo::BaseMesh& mesh = mbuf->m_Mesh;
1765 for (const lib_geo::BaseMaterial& mat : mesh.m_Materials)
1767 const std::string& name = mat.m_Name;
1770 list_mat->addItem("--");
1772 list_mat->addItem(QString::fromLocal8Bit(name.c_str()));
1776 list_mat->blockSignals(false);
1780 mbuf->SelectMatAuto();
1781 list_mat->setCurrentRow(mbuf->GetSelMatIdx());
1785 list_mat->setCurrentRow(-1);
1788 OnChangedSelectedMaterial();
1792 void FormMain::DeleteSelectedObject()
1794 int sel_idx = ui.widgetObjectList->getSelObjIdx();
1798 m_ContextShare.BeginDrawTop();
1800 m_Scene.RemoveItem(sel_idx);
1802 m_ContextShare.EndDrawTop();
1804 m_View3d.ClearRenderMap();
1806 ui.widgetObjectList->removeObject(sel_idx);
1808 int sel_idx2 = ui.widgetObjectList->getSelObjIdxWhenSelObjNode();
1810 m_Scene.m_Sels.SelectObject(sel_idx2);
1812 m_Scene.UpdateTransform();
1814 RefreshObjectSelectState();
1816 ResetSequenceSliderRange();
1821 void FormMain::ShowObjectOnlySelected(void)
1823 GeomObject* sel_obj = m_Scene.GetPrimaryObject();
1824 if (sel_obj == NULL)
1827 for (GeomObject& o : m_Scene.m_Objects)
1829 o.m_Visible = (sel_obj == &o);
1832 ui.widgetObjectList->SyncViewMark();
1836 void FormMain::on_actionUVResetView_triggered()
1838 m_View2d.ResetView();
1844 //!
\83\8f\83C
\83\84\81[
\83I
\81[
\83o
\81[
\83\8c\83C
\95\
\8e¦
\8e\9e\82Ì
\90F
\90Ý
\92è
1845 void FormMain::on_actionWireColor_triggered()
1847 m_WireColorSelDlg.exec();
1850 //!
\83f
\83t
\83H
\83\8b\83g
\83}
\83e
\83\8a\83A
\83\8b\82Ì
\90F
\90Ý
\92è
1851 void FormMain::on_actionFaceColor_triggered()
1853 const lgr::color4f& c = m_Scene.m_DefaultMaterial.m_Diffuse;
1855 m_DiffuseColorSelDlg.setOption(QColorDialog::ShowAlphaChannel);
1856 m_DiffuseColorSelDlg.setCurrentColor(ToQColor(c));
1857 m_DiffuseColorSelDlg.exec();
1860 //!
\94w
\8ci
\90F
\82Ì
\90Ý
\92è
1861 void FormMain::on_actionBackGroundColor_triggered()
1863 const lgr::color4f& c = m_View3d.m_BGColor;
1865 m_BGColorSelDlg.setCurrentColor(ToQColor(c));
1866 m_BGColorSelDlg.exec();
1869 void FormMain::WireOverlayColorChanged(const QColor & color)
1871 lgr::color3b& c = m_View3d.m_Config.m_WireColor;
1872 c.set(color.red(), color.green(), color.blue());
1874 m_View3d.ReleaseAllRenderBuffer();
1879 void FormMain::CopyRGB(lgr::color4f& c, const QColor & color)
1881 c.r() = (float)color.red() / 255.0f;
1882 c.g() = (float)color.green() / 255.0f;
1883 c.b() = (float)color.blue() / 255.0f;
1886 void FormMain::CopyRGBA(lgr::color4f& c, const QColor & color)
1888 c.r() = (float)color.red() / 255.0f;
1889 c.g() = (float)color.green() / 255.0f;
1890 c.b() = (float)color.blue() / 255.0f;
1891 c.a() = (float)color.alpha() / 255.0f;
1894 void FormMain::FaceDiffuseColorChanged(const QColor & color)
1896 lgr::color4f& c = m_Scene.m_DefaultMaterial.m_Diffuse;
1899 m_View3d.ReleaseAllRenderBuffer();
1903 void FormMain::BGColorChanged(const QColor & color)
1905 lgr::color4f& c = m_View3d.m_BGColor;
1911 void FormMain::SetSelectedMaterialColor(QColor col)
1913 lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
1917 if (m_SelMatColorWidget == ui.colorAmbient ) CopyRGBA(mat->m_Ambient , col);
1918 if (m_SelMatColorWidget == ui.colorEmission ) CopyRGBA(mat->m_Emission , col);
1919 if (m_SelMatColorWidget == ui.colorDiffuse ) CopyRGBA(mat->m_Diffuse , col);
1920 if (m_SelMatColorWidget == ui.colorSpecular ) CopyRGBA(mat->m_Specular , col);
1922 SetColorPalleteBG(m_SelMatColorWidget, col);
1925 void FormMain::SelMatColorChanged(const QColor & color)
1927 SetSelectedMaterialColor(color);
1928 m_View3d.ResetPrimaryObjectLists();
1933 void FormMain::on_actionWindowOptions_triggered()
1935 m_ViewConfigDlg.showNormal();
1936 m_ViewConfigDlg.show();
1937 m_ViewConfigDlg.activateWindow();
1940 void FormMain::on_actionWindowCustomShader_triggered()
1942 if (m_CustomShaderDlg == NULL)
1944 m_CustomShaderDlg = new FormCustomShader(this);
1945 m_CustomShaderDlg->SetShaderLibrary(&m_View3d.m_ShaderLib);
1946 m_CustomShaderDlg->SetParentWidget(ui.GLWidgetMain);
1947 m_CustomShaderDlg->LoadOrSetDefaultCode();
1950 SIGNAL(ShaderBuild()),
1952 SLOT(CustomShaderDlg_ShaderBuild()));
1955 m_CustomShaderDlg->showNormal();
1956 m_CustomShaderDlg->show();
1957 m_CustomShaderDlg->activateWindow();
1961 void FormMain::ConfigChangedDlg_ConfigChanged()
1963 m_View3d.ReleaseAllRenderBuffer();
1967 void FormMain::CrossSectionDlg_ConfigChanged()
1973 void FormMain::OnPaintImage(QPrinter *printer)
1975 QPainter painter(printer);
1977 QRect rect = painter.viewport();
1978 QSize size = this->size();
1979 size.scale(rect.size(), Qt::KeepAspectRatio);//
\8fc
\89¡
\94ä
\88Û
\8e\9d
1981 painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
1982 painter.setWindow(this->rect());
1984 this->render(&painter);
1987 void FormMain::on_actionPrint_triggered()
1992 void FormMain::on_actionPrintPreview_triggered()
1997 void FormMain::PrintImage(bool WithPreview)
1999 //QPrinter printer(QPrinter::ScreenResolution);
2000 QPrinter printer(QPrinter::ScreenResolution);
2004 QPrintPreviewDialog preview(&printer, this);
2005 preview.setWindowFlags( Qt::Window );
2008 SIGNAL(paintRequested(QPrinter *)),
2009 SLOT(OnPaintImage(QPrinter *)));
2011 preview.showMaximized();
2016 QPrintDialog printDialog(&printer, this);
2017 if (printDialog.exec() == QDialog::Accepted)
2018 OnPaintImage(&printer);
2023 void FormMain::on_actionSaveCamera_triggered()
2025 QString title = "camera";
2026 QString filter = "Camera File(*.camera)";
2027 QString fileName = GetFilePathFromSaveDlg(title, filter);
2028 if (fileName.isEmpty())
2031 m_View3d.m_CameraRecord.SaveCamera(fileName.toLocal8Bit().data());
2034 void FormMain::on_actionProjectionOrtho_triggered()
2036 ui.actionProjectionOrtho->setChecked(true);
2037 ui.actionProjectionPers->setChecked(false);
2039 m_Scene.m_Camera.m_ProjMode = gl::Camera::PROJ_ORTHO;
2044 void FormMain::on_actionProjectionPers_triggered()
2046 ui.actionProjectionPers->setChecked(true);
2047 ui.actionProjectionOrtho->setChecked(false);
2049 m_Scene.m_Camera.m_ProjMode = gl::Camera::PROJ_PERS;
2055 void FormMain::CustomShaderDlg_ShaderBuild()
2060 void FormMain::OnAnimationTimerUpdated()
2062 static const float rot_speed = 0.005f;
2064 if (ui.actionRotateCamera->isChecked())
2066 m_Scene.m_Camera.m_Manip.Tumble(rot_speed, 0.0f);
2067 UpdateCameraStatus();
2070 if (ui.actionRotateLight->isChecked())
2071 m_View3d.m_ControlLight.m_Position.rotate_y(rot_speed);
2073 if (ui.actionAnimation->isChecked())
2076 if (IsLastSequence())
2077 ui.actionAnimation->setChecked(false);
2079 else if (ui.actionAnimationRev->isChecked())
2082 if (IsTopSequence())
2083 ui.actionAnimationRev->setChecked(false);
2089 void FormMain::on_actionRotateCamera_toggled(bool checked)
2094 void FormMain::on_actionRotateLight_toggled(bool checked)
2099 void FormMain::on_actionAnimation_toggled(bool checked)
2103 ui.actionAnimationRev->setChecked(false);
2104 if (IsLastSequence())
2106 QSlider* s = ui.sliderSequence;
2111 ui.butonAnimationFwd->blockSignals(true);
2112 ui.butonAnimationFwd->setChecked(checked);
2113 ui.butonAnimationFwd->blockSignals(false);
2118 void FormMain::on_actionAnimationRev_toggled(bool checked)
2122 ui.actionAnimation->setChecked(false);
2123 if (IsTopSequence())
2125 QSlider* s = ui.sliderSequence;
2126 s->setValue(s->maximum());
2130 ui.butonAnimationRev->blockSignals(true);
2131 ui.butonAnimationRev->setChecked(checked);
2132 ui.butonAnimationRev->blockSignals(false);
2137 void FormMain::on_butonAnimationFwd_toggled(bool checked)
2139 ui.actionAnimation->setChecked(checked);
2142 void FormMain::on_butonAnimationRev_toggled(bool checked)
2144 ui.actionAnimationRev->setChecked(checked);
2147 void FormMain::UpdateAnimState(void)
2149 if (IsEnableAnimation())
2150 m_AnimationTimer.start();
2152 m_AnimationTimer.stop();
2155 bool FormMain::IsEnableAnimation(void)
2157 if (ui.actionRotateCamera->isChecked())
2159 if (ui.actionRotateLight->isChecked())
2161 if (ui.actionAnimation->isChecked())
2163 if (ui.actionAnimationRev->isChecked())
2169 void FormMain::on_actionCrossSectionDlg_triggered()
2171 m_CrossSectionDlg.showNormal();
2172 m_CrossSectionDlg.show();
2173 m_CrossSectionDlg.activateWindow();
2176 void FormMain::on_actionSelectNext_triggered()
2178 ui.widgetObjectList->AddSelectObjectIdx(1);
2181 void FormMain::on_actionSelectPrev_triggered()
2183 ui.widgetObjectList->AddSelectObjectIdx(-1);
2186 void FormMain::on_actionSwitchVisible_triggered()
2188 ui.widgetObjectList->FlipVisibleSelectedObject();
2191 void FormMain::on_actionHideAll_triggered()
2193 m_Scene.HideAllObject();
2195 ui.widgetObjectList->SyncViewMark();
2199 void FormMain::on_actionShowAll_triggered()
2201 m_Scene.ShowAllObject();
2203 ui.widgetObjectList->SyncViewMark();
2207 void FormMain::on_actionVertexBuilder_triggered()
2209 FormVertexBuilder builder;
2210 builder.CreateVertex(m_Scene);
2212 ui.widgetObjectList->RebuildObjectList();
2216 void FormMain::on_actionFullScreen_triggered()
2218 m_FullscreenPanel.ShowWidgetAsFullscreen(ui.splitter, ui.gridLayout_4);
2221 void FormMain::on_actionResetConfig_triggered()
2223 QString msg = QString::fromLocal8Bit("
\90Ý
\92è
\82ð
\83\8a\83Z
\83b
\83g
\82µ
\82Ü
\82·");
2224 if (QMessageBox::question(this, "", msg, QMessageBox::Ok|QMessageBox::Cancel) != QMessageBox::Ok)
2227 setGeometry(m_InitRect);
2229 LoadDefaultConfig();
2231 SyncViewSettingsFromGUI();
2232 m_Binder_UVConfig.UpdateAllData();
2233 m_Binder_TexConfig.UpdateAllData();
2234 SyncTexConfigToData();
2235 ApplyGeomStateFromGUI();
2236 SyncShaderSettingsToGUI();
2241 QString FormMain::GetFilePathFromOpenDlg(const QString& title, const QString& filter)
2243 QString default_path = GetNextDefaultPathForFileDlg();
2244 QString s = QFileDialog::getOpenFileName(this, title, default_path, filter);
2247 m_LastFileDialogDir = QFileInfo(s).absolutePath();
2252 QString FormMain::GetFilePathFromSaveDlg(const QString& title, const QString& filter)
2254 QString default_path = GetNextDefaultPathForFileDlg();
2255 QString s = QFileDialog::getSaveFileName(this, title, default_path, filter);
2258 m_LastFileDialogDir = QFileInfo(s).absolutePath();
2263 bool FormMain::IsSupportedTextureExt(const QString& path) const
2265 QString ext = QFileInfo(path).suffix().toLower();
2267 std::map<QString, bool> types;
2268 types[ "png" ] = true;
2269 types[ "jpg" ] = true;
2270 types[ "jepg" ] = true;
2271 types[ "bmp" ] = true;
2272 types[ "tif" ] = true;
2273 types[ "tiff" ] = true;
2274 types[ "spa" ] = true;
2279 QString FormMain::GetSupportedImageFilePathFromDlg(const QString& title)
2281 FileDlgFilterList exts;
2282 exts.Add( "Png" , "png" );
2283 exts.Add( "Jpg" , "jpg" );
2284 exts.Add( "Jpg" , "jpeg" );
2285 exts.Add( "Bmp" , "bmp" );
2286 exts.Add( "Tif" , "tif" );
2287 exts.Add( "Tif" , "tiff" );
2289 QString filter = FileDlgUtil::ExtListToDlgFilter("Image", exts);
2290 return GetFilePathFromOpenDlg(title, filter);
2294 QString FormMain::GetNextDefaultPathForFileDlg(void)
2296 if (m_LastFileDialogDir.isEmpty())
2297 return PathInfo::GetMyDocDirPath();
2299 return m_LastFileDialogDir;
2303 void FormMain::on_toolLoadEnvMap_clicked()
2305 QString fileName = GetSupportedImageFilePathFromDlg("Open envmap");
2306 if (fileName.isEmpty())
2309 LoadEnvMap(fileName);
2312 void FormMain::LoadEnvMap(QString& path)
2314 m_ContextShare.BeginDrawTop();
2315 m_Scene.m_EnvImg.LoadTexture(path.toLocal8Bit().data());
2316 m_ContextShare.EndDrawTop();
2318 QString title = QFileInfo(path).fileName();
2319 ui.editEnvMap->setText(title);
2324 void FormMain::on_buttonReleaseEnvImg_clicked()
2326 m_ContextShare.BeginDrawTop();
2327 m_Scene.m_EnvImg.ClearEnv();
2328 m_ContextShare.EndDrawTop();
2330 ui.editEnvMap->clear();
2335 void FormMain::on_buttonPresetEnvMap_clicked()
2337 if (m_EnvmapDlg == NULL)
2339 m_EnvmapDlg = new EnvmapSelectDlg(this);
2342 SIGNAL(ListSelectChanged()),
2344 SLOT(EnvmapDlg_ListSelectChanged()));
2347 m_EnvmapDlg->show();
2350 void FormMain::EnvmapDlg_ListSelectChanged()
2352 QString p = m_EnvmapDlg->GetSelectedItemPath();
2359 void FormMain::on_toolLoadMatcap_clicked()
2361 QString fileName = GetSupportedImageFilePathFromDlg("Open matcap");
2362 if (fileName.isEmpty())
2365 LoadMatcapImage(fileName);
2368 void FormMain::on_buttonReleaseMatcap_clicked()
2370 m_ContextShare.BeginDrawTop();
2371 m_Scene.m_MatcapImg.ClearEnv();
2372 m_ContextShare.EndDrawTop();
2374 ui.editMatcap->clear();
2379 void FormMain::on_buttonLoadMatcapPreset_clicked()
2381 if (m_MatcapDlg == NULL)
2383 m_MatcapDlg = new MatcapSelectDlg(this);
2386 SIGNAL(ListSelectChanged()),
2388 SLOT(MatcapDlg_ListSelectChanged()));
2391 m_MatcapDlg->show();
2394 void FormMain::MatcapDlg_ListSelectChanged()
2396 QString p = m_MatcapDlg->GetSelectedItemPath();
2403 void FormMain::on_sliderEnvReflection_valueChanged(int value)
2405 float r = GetSliderNormalizedPos(ui.sliderEnvReflection);
2406 m_Scene.m_EnvImg.m_EnvReflection = r;
2408 ui.labelEnvReflection->setText(QString::number(r, 'f', 2));
2413 void FormMain::on_sliderEnvRefract_valueChanged(int value)
2415 float r = ui.sliderEnvRefract->value() / 1000.0;
2416 m_Scene.m_EnvImg.m_EnvRefract = r;
2418 ui.labelEnvRefract->setText(QString::number(r, 'f', 2));
2423 void FormMain::on_comboCoordinate_currentIndexChanged(int index)
2425 SceneTransform& transform = m_Scene.m_WorldTransform;
2427 int idx = ui.comboCoordinate->currentIndex();
2430 case 0: transform.SetCoordType(geom::SceneTransform::COORD_RUF); break;
2431 case 1: transform.SetCoordType(geom::SceneTransform::COORD_FRU); break;
2432 case 2: transform.SetCoordType(geom::SceneTransform::COORD_UFR); break;
2433 case 3: transform.SetCoordType(geom::SceneTransform::COORD_RUB); break;
2434 case 4: transform.SetCoordType(geom::SceneTransform::COORD_BRU); break;
2435 case 5: transform.SetCoordType(geom::SceneTransform::COORD_UBR); break;
2443 void FormMain::on_sliderShadowDarkness_valueChanged(int value)
2445 int b = ui.sliderShadowDarkness->minimum();
2446 int t = ui.sliderShadowDarkness->maximum();
2448 float r = (float)(value - b) / (float)(t - b);
2449 m_Scene.m_ShadowConfig.m_ShadowDarkness = r;
2455 void FormMain::on_actionOpenAppdir_triggered()
2457 PathInfo::OpenAppDir();
2460 void FormMain::on_actionOpenConfigDir_triggered()
2462 PathInfo::OpenConfigDir();
2465 void FormMain::on_buttonDecGridAxis_clicked()
2467 m_View3d.m_GridAxisScale /= 10.0f;
2471 void FormMain::on_buttonIncGridAxis_clicked()
2473 m_View3d.m_GridAxisScale *= 10.0f;
2477 void FormMain::on_buttonResetGridAxis_clicked()
2479 m_View3d.m_GridAxisScale = 1.0f;
2484 void FormMain::View3D_SelectedObjectChanged(int sel_obj, int sel_mesh)
2486 ui.widgetObjectList->OnSelectedObjectChanged(sel_obj, sel_mesh);
2489 void FormMain::View3D_SelectedMatChanged(int sel_idx)
2491 ui.listMaterial->setCurrentRow(sel_idx);
2494 void FormMain::View3D_CameraMoved(void)
2496 UpdateCameraStatus();
2499 void FormMain::View3D_StatusTipChanged(QString msg)
2501 //ui.statusBar->showMessage(msg, 1500);
2504 void FormMain::View3D_SequenceStepped(int step)
2509 void FormMain::View3D_CursorMoved()
2511 Cursor3D& c = m_Scene.m_Cursor3d;
2512 QString x = QString::number(c.CursorPos.x, 'f', 4);
2513 QString y = QString::number(c.CursorPos.y, 'f', 4);
2514 QString z = QString::number(c.CursorPos.z, 'f', 4);
2528 ui.editCursorPos->setText(s);
2531 void FormMain::StepSequence(int step)
2533 QSlider* s = ui.sliderSequence;
2534 s->setValue(s->value() + step);
2537 bool FormMain::IsLastSequence(void)
2539 QSlider* s = ui.sliderSequence;
2540 return s->value() == s->maximum();
2543 bool FormMain::IsTopSequence(void)
2545 QSlider* s = ui.sliderSequence;
2546 return s->value() == 0;
2549 void FormMain::UpdateCameraStatus(void)
2551 const Camera& camera = m_Scene.m_Camera;
2552 const lib_gl::CameraManipulator& manip = camera.m_Manip;
2553 const lm::vec3f& vp = manip.m_ViewPos;
2556 manip.GetViewAngles(a, b);
2557 a = a * 180.0f / M_PI;
2558 b = b * 180.0f / M_PI;
2562 msg += QString::number(vp.x, 'f', 2) + " ";
2563 msg += QString::number(vp.y, 'f', 2) + " ";
2564 msg += QString::number(vp.z, 'f', 2);
2568 msg += QString::number(a, 'f', 2) + " ";
2569 msg += QString::number(b, 'f', 2);
2573 msg += QString::number(camera.m_Projection.m_Near, 'f', 2) + " ";
2574 msg += QString::number(camera.m_Projection.m_Far, 'f', 2);
2577 m_StatusBar1->setText(msg);
2580 void FormMain::on_actionCameraFPSMode_toggled(bool arg1)
2582 m_View3d.m_FpsMode = arg1;
2586 void FormMain::actionCursorMenuStates_Toggled(bool)
2588 m_Binder_Cursor.UpdateAllData();
2590 if (QObject::sender() == ui.actionRecordStroke)
2592 m_Scene.m_Cursor3d.CutStroke();
2598 void FormMain::on_actionResetCursor_triggered()
2600 m_Scene.m_Cursor3d.ResetCursorPos();
2604 void FormMain::on_actionResetMeasure_triggered()
2606 m_View3d.ResetCursorMeasure();
2611 void FormMain::on_actionPyScript_triggered()
2613 if (m_PyScriptDlg == NULL)
2615 m_PyScriptDlg = new FormPyScript(this);
2616 m_PyScriptDlg->m_Scene = &m_Scene;
2617 m_PyScriptDlg->m_View3d = &m_View3d;
2618 m_PyScriptDlg->m_View2d = &m_View2d;
2621 m_PyScriptDlg->showNormal();
2622 m_PyScriptDlg->show();
2623 m_PyScriptDlg->activateWindow();
2626 void FormMain::on_actionConsole_triggered()
2629 freopen( "CON", "r", stdin );
2630 freopen( "CON", "w", stdout );
2634 void FormMain::on_actionClearVertSelect_triggered()
2636 m_Scene.ClearAllVertSelect();
2641 void FormMain::on_action_About_triggered()
2647 void FormMain::on_action_Association_triggered()
2649 m_AssociationDlg.exec();
2652 void FormMain::on_actionLookDepth_triggered()
2654 m_View3d.LookDepth();
2657 void FormMain::on_actionLook3DCursor_triggered()
2659 m_View3d.Look3DCursor();
2662 void FormMain::on_sliderLightPowerDS_valueChanged(int value)
2664 float n = 2.0f * GetSliderNormalizedPos(ui.sliderLightPowerDS);
2665 m_View3d.SetDfSpLightPower(n);
2667 UpdateLightPowerText();
2672 void FormMain::on_buttonResetLightPowerDS_clicked()
2674 ui.sliderLightPowerDS->setValue(1000);
2677 void FormMain::on_sliderLightPowerA_valueChanged(int value)
2679 float n = 2.0f * GetSliderNormalizedPos(ui.sliderLightPowerA);
2680 m_View3d.SetAmbientLightPower(n);
2682 UpdateLightPowerText();
2687 void FormMain::on_buttonResetLightPowerA_clicked()
2689 ui.sliderLightPowerA->setValue(1000);
2692 void FormMain::UpdateLightPowerText(void)
2694 float ld = 2.0f * GetSliderNormalizedPos(ui.sliderLightPowerDS);
2695 float la = 2.0f * GetSliderNormalizedPos(ui.sliderLightPowerA);
2698 s += QString("Light");
2699 s += QString(" DS=") + QString::number(ld, 'f', 2);
2700 s += QString(" A=") + QString::number(la, 'f', 2);
2701 ui.labelLightPower->setText(s);
2704 void FormMain::on_checkHoleAroundCursor_clicked(bool checked)
2707 ui.checkShowOnlyAroundCursor->setChecked(false);
2710 m_Scene.m_Cursor3d.SphereClip = SphereClipType::Hole;
2712 m_Scene.m_Cursor3d.SphereClip = SphereClipType::None;
2717 void FormMain::on_checkShowOnlyAroundCursor_toggled(bool checked)
2720 ui.checkHoleAroundCursor->setChecked(false);
2723 m_Scene.m_Cursor3d.SphereClip = SphereClipType::ShowAround;
2725 m_Scene.m_Cursor3d.SphereClip = SphereClipType::None;
2730 void FormMain::on_sliderCursorHoleRange_valueChanged(int value)
2732 float val = (float)ui.sliderCursorHoleRange->value();
2733 float maxval = (float)ui.sliderCursorHoleRange->maximum();
2734 float n = val / maxval;
2736 m_Scene.m_Cursor3d.HoleRangeRatio = n;
2740 void FormMain::on_buttonResetCursorHoleRange_clicked()
2745 void FormMain::ResetHoleRange(void)
2747 ui.sliderCursorHoleRange->setValue(500);
2750 void FormMain::on_actionSaveImageToMydoc_triggered()
2752 QString path = PathInfo::GetMyDocDirPath();
2753 QString basename = path + "/" + "qgv_snap_";
2755 QDateTime dt = QDateTime::currentDateTime();
2760 QString tp = dt.toString("yyyyMMdd_hhmmss_zzz");
2761 dst = basename + tp + ".png";
2762 if (!QFile(dst).exists())
2766 ui.GLWidgetMain->grabFrameBuffer().save(dst);
2769 void FormMain::on_actionPostProcNone_triggered()
2771 ChangePostprocMode(PostProcType::None);
2774 void FormMain::on_actionPostProcAntialias_triggered()
2776 ChangePostprocMode(PostProcType::Antialias);
2779 void FormMain::on_actionPostProcBorder_triggered()
2781 ChangePostprocMode(PostProcType::Border);
2784 void FormMain::on_actionPostProcDepthLayerColor_triggered()
2786 ChangePostprocMode(PostProcType::DepthLayerColor);
2789 void FormMain::on_actionPostProcDepthColor_triggered()
2791 ChangePostprocMode(PostProcType::DepthColor);
2794 void FormMain::on_actionPostProcDepthOfField_triggered()
2796 ChangePostprocMode(PostProcType::DepthOfField);
2799 void FormMain::ChangePostprocMode(PostProcType type)
2801 m_View3d.m_Config.m_PPMode = type;
2805 void FormMain::on_sliderDOFPint_valueChanged(int value)
2807 float n = GetSliderNormalizedPos(ui.sliderDOFPint);
2808 m_View3d.m_PPContext.m_DOFPintPos = n;
2813 void FormMain::on_sliderDOFRange_valueChanged(int value)
2815 float n = GetSliderNormalizedPos(ui.sliderDOFRange);
2816 m_View3d.m_PPContext.m_DOFRange = 10.0f * n;
2821 float FormMain::GetSliderNormalizedPos(const QSlider* slider) const
2823 float t = (float)slider->maximum();
2824 float b = (float)slider->minimum();
2825 float v = (float)slider->value();
2827 return (v - b) / (t - b);
2830 void FormMain::on_buttonResetDOFPint_clicked()
2832 ui.sliderDOFPint->setValue(1000);
2835 void FormMain::on_buttonResetDOFRange_clicked()
2837 ui.sliderDOFRange->setValue(1000);
2840 void FormMain::on_actionAddCrossSectionRecord_triggered()
2842 m_Scene.AddCrossSectionRecord();
2846 void FormMain::on_actionClearCrossSectionRecord_triggered()
2848 m_Scene.ClearCrossSectionRecord();
2852 void FormMain::LoadCurSelMatTexture(TextureType type)
2854 QString path = GetSupportedImageFilePathFromDlg("Load Texture");
2858 LoadCurSelMatTexture(type, path);
2861 void FormMain::LoadCurSelMatTexture(TextureType type, QString filepath)
2863 GeomTextureSet* ts = m_Scene.GetSelectedTexture();
2867 MeshBuf* mbuf = ts->GetParent();
2868 std::string fp = filepath.toLocal8Bit().data();
2870 QString name_qs = QFileInfo(filepath).fileName();
2871 std::string name = name_qs.toLocal8Bit().data();
2873 m_ContextShare.BeginDrawTop();
2875 mbuf->ReleaseTextureUnit(ts, type);
2876 gl::GlTexture* tex = mbuf->GetInitTexture(fp, name, m_Scene.m_TexConfig);
2877 ts->SetTextureUnit(type, tex);
2879 if (type == TextureType::Normal)
2880 m_View3d.ReleaseAllRenderBuffer();
2882 m_ContextShare.EndDrawTop();
2884 OnChangedSelectedMaterial();
2888 void FormMain::ReleaseCurSelTexture(TextureType type)
2890 GeomTextureSet* ts = m_Scene.GetSelectedTexture();
2894 MeshBuf* mbuf = ts->GetParent();
2895 int mat_idx = mbuf->GetSelMatIdx();
2897 m_ContextShare.BeginDrawTop();
2898 mbuf->ReleaseTextureUnit(mat_idx, type);
2899 m_ContextShare.EndDrawTop();
2901 OnChangedSelectedMaterial();
2905 void FormMain::LoadMatcapImageForCurrentMat(QString& path)
2907 GeomTextureSet* ts = m_Scene.GetSelectedTexture();
2911 QString title = QFileInfo(path).fileName();
2913 m_ContextShare.BeginDrawTop();
2914 ts->TexMatcap.LoadTexture(path.toLocal8Bit().data());
2915 ts->TexMatcap.SetName(title);
2916 m_ContextShare.EndDrawTop();
2918 OnChangedSelectedMaterial();
2922 void FormMain::LoadMatcapImage(QString& path)
2924 MatcapImage& mc = m_Scene.m_MatcapImg;
2926 QString title = QFileInfo(path).fileName();
2928 m_ContextShare.BeginDrawTop();
2929 mc.LoadTexture(path.toLocal8Bit().data());
2931 m_ContextShare.EndDrawTop();
2933 ui.editMatcap->setText(mc.GetName());
2938 void FormMain::on_buttonOpenMatCapEachMaterial_clicked()
2940 QString path = GetSupportedImageFilePathFromDlg("Load Texture");
2944 LoadMatcapImage(path);
2947 void FormMain::on_buttonClearMatCapEachMaterial_clicked()
2949 geom::GeomTextureSet* tex = m_Scene.GetSelectedTexture();
2953 m_ContextShare.BeginDrawTop();
2954 tex->TexMatcap.ClearEnv();
2955 m_ContextShare.EndDrawTop();
2957 ui.editMatCapEachMaterial->clear();
2962 void FormMain::on_buttonOpenCurrentMatColorMap_clicked()
2964 LoadCurSelMatTexture(TextureType::Color);
2967 void FormMain::on_buttonClearCurrentMatColorMap_clicked()
2969 ReleaseCurSelTexture(TextureType::Color);
2972 void FormMain::on_buttonOpenCurrentMatNormalMap_clicked()
2974 LoadCurSelMatTexture(TextureType::Normal);
2977 void FormMain::on_buttonClearCurrentMatNormalMap_clicked()
2979 ReleaseCurSelTexture(TextureType::Normal);
2982 void FormMain::SetColorPalleteBG(QWidget* w, QColor col)
2984 QColor border(0, 0, 0);
2985 SetWidgetColor(w, col, border);
2988 void FormMain::SetWidgetColor(QWidget* w, QColor col)
2990 QString ss = QString("background-color: %1").arg(col.name());
2991 w->setStyleSheet(ss);
2994 void FormMain::SetWidgetColor(QWidget* w, QColor col, QColor col_border)
2997 ss += QString("background-color: %1;").arg(col.name());
2998 ss += QString("border: 1px solid %1;").arg(col_border.name());
2999 w->setStyleSheet(ss);
3002 void FormMain::on_sliderShininess_valueChanged(int value)
3004 lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
3008 float val = (float)ui.sliderShininess->value();
3009 float val_max = (float)ui.sliderShininess->maximum();
3011 float real_val = 200.0f * val / val_max;
3013 mat->m_Shininess = real_val;
3015 ui.labelShininessVal->setText(QString::number(real_val, 'f', 2));
3020 void FormMain::CreateRecentFilesMenu(const std::vector<QString>& path)
3022 QMenu* recents = ui.menuOpenRecent;
3023 recents->actions().clear();
3025 for (size_t i = 0; i < path.size(); ++i)
3027 AddRecentFile(path[path.size() - i - 1]);
3031 void FormMain::CreateRecentFilesFromMenu(std::vector<QString>& path)
3033 QMenu* recents = ui.menuOpenRecent;
3034 for (QAction* a : recents->actions())
3036 path.push_back(a->text());
3040 void FormMain::AddRecentFile(const QString& path)
3042 QString path_local = QDir::toNativeSeparators(path);
3044 static const int max_files = 10;
3046 QMenu* recents = ui.menuOpenRecent;
3048 for (QAction* a : recents->actions())
3050 if (a->text() == path_local)
3052 recents->removeAction(a);
3057 QAction* new_path = new QAction(path_local, this);
3060 SIGNAL(triggered()),
3062 SLOT(OnOpenRecent()));
3064 if (recents->actions().empty())
3065 recents->addAction(new_path);
3067 recents->insertAction(recents->actions().front(), new_path);
3069 if (recents->actions().size() > max_files)
3071 QAction* a = recents->actions().back();
3072 recents->removeAction(a);
3076 void FormMain::OnOpenRecent()
3078 QAction* a = dynamic_cast<QAction*>(QObject::sender());
3083 QString path = a->text();
3085 if (IsResetSceneOnBeforeLoadFile())
3088 if (OpenGeomFileToLast(path))
3092 void FormMain::on_actionReleaseShader_triggered()
3094 m_ContextShare.BeginDrawTop();
3096 m_View3d.m_ShaderLib.ReleaseAllShaders();
3098 m_ContextShare.EndDrawTop();
3103 void FormMain::on_combo2DViewSrcType_currentIndexChanged(int index)
3107 case 0 : return m_View2d.ChangeTextureSource(View2DTexSrc::Color);
3108 case 1 : return m_View2d.ChangeTextureSource(View2DTexSrc::Normal);
3115 void FormMain::on_sliderSequence_valueChanged(int value)
3120 void FormMain::ResetSequenceSliderRange(void)
3122 int m = m_Scene.GetKeyframeMax();
3123 ui.sliderSequence->setMaximum(m);
3127 void FormMain::UpdateSequence(void)
3129 int v = ui.sliderSequence->value();
3130 int m = ui.sliderSequence->maximum();
3132 QString s = QString("%1 / %2").arg(v).arg(m);
3133 ui.labelSequencePos->setText(s);
3135 m_Scene.SetFrame(v);
3137 m_View3d.ReleaseAllRenderBuffer();
3141 void FormMain::on_actionNewStroke_triggered()
3143 m_Scene.m_Cursor3d.CutStroke();
3147 void FormMain::on_actionClearStroke_triggered()
3149 m_Scene.m_Cursor3d.ClearStroke();
3153 void FormMain::on_buttonMatPreset_clicked()
3155 lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
3159 lib_geo::BaseMaterial mat_backup = (*mat);
3161 if (m_MatPresetDlg == NULL)
3163 m_MatPresetDlg = new MaterialPresetDlg(this);
3166 SIGNAL(OnMatChanged()),
3168 SLOT(MatPresetDlg_OnMatChanged()));
3171 MatPresetDlg_OnMatChanged();
3173 if (m_MatPresetDlg->exec() != QDialog::Accepted)
3175 (*mat) = mat_backup;
3176 OnChangedSelectedMaterial();
3181 lgr::MaterialSamples::MaterialSampleType t = m_MatPresetDlg->GetSelectedType();
3183 if (t != lgr::MaterialSamples::MAT_NONE)
3184 (*mat) = lgr::MaterialSamples::GetMaterial(t);
3186 (*mat) = mat_backup;
3188 OnChangedSelectedMaterial();
3192 void FormMain::MatPresetDlg_OnMatChanged()
3194 lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
3198 lgr::MaterialSamples::MaterialSampleType t = m_MatPresetDlg->GetSelectedType();
3199 if (t == lgr::MaterialSamples::MAT_NONE)
3202 (*mat) = lgr::MaterialSamples::GetMaterial(t);
3204 OnChangedSelectedMaterial();
3208 void FormMain::on_checkEnableIndexRange_toggled(bool checked)
3210 IndexRangeConfig& ir = m_Scene.m_IndexVisrange;
3211 ir.enableRange = checked;
3213 m_View3d.ReleaseAllIndexList();
3217 void FormMain::on_editIndexLimitOffset_textChanged(const QString &arg1)
3219 IndexRangeConfig& ir = m_Scene.m_IndexVisrange;
3222 int i = arg1.toInt(&b);
3230 m_View3d.ReleaseAllIndexList();
3235 void FormMain::on_editIndexLimitLen_textChanged(const QString &arg1)
3237 IndexRangeConfig& ir = m_Scene.m_IndexVisrange;
3240 int i = arg1.toInt(&b);
3248 m_View3d.ReleaseAllIndexList();
3253 void FormMain::on_fscrollIndexLimitOffset_onScroll(int step)
3255 IndexRangeConfig& ir = m_Scene.m_IndexVisrange;
3257 int n = ir.beginIdx + step;
3258 n = (std::max)(n, 0);
3259 ui.editIndexLimitOffset->setText(QString::number(n));
3262 void FormMain::on_fscrollIndexLimitOffset_onReset()
3264 ui.editIndexLimitOffset->setText("0");
3267 void FormMain::on_fscrollIndexLimitLen_onScroll(int step)
3269 IndexRangeConfig& ir = m_Scene.m_IndexVisrange;
3271 int n = ir.idxLen + step;
3272 n = (std::max)(n, 1);
3273 ui.editIndexLimitLen->setText(QString::number(n));
3276 void FormMain::on_fscrollIndexLimitLen_onReset()
3278 ui.editIndexLimitLen->setText("1");
3281 void FormMain::on_buttonTextureScaleDiv10_clicked()
3283 MulTexScaleMain(1.0 / 10.0);
3286 void FormMain::on_buttonTextureScaleMul10_clicked()
3288 MulTexScaleMain(10.0);
3291 void FormMain::on_fscrollTextureScale_onScroll(int step)
3293 double s = pow(2.0, (double)step / 100.0);
3297 void FormMain::MulTexScaleMain(double s)
3299 m_Scene.m_TextureTransform.m_TexScale *= s;
3300 float ts = m_Scene.m_TextureTransform.m_TexScale;
3301 SetTextSilent(ui.editTextureScale, QString::number(ts));
3305 void FormMain::on_fscrollTextureScale_onReset()
3307 ui.editTextureScale->setText("1.0");
3310 void FormMain::on_editTextureScale_textChanged(const QString &arg1)
3313 double d = arg1.toDouble(&b);
3317 m_Scene.m_TextureTransform.m_TexScale = d;
3322 void FormMain::SetTextSilent(QLineEdit* edit, const QString& text)
3324 edit->blockSignals(true);
3325 edit->setText(text);
3326 edit->blockSignals(false);
3329 void FormMain::on_sliderMatcapRate_valueChanged(int value)
3331 float r = GetSliderNormalizedPos(ui.sliderMatcapRate);
3332 m_Scene.m_MatcapImg.m_BlendRate = r;
3334 ui.labelMatcapRate->setText(QString::number(r, 'f', 2));