-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathglc_player.cpp
More file actions
2924 lines (2636 loc) · 88.2 KB
/
Copy pathglc_player.cpp
File metadata and controls
2924 lines (2636 loc) · 88.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
This file is part of GLC-Player.
Copyright (C) 2007-2008 Laurent Ribon (laumaya@users.sourceforge.net)
Version 2.2.0, packaged on July 2010.
http://www.glc-player.net
GLC-Player is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLC-Player is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLC-Player; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include "glc_player.h"
#include "ui_class/SettingsDialog.h"
#include "ui_class/AboutPlayer.h"
#include "AlbumFile.h"
#include "ui_class/EditCamera.h"
#include "ui_class/SelectionProperty.h"
#include "ui_class/EditLightDialog.h"
#include "ui_class/AlbumManagerView.h"
#include "ui_class/ModelManagerView.h"
#include "ui_class/InstanceProperty.h"
#include "UserInterfaceSate.h"
#include "ui_class/MaterialProperty.h"
#include "ui_class/ChooseShaderDialog.h"
#include "ui_class/ListOfMaterial.h"
#include "ui_class/OpenAlbumOption.h"
#include "ui_class/SendFilesDialog.h"
#include "ui_class/ScreenshotDialog.h"
#include "ui_class/MultiScreenshotsDialog.h"
#include "ui_class/ExportWebDialog.h"
#include "ui_class/LeftSideDock.h"
#include "ui_class/ExportProgressDialog.h"
#include "ui_class/ErrorLogDialog.h"
#include <GLC_Exception>
#include <GLC_State>
#include <GLC_Plane>
#include <GLC_OctreeNode>
#include <GLC_Mesh>
#include <GLC_ErrorLog>
#include <SaveFileThread.h>
#include <GLC_WorldTo3ds>
glc_player::glc_player(QWidget *parent)
: QMainWindow(parent)
, m_OpenglView(this)
, m_CurrentPath(QDir::homePath())
, m_CurrentAlbumPath(QDir::homePath())
, m_pProgressBar(new QProgressBar())
, m_pQErrorMessage(NULL)
, m_RecentFilesList()
, m_RecentAlbumsList()
, m_CurrentFileName()
, m_CurrentAlbumName()
, m_OpenFileThread()
, m_FileEntryHash()
, m_modelName()
, m_FileLoadingInProgress(false)
, m_ListLoadingInProgress(false)
, m_ContinuListLoading(true)
, m_MakeFirstFileCurrent(true)
, m_dislayInfoPanel()
, m_pSelectionProperty(NULL)
, m_pEditLightDialog(NULL)
, m_QuitConfirmation()
, m_pLeftSideDock(NULL)
, m_pAlbumManagerView(NULL)
, m_pModelManagerView(NULL)
, m_pInstanceProperty(NULL)
, m_pInstancePropertyVis(NULL)
, m_pMaterialProperty(NULL)
, m_pChooseShaderDialog(NULL)
, m_pListOfMaterial(NULL)
, m_pOpenAlbumOption(NULL)
, m_pSendFilesDialog(NULL)
, m_pScreenshotDialog(NULL)
, m_pMultiScreenshotsDialog(NULL)
, m_pExportWebDialog(NULL)
, m_UseSelectionShader(true)
, m_UseVbo(-1)
, m_UseShader(-1)
, m_DefaultLodValue(10)
, m_UsePixelCulling(true)
, m_PixelCullingSize(6)
, m_UseFrustumCulling(true)
, m_UseSpacePartion(true)
, m_UseOctreeBoundingBox(false)
, m_OctreeDepth(3)
, m_ClipBoard(0, NULL)
{
setupUi(this);
actionShowHideSection->setVisible(false);
//setUnifiedTitleAndToolBarOnMac(true);
setCentralWidget(&m_OpenglView);
m_OpenglView.setFocusPolicy(Qt::StrongFocus);
// Album management dock area
m_pAlbumManagerView= new AlbumManagerView(&m_OpenglView, &m_FileEntryHash, albumManagementWindow);
m_pModelManagerView= new ModelManagerView(&m_OpenglView, action_Property, actionHide_unselected, actionCopy, actionPaste, &m_ClipBoard, albumManagementWindow);
connect(m_pModelManagerView, SIGNAL(currentModelProperties()), m_pAlbumManagerView, SLOT(modelProperties()));
// LeftSideDock
m_pLeftSideDock= new LeftSideDock(m_pAlbumManagerView, m_pModelManagerView, &m_FileEntryHash, albumManagementWindow);
albumManagementWindow->setWidget(m_pLeftSideDock);
readSettings();
GLC_3DViewInstance::setGlobalDefaultLod(m_DefaultLodValue);
createRecentFileActionsArray();
updateRecentsFiles();
createRecentAlbumActionsArray();
updateRecentsAlbums();
// Default lighting
m_OpenglView.getLight()->setTwoSided(actionTwo_sided_Lightning->isChecked());
// Display info panel
m_OpenglView.setDisplayInfoPanel(m_dislayInfoPanel);
// Resize Texture cache limite to 128 Mo
QGLContext::setTextureCacheLimit(256 * 1024);
// Accept drop event
m_OpenglView.setAcceptDrops(false);
setAcceptDrops(true);
// Set the current file name
addToRecentFiles(m_CurrentFileName);
// Status bar
statusbar->addPermanentWidget(m_pProgressBar);
m_pProgressBar->hide();
connect(&m_OpenglView, SIGNAL(currentQuantum(int)), this, SLOT(updateProgressBar(int)), Qt::QueuedConnection);
// QAction Signals and slots connection
// Signals from the view
connect(&m_OpenglView, SIGNAL(updateSelection(PointerViewInstanceHash*)), this, SLOT(updateSelection(PointerViewInstanceHash*)));
connect(&m_OpenglView, SIGNAL(unselectAll()), this, SLOT(unselectAll()));
connect(&m_OpenglView, SIGNAL(hideInfoPanel()), this, SLOT(hideInfoPanel()));
connect(&m_OpenglView, SIGNAL(glInitialed()), this, SLOT(glInitialed()));
//Menu File
connect(actionNew_Model, SIGNAL(triggered()), this , SLOT(newModel()));
connect(action_NewAlbum, SIGNAL(triggered()), this , SLOT(newAlbum()));
connect(action_OpenAlbum, SIGNAL(triggered()), this , SLOT(openAlbum()));
connect(actionOpen_Models_from_path, SIGNAL(triggered()), this, SLOT(openModelsFromPath()));
connect(action_SaveAlbum, SIGNAL(triggered()), this , SLOT(saveAlbum()));
connect(action_SaveAlbumAs, SIGNAL(triggered()), this , SLOT(saveAlbumAs()));
connect(action_Open, SIGNAL(triggered()), this, SLOT(open()));
connect(action_Quit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
connect(actionExport_To_Folder, SIGNAL(triggered()), this, SLOT(sendToFolder()));
connect(actionExport_to_web, SIGNAL(triggered()), this, SLOT(exportToWeb()));
connect(actionExport_current_Model, SIGNAL(triggered()), this, SLOT(exportCurrentModel()));
// Menu edit
connect(actionSelectAll, SIGNAL(triggered()), &m_OpenglView, SLOT(selectAll()));
connect(actionUnselectAll, SIGNAL(triggered()), &m_OpenglView, SLOT(unselectAllSlot()));
connect(action_Property, SIGNAL(triggered()), this, SLOT(instanceProperty()));
connect(actionAssign_Shader, SIGNAL(triggered()), this, SLOT(assignShader()));
//Menu Window
connect(action_AlbumManagement, SIGNAL(triggered()), this, SLOT(albumManagementVisibilityToggle()));
connect(albumManagementWindow, SIGNAL(visibilityChanged(bool)), this, SLOT(albumManagementVisibilityChanged(bool)));
connect(action_CameraProperty, SIGNAL(triggered()), this, SLOT(cameraPropertyVisibilityToggle()));
connect(cameraProperties, SIGNAL(visibilityChanged(bool)), this, SLOT(cameraPropertyVisibilityChanged(bool)));
connect(action_SelectionProperty, SIGNAL(triggered()), this, SLOT(selectionPropertyVisibilityToggle()));
connect(selectionDockWidget, SIGNAL(visibilityChanged(bool)), this, SLOT(selectionPropertyVisibilityChanged(bool)));
connect(actionError_Log, SIGNAL(triggered()), this, SLOT(showErrorLog()));
//Menu View
connect(actionChange_UP_Vector, SIGNAL(triggered()), &m_OpenglView, SLOT(changeDefaultUp()));
connect(action_Reframe, SIGNAL(triggered()), this, SLOT(reframe()));
connect(actionReframeOnSelection, SIGNAL(triggered()), &m_OpenglView, SLOT(reframeOnSelection()));
QActionGroup* pGroup= new QActionGroup(this);
pGroup->addAction(actionTrackball);
pGroup->addAction(actionTurnTable);
pGroup->addAction(actionFly);
actionTrackball->setChecked(true);
connect(actionTrackball, SIGNAL(triggered()), this, SLOT(changeCurrentMoverToTrackBall()));
connect(actionTurnTable, SIGNAL(triggered()), this, SLOT(changeCurrentMoverToTurnTable()));
connect(actionFly, SIGNAL(triggered()), this, SLOT(changeCurrentMoverToFly()));
pGroup= new QActionGroup(this);
pGroup->addAction(actionPerspective);
pGroup->addAction(actionParallel);
actionPerspective->setChecked(true);
connect(actionPerspective, SIGNAL(triggered()), this, SLOT(changeCurrentProjectionMode()));
connect(actionParallel, SIGNAL(triggered()), this, SLOT(changeCurrentProjectionMode()));
connect(action_Select, SIGNAL(triggered()), this, SLOT(selectMode()));
connect(action_ViewCenter, SIGNAL(triggered()), this, SLOT(viewCenterMode()));
connect(action_Pan, SIGNAL(triggered()), this, SLOT(panMode()));
connect(action_Rotate, SIGNAL(triggered()), this, SLOT(rotateMode()));
connect(action_Zoom, SIGNAL(triggered()), this, SLOT(zoomMode()));
connect(action_ZoomIn, SIGNAL(triggered()), &m_OpenglView, SLOT(zoomIn()));
connect(action_ZoomOut, SIGNAL(triggered()), &m_OpenglView, SLOT(zoomOut()));
connect(actionShow_Hide, SIGNAL(triggered()), this, SLOT(showOrHide()));
connect(actionHide_unselected, SIGNAL(triggered()), this, SLOT(hideUnselected()));
connect(actionShow_all, SIGNAL(triggered()), this, SLOT(showAll()));
connect(actionSwap_visible_space, SIGNAL(triggered()), this, SLOT(swapVisibleSpace()));
connect(action_FullScreen, SIGNAL(triggered()), this, SLOT(fullScreen()));
connect(actionDisplay_Octree, SIGNAL(triggered(bool)), &m_OpenglView, SLOT(toggleOctreeDisplay(bool)));
// predifined view
connect(action_IsoView1, SIGNAL(triggered()), &m_OpenglView, SLOT(isoView1()));
connect(action_IsoView2, SIGNAL(triggered()), &m_OpenglView, SLOT(isoView2()));
connect(action_IsoView3, SIGNAL(triggered()), &m_OpenglView, SLOT(isoView3()));
connect(action_IsoView4, SIGNAL(triggered()), &m_OpenglView, SLOT(isoView4()));
connect(action_FrontView, SIGNAL(triggered()), &m_OpenglView, SLOT(frontView()));
connect(action_RightView, SIGNAL(triggered()), &m_OpenglView, SLOT(rightView()));
connect(action_TopView, SIGNAL(triggered()), &m_OpenglView, SLOT(topView()));
// Menu Render
// Render Mode
connect(action_RenderPoints, SIGNAL(triggered()), this, SLOT(pointsRenderingMode()));
connect(action_RenderWireframe, SIGNAL(triggered()), this, SLOT(wireframeRenderingMode()));
connect(action_RenderShading, SIGNAL(triggered()), this, SLOT(shadingRenderingMode()));
connect(action_ShadingAndWire, SIGNAL(triggered()), this, SLOT(shadingAndWireRenderingMode()));
connect(action_EditLight, SIGNAL(triggered()), this, SLOT(editLightDialog()));
connect(actionTwo_sided_Lightning, SIGNAL(triggered()), this, SLOT(twoSidedLightning()));
connect(actionSet_Shader, SIGNAL(triggered()), this, SLOT(chooseShader()));
// Menu Tools
connect(action_SnapShot, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
connect(actionMultiShots, SIGNAL(triggered()), this, SLOT(takeMultiShots()));
connect(action_Settings, SIGNAL(triggered()), this, SLOT(showSettings()));
connect(actionSectioning, SIGNAL(triggered()), this, SLOT(sectioning()));
connect(actionShowHideSection, SIGNAL(triggered()), &m_OpenglView, SLOT(showHideSectionPlane()));
// Menu Help
connect(action_About, SIGNAL(triggered()), this, SLOT(aboutPlayer()));
connect(action_Help, SIGNAL(triggered()), this, SLOT(help()));
// Open File thread
connect(&m_OpenFileThread, SIGNAL(currentQuantum(int)), this, SLOT(updateProgressBar(int)), Qt::QueuedConnection);
connect(&m_OpenFileThread, SIGNAL(finished()), this, SLOT(fileOpened()), Qt::QueuedConnection);
connect(&m_OpenFileThread, SIGNAL(loadError()), this, SLOT(loadFileFailed()), Qt::QueuedConnection);
// Album manager view
connect(m_pAlbumManagerView, SIGNAL(computeIconInBackBuffer(int)), this , SLOT(computeIconInBackBuffer(int)));
connect(m_pAlbumManagerView, SIGNAL(removeUnloadFileItem()), this , SLOT(removeUnloadFileItem()));
connect(m_pAlbumManagerView, SIGNAL(removeOnErrorModels()), this , SLOT(removeItemOnError()));
connect(m_pAlbumManagerView, SIGNAL(startLoading()), this , SLOT(startLoadingButton()));
connect(m_pAlbumManagerView, SIGNAL(stopLoading()), this , SLOT(stopLoadingButton()));
connect(m_pAlbumManagerView, SIGNAL(newAlbum(bool)), this, SLOT(newAlbum(bool)));
connect(m_pAlbumManagerView, SIGNAL(deleteModel(GLC_uint)), this, SLOT(deleteItem(GLC_uint)));
connect(m_pAlbumManagerView, SIGNAL(reloadCurrentModelSignal(const GLC_uint)), this, SLOT(reloadModel(const GLC_uint)));
connect(m_pAlbumManagerView, SIGNAL(currentModelChanged(QListWidgetItem *, QListWidgetItem *))
, this , SLOT(currentFileItemChanged(QListWidgetItem *, QListWidgetItem *)));
connect(m_pAlbumManagerView, SIGNAL(displayMessage(QString)), this , SLOT(displayMessageInStatusBar(QString)));
// Camera Property dock area
EditCamera* pEditCamWidget= new EditCamera(m_OpenglView.viewportHandle(), cameraProperties);
cameraProperties->setWidget(pEditCamWidget);
connect(&m_OpenglView, SIGNAL(viewChanged()), pEditCamWidget, SLOT(updateValues()));
connect(pEditCamWidget, SIGNAL(valueChanged()), this, SLOT(updateView()));
// Current selection dock area
m_pSelectionProperty= new SelectionProperty(actionShow_Hide, actionAssign_Shader, action_Property, selectionDockWidget);
selectionDockWidget->setWidget(m_pSelectionProperty);
connect(m_pSelectionProperty, SIGNAL(updateView()), &m_OpenglView, SLOT(updateGL()));
// Parse arguments command line
QStringList args= QCoreApplication::arguments ();
if (args.size() > 1)
{
QStringList argList(QFileInfo(args[1]).filePath());
if (QFileInfo(argList[0]).suffix().toLower() == "album")
{
openAlbum(argList[0]);
}
else
{
addItems(argList);
startLoading();
}
}
else
{
// Update UI
action_NewAlbum->setEnabled(false);
action_SaveAlbumAs->setEnabled(false);
action_SaveAlbum->setEnabled(false);
actionExport_To_Folder->setEnabled(false);
actionExport_current_Model->setEnabled(false);
actionExport_to_web->setEnabled(false);
setWindowTitle(QCoreApplication::applicationName());
statusbar->showMessage(tr("Untiteled"));
}
}
glc_player::~glc_player()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
// delete the progress bar
delete m_pProgressBar;
// delete error message dialog
delete m_pQErrorMessage;
delete m_pScreenshotDialog;
delete m_pEditLightDialog;
delete m_pChooseShaderDialog;
delete m_pModelManagerView;
delete m_pAlbumManagerView;
//m_pAlbumManagerView->clear();
m_FileEntryHash.clear();
delete m_pInstanceProperty;
GLC_ErrorLog::close();
QApplication::restoreOverrideCursor();
}
//////////////////////////////////////////////////////////////////////
// Virtual protected function
//////////////////////////////////////////////////////////////////////
// Close event handler
void glc_player::closeEvent(QCloseEvent* pEvent)
{
int ret= QMessageBox::Yes;
// Display confirmation msgBox only if there album is not empty
// And Quit confirmation is set to yes
if ((!m_FileEntryHash.empty()) && m_QuitConfirmation)
{
ret= QMessageBox::question(this, QCoreApplication::applicationName(),
QString(tr("Quits ")) + QCoreApplication::applicationName() + QString("?"), QMessageBox::Yes | QMessageBox::No);
}
if (ret == QMessageBox::Yes)
{
// Return to normal mode if needed
if (UserInterfaceSate::globalState() == INSTANCE_STATE)
{
returnToNormalMode();
}
m_pAlbumManagerView->blockSignals(true);
writeSettings();
pEvent->accept();
QCoreApplication::quit();
}
else
{
pEvent->ignore();
}
}
//////////////////////////////////////////////////////////////////////
// public Methods
//////////////////////////////////////////////////////////////////////
void glc_player::openOnEvent(QString fileName)
{
const bool fileIsAlbum= (QFileInfo(fileName).suffix().toLower() == "album");
if (fileIsAlbum && action_OpenAlbum->isEnabled())
{
openAlbum(fileName);
}
else if (!fileIsAlbum)
{
QStringList localFiles;
localFiles.append(fileName);
addItems(localFiles);
startLoading();
}
}
//////////////////////////////////////////////////////////////////////
// public Slots
//////////////////////////////////////////////////////////////////////
// The selection as been changed
void glc_player::updateSelection(PointerViewInstanceHash* pSelections)
{
if (pSelections->isEmpty())
{
unselectAll();
}
else
{
m_pSelectionProperty->setSelection(pSelections);
if(pSelections->size() == 1 && !(m_ContinuListLoading && m_ListLoadingInProgress))
{
action_Property->setEnabled(true);
m_pSelectionProperty->editPropertySetEnabled(true);
}
else
{
action_Property->setEnabled(false);
m_pSelectionProperty->editPropertySetEnabled(false);
}
actionUnselectAll->setEnabled(true);
if (GLC_State::glslUsed()) actionAssign_Shader->setEnabled(true);
actionShow_Hide->setEnabled(true);
actionHide_unselected->setEnabled(true);
actionReframeOnSelection->setEnabled(true);
}
}
// Info panel not supported
void glc_player::hideInfoPanel()
{
m_dislayInfoPanel= false;
writeSettings();
QCoreApplication::quit();
}
//////////////////////////////////////////////////////////////////////
// private Slots
//////////////////////////////////////////////////////////////////////
// The selection is Empty
void glc_player::unselectAll()
{
m_pSelectionProperty->unsetSelection();
action_Property->setEnabled(false);
m_pSelectionProperty->editPropertySetEnabled(false);
actionUnselectAll->setEnabled(false);
if (GLC_State::glslUsed()) actionAssign_Shader->setEnabled(false);
actionShow_Hide->setEnabled(false);
actionHide_unselected->setEnabled(false);
actionReframeOnSelection->setEnabled(false);
}
// Set Instance visibility
void glc_player::showOrHide()
{
if (m_pAlbumManagerView->haveCurrentModel())
{
const GLC_uint modelId(m_pAlbumManagerView->currentModelId());
GLC_World currentWorld= m_FileEntryHash.value(modelId).getWorld();
if (0 != currentWorld.selectionSize())
{
currentWorld.showHideSelected3DViewInstance();
m_OpenglView.updateGL();
m_pLeftSideDock->updateSelectedTreeShowNoShow();
}
}
}
// Hide unseleted instance
void glc_player::hideUnselected()
{
if (m_pAlbumManagerView->haveCurrentModel())
{
const GLC_uint modelId(m_pAlbumManagerView->currentModelId());
GLC_World currentWorld= m_FileEntryHash.value(modelId).getWorld();
if (0 != currentWorld.selectionSize())
{
currentWorld.rootOccurence()->setVisibility(false);
currentWorld.showSelected3DViewInstance();
m_OpenglView.setDistMinAndMax();
m_OpenglView.updateGL();
m_pLeftSideDock->updateTreeShowNoShow();
}
}
}
// Show All instance
void glc_player::showAll()
{
if (m_pAlbumManagerView->haveCurrentModel())
{
const GLC_uint modelId(m_pAlbumManagerView->currentModelId());
GLC_World currentWorld= m_FileEntryHash.value(modelId).getWorld();
currentWorld.rootOccurence()->setVisibility(true);
m_OpenglView.setDistMinAndMax();
m_OpenglView.updateGL();
m_pLeftSideDock->updateTreeShowNoShow();
}
}
// Swap visible space
void glc_player::swapVisibleSpace()
{
if (m_pAlbumManagerView->haveCurrentModel())
{
m_OpenglView.swapVisibleSpace();
m_OpenglView.setDistMinAndMax();
m_OpenglView.updateGL();
}
}
// update the value of the progress bar
void glc_player::updateProgressBar(int value)
{
if (value < 100)
{
statusbar->showMessage(tr("Loading in Progress Please Wait"));
m_pProgressBar->show();
m_pProgressBar->setValue(value);
}
else
{
statusbar->showMessage(tr("File Loaded"));
m_pProgressBar->hide();
}
}
// update the value of the progress bar
void glc_player::updateProgressBarForExport(int value)
{
if (value < 100)
{
statusbar->showMessage(tr("Exporting in Progress Please Wait"));
m_pProgressBar->show();
m_pProgressBar->setValue(value);
}
else
{
statusbar->showMessage(tr("File Exported"));
m_pProgressBar->hide();
}
}
//////////////////////////////////////////////////////////////////////
// private Slots
//////////////////////////////////////////////////////////////////////
void glc_player::newModel()
{
// add the File Entry
FileEntry newEntry(tr("New Model"));
GLC_uint modelId= newEntry.id();
m_FileEntryHash.insert(modelId, newEntry);
// Add the model to the view
m_pAlbumManagerView->addModel(modelId);
GLC_World newWorld;
m_FileEntryHash[modelId].setWorld(newWorld);
// Update the foreground of the item Opened file
int loadedItem= m_pAlbumManagerView->modelLoaded(modelId);
// Test if the loaded model have to be set as current
if (m_MakeFirstFileCurrent)
{
//Update window Title
setWindowTitle(QCoreApplication::applicationName() + QString(" [") + newEntry.name() + QString("]"));
// Set loading file as current item
if (m_pAlbumManagerView->isCurrent(loadedItem))
{
m_pAlbumManagerView->setCurrent(loadedItem);
}
else // force the display of loaded file
{
currentFileItemChanged(m_pAlbumManagerView->currentItem(), NULL);
}
}
else if (m_pAlbumManagerView->item(loadedItem) == m_pAlbumManagerView->currentItem())
{
// force the display of loaded file
currentFileItemChanged(m_pAlbumManagerView->currentItem(), NULL);
}
// Create the icon of the loaded file
if (m_pAlbumManagerView->thumbnailsAreDisplay())
{
computeIconInBackBuffer(loadedItem);
}
m_MakeFirstFileCurrent= (m_pAlbumManagerView->numberOfUnloadedModels() == 0);
m_FileEntryHash[modelId].setLoadingStatus(false);
}
// Remove all file item from the current album
bool glc_player::newAlbum(bool confirmation)
{
if (!m_FileLoadingInProgress)
{
int ret= QMessageBox::No;
if (confirmation)
{
ret= QMessageBox::question(this, tr("New Album Confirmation"),
tr("Remove all models from the current album?"), QMessageBox::Yes | QMessageBox::No);
}
if (!confirmation || (ret == QMessageBox::Yes))
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
unselectAll();
//loadingList->blockSignals(true);
m_pAlbumManagerView->clear();
m_pModelManagerView->clear();
//loadingList->blockSignals(false);
m_FileEntryHash.clear();
m_modelName.clear();
m_ClipBoard.first= 0;
m_ClipBoard.second= NULL;
// Update Continu list loading flag
m_ContinuListLoading= true;
m_CurrentAlbumName.clear();
// Update UI
action_NewAlbum->setEnabled(false);
action_SaveAlbumAs->setEnabled(false);
action_SaveAlbum->setEnabled(false);
actionExport_To_Folder->setEnabled(false);
actionExport_current_Model->setEnabled(false);
actionExport_to_web->setEnabled(false);
setWindowTitle(QCoreApplication::applicationName());
statusbar->showMessage(tr("Untiteled"));
m_MakeFirstFileCurrent= true;
if (actionSectioning->isChecked())
{
actionSectioning->setChecked(false);
sectioning();
}
QApplication::restoreOverrideCursor();
return true;
}
else return false;
}
else return false;
}
// Open An existing file
void glc_player::open()
{
// Define File Format filter
QStringList filters;
filters.append(tr("All Known format(*.obj *.OBJ *.3ds *.3DS *.stl *.STL *.off *.OFF *.3DXML *.3dxml *.DAE *.dae *.BSRep)"));
filters.append(tr("Alias File Format OBJ (*.obj *.OBJ)"));
filters.append(tr("3D Studio File Format 3DS (*.3ds *.3DS)"));
filters.append(tr("STL File Format STL (*.stl *.STL)"));
filters.append(tr("Object File Format OFF (*.off *.OFF)"));
filters.append(tr("Dassault Systemes 3DXML(*.3dxml *.3DXML)"));
filters.append(tr("Sony Collada(*.dae *.DAE)"));
filters.append(tr("GLC_lib Binary Serialized Representation(*.BSRep)"));
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select File(s) to Open and Add in album"), m_CurrentPath, filters.join("\n"));
if (!fileNames.isEmpty())
{
addItems(fileNames);
startLoading();
}
}
// Open An existing album
void glc_player::openAlbum()
{
if (!m_FileLoadingInProgress)
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Select Album File to Open")
, m_CurrentAlbumPath, "GLC_Player Album (*.album)");
if (!fileName.isEmpty())
{
openAlbum(fileName);
}
}
}
void glc_player::openModelsFromPath()
{
QStringList filters;
filters.append("*.OBJ");
filters.append("*.obj");
filters.append("*.3DS");
filters.append("*.3ds");
filters.append("*.STL");
filters.append("*.stl");
filters.append("*.OFF");
filters.append("*.off");
filters.append("*.3DXML");
filters.append("*.3dxml");
filters.append("*.DAE");
filters.append("*.dae");
filters.append("*.BSRep");
QString path= QFileDialog::getExistingDirectory(this, tr("Select Path"), m_CurrentPath);
qDebug() << "Load From path " << path;
if (!path.isEmpty())
{
//Search all supported 3D file from the given Path
QStringList fileNames= fileNameFromGivenPath(path, filters);
qDebug() << fileNames.count() << " File(s) found";
if (!fileNames.isEmpty())
{
addItems(fileNames);
startLoading();
}
}
}
// Save the current album
void glc_player::saveAlbum()
{
if (m_CurrentAlbumName.isEmpty())
{
saveAlbumAs();
}
else
{
applySavingAlbum(m_CurrentAlbumName);
}
}
// Save As a new album
void glc_player::saveAlbumAs()
{
QString currentPath;
if (!m_CurrentAlbumName.isEmpty())
{
currentPath= m_CurrentAlbumName;
}
else
{
currentPath= m_CurrentAlbumPath;
}
const QString suffix(".album");
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Album As ")
, currentPath, tr("GLC_Player Album (*.album)"));
if (!fileName.isEmpty())
{
if (!fileName.endsWith(suffix))
{
fileName.append(suffix);
}
applySavingAlbum(fileName);
}
}
// Open a Recent File
void glc_player::openRecentFile()
{
QAction* action= qobject_cast<QAction*>(sender());
if (action)
{
addItems(QStringList(action->data().toString()));
startLoading();
}
}
// Open a Recent Album
void glc_player::openRecentAlbum()
{
QAction* action= qobject_cast<QAction*>(sender());
if (action)
{
const QString albumName(action->data().toString());
qDebug() << albumName;
openAlbum(albumName);
}
}
// Send File to folder
void glc_player::sendToFolder()
{
if (NULL == m_pSendFilesDialog)
{
m_pSendFilesDialog= new SendFilesDialog(&m_FileEntryHash, this);
}
m_pSendFilesDialog->updateView(m_CurrentAlbumName);
if (m_pSendFilesDialog->exec() == QDialog::Accepted)
{
// OK we have to send some files
if (m_pSendFilesDialog->sendFiles())
{
if (m_pSendFilesDialog->copyAlbum() && m_pSendFilesDialog->updateAlbum())
{
m_CurrentAlbumName= m_pSendFilesDialog->newAlbumFileName();
saveAlbum();
}
QMessageBox::information(this, tr("Send To Folder"), tr("Files succesfuly send"));
}
}
}
// Export album to web
void glc_player::exportToWeb()
{
// Update current entry
FileEntryHash::iterator iEntry= m_FileEntryHash.find(m_pAlbumManagerView->currentModelId());
iEntry.value().setCameraAndAngle(m_OpenglView.getCamera(), m_OpenglView.getViewAngle());
iEntry.value().setPolygonMode(m_OpenglView.getMode());
if (NULL == m_pExportWebDialog)
{
m_pExportWebDialog= new ExportWebDialog(this);
}
m_pExportWebDialog->initDialog(QFileInfo(m_CurrentAlbumName).baseName(), m_pAlbumManagerView->sortedFileEntryList(), &m_OpenglView);
m_pExportWebDialog->exec();
}
void glc_player::exportCurrentModel()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Model As "), m_CurrentPath, tr("3DXML file (*.3dxml);;3DS file (*.3ds)"));
const QString suffix= QFileInfo(fileName).suffix();
if (!fileName.isEmpty() && ((suffix == "3dxml") || (suffix == "3ds")))
{
GLC_World worldToSav= m_FileEntryHash.value(m_pAlbumManagerView->currentModelId()).getWorld();
if (suffix == "3dxml")
{
if (GLC_State::vboUsed())
{
GLC_WorldTo3dxml worldTo3dxml(worldToSav, true);
connect(&worldTo3dxml, SIGNAL(currentQuantum(int)), this, SLOT(updateProgressBarForExport(int)));
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
worldTo3dxml.exportTo3dxml(fileName, GLC_WorldTo3dxml::Compressed3dxml);
QApplication::restoreOverrideCursor();
}
else
{
ExportProgressDialog exportProgress(this, worldToSav, fileName);
exportProgress.startThread();
}
}
else
{
GLC_WorldTo3ds worldTo3ds(worldToSav);
connect(&worldTo3ds, SIGNAL(currentQuantum(int)), this, SLOT(updateProgressBarForExport(int)));
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
worldTo3ds.exportToFile(fileName, true);
QApplication::restoreOverrideCursor();
}
}
}
// View and edit instance property
void glc_player::instanceProperty()
{
// in Instance property mode selection is disable
m_OpenglView.blockSelection(true);
// Create instance world
GLC_World instanceWorld;
GLC_World CurrentWorld(m_FileEntryHash.value(m_pAlbumManagerView->currentModelId()).getWorld());
instanceWorld.mergeWithAnotherWorld(CurrentWorld);
// Get the instance
Q_ASSERT(1 == instanceWorld.collection()->selectionSize());
GLC_3DViewInstance* pInstance= instanceWorld.collection()->selection()->begin().value();
instanceWorld.collection()->hideAll();
instanceWorld.collection()->setVisibility(pInstance->id(), true);
instanceWorld.collection()->unselectAll();
if (!m_OpenglView.getVisibleState())
{
m_OpenglView.setToVisibleState();
}
m_OpenglView.add(instanceWorld);
// Save and Update user Interface state
UserInterfaceSate::SetGlobalState(INSTANCE_STATE);
UserInterfaceSate::albumMangerVisibility(albumManagementWindow->isVisible());
albumManagementWindow->hide();
UserInterfaceSate::cameraPropertyVisibility(cameraProperties->isVisible());
cameraProperties->hide();
UserInterfaceSate::selectionPropertyVisibility(selectionDockWidget->isVisible());
selectionDockWidget->hide();
// Create instance property dock window if needed or show it
if (m_pInstanceProperty == NULL)
{
m_pInstanceProperty= new InstanceProperty(&m_OpenglView, actionAssign_Shader, this);
}
addDockWidget(Qt::LeftDockWidgetArea, m_pInstanceProperty);
m_pInstanceProperty->show();
//////////////////// Update Window menu////////////////////////////////////
// Disable dockWindow visibility change
action_AlbumManagement->setEnabled(false);
action_CameraProperty->setEnabled(false);
action_SelectionProperty->setEnabled(false);
// Menu edit
actionSelectAll->setEnabled(false);
actionUnselectAll->setEnabled(false);
action_Property->setEnabled(false);
m_pSelectionProperty->editPropertySetEnabled(false);
//Menu View
actionReframeOnSelection->setEnabled(false);
actionShow_Hide->setEnabled(false);
actionHide_unselected->setEnabled(false);
actionShow_all->setEnabled(false);
actionSwap_visible_space->setEnabled(false);
//Menu File
action_NewAlbum->setEnabled(false);
action_OpenAlbum->setEnabled(false);
menuRecent_Album->setEnabled(false);
action_SaveAlbum->setEnabled(false);
action_SaveAlbumAs->setEnabled(false);
actionExport_To_Folder->setEnabled(false);
actionExport_current_Model->setEnabled(false);
actionExport_to_web->setEnabled(false);
action_Open->setEnabled(false);
menuRecent_Models->setEnabled(false);
// Add instanceProperty visibility action
if (m_pInstancePropertyVis == NULL)
{
m_pInstancePropertyVis= new QAction(tr("Instance Property"), this);
m_pInstancePropertyVis->setCheckable(true);
}
m_pInstancePropertyVis->setChecked(true);
menu_Window->addAction(m_pInstancePropertyVis);
// Create action conection
connect(m_pInstancePropertyVis, SIGNAL(triggered()), this, SLOT(instancePropertyVisibilityToggle()));
connect(m_pInstanceProperty, SIGNAL(visibilityChanged(bool)), this, SLOT(instancePropertyVisibilityChanged(bool)));
connect(m_pInstanceProperty, SIGNAL(doneSignal()), this, SLOT(returnToNormalMode()));
connect(m_pInstanceProperty, SIGNAL(updateView()), &m_OpenglView, SLOT(updateGL()));
connect(m_pInstanceProperty, SIGNAL(viewSubMaterialList()), this, SLOT(viewListOfMaterial()));
m_pInstanceProperty->setInstance(pInstance);
////////////////////////////////////////////////////////////////////////////
// Reframe
m_OpenglView.reframe(pInstance->boundingBox(), true);
// Disable edit menu action
actionSelectAll->setEnabled(false);
}
// View and edit material property
void glc_player::viewMaterialProperty(GLC_Material* pMaterial)
{
m_OpenglView.doneCurrent();
if (NULL == m_pMaterialProperty)
{
m_pMaterialProperty= new MaterialProperty(&m_OpenglView, pMaterial, this);
addDockWidget(Qt::RightDockWidgetArea, m_pMaterialProperty);
if ((NULL != m_pListOfMaterial) && m_pListOfMaterial->isVisible())
{
connect(m_pMaterialProperty, SIGNAL(materialUpdated(GLC_Material*)), m_pListOfMaterial, SLOT(updateRow()));
connect(m_pMaterialProperty, SIGNAL(materialUpdated(GLC_Material*)), this, SLOT(updateCurrentEntryMaterial(GLC_Material*)));
}
}
else
{
addDockWidget(Qt::RightDockWidgetArea, m_pMaterialProperty);
m_pMaterialProperty->setMaterial(pMaterial);
}
m_pMaterialProperty->show();
//m_pMaterialProperty->updatePreview();
}
// View the list of material
void glc_player::viewListOfMaterial()
{
if (NULL == m_pListOfMaterial)
{
m_pListOfMaterial= m_pInstanceProperty->getListOfMaterials();
}
connect(m_pListOfMaterial, SIGNAL(updateMaterialSignal(GLC_Material*)), this, SLOT(viewMaterialProperty(GLC_Material*)));
m_pInstanceProperty->createOrUpdateListOfMaterial();
}
// Use the toon shader
void glc_player::assignShader()
{
if (NULL == m_pChooseShaderDialog)
{
m_pChooseShaderDialog= new ChooseShaderDialog(&m_OpenglView, this);
}
// -------------Prepare world for the choose shader dialog----------------
GLC_World ThumbnailsWorld;
GLC_World CurrentWorld(m_OpenglView.getWorld());
ThumbnailsWorld.mergeWithAnotherWorld(CurrentWorld);
// Hide unselected object
if (UserInterfaceSate::globalState() != INSTANCE_STATE)
{
ThumbnailsWorld.collection()->hideAll();
PointerViewInstanceHash* pSelection= ThumbnailsWorld.collection()->selection();
PointerViewInstanceHash::iterator iEntry= pSelection->begin();
while (iEntry != pSelection->constEnd())
{
ThumbnailsWorld.collection()->setVisibility(iEntry.value()->id(), true);
ThumbnailsWorld.collection()->changeShadingGroup(iEntry.value()->id(), 0);
iEntry++;
}
ThumbnailsWorld.collection()->unselectAll();
}
else
{
const GLC_uint id= ThumbnailsWorld.visibleInstancesHandle().first()->id();
ThumbnailsWorld.collection()->changeShadingGroup(id, 0);
}
m_OpenglView.add(ThumbnailsWorld);
// Save previous global shader
const GLuint oldShaderId= m_OpenglView.globalShaderId();
m_OpenglView.setGlobalShaderId(0, QString());