@@ -131,7 +131,21 @@ export setAll!
131
131
132
132
Recursively set the property `name` of each nested `RecoPlan` of `plan` to `x`.
133
133
"""
134
- function setAll! (plan:: RecoPlan{T} , name:: Symbol , x) where {T<: AbstractImageReconstructionParameters }
134
+ function setAll! (plan:: AbstractRecoPlan , name:: Symbol , x)
135
+ set = Ref (false )
136
+ found = Ref (false )
137
+ setAll! (plan, name, x, set, found)
138
+ if ! set[]
139
+ if ! found[]
140
+ @warn " Could not set all `$name ` properties of plan: Property not found"
141
+ else
142
+ @warn " Could not set all `$name ` properties of plan: Property of type $(typeof (x)) cannot be converted to the correct type"
143
+ end
144
+ end
145
+ return nothing
146
+ end
147
+
148
+ function setAll! (plan:: RecoPlan{T} , name:: Symbol , x, set, found) where {T<: AbstractImageReconstructionParameters }
135
149
fields = getfield (plan, :values )
136
150
137
151
# Filter out nested plans
@@ -142,21 +156,23 @@ function setAll!(plan::RecoPlan{T}, name::Symbol, x) where {T<:AbstractImageReco
142
156
143
157
# Recursively call setAll! on nested plans
144
158
for (key, nested) in nestedPlans
145
- key != name && setAll! (Observables. to_value (nested), name, x)
159
+ key != name && setAll! (Observables. to_value (nested), name, x, set, found )
146
160
end
147
161
148
162
# Set the value of the field
149
163
if hasproperty (plan, name)
150
164
try
165
+ found[] |= true
151
166
Base. setproperty! (plan, name, x)
167
+ set[] |= true
152
168
catch ex
153
- @error ex
154
169
@warn " Could not set $name of $T with value of type $(typeof (x)) "
155
170
end
156
171
end
172
+ return nothing
157
173
end
158
- setAll! (plans:: AbstractArray{<:AbstractRecoPlan} , name:: Symbol , x ) = foreach (p -> setAll! (p, name, x ), plans)
159
- setAll! (plan:: RecoPlan{<:AbstractImageReconstructionAlgorithm} , name:: Symbol , x ) = setAll! (plan. parameter, name, x )
174
+ setAll! (plans:: AbstractArray{<:AbstractRecoPlan} , name:: Symbol , args ... ) = foreach (p -> setAll! (p, name, args ... ), plans)
175
+ setAll! (plan:: RecoPlan{<:AbstractImageReconstructionAlgorithm} , name:: Symbol , args ... ) = setAll! (plan. parameter, name, args ... )
160
176
"""
161
177
setAll!(plan::AbstractRecoPlan; kwargs...)
162
178
0 commit comments