-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexport.py
209 lines (195 loc) · 8.21 KB
/
export.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
# -*- coding: utf-8 -*-
"""
@brief GUI panel for export functionality
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@author: Anna Petrasova ([email protected])
"""
import os
import wx
import wx.lib.filebrowsebutton as filebrowse
from gui_core.gselect import Select
from grass.pydispatch.signal import Signal
from tangible_utils import get_show_layer_icon
class OutputPanel(wx.Panel):
def __init__(self, parent, giface, settings):
wx.Panel.__init__(self, parent)
self.giface = giface
self.settings = settings
self.settingsChanged = Signal("OutputPanel.settingsChanged")
if "output" not in self.settings:
self.settings["output"] = {}
self.settings["output"]["scan"] = "scan"
self.settings["output"]["calibration_scan"] = "scan_saved"
self.settings["output"]["calibrate"] = False
self.settings["output"]["PLY"] = False
self.settings["output"]["PLY_file"] = ""
self.settings["output"]["color"] = False
self.settings["output"]["color_name"] = ""
self.settings["output"]["blender"] = False
self.settings["output"]["blender_path"] = ""
if self.settings["output"]["PLY_file"]:
initDir = os.path.dirname(self.settings["output"]["PLY_file"])
else:
initDir = ""
# added later, must be checked explicitly
if "calibration_scan" not in self.settings["output"]:
self.settings["output"]["calibration_scan"] = "scan_saved"
self.settings["output"]["calibrate"] = False
# scan
self.scan_name = wx.TextCtrl(self)
self.scan_name.SetValue(self.settings["output"]["scan"])
self.scan_name.Bind(wx.EVT_TEXT, self.OnChange)
bmp = get_show_layer_icon()
addScan = wx.BitmapButton(
self, bitmap=bmp, size=(bmp.GetWidth() + 12, bmp.GetHeight() + 8)
)
addScan.Bind(wx.EVT_BUTTON, lambda evt: self._addLayer("scan"))
self.calib_scan_name = wx.TextCtrl(self)
self.calib_scan_name.SetValue(self.settings["output"]["calibration_scan"])
self.calib_scan_name.Bind(wx.EVT_TEXT, self.OnChange)
bmp = get_show_layer_icon()
addCScan = wx.BitmapButton(
self, bitmap=bmp, size=(bmp.GetWidth() + 12, bmp.GetHeight() + 8)
)
addCScan.Bind(wx.EVT_BUTTON, lambda evt: self._addLayer("calib"))
# color
self.ifColor = wx.CheckBox(
self, label=_("Save color rasters (with postfixes _r, _g, _b):")
)
self.ifColor.SetValue(self.settings["output"]["color"])
self.ifColor.Bind(wx.EVT_CHECKBOX, self.OnChange)
self.exportColor = Select(self, size=(-1, -1), type="raster")
self.exportColor.SetValue(self.settings["output"]["color_name"])
self.exportColor.Bind(wx.EVT_TEXT, self.OnChange)
bmp = get_show_layer_icon()
self.addColor = wx.BitmapButton(
self, bitmap=bmp, size=(bmp.GetWidth() + 12, bmp.GetHeight() + 8)
)
self.addColor.Bind(wx.EVT_BUTTON, lambda evt: self._addLayer("color"))
# Blender
self.ifBlender = wx.CheckBox(self, label="")
self.ifBlender.SetValue(self.settings["output"]["blender"])
self.ifBlender.Bind(wx.EVT_CHECKBOX, self.OnChange)
initDirBlender = ""
if self.settings["output"]["blender_path"]:
initDirBlender = self.settings["output"]["blender_path"]
self.blenderPath = filebrowse.DirBrowseButton(
self,
labelText="Export folder for Blender coupling:",
startDirectory=initDirBlender,
newDirectory=True,
changeCallback=self.OnChange,
)
# PLY
self.ifPLY = wx.CheckBox(self, label="")
self.ifPLY.SetValue(self.settings["output"]["PLY"])
self.ifPLY.Bind(wx.EVT_CHECKBOX, self.OnChange)
self.exportPLY = filebrowse.FileBrowseButton(
self,
labelText="Export PLY:",
fileMode=wx.FD_SAVE,
startDirectory=initDir,
initialValue=self.settings["output"]["PLY_file"],
changeCallback=self.OnChange,
)
# must be called after all widgets are created
self.blenderPath.SetValue(initDirBlender)
mainSizer = wx.BoxSizer(wx.VERTICAL)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(
wx.StaticText(self, label="Name of scanned raster:"),
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
border=5,
)
sizer.Add(self.scan_name, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
sizer.Add(
addScan,
proportion=0,
flag=wx.EXPAND | wx.RIGHT | wx.TOP | wx.BOTTOM,
border=5,
)
mainSizer.Add(sizer, flag=wx.EXPAND | wx.ALL, border=5)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(
wx.StaticText(self, label="Name of calibration scan raster:"),
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
border=5,
)
sizer.Add(self.calib_scan_name, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
sizer.Add(
addCScan,
proportion=0,
flag=wx.EXPAND | wx.RIGHT | wx.TOP | wx.BOTTOM,
border=5,
)
mainSizer.Add(sizer, flag=wx.EXPAND | wx.ALL, border=5)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.ifColor, flag=wx.ALIGN_CENTER_VERTICAL, border=5)
sizer.Add(
self.exportColor, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL, border=5
)
sizer.Add(self.addColor, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
mainSizer.Add(sizer, flag=wx.EXPAND | wx.ALL, border=5)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(
self.ifBlender, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3
)
sizer.Add(
self.blenderPath,
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
proportion=1,
border=0,
)
mainSizer.Add(sizer, flag=wx.EXPAND | wx.ALL, border=5)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(
self.ifPLY, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=3
)
sizer.Add(
self.exportPLY,
flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
proportion=1,
border=0,
)
mainSizer.Add(sizer, flag=wx.EXPAND | wx.ALL, border=5)
self.SetSizer(mainSizer)
mainSizer.Fit(self)
def OnChange(self, event):
self.settings["output"]["scan"] = self.scan_name.GetValue()
self.settings["output"]["calibration_scan"] = self.calib_scan_name.GetValue()
self.settings["output"]["color"] = self.ifColor.IsChecked()
self.settings["output"]["color_name"] = self.exportColor.GetValue()
self.settings["output"]["blender"] = self.ifBlender.IsChecked()
self.settings["output"]["blender_path"] = self.blenderPath.GetValue()
self.settings["output"]["PLY"] = self.ifPLY.IsChecked()
self.settings["output"]["PLY_file"] = self.exportPLY.GetValue()
self.settingsChanged.emit()
def _addLayer(self, ltype):
if not self.giface.GetLayerTree():
return
ll = self.giface.GetLayerList()
if ltype == "scan":
raster = self.scan_name.GetValue()
if not raster:
return
cmd = ["d.rast", "map=" + raster]
ll.AddLayer("raster", name=raster, checked=True, cmd=cmd)
elif ltype == "calib":
raster = self.calib_scan_name.GetValue()
if not raster:
return
cmd = ["d.rast", "map=" + raster]
ll.AddLayer("raster", name=raster, checked=True, cmd=cmd)
elif ltype == "color":
name = self.exportColor.GetValue()
if not name:
return
cmd = [
"d.rgb",
"red={m}".format(m=name + "_r"),
"green={m}".format(m=name + "_g"),
"blue={m}".format(m=name + "_b"),
"-n",
]
ll.AddLayer("rgb", name=name, checked=True, cmd=cmd)