Skip to content

Commit 77253a9

Browse files
authored
Merge pull request #998 from JuliaRobotics/23Q1/maint/blob
Aligning blob with sdk
2 parents d541fc9 + 369a07a commit 77253a9

File tree

8 files changed

+421
-219
lines changed

8 files changed

+421
-219
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.20.2"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
7+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
78
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
89
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
910
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

docs/extra/CoreAPI.fods

Lines changed: 201 additions & 105 deletions
Large diffs are not rendered by default.

src/DataBlobs/DataBlobs.jl

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/DataBlobs/services/BlobEntry.jl

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ end
8181

8282
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
8383
for (k,v) in var.dataDict
84-
# FIXME stop using v.id since that has been repurposed for unique BlobEntry indexing
85-
if v.originId == blobId || v.blobId == blobId || v.id == blobId
84+
if blobId in [v.originId, v.blobId]
8685
return v
8786
end
8887
end
@@ -91,9 +90,15 @@ function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
9190
)
9291
end
9392

94-
#TODO consider changing this to use `first` as in julia's findfirst - as in findfirstBlobEntry->label::Symbol
95-
# or getBlobEntryFirst, btw this returns a vector in some other places
96-
function getBlobEntry(var::AbstractDFGVariable, key::Regex)
93+
@deprecate getBlobEntry(var::AbstractDFGVariable, key::Regex) getBlobEntryFirst(var, key)
94+
95+
"""
96+
$(SIGNATURES)
97+
Finds and returns the first blob entry that matches the regex.
98+
99+
Also see: [`getBlobEntry`](@ref)
100+
"""
101+
function getBlobEntryFirst(var::AbstractDFGVariable, key::Regex)
97102
for (k,v) in var.dataDict
98103
if occursin(key, string(v.label))
99104
return v
@@ -106,7 +111,7 @@ end
106111

107112
getBlobEntry(var::AbstractDFGVariable, key::AbstractString) = getBlobEntry(var,Regex(key))
108113

109-
114+
#TODO split betweeen getfirstBlobEntry and getBlobEntry
110115
getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:AbstractString, Regex}) = getBlobEntry(getVariable(dfg, label), key)
111116
# getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobEntry(getVariable(dfg, label), key)
112117

@@ -121,22 +126,30 @@ Also see: [`getBlobEntry`](@ref), [`addBlob!`](@ref), [`mergeBlobEntries!`](@ref
121126
function addBlobEntry!(
122127
var::AbstractDFGVariable,
123128
entry::BlobEntry;
124-
blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
125-
blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
126129
)
127130
# see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
131+
# blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
132+
# blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
128133
haskey(var.dataDict, entry.label) && error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
129134
var.dataDict[entry.label] = entry
130135
return entry
131136
end
132137

138+
function addBlobEntry!(
139+
var::PackedVariable,
140+
entry::BlobEntry,
141+
)
142+
entry.label in getproperty.(var.blobEntries,:label) && error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
143+
push!(var.blobEntries, entry)
144+
return entry
145+
end
146+
133147
function addBlobEntry!(
134148
dfg::AbstractDFG,
135149
vLbl::Symbol,
136150
entry::BlobEntry;
137-
kw...
138151
)
139-
return addBlobEntry!(getVariable(dfg, vLbl), entry; kw...)
152+
return addBlobEntry!(getVariable(dfg, vLbl), entry)
140153
end
141154

142155

@@ -203,12 +216,25 @@ function getBlobEntries(var::AbstractDFGVariable)
203216
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
204217
collect(values(var.dataDict))
205218
end
219+
220+
function getBlobEntries(var::PackedVariable)
221+
var.blobEntries
222+
end
223+
206224
function getBlobEntries(dfg::AbstractDFG, label::Symbol)
207225
# !isVariable(dfg, label) && return nothing
208226
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
209227
getBlobEntries(getVariable(dfg, label))
210228
end
211229

230+
function getBlobEntries(dfg::AbstractDFG, label::Symbol, regex::Regex)
231+
entries = getBlobEntries(dfg, label)
232+
return filter(entries) do e
233+
occursin(regex, string(e.label))
234+
end
235+
end
236+
237+
212238
"""
213239
$(SIGNATURES)
214240

0 commit comments

Comments
 (0)