Skip to content

Commit 44da244

Browse files
committed
Add warnings when the probe interface file is invalid
1 parent 946e0a6 commit 44da244

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

Source/Formats/ProbeInterface.h

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,48 +120,77 @@ namespace OnixSourcePlugin
120120
auto json = JSON::parse(file);
121121

122122
if (json == var())
123+
{
124+
Onix1::showWarningMessageBoxAsync("Unable to Parse File", "The file " + file.getFileName().toStdString() + " could not be parsed. " +
125+
"Please ensure that the file exists and is readable.");
123126
return false;
127+
}
124128

125129
DynamicObject::Ptr obj = json.getDynamicObject();
126130

127131
if (obj->hasProperty(Identifier("specification")))
128132
{
129133
std::string specification = obj->getProperty(Identifier("specification")).toString().toStdString();
130134

131-
if (specification.compare("probeinterface") != 0)
135+
const std::string probeInterfaceSpecification = "probeinterface";
136+
137+
if (specification.compare(probeInterfaceSpecification) != 0)
138+
{
139+
Onix1::showWarningMessageBoxAsync("Invalid Specification", "The specification listed in the Probe Interface file is " + specification +
140+
", but it is expected to be " + probeInterfaceSpecification + ".");
132141
return false;
142+
}
133143
}
134144
else
145+
{
146+
Onix1::showWarningMessageBoxAsync("No Specification Found", "No specification field was found in the JSON file.");
135147
return false;
148+
}
136149

137150
if (obj->hasProperty(Identifier("probes")))
138151
{
139152
Array<var>* probes = obj->getProperty(Identifier("probes")).getArray();
140153

141154
if (probes->size() != 1)
155+
{
156+
Onix1::showWarningMessageBoxAsync("Wrong Number of Probes", "Expected to find one probe listed in this file, but found " +
157+
std::to_string(probes->size()) + " probes in the file.");
142158
return false;
159+
}
143160

144161
DynamicObject::Ptr probe = probes->getReference(0).getDynamicObject();
145162

146163
if (probe->hasProperty(Identifier("ndim")))
147164
{
148165
if (!probe->getProperty(Identifier("ndim")).equalsWithSameType(2))
149166
{
167+
Onix1::showWarningMessageBoxAsync("Invalid Number of Dimensions", "Expected this file to contain two dimensions, but found "
168+
+ probe->getProperty(Identifier("ndim")).toString().toStdString() + " instead.");
150169
return false;
151170
}
152171
}
153172
else
173+
{
174+
Onix1::showWarningMessageBoxAsync("No Dimensions Found", "Could not find the number of dimensions in the file.");
154175
return false;
176+
}
155177

156178
if (probe->hasProperty(Identifier("si_units")))
157179
{
158-
if (!probe->getProperty(Identifier("si_units")).equalsWithSameType("um"))
180+
const std::string um = "um";
181+
182+
if (!probe->getProperty(Identifier("si_units")).equalsWithSameType(var(um)))
159183
{
184+
Onix1::showWarningMessageBoxAsync("Unexpected Units Found", "Expected to see units " + um + ", but found "
185+
+ probe->getProperty(Identifier("si_units")).toString().toStdString() + " instead.");
160186
return false;
161187
}
162188
}
163189
else
190+
{
191+
Onix1::showWarningMessageBoxAsync("No Units Found", "Could not find any units in the file.");
164192
return false;
193+
}
165194

166195
Array<var>* contact_positions = nullptr;
167196

@@ -170,10 +199,17 @@ namespace OnixSourcePlugin
170199
contact_positions = probe->getProperty(Identifier("contact_positions")).getArray();
171200

172201
if (contact_positions->size() != settings->electrodeMetadata.size())
202+
{
203+
Onix1::showWarningMessageBoxAsync("Different Number of Contacts", "Expected to find " + std::to_string(settings->electrodeMetadata.size()) +
204+
" contacts, but found " + std::to_string(contact_positions->size()) + " contacts instead.");
173205
return false;
206+
}
174207
}
175208
else
209+
{
210+
Onix1::showWarningMessageBoxAsync("No Contacts Found", "Could not find any contacts in the file.");
176211
return false;
212+
}
177213

178214
Array<var>* probe_planar_contour = nullptr;
179215

@@ -193,10 +229,17 @@ namespace OnixSourcePlugin
193229
device_channel_indices = probe->getProperty(Identifier("device_channel_indices")).getArray();
194230

195231
if (device_channel_indices->size() != settings->electrodeMetadata.size())
232+
{
233+
Onix1::showWarningMessageBoxAsync("Wrong Number of Indices Found", "Expected to find " + std::to_string(settings->electrodeMetadata.size()) +
234+
" device channel indices, but found " + std::to_string(device_channel_indices->size()) + " instead.");
196235
return false;
236+
}
197237
}
198238
else
239+
{
240+
Onix1::showWarningMessageBoxAsync("No Indices Found", "No device channel indices found in the file.");
199241
return false;
242+
}
200243

201244
Array<var>* shank_ids = nullptr;
202245

@@ -205,10 +248,17 @@ namespace OnixSourcePlugin
205248
shank_ids = probe->getProperty(Identifier("shank_ids")).getArray();
206249

207250
if (shank_ids->size() != settings->electrodeMetadata.size())
251+
{
252+
Onix1::showWarningMessageBoxAsync("Wrong Number of Shank IDs Found", "Expected to find " + std::to_string(settings->electrodeMetadata.size()) +
253+
" shank IDs, but found " + std::to_string(shank_ids->size()) + " instead.");
208254
return false;
255+
}
209256
}
210257
else
258+
{
259+
Onix1::showWarningMessageBoxAsync("No Shank IDs Found", "No shank IDs found in the file.");
211260
return false;
261+
}
212262

213263
for (int ch = 0; ch < contact_positions->size(); ch++)
214264
{
@@ -249,7 +299,10 @@ namespace OnixSourcePlugin
249299
settings->selectElectrodes(selectedChannels);
250300
}
251301
else
302+
{
303+
Onix1::showWarningMessageBoxAsync("No Probes Found", "Could not find any probes in the file.");
252304
return false;
305+
}
253306

254307
return true;
255308
}

0 commit comments

Comments
 (0)