Skip to content

Commit 3c8f3c1

Browse files
authored
Merge pull request #501 from JuliaRobotics/maint/2Q20/refactorprintfct
consolidate printFactor, bugfix
2 parents d0a17e4 + 2d289eb commit 3c8f3c1

File tree

3 files changed

+50
-48
lines changed

3 files changed

+50
-48
lines changed

src/services/CustomPrinting.jl

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,3 @@
1-
##==============================================================================
2-
## Overloading show
3-
##==============================================================================
4-
# Base.show_default(io, v)
5-
Base.show(io::IO, ::MIME"text/plain", v::DFGVariable) = show(IOContext(io, :limit=>true, :compact=>true), v)
6-
7-
function Base.show(io::IO, ::MIME"text/plain", f::DFGFactor)
8-
# show(IOContext(io, :limit=>true, :compact=>true), f)
9-
fctt = getFactorType(f)
10-
println(io, "$(typeof(f))")
11-
println(io, " Name: $(f.label)")
12-
println(io, " VariableOrder: $(getVariableOrder(f))")
13-
println(io, " multihypo: $(getSolverData(f).multihypo)") # FIXME #477
14-
println(io, " nullhypo: TBD")
15-
println(io, " solvable: $(f.solvable)")
16-
println(io, " timestamp: $(f.timestamp)")
17-
println(io, " nstime: $(f.nstime)")
18-
println(io, " tags: $(f.tags)")
19-
println(io, " Type: $(typeof(fctt))")
20-
println(io, " Fields: $(fieldnames(typeof(fctt)))")
21-
show(IOContext(io, :limit=>true, :compact=>true), fctt)
22-
end
23-
24-
function Base.show(io::IO, ::MIME"text/plain", dfg::AbstractDFG)
25-
summary(io, dfg)
26-
println(io, "\n UserId: ", dfg.userId)
27-
println(io, " RobotId: ", dfg.robotId)
28-
println(io, " SessionId: ", dfg.sessionId)
29-
println(io, " Description: ", dfg.description)
30-
println(io, " Nr variables: ", length(ls(dfg)))
31-
println(io, " Nr factors: ",length(lsf(dfg)))
32-
println(io, " User Data: ", keys(dfg.userData))
33-
println(io, " Robot Data: ", keys(dfg.robotData))
34-
println(io, " Session Data: ", keys(dfg.sessionData))
35-
end
36-
37-
38-
#default for Atom/Juno
39-
Base.show(io::IO, ::MIME"application/prs.juno.inline", x::Union{AbstractDFG, DFGVariable, DFGFactor}) = x
40-
41-
421
##==============================================================================
432
## Printing Variables and Factors
443
##==============================================================================
@@ -98,11 +57,23 @@ function printFactor(io::IO, vert::DFGFactor;
9857

9958
if short
10059
printstyled(ioc, summary(vert),"\n", bold=true)
101-
println(ioc, "label: ", vert.label)
102-
println(ioc, "timestamp: ", vert.timestamp)
103-
println(ioc, "tags: ", vert.tags)
104-
println(ioc, "solvable: ", vert.solvable)
105-
println(ioc, "VariableOrder: ", vert._variableOrderSymbols)
60+
println(ioc, " label: ", vert.label)
61+
println(ioc, " solvable: ", vert.solvable)
62+
println(ioc, " VariableOrder: ", vert._variableOrderSymbols)
63+
println(ioc, " multihypo: ", getSolverData(vert).multihypo) # FIXME #477
64+
println(ioc, " nullhypo: ", "see DFG #477")
65+
println(ioc, " timestamp: ", vert.timestamp)
66+
println(ioc, " nstime: ",vert.nstime)
67+
println(ioc, " tags: ", vert.tags)
68+
fct = getFactorType(vert)
69+
fctt = fct |> typeof
70+
println(ioc, " Type: ", fctt)
71+
# show(ioc, fctt)
72+
for f in setdiff(fieldnames(fctt), skipfields)
73+
printstyled(ioc, f,":\n", color=:blue)
74+
show(ioc, getproperty(fct, f))
75+
println(ioc)
76+
end
10677
else
10778

10879
printstyled(ioc, summary(vert),"\n", bold=true, color=:blue)
@@ -140,3 +111,29 @@ Dev Notes
140111
printVariable(dfg::AbstractDFG, sym::Symbol) = print(getVariable(dfg, sym))
141112

142113
printNode(dfg::AbstractDFG, sym::Symbol) = isVariable(dfg,sym) ? printVariable(dfg, sym) : printFactor(dfg, sym)
114+
115+
116+
##==============================================================================
117+
## Overloading show
118+
##==============================================================================
119+
# Base.show_default(io, v)
120+
Base.show(io::IO, ::MIME"text/plain", v::DFGVariable) = show(IOContext(io, :limit=>true, :compact=>true), v)
121+
122+
Base.show(io::IO, ::MIME"text/plain", f::DFGFactor) = printFactor(io, f, short=true, limit=false)
123+
124+
function Base.show(io::IO, ::MIME"text/plain", dfg::AbstractDFG)
125+
summary(io, dfg)
126+
println(io, "\n UserId: ", dfg.userId)
127+
println(io, " RobotId: ", dfg.robotId)
128+
println(io, " SessionId: ", dfg.sessionId)
129+
println(io, " Description: ", dfg.description)
130+
println(io, " Nr variables: ", length(ls(dfg)))
131+
println(io, " Nr factors: ",length(lsf(dfg)))
132+
println(io, " User Data: ", keys(dfg.userData))
133+
println(io, " Robot Data: ", keys(dfg.robotData))
134+
println(io, " Session Data: ", keys(dfg.sessionData))
135+
end
136+
137+
138+
#default for Atom/Juno
139+
Base.show(io::IO, ::MIME"application/prs.juno.inline", x::Union{AbstractDFG, DFGVariable, DFGFactor}) = x

test/fileDFGTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ using Test
5252

5353
retDFG = loadDFG!(copyDfg, filename)
5454
# TODO REMOVE test deprecation
55-
retDFG_ = loadDFG(filename, Main, copyDfg2) #, loaddir="/tmp")
55+
retDFG_ = loadDFG(filename, Main, copyDf2) #, loaddir="/tmp")
5656

5757
@test issetequal(ls(dfg), ls(retDFG))
5858
@test issetequal(lsf(dfg), lsf(retDFG))

test/interfaceTests.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ end
6262
String(take!(iobuf)) == "DFGFactor{TestCCW{TestFunctorInferenceType1}}\nlabel:\n:abf1\ntags:\nSet([:tag1, :tag2])\nsolvable:\n0\nsolvable:\n1\n_variableOrderSymbols:\n[:a, :b]\n"
6363

6464
@test printFactor(iobuf, fac1, short=true) == nothing
65-
@test occursin(r"DFGFactor.*\nlabel.*\ntimestamp.*\ntags.*\nsolvable", String(take!(iobuf)))
65+
@show teststr = String(take!(iobuf))
66+
@test occursin(r"DFGFactor", teststr)
67+
@test occursin(r"label", teststr)
68+
@test occursin(r"timestamp", teststr)
69+
@test occursin(r"tags", teststr)
70+
@test occursin(r"solvable", teststr)
6671

6772
# s = String(take!(iobuf))
6873

0 commit comments

Comments
 (0)