OSDN Git Service

ウィンドウ位置標準設定機能を追加
[qtgeoviewer/QtGeoViewer.git] / Src / QtGeoViewer / FormMain.cpp
1 #include "stdafx.h"
2 #include "FormMain.h"
3
4 #include <QFileInfo>
5 #include <fstream>
6 #include <sstream>
7
8 #include <cassert>
9 #include <QSettings>
10
11 #include "FormVertexBuilder.h"
12 #include "FullScreenPanel.h"
13
14 #include <Qt5Utility/QGui.h>
15
16 #include <QMessageBox>
17 #include <QFileDialog>
18 #include <QPrintDialog>
19 #include <QPrintPreviewDialog>
20
21 #include "BuildInfo.h"
22 #include "PathInfo.h"
23 #include "PostprocLibrary.h"
24 #include "SampleShapeBuilder.h"
25 #include "ShaderLibrary.h"
26 #include "QGVAboutDlg.h"
27
28 #include "FormCustomShader.h"
29 #include "FormPyScript.h"
30 #include "MatcapSelectDlg.h"
31 #include "EnvmapSelectDlg.h"
32 #include "FileDlgUtil.h"
33 #include "TreeUtil.h"
34
35
36
37 QColor ToQColor(const lib_graph::color4f& c)
38 {
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);
43
44         return QColor(r, g, b, a);
45 }
46
47
48
49 FormMain::FormMain(QWidget *parent)
50         : QMainWindow(parent)
51         , m_MatcapDlg(NULL)
52         , m_EnvmapDlg(NULL)
53         , m_CustomShaderDlg(NULL)
54         , m_PyScriptDlg(NULL)
55 {
56         ui.setupUi(this);
57
58         m_EnableAllFeatures = false;
59         m_LastFocusedDockDlg = NULL;
60
61         setAcceptDrops(true);
62
63         setWindowTitle("QtGeoViewer");
64
65         InitializeGLView();
66         InitializeStatusBar();
67         InitializeMenu();
68         InitializeCoordinateCombobox();
69         Initialize2DViewSrcCombobox();
70         InitializeEventFilter();
71         InitContextMenu();
72
73         InitDataBinding();
74
75         SyncViewSettingsFromGUI();
76         SyncUVViewSettingsFromGUI();
77         SyncSceneSettingsFromGUI();
78         ApplyGeomStateFromGUI();
79         SyncShaderSettingsToGUI();
80
81         ui.toolBar_View->setVisible( ui.actionWindow_ToolBarView->isChecked() );
82
83         UpdateViewTypeFromMenu();
84
85         CenteringSplitter();
86
87         RebuildObjectList();
88
89         InitializeSubDlg();
90
91         InitializeAnimation();
92
93         InitializeFromConfigFiles();
94
95         HideFeatures();
96
97         ResetHoleRange();
98
99         this->show();
100
101         m_InitRect = rect();
102         m_InitRect.translate(pos());
103
104         LoadLastWinPos();
105
106         ProcArguments();
107 }
108
109 FormMain::~FormMain()
110 {
111 }
112
113
114 void FormMain::LoadLastWinPos(void)
115 {
116         QString file = PathInfo::GetPosConfigFilePath();
117         QSettings conf(file, QSettings::IniFormat);
118
119         QVariant v;
120         v = conf.value("main/WindowPos");
121         if (v.isValid())
122         {
123                 QRect r = v.toRect();
124                 int dl = r.left();
125                 int dt = r.top();
126                 int dw = r.width();
127                 int dh = r.height();
128
129                 resize(dw, dh);
130
131                 move(QPoint(dl, dt));
132         }
133
134         v = conf.value("main/WinState");
135         if (v.isValid())
136         {
137                 if (v.toBool())
138                         setWindowState(Qt::WindowMaximized);
139         }
140 }
141
142 void FormMain::SaveWinPos(void)
143 {
144         QString file = PathInfo::GetPosConfigFilePath();
145         QSettings conf(file, QSettings::IniFormat);
146
147         conf.setValue("main/WinState", isMaximized());
148
149         if (isMaximized() || isMinimized())
150         {
151                 setWindowState(Qt::WindowNoState);
152                 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
153         }
154
155         QRect r = rect();
156         r.translate(pos());
157
158         conf.setValue("main/WindowPos", r);
159 }
160
161 void FormMain::HideFeatures(void)
162 {
163         bool b = m_EnableAllFeatures;
164
165         ui.actionVertexBuilder->setVisible(b);
166         ui.menuPrintRoot->menuAction()->setVisible(b);
167         ui.actionShadowmap->setVisible(b);
168         ui.actionEnvmap->setVisible(b);
169         ui.actionShaderCustom->setVisible(b);
170         ui.actionWindowCustomShader->setVisible(b);
171         ui.actionPyScript->setVisible(b);
172         ui.actionConsole->setVisible(b);
173         ui.actionReleaseShader->setVisible(b);
174 }
175
176 void FormMain::InitializeEventFilter(void)
177 {
178         ui.editEnvMap->installEventFilter(this);
179         ui.editMatcap->installEventFilter(this);
180
181         ui.editCurrentTexName->installEventFilter(this);
182         ui.editCurrentMatNormalMap->installEventFilter(this);
183         ui.editMatCapEachMaterial->installEventFilter(this);
184
185         ui.colorAmbient->installEventFilter(this);
186         ui.colorEmission->installEventFilter(this);
187         ui.colorDiffuse->installEventFilter(this);
188         ui.colorSpecular->installEventFilter(this);
189 }
190
191 void FormMain::InitDataBinding(void)
192 {
193         InitializeVisiblStateMenu();
194         InitializeUVStateMenu();
195         InitializeSceneStateMenu();
196         InitializeGeomStateMenu();
197         InitializeCursorMenu();
198 }
199
200 void FormMain::InitializeVisiblStateMenu(void)
201 {
202         DataBinderMap& dbmap = m_Binder_ViewConfig;
203
204         View3DConfig& cfg_3d = m_View3d.m_Config;
205
206         dbmap.AddBinder(new MenuBinder(ui.actionDrawBBox            , &cfg_3d.m_DrawBBox            ));
207         dbmap.AddBinder(new MenuBinder(ui.actionFaceVBO             , &cfg_3d.m_EnableFaceVBO       ));
208         dbmap.AddBinder(new MenuBinder(ui.actionVidTopMost          , &cfg_3d.m_ShowVidTopMost      ));
209         dbmap.AddBinder(new MenuBinder(ui.actionDrawBBoxRange       , &cfg_3d.m_DrawBBoxRange       ));
210         dbmap.AddBinder(new MenuBinder(ui.actionWireDispList        , &cfg_3d.m_EnableWireDispList  ));
211         dbmap.AddBinder(new MenuBinder(ui.actionMultisample         , &cfg_3d.m_EnableMultisample   ));
212         dbmap.AddBinder(new MenuBinder(ui.actionCoverageTransparent , &cfg_3d.m_EnableCoverageTrans ));
213         dbmap.AddBinder(new MenuBinder(ui.actionSeparateSpecular    , &cfg_3d.m_SeparateSpecular    ));
214         dbmap.AddBinder(new MenuBinder(ui.actionShowSelVertCoord    , &cfg_3d.m_ShowSelVertCoord    ));
215         dbmap.AddBinder(new MenuBinder(ui.actionHighlightSelected   , &cfg_3d.m_HighlightSelected   ));
216         dbmap.AddBinder(new MenuBinder(ui.actionFixMaterialSilver   , &cfg_3d.m_UseFixMaterial      ));
217         dbmap.AddBinder(new MenuBinder(ui.actionShadowmapBuffer     , &cfg_3d.m_DrawShadowmapBuf    ));
218         dbmap.AddBinder(new MenuBinder(ui.actionEnableTexture3D     , &cfg_3d.m_EnableTexture       ));
219         dbmap.AddBinder(new MenuBinder(ui.actionEnableLighting      , &cfg_3d.m_EnableLighting      ));
220         dbmap.AddBinder(new MenuBinder(ui.actionEnableCulling       , &cfg_3d.m_EnableCullFace      ));
221         dbmap.AddBinder(new MenuBinder(ui.actionDrawWire            , &cfg_3d.m_DrawWire            ));
222         dbmap.AddBinder(new MenuBinder(ui.actionDrawVid             , &cfg_3d.m_DrawVid             ));
223         dbmap.AddBinder(new MenuBinder(ui.actionDrawVertNormal      , &cfg_3d.m_DrawVertNormal      ));
224         dbmap.AddBinder(new MenuBinder(ui.actionDrawVert            , &cfg_3d.m_DrawVert            ));
225         dbmap.AddBinder(new MenuBinder(ui.actionWireVBO             , &cfg_3d.m_EnableWireVBO       ));
226         dbmap.AddBinder(new MenuBinder(ui.actionIndexColorMode      , &cfg_3d.m_IndexMaterial       ));
227         dbmap.AddBinder(new MenuBinder(ui.actionFBMaterial          , &cfg_3d.m_FBMaterial          ));
228         dbmap.AddBinder(new MenuBinder(ui.actionDrawMiniAxis        , &cfg_3d.m_DrawMiniAxis        ));
229         dbmap.AddBinder(new MenuBinder(ui.actionDrawLookPos         , &cfg_3d.m_DrawLookPos         ));
230         dbmap.AddBinder(new MenuBinder(ui.actionDrawLightPos        , &cfg_3d.m_DrawLightPosition   ));
231         dbmap.AddBinder(new MenuBinder(ui.actionDrawGround          , &cfg_3d.m_DrawGround          ));
232         dbmap.AddBinder(new MenuBinder(ui.actionDrawFid             , &cfg_3d.m_DrawFid             ));
233         dbmap.AddBinder(new MenuBinder(ui.actionDrawFace            , &cfg_3d.m_DrawFace            ));
234         dbmap.AddBinder(new MenuBinder(ui.actionCameraRecords       , &cfg_3d.m_DrawCameraRecord    ));
235         dbmap.AddBinder(new MenuBinder(ui.actionDrawAxis            , &cfg_3d.m_DrawAxis            ));
236         dbmap.AddBinder(new MenuBinder(ui.actionDoubleSideShading   , &cfg_3d.m_DoubleSideShading   ));
237         dbmap.AddBinder(new MenuBinder(ui.actionDirectionalLight    , &cfg_3d.m_LightIsDirectional  ));
238         dbmap.AddBinder(new MenuBinder(ui.actionCullFrontOrBack     , &cfg_3d.m_CullAngle_F         ));
239         dbmap.AddBinder(new MenuBinder(ui.actionHighlightMaterial   , &cfg_3d.m_HighlightMaterial   ));
240         dbmap.AddBinder(new MenuBinder(ui.actionCloseVert           , &cfg_3d.m_ShowCloseVertInfo   ));
241         dbmap.AddBinder(new MenuBinder(ui.actionCameraRange         , &cfg_3d.m_DrawRenderRange     ));
242         dbmap.AddBinder(new MenuBinder(ui.actionRenderTime          , &cfg_3d.m_ShowRenderTime      ));
243         dbmap.AddBinder(new MenuBinder(ui.actionUseFixTexture       , &cfg_3d.m_UseFixTexture       ));
244         dbmap.AddBinder(new MenuBinder(ui.actionShowSelVertIdx      , &cfg_3d.m_ShowSelVertIdx      ));
245         dbmap.AddBinder(new MenuBinder(ui.actionShowMeshBound       , &cfg_3d.m_ShowMeshBound       ));
246         dbmap.AddBinder(new MenuBinder(ui.actionPickTransparent     , &cfg_3d.m_PickTransparent     ));
247         dbmap.AddBinder(new MenuBinder(ui.actionFlatShading         , &cfg_3d.m_EnableFlatShade     ));
248         dbmap.AddBinder(new MenuBinder(ui.actionDrawPolylineLenWhl  , &cfg_3d.m_DrawPolylineLenWhl  ));
249         dbmap.AddBinder(new MenuBinder(ui.actionDrawPolylineLen     , &cfg_3d.m_DrawPolylineLen     ));
250         dbmap.AddBinder(new MenuBinder(ui.actionDrawPolylineIdx     , &cfg_3d.m_DrawPolylineIdx     ));
251         dbmap.AddBinder(new MenuBinder(ui.actionDrawPolyline        , &cfg_3d.m_DrawPolyline        ));
252         dbmap.AddBinder(new MenuBinder(ui.actionDrawBone            , &cfg_3d.m_DrawBone            ));
253         dbmap.AddBinder(new MenuBinder(ui.actionShowMeasure         , &cfg_3d.m_DrawCameraMeasure   ));
254         dbmap.AddBinder(new MenuBinder(ui.actionFlipMouseMR         , &cfg_3d.m_FlipMouseMR         ));
255         dbmap.AddBinder(new MenuBinder(ui.actionSyncLightToCamera   , &cfg_3d.m_SyncLightTocamera   ));
256
257         for (GuiBinder& binder : dbmap.m_BinderMap)
258         {
259                 MenuBinder* mb = dynamic_cast<MenuBinder*>(&binder);
260                 if (mb != NULL)
261                 {
262                         QAction* a = mb->GetMenu();
263                         connect(
264                                 a,
265                                 SIGNAL(triggered(bool)),
266                                 this,
267                                 SLOT(actionVisibleStates_Triggered(bool)));
268                 }
269         }
270 }
271
272 void FormMain::InitializeUVStateMenu(void)
273 {
274         DataBinderMap& dbmap = m_Binder_UVConfig;
275
276         dbmap.AddBinder(new MenuBinder(ui.actionUVRepeat         , &m_View2d.m_RepeatTexture             ));
277         dbmap.AddBinder(new MenuBinder(ui.actionUseFixTexture2D  , &m_View2d.m_UseFixTexute              ));
278         dbmap.AddBinder(new MenuBinder(ui.actionShowVertex2d     , &m_View2d.m_DrawVerts                 ));
279         dbmap.AddBinder(new MenuBinder(ui.actionShowImage2d      , &m_View2d.m_EnableTexture             ));
280         dbmap.AddBinder(new MenuBinder(ui.actionTextureMipmap    , &m_Scene.m_TexConfig.m_EnableMipmap   ));
281         dbmap.AddBinder(new MenuBinder(ui.actionTextureCompress  , &m_Scene.m_TexConfig.m_EnableCompress ));
282         dbmap.AddBinder(new MenuBinder(ui.actionUVFlipY          , &m_Scene.m_TextureTransform.m_FlipY   ));
283
284         for (GuiBinder& binder : dbmap.m_BinderMap)
285         {
286                 MenuBinder* mb = dynamic_cast<MenuBinder*>(&binder);
287                 if (mb != NULL)
288                 {
289                         QAction* a = mb->GetMenu();
290                         connect(
291                                 a,
292                                 SIGNAL(triggered(bool)),
293                                 this,
294                                 SLOT(actionVisibleStatesUV_Triggered(bool)));
295                 }
296         }
297 }
298
299 void FormMain::InitializeSceneStateMenu(void)
300 {
301         DataBinderMap& dbmap = m_Binder_Scene;
302
303         dbmap.AddBinder(new CheckboxBinder( ui.checkEnvMap         , &m_Scene.m_EnvImg.m_VisibleEnvSphere       ));
304         dbmap.AddBinder(new CheckboxBinder( ui.checkEnvReflection  , &m_Scene.m_EnvImg.m_IsEnableReflection     ));
305         dbmap.AddBinder(new CheckboxBinder( ui.checkShadowEnabled  , &m_Scene.m_ShadowConfig.m_EnableShadow     ));
306         dbmap.AddBinder(new CheckboxBinder( ui.checkSoftShadow     , &m_Scene.m_ShadowConfig.m_EnableSoftShadow ));
307
308         for (GuiBinder& binder : dbmap.m_BinderMap)
309         {
310                 CheckboxBinder* mb = dynamic_cast<CheckboxBinder*>(&binder);
311                 if (mb != NULL)
312                 {
313                         QCheckBox* c = mb->GetCheckBox();
314                         connect(
315                                 c,
316                                 SIGNAL(toggled(bool)),
317                                 this,
318                                 SLOT(actionSceneStates_Toggled(bool)));
319                 }
320         }
321 }
322
323 void FormMain::InitializeCursorMenu(void)
324 {
325         DataBinderMap& dbmap = m_Binder_Cursor;
326
327         Cursor3D& cursor = m_Scene.m_Cursor3d;
328         dbmap.AddBinder(new MenuBinder( ui.actionShowCursor        , &cursor.ShowCursor     ));
329         dbmap.AddBinder(new MenuBinder( ui.actionCursorToDepth     , &cursor.CursorDepth    ));
330         dbmap.AddBinder(new MenuBinder( ui.actionCursorCoord       , &cursor.ShowCoord      ));
331         dbmap.AddBinder(new MenuBinder( ui.actionCheckBaryCoord    , &cursor.CheckBaryCoord ));
332         dbmap.AddBinder(new MenuBinder( ui.actionSelectCloseMat    , &cursor.SelCloseVert   ));
333         dbmap.AddBinder(new MenuBinder( ui.actionCursorAxis        , &cursor.ShowAxis       ));
334         dbmap.AddBinder(new MenuBinder( ui.actionMeasure           , &cursor.ShowMeasure    ));
335         dbmap.AddBinder(new MenuBinder( ui.actionMeasureLen        , &cursor.ShowMeasureLen ));
336         dbmap.AddBinder(new MenuBinder( ui.actionMeasureXYZ        , &cursor.ShowMeasureXYZ ));
337         dbmap.AddBinder(new MenuBinder( ui.actionRecordStroke      , &cursor.RecordStroke   ));
338         dbmap.AddBinder(new MenuBinder( ui.actionShowStrokeLength  , &cursor.ShowStrokeLen  ));
339         dbmap.AddBinder(new MenuBinder( ui.actionTransparentStroke , &cursor.TranspStorke   ));
340
341         for (GuiBinder& binder : dbmap.m_BinderMap)
342         {
343                 MenuBinder* mb = dynamic_cast<MenuBinder*>(&binder);
344                 if (mb != NULL)
345                 {
346                         QAction* a = mb->GetMenu();
347                         connect(
348                                 a,
349                                 SIGNAL(triggered(bool)),
350                                 this,
351                                 SLOT(actionCursorMenuStates_Toggled(bool)));
352                 }
353         }
354 }
355
356
357 void FormMain::InitializeGeomStateMenu(void)
358 {
359         AddGeomStateAction( ui.actionCentering  );
360         AddGeomStateAction( ui.actionAutoResize );
361 }
362
363 void FormMain::AddGeomStateAction(const QAction* action)
364 {
365         connect(
366                 action,
367                 SIGNAL(triggered(bool)),
368                 this,
369                 SLOT(actionGeomStates_Triggered(bool)));
370 }
371
372
373 void FormMain::InitializeGLView(void)
374 {
375         ui.GLWidgetMain->setMouseTracking(true);
376         ui.GLWidgetUV->setMouseTracking(true);
377
378         ui.GLWidgetMain->SetViewer(&m_View3d);
379         m_View3d.m_Widgets = &m_Widgets;
380         m_View3d.RegisterScene(&m_Scene);
381         m_View3d.InitializeView(ui.GLWidgetMain);
382
383         ui.GLWidgetUV->SetViewer(&m_View2d);
384         m_View2d.m_Widgets = &m_Widgets;
385         m_View2d.RegisterScene(&m_Scene);
386         m_View2d.InitializeView(ui.GLWidgetUV);
387
388         m_Widgets.AddWidget(ui.GLWidgetMain);
389         m_Widgets.AddWidget(ui.GLWidgetUV);
390
391         // OpenGL\82Ì\83\8a\83X\83g\82Ì\8b¤\97L\89»
392         SetContextShare();
393
394         m_ContextShare.BeginDrawTop();
395
396         m_Scene.Initialize();
397
398         m_ContextShare.EndDrawTop();
399
400         connect(
401                 &m_View3d,
402                 SIGNAL(SelectedObjectChanged(int, int)),
403                 SLOT(View3D_SelectedObjectChanged(int, int)));
404         connect(
405                 &m_View3d,
406                 SIGNAL(SelectedMatChanged(int)),
407                 SLOT(View3D_SelectedMatChanged(int)));
408         connect(
409                 &m_View3d,
410                 SIGNAL(CameraMoved(void)),
411                 SLOT(View3D_CameraMoved(void)));
412         connect(
413                 &m_View3d,
414                 SIGNAL(StatusTipChanged(QString)),
415                 SLOT(View3D_StatusTipChanged(QString)));
416         connect(
417                 &m_View3d,
418                 SIGNAL(SequenceStepped(int)),
419                 SLOT(View3D_SequenceStepped(int)));
420         connect(
421                 &m_View3d,
422                 SIGNAL(CursorMoved()),
423                 SLOT(View3D_CursorMoved()));
424 }
425
426 // OpenGL\82Ì\83\8a\83X\83g\82Ì\8b¤\97L\89»
427 void FormMain::SetContextShare(void)
428 {
429         ui.GLWidgetUV->makeCurrent();
430         m_ContextShare.AddContext( GetDC((HWND)ui.GLWidgetUV->winId()) , wglGetCurrentContext() );
431         ui.GLWidgetUV->doneCurrent();
432
433         ui.GLWidgetMain->makeCurrent();
434         m_ContextShare.AddContext( GetDC((HWND)ui.GLWidgetUV->winId()) , wglGetCurrentContext() );
435         ui.GLWidgetMain->doneCurrent();
436
437         m_ContextShare.MakeShare();
438 }
439
440 void FormMain::InitializeCoordinateCombobox(void)
441 {
442         ui.comboCoordinate->blockSignals(true);
443         ui.comboCoordinate->addItem("Yup RH"); // RUF
444         ui.comboCoordinate->addItem("Zup RH"); // FRU
445         ui.comboCoordinate->addItem("Xup RH"); // UFR
446         ui.comboCoordinate->addItem("Yup LH"); // RUB
447         ui.comboCoordinate->addItem("Zup LH"); // BRU
448         ui.comboCoordinate->addItem("Xup LH"); // UBR
449         ui.comboCoordinate->blockSignals(false);
450 }
451
452 void FormMain::Initialize2DViewSrcCombobox(void)
453 {
454         ui.combo2DViewSrcType->blockSignals(true);
455         ui.combo2DViewSrcType->addItem("Color");
456         ui.combo2DViewSrcType->addItem("Normal");
457         ui.combo2DViewSrcType->blockSignals(false);
458 }
459
460 void FormMain::InitializeStatusBar(void)
461 {
462         m_StatusBar0 = new QLabel(this);
463         m_StatusBar1 = new QLabel(this);
464         ui.statusBar->addWidget(m_StatusBar0, 1);
465         ui.statusBar->addWidget(m_StatusBar1, 0);
466
467         m_StatusBar0->setText("");
468
469         m_StatusBar1->setMinimumWidth(290);
470         m_StatusBar1->setText("");
471 }
472
473 void FormMain::InitializeFromConfigFiles(void)
474 {
475         if (!InitializeConfig(PathInfo::GetGuiConfigFilePath()))
476         {
477                 InitializeConfig(PathInfo::GetDefaultGuiConfigFilePath());
478         }
479
480         OpenCameraFile(PathInfo::GetCameraLogFilePath());
481
482         if (!LoadWindowLayout(PathInfo::GetWindowLayoutConfigFilePath()))
483         {
484                 LoadWindowLayout(PathInfo::GetDefaultWindowLayoutConfigFilePath());
485         }
486
487         if (!QGui::LoadGUIState(this, PathInfo::GetLayoutConfigFilePath()))
488         {
489                 QGui::LoadGUIState(this, PathInfo::GetDefaultLayoutConfigFilePath());
490         }
491 }
492
493 void FormMain::LoadDefaultConfig(void)
494 {
495         InitializeConfig(PathInfo::GetDefaultGuiConfigFilePath());
496         QGui::LoadGUIState(this, PathInfo::GetDefaultLayoutConfigFilePath());
497         LoadWindowLayout(PathInfo::GetDefaultWindowLayoutConfigFilePath());
498 }
499
500 void FormMain::SaveConfig(void)
501 {
502         PathInfo::CreateConfiDirIfNotExist();
503
504         SaveConfigFile(PathInfo::GetGuiConfigFilePath());
505
506         m_View3d.m_CameraRecord.SaveCamera(PathInfo::GetCameraLogFilePath().toLocal8Bit().data());
507
508         QGui::SaveGUIState(this, PathInfo::GetLayoutConfigFilePath());
509
510         SaveWindowLayout(PathInfo::GetWindowLayoutConfigFilePath());
511 }
512
513 bool FormMain::InitializeConfig(QString path)
514 {
515         View3DConfig& config_3d = m_View3d.m_Config;
516
517         GuiConfig cfg;
518         cfg.m_Config3D = &config_3d;
519         cfg.m_Scene    = &m_Scene;
520
521         if (!cfg.LoadConfigT(path.toLocal8Bit().data()))
522                 return false;
523
524         ui.actionUVAutoFit->setChecked(cfg.m_AutFitUVView);
525
526         ui.comboCoordinate->setCurrentIndex(cfg.m_CoordType);
527
528         CreateRecentFilesMenu(cfg.m_RecentFiles);
529
530         m_Binder_ViewConfig.UpdateAllGUI(true);
531         m_Binder_UVConfig.UpdateAllGUI(true);
532         m_Binder_Scene.UpdateAllGUI(true);
533         m_Binder_Cursor.UpdateAllGUI(true);
534
535         ApplyGeomStateDataoToGUI();
536
537         SyncViewSettingsFromGUI();
538         SyncUVViewSettingsFromGUI();
539         SyncShaderSettingsToGUI();
540
541         m_EnableAllFeatures = cfg.m_EnableAllFeatures;
542
543         return true;
544 }
545
546 void FormMain::SaveConfigFile(QString path)
547 {
548         GuiConfig cfg;
549         cfg.m_Config3D = &m_View3d.m_Config;
550         cfg.m_Scene    = &m_Scene;
551
552         cfg.m_EnableAllFeatures = m_EnableAllFeatures;
553
554         cfg.m_AutFitUVView = ui.actionUVAutoFit ->isChecked();
555
556         cfg.m_CoordType = ui.comboCoordinate->currentIndex();
557
558         CreateRecentFilesFromMenu(cfg.m_RecentFiles);
559
560         cfg.SaveConfigT(path.toLocal8Bit().data());
561 }
562
563
564 void FormMain::InitializeSubDlg(void)
565 {
566         connect(
567                 &m_WireColorSelDlg,
568                 SIGNAL(currentColorChanged(const QColor &)),
569                 this,
570                 SLOT(WireOverlayColorChanged(const QColor &)));
571         connect(
572                 &m_DiffuseColorSelDlg,
573                 SIGNAL(currentColorChanged(const QColor &)),
574                 this,
575                 SLOT(FaceDiffuseColorChanged(const QColor &)));
576         connect(
577                 &m_BGColorSelDlg,
578                 SIGNAL(currentColorChanged(const QColor &)),
579                 this,
580                 SLOT(BGColorChanged(const QColor &)));
581         connect(
582                 &m_SelMatColorSelDlg,
583                 SIGNAL(currentColorChanged(const QColor &)),
584                 this,
585                 SLOT(SelMatColorChanged(const QColor &)));
586
587         m_SelMatColorWidget = NULL;
588
589         m_ViewConfigDlg.InitializeConfigDlg(&m_View3d.m_Config);
590         connect(
591                 &m_ViewConfigDlg,
592                 SIGNAL(ConfigChanged()),
593                 this,
594                 SLOT(ConfigChangedDlg_ConfigChanged()));
595
596         m_CrossSectionDlg.InitializeConfigDlg(&m_View3d);
597         connect(
598                 &m_CrossSectionDlg,
599                 SIGNAL(ConfigChanged()),
600                 this,
601                 SLOT(CrossSectionDlg_ConfigChanged()));
602 }
603
604 void FormMain::InitializeAnimation(void)
605 {
606         connect(
607                 &m_AnimationTimer,
608                 SIGNAL(timeout()),
609                 this,
610                 SLOT(OnAnimationTimerUpdated()));
611         m_AnimationTimer.setInterval(20);
612 }
613
614 void FormMain::InitializeMenu(void)
615 {
616         m_AGroup_Window = new QActionGroup(this);
617         m_AGroup_Window->setExclusive(true);
618         m_AGroup_Window->addAction( ui.actionWindow_3DView    );
619         m_AGroup_Window->addAction( ui.actionWindow_UVView    );
620         m_AGroup_Window->addAction( ui.actionWindows_DualView );
621
622         m_AGroup_Shader = new QActionGroup(this);
623         m_AGroup_Shader->setExclusive(true);
624         m_AGroup_Shader->addAction( ui.actionShaderDefault   );
625         m_AGroup_Shader->addAction( ui.actionShaderPhong     );
626         m_AGroup_Shader->addAction( ui.actionShaderCustom    );
627         m_AGroup_Shader->addAction( ui.actionNormalColor     );
628         m_AGroup_Shader->addAction( ui.actionDepthColor      );
629         m_AGroup_Shader->addAction( ui.actionShadowmap       );
630         m_AGroup_Shader->addAction( ui.actionEnvmap          );
631         m_AGroup_Shader->addAction( ui.actionIntegrateShader );
632         m_AGroup_Shader->addAction( ui.actionMatcapShader    );
633
634         m_AGroup_PProc = new QActionGroup(this);
635         m_AGroup_PProc->addAction( ui.actionPostProcNone            );
636         m_AGroup_PProc->addAction( ui.actionPostProcAntialias       );
637         m_AGroup_PProc->addAction( ui.actionPostProcBorder          );
638         m_AGroup_PProc->addAction( ui.actionPostProcDepthLayerColor );
639         m_AGroup_PProc->addAction( ui.actionPostProcDepthColor      );
640         m_AGroup_PProc->addAction( ui.actionPostProcDepthOfField    );
641 }
642
643 void FormMain::InitContextMenu(void)
644 {
645         QList<QAction*> actions;
646         actions
647                 << ui.actionSelObjectVisible
648                 << ui.actionSelObjectVertexOnlyMode
649                 << ui.actionSelObjectDelete
650                 << ui.actionSelObjectReload
651                 << ui.actionSelObjectFlipFace
652                 << ui.actionSelObjectFlipNormal
653                 << ui.actionSelObjectOpenDir
654                 << ui.actionActionSelObjectShowOnlyOnce
655                 << ui.actionSelObjectTriangulate
656                 << ui.actionTreeCollapseAll
657                 << ui.actionTreeExpandAll;
658
659         QTreeWidget* obj_tree = ui.treeObjects;
660
661         obj_tree->setContextMenuPolicy(Qt::ActionsContextMenu);
662         obj_tree->addActions(actions);
663 }
664
665 void FormMain::ProcArguments(void)
666 {
667         QStringList args = QApplication::arguments();
668         for (int i = 1; i < args.size(); ++i)
669         {
670                 QString s = args[i];
671                 OpenGeomFile(s);
672         }
673 }
674
675 void FormMain::closeEvent(QCloseEvent *e)
676 {
677         SaveWinPos();
678
679         SaveConfig();
680
681         e->accept();
682
683         m_ViewConfigDlg.close();
684         m_CrossSectionDlg.close();
685         m_FullscreenPanel.close();
686
687         if (m_CustomShaderDlg != NULL)
688                 m_CustomShaderDlg->close();
689         if (m_PyScriptDlg != NULL)
690                 m_PyScriptDlg->close();
691
692         if (m_MatcapDlg != NULL)
693                 m_MatcapDlg->close();
694         if (m_EnvmapDlg != NULL)
695                 m_EnvmapDlg->close();
696
697         m_ContextShare.BeginDrawTop();
698         m_Scene.FinalizeScene();
699         m_ContextShare.EndDrawTop();
700 }
701
702
703 bool FormMain::eventFilter(QObject * filterobj, QEvent * filterevt)
704 {
705         if (filterobj == ui.editEnvMap)
706         {
707                 if (filterevt->type() == QEvent::DragEnter)
708                         return AcceptDropFilterIfUrl(filterevt);
709
710                 if (filterevt->type() == QEvent::Drop)
711                         return OnDropFile_editEnvMap(filterevt);
712         }
713         else if (filterobj == ui.editMatcap)
714         {
715                 if (filterevt->type() == QEvent::DragEnter)
716                         return AcceptDropFilterIfUrl(filterevt);
717
718                 if (filterevt->type() == QEvent::Drop)
719                         return OnDropFile_editMatcap(filterevt);
720         }
721         else if (filterobj == ui.editMatCapEachMaterial)
722         {
723                 if (filterevt->type() == QEvent::DragEnter)
724                         return AcceptDropFilterIfUrl(filterevt);
725
726                 if (filterevt->type() == QEvent::Drop)
727                         return OnDropFile_editMatcapEachMat(filterevt);
728         }
729         else if (filterobj == ui.editCurrentTexName)
730         {
731                 if (filterevt->type() == QEvent::DragEnter)
732                         return AcceptDropFilterIfUrl(filterevt);
733
734                 if (filterevt->type() == QEvent::Drop)
735                         return OnDropFile_editCurrentTexName(filterevt);
736         }
737         else if (filterobj == ui.editCurrentMatNormalMap)
738         {
739                 if (filterevt->type() == QEvent::DragEnter)
740                         return AcceptDropFilterIfUrl(filterevt);
741
742                 if (filterevt->type() == QEvent::Drop)
743                         return OnDropFile_editCurrentMatNormalMap(filterevt);
744         }
745         else if (filterobj == ui.colorAmbient)
746         {
747                 if (filterevt->type() == QEvent::MouseButtonPress)
748                         return colorAmbient_OnButtonDown(filterevt);
749         }
750         else if (filterobj == ui.colorEmission)
751         {
752                 if (filterevt->type() == QEvent::MouseButtonPress)
753                         return colorEmission_OnButtonDown(filterevt);
754         }
755         else if (filterobj == ui.colorDiffuse)
756         {
757                 if (filterevt->type() == QEvent::MouseButtonPress)
758                         return colorDiffuse_OnButtonDown(filterevt);
759         }
760         else if (filterobj == ui.colorSpecular)
761         {
762                 if (filterevt->type() == QEvent::MouseButtonPress)
763                         return colorSpecular_OnButtonDown(filterevt);
764         }
765
766         return QMainWindow::eventFilter(filterobj, filterevt);
767 }
768
769 bool FormMain::OnDropFile_editEnvMap(QEvent * filterevt)
770 {
771         QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
772         if (!path.isEmpty())
773                 LoadEnvMap(path);
774
775         return true;
776 }
777
778 bool FormMain::OnDropFile_editMatcap(QEvent * filterevt)
779 {
780         QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
781         if (!path.isEmpty())
782                 LoadMatcapImage(path);
783
784         return true;
785 }
786
787 bool FormMain::OnDropFile_editMatcapEachMat(QEvent * filterevt)
788 {
789         QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
790         if (!path.isEmpty())
791                 LoadMatcapImageForCurrentMat(path);
792
793         return true;
794 }
795
796 bool FormMain::OnDropFile_editCurrentTexName(QEvent * filterevt)
797 {
798         QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
799         if (!path.isEmpty())
800                 LoadCurSelMatTexture(TextureType::Color, path);
801
802         return true;
803 }
804
805 bool FormMain::OnDropFile_editCurrentMatNormalMap(QEvent * filterevt)
806 {
807         QString path = GetFirstLoadableImagePathFromDragEvent(filterevt);
808         if (!path.isEmpty())
809                 LoadCurSelMatTexture(TextureType::Normal, path);
810
811         return true;
812 }
813
814 bool FormMain::AcceptDropFilterIfUrl(QEvent * filterevt)
815 {
816         QDragEnterEvent* e = dynamic_cast<QDragEnterEvent*>(filterevt);
817         if (e == NULL)
818                 return false;
819
820         if (e->mimeData()->hasUrls())
821                 e->acceptProposedAction();
822
823         return true;
824 }
825
826 QString FormMain::GetFirstLoadableImagePathFromDragEvent(QEvent* filterevt)
827 {
828         QDropEvent* e = dynamic_cast<QDropEvent*>(filterevt);
829         if (e == NULL)
830                 return false;
831
832         if (!e->mimeData()->hasUrls())
833                 return false;
834
835         QList<QUrl> urls = e->mimeData()->urls();
836         for (int i = 0; i < urls.size(); ++i)
837         {
838                 QString path = urls[i].toLocalFile();
839                 if (IsSupportedTextureExt(path))
840                         return path;
841         }
842
843         return QString();
844 }
845
846 bool FormMain::colorAmbient_OnButtonDown(QEvent * filterevt)
847 {
848         QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
849         if (e->buttons() == Qt::LeftButton)
850                 ChangeMatlemColor(ui.colorAmbient);
851         return true;
852 }
853
854 bool FormMain::colorEmission_OnButtonDown(QEvent * filterevt)
855 {
856         QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
857         if (e->buttons() == Qt::LeftButton)
858                 ChangeMatlemColor(ui.colorEmission);
859         return true;
860 }
861
862 bool FormMain::colorDiffuse_OnButtonDown(QEvent * filterevt)
863 {
864         QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
865         if (e->buttons() == Qt::LeftButton)
866                 ChangeMatlemColor(ui.colorDiffuse);
867         return true;
868 }
869
870 bool FormMain::colorSpecular_OnButtonDown(QEvent * filterevt)
871 {
872         QMouseEvent * e = dynamic_cast<QMouseEvent *>(filterevt);
873         if (e->buttons() == Qt::LeftButton)
874                 ChangeMatlemColor(ui.colorSpecular);
875         return true;
876 }
877
878
879 void FormMain::CenteringSplitter(void)
880 {
881         int w = ui.splitter->width();
882         QList<int> s;
883         s.append(w / 2);
884         s.append(w / 2);
885         ui.splitter->setSizes(s);
886 }
887
888 void FormMain::updateView_All(void)
889 {
890         updateView_3D();
891         updateView_2D();
892 }
893
894 void FormMain::updateView_2D(void)
895 {
896         ui.GLWidgetUV->update();
897 }
898
899 void FormMain::updateView_3D(void)
900 {
901         ui.GLWidgetMain->update();
902 }
903
904 void FormMain::on_actionOpen_triggered()
905 {
906         FileDlgFilterList exts;
907         exts.Add( "Wavefront"   , "obj" );
908         exts.Add( "STL"         , "stl" );
909         exts.Add( "PLY"         , "ply" );
910         exts.Add( "Metasequoia" , "mqo" );
911         exts.Add( "Pmd"         , "pmd" );
912         exts.Add( "Collada"     , "dae" );
913         exts.Add( "DirectX"     , "x"   );
914
915         QString filter = FileDlgUtil::ExtListToDlgFilter("Geometry", exts);
916         QString title = "Open file";
917         QString fileName = GetFilePathFromOpenDlg(title, filter);
918
919         if (fileName.isEmpty())
920                 return;
921
922         if (IsResetSceneOnBeforeLoadFile())
923                 ClearAllObjects();
924
925         if (OpenGeomFile(fileName))
926                 return;
927 }
928
929 void FormMain::on_actionExit_triggered()
930 {
931         close();
932 }
933
934 void FormMain::actionVisibleStates_Triggered(bool checked)
935 {
936         QAction* a = dynamic_cast<QAction*>(QObject::sender());
937         if (checked)
938         {
939                 if (a == ui.actionIndexColorMode)
940                 {
941                         ui.actionFixMaterialSilver->setChecked(false);
942                         ui.actionFBMaterial->setChecked(false);
943                 }
944                 else if (a == ui.actionFixMaterialSilver)
945                 {
946                         ui.actionIndexColorMode->setChecked(false);
947                         ui.actionFBMaterial->setChecked(false);
948                 }
949                 else if (a == ui.actionFBMaterial)
950                 {
951                         ui.actionFixMaterialSilver->setChecked(false);
952                         ui.actionIndexColorMode->setChecked(false);
953                 }
954         }
955
956         SyncViewSettingsFromGUI();
957         updateView_All();
958 }
959
960 void FormMain::SyncViewSettingsFromGUI(void)
961 {
962         m_Binder_ViewConfig.UpdateAllData();
963
964         QAction* menu = GetMenuFromShader(m_View3d.m_Config.m_ShaderMode);
965         if (menu != NULL)
966                 menu->setChecked(true);
967 }
968
969 QAction* FormMain::GetMenuFromShader(ShaderType type)
970 {
971         switch(m_View3d.m_Config.m_ShaderMode)
972         {
973         case ShaderType::Phong      : return ui.actionShaderPhong;
974         case ShaderType::Custom     : return ui.actionShaderCustom;
975         case ShaderType::NormalColor: return ui.actionNormalColor;
976         case ShaderType::DepthColor : return ui.actionDepthColor;
977         case ShaderType::Shadowmap  : return ui.actionShadowmap;
978         case ShaderType::Envmap     : return ui.actionEnvmap;
979         case ShaderType::Integrate  : return ui.actionIntegrateShader;
980         case ShaderType::Matcap     : return ui.actionMatcapShader;
981         case ShaderType::Default    : return ui.actionShaderDefault;
982
983         default:
984                 assert(false);
985                 return NULL;
986         };
987 }
988
989 bool FormMain::SaveWindowLayout(const QString& filepath)
990 {
991         WindowConfig config;
992
993         config.m_MainWinLeft   = geometry().x();
994         config.m_MainWinTop    = geometry().y();
995         config.m_MainWinWidth  = geometry().width();
996         config.m_MainWinHeight = geometry().height();
997         config.m_IsMaximized   = isMaximized();
998
999         return config.SaveConfig(filepath.toLocal8Bit().data());
1000 }
1001
1002 bool FormMain::LoadWindowLayout(const QString& filepath)
1003 {
1004         WindowConfig config;
1005         if (!config.LoadConfig(filepath.toLocal8Bit().data()))
1006                 return false;
1007
1008         if (config.m_IsMaximized)
1009                 showMaximized();
1010
1011         int l = config.m_MainWinLeft;
1012         int t = config.m_MainWinTop;
1013         int w = config.m_MainWinWidth;
1014         int h = config.m_MainWinHeight;
1015         setGeometry(l, t, w, h);
1016
1017         return true;
1018 }
1019
1020 void FormMain::actionVisibleStatesUV_Triggered(bool)
1021 {
1022         SyncUVViewSettingsFromGUI();
1023 }
1024
1025 void FormMain::SyncUVViewSettingsFromGUI(void)
1026 {
1027         m_Binder_UVConfig.UpdateAllData();
1028         updateView_All();
1029 }
1030
1031 void FormMain::actionSceneStates_Toggled(bool)
1032 {
1033         SyncSceneSettingsFromGUI();
1034 }
1035
1036 void FormMain::SyncSceneSettingsFromGUI(void)
1037 {
1038         m_Binder_Scene.UpdateAllData();
1039         updateView_All();
1040 }
1041
1042 void FormMain::on_actionWindow_ToolBarView_triggered(bool checked)
1043 {
1044         ui.toolBar_View->setVisible( ui.actionWindow_ToolBarView->isChecked() );
1045 }
1046
1047 void FormMain::on_actionToolBar_Options_toggled(bool checked)
1048 {
1049         ui.toolBar_Option->setVisible(checked);
1050 }
1051
1052 void FormMain::on_actionToolBar_Operation_toggled(bool checked)
1053 {
1054         ui.toolBar_Operation->setVisible(checked);
1055 }
1056
1057 void FormMain::on_actionCameraDist_triggered()
1058 {
1059         m_View3d.AdjustCameraDistAuto();
1060 }
1061
1062 void FormMain::on_actionCameraFront_triggered()
1063 {
1064         m_View3d.MoveCaemraTo(ViewPoint::Front);
1065 }
1066
1067 void FormMain::on_actionCameraBack_triggered()
1068 {
1069         m_View3d.MoveCaemraTo(ViewPoint::Back);
1070 }
1071
1072 void FormMain::on_actionCameraLeft_triggered()
1073 {
1074         m_View3d.MoveCaemraTo(ViewPoint::Left);
1075 }
1076
1077 void FormMain::on_actionCameraRight_triggered()
1078 {
1079         m_View3d.MoveCaemraTo(ViewPoint::Right);
1080 }
1081
1082 void FormMain::on_actionCameraTop_triggered()
1083 {
1084         m_View3d.MoveCaemraTo(ViewPoint::Top);
1085 }
1086
1087 void FormMain::on_actionCameraBottom_triggered()
1088 {
1089         m_View3d.MoveCaemraTo(ViewPoint::Bottom);
1090 }
1091
1092 void FormMain::on_actionCameraPers_triggered()
1093 {
1094         m_View3d.MoveCaemraTo(ViewPoint::Perse);
1095 }
1096
1097 void FormMain::on_actionCameraLookOrigin_triggered()
1098 {
1099         m_View3d.MoveLookPosToOrigin();
1100 }
1101
1102 void FormMain::on_actionCameraLookCenter_triggered()
1103 {
1104         m_View3d.MoveLookPosToCenter();
1105 }
1106
1107 void FormMain::on_actionWindow_3DView_triggered(bool checked)
1108 {
1109         UpdateViewTypeFromMenu();
1110 }
1111
1112 void FormMain::on_actionWindows_DualView_triggered(bool checked)
1113 {
1114         UpdateViewTypeFromMenu();
1115 }
1116
1117 void FormMain::on_actionWindow_UVView_triggered(bool checked)
1118 {
1119         UpdateViewTypeFromMenu();
1120 }
1121
1122 void FormMain::UpdateViewTypeFromMenu(void)
1123 {
1124         if (ui.actionWindows_DualView->isChecked())
1125         {
1126                 ui.frameView3D->setVisible(true);
1127                 ui.frameView2D->setVisible(true);
1128
1129                 // 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.
1130                 static bool firsttime = true;
1131                 if (firsttime)
1132                 {
1133                         firsttime = false;
1134                         CenteringSplitter();
1135                 }
1136         }
1137         if (ui.actionWindow_3DView->isChecked())
1138         {
1139                 ui.frameView3D->setVisible(true);
1140                 ui.frameView2D->setVisible(false);
1141         }
1142         if (ui.actionWindow_UVView->isChecked())
1143         {
1144                 ui.frameView3D->setVisible(false);
1145                 ui.frameView2D->setVisible(true);
1146         }
1147 }
1148
1149 void FormMain::on_actionWindowMaterialList_triggered()
1150 {
1151         ShowAndActivateAndRaise(ui.dockMaterial);
1152         ui.listMaterial->setFocus();
1153 }
1154
1155 void FormMain::on_actionWindowObjectList_triggered()
1156 {
1157         ShowAndActivateAndRaise(ui.dockObject);
1158         ui.treeObjects->setFocus();
1159 }
1160
1161 void FormMain::on_actionWindowCameraList_triggered()
1162 {
1163         ShowAndActivateAndRaise(ui.dockCamera);
1164         ui.listCamera->setFocus();
1165 }
1166
1167 void FormMain::on_actionWindowScenePanel_triggered()
1168 {
1169         ShowAndActivateAndRaise(ui.dockScene);
1170 }
1171
1172 void FormMain::on_actionCursorPanel_triggered()
1173 {
1174         ShowAndActivateAndRaise(ui.dockCursor);
1175 }
1176
1177 void FormMain::on_actionIOOptionPanel_triggered()
1178 {
1179         ShowAndActivateAndRaise(ui.dockIOOption);
1180 }
1181
1182 void FormMain::on_listMaterial_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
1183 {
1184         m_Scene.m_Sels.SetSelMat(ui.listMaterial->currentRow());
1185         OnChangedSelectedMaterial();
1186         updateView_All();
1187 }
1188
1189 void FormMain::ShowAndActivateAndRaise(QDockWidget* widget)
1190 {
1191         widget->setVisible(true);
1192         widget->activateWindow();
1193         widget->raise();
1194 }
1195
1196 void FormMain::on_treeObjects_currentItemChanged(QTreeWidgetItem * current, QTreeWidgetItem * previous)
1197 {
1198         RefreshObjectSelectState();
1199 }
1200
1201 void FormMain::RefreshObjectSelectState(void)
1202 {
1203         SetPrimayrSelectObjectToScene();
1204
1205         QListWidget* list_mat = ui.listMaterial;
1206         list_mat->clear();
1207
1208         const MeshBuf* mbuf = m_Scene.GetPrimaryMeshbuf();
1209         if (mbuf != NULL)
1210         {
1211                 const lib_geo::BaseMesh& mesh = mbuf->m_Mesh;
1212                 for (const lib_geo::BaseMaterial& mat : mesh.m_Materials)
1213                 {
1214                         const std::string& name = mat.m_Name;
1215
1216                         if (name.empty())
1217                                 list_mat->addItem("--");
1218                         else
1219                                 list_mat->addItem(QString::fromLocal8Bit(name.c_str()));
1220                 }
1221         }
1222
1223         const GeomObject* obj = m_Scene.GetPrimaryObject();
1224         if (mbuf != NULL)
1225         {
1226                 ui.actionSelObjectVisible->setChecked(mbuf->IsVisible());
1227         }
1228         else if (obj != NULL)
1229         {
1230                 ui.actionSelObjectVisible->setChecked(obj->m_Visible);
1231         }
1232         
1233         if (obj != NULL)
1234                 ui.actionSelObjectVertexOnlyMode->setChecked(obj->m_VertexOnlyMode);
1235
1236         if (list_mat->count() > 0 && list_mat->currentRow() < 0)
1237         {
1238                 list_mat->setCurrentRow(0);
1239                 m_Scene.m_Sels.SetSelMat(0);
1240                 OnChangedSelectedMaterial();
1241         }
1242
1243         updateView_All();
1244 }
1245
1246 void FormMain::OnChangedSelectedMaterial(void)
1247 {
1248         if (IsAutUVFit())
1249         {
1250                 m_View2d.FitView();
1251         }
1252
1253         ui.editCurrentTexName->clear();
1254
1255         GeomTextureSet* ts = m_Scene.GetSelectedTexture();
1256         if (ts == NULL)
1257         {
1258                 ui.editCurrentTexName->setText("");
1259                 ui.editMatCapEachMaterial->setText("");
1260         }
1261         else
1262         {
1263                 QString name_c, name_n;
1264
1265                 gl::GlTexture* tex_c = ts->GetTexColor();
1266                 if (tex_c != NULL)
1267                         name_c = QString::fromLocal8Bit(tex_c->GetName().c_str());
1268
1269                 gl::GlTexture* tex_n = ts->GetTexNormal();
1270                 if (tex_n != NULL)
1271                         name_n = QString::fromLocal8Bit(tex_n->GetName().c_str());
1272
1273                 ui.editCurrentTexName->setText(name_c);
1274                 ui.editCurrentMatNormalMap->setText(name_n);
1275
1276                 MatcapImage& matcap = ts->TexMatcap;
1277                 ui.editMatCapEachMaterial->setText(matcap.GetName());
1278         }
1279
1280         lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
1281         if (mat != NULL)
1282         {
1283                 SetColorPalleteBG(ui.colorAmbient  , ToQColor(mat->m_Ambient));
1284                 SetColorPalleteBG(ui.colorEmission , ToQColor(mat->m_Emission));
1285                 SetColorPalleteBG(ui.colorDiffuse  , ToQColor(mat->m_Diffuse));
1286                 SetColorPalleteBG(ui.colorSpecular , ToQColor(mat->m_Specular));
1287                 SetMatShininessSliderPos(mat->m_Shininess);
1288         }
1289         else
1290         {
1291                 QColor w(255, 255, 255);
1292                 SetColorPalleteBG( ui.colorAmbient  , w );
1293                 SetColorPalleteBG( ui.colorEmission , w );
1294                 SetColorPalleteBG( ui.colorDiffuse  , w );
1295                 SetColorPalleteBG( ui.colorSpecular , w );
1296                 SetMatShininessSliderPos(0);
1297         }
1298
1299         updateView_All();
1300 }
1301
1302 void FormMain::SetMatShininessSliderPos(float shininess)
1303 {
1304         int val_max = ui.sliderShininess->maximum();
1305         int slider_pos = (int)(shininess * (float)val_max / 200.0f);
1306         slider_pos = (lm::min)(val_max, slider_pos);
1307         ui.sliderShininess->blockSignals(true);
1308         ui.sliderShininess->setValue(slider_pos);
1309         ui.sliderShininess->blockSignals(false);
1310         ui.labelShininessVal->setText(QString::number(shininess, 'f', 2));
1311 }
1312
1313 void FormMain::keyPressEvent(QKeyEvent *e)
1314 {
1315         Modifier m(e);
1316         if (m.Flag_C() && e->key() == Qt::Key_Tab)
1317         {
1318                 FocusNextSubDlg();
1319         }
1320 }
1321
1322 void FormMain::FocusNextSubDlg(void)
1323 {
1324         std::vector<QDockWidget*> widgets;
1325
1326         if (ui.dockObject   ->isVisible()) widgets.push_back( ui.dockObject   );
1327         if (ui.dockCamera   ->isVisible()) widgets.push_back( ui.dockCamera   );
1328         if (ui.dockScene    ->isVisible()) widgets.push_back( ui.dockScene    );
1329         if (ui.dockMaterial ->isVisible()) widgets.push_back( ui.dockMaterial );
1330
1331         if (widgets.empty())
1332                 return;
1333
1334         QDockWidget* next_widget = NULL;
1335
1336         for (size_t i = 0; i < widgets.size(); ++i)
1337         {
1338                 if (widgets[i] == m_LastFocusedDockDlg)
1339                 {
1340                         next_widget = widgets[(i + 1) % widgets.size()];
1341                         break;
1342                 }
1343         }
1344
1345         if (next_widget == NULL)
1346                 next_widget = widgets.front();
1347
1348         m_LastFocusedDockDlg = next_widget;
1349
1350         next_widget->activateWindow();
1351         next_widget->raise();
1352         next_widget->setFocus();
1353 }
1354
1355 void FormMain::dragEnterEvent(QDragEnterEvent* e)
1356 {
1357         if (e->mimeData()->hasUrls())
1358                 e->acceptProposedAction();
1359 }
1360
1361 void FormMain::dropEvent(QDropEvent* e)
1362 {
1363         if (e->mimeData()->hasUrls())
1364         {
1365                 QList<QUrl> urls = e->mimeData()->urls();
1366
1367                 std::vector<QString> geom_files;
1368
1369                 for (int i = 0; i < urls.size(); ++i)
1370                 {
1371                         QString path = urls[i].toLocalFile();
1372                         if (FormatType::IsGeomFileExt(path))
1373                                 geom_files.push_back(path);
1374                 }
1375
1376                 if (!geom_files.empty())
1377                 {
1378                         if (IsResetSceneOnBeforeLoadFile())
1379                                 ClearAllObjects();
1380
1381                         for (size_t i = 0; i < geom_files.size(); ++i)
1382                         {
1383                                 if (OpenGeomFile(geom_files[i]))
1384                                         continue;
1385                         }
1386                 }
1387
1388                 for (int i = 0; i < urls.size(); ++i)
1389                 {
1390                         QString path = urls[i].toLocalFile();
1391
1392                         if (IsSupportedTextureExt(path))
1393                         {
1394                                 OpenFixTextureFile(path);
1395                                 continue;
1396                         }
1397
1398                         if (IsCameraFile(path))
1399                         {
1400                                 OpenCameraFile(path);
1401                                 continue;
1402                         }
1403                 }
1404         }
1405 }
1406
1407 bool FormMain::IsResetSceneOnBeforeLoadFile(void) const
1408 {
1409         if (QApplication::keyboardModifiers() & Qt::ShiftModifier)
1410                 return true;
1411
1412         return false;
1413 }
1414
1415 //! \83I\83u\83W\83F\83N\83g\82Ì\83}\83e\83\8a\83A\83\8b\82É\90Ý\92è\82³\82ê\82½\82à\82Ì\82Æ\82Í\95Ê\82Ì\83e\83N\83X\83`\83\83\82ð\8ew\92è\82·\82é.
1416 void FormMain::OpenFixTextureFile(const QString& path)
1417 {
1418         std::string fname = path.toLocal8Bit().data();
1419
1420         m_ContextShare.BeginDrawTop();
1421         m_Scene.LoadDefaultMatTexture(fname);
1422         m_ContextShare.EndDrawTop();
1423
1424         updateView_All();
1425 }
1426
1427 bool FormMain::OpenGeomFile(const QString& path)
1428 {
1429         m_Scene.m_ObjSplit = ui.checkSplitOBJ->isChecked();
1430
1431         m_ContextShare.BeginDrawTop();
1432
1433         bool suc = true;
1434         try
1435         {
1436                 m_Scene.ImportFileAutoFmt(path);
1437         }
1438         catch(const FileLoadErrorException& ex)
1439         {
1440                 QString msg;
1441                 msg += "Failed Load ";
1442                 msg += path + "\n\n";
1443                 msg += QString::fromLocal8Bit(ex.what());
1444
1445                 QMessageBox::warning(this, "", msg);
1446                 suc = false;
1447         }
1448
1449         m_ContextShare.EndDrawTop();
1450
1451         RebuildObjectList();
1452
1453         ResetSequenceSliderRange();
1454
1455         updateView_All();
1456
1457         if (!suc)
1458                 return false;
1459
1460         AddRecentFile(path);
1461
1462         return true;
1463 }
1464
1465 void FormMain::ClearAllObjects(void)
1466 {
1467         m_ContextShare.BeginDrawTop();
1468
1469         m_Scene.ClearObjects();
1470
1471         m_ContextShare.EndDrawTop();
1472
1473         m_View3d.ClearRenderMap();
1474
1475         RebuildObjectList();
1476         RefreshObjectSelectState();
1477
1478         updateView_All();
1479 }
1480
1481 void FormMain::RebuildObjectList(void)
1482 {
1483         QTreeWidget* obj_tree = ui.treeObjects;
1484
1485         obj_tree->setCurrentItem(NULL);
1486         obj_tree->blockSignals(true);
1487
1488         obj_tree->clear();
1489
1490         obj_tree->setSelectionBehavior(QAbstractItemView::SelectRows);
1491         obj_tree->setSelectionMode(QAbstractItemView::SingleSelection);
1492         obj_tree->setEditTriggers(QAbstractItemView::NoEditTriggers);
1493
1494         obj_tree->setColumnCount(4);
1495
1496         InitObjectListHeader();
1497
1498         for (const geom::GeomObject& obj : m_Scene.m_Objects)
1499         {
1500                 QTreeWidgetItem* n = CreateObjectTreeNode(obj);
1501                 PushbackTreeNode(ui.treeObjects, n);
1502                 n->setExpanded(true);
1503         }
1504
1505         SetPrimayrSelectObjectFromScene();
1506
1507         obj_tree->blockSignals(false);
1508
1509         if (obj_tree->currentItem() == NULL)
1510         {
1511                 if (!m_Scene.m_Objects.empty())
1512                 {
1513                         QTreeWidgetItem* ti = obj_tree->topLevelItem(0);
1514                         obj_tree->setCurrentItem(ti);
1515
1516                         if (IsAutUVFit())
1517                                 m_View2d.FitView();
1518                 }
1519         }
1520
1521         ResizeTreeColumns(obj_tree, 4);
1522 }
1523
1524
1525 bool FormMain::IsCameraFile(const QString& path) const
1526 {
1527         QFileInfo fInfo( path );
1528         QString ext = fInfo.suffix().toLower();
1529         return (ext == "camera");
1530 }
1531
1532 bool FormMain::OpenCameraFile(const QString& path)
1533 {
1534         std::string fname = path.toLocal8Bit().data();
1535
1536         if(!m_View3d.m_CameraRecord.LoadCamera(fname.c_str()))
1537                 return false;
1538
1539         ui.listCamera->blockSignals(true);
1540         ui.listCamera->clear();
1541         for (size_t i = 0; i < m_View3d.m_CameraRecord.m_Records.size(); ++i)
1542         {
1543                 ui.listCamera->addItem( QString::number(i) );
1544         }
1545         ui.listCamera->blockSignals(false);
1546
1547         return true;
1548 }
1549
1550
1551 void FormMain::actionGeomStates_Triggered(bool)
1552 {
1553         ApplyGeomStateFromGUI();
1554
1555         m_Scene.UpdateTransform();
1556
1557         updateView_All();
1558 }
1559
1560 void FormMain::ApplyGeomStateFromGUI(void)
1561 {
1562         m_Scene.m_Config.m_EnableAutoCentering = ui.actionCentering->isChecked();
1563         m_Scene.m_Config.m_EnableAutoReisze    = ui.actionAutoResize->isChecked();
1564 }
1565
1566 void FormMain::ApplyGeomStateDataoToGUI(void)
1567 {
1568         ui.actionAutoResize ->setChecked( m_Scene.m_Config.m_EnableAutoReisze    );
1569         ui.actionCentering  ->setChecked( m_Scene.m_Config.m_EnableAutoCentering );
1570
1571         ui.checkShowOnlySelect->setChecked(m_View3d.m_Config.m_ShowOnlySelect);
1572 }
1573
1574 void FormMain::on_actionGeomClear_triggered()
1575 {
1576         ClearAllObjects();
1577 }
1578
1579
1580 void FormMain::on_actionUVFitView_triggered()
1581 {
1582         m_View2d.FitView();
1583         updateView_All();
1584 }
1585
1586 void FormMain::on_actionSelObjectDelete_triggered()
1587 {
1588         DeleteSelectedObject();
1589 }
1590
1591 void FormMain::on_actionSelObjectReload_triggered()
1592 {
1593         GeomObject* obj = m_Scene.GetPrimaryObject();
1594         if (obj == NULL)
1595                 return;
1596
1597         if (!obj->IsFileObject())
1598         {
1599                 QMessageBox::information(this, "", "IsNotFileObject");
1600                 return;
1601         }
1602
1603         m_Scene.ReloadObject(obj);
1604
1605         RebuildObjectList();
1606
1607         m_View3d.ClearRenderMap();
1608         updateView_All();
1609 }
1610
1611 void FormMain::on_actionSelObjectVisible_triggered()
1612 {
1613         FlipVisibleSelectedObject();
1614 }
1615
1616 void FormMain::on_actionSelObjectVertexOnlyMode_triggered()
1617 {
1618         GeomObject* obj = m_Scene.GetPrimaryObject();
1619         if (obj == NULL)
1620                 return;
1621
1622         obj->m_VertexOnlyMode = !obj->m_VertexOnlyMode;
1623
1624         ui.actionSelObjectVertexOnlyMode->setChecked(obj->m_VertexOnlyMode);
1625
1626         updateView_All();
1627 }
1628
1629 void FormMain::on_actionSelObjectFlipFace_triggered()
1630 {
1631         m_Scene.FlipCurselFace(false);
1632
1633         ui.GLWidgetMain->makeCurrent();
1634         std::vector<MeshBuf*> mv = m_Scene.GetCurSelMeshes();
1635         for (MeshBuf* m : mv)
1636         {
1637                 m_View3d.ReleaseRenderbuffer(m);
1638         }
1639         ui.GLWidgetMain->doneCurrent();
1640
1641         updateView_All();
1642 }
1643
1644 void FormMain::on_actionSelObjectFlipNormal_triggered()
1645 {
1646         m_Scene.FlipCurselFace(true);
1647
1648         ui.GLWidgetMain->makeCurrent();
1649         std::vector<MeshBuf*> mv = m_Scene.GetCurSelMeshes();
1650         for (MeshBuf* m : mv)
1651         {
1652                 m_View3d.ReleaseRenderbuffer(m);
1653         }
1654         ui.GLWidgetMain->doneCurrent();
1655
1656         updateView_All();
1657 }
1658
1659 void FormMain::on_actionSelObjectOpenDir_triggered()
1660 {
1661         GeomObject* obj = m_Scene.GetPrimaryObject();
1662         if (obj == NULL)
1663                 return;
1664
1665         if (!obj->IsFileObject())
1666                 return;
1667
1668         QString path = QString::fromLocal8Bit(obj->m_FilePath.c_str());
1669         QString p2 = QDir::toNativeSeparators(path);
1670         QGui::ShowExplorerFileSel(p2);
1671 }
1672
1673 void FormMain::on_actionShowOnlySelected_triggered()
1674 {
1675         ShowObjectOnlySelected();
1676 }
1677
1678 void FormMain::on_actionSelObjectTriangulate_triggered()
1679 {
1680         MeshBuf* mbuf = m_Scene.GetPrimaryMeshbuf();
1681         if (mbuf == NULL)
1682                 return;
1683
1684         mbuf->Triangulate();
1685
1686         m_View3d.ReleaseAllRenderBuffer();
1687
1688         RebuildObjectList();
1689         updateView_All();
1690 }
1691
1692 void FormMain::on_actionTreeCollapseAll_triggered()
1693 {
1694         TreeUtil::SetAllTopExpand(ui.treeObjects, false);
1695 }
1696
1697 void FormMain::on_actionTreeExpandAll_triggered()
1698 {
1699         TreeUtil::SetAllTopExpand(ui.treeObjects, true);
1700 }
1701
1702
1703 void FormMain::on_actionAddSample_triggered()
1704 {
1705         SampleShapeBuilder::CreateSphere(m_Scene);
1706         OnDoneAddGeom();
1707 }
1708
1709 void FormMain::on_actionAddGroundPlane_triggered()
1710 {
1711         SampleShapeBuilder::CreateGroundPlane(m_Scene);
1712         OnDoneAddGeom();
1713 }
1714
1715 void FormMain::OnDoneAddGeom(void)
1716 {
1717         QTreeWidget* obj_tree = ui.treeObjects;
1718
1719         const GeomObject& obj = m_Scene.m_Objects.back();
1720
1721         obj_tree->setCurrentItem(NULL);
1722         obj_tree->blockSignals(true);
1723
1724         QTreeWidgetItem* n = CreateObjectTreeNode(obj);
1725         PushbackTreeNode(obj_tree, n);
1726         n->setExpanded(true);
1727
1728         SetPrimayrSelectObjectFromScene();
1729
1730         obj_tree->blockSignals(false);
1731
1732         if (obj_tree->currentItem() == NULL)
1733         {
1734                 if (!m_Scene.m_Objects.empty())
1735                 {
1736                         QTreeWidgetItem * j = obj_tree->topLevelItem(0);
1737                         obj_tree->setCurrentItem(j);
1738
1739                         if (IsAutUVFit())
1740                                 m_View2d.FitView();
1741                 }
1742         }
1743
1744         ResizeTreeColumns(obj_tree, 4);
1745
1746         ResetSequenceSliderRange();
1747
1748         updateView_All();
1749 }
1750
1751
1752 void FormMain::on_actionShaderDefault_triggered(bool)
1753 {
1754         ChangeShaderMenuMain(ShaderType::Default);
1755 }
1756
1757 void FormMain::on_actionShaderPhong_triggered(bool)
1758 {
1759         ChangeShaderMenuMain(ShaderType::Phong);
1760 }
1761
1762 void FormMain::on_actionShaderCustom_triggered(bool)
1763 {
1764         ChangeShaderMenuMain(ShaderType::Custom);
1765 }
1766
1767 void FormMain::on_actionNormalColor_triggered(bool)
1768 {
1769         ChangeShaderMenuMain(ShaderType::NormalColor);
1770 }
1771
1772 void FormMain::on_actionDepthColor_triggered(bool)
1773 {
1774         ChangeShaderMenuMain(ShaderType::DepthColor);
1775 }
1776
1777 void FormMain::on_actionShadowmap_triggered(bool)
1778 {
1779         ChangeShaderMenuMain(ShaderType::Shadowmap);
1780 }
1781
1782 void FormMain::on_actionEnvmap_triggered(bool)
1783 {
1784         ChangeShaderMenuMain(ShaderType::Envmap);
1785 }
1786
1787 void FormMain::on_actionIntegrateShader_triggered(bool)
1788 {
1789         ChangeShaderMenuMain(ShaderType::Integrate);
1790 }
1791
1792 void FormMain::on_actionMatcapShader_triggered(bool)
1793 {
1794         ChangeShaderMenuMain(ShaderType::Matcap);
1795 }
1796
1797 void FormMain::SyncShaderSettingsToGUI(void)
1798 {
1799         ChangeShaderMenuMain(m_View3d.m_Config.m_ShaderMode);
1800 }
1801
1802 void FormMain::ChangeShaderMenuMain(ShaderType type)
1803 {
1804         m_View3d.m_Config.m_ShaderMode = type;
1805         updateView_All();
1806 }
1807
1808
1809 void FormMain::on_actionCreate_Check_triggered()
1810 {
1811         CreateSampleTextureMain(SampleTextureBuilder::TEX_CHECKER);
1812 }
1813
1814 void FormMain::on_actionCreate_Stripe_V_triggered()
1815 {
1816         CreateSampleTextureMain(SampleTextureBuilder::TEX_STRIPE_V);
1817 }
1818
1819 void FormMain::on_actionCreate_Stripe_H_triggered()
1820 {
1821         CreateSampleTextureMain(SampleTextureBuilder::TEX_STRIPE_H);
1822 }
1823
1824 void FormMain::CreateSampleTextureMain(SampleTextureBuilder::TextureType tex_type)
1825 {
1826         m_ContextShare.BeginDrawTop();
1827         m_Scene.CreateSampleTexture(tex_type);
1828         m_ContextShare.EndDrawTop();
1829
1830         updateView_All();
1831 }
1832
1833 bool FormMain::IsAutUVFit(void) const
1834 {
1835         return ui.actionUVAutoFit->isChecked();
1836 }
1837
1838
1839 void FormMain::on_pushDeleteSelectedObject_clicked()
1840 {
1841         DeleteSelectedObject();
1842 }
1843
1844 void FormMain::on_treeObjects_itemChanged(QTreeWidgetItem * item, int column)
1845 {
1846         QTreeWidget* obj_tree = ui.treeObjects;
1847
1848         if (column == 1)
1849         {
1850                 QTreeWidgetItem* t = item->parent();
1851                 bool checked = (item->checkState(1) == Qt::Checked);
1852                 if (t == NULL)
1853                 {
1854                         int sel_idx = obj_tree->indexOfTopLevelItem(item);
1855                         GeomObject& obj = m_Scene.m_Objects[sel_idx];
1856                         obj.m_Visible = checked;
1857                 }
1858                 else
1859                 {
1860                         int sel_idx = obj_tree->indexOfTopLevelItem(t);
1861                         int midx = t->indexOfChild(item);
1862
1863                         GeomObject& obj = m_Scene.m_Objects[sel_idx];
1864                         MeshBuf& mb = obj.m_MeshAry[midx];
1865                         mb.m_Visible = checked;
1866                 }
1867
1868                 updateView_All();
1869         }
1870 }
1871
1872
1873 void FormMain::DeleteSelectedObject()
1874 {
1875         QTreeWidget* obj_tree = ui.treeObjects;
1876         QTreeWidgetItem* ti = obj_tree->currentItem();
1877         if (ti == NULL)
1878                 return;
1879
1880         QTreeWidgetItem* pn = ti->parent();
1881
1882         int sel_idx;
1883         if (pn == NULL)
1884                 sel_idx = obj_tree->indexOfTopLevelItem(ti);
1885         else
1886                 sel_idx = obj_tree->indexOfTopLevelItem(pn);
1887
1888         if (sel_idx < 0)
1889                 return;
1890
1891         m_ContextShare.BeginDrawTop();
1892
1893         m_Scene.RemoveItem(sel_idx);
1894
1895         m_ContextShare.EndDrawTop();
1896
1897         m_View3d.ClearRenderMap();
1898
1899         obj_tree->setCurrentItem(NULL);
1900         obj_tree->takeTopLevelItem(sel_idx);
1901
1902         ResizeTreeColumns(obj_tree, 4);
1903
1904         ti = obj_tree->currentItem();
1905         sel_idx = obj_tree->indexOfTopLevelItem(ti);
1906         m_Scene.m_Sels.SelectObject(sel_idx);
1907
1908         m_Scene.UpdateTransform();
1909
1910         RefreshObjectSelectState();
1911
1912         ResetSequenceSliderRange();
1913
1914         updateView_All();
1915 }
1916
1917 void FormMain::FlipVisibleSelectedObject()
1918 {
1919         QTreeWidget* obj_tree = ui.treeObjects;
1920         QTreeWidgetItem * item = obj_tree->currentItem();
1921         if (item == NULL)
1922                 return;
1923
1924         item->setCheckState(1, FilpState(item->checkState(1)));
1925 }
1926
1927 Qt::CheckState FormMain::FilpState(Qt::CheckState state) const
1928 {
1929         if(state == Qt::Checked)
1930                 return Qt::Unchecked;
1931         else
1932                 return Qt::Checked;
1933 }
1934
1935 void FormMain::ShowObjectOnlySelected(void)
1936 {
1937         GeomObject* sel_obj = m_Scene.GetPrimaryObject();
1938         if (sel_obj == NULL)
1939                 return;
1940
1941         for (GeomObject& o : m_Scene.m_Objects)
1942         {
1943                 o.m_Visible = (sel_obj == &o);
1944         }
1945
1946         RebuildObjectList();
1947         updateView_All();
1948 }
1949
1950 void FormMain::ShowAllObject(void)
1951 {
1952         m_Scene.ShowAllObject();
1953
1954         RebuildObjectList();
1955         updateView_All();
1956 }
1957
1958 void FormMain::HideAllObject(void)
1959 {
1960         m_Scene.HideAllObject();
1961
1962         RebuildObjectList();
1963         updateView_All();
1964 }
1965
1966 void FormMain::on_actionUVResetView_triggered()
1967 {
1968         m_View2d.ResetView();
1969
1970         updateView_All();
1971 }
1972
1973
1974 //! \83\8f\83C\83\84\81[\83I\81[\83o\81[\83\8c\83C\95\\8e¦\8e\9e\82Ì\90F\90Ý\92è
1975 void FormMain::on_actionWireColor_triggered()
1976 {
1977         m_WireColorSelDlg.exec();
1978 }
1979
1980 //! \83f\83t\83H\83\8b\83g\83}\83e\83\8a\83A\83\8b\82Ì\90F\90Ý\92è
1981 void FormMain::on_actionFaceColor_triggered()
1982 {
1983         const lib_graph::color4f& c = m_Scene.m_DefaultMaterial.m_Diffuse;
1984
1985         m_DiffuseColorSelDlg.setOption(QColorDialog::ShowAlphaChannel);
1986         m_DiffuseColorSelDlg.setCurrentColor(ToQColor(c));
1987         m_DiffuseColorSelDlg.exec();
1988 }
1989
1990 //! \94w\8ci\90F\82Ì\90Ý\92è
1991 void FormMain::on_actionBackGroundColor_triggered()
1992 {
1993         const lib_graph::color4f& c = m_View3d.m_BGColor;
1994
1995         m_BGColorSelDlg.setCurrentColor(ToQColor(c));
1996         m_BGColorSelDlg.exec();
1997 }
1998
1999 void FormMain::WireOverlayColorChanged(const QColor & color)
2000 {
2001         lib_graph::color3b& c = m_View3d.m_Config.m_WireColor;
2002         c.set(color.red(), color.green(), color.blue());
2003
2004         m_View3d.ReleaseAllRenderBuffer();
2005
2006         updateView_All();
2007 }
2008
2009 void FormMain::CopyRGB(lib_graph::color4f& c, const QColor & color)
2010 {
2011         c.r() = (float)color.red()   / 255.0f;
2012         c.g() = (float)color.green() / 255.0f;
2013         c.b() = (float)color.blue()  / 255.0f;
2014 }
2015
2016 void FormMain::CopyRGBA(lib_graph::color4f& c, const QColor & color)
2017 {
2018         c.r() = (float)color.red()   / 255.0f;
2019         c.g() = (float)color.green() / 255.0f;
2020         c.b() = (float)color.blue()  / 255.0f;
2021         c.a() = (float)color.alpha() / 255.0f;
2022 }
2023
2024 void FormMain::FaceDiffuseColorChanged(const QColor & color)
2025 {
2026         lib_graph::color4f& c = m_Scene.m_DefaultMaterial.m_Diffuse;
2027         CopyRGB(c, color);
2028
2029         m_View3d.ReleaseAllRenderBuffer();
2030         updateView_All();
2031 }
2032
2033 void FormMain::BGColorChanged(const QColor & color)
2034 {
2035         lib_graph::color4f& c = m_View3d.m_BGColor;
2036         CopyRGB(c, color);
2037
2038         updateView_All();
2039 }
2040
2041 void FormMain::SetSelectedMaterialColor(QColor col)
2042 {
2043         lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
2044         if (mat == NULL)
2045                 return;
2046
2047         if (m_SelMatColorWidget == ui.colorAmbient  ) CopyRGBA(mat->m_Ambient  , col);
2048         if (m_SelMatColorWidget == ui.colorEmission ) CopyRGBA(mat->m_Emission , col);
2049         if (m_SelMatColorWidget == ui.colorDiffuse  ) CopyRGBA(mat->m_Diffuse  , col);
2050         if (m_SelMatColorWidget == ui.colorSpecular ) CopyRGBA(mat->m_Specular , col);
2051
2052         SetColorPalleteBG(m_SelMatColorWidget, col);
2053 }
2054
2055 void FormMain::SelMatColorChanged(const QColor & color)
2056 {
2057         SetSelectedMaterialColor(color);
2058         m_View3d.ResetPrimaryObjectLists();
2059         updateView_All();
2060 }
2061
2062
2063 void FormMain::on_actionWindowOptions_triggered()
2064 {
2065         m_ViewConfigDlg.showNormal();
2066         m_ViewConfigDlg.show();
2067         m_ViewConfigDlg.activateWindow();
2068 }
2069
2070 void FormMain::on_actionWindowCustomShader_triggered()
2071 {
2072         if (m_CustomShaderDlg == NULL)
2073         {
2074                 m_CustomShaderDlg = new FormCustomShader(this);
2075                 m_CustomShaderDlg->SetShaderLibrary(&m_View3d.m_ShaderLib);
2076                 m_CustomShaderDlg->SetParentWidget(ui.GLWidgetMain);
2077                 m_CustomShaderDlg->LoadOrSetDefaultCode();
2078                 connect(
2079                         m_CustomShaderDlg,
2080                         SIGNAL(ShaderBuild()),
2081                         this,
2082                         SLOT(CustomShaderDlg_ShaderBuild()));
2083         }
2084
2085         m_CustomShaderDlg->showNormal();
2086         m_CustomShaderDlg->show();
2087         m_CustomShaderDlg->activateWindow();
2088 }
2089
2090
2091 void FormMain::ConfigChangedDlg_ConfigChanged()
2092 {
2093         m_View3d.ReleaseAllRenderBuffer();
2094         updateView_All();
2095 }
2096
2097 void FormMain::CrossSectionDlg_ConfigChanged()
2098 {
2099         updateView_All();
2100 }
2101
2102
2103 void FormMain::OnPaintImage(QPrinter *printer)
2104 {
2105         QPainter painter(printer);
2106
2107         QRect rect = painter.viewport();
2108         QSize size = this->size();
2109         size.scale(rect.size(), Qt::KeepAspectRatio);//\8fc\89¡\94ä\88Û\8e\9d
2110
2111         painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
2112         painter.setWindow(this->rect());
2113
2114         this->render(&painter);
2115 }
2116
2117 void FormMain::on_actionPrint_triggered()
2118 {
2119         PrintImage(false);
2120 }
2121
2122 void FormMain::on_actionPrintPreview_triggered()
2123 {
2124         PrintImage(true);
2125 }
2126
2127 void FormMain::PrintImage(bool WithPreview)
2128 {
2129         //QPrinter printer(QPrinter::ScreenResolution);
2130         QPrinter printer(QPrinter::ScreenResolution);
2131
2132         if(WithPreview)
2133         {
2134                 QPrintPreviewDialog preview(&printer, this);
2135                 preview.setWindowFlags( Qt::Window );
2136                 connect(
2137                         &preview,
2138                         SIGNAL(paintRequested(QPrinter *)),
2139                         SLOT(OnPaintImage(QPrinter *)));
2140
2141                 preview.showMaximized();
2142                 preview.exec();
2143         }
2144         else
2145         {
2146                 QPrintDialog printDialog(&printer, this);
2147                 if(printDialog.exec() == QDialog::Accepted)
2148                         OnPaintImage(&printer);
2149         }
2150 }
2151
2152
2153 void FormMain::on_pushButtonAddCameraRecord_clicked()
2154 {
2155         m_View3d.RecordCamera();
2156
2157         ui.listCamera->addItem( QString::number(ui.listCamera->count()) );
2158
2159         updateView_3D();
2160 }
2161
2162 void FormMain::on_pushButtonDeleteCameraRecord_clicked()
2163 {
2164         int idx = ui.listCamera->currentRow();
2165         if(idx < 0)
2166                 return;
2167
2168         m_View3d.RemoveRecordedCamera(idx);
2169
2170         for (int i = idx+1; i < ui.listCamera->count(); ++i)
2171         {
2172                 ui.listCamera->item(i)->setText(QString::number(i - 1));
2173         }
2174
2175         ui.listCamera->takeItem(idx);
2176
2177         updateView_3D();
2178 }
2179
2180 void FormMain::on_pushCameraRecordClear_clicked()
2181 {
2182         m_View3d.ClearRecordedCamera();
2183
2184         ui.listCamera->clear();
2185
2186         updateView_3D();
2187 }
2188
2189 void FormMain::on_listCamera_itemDoubleClicked(QListWidgetItem *item)
2190 {
2191         int idx = ui.listCamera->currentRow();
2192         if (idx < 0)
2193                 return;
2194
2195         m_View3d.MoveToRecordedCamera(idx, ui.checkCameraAnimation->isChecked());
2196 }
2197
2198 void FormMain::on_actionSaveCamera_triggered()
2199 {
2200         QString title = "camera";
2201         QString filter = "Camera File(*.camera)";
2202         QString fileName = GetFilePathFromSaveDlg(title, filter);
2203         if (fileName.isEmpty())
2204                 return;
2205
2206         m_View3d.m_CameraRecord.SaveCamera(fileName.toLocal8Bit().data());
2207 }
2208
2209 void FormMain::on_actionProjectionOrtho_triggered()
2210 {
2211         ui.actionProjectionOrtho->setChecked(true);
2212         ui.actionProjectionPers->setChecked(false);
2213
2214         m_View3d.m_Camera.m_ProjMode = gl::Camera::PROJ_ORTHO;
2215
2216         updateView_All();
2217 }
2218
2219 void FormMain::on_actionProjectionPers_triggered()
2220 {
2221         ui.actionProjectionPers->setChecked(true);
2222         ui.actionProjectionOrtho->setChecked(false);
2223
2224         m_View3d.m_Camera.m_ProjMode = gl::Camera::PROJ_PERS;
2225
2226         updateView_All();
2227 }
2228
2229
2230 void FormMain::CustomShaderDlg_ShaderBuild()
2231 {
2232         updateView_All();
2233 }
2234
2235 void FormMain::OnAnimationTimerUpdated()
2236 {
2237         static const float rot_speed = 0.005f;
2238
2239         if (ui.actionRotateCamera->isChecked())
2240         {
2241                 m_View3d.m_Camera.m_Manip.Tumble(rot_speed, 0.0f);
2242                 UpdateCameraStatus();
2243         }
2244
2245         if (ui.actionRotateLight->isChecked())
2246                 m_View3d.m_ControlLight.m_Position.rotate_y(rot_speed);
2247
2248         if (ui.actionAnimation->isChecked())
2249         {
2250                 StepSequence(1);
2251                 if (IsLastSequence())
2252                         ui.actionAnimation->setChecked(false);
2253         }
2254         else if (ui.actionAnimationRev->isChecked())
2255         {
2256                 StepSequence(-1);
2257                 if (IsTopSequence())
2258                         ui.actionAnimationRev->setChecked(false);
2259         }
2260
2261         updateView_3D();
2262 }
2263
2264 void FormMain::on_actionRotateCamera_toggled(bool checked)
2265 {
2266         UpdateAnimState();
2267 }
2268
2269 void FormMain::on_actionRotateLight_toggled(bool checked)
2270 {
2271         UpdateAnimState();
2272 }
2273
2274 void FormMain::on_actionAnimation_toggled(bool checked)
2275 {
2276         if (checked)
2277         {
2278                 ui.actionAnimationRev->setChecked(false);
2279                 if (IsLastSequence())
2280                 {
2281                         QSlider* s = ui.sliderSequence;
2282                         s->setValue(0);
2283                 }
2284         }
2285
2286         ui.butonAnimationFwd->blockSignals(true);
2287         ui.butonAnimationFwd->setChecked(checked);
2288         ui.butonAnimationFwd->blockSignals(false);
2289
2290         UpdateAnimState();
2291 }
2292
2293 void FormMain::on_actionAnimationRev_toggled(bool checked)
2294 {
2295         if (checked)
2296         {
2297                 ui.actionAnimation->setChecked(false);
2298                 if (IsTopSequence())
2299                 {
2300                         QSlider* s = ui.sliderSequence;
2301                         s->setValue(s->maximum());
2302                 }
2303         }
2304
2305         ui.butonAnimationRev->blockSignals(true);
2306         ui.butonAnimationRev->setChecked(checked);
2307         ui.butonAnimationRev->blockSignals(false);
2308
2309         UpdateAnimState();
2310 }
2311
2312 void FormMain::on_butonAnimationFwd_toggled(bool checked)
2313 {
2314         ui.actionAnimation->setChecked(checked);
2315 }
2316
2317 void FormMain::on_butonAnimationRev_toggled(bool checked)
2318 {
2319         ui.actionAnimationRev->setChecked(checked);
2320 }
2321
2322 void FormMain::UpdateAnimState(void)
2323 {
2324         if (IsEnableAnimation())
2325                 m_AnimationTimer.start();
2326         else
2327                 m_AnimationTimer.stop();
2328 }
2329
2330 bool FormMain::IsEnableAnimation(void)
2331 {
2332         if (ui.actionRotateCamera->isChecked())
2333                 return true;
2334         if (ui.actionRotateLight->isChecked())
2335                 return true;
2336         if (ui.actionAnimation->isChecked())
2337                 return true;
2338         if (ui.actionAnimationRev->isChecked())
2339                 return true;
2340
2341         return false;
2342 }
2343
2344 void FormMain::on_actionCrossSectionDlg_triggered()
2345 {
2346         m_CrossSectionDlg.showNormal();
2347         m_CrossSectionDlg.show();
2348         m_CrossSectionDlg.activateWindow();
2349 }
2350
2351 void FormMain::on_actionSelectNext_triggered()
2352 {
2353         AddSelectObjectIdx(1);
2354 }
2355
2356 void FormMain::on_actionSelectPrev_triggered()
2357 {
2358         AddSelectObjectIdx(-1);
2359 }
2360
2361 void FormMain::AddSelectObjectIdx(int step)
2362 {
2363         QTreeWidget* obj_tree = ui.treeObjects;
2364
2365         int num_obj = obj_tree->topLevelItemCount();
2366         if (num_obj == 0)
2367                 return;
2368
2369         QTreeWidgetItem * i = obj_tree->currentItem();
2370         int idx = obj_tree->indexOfTopLevelItem(i);
2371         idx += step;
2372
2373         if (0 > idx)
2374                 idx = num_obj - 1;
2375         else if (idx >= num_obj)
2376                 idx = 0;
2377
2378         QTreeWidgetItem * j = obj_tree->topLevelItem(idx);
2379         obj_tree->setCurrentItem(j);
2380 }
2381
2382 void FormMain::on_actionSwitchVisible_triggered()
2383 {
2384         FlipVisibleSelectedObject();
2385 }
2386
2387 void FormMain::on_actionActionSelObjectShowOnlyOnce_triggered()
2388 {
2389         ShowObjectOnlySelected();
2390 }
2391
2392 void FormMain::on_actionHideAll_triggered()
2393 {
2394         HideAllObject();
2395 }
2396
2397 void FormMain::on_actionShowAll_triggered()
2398 {
2399         ShowAllObject();
2400 }
2401
2402 void FormMain::on_actionVertexBuilder_triggered()
2403 {
2404         FormVertexBuilder builder;
2405         builder.CreateVertex(m_Scene);
2406
2407         RebuildObjectList();
2408         updateView_All();
2409 }
2410
2411 void FormMain::on_actionFullScreen_triggered()
2412 {
2413         m_FullscreenPanel.ShowWidgetAsFullscreen(ui.splitter, ui.gridLayout_4);
2414 }
2415
2416 void FormMain::on_actionResetConfig_triggered()
2417 {
2418         QString msg = QString::fromLocal8Bit("\90Ý\92è\82ð\83\8a\83Z\83b\83g\82µ\82Ü\82·");
2419         if (QMessageBox::question(this, "", msg, QMessageBox::Ok|QMessageBox::Cancel) != QMessageBox::Ok)
2420                 return;
2421
2422         setGeometry(m_InitRect);
2423
2424         LoadDefaultConfig();
2425
2426         SyncViewSettingsFromGUI();
2427         SyncUVViewSettingsFromGUI();
2428         ApplyGeomStateFromGUI();
2429         SyncShaderSettingsToGUI();
2430 }
2431
2432 QString FormMain::GetFilePathFromOpenDlg(const QString& title, const QString& filter)
2433 {
2434         QString default_path = GetNextDefaultPathForFileDlg();
2435         QString s = QFileDialog::getOpenFileName(this, title, default_path, filter);
2436
2437         if (!s.isEmpty())
2438                 m_LastFileDialogDir = QFileInfo(s).absolutePath();
2439
2440         return s;
2441 }
2442
2443 QString FormMain::GetFilePathFromSaveDlg(const QString& title, const QString& filter)
2444 {
2445         QString default_path = GetNextDefaultPathForFileDlg();
2446         QString s = QFileDialog::getSaveFileName(this, title, default_path, filter);
2447
2448         if (!s.isEmpty())
2449                 m_LastFileDialogDir = QFileInfo(s).absolutePath();
2450
2451         return s;
2452 }
2453
2454 bool FormMain::IsSupportedTextureExt(const QString& path) const
2455 {
2456         QString ext = QFileInfo(path).suffix().toLower();
2457
2458         std::map<QString, bool> types;
2459         types[ "png"  ] = true;
2460         types[ "jpg"  ] = true;
2461         types[ "jepg" ] = true;
2462         types[ "bmp"  ] = true;
2463         types[ "tif"  ] = true;
2464         types[ "tiff" ] = true;
2465
2466         return types[ext];
2467 }
2468
2469 QString FormMain::GetSupportedImageFilePathFromDlg(const QString& title)
2470 {
2471         FileDlgFilterList exts;
2472         exts.Add( "Png" , "png"  );
2473         exts.Add( "Jpg" , "jpg"  );
2474         exts.Add( "Jpg" , "jpeg" );
2475         exts.Add( "Bmp" , "bmp"  );
2476         exts.Add( "Tif" , "tif"  );
2477         exts.Add( "Tif" , "tiff" );
2478
2479         QString filter = FileDlgUtil::ExtListToDlgFilter("Image", exts);
2480         return GetFilePathFromOpenDlg(title, filter);
2481 }
2482
2483
2484 QString FormMain::GetNextDefaultPathForFileDlg(void)
2485 {
2486         if (m_LastFileDialogDir.isEmpty())
2487                 return PathInfo::GetMyDocDirPath();
2488
2489         return m_LastFileDialogDir;
2490 }
2491
2492
2493 void FormMain::on_toolLoadEnvMap_clicked()
2494 {
2495         QString fileName = GetSupportedImageFilePathFromDlg("Open envmap");
2496         if (fileName.isEmpty())
2497                 return;
2498
2499         LoadEnvMap(fileName);
2500 }
2501
2502 void FormMain::LoadEnvMap(QString& path)
2503 {
2504         m_ContextShare.BeginDrawTop();
2505         m_Scene.m_EnvImg.LoadTexture(path.toLocal8Bit().data());
2506         m_ContextShare.EndDrawTop();
2507
2508         QString title = QFileInfo(path).fileName();
2509         ui.editEnvMap->setText(title);
2510
2511         updateView_All();
2512 }
2513
2514 void FormMain::on_buttonReleaseEnvImg_clicked()
2515 {
2516         m_ContextShare.BeginDrawTop();
2517         m_Scene.m_EnvImg.ClearEnv();
2518         m_ContextShare.EndDrawTop();
2519
2520         ui.editEnvMap->clear();
2521
2522         updateView_All();
2523 }
2524
2525 void FormMain::on_buttonPresetEnvMap_clicked()
2526 {
2527         if (m_EnvmapDlg == NULL)
2528         {
2529                 m_EnvmapDlg = new EnvmapSelectDlg(this);
2530                 connect(
2531                         m_EnvmapDlg,
2532                         SIGNAL(ListSelectChanged()),
2533                         this,
2534                         SLOT(EnvmapDlg_ListSelectChanged()));
2535         }
2536
2537         m_EnvmapDlg->show();
2538 }
2539
2540 void FormMain::EnvmapDlg_ListSelectChanged()
2541 {
2542         QString p = m_EnvmapDlg->GetSelectedItemPath();
2543         if (p.isEmpty())
2544                 return;
2545
2546         LoadEnvMap(p);
2547 }
2548
2549 void FormMain::on_toolLoadMatcap_clicked()
2550 {
2551         QString fileName = GetSupportedImageFilePathFromDlg("Open matcap");
2552         if (fileName.isEmpty())
2553                 return;
2554
2555         LoadMatcapImage(fileName);
2556 }
2557
2558 void FormMain::on_buttonReleaseMatcap_clicked()
2559 {
2560         m_ContextShare.BeginDrawTop();
2561         m_Scene.m_MatcapImg.ClearEnv();
2562         m_ContextShare.EndDrawTop();
2563
2564         ui.editMatcap->clear();
2565
2566         updateView_All();
2567 }
2568
2569 void FormMain::on_buttonLoadMatcapPreset_clicked()
2570 {
2571         if (m_MatcapDlg == NULL)
2572         {
2573                 m_MatcapDlg = new MatcapSelectDlg(this);
2574                 connect(
2575                         m_MatcapDlg,
2576                         SIGNAL(ListSelectChanged()),
2577                         this,
2578                         SLOT(MatcapDlg_ListSelectChanged()));
2579         }
2580
2581         m_MatcapDlg->show();
2582 }
2583
2584 void FormMain::MatcapDlg_ListSelectChanged()
2585 {
2586         QString p = m_MatcapDlg->GetSelectedItemPath();
2587         if (p.isEmpty())
2588                 return;
2589
2590         LoadMatcapImage(p);
2591 }
2592
2593 void FormMain::on_sliderEnvReflection_valueChanged(int value)
2594 {
2595         float r = GetSliderNormalizedPos(ui.sliderEnvReflection);
2596         m_Scene.m_EnvImg.m_EnvReflection = r;
2597
2598         updateView_All();
2599 }
2600
2601
2602 void FormMain::on_comboCoordinate_currentIndexChanged(int index)
2603 {
2604         SceneTransform& transform = m_Scene.m_WorldTransform;
2605
2606         int idx = ui.comboCoordinate->currentIndex();
2607         switch (idx)
2608         {
2609         case 0: transform.SetCoordType(geom::SceneTransform::COORD_RUF); break;
2610         case 1: transform.SetCoordType(geom::SceneTransform::COORD_FRU); break;
2611         case 2: transform.SetCoordType(geom::SceneTransform::COORD_UFR); break;
2612         case 3: transform.SetCoordType(geom::SceneTransform::COORD_RUB); break;
2613         case 4: transform.SetCoordType(geom::SceneTransform::COORD_BRU); break;
2614         case 5: transform.SetCoordType(geom::SceneTransform::COORD_UBR); break;
2615         default:
2616                 break;
2617         }
2618
2619         updateView_All();
2620 }
2621
2622 void FormMain::on_sliderShadowDarkness_valueChanged(int value)
2623 {
2624         int b = ui.sliderShadowDarkness->minimum();
2625         int t = ui.sliderShadowDarkness->maximum();
2626
2627         float r = (float)(value - b) / (float)(t - b);
2628         m_Scene.m_ShadowConfig.m_ShadowDarkness = r;
2629
2630         updateView_All();
2631 }
2632
2633 void FormMain::on_buttonClearAllGeoms_clicked()
2634 {
2635         ClearAllObjects();
2636 }
2637
2638 //! \83J\83\81\83\89\88Ê\92u\95\9c\8c³\8b@\94\\8eg\97p\8e\9e\82Ì\83A\83j\83\81\81[\83V\83\87\83\93\97L\96³
2639 void FormMain::on_checkCameraAnimation_toggled(bool checked)
2640 {
2641 }
2642
2643
2644 void FormMain::on_actionOpenAppdir_triggered()
2645 {
2646         PathInfo::OpenAppDir();
2647 }
2648
2649 void FormMain::on_actionOpenConfigDir_triggered()
2650 {
2651         PathInfo::OpenConfigDir();
2652 }
2653
2654 void FormMain::on_buttonDecGridAxis_clicked()
2655 {
2656         m_View3d.m_GridAxisScale /= 10.0f;
2657         updateView_3D();
2658 }
2659
2660 void FormMain::on_buttonIncGridAxis_clicked()
2661 {
2662         m_View3d.m_GridAxisScale *= 10.0f;
2663         updateView_3D();
2664 }
2665
2666 void FormMain::on_buttonResetGridAxis_clicked()
2667 {
2668         m_View3d.m_GridAxisScale = 1.0f;
2669         updateView_3D();
2670 }
2671
2672
2673 void FormMain::View3D_SelectedObjectChanged(int sel_obj, int sel_mesh)
2674 {
2675         QTreeWidgetItem* on = ui.treeObjects->topLevelItem(sel_obj);
2676
2677         if (sel_mesh == -1)
2678         {
2679                 ui.treeObjects->setCurrentItem(on);
2680         }
2681         else
2682         {
2683                 QTreeWidgetItem* mn = on->child(sel_mesh);
2684                 ui.treeObjects->setCurrentItem(mn);
2685         }
2686 }
2687
2688 void FormMain::View3D_SelectedMatChanged(int sel_idx)
2689 {
2690         ui.listMaterial->setCurrentRow(sel_idx);
2691 }
2692
2693 void FormMain::View3D_CameraMoved(void)
2694 {
2695         UpdateCameraStatus();
2696 }
2697
2698 void FormMain::View3D_StatusTipChanged(QString msg)
2699 {
2700         //ui.statusBar->showMessage(msg, 1500);
2701 }
2702
2703 void FormMain::View3D_SequenceStepped(int step)
2704 {
2705         StepSequence(step);
2706 }
2707
2708 void FormMain::View3D_CursorMoved()
2709 {
2710         Cursor3D& c = m_Scene.m_Cursor3d;
2711         QString x = QString::number(c.CursorPos.x, 'f', 4);
2712         QString y = QString::number(c.CursorPos.y, 'f', 4);
2713         QString z = QString::number(c.CursorPos.z, 'f', 4);
2714         QString s;
2715         if (x.at(0) != '-')
2716                 s += " ";
2717         s += x;
2718         if (y.at(0) != '-')
2719                 s += " ";
2720         s += " ";
2721         s += y;
2722         if (z.at(0) != '-')
2723                 s += " ";
2724         s += " ";
2725         s += z;
2726
2727         ui.editCursorPos->setText(s);
2728 }
2729
2730 void FormMain::StepSequence(int step)
2731 {
2732         QSlider* s = ui.sliderSequence;
2733         s->setValue(s->value() + step);
2734 }
2735
2736 bool FormMain::IsLastSequence(void)
2737 {
2738         QSlider* s = ui.sliderSequence;
2739         return s->value() == s->maximum();
2740 }
2741
2742 bool FormMain::IsTopSequence(void)
2743 {
2744         QSlider* s = ui.sliderSequence;
2745         return s->value() == 0;
2746 }
2747
2748 void FormMain::UpdateCameraStatus(void)
2749 {
2750         const Camera& camera = m_View3d.m_Camera;
2751         const lib_gl::CameraManipulator& manip = camera.m_Manip;
2752         const lm::vec3f& vp = manip.m_ViewPos;
2753
2754         float a, b;
2755         manip.GetViewAngles(a, b);
2756         a = a * 180.0f / M_PI;
2757         b = b * 180.0f / M_PI;
2758
2759         QString msg;
2760         msg += "(";
2761         msg += QString::number(vp.x, 'f', 2) + " ";
2762         msg += QString::number(vp.y, 'f', 2) + " ";
2763         msg += QString::number(vp.z, 'f', 2);
2764         msg += ")";
2765
2766         msg += "(";
2767         msg += QString::number(a, 'f', 2) + " ";
2768         msg += QString::number(b, 'f', 2);
2769         msg += ")";
2770
2771         msg += "(";
2772         msg += QString::number(camera.m_Projection.m_Near, 'f', 2) + " ";
2773         msg += QString::number(camera.m_Projection.m_Far, 'f', 2);
2774         msg += ")";
2775
2776         m_StatusBar1->setText(msg);
2777 }
2778
2779 void FormMain::on_actionCameraFPSMode_toggled(bool arg1)
2780 {
2781         m_View3d.m_FpsMode = arg1;
2782 }
2783
2784
2785 void FormMain::actionCursorMenuStates_Toggled(bool)
2786 {
2787         m_Binder_Cursor.UpdateAllData();
2788
2789         if (QObject::sender() == ui.actionRecordStroke)
2790         {
2791                 m_Scene.m_Cursor3d.CutStroke();
2792         }
2793
2794         updateView_3D();
2795 }
2796
2797 void FormMain::on_actionResetCursor_triggered()
2798 {
2799         m_Scene.m_Cursor3d.ResetCursorPos();
2800         m_Scene.m_Cursor3d.UpdateNormal(m_View3d.m_Camera.m_Manip.GetFront());
2801         updateView_3D();
2802 }
2803
2804 void FormMain::on_actionResetMeasure_triggered()
2805 {
2806         m_View3d.ResetCursorMeasure();
2807         updateView_3D();
2808 }
2809
2810
2811 void FormMain::on_actionPyScript_triggered()
2812 {
2813         if (m_PyScriptDlg == NULL)
2814         {
2815                 m_PyScriptDlg = new FormPyScript(this);
2816                 m_PyScriptDlg->m_Scene = &m_Scene;
2817                 m_PyScriptDlg->m_View3d = &m_View3d;
2818                 m_PyScriptDlg->m_View2d = &m_View2d;
2819         }
2820
2821         m_PyScriptDlg->showNormal();
2822         m_PyScriptDlg->show();
2823         m_PyScriptDlg->activateWindow();
2824 }
2825
2826 void FormMain::on_actionConsole_triggered()
2827 {
2828         ::AllocConsole();
2829         freopen( "CON", "r", stdin  );
2830         freopen( "CON", "w", stdout );
2831 }
2832
2833
2834 void FormMain::on_actionClearVertSelect_triggered()
2835 {
2836         m_Scene.ClearAllVertSelect();
2837         updateView_All();
2838 }
2839
2840
2841 void FormMain::on_action_About_triggered()
2842 {
2843         QGVAboutDlg dlg;
2844         dlg.exec();
2845 }
2846
2847 void FormMain::on_action_Association_triggered()
2848 {
2849         m_AssociationDlg.exec();
2850 }
2851
2852 void FormMain::on_actionLookDepth_triggered()
2853 {
2854         m_View3d.LookDepth();
2855 }
2856
2857 void FormMain::on_actionLook3DCursor_triggered()
2858 {
2859         m_View3d.Look3DCursor();
2860 }
2861
2862 void FormMain::on_sliderLightPower_valueChanged(int value)
2863 {
2864         float val = (float)ui.sliderLightPower->value();
2865         float val_max = (float)ui.sliderLightPower->maximum();
2866         float n = 2.0f * val / val_max;
2867         
2868         m_View3d.SetLightStrengthByStdRatio(n);
2869
2870         ui.labelLightPower->setText(QString("LightPower ") + QString::number(n, 'f', 2));
2871
2872         updateView_All();
2873 }
2874
2875 void FormMain::on_buttonResetLightPower_clicked()
2876 {
2877         ui.sliderLightPower->setValue(1000);
2878 }
2879
2880 void FormMain::on_checkHoleAroundCursor_clicked(bool checked)
2881 {
2882         if (checked)
2883                 ui.checkShowOnlyAroundCursor->setChecked(false);
2884
2885         if (checked)
2886                 m_Scene.m_Cursor3d.CircleClip = Cursor3DCircleClip::Hole;
2887         else
2888                 m_Scene.m_Cursor3d.CircleClip = Cursor3DCircleClip::None;
2889
2890         updateView_All();
2891 }
2892
2893 void FormMain::on_checkShowOnlyAroundCursor_toggled(bool checked)
2894 {
2895         if (checked)
2896                 ui.checkHoleAroundCursor->setChecked(false);
2897
2898         if (checked)
2899                 m_Scene.m_Cursor3d.CircleClip = Cursor3DCircleClip::ShowAround;
2900         else
2901                 m_Scene.m_Cursor3d.CircleClip = Cursor3DCircleClip::None;
2902
2903         updateView_All();
2904 }
2905
2906 void FormMain::on_sliderCursorHoleRange_valueChanged(int value)
2907 {
2908         float val = (float)ui.sliderCursorHoleRange->value();
2909         float maxval = (float)ui.sliderCursorHoleRange->maximum();
2910         float n = val / maxval;
2911
2912         m_Scene.m_Cursor3d.HoleRangeRatio = n;
2913         updateView_All();
2914 }
2915
2916 void FormMain::on_buttonResetCursorHoleRange_clicked()
2917 {
2918         ResetHoleRange();
2919 }
2920
2921 void FormMain::ResetHoleRange(void)
2922 {
2923         ui.sliderCursorHoleRange->setValue(500);
2924 }
2925
2926 void FormMain::on_actionSaveImageToMydoc_triggered()
2927 {
2928         QString path = PathInfo::GetMyDocDirPath();
2929         QString basename = path + "/" + "qgv_snap_";
2930
2931         QDateTime dt = QDateTime::currentDateTime();
2932
2933         QString dst;
2934         for(;;)
2935         {
2936                 QString tp = dt.toString("yyyyMMdd_hhmmss_zzz");
2937                 dst = basename + tp + ".png";
2938                 if (!QFile(dst).exists())
2939                         break;
2940         }
2941
2942         ui.GLWidgetMain->grabFrameBuffer().save(dst);
2943 }
2944
2945 void FormMain::on_actionPostProcNone_triggered()
2946 {
2947         ChangePostprocMode(PostProcType::None);
2948 }
2949
2950 void FormMain::on_actionPostProcAntialias_triggered()
2951 {
2952         ChangePostprocMode(PostProcType::Antialias);
2953 }
2954
2955 void FormMain::on_actionPostProcBorder_triggered()
2956 {
2957         ChangePostprocMode(PostProcType::Border);
2958 }
2959
2960 void FormMain::on_actionPostProcDepthLayerColor_triggered()
2961 {
2962         ChangePostprocMode(PostProcType::DepthLayerColor);
2963 }
2964
2965 void FormMain::on_actionPostProcDepthColor_triggered()
2966 {
2967         ChangePostprocMode(PostProcType::DepthColor);
2968 }
2969
2970 void FormMain::on_actionPostProcDepthOfField_triggered()
2971 {
2972         ChangePostprocMode(PostProcType::DepthOfField);
2973 }
2974
2975 void FormMain::ChangePostprocMode(PostProcType type)
2976 {
2977         m_View3d.m_Config.m_PPMode = type;
2978         updateView_3D();
2979 }
2980
2981 void FormMain::on_sliderDOFPint_valueChanged(int value)
2982 {
2983         float n = GetSliderNormalizedPos(ui.sliderDOFPint);
2984         m_View3d.m_PPContext.m_DOFPintPos = n;
2985
2986         updateView_3D();
2987 }
2988
2989 void FormMain::on_sliderDOFRange_valueChanged(int value)
2990 {
2991         float n = GetSliderNormalizedPos(ui.sliderDOFRange);
2992         m_View3d.m_PPContext.m_DOFRange = 10.0f * n;
2993
2994         updateView_3D();
2995 }
2996
2997 float FormMain::GetSliderNormalizedPos(const QSlider* slider) const
2998 {
2999         float t = (float)slider->maximum();
3000         float b = (float)slider->minimum();
3001         float v = (float)slider->value();
3002
3003         return (v - b) / (t - b);
3004 }
3005
3006 void FormMain::on_buttonResetDOFPint_clicked()
3007 {
3008         ui.sliderDOFPint->setValue(1000);
3009 }
3010
3011 void FormMain::on_buttonResetDOFRange_clicked()
3012 {
3013         ui.sliderDOFRange->setValue(1000);
3014 }
3015
3016 void FormMain::on_actionAddCrossSectionRecord_triggered()
3017 {
3018         m_Scene.AddCrossSectionRecord();
3019         updateView_All();
3020 }
3021
3022 void FormMain::on_actionClearCrossSectionRecord_triggered()
3023 {
3024         m_Scene.ClearCrossSectionRecord();
3025         updateView_All();
3026 }
3027
3028 void FormMain::LoadCurSelMatTexture(TextureType type)
3029 {
3030         QString path = GetSupportedImageFilePathFromDlg("Load Texture");
3031         if (path.isEmpty())
3032                 return;
3033
3034         LoadCurSelMatTexture(type, path);
3035 }
3036
3037 void FormMain::LoadCurSelMatTexture(TextureType type, QString filepath)
3038 {
3039         GeomTextureSet* ts = m_Scene.GetSelectedTexture();
3040         if (ts == NULL)
3041                 return;
3042
3043         MeshBuf* mbuf = ts->GetParent();
3044         std::string fp = filepath.toLocal8Bit().data();
3045
3046         QString name_qs = QFileInfo(filepath).fileName();
3047         std::string name = name_qs.toLocal8Bit().data();
3048
3049         m_ContextShare.BeginDrawTop();
3050
3051         mbuf->ReleaseTextureUnit(ts, type);
3052         gl::GlTexture* tex = mbuf->GetInitTexture(fp, name, m_Scene.m_TexConfig);
3053         ts->SetTextureUnit(type, tex);
3054
3055         if (type == TextureType::Normal)
3056                 m_View3d.ReleaseAllRenderBuffer();
3057
3058         m_ContextShare.EndDrawTop();
3059
3060         OnChangedSelectedMaterial();
3061         updateView_All();
3062 }
3063
3064 void FormMain::ReleaseCurSelTexture(TextureType type)
3065 {
3066         MeshBuf* mbuf = m_Scene.GetPrimaryMeshbuf();
3067         if (mbuf == NULL)
3068                 return;
3069
3070         int mat_idx = m_Scene.m_Sels.GetSelMat();
3071
3072         m_ContextShare.BeginDrawTop();
3073         mbuf->ReleaseTextureUnit(mat_idx, type);
3074         m_ContextShare.EndDrawTop();
3075
3076         OnChangedSelectedMaterial();
3077         updateView_All();
3078 }
3079
3080 void FormMain::LoadMatcapImageForCurrentMat(QString& path)
3081 {
3082         GeomTextureSet* ts = m_Scene.GetSelectedTexture();
3083
3084         QString title = QFileInfo(path).fileName();
3085
3086         m_ContextShare.BeginDrawTop();
3087         ts->TexMatcap.LoadTexture(path.toLocal8Bit().data());
3088         ts->TexMatcap.SetName(title);
3089         m_ContextShare.EndDrawTop();
3090
3091         OnChangedSelectedMaterial();
3092         updateView_All();
3093 }
3094
3095 void FormMain::LoadMatcapImage(QString& path)
3096 {
3097         MatcapImage& mc = m_Scene.m_MatcapImg;
3098
3099         QString title = QFileInfo(path).fileName();
3100
3101         m_ContextShare.BeginDrawTop();
3102         mc.LoadTexture(path.toLocal8Bit().data());
3103         mc.SetName(title);
3104         m_ContextShare.EndDrawTop();
3105
3106         ui.editMatcap->setText(mc.GetName());
3107
3108         updateView_All();
3109 }
3110
3111 void FormMain::on_buttonOpenMatCapEachMaterial_clicked()
3112 {
3113         QString path = GetSupportedImageFilePathFromDlg("Load Texture");
3114         if (path.isEmpty())
3115                 return;
3116
3117         LoadMatcapImage(path);
3118 }
3119
3120 void FormMain::on_buttonClearMatCapEachMaterial_clicked()
3121 {
3122         geom::GeomTextureSet* tex = m_Scene.GetSelectedTexture();
3123         if (tex == NULL)
3124                 return;
3125
3126         m_ContextShare.BeginDrawTop();
3127         tex->TexMatcap.ClearEnv();
3128         m_ContextShare.EndDrawTop();
3129
3130         ui.editMatCapEachMaterial->clear();
3131
3132         updateView_All();
3133 }
3134
3135 void FormMain::on_buttonOpenCurrentMatColorMap_clicked()
3136 {
3137         LoadCurSelMatTexture(TextureType::Color);
3138 }
3139
3140 void FormMain::on_buttonClearCurrentMatColorMap_clicked()
3141 {
3142         ReleaseCurSelTexture(TextureType::Color);
3143 }
3144
3145 void FormMain::on_buttonOpenCurrentMatNormalMap_clicked()
3146 {
3147         LoadCurSelMatTexture(TextureType::Normal);
3148 }
3149
3150 void FormMain::on_buttonClearCurrentMatNormalMap_clicked()
3151 {
3152         ReleaseCurSelTexture(TextureType::Normal);
3153 }
3154
3155 void FormMain::ChangeMatlemColor(QWidget* col_widget)
3156 {
3157         lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
3158         if (mat == NULL)
3159                 return;
3160
3161         lib_graph::color4f* col = NULL;
3162         if (col_widget == ui.colorAmbient  ) col = &mat->m_Ambient  ;
3163         if (col_widget == ui.colorEmission ) col = &mat->m_Emission ;
3164         if (col_widget == ui.colorDiffuse  ) col = &mat->m_Diffuse  ;
3165         if (col_widget == ui.colorSpecular ) col = &mat->m_Specular ;
3166
3167         lib_graph::color4f src = *col;
3168
3169         QColor dc = ToQColor(*col);
3170
3171         m_SelMatColorWidget = col_widget;
3172
3173         m_SelMatColorSelDlg.setOption(QColorDialog::ShowAlphaChannel);
3174         m_SelMatColorSelDlg.setCurrentColor(dc);
3175         if (m_SelMatColorSelDlg.exec() == QDialog::Rejected)
3176         {
3177                 *col = src;
3178                 SetColorPalleteBG(col_widget, dc);
3179         }
3180 }
3181
3182 void FormMain::SetColorPalleteBG(QWidget* w, QColor col)
3183 {
3184         QColor border(0, 0, 0);
3185         SetWidgetColor(w, col, border);
3186 }
3187
3188 void FormMain::SetWidgetColor(QWidget* w, QColor col)
3189 {
3190         QString ss = QString("background-color: %1").arg(col.name());
3191         w->setStyleSheet(ss);
3192 }
3193
3194 void FormMain::SetWidgetColor(QWidget* w, QColor col, QColor col_border)
3195 {
3196         QString ss;
3197         ss += QString("background-color: %1;").arg(col.name());
3198         ss += QString("border: 1px solid %1;").arg(col_border.name());
3199         w->setStyleSheet(ss);
3200 }
3201
3202 void FormMain::on_sliderShininess_valueChanged(int value)
3203 {
3204         lib_geo::BaseMaterial* mat = m_Scene.GetSelectedMaterial();
3205         if (mat == NULL)
3206                 return;
3207
3208         float val = (float)ui.sliderShininess->value();
3209         float val_max = (float)ui.sliderShininess->maximum();
3210
3211         float real_val = 200.0f * val / val_max;
3212
3213         mat->m_Shininess = real_val;
3214
3215         ui.labelShininessVal->setText(QString::number(real_val, 'f', 2));
3216
3217         updateView_All();
3218 }
3219
3220 void FormMain::CreateRecentFilesMenu(const std::vector<QString>& path)
3221 {
3222         QMenu* recents = ui.menuOpenRecent;
3223         recents->actions().clear();
3224
3225         for (size_t i = 0; i < path.size(); ++i)
3226         {
3227                 AddRecentFile(path[path.size() - i - 1]);
3228         }
3229 }
3230
3231 void FormMain::CreateRecentFilesFromMenu(std::vector<QString>& path)
3232 {
3233         QMenu* recents = ui.menuOpenRecent;
3234         for (int i = 0; i < recents->actions().size(); ++i)
3235         {
3236                 QAction* a = recents->actions().at(i);
3237                 path.push_back(a->text());
3238         }
3239 }
3240
3241 void FormMain::AddRecentFile(const QString& path)
3242 {
3243         QString path_local = QDir::toNativeSeparators(path);
3244
3245         static const int max_files = 10;
3246
3247         QMenu* recents = ui.menuOpenRecent;
3248
3249         for (int i = 0; i < recents->actions().size(); ++i)
3250         {
3251                 QAction* a = recents->actions().at(i);
3252                 if (a->text() == path_local)
3253                 {
3254                         recents->removeAction(a);
3255                         break;
3256                 }
3257         }
3258
3259         QAction* new_path = new QAction(path_local, this);
3260         connect(
3261                 new_path,
3262                 SIGNAL(triggered()),
3263                 this,
3264                 SLOT(OnOpenRecent()));
3265
3266         if (recents->actions().empty())
3267                 recents->addAction(new_path);
3268         else
3269                 recents->insertAction(recents->actions().front(), new_path);
3270
3271         if (recents->actions().size() > max_files)
3272         {
3273                 QAction* a = recents->actions().back();
3274                 recents->removeAction(a);
3275         }
3276 }
3277
3278 void FormMain::OnOpenRecent()
3279 {
3280         QAction* a = dynamic_cast<QAction*>(QObject::sender());
3281         assert(a != NULL);
3282         if (a == NULL)
3283                 return;
3284
3285         QString path = a->text();
3286
3287         if (IsResetSceneOnBeforeLoadFile())
3288                 ClearAllObjects();
3289
3290         if (OpenGeomFile(path))
3291                 return;
3292 }
3293
3294 void FormMain::on_checkShowOnlySelect_toggled(bool checked)
3295 {
3296         m_View3d.m_Config.m_ShowOnlySelect = checked;
3297         updateView_All();
3298 }
3299
3300 void FormMain::ResizeTreeColumns(QTreeWidget* t, int num_col)
3301 {
3302         t->setVisible(false);
3303         t->resizeColumnToContents(0);
3304         t->resizeColumnToContents(1);
3305         t->resizeColumnToContents(2);
3306         t->resizeColumnToContents(3);
3307         t->setVisible(true);
3308 }
3309
3310 void FormMain::PushbackTreeNode(QTreeWidget* tree, QTreeWidgetItem *node)
3311 {
3312         int next_idx = tree->topLevelItemCount();
3313         tree->insertTopLevelItem(next_idx, node);
3314 }
3315
3316 QTreeWidgetItem* FormMain::CreateObjectTreeNode(const geom::GeomObject& obj) const
3317 {
3318         QTreeWidgetItem* n = new QTreeWidgetItem;
3319
3320         n->setText(0, QString::fromLocal8Bit(obj.m_Name.c_str()));
3321         n->setCheckState(1, obj.m_Visible ? Qt::Checked : Qt::Unchecked);
3322         n->setText(2, QString::number(obj.GetNumTotalVerts()));
3323         n->setText(3, QString::number(obj.GetNumTotalFaces()));
3324
3325         int idx = 0;
3326         for (const MeshBuf& mbuf : obj.m_MeshAry)
3327         {
3328                 n->addChild(CreateMeshBufNode(obj, mbuf, idx++));
3329         }
3330
3331         n->setExpanded(true);
3332
3333         return n;
3334 }
3335
3336 QTreeWidgetItem* FormMain::CreateMeshBufNode(const geom::GeomObject& obj, const MeshBuf& mbuf, int idx) const
3337 {
3338         QTreeWidgetItem* n = new QTreeWidgetItem;
3339
3340         QString name;
3341         if (mbuf.m_Name.empty())
3342                 name = QString::fromLocal8Bit(obj.m_Name.c_str()) + QString::number(idx);
3343         else
3344                 name = QString::fromLocal8Bit(mbuf.m_Name.c_str());
3345
3346         n->setText(0, name);
3347         n->setCheckState(1, mbuf.m_Visible ? Qt::Checked : Qt::Unchecked);
3348         n->setText(2, QString::number(mbuf.GetNumVerts()));
3349         n->setText(3, QString::number(mbuf.GetNumFaces()));
3350
3351         return n;
3352 }
3353
3354 void FormMain::InitObjectListHeader(void)
3355 {
3356         QStringList qs;
3357         qs << "Name" << "Visible" << "Verts" << "Faces";
3358         ui.treeObjects->setHeaderLabels(qs);
3359 }
3360
3361 void FormMain::SetPrimayrSelectObjectFromScene(void)
3362 {
3363         QTreeWidget* obj_tree = ui.treeObjects;
3364
3365         Selection3D& sels = m_Scene.m_Sels;
3366         if (!sels.IsObjectSelected())
3367                 return;
3368
3369         int sel_idx = sels.GetSelObjectIdx();
3370
3371         QTreeWidgetItem* on = obj_tree->topLevelItem(sel_idx);
3372         if (on == NULL)
3373                 return;
3374
3375         if (sels.IsMBufSelected())
3376         {
3377                 QTreeWidgetItem* mn = on->child(sels.GetMBufIdx());
3378                 obj_tree->setCurrentItem(mn);
3379         }
3380         else
3381         {
3382                 obj_tree->setCurrentItem(on);
3383         }
3384 }
3385
3386 void FormMain::SetPrimayrSelectObjectToScene(void)
3387 {
3388         Selection3D& sels = m_Scene.m_Sels;
3389
3390         QTreeWidget* tree = ui.treeObjects;
3391
3392         QTreeWidgetItem* sel_node = tree->currentItem();
3393         if (sel_node == NULL)
3394                 return;
3395
3396         QTreeWidgetItem* on = sel_node->parent();
3397         if (on == NULL)
3398         {
3399                 int obj_idx = tree->indexOfTopLevelItem(sel_node);
3400                 sels.SelectObject(obj_idx);
3401         }
3402         else
3403         {
3404                 int obj_idx = tree->indexOfTopLevelItem(on);
3405                 int mb_idx = on->indexOfChild(sel_node);
3406                 sels.SelectMBuf(obj_idx, mb_idx);
3407         }
3408 }
3409
3410 void FormMain::on_actionReleaseShader_triggered()
3411 {
3412         m_ContextShare.BeginDrawTop();
3413
3414         m_View3d.m_ShaderLib.ReleaseAllShaders();
3415
3416         m_ContextShare.EndDrawTop();
3417 }
3418
3419 void FormMain::on_combo2DViewSrcType_currentIndexChanged(int index)
3420 {
3421         switch (index)
3422         {
3423         case 0 : return m_View2d.ChangeTextureSource(View2DTexSrc::Color);
3424         case 1 : return m_View2d.ChangeTextureSource(View2DTexSrc::Normal);
3425         default:
3426                 assert(false);
3427                 break;
3428         }
3429 }
3430
3431 void FormMain::on_sliderSequence_valueChanged(int value)
3432 {
3433         UpdateSequence();
3434 }
3435
3436 void FormMain::ResetSequenceSliderRange(void)
3437 {
3438         int m = m_Scene.GetKeyframeMax();
3439         ui.sliderSequence->setMaximum(m);
3440         UpdateSequence();
3441 }
3442
3443 void FormMain::UpdateSequence(void)
3444 {
3445         int v = ui.sliderSequence->value();
3446         int m = ui.sliderSequence->maximum();
3447
3448         QString s = QString("%1 / %2").arg(v).arg(m);
3449         ui.labelSequencePos->setText(s);
3450
3451         m_Scene.SetFrame(v);
3452
3453         m_View3d.ReleaseAllRenderBuffer();
3454         updateView_All();
3455 }
3456
3457 void FormMain::on_actionNewStroke_triggered()
3458 {
3459         m_Scene.m_Cursor3d.CutStroke();
3460         updateView_All();
3461 }
3462
3463 void FormMain::on_actionClearStroke_triggered()
3464 {
3465         m_Scene.m_Cursor3d.ClearStroke();
3466         updateView_All();
3467 }