-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCheck model.lua
More file actions
93 lines (83 loc) · 2.44 KB
/
Copy pathCheck model.lua
File metadata and controls
93 lines (83 loc) · 2.44 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
local sim = require 'sim'
local simUI
function sysCall_info()
return {autoStart = false, menu = 'Developer tools\nCheck selected model'}
end
function sysCall_init()
simUI = require 'simUI'
showGraph = simUI.getKeyboardModifiers().shift
local sel = sim.getObjectSel()
if #sel == 0 or #sel > 1 then
sim.addLog(sim.verbosity_scripterrors, "This add-on requires one object to be selected.")
return {cmd = 'cleanup'}
end
step = 0
if sim.getSimulationState() == sim.simulation_stopped then
stop = true
sim.startSimulation()
end
end
function sysCall_sensing()
step = step + 1
if step > 1 then
check()
if stop then
sim.stopSimulation()
end
end
if leaveNow then return {cmd = 'cleanup'} end
end
function sysCall_nonSimulation()
if leaveNow then return {cmd = 'cleanup'} end
end
function sysCall_suspended()
check()
if leaveNow then return {cmd = 'cleanup'} end
end
function check()
sim.addLog(sim.verbosity_scriptwarnings, "Checking...")
local checkmodel = require 'checkmodel'
local sel = sim.getObjectSel()
assert(#sel == 1)
if showGraph then
local g = checkmodel.buildObjectsGraph(sel[1])
checkmodel.showObjectsGraph(g)
end
check = function() end
local issues = checkmodel.check(sel[1])
showReport(issues)
end
function showReport(issues)
if next(issues) == nil then
simUI.msgBox(
simUI.msgbox_type.info, simUI.msgbox_buttons.ok, 'Check Model - Results',
'No issues were found.'
)
return
end
local items = {}
for handle, issues in pairs(issues) do
local itemText = '<h4>Object ' .. sim.getObjectAlias(handle, 9) .. ' (handle: ' .. handle .. ')</h4>'
itemText = itemText .. '<ul>'
for _, issue in ipairs(issues) do
itemText = itemText .. '<li>' .. issue .. '</li>'
end
itemText = itemText .. '</ul>'
table.insert(items, itemText)
end
simUI.create([[
<ui
title="Check Model - Results"
resizable="true"
closeable="true"
placement="center"
modal="true"
size="600,400"
on-close="closed">
<text-browser text="]] .. string.escapehtml(table.concat(items, '')) .. [["></text-browser>
</ui>
]])
end
function closed()
leaveNow = true
end