forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
6004 lines (5229 loc) · 221 KB
/
tools.py
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
"""
@package nviz.tools
@brief Nviz (3D view) tools window
Classes:
- tools::NvizToolWindow
- tools::PositionWindow
- tools::ViewPositionWindow
- tools::LightPositionWindow
(C) 2008-2011 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
@author Enhancements by Michael Barton <michael.barton asu.edu>
@author Anna Kratochvilova <kratochanna gmail.com> (Google SoC 2011)
"""
import os
import sys
import copy
import wx
import wx.lib.colourselect as csel
import wx.lib.scrolledpanel as SP
import wx.lib.filebrowsebutton as filebrowse
try:
import wx.lib.agw.flatnotebook as FN
except ImportError:
import wx.lib.flatnotebook as FN
try:
from agw import foldpanelbar as fpb
except ImportError: # if it's not there locally, try the wxPython lib.
try:
import wx.lib.agw.foldpanelbar as fpb
except ImportError:
import wx.lib.foldpanelbar as fpb # versions <=2.5.5.1
try:
import wx.lib.agw.floatspin as fs
except ImportError:
fs = None
import grass.script as grass
from core import globalvar
from gui_core.gselect import VectorDBInfo
from core.gcmd import GMessage, RunCommand
from modules.colorrules import ThematicVectorTable
from core.settings import UserSettings
from gui_core.widgets import (
ScrolledPanel,
NumTextCtrl,
FloatSlider,
SymbolButton,
GNotebook,
)
from gui_core.gselect import Select
from gui_core.wrap import (
Window,
SpinCtrl,
PseudoDC,
ToggleButton,
Button,
TextCtrl,
Slider,
StaticText,
StaticBox,
CheckListBox,
ColourSelect,
)
from core.debug import Debug
from nviz.mapwindow import (
wxUpdateProperties,
wxUpdateView,
wxUpdateLight,
wxUpdateCPlane,
)
from .wxnviz import DM_FLAT, DM_GOURAUD, MAX_ISOSURFS
class NvizToolWindow(GNotebook):
"""Nviz (3D view) tools panel"""
def __init__(
self,
parent,
tree,
display,
id=wx.ID_ANY,
style=globalvar.FNPageStyle | FN.FNB_NO_X_BUTTON,
**kwargs,
):
Debug.msg(5, "NvizToolWindow.__init__()")
self.parent = parent
self.tree = tree
self.mapDisplay = display
self.mapWindow = display.GetWindow()
self._display = self.mapWindow.GetDisplay()
GNotebook.__init__(self, parent, style=style)
self.win = {} # window ids
self.page = {} # page ids
# view page
self.AddPage(page=self._createViewPage(), text=" %s " % _("View"))
# data page
self.AddPage(page=self._createDataPage(), text=" %s " % _("Data"))
# appearance page
self.AddPage(page=self._createAppearancePage(), text=" %s " % _("Appearance"))
# analysis page
self.AddPage(page=self._createAnalysisPage(), text=" %s " % _("Analysis"))
# view page
self.AddPage(page=self._createAnimationPage(), text=" %s " % _("Animation"))
self.UpdateSettings()
self.mapWindow.SetToolWin(self)
self.pageChanging = False
self.vetoGSelectEvt = False # when setting map, event is invoked
self.mapWindow.render["quick"] = False
self.mapWindow.Refresh(False)
# bindings
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.mapWindow.GetAnimation().animationFinished.connect(
self.OnAnimationFinished
)
self.mapWindow.GetAnimation().animationUpdateIndex.connect(
self.OnAnimationUpdateIndex
)
Debug.msg(3, "NvizToolWindow.__init__()")
self.Update()
wx.CallAfter(self.SetPage, "view")
wx.CallAfter(self.SetInitialMaps)
def SetInitialMaps(self):
"""Set initial raster and vector map"""
for ltype in ("raster", "vector", "raster_3d"):
selectedLayer = self.tree.GetSelectedLayer(multi=False, checkedOnly=True)
if selectedLayer is None:
continue
selectedLayer = self.tree.GetLayerInfo(selectedLayer, key="maplayer")
layers = self.mapWindow.Map.GetListOfLayers(ltype=ltype, active=True)
if selectedLayer in layers:
selection = selectedLayer.GetName()
else:
try:
selection = layers[0].GetName()
except:
continue
if ltype == "raster":
self.FindWindowById(self.win["surface"]["map"]).SetValue(selection)
self.FindWindowById(self.win["fringe"]["map"]).SetValue(selection)
elif ltype == "vector":
self.FindWindowById(self.win["vector"]["map"]).SetValue(selection)
elif ltype == "raster_3d":
self.FindWindowById(self.win["volume"]["map"]).SetValue(selection)
def UpdateState(self, **kwargs):
if "view" in kwargs:
self.mapWindow.view = kwargs["view"]
self.FindWindowById(self.win["view"]["position"]).data = kwargs["view"]
self.FindWindowById(self.win["view"]["position"]).PostDraw()
if "iview" in kwargs:
self.mapWindow.iview = kwargs["iview"]
if "light" in kwargs:
self.mapWindow.light = kwargs["light"]
self.FindWindowById(self.win["light"]["position"]).data = kwargs["light"]
self.FindWindowById(self.win["light"]["position"]).PostDraw()
if "fly" in kwargs:
self.mapWindow.fly["exag"] = kwargs["fly"]["exag"]
def LoadSettings(self):
"""Load Nviz settings and apply to current session"""
view = copy.deepcopy(UserSettings.Get(group="nviz", key="view")) # copy
light = copy.deepcopy(UserSettings.Get(group="nviz", key="light")) # copy
fly = copy.deepcopy(UserSettings.Get(group="nviz", key="fly")) # copy
self.UpdateState(view=view, light=light, fly=fly)
self.PostViewEvent(zExag=True)
self.PostLightEvent()
self.UpdatePage("view")
self.UpdatePage("light")
self.mapWindow.ReloadLayersData()
self.UpdatePage("surface")
self.UpdatePage("vector")
self.UpdateSettings()
def OnPageChanged(self, event):
new = event.GetSelection()
pages = {
# Data page
1: {
"expand": lambda: self._expandFoldPanelBarPanel(
foldPanelBar=self.foldpanelData,
),
"foldPanelBar": self.foldpanelData,
},
# Appearance page
2: {
"expand": lambda: self._expandFoldPanelBarPanel(
foldPanelBar=self.foldpanelAppear,
),
"foldPanelBar": self.foldpanelAppear,
},
# Analysis page
3: {
"expand": lambda: self._expandFoldPanelBarPanel(
foldPanelBar=self.foldpanelAnalysis,
),
"foldPanelBar": self.foldpanelAnalysis,
},
}
if new in pages.keys():
pages[new]["expand"]()
wx.CallAfter(self.UpdateScrolling, (pages[new]["foldPanelBar"],))
def PostViewEvent(self, zExag=False):
"""Change view settings"""
event = wxUpdateView(zExag=zExag)
wx.PostEvent(self.mapWindow, event)
def PostLightEvent(self, refresh=False):
"""Change light settings"""
event = wxUpdateLight(refresh=refresh)
wx.PostEvent(self.mapWindow, event)
def OnSize(self, event):
"""After window is resized, update scrolling"""
# workaround to resize captionbars of foldpanelbar
wx.CallAfter(
self.UpdateScrolling,
(self.foldpanelData, self.foldpanelAppear, self.foldpanelAnalysis),
)
event.Skip()
def OnPressCaption(self, event):
"""When foldpanel item collapsed/expanded, update scrollbars"""
foldpanel = event.GetBar().GetGrandParent().GetParent()
wx.CallAfter(self.UpdateScrolling, (foldpanel,))
event.Skip()
def UpdateScrolling(self, foldpanels):
"""Update scrollbars in foldpanel"""
for foldpanel in foldpanels:
length = foldpanel.GetPanelsLength(collapsed=0, expanded=0)
# Show scrollbars
for panelIdx in range(foldpanel.GetCount()):
# Nested ScrolledPanel widget with horizontal scrollbar
scrolledPanel = (
foldpanel.GetFoldPanel(panelIdx).GetParent().GetGrandParent()
)
width = self.GetSize()[0]
if sys.platform in ("darwin", "win32"):
width -= 60 # 60px right margin to show scrollbar
scrolledPanel.SetVirtualSize(width=width, height=length[2])
scrolledPanel.Layout()
def _expandFoldPanelBarPanel(self, foldPanelBar, expandFoldPanelBarIdx=0):
"""
Expand FoldPanelBar widget panel
Fix expanding FoldPanelBar widget panel (fist panel), because using
AddFoldPanel method with collapsed=True param arg cause the expanding
panel to render incorrectly on wxMAC, wxMSW.
:param obj foldPanelBar: FoldPanelBar widget obj instance
:param int expandFoldpanelbarIdx: FoldPanelBar widget panel index with
default value 0 (first panel)
"""
foldPanelsCount = foldPanelBar.GetCount()
expanded = []
for panelIdx in range(foldPanelsCount):
foldPanel = foldPanelBar.GetFoldPanel(panelIdx)
expanded.append(foldPanel.IsExpanded())
if not any(expanded):
foldPanelBar.Expand(foldPanelBar.GetFoldPanel(expandFoldPanelBarIdx))
def _resizeScrolledPanel(self, foldPanelBar, scrolledPanel, collapsed, expanded):
"""
Resize FoldPanelBar widget ScrolledPanel to show scrollbars
:param obj foldPanelBar: FolPanelBar widget obj instance
:param obj scrolledPanel: ScrolledPanel widget obj instance
:param int collapsed: number of collapsed panels of FoldPanelBar
widget
:param int expanded: number of expanded panels of FoldPanelBar
widget
"""
if expanded > 0:
foldPanelBar.Expand(foldPanelBar.GetFoldPanel(0))
length = foldPanelBar.GetPanelsLength(collapsed, expanded)
scrolledPanel.SetSize(self.GetSize()[0], length[2])
foldPanelBar.Collapse(foldPanelBar.GetFoldPanel(0))
def _createViewPage(self):
"""Create view settings page"""
panel = SP.ScrolledPanel(parent=self, id=wx.ID_ANY)
panel.SetupScrolling()
self.page["view"] = {"id": 0, "notebook": self.GetId()}
pageSizer = wx.BoxSizer(wx.VERTICAL)
box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % (_("Control View")))
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
gridSizer = wx.GridBagSizer(vgap=5, hgap=10)
self.win["view"] = {}
# position
posSizer = wx.GridBagSizer(vgap=3, hgap=3)
self._createCompass(panel=panel, sizer=posSizer, type="view")
view = ViewPositionWindow(panel, size=(175, 175), mapwindow=self.mapWindow)
self.win["view"]["position"] = view.GetId()
posSizer.Add(view, pos=(1, 1), flag=wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
gridSizer.Add(posSizer, pos=(0, 0))
# perspective
# set initial defaults here (or perhaps in a default values file), not in user
# settings
# todo: consider setting an absolute max at 360 instead of undefined.
# (leave the default max value at pi)
tooltip = _(
"Adjusts the distance and angular perspective of the image viewpoint"
)
self._createControl(
panel,
data=self.win["view"],
name="persp",
tooltip=tooltip,
range=(1, 120),
bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedText),
)
gridSizer.Add(
StaticText(panel, id=wx.ID_ANY, label=_("Perspective:")),
pos=(1, 0),
flag=wx.ALIGN_CENTER,
)
gridSizer.Add(
self.FindWindowById(self.win["view"]["persp"]["slider"]),
pos=(2, 0),
flag=wx.ALIGN_CENTER,
)
gridSizer.Add(
self.FindWindowById(self.win["view"]["persp"]["text"]),
pos=(3, 0),
flag=wx.ALIGN_CENTER,
)
# twist
tooltip = _("Tilts the plane of the surface from the horizontal")
self._createControl(
panel,
data=self.win["view"],
name="twist",
tooltip=tooltip,
range=(-180, 180),
bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedText),
)
gridSizer.Add(
StaticText(panel, id=wx.ID_ANY, label=_("Tilt:")),
pos=(1, 1),
flag=wx.ALIGN_CENTER,
)
gridSizer.Add(
self.FindWindowById(self.win["view"]["twist"]["slider"]), pos=(2, 1)
)
gridSizer.Add(
self.FindWindowById(self.win["view"]["twist"]["text"]),
pos=(3, 1),
flag=wx.ALIGN_CENTER,
)
# height + z-exag
tooltip = _(
"Adjusts the viewing height above the surface"
" (angle of view automatically adjusts to maintain the same center of view)"
)
self._createControl(
panel,
data=self.win["view"],
name="height",
sliderHor=False,
tooltip=tooltip,
range=(0, 1),
bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedText),
)
tooltip = _(
"Adjusts the relative height of features above the plane of the surface"
)
self._createControl(
panel,
data=self.win["view"],
name="z-exag",
sliderHor=False,
tooltip=tooltip,
range=(0, 10),
floatSlider=True,
bind=(self.OnViewChange, self.OnViewChanged, self.OnViewChangedText),
)
self.FindWindowById(self.win["view"]["z-exag"]["slider"]).SetValue(1)
self.FindWindowById(self.win["view"]["z-exag"]["text"]).SetValue(1)
heightSizer = wx.GridBagSizer(vgap=3, hgap=3)
heightSizer.Add(
StaticText(panel, id=wx.ID_ANY, label=_("Height:")),
pos=(0, 0),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
span=(1, 2),
)
heightSizer.Add(
self.FindWindowById(self.win["view"]["height"]["slider"]),
flag=wx.ALIGN_RIGHT,
pos=(1, 0),
)
heightSizer.Add(
self.FindWindowById(self.win["view"]["height"]["text"]),
flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
pos=(1, 1),
)
heightSizer.Add(
StaticText(panel, id=wx.ID_ANY, label=_("Z-exag:")),
pos=(0, 2),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
span=(1, 2),
)
heightSizer.Add(
self.FindWindowById(self.win["view"]["z-exag"]["slider"]),
flag=wx.ALIGN_RIGHT,
pos=(1, 2),
)
heightSizer.Add(
self.FindWindowById(self.win["view"]["z-exag"]["text"]),
flag=wx.ALIGN_CENTER_VERTICAL
| wx.ALIGN_LEFT
| wx.TOP
| wx.BOTTOM
| wx.RIGHT,
pos=(1, 3),
)
gridSizer.Add(heightSizer, pos=(0, 1), flag=wx.ALIGN_CENTER)
# view setup + reset
viewSizer = wx.BoxSizer(wx.HORIZONTAL)
viewSizer.Add(
StaticText(panel, id=wx.ID_ANY, label=_("Look:")),
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
border=5,
)
here = ToggleButton(panel, id=wx.ID_ANY, label=_("here"))
here.Bind(wx.EVT_TOGGLEBUTTON, self.OnLookAt)
here.SetName("here")
here.SetToolTip(
_(
"Allows you to select a point on the surface "
"that becomes the new center of view. "
"Click on the button and then on the surface."
)
)
viewSizer.Add(
here, flag=wx.TOP | wx.BOTTOM | wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=5
)
center = Button(panel, id=wx.ID_ANY, label=_("center"))
center.Bind(wx.EVT_BUTTON, self.OnLookAt)
center.SetName("center")
center.SetToolTip(_("Resets the view to the original default center of view"))
viewSizer.Add(
center, flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, border=5
)
top = Button(panel, id=wx.ID_ANY, label=_("top"))
top.Bind(wx.EVT_BUTTON, self.OnLookAt)
top.SetName("top")
top.SetToolTip(
_(
"Sets the viewer directly over the scene's center position. This top "
"view orients approximately north south."
)
)
viewSizer.Add(top, flag=wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL, border=5)
reset = Button(panel, id=wx.ID_ANY, label=_("reset"))
reset.SetToolTip(_("Reset to default view"))
reset.Bind(wx.EVT_BUTTON, self.OnResetView)
viewSizer.Add(reset, proportion=0, flag=wx.TOP | wx.BOTTOM | wx.RIGHT, border=5)
gridSizer.Add(viewSizer, pos=(4, 0), span=(1, 3), flag=wx.EXPAND)
# body
boxSizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=2)
pageSizer.Add(boxSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=3)
box = StaticBox(
parent=panel, id=wx.ID_ANY, label=" %s " % (_("Image Appearance"))
)
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
# background color
self.win["view"]["background"] = {}
gridSizer.Add(
StaticText(parent=panel, id=wx.ID_ANY, label=_("Background color:")),
pos=(0, 0),
flag=wx.ALIGN_CENTER_VERTICAL,
)
color = csel.ColourSelect(
panel,
id=wx.ID_ANY,
colour=UserSettings.Get(
group="nviz", key="view", subkey=["background", "color"]
),
size=globalvar.DIALOG_COLOR_SIZE,
)
self.win["view"]["background"]["color"] = color.GetId()
color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
gridSizer.Add(color, pos=(0, 1))
gridSizer.AddGrowableCol(0)
boxSizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=3)
pageSizer.Add(
boxSizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=3
)
panel.SetSizer(pageSizer)
return panel
def _createAnimationPage(self):
"""Create view settings page"""
panel = SP.ScrolledPanel(parent=self, id=wx.ID_ANY)
panel.SetupScrolling()
self.page["animation"] = {"id": 0, "notebook": self.GetId()}
pageSizer = wx.BoxSizer(wx.VERTICAL)
box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % (_("Animation")))
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
hSizer = wx.BoxSizer(wx.HORIZONTAL)
self.win["anim"] = {}
# animation help text
help = StaticText(
parent=panel,
id=wx.ID_ANY,
label=_(
"Press 'Record' button and start changing the view. "
"It is recommended to use fly-through mode "
"(Map Display toolbar) to achieve smooth motion."
),
)
self.win["anim"]["help"] = help.GetId()
hSizer.Add(help, proportion=0)
boxSizer.Add(hSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
# animation controls
hSizer = wx.BoxSizer(wx.HORIZONTAL)
record = SymbolButton(
parent=panel, id=wx.ID_ANY, usage="record", label=_("Record")
)
play = SymbolButton(parent=panel, id=wx.ID_ANY, usage="play", label=_("Play"))
pause = SymbolButton(
parent=panel, id=wx.ID_ANY, usage="pause", label=_("Pause")
)
stop = SymbolButton(parent=panel, id=wx.ID_ANY, usage="stop", label=_("Stop"))
self.win["anim"]["record"] = record.GetId()
self.win["anim"]["play"] = play.GetId()
self.win["anim"]["pause"] = pause.GetId()
self.win["anim"]["stop"] = stop.GetId()
self._createControl(
panel,
data=self.win["anim"],
name="frameIndex",
range=(0, 1),
floatSlider=False,
bind=(self.OnFrameIndex, None, self.OnFrameIndexText),
)
frameSlider = self.FindWindowById(self.win["anim"]["frameIndex"]["slider"])
frameText = self.FindWindowById(self.win["anim"]["frameIndex"]["text"])
infoLabel = StaticText(
parent=panel, id=wx.ID_ANY, label=_("Total number of frames :")
)
info = StaticText(parent=panel, id=wx.ID_ANY)
self.win["anim"]["info"] = info.GetId()
fpsLabel = StaticText(parent=panel, id=wx.ID_ANY, label=_("Frame rate (FPS):"))
fps = SpinCtrl(
parent=panel,
id=wx.ID_ANY,
size=(65, -1),
initial=UserSettings.Get(group="nviz", key="animation", subkey="fps"),
min=1,
max=50,
)
self.win["anim"]["fps"] = fps.GetId()
fps.SetToolTip(_("Frames are recorded with given frequency (FPS). "))
record.Bind(wx.EVT_BUTTON, self.OnRecord)
play.Bind(wx.EVT_BUTTON, self.OnPlay)
stop.Bind(wx.EVT_BUTTON, self.OnStop)
pause.Bind(wx.EVT_BUTTON, self.OnPause)
fps.Bind(wx.EVT_SPINCTRL, self.OnFPS)
hSizer.Add(record, proportion=0)
hSizer.Add(play, proportion=0)
hSizer.Add(pause, proportion=0)
hSizer.Add(stop, proportion=0)
boxSizer.Add(hSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
sliderBox = wx.BoxSizer(wx.HORIZONTAL)
sliderBox.Add(frameSlider, proportion=1, border=5, flag=wx.EXPAND | wx.RIGHT)
sliderBox.Add(
frameText, proportion=0, border=5, flag=wx.EXPAND | wx.RIGHT | wx.LEFT
)
boxSizer.Add(sliderBox, proportion=0, flag=wx.EXPAND)
# total number of frames
hSizer = wx.BoxSizer(wx.HORIZONTAL)
hSizer.Add(infoLabel, proportion=0, flag=wx.RIGHT, border=5)
hSizer.Add(info, proportion=0, flag=wx.LEFT, border=5)
boxSizer.Add(hSizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
# frames per second
hSizer = wx.BoxSizer(wx.HORIZONTAL)
hSizer.Add(
fpsLabel, proportion=0, flag=wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=5
)
hSizer.Add(fps, proportion=0, flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=5)
boxSizer.Add(
hSizer,
proportion=0,
flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
border=5,
)
pageSizer.Add(
boxSizer,
proportion=0,
flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border=3,
)
# save animation
self.win["anim"]["save"] = {}
self.win["anim"]["save"]["image"] = {}
box = StaticBox(
parent=panel, id=wx.ID_ANY, label=" %s " % (_("Save image sequence"))
)
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
vSizer = wx.BoxSizer(wx.VERTICAL)
gridSizer = wx.GridBagSizer(vgap=5, hgap=10)
pwd = os.getcwd()
dir = filebrowse.DirBrowseButton(
parent=panel,
id=wx.ID_ANY,
labelText=_("Choose a directory:"),
dialogTitle=_("Choose a directory for images"),
buttonText=_("Browse"),
startDirectory=pwd,
)
dir.SetValue(pwd)
prefixLabel = StaticText(parent=panel, id=wx.ID_ANY, label=_("File prefix:"))
prefixCtrl = TextCtrl(
parent=panel,
id=wx.ID_ANY,
size=(100, -1),
value=UserSettings.Get(group="nviz", key="animation", subkey="prefix"),
)
prefixCtrl.SetToolTip(
_(
"Generated files names will look like this: prefix_1.ppm, "
"prefix_2.ppm, ..."
)
)
fileTypeLabel = StaticText(parent=panel, id=wx.ID_ANY, label=_("File format:"))
fileTypeCtrl = wx.Choice(parent=panel, id=wx.ID_ANY, choices=["TIF", "PPM"])
save = Button(parent=panel, id=wx.ID_ANY, label="Save")
self.win["anim"]["save"]["image"]["dir"] = dir.GetId()
self.win["anim"]["save"]["image"]["prefix"] = prefixCtrl.GetId()
self.win["anim"]["save"]["image"]["format"] = fileTypeCtrl.GetId()
self.win["anim"]["save"]["image"]["confirm"] = save.GetId()
boxSizer.Add(dir, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
gridSizer.Add(
prefixLabel, pos=(0, 0), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
)
gridSizer.Add(prefixCtrl, pos=(0, 1), flag=wx.EXPAND)
gridSizer.Add(
fileTypeLabel, pos=(1, 0), flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
)
gridSizer.Add(fileTypeCtrl, pos=(1, 1), flag=wx.EXPAND)
boxSizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
boxSizer.Add(save, proportion=0, flag=wx.ALL | wx.ALIGN_RIGHT, border=5)
save.Bind(wx.EVT_BUTTON, self.OnSaveAnimation)
pageSizer.Add(
boxSizer,
proportion=0,
flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border=3,
)
panel.SetSizer(pageSizer)
return panel
def _createDataPage(self):
"""Create data (surface, vector, volume) settings page"""
self.mainPanelData = SP.ScrolledPanel(parent=self)
self.mainPanelData.SetupScrolling(scroll_x=False)
self.mainPanelData.AlwaysShowScrollbars(hflag=False)
try: # wxpython <= 2.8.10
self.foldpanelData = fpb.FoldPanelBar(
parent=self.mainPanelData,
id=wx.ID_ANY,
style=fpb.FPB_DEFAULT_STYLE,
extraStyle=fpb.FPB_SINGLE_FOLD,
)
except:
try: # wxpython >= 2.8.11
self.foldpanelData = fpb.FoldPanelBar(
parent=self.mainPanelData,
id=wx.ID_ANY,
agwStyle=fpb.FPB_SINGLE_FOLD,
)
except: # to be sure
self.foldpanelData = fpb.FoldPanelBar(
parent=self.mainPanelData, id=wx.ID_ANY, style=fpb.FPB_SINGLE_FOLD
)
self.foldpanelData.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
# # surface page
surfacePanel = self.foldpanelData.AddFoldPanel(_("Surface"), collapsed=True)
self.foldpanelData.AddFoldPanelWindow(
surfacePanel,
window=self._createSurfacePage(parent=surfacePanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
self.EnablePage("surface", enabled=False)
# constant page
constantPanel = self.foldpanelData.AddFoldPanel(
_("Constant surface"), collapsed=True
)
self.foldpanelData.AddFoldPanelWindow(
constantPanel,
window=self._createConstantPage(parent=constantPanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
self.EnablePage("constant", enabled=False)
# vector page
vectorPanel = self.foldpanelData.AddFoldPanel(_("Vector"), collapsed=True)
self.foldpanelData.AddFoldPanelWindow(
vectorPanel,
window=self._createVectorPage(parent=vectorPanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
self.EnablePage("vector", enabled=False)
# volume page
volumePanel = self.foldpanelData.AddFoldPanel(_("3D raster"), collapsed=True)
self.foldpanelData.AddFoldPanelWindow(
volumePanel,
window=self._createVolumePage(parent=volumePanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
self.EnablePage("volume", enabled=False)
# self.foldpanelData.ApplyCaptionStyleAll(style)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.foldpanelData, proportion=1, flag=wx.EXPAND)
self.mainPanelData.SetSizer(sizer)
self.mainPanelData.Layout()
self.mainPanelData.Fit()
self._resizeScrolledPanel(
foldPanelBar=self.foldpanelData,
scrolledPanel=self.mainPanelData,
collapsed=self.foldpanelData.GetCount() - 1,
expanded=1,
)
return self.mainPanelData
def _createAppearancePage(self):
"""Create data (surface, vector, volume) settings page"""
self.mainPanelAppear = SP.ScrolledPanel(parent=self)
self.mainPanelAppear.SetupScrolling(scroll_x=False)
self.mainPanelAppear.AlwaysShowScrollbars(hflag=False)
try: # wxpython <= 2.8.10
self.foldpanelAppear = fpb.FoldPanelBar(
parent=self.mainPanelAppear,
id=wx.ID_ANY,
style=fpb.FPB_DEFAULT_STYLE,
extraStyle=fpb.FPB_SINGLE_FOLD,
)
except:
try: # wxpython >= 2.8.11
self.foldpanelAppear = fpb.FoldPanelBar(
parent=self.mainPanelAppear,
id=wx.ID_ANY,
agwStyle=fpb.FPB_SINGLE_FOLD,
)
except: # to be sure
self.foldpanelAppear = fpb.FoldPanelBar(
parent=self.mainPanelAppear, id=wx.ID_ANY, style=fpb.FPB_SINGLE_FOLD
)
self.foldpanelAppear.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
# light page
lightPanel = self.foldpanelAppear.AddFoldPanel(_("Lighting"), collapsed=True)
self.foldpanelAppear.AddFoldPanelWindow(
lightPanel,
window=self._createLightPage(parent=lightPanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
# fringe page
fringePanel = self.foldpanelAppear.AddFoldPanel(_("Fringe"), collapsed=True)
self.foldpanelAppear.AddFoldPanelWindow(
fringePanel,
window=self._createFringePage(parent=fringePanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
self.EnablePage("fringe", False)
# decoration page
decorationPanel = self.foldpanelAppear.AddFoldPanel(
_("Decorations"), collapsed=True
)
self.foldpanelAppear.AddFoldPanelWindow(
decorationPanel,
window=self._createDecorationPage(parent=decorationPanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.foldpanelAppear, proportion=1, flag=wx.EXPAND)
self.mainPanelAppear.SetSizer(sizer)
self.mainPanelAppear.Layout()
self.mainPanelAppear.Fit()
self._resizeScrolledPanel(
foldPanelBar=self.foldpanelAppear,
scrolledPanel=self.mainPanelAppear,
collapsed=self.foldpanelAppear.GetCount() - 1,
expanded=1,
)
return self.mainPanelAppear
def _createAnalysisPage(self):
"""Create data analysis (cutting planes, ...) page"""
self.mainPanelAnalysis = SP.ScrolledPanel(parent=self)
self.mainPanelAnalysis.SetupScrolling(scroll_x=False)
self.mainPanelAnalysis.AlwaysShowScrollbars(hflag=False)
self.foldpanelAnalysis = fpb.FoldPanelBar(
parent=self.mainPanelAnalysis, id=wx.ID_ANY, style=fpb.FPB_SINGLE_FOLD
)
self.foldpanelAnalysis.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
# cutting planes page
cplanePanel = self.foldpanelAnalysis.AddFoldPanel(
_("Cutting planes"), collapsed=True
)
self.foldpanelAnalysis.AddFoldPanelWindow(
cplanePanel,
window=self._createCPlanePage(parent=cplanePanel),
flags=fpb.FPB_ALIGN_WIDTH,
)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.foldpanelAnalysis, proportion=1, flag=wx.EXPAND)
self.mainPanelAnalysis.SetSizer(sizer)
self.mainPanelAnalysis.Layout()
self.mainPanelAnalysis.Fit()
self._resizeScrolledPanel(
foldPanelBar=self.foldpanelAnalysis,
scrolledPanel=self.mainPanelAnalysis,
collapsed=self.foldpanelAnalysis.GetCount() - 1,
expanded=1,
)
return self.mainPanelAnalysis
def _createSurfacePage(self, parent):
"""Create view settings page"""
panel = ScrolledPanel(parent=parent)
self.page["surface"] = {"id": 0, "notebook": self.foldpanelData.GetId()}
pageSizer = wx.BoxSizer(wx.VERTICAL)
self.win["surface"] = {}
# selection
box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % (_("Raster map")))
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
rmaps = Select(parent=panel, type="raster", onPopup=self.GselectOnPopup)
rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
self.win["surface"]["map"] = rmaps.GetId()
desc = StaticText(parent=panel, id=wx.ID_ANY)
self.win["surface"]["desc"] = desc.GetId()
boxSizer.Add(rmaps, proportion=0, flag=wx.ALL, border=3)
boxSizer.Add(desc, proportion=0, flag=wx.ALL, border=3)
pageSizer.Add(
boxSizer,
proportion=0,
flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border=3,
)
#
# draw
#
self.win["surface"]["draw"] = {}
box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s " % (_("Draw")))
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
gridSizer = wx.GridBagSizer(vgap=3, hgap=3)
# mode
gridSizer.Add(
StaticText(parent=panel, id=wx.ID_ANY, label=_("Mode:")),
pos=(0, 0),
flag=wx.ALIGN_CENTER_VERTICAL,
)
mode = wx.Choice(
parent=panel,
id=wx.ID_ANY,
size=(-1, -1),
choices=[_("coarse"), _("fine"), _("both")],
)
mode.SetName("selection")
mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
self.win["surface"]["draw"]["mode"] = mode.GetId()
gridSizer.Add(
mode, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos=(0, 1), span=(1, 2)
)
# shading
gridSizer.Add(
StaticText(parent=panel, id=wx.ID_ANY, label=_("Shading:")),
pos=(0, 3),
flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT,
)
shade = wx.Choice(
parent=panel, id=wx.ID_ANY, size=(-1, -1), choices=[_("flat"), _("gouraud")]
)
shade.SetName("selection")
self.win["surface"]["draw"]["shading"] = shade.GetId()
shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
gridSizer.Add(shade, flag=wx.ALIGN_CENTER_VERTICAL, pos=(0, 4))
# set to all
all = Button(panel, id=wx.ID_ANY, label=_("Set to all"))
all.SetToolTip(_("Use draw settings for all loaded surfaces"))
all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
gridSizer.Add(
all, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos=(3, 4)
)
self.win["surface"]["all"] = all.GetId()
# resolution coarse
gridSizer.Add(
StaticText(parent=panel, id=wx.ID_ANY, label=_("Coarse mode:")),
pos=(2, 0),
flag=wx.ALIGN_CENTER_VERTICAL,
)
gridSizer.Add(
StaticText(parent=panel, id=wx.ID_ANY, label=_("resolution:")),
pos=(2, 1),
flag=wx.ALIGN_CENTER_VERTICAL,
)
resC = SpinCtrl(
parent=panel, id=wx.ID_ANY, size=(65, -1), initial=6, min=1, max=100