Skip to content

Commit ca2de86

Browse files
committed
simUI.fileDialog fix
1 parent 5d6dc6b commit ca2de86

6 files changed

+28
-30
lines changed

Events capture.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ function export()
4040
local scenePath = sim.getStringParameter(sim.stringparam_scene_path)
4141
local sceneName = sim.getStringParameter(sim.stringparam_scene_name):match("(.+)%..+")
4242
if sceneName == nil then sceneName = 'untitled' end
43-
local fileName = simUI.fileDialog(
43+
local fileNames = simUI.fileDialog(
4444
simUI.filedialog_type.save, 'Export events dump...', scenePath,
4545
sceneName .. '.cbor', 'CBOR file', 'cbor'
4646
)
47-
if fileName == nil then return end
47+
if #fileNames == 0 then return end
48+
local fileName = fileNames[1]
4849
local file = io.open(fileName, 'w')
4950
data = data .. string.char(255)
5051
file:write(data)

Events dump exporter.lua

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ function export()
1919
local scenePath = sim.getStringParameter(sim.stringparam_scene_path)
2020
local sceneName = sim.getStringParameter(sim.stringparam_scene_name):match("(.+)%..+")
2121
if sceneName == nil then sceneName = 'untitled' end
22-
local fileName = simUI.fileDialog(
22+
local fileNames = simUI.fileDialog(
2323
simUI.filedialog_type.save, 'Export events dump...', scenePath,
2424
sceneName .. '.cbor', 'CBOR file', 'cbor'
2525
)
26-
if fileName == nil then return end
26+
if #fileNames == 0 then return end
27+
local fileName = fileNames[1]
2728
local data = sim.getGenesisEvents()
2829
local file = io.open(fileName, 'w')
2930
file:write(data)
3031
file:close()
31-
sim.addLog(
32-
sim.verbosity_infos + sim.verbosity_undecorated, 'Exported events dump to ' .. fileName
33-
)
32+
sim.addLog(sim.verbosity_infos + sim.verbosity_undecorated, 'Exported events dump to ' .. fileName)
3433
end

Floor plan importer.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function sysCall_init()
6161
end
6262
path = sim.getStringParam(sim.stringparam_scene_path)
6363
fmts, fmtss = simUI.supportedImageFormats(';')
64-
imageFile = simUI.fileDialog(
64+
imageFiles = simUI.fileDialog(
6565
simUI.filedialog_type.load, 'Open image...', path, '', 'Image files', fmtss
6666
)
6767
addCuboid = function(classTbl, x1, y1, x2, y2)
@@ -118,7 +118,7 @@ function sysCall_init()
118118
optimizationEnabled = simUI.getCheckboxValue(ui, 901) > 0
119119
invertImageValues = simUI.getCheckboxValue(ui, 902) > 0
120120
respondable = simUI.getCheckboxValue(ui, 911) > 0
121-
im, res = sim.loadImage(0, imageFile)
121+
im, res = sim.loadImage(0, imageFiles)
122122
c = {res[1] / 2, res[2] / 2}
123123
im = sim.transformBuffer(im, sim.buffer_uint8rgb, 1, 0, sim.buffer_uint8)
124124
im = sim.unpackUInt8Table(im)
@@ -177,7 +177,7 @@ function sysCall_init()
177177
ui = nil
178178
leaveNow = true
179179
end
180-
if imageFile then
180+
if #imageFiles > 0 then
181181
ui = simUI.create(
182182
[[<ui title="Import floorplan..." closeable="true" on-close="closeUi" resizable="true" modal="true" layout="vbox">
183183
<group layout="form">

Point cloud importer.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ function sysCall_init()
1616
end
1717

1818
function importClicked_callback()
19-
local files = simUI.fileDialog(
19+
local fileNames = simUI.fileDialog(
2020
simUI.filedialog_type.load_multiple, '*.xyz point cloud import', '', '', '*.xyz',
2121
'xyz'
2222
)
23-
if files then
23+
if #fileNames > 0 then
2424
local pc = sim.createPointCloud(0.02, 20, 0, size)
25-
for token in (files .. ";"):gmatch("([^;]*);") do
25+
for _, fileName in ipairs(fileNames) do
2626
local pts = {}
2727
local cols = {}
28-
for line in io.lines(token) do
28+
for line in io.lines(fileName) do
2929
local c = 0
3030
for coord in line:gmatch("([^\9 ]+)") do
3131
if c >= 3 then

Screenshot tool.lua

+11-13
Original file line numberDiff line numberDiff line change
@@ -317,29 +317,27 @@ end
317317
function save_callback(ui, id, v)
318318
local options = 0
319319
if config.transparent then options = 1 end
320-
local filenameAndPath
320+
local fileNames
321321
if config.fileDlg then
322-
filenameAndPath = simUI.fileDialog(
322+
fileNames = simUI.fileDialog(
323323
simUI.filedialog_type.save, 'title', '', 'screenshot.png', 'image file',
324324
'*'
325325
)
326326
else
327-
local theOs = sim.getInt32Param(sim.intparam_platform)
328-
if theOs == 1 then
327+
local fileName = 'coppeliaSim_screenshot_' .. os.date("%Y_%m_%d-%H_%M_%S", os.time()) .. '.png'
328+
if sim.getInt32Param(sim.intparam_platform) == 1 then
329329
-- MacOS, special: executable is inside of a bundle:
330-
filenameAndPath = '../../../coppeliaSim_screenshot_' ..
331-
os.date("%Y_%m_%d-%H_%M_%S", os.time()) .. '.png'
332-
else
333-
filenameAndPath =
334-
'coppeliaSim_screenshot_' .. os.date("%Y_%m_%d-%H_%M_%S", os.time()) .. '.png'
330+
fileName = '../../../' .. fileName
335331
end
332+
fileNames = {fileName}
336333
end
337-
if filenameAndPath then
338-
if sim.saveImage(image, {resX, resY}, options, filenameAndPath, -1) ~= -1 then
339-
sim.addLog(sim.verbosity_msgs, "Screenshot was saved to " .. filenameAndPath)
334+
if #fileNames > 0 then
335+
local fileName = fileNames[1]
336+
if sim.saveImage(image, {resX, resY}, options, fileName, -1) ~= -1 then
337+
sim.addLog(sim.verbosity_msgs, "Screenshot was saved to " .. fileName)
340338
simUI.msgBox(
341339
simUI.msgbox_type.info, simUI.msgbox_buttons.ok, 'Screenshot',
342-
"Screenshot was saved to " .. filenameAndPath
340+
"Screenshot was saved to " .. fileName
343341
)
344342
else
345343
sim.addLog(

Video recorder.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ function onUiClose()
6161
end
6262

6363
function browse()
64-
local r = simUI.fileDialog(
64+
local fileNames = simUI.fileDialog(
6565
simUI.filedialog_type.folder, 'Select output directory', outputDir, '', '', '',
6666
true
6767
)
68-
if r[1] == '' then return end
69-
outputDir = r[1]
68+
if #fileNames == 0 then return end
69+
outputDir = fileNames[1]
7070
updateUi()
7171
end
7272

0 commit comments

Comments
 (0)