-
Notifications
You must be signed in to change notification settings - Fork 3
/
STLWindow.cpp
1547 lines (1410 loc) · 53.3 KB
/
STLWindow.cpp
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
/* STLover - A powerful tool for viewing and manipulating 3D STL models
* Copyright (C) 2020 Gerasim Troeglazov <3dEyes@gmail.com>
*
* This program 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.
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "STLApp.h"
#include "STLView.h"
#include "STLWindow.h"
#include "STLLogoView.h"
#include "STLStatView.h"
#include "STLInputWindow.h"
#include "STLRepairWindow.h"
#include "STLToolBar.h"
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "STLoverMainWindow"
STLWindow::STLWindow()
: BWindow(BRect(100, 100, 100 + 800, 100 + 640), MAIN_WIN_TITLE, B_TITLED_WINDOW, 0),
fOpenFilePanel(NULL),
fSaveFilePanel(NULL),
fMeasureWindow(NULL),
fStlModified(false),
fStlLoading(false),
fShowStat(false),
fShowBoundingBox(false),
fShowAxes(false),
fShowAxesPlane(false),
fShowAxesCompass(true),
fShowOXY(false),
fViewOrtho(false),
fShowMode(MSG_VIEWMODE_SOLID),
fMeasureMode(false),
fExactFlag(false),
fNearbyFlag(false),
fRemoveUnconnectedFlag(false),
fFillHolesFlag(false),
fNormalDirectionsFlag(false),
fNormalValuesFlag(false),
fReverseAllFlag(false),
fIterationsValue(2),
fStlValid(false),
fStlObject(NULL),
fErrorTimeCounter(0),
fRenderWork(true),
fZDepth(-5),
fMaxExtent(10)
{
fMenuBar = new BMenuBar(BRect(0, 0, Bounds().Width(), 22), "menubar");
fMenuFile = new BMenu(B_TRANSLATE("File"));
fMenuFileSaveAs = new BMenu(B_TRANSLATE("Save as" B_UTF8_ELLIPSIS));
fMenuView = new BMenu(B_TRANSLATE("View"));
fMenuAxes = new BMenu(B_TRANSLATE("Axes"));
fMenuTools = new BMenu(B_TRANSLATE("Tools"));
fMenuToolsMirror = new BMenu(B_TRANSLATE("Mirror"));
fMenuToolsScale = new BMenu(B_TRANSLATE("Scale"));
fMenuToolsMove = new BMenu(B_TRANSLATE("Move"));
fMenuHelp = new BMenu(B_TRANSLATE("Help"));
fMenuFileSaveAs->AddItem(new BMenuItem(B_TRANSLATE("STL (ASCII)"), new BMessage(MSG_FILE_EXPORT_STLA)));
fMenuFileSaveAs->AddItem(new BMenuItem(B_TRANSLATE("STL (Binary)"), new BMessage(MSG_FILE_EXPORT_STLB)));
fMenuFileSaveAs->AddItem(new BMenuItem(B_TRANSLATE("Geomview OFF"), new BMessage(MSG_FILE_EXPORT_OFF)));
fMenuFileSaveAs->AddItem(new BMenuItem(B_TRANSLATE("Autodesk DXF"), new BMessage(MSG_FILE_EXPORT_DXF)));
fMenuFileSaveAs->AddItem(new BMenuItem(B_TRANSLATE("Wavefront OBJ"), new BMessage(MSG_FILE_EXPORT_OBJ)));
fMenuFileSaveAs->AddItem(new BMenuItem(B_TRANSLATE("VRML"), new BMessage(MSG_FILE_EXPORT_VRML)));
fMenuItemOpen = new BMenuItem(BRecentFilesList::NewFileListMenu( B_TRANSLATE("Open" B_UTF8_ELLIPSIS),
NULL, NULL, be_app, 9, true, NULL, APP_SIGNATURE), new BMessage(MSG_FILE_OPEN));
fMenuItemOpen->SetShortcut('O', 0);
fMenuFile->AddItem(fMenuItemOpen);
fMenuItemReload = new BMenuItem(B_TRANSLATE("Reload"), new BMessage(MSG_FILE_RELOAD), 'L');
fMenuFile->AddItem(fMenuItemReload);
fMenuFile->AddSeparatorItem();
fMenuItemSave = new BMenuItem(B_TRANSLATE("Save"), new BMessage(MSG_FILE_SAVE), 'S');
fMenuFile->AddItem(fMenuItemSave);
fMenuFile->AddItem(fMenuFileSaveAs);
fMenuFileSaveAs->SetTargetForItems(this);
fMenuFile->AddSeparatorItem();
fMenuItemClose = new BMenuItem(B_TRANSLATE("Close"), new BMessage(MSG_FILE_CLOSE));
fMenuFile->AddItem(fMenuItemClose);
fMenuFile->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q'));
fMenuBar->AddItem(fMenuFile);
fMenuFile->SetTargetForItems(this);
fMenuItemShowAxesPlane = new BMenuItem(B_TRANSLATE("Plane"), new BMessage(MSG_VIEWMODE_AXES_PLANE));
fMenuAxes->AddItem(fMenuItemShowAxesPlane);
fMenuItemShowAxesCompass = new BMenuItem(B_TRANSLATE("Compass"), new BMessage(MSG_VIEWMODE_AXES_COMPASS));
fMenuAxes->AddItem(fMenuItemShowAxesCompass);
fMenuAxes->SetTargetForItems(this);
fMenuItemPoints = new BMenuItem(B_TRANSLATE("Points"), new BMessage(MSG_VIEWMODE_POINTS));
fMenuView->AddItem(fMenuItemPoints);
fMenuItemWireframe = new BMenuItem(B_TRANSLATE("Wireframe"), new BMessage(MSG_VIEWMODE_WIREFRAME));
fMenuView->AddItem(fMenuItemWireframe);
fMenuItemSolid = new BMenuItem(B_TRANSLATE("Solid"), new BMessage(MSG_VIEWMODE_SOLID));
fMenuView->AddItem(fMenuItemSolid);
fMenuView->AddSeparatorItem();
fMenuItemOrthographicView = new BMenuItem(B_TRANSLATE("Orthographic projection"), new BMessage(MSG_VIEWMODE_ORTHO));
fMenuView->AddItem(fMenuItemOrthographicView);
fMenuView->AddSeparatorItem();
fMenuItemShowAxes = new BMenuItem(fMenuAxes, new BMessage(MSG_VIEWMODE_AXES));
fMenuView->AddItem(fMenuItemShowAxes);
fMenuItemShowOXY = new BMenuItem(B_TRANSLATE("Plane OXY"), new BMessage(MSG_VIEWMODE_OXY));
fMenuView->AddItem(fMenuItemShowOXY);
fMenuItemShowBox = new BMenuItem(B_TRANSLATE("Bounding box"), new BMessage(MSG_VIEWMODE_BOUNDING_BOX));
fMenuView->AddItem(fMenuItemShowBox);
fMenuView->AddSeparatorItem();
fMenuItemStat = new BMenuItem(B_TRANSLATE("Statistics"), new BMessage(MSG_VIEWMODE_STAT), 'I');
fMenuView->AddItem(fMenuItemStat);
fMenuView->AddSeparatorItem();
fMenuItemReset = new BMenuItem(B_TRANSLATE("Reset"), new BMessage(MSG_VIEWMODE_RESETPOS), 'R');
fMenuView->AddItem(fMenuItemReset);
fMenuToolsMirror->AddItem(new BMenuItem(B_TRANSLATE("Mirror XY"), new BMessage(MSG_TOOLS_MIRROR_XY)));
fMenuToolsMirror->AddItem(new BMenuItem(B_TRANSLATE("Mirror YZ"), new BMessage(MSG_TOOLS_MIRROR_YZ)));
fMenuToolsMirror->AddItem(new BMenuItem(B_TRANSLATE("Mirror XZ"), new BMessage(MSG_TOOLS_MIRROR_XZ)));
fMenuToolsMirror->SetTargetForItems(this);
fMenuToolsScale->AddItem(new BMenuItem(B_TRANSLATE("Scale" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_SCALE)));
fMenuToolsScale->AddItem(new BMenuItem(B_TRANSLATE("Axis scaling" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_SCALE_3)));
fMenuToolsScale->SetTargetForItems(this);
fMenuToolsMove->AddItem(new BMenuItem(B_TRANSLATE("To" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_MOVE_TO)));
fMenuToolsMove->AddItem(new BMenuItem(B_TRANSLATE("By" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_MOVE_BY)));
fMenuToolsMove->AddItem(new BMenuItem(B_TRANSLATE("To origin"), new BMessage(MSG_TOOLS_MOVE_CENTER)));
fMenuToolsMove->AddItem(new BMenuItem(B_TRANSLATE("To (0,0,0)"), new BMessage(MSG_TOOLS_MOVE_ZERO)));
fMenuToolsMove->AddItem(new BMenuItem(B_TRANSLATE("To top of OXY plane"), new BMessage(MSG_TOOLS_MOVE_MIDDLE)));
fMenuToolsMove->SetTargetForItems(this);
fMenuItemEditTitle = new BMenuItem(B_TRANSLATE("Edit title" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_EDIT_TITLE));
fMenuTools->AddItem(fMenuItemEditTitle);
fMenuTools->AddSeparatorItem();
fMenuTools->AddItem(fMenuToolsScale);
fMenuTools->AddItem(fMenuToolsMove);
fMenuTools->AddItem(fMenuToolsMirror);
fMenuItemRotate = new BMenuItem(B_TRANSLATE("Rotate" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_ROTATE));
fMenuTools->AddItem(fMenuItemRotate);
fMenuTools->AddSeparatorItem();
fMenuItemRepair = new BMenuItem(B_TRANSLATE("Repair" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_REPAIR));
fMenuTools->AddItem(fMenuItemRepair);
fMenuTools->AddSeparatorItem();
fMenuItemMeasure = new BMenuItem(B_TRANSLATE("Measure" B_UTF8_ELLIPSIS), new BMessage(MSG_TOOLS_MEASURE));
fMenuTools->AddItem(fMenuItemMeasure);
fMenuBar->AddItem(fMenuView);
fMenuView->SetTargetForItems(this);
fMenuBar->AddItem(fMenuTools);
fMenuTools->SetTargetForItems(this);
fMenuHelp->AddItem(new BMenuItem(B_TRANSLATE("Documentation"), new BMessage(MSG_HELP_WIKI)));
fMenuHelp->AddSeparatorItem();
fMenuHelp->AddItem(new BMenuItem(B_TRANSLATE("About"), new BMessage(B_ABOUT_REQUESTED)));
fMenuBar->AddItem(fMenuHelp);
fMenuHelp->SetTargetForItems(this);
AddChild(fMenuBar);
BRect toolBarRect = Bounds();
toolBarRect.top = fMenuBar->Frame().bottom + 1;
fToolBar = new STLToolBar(toolBarRect);
fToolBar->AddAction(MSG_FILE_OPEN, this, STLoverApplication::GetIcon("document-open", TOOLBAR_ICON_SIZE), B_TRANSLATE("Open"));
fToolBar->AddAction(MSG_FILE_SAVE, this, STLoverApplication::GetIcon("document-save", TOOLBAR_ICON_SIZE), B_TRANSLATE("Save"));
fToolBar->AddSeparator();
fToolBar->AddAction(MSG_TOOLS_EDIT_TITLE, this, STLoverApplication::GetIcon("document-edit", TOOLBAR_ICON_SIZE), B_TRANSLATE("Edit title"));
fToolBar->AddAction(MSG_TOOLS_MIRROR_XY, this, STLoverApplication::GetIcon("mirror-xy", TOOLBAR_ICON_SIZE), B_TRANSLATE("Mirror XY"));
fToolBar->AddAction(MSG_TOOLS_MIRROR_YZ, this, STLoverApplication::GetIcon("mirror-yz", TOOLBAR_ICON_SIZE), B_TRANSLATE("Mirror YZ"));
fToolBar->AddAction(MSG_TOOLS_MIRROR_XZ, this, STLoverApplication::GetIcon("mirror-xz", TOOLBAR_ICON_SIZE), B_TRANSLATE("Mirror XZ"));
fToolBar->AddAction(MSG_TOOLS_MOVE_MIDDLE, this, STLoverApplication::GetIcon("move-middle", TOOLBAR_ICON_SIZE), B_TRANSLATE("Move to top of OXY plane"));
fToolBar->AddAction(MSG_TOOLS_MOVE_TO, this, STLoverApplication::GetIcon("move-to", TOOLBAR_ICON_SIZE), B_TRANSLATE("Move to"));
fToolBar->AddAction(MSG_TOOLS_MOVE_BY, this, STLoverApplication::GetIcon("move-by", TOOLBAR_ICON_SIZE), B_TRANSLATE("Move by"));
fToolBar->AddAction(MSG_TOOLS_SCALE, this, STLoverApplication::GetIcon("scale", TOOLBAR_ICON_SIZE), B_TRANSLATE("Scale"));
fToolBar->AddAction(MSG_TOOLS_SCALE_3, this, STLoverApplication::GetIcon("scale-axis", TOOLBAR_ICON_SIZE), B_TRANSLATE("Axis scale"));
fToolBar->AddAction(MSG_TOOLS_ROTATE, this, STLoverApplication::GetIcon("rotate", TOOLBAR_ICON_SIZE), B_TRANSLATE("Rotate"));
fToolBar->AddSeparator();
fToolBar->AddAction(MSG_TOOLS_REPAIR, this, STLoverApplication::GetIcon("tools-wizard", TOOLBAR_ICON_SIZE), B_TRANSLATE("Repair"));
fToolBar->AddSeparator();
fToolBar->AddAction(MSG_TOOLS_MEASURE, this, STLoverApplication::GetIcon("tool-measure", TOOLBAR_ICON_SIZE), B_TRANSLATE("Measure"));
fToolBar->AddSeparator();
fToolBar->AddAction(MSG_VIEWMODE_STAT, this, STLoverApplication::GetIcon("stat", TOOLBAR_ICON_SIZE), B_TRANSLATE("Statistics"));
fToolBar->AddGlue();
fToolBar->ResizeTo(toolBarRect.Width(), fToolBar->MinSize().height);
fToolBar->GroupLayout()->SetInsets(0);
AddChild(fToolBar);
BRect viewToolBarRect = Bounds();
viewToolBarRect.top = fToolBar->Frame().bottom + 1;
fViewToolBar = new STLToolBar(viewToolBarRect, B_VERTICAL);
fViewToolBar->AddAction(MSG_VIEWMODE_ZOOMIN, this, STLoverApplication::GetIcon("zoom-in", TOOLBAR_ICON_SIZE), B_TRANSLATE("Zoom in"));
fViewToolBar->AddAction(MSG_VIEWMODE_ZOOMOUT, this, STLoverApplication::GetIcon("zoom-out", TOOLBAR_ICON_SIZE), B_TRANSLATE("Zoom out"));
fViewToolBar->AddAction(MSG_VIEWMODE_ZOOMFIT, this, STLoverApplication::GetIcon("zoom-fit-best", TOOLBAR_ICON_SIZE), B_TRANSLATE("Best fit"));
fViewToolBar->AddSeparator();
fViewToolBar->AddAction(MSG_VIEWMODE_RESETPOS, this, STLoverApplication::GetIcon("reset", TOOLBAR_ICON_SIZE), B_TRANSLATE("Reset view"));
fViewToolBar->AddSeparator();
fViewToolBar->AddAction(MSG_VIEWMODE_POINTS, this, STLoverApplication::GetIcon("points", TOOLBAR_ICON_SIZE), B_TRANSLATE("Points"));
fViewToolBar->AddAction(MSG_VIEWMODE_WIREFRAME, this, STLoverApplication::GetIcon("wireframe", TOOLBAR_ICON_SIZE), B_TRANSLATE("Wireframe"));
fViewToolBar->AddAction(MSG_VIEWMODE_SOLID, this, STLoverApplication::GetIcon("solid", TOOLBAR_ICON_SIZE), B_TRANSLATE("Solid"));
fViewToolBar->AddAction(MSG_VIEWMODE_AXES, this, STLoverApplication::GetIcon("axes", TOOLBAR_ICON_SIZE), B_TRANSLATE("Show axes"));
fViewToolBar->AddAction(MSG_VIEWMODE_OXY, this, STLoverApplication::GetIcon("plane", TOOLBAR_ICON_SIZE), B_TRANSLATE("Show plane OXY"));
fViewToolBar->AddAction(MSG_VIEWMODE_BOUNDING_BOX, this, STLoverApplication::GetIcon("bounding-box", TOOLBAR_ICON_SIZE), B_TRANSLATE("Bounding box"));
fViewToolBar->AddSeparator();
fViewToolBar->AddAction(MSG_VIEWMODE_FRONT, this, STLoverApplication::GetIcon("view-front", TOOLBAR_ICON_SIZE), B_TRANSLATE("Front view"));
fViewToolBar->AddAction(MSG_VIEWMODE_RIGHT, this, STLoverApplication::GetIcon("view-right", TOOLBAR_ICON_SIZE), B_TRANSLATE("Right view"));
fViewToolBar->AddAction(MSG_VIEWMODE_TOP, this, STLoverApplication::GetIcon("view-top", TOOLBAR_ICON_SIZE), B_TRANSLATE("Top view"));
fViewToolBar->AddSeparator();
fViewToolBar->AddAction(MSG_VIEWMODE_ORTHO, this, STLoverApplication::GetIcon("orthographic", TOOLBAR_ICON_SIZE), B_TRANSLATE("Orthographic projection"));
fViewToolBar->AddGlue();
fViewToolBar->ResizeTo(fViewToolBar->MinSize().width, viewToolBarRect.Height());
fViewToolBar->GroupLayout()->SetInsets(0);
AddChild(fViewToolBar);
BRect stlRect = Bounds();
stlRect.top = fToolBar->Frame().bottom + 1;
stlRect.left =fViewToolBar->Frame().right + 1;
fStlView = new STLView(stlRect, BGL_RGB | BGL_DOUBLE | BGL_DEPTH);
AddChild(fStlView);
fStlView->Hide();
fStlLogoView = new STLLogoView(stlRect);
fStlLogoView->SetText(B_TRANSLATE("Drop STL files here"));
fStlLogoView->SetTextColor(255, 255, 255);
AddChild(fStlLogoView);
BRect statRect = Bounds();
statRect.left = stlRect.right + 1;
statRect.top = stlRect.top;
fStatView = new STLStatView(statRect);
AddChild(fStatView);
AddShortcut('H', B_COMMAND_KEY, new BMessage(MSG_EASTER_EGG));
AddShortcut('Q', B_COMMAND_KEY, new BMessage(MSG_APP_QUIT));
LoadSettings();
UpdateUI();
fRendererThread = spawn_thread(_RenderFunction, "renderThread", B_NORMAL_PRIORITY, (void*)fStlView);
resume_thread(fRendererThread);
SetPulseRate(1000000);
}
STLWindow::~STLWindow()
{
SaveSettings();
status_t exitValue;
fRenderWork = false;
wait_for_thread(fRendererThread, &exitValue);
CloseFile();
if (fOpenFilePanel != NULL)
fOpenFilePanel->Window()->PostMessage(B_QUIT_REQUESTED);
if (fSaveFilePanel != NULL)
fSaveFilePanel->Window()->PostMessage(B_QUIT_REQUESTED);
be_app->PostMessage(MSG_WINDOW_CLOSED);
}
void
STLWindow::UpdateUI(void)
{
UpdateStats();
UpdateUIStates(IsLoaded());
fStlView->RenderUpdate();
}
void
STLWindow::LoadSettings(void)
{
BPath path;
if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
path.Append(APP_SETTINGS_FILENAME);
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() != B_OK || file.Lock() != B_OK)
return;
bool _fShowBoundingBox = false;
bool _fShowAxes = false;
bool _fShowAxesPlane = false;
bool _fShowAxesCompass = true;
bool _showStat = false;
bool _fShowOXY = false;
bool _fOrthoProj = false;
uint32 _fShowMode = MSG_VIEWMODE_SOLID;
BRect _windowRect(100, 100, 100 + 800, 100 + 640);
file.ReadAttr("WindowRect", B_RECT_TYPE, 0, &_windowRect, sizeof(BRect));
file.ReadAttr("ShowAxes", B_BOOL_TYPE, 0, &_fShowAxes, sizeof(bool));
file.ReadAttr("ShowAxesPlane", B_BOOL_TYPE, 0, &_fShowAxesPlane, sizeof(bool));
file.ReadAttr("ShowAxesCompass", B_BOOL_TYPE, 0, &_fShowAxesCompass, sizeof(bool));
file.ReadAttr("ShowOXY", B_BOOL_TYPE, 0, &_fShowOXY, sizeof(bool));
file.ReadAttr("ShowBoundingBox", B_BOOL_TYPE, 0, &_fShowBoundingBox, sizeof(bool));
file.ReadAttr("ShowStat", B_BOOL_TYPE, 0, &_showStat, sizeof(bool));
file.ReadAttr("ShowMode", B_UINT32_TYPE, 0, &_fShowMode, sizeof(uint32));
file.ReadAttr("OrthographicProjection", B_BOOL_TYPE, 0, &_fOrthoProj, sizeof(bool));
file.ReadAttr("Exact", B_INT32_TYPE, 0, &fExactFlag, sizeof(int32));
file.ReadAttr("Nearby", B_INT32_TYPE, 0, &fNearbyFlag, sizeof(int32));
file.ReadAttr("RemoveUnconnected", B_INT32_TYPE, 0, &fRemoveUnconnectedFlag, sizeof(int32));
file.ReadAttr("FillHoles", B_INT32_TYPE, 0, &fFillHolesFlag, sizeof(int32));
file.ReadAttr("NormalDirections", B_INT32_TYPE, 0, &fNormalDirectionsFlag, sizeof(int32));
file.ReadAttr("NormalValues", B_INT32_TYPE, 0, &fNormalValuesFlag, sizeof(int32));
file.ReadAttr("ReverseAll", B_INT32_TYPE, 0, &fReverseAllFlag, sizeof(int32));
file.ReadAttr("Iterations", B_INT32_TYPE, 0, &fIterationsValue, sizeof(int32));
MoveTo(_windowRect.left, _windowRect.top);
ResizeTo(_windowRect.Width(), _windowRect.Height());
fShowBoundingBox = _fShowBoundingBox;
fStlView->ShowBoundingBox(fShowBoundingBox);
fShowAxes = _fShowAxes;
fShowAxesPlane = _fShowAxesPlane;
fShowAxesCompass = _fShowAxesCompass;
fStlView->ShowAxes(fShowAxes, fShowAxesPlane, fShowAxesCompass);
fShowOXY = _fShowOXY;
fStlView->ShowOXY(fShowOXY);
fShowMode = _fShowMode;
fStlView->SetViewMode(fShowMode);
fViewOrtho = _fOrthoProj;
fStlView->SetOrthographic(fViewOrtho);
fShowStat = _showStat;
if (fShowStat)
UpdateStats();
UpdateUIStates(IsLoaded());
file.Unlock();
}
}
void
STLWindow::SaveSettings(void)
{
BPath path;
if (find_directory (B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
path.Append(APP_SETTINGS_FILENAME);
BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
if (file.InitCheck() != B_OK || file.Lock() != B_OK)
return;
BRect _windowRect = Frame();
file.WriteAttr("WindowRect", B_RECT_TYPE, 0, &_windowRect, sizeof(BRect));
file.WriteAttr("ShowAxes", B_BOOL_TYPE, 0, &fShowAxes, sizeof(bool));
file.WriteAttr("ShowAxesPlane", B_BOOL_TYPE, 0, &fShowAxesPlane, sizeof(bool));
file.WriteAttr("ShowAxesCompass", B_BOOL_TYPE, 0, &fShowAxesCompass, sizeof(bool));
file.WriteAttr("ShowOXY", B_BOOL_TYPE, 0, &fShowOXY, sizeof(bool));
file.WriteAttr("ShowBoundingBox", B_BOOL_TYPE, 0, &fShowBoundingBox, sizeof(bool));
file.WriteAttr("ShowStat", B_BOOL_TYPE, 0, &fShowStat, sizeof(bool));
file.WriteAttr("ShowMode", B_UINT32_TYPE, 0, &fShowMode, sizeof(uint32));
file.WriteAttr("OrthographicProjection", B_BOOL_TYPE, 0, &fViewOrtho, sizeof(bool));
file.WriteAttr("Exact", B_INT32_TYPE, 0, &fExactFlag, sizeof(int32));
file.WriteAttr("Nearby", B_INT32_TYPE, 0, &fNearbyFlag, sizeof(int32));
file.WriteAttr("RemoveUnconnected", B_INT32_TYPE, 0, &fRemoveUnconnectedFlag, sizeof(int32));
file.WriteAttr("FillHoles", B_INT32_TYPE, 0, &fFillHolesFlag, sizeof(int32));
file.WriteAttr("NormalDirections", B_INT32_TYPE, 0, &fNormalDirectionsFlag, sizeof(int32));
file.WriteAttr("NormalValues", B_INT32_TYPE, 0, &fNormalValuesFlag, sizeof(int32));
file.WriteAttr("ReverseAll", B_INT32_TYPE, 0, &fReverseAllFlag, sizeof(int32));
file.WriteAttr("Iterations", B_INT32_TYPE, 0, &fIterationsValue, sizeof(int32));
file.Sync();
file.Unlock();
}
}
void
STLWindow::WindowActivated(bool active)
{
if (active) {
BMessage *message = new BMessage(MSG_WINDOW_ACTIVATED);
message->AddPointer("window", this);
be_app->PostMessage(message);
}
}
bool
STLWindow::QuitRequested()
{
if (fStlModified) {
BPath path(fOpenedFileName);
BString alertText(B_TRANSLATE("Save changes to document '%filename%' ?"));
alertText.ReplaceFirst("%filename%", path.Leaf());
BAlert* alert = new BAlert(B_TRANSLATE("Save"), alertText,
B_TRANSLATE("Cancel"), B_TRANSLATE("Don't save"), B_TRANSLATE("Save"), B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_WARNING_ALERT);
alert->SetShortcut(0, B_ESCAPE);
int32 choice = alert->Go();
switch (choice) {
case 0:
return false;
case 1:
return true;
case 2:
default:
{
BPath path(fOpenedFileName);
if (fStlObject->stats.type == binary)
stl_write_binary(fStlObject, path.Path(), fStlObject->stats.header);
else
stl_write_ascii(fStlObject, path.Path(), fStlObject->stats.header);
fStlModified = false;
return true;
}
}
}
return true;
}
void
STLWindow::MessageReceived(BMessage *message)
{
if (message->WasDropped())
message->what = B_REFS_RECEIVED;
switch (message->what) {
case B_KEY_DOWN:
case B_UNMAPPED_KEY_DOWN:
{
if (IsLoaded()) {
uint32 key = message->FindInt32("key");
uint32 modifiers = message->FindInt32("modifiers");
float scaleFactor = fStlView->ScaleFactor();
float scaleDelta = (GetZDepth() + scaleFactor) * 0.053589838958;
float xRotate = fStlView->XRotate();
float yRotate = fStlView->YRotate();
float rotateDelta = 5.0;
if (modifiers & B_SHIFT_KEY) {
scaleDelta /= 5.0;
rotateDelta /= 5.0;
}
if (modifiers & B_CONTROL_KEY) {
scaleDelta *= 2.0;
rotateDelta = 90.0;
}
switch (key) {
case 0x25: // Zoom [-]
case 0x1C:
scaleFactor += scaleDelta;
break;
case 0x3A: // Zoom [+]
case 0x1D:
scaleFactor -= scaleDelta;
break;
case 0x61: // Left
yRotate -= rotateDelta;
break;
case 0x63: // Right
yRotate += rotateDelta;
break;
case 0x57: // Up
xRotate -= rotateDelta;
break;
case 0x62: // Down
xRotate += rotateDelta;
break;
case 0x5E: // Reset position [Space]
fStlView->Reset(false, true, true);
return;
case 0x64: // Reset scale [0]
case 0x1B:
fStlView->Reset(true, false, false);
return;
}
fStlView->SetScaleFactor(scaleFactor);
fStlView->SetXRotate(xRotate);
fStlView->SetYRotate(yRotate);
}
break;
}
case MSG_FILE_OPEN:
{
if (fOpenFilePanel == NULL) {
fOpenFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
B_FILE_NODE, true, NULL, NULL, false, true);
fOpenFilePanel->SetTarget(this);
}
BMessage *openMsg = new BMessage(B_REFS_RECEIVED);
fOpenFilePanel->SetMessage(openMsg);
delete openMsg;
fOpenFilePanel->Show();
break;
}
case MSG_FILE_SAVE:
{
BPath path(fOpenedFileName);
if (fStlObject->stats.type == binary)
stl_write_binary(fStlObject, path.Path(), fStlObject->stats.header);
else
stl_write_ascii(fStlObject, path.Path(), fStlObject->stats.header);
BNode node(path.Path());
BNodeInfo nodeInfo(&node);
nodeInfo.SetType("application/sla");
fStlModified = false;
UpdateUIStates(true);
break;
}
case MSG_FILE_EXPORT_STLA:
case MSG_FILE_EXPORT_STLB:
case MSG_FILE_EXPORT_DXF:
case MSG_FILE_EXPORT_VRML:
case MSG_FILE_EXPORT_OFF:
case MSG_FILE_EXPORT_OBJ:
{
BMessage *fileMsg = new BMessage(*message);
fileMsg->AddInt32("format", message->what);
fileMsg->what = B_SAVE_REQUESTED;
if (fSaveFilePanel == NULL) {
fSaveFilePanel = new BFilePanel(B_SAVE_PANEL, NULL, NULL,
B_FILE_NODE, true, fileMsg, NULL, false, true);
fSaveFilePanel->SetTarget(this);
} else {
fSaveFilePanel->SetMessage(fileMsg);
fSaveFilePanel->SetSaveText("");
}
BPath openedFile(fOpenedFileName);
BString title(B_TRANSLATE(
"Save '%document%' as a '%format%' file as" B_UTF8_ELLIPSIS));
title.ReplaceFirst("%document%", openedFile.Leaf());
if (message->what == MSG_FILE_EXPORT_STLA)
title.ReplaceFirst("%format%", B_TRANSLATE("STL (ASCII)"));
if (message->what == MSG_FILE_EXPORT_STLB)
title.ReplaceFirst("%format%", B_TRANSLATE("STL (Binary)"));
if (message->what == MSG_FILE_EXPORT_DXF)
title.ReplaceFirst("%format%", B_TRANSLATE("Autodesk DXF"));
if (message->what == MSG_FILE_EXPORT_VRML)
title.ReplaceFirst("%format%", B_TRANSLATE("VRML"));
if (message->what == MSG_FILE_EXPORT_OFF)
title.ReplaceFirst("%format%", B_TRANSLATE("Geomview OFF"));
if (message->what == MSG_FILE_EXPORT_OBJ)
title.ReplaceFirst("%format%", B_TRANSLATE("Wavefront OBJ"));
fSaveFilePanel->Window()->SetTitle(title.String());
fSaveFilePanel->Show();
delete fileMsg;
break;
}
case MSG_FILE_CLOSE:
{
CloseFile();
break;
}
case MSG_FILE_OPENED:
{
fZDepth = -5;
fMaxExtent = 10;
BPath path(fOpenedFileName);
SetTitle(path.Leaf());
TransformPosition();
fStlView->SetSTL(fStlObject);
fErrorTimeCounter = 0;
fStlLoading = false;
fStlModified = false;
fStlValid = true;
UpdateUI();
fStlLogoView->Hide();
fStlView->Show();
break;
}
case MSG_FILE_OPEN_FAILED:
{
CloseFile();
fErrorTimeCounter = 4;
fStlLoading = false;
break;
}
case MSG_PULSE:
{
if (fErrorTimeCounter > 1) {
fErrorTimeCounter--;
fStlLogoView->SetText(B_TRANSLATE("Unknown file format!"));
fStlLogoView->SetTextColor(255, 25, 25);
} else if (fErrorTimeCounter == 1) {
fErrorTimeCounter--;
fStlLogoView->SetText(B_TRANSLATE("Drop STL files here"));
fStlLogoView->SetTextColor(255, 255, 255);
}
break;
}
case B_REFS_RECEIVED:
{
entry_ref ref;
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) {
BEntry entry(&ref, true);
if (!entry.Exists())
continue;
BPath path;
if (entry.GetPath(&path) != B_OK)
continue;
if (i==0 && !IsLoaded() && !IsLoading()) {
OpenFile(path.Path());
} else {
BMessage *msg = new BMessage(B_REFS_RECEIVED);
msg->AddRef("refs", &ref);
be_app->PostMessage(msg);
}
}
break;
}
case B_SAVE_REQUESTED:
{
entry_ref ref;
if (message->FindRef("directory", 0, &ref) == B_OK) {
BEntry entry = BEntry(&ref);
BPath path;
entry.GetPath(&path);
BString filename = message->FindString("name");
path.Append(filename);
uint32 format = message->FindInt32("format");
BString mime("application/sla");
switch (format) {
case MSG_FILE_EXPORT_STLA:
stl_write_ascii(fStlObject, path.Path(), fStlObject->stats.header);
break;
case MSG_FILE_EXPORT_STLB:
stl_write_binary(fStlObject, path.Path(), fStlObject->stats.header);
break;
case MSG_FILE_EXPORT_DXF:
stl_write_dxf(fStlObject, (char*)path.Path(), fStlObject->stats.header);
mime.SetTo("application/dxf");
break;
case MSG_FILE_EXPORT_VRML:
stl_repair(fStlObject, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1);
stl_generate_shared_vertices(fStlObject);
stl_write_vrml(fStlObject, (char*)path.Path());
mime.SetTo("text/plain");
break;
case MSG_FILE_EXPORT_OFF:
stl_repair(fStlObject, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1);
stl_generate_shared_vertices(fStlObject);
stl_write_off(fStlObject, (char*)path.Path());
mime.SetTo("text/plain");
break;
case MSG_FILE_EXPORT_OBJ:
stl_repair(fStlObject, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1);
stl_generate_shared_vertices(fStlObject);
stl_write_obj(fStlObject, (char*)path.Path());
mime.SetTo("text/plain");
break;
}
BNode node(path.Path());
BNodeInfo nodeInfo(&node);
nodeInfo.SetType(mime.String());
fStlModified = false;
UpdateUI();
}
break;
}
case B_CANCEL:
break;
case B_ABOUT_REQUESTED:
{
BAboutWindow* wind = new BAboutWindow(MAIN_WIN_TITLE, APP_SIGNATURE);
wind->AddCopyright(2021, "Gerasim Troeglazov (3dEyes**)");
wind->AddCopyright(2021, "Enrique M.G. (Lt-Henry)");
wind->AddDescription(
"This program 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.\n\n"
"This program 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.\n\n"
"You should have received a copy of the GNU General Public License along"
"with this program; if not, write to the Free Software Foundation, Inc., "
"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA." );
wind->Show();
break;
}
case MSG_VIEWMODE_OXY:
{
fShowOXY = !fShowOXY;
fStlView->ShowOXY(fShowOXY);
UpdateUI();
break;
}
case MSG_VIEWMODE_AXES:
{
fShowAxes = !fShowAxes;
if (fShowAxes && !fShowAxesPlane && !fShowAxesCompass) {
fShowAxesPlane = true;
fShowAxesCompass = true;
}
fStlView->ShowAxes(fShowAxes, fShowAxesPlane, fShowAxesCompass);
UpdateUI();
break;
}
case MSG_VIEWMODE_AXES_PLANE:
{
fShowAxesPlane = !fShowAxesPlane;
if (fShowAxes && !fShowAxesPlane && !fShowAxesCompass) {
fShowAxes = false;
}
fStlView->ShowAxes(fShowAxes, fShowAxesPlane, fShowAxesCompass);
UpdateUI();
break;
}
case MSG_VIEWMODE_AXES_COMPASS:
{
fShowAxesCompass = !fShowAxesCompass;
if (fShowAxes && !fShowAxesPlane && !fShowAxesCompass) {
fShowAxes = false;
}
fStlView->ShowAxes(fShowAxes, fShowAxesPlane, fShowAxesCompass);
UpdateUI();
break;
}
case MSG_VIEWMODE_BOUNDING_BOX:
{
fShowBoundingBox = !fShowBoundingBox;
fStlView->ShowBoundingBox(fShowBoundingBox);
UpdateUI();
break;
}
case MSG_VIEWMODE_RESETPOS:
{
fStlView->Reset();
UpdateUI();
break;
}
case MSG_VIEWMODE_ZOOMIN:
{
float scaleFactor = fStlView->ScaleFactor();
float scaleDelta = (GetZDepth() + scaleFactor) * 0.053589838958;
fStlView->SetScaleFactor(scaleFactor - scaleDelta);
UpdateUI();
break;
}
case MSG_VIEWMODE_ZOOMOUT:
{
float scaleFactor = fStlView->ScaleFactor();
float scaleDelta = (GetZDepth() + scaleFactor) * 0.053589838958;
fStlView->SetScaleFactor(scaleFactor + scaleDelta);
UpdateUI();
break;
}
case MSG_VIEWMODE_ZOOMFIT:
{
fStlView->Reset(true, false, false);
UpdateUI();
break;
}
case MSG_VIEWMODE_FRONT:
{
fStlView->Reset(true, false, true);
fStlView->SetXRotate(-90);
fStlView->SetYRotate(0);
UpdateUI();
break;
}
case MSG_VIEWMODE_TOP:
{
fStlView->Reset(true, false, true);
fStlView->SetXRotate(0);
fStlView->SetYRotate(0);
UpdateUI();
break;
}
case MSG_VIEWMODE_ORTHO:
{
fViewOrtho=!fViewOrtho;
UpdateUI();
fStlView->SetOrthographic(fViewOrtho);
break;
}
case MSG_VIEWMODE_RIGHT:
{
fStlView->Reset(true, false, true);
fStlView->SetXRotate(-90);
fStlView->SetYRotate(-90);
UpdateUI();
break;
}
case MSG_FILE_RELOAD:
{
OpenFile(fOpenedFileName.String());
break;
}
case MSG_TOOLS_MEASURE:
{
fMeasureMode = !fMeasureMode;
if (fMeasureMode) {
fMeasureWindow = new STLInputWindow(B_TRANSLATE("Measure"), this, MSG_TOOLS_MEASURE_DROP, BUTTON_RESET | BUTTON_CLOSE);
fMeasureWindow->AddGroup("from", B_TRANSLATE("From:"), 3);
fMeasureWindow->AddFloatField("x1", "", 0.0);
fMeasureWindow->SetFieldEditable("x1", false);
fMeasureWindow->SetFieldBackgroundColor("x1", {164, 255, 164});
fMeasureWindow->AddFloatField("y1", "", 0.0);
fMeasureWindow->SetFieldEditable("y1", false);
fMeasureWindow->SetFieldBackgroundColor("y1", {164, 255, 164});
fMeasureWindow->AddFloatField("z1", "", 0.0);
fMeasureWindow->SetFieldEditable("z1", false);
fMeasureWindow->SetFieldBackgroundColor("z1", {164, 255, 164});
fMeasureWindow->AddGroup("to", B_TRANSLATE("To:"), 3);
fMeasureWindow->AddFloatField("x2", "", 0.0);
fMeasureWindow->SetFieldEditable("x2", false);
fMeasureWindow->SetFieldBackgroundColor("x2", {255, 164, 164});
fMeasureWindow->AddFloatField("y2", "", 0.0);
fMeasureWindow->SetFieldEditable("y2", false);
fMeasureWindow->SetFieldBackgroundColor("y2", {255, 164, 164});
fMeasureWindow->AddFloatField("z2", "", 0.0);
fMeasureWindow->SetFieldEditable("z2", false);
fMeasureWindow->SetFieldBackgroundColor("z2", {255, 164, 164});
fMeasureWindow->AddFloatField("distance", B_TRANSLATE("Distance:"), 0.0);
fMeasureWindow->SetFieldEditable("distance", false);
fMeasureWindow->Show();
} else {
if (fMeasureWindow) {
fMeasureWindow->Lock();
fMeasureWindow->Quit();
fMeasureWindow = NULL;
}
}
fStlView->SetMeasureMode(fMeasureMode);
UpdateUI();
break;
}
case MSG_TOOLS_MEASURE_DROP:
{
fMeasureMode = false;
fStlView->SetMeasureMode(fMeasureMode);
UpdateUI();
break;
}
case MSG_TOOLS_MEASURE_UPDATE:
{
if (fMeasureMode) {
fMeasureWindow->SetFloatFieldValue("x1", message->FindFloat("x1"));
fMeasureWindow->SetFloatFieldValue("y1", message->FindFloat("y1"));
fMeasureWindow->SetFloatFieldValue("z1", message->FindFloat("z1"));
fMeasureWindow->SetFloatFieldValue("x2", message->FindFloat("x2"));
fMeasureWindow->SetFloatFieldValue("y2", message->FindFloat("y2"));
fMeasureWindow->SetFloatFieldValue("z2", message->FindFloat("z2"));
fMeasureWindow->SetFloatFieldValue("distance", message->FindFloat("distance"));
}
break;
}
case MSG_VIEWMODE_STAT:
{
fShowStat = !fShowStat;
UpdateUI();
break;
}
case MSG_TOOLS_REPAIR:
{
BMessage *options = new BMessage();
options->AddInt32("fExactFlag", fExactFlag);
options->AddInt32("fNearbyFlag", fNearbyFlag);
options->AddInt32("fRemoveUnconnectedFlag", fRemoveUnconnectedFlag);
options->AddInt32("fFillHolesFlag", fFillHolesFlag);
options->AddInt32("fNormalDirectionsFlag", fNormalDirectionsFlag);
options->AddInt32("fNormalValuesFlag", fNormalValuesFlag);
options->AddInt32("fReverseAllFlag", fReverseAllFlag);
options->AddInt32("fIterationsValue", fIterationsValue);
options->AddFloat("toleranceValue", fStlObject->stats.shortest_edge);
options->AddFloat("incrementValue", fStlObject->stats.bounding_diameter / 10000.0);
STLRepairWindow *repairDialog = new STLRepairWindow(this, MSG_TOOLS_REPAIR_DO, options);
repairDialog->Show();
UpdateUIStates(false);
break;
}
case MSG_TOOLS_REPAIR_DO:
{
fExactFlag = message->FindInt32("fExactFlag");
fNearbyFlag = message->FindInt32("fNearbyFlag");
fRemoveUnconnectedFlag = message->FindInt32("fRemoveUnconnectedFlag");
fFillHolesFlag = message->FindInt32("fFillHolesFlag");
fNormalDirectionsFlag = message->FindInt32("fNormalDirectionsFlag");
fNormalValuesFlag = message->FindInt32("fNormalValuesFlag");
fReverseAllFlag = message->FindInt32("fReverseAllFlag");
fIterationsValue = message->FindInt32("fIterationsValue");
float toleranceValue = message->FindInt32("toleranceValue");
float incrementValue = message->FindInt32("incrementValue");
if (IsLoaded()) {
stl_repair(fStlObject, 0, fExactFlag, 1, toleranceValue, 1, incrementValue, fNearbyFlag,
fIterationsValue, fRemoveUnconnectedFlag, fFillHolesFlag, fNormalDirectionsFlag,
fNormalValuesFlag, fReverseAllFlag, 0);
fStlModified = true;
fStlView->Reload();
UpdateUI();
}
break;
}
case MSG_TOOLS_EDIT_TITLE:
{
STLInputWindow *input = new STLInputWindow(B_TRANSLATE("STL Title"), this, MSG_TOOLS_TITLE_SET);
input->AddTextField("title", B_TRANSLATE("Title:"), (const char*)fStlObject->stats.header);
input->Show();
UpdateUIStates(false);
break;
}
case MSG_TOOLS_TITLE_SET:
{
const char *value = message->FindString("title");
if (value != NULL && IsLoaded()) {
snprintf(fStlObject->stats.header, 80, value);
fStlModified = true;
UpdateUI();
}
break;
}
case MSG_TOOLS_SCALE:
{
STLInputWindow *input = new STLInputWindow(B_TRANSLATE("Scale"), this, MSG_TOOLS_SCALE_SET);
input->AddFloatField("scale", B_TRANSLATE("Scale factor:"), 1.0);
input->Show();
UpdateUIStates(false);
break;
}
case MSG_TOOLS_SCALE_SET:
{
float value = message->FindFloat("scale");
if (IsLoaded()) {
stl_scale(fStlObject, value);
fStlModified = true;
UpdateUI();
fStlView->HidePreview();
fStlView->Reload();
}
break;
}
case MSG_TOOLS_SCALE_3:
{
STLInputWindow *input = new STLInputWindow(B_TRANSLATE("Custom axis scale"), this, MSG_TOOLS_SCALE_SET_3);
input->AddFloatField("x", B_TRANSLATE("Scale X factor:"), 1.0);
input->SetFieldBackgroundColor("x", {255, 164, 164});
input->AddFloatField("y", B_TRANSLATE("Scale Y factor:"), 1.0);
input->SetFieldBackgroundColor("y", {164, 255, 164});
input->AddFloatField("z", B_TRANSLATE("Scale Z factor:"), 1.0);
input->SetFieldBackgroundColor("z", {164, 164, 255});
input->Show();
UpdateUIStates(false);
break;
}
case MSG_TOOLS_SCALE_SET_3:
{
float values[3];
values[0] = message->FindFloat("x");
values[1] = message->FindFloat("y");
values[2] = message->FindFloat("z");
if (IsLoaded()) {
stl_scale_versor(fStlObject, values);
fStlModified = true;
UpdateUI();
fStlView->HidePreview();
fStlView->Reload();
}
break;
}
case MSG_TOOLS_ROTATE:
{
STLInputWindow *input = new STLInputWindow(B_TRANSLATE("Rotate"), this, MSG_TOOLS_ROTATE_SET);
input->AddSliderField("x", B_TRANSLATE("X-axis:"), 0, -180, 180);
input->SetFieldBackgroundColor("x", {255, 164, 164});
input->AddSliderField("y", B_TRANSLATE("Y-axis:"), 0, -180, 180);