comparison framework/SVFileReader.cpp @ 595:b23bebfdfaba

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents c196680910dc
children 021d42e6c8cb
comparison
equal deleted inserted replaced
594:72b4870f0e6b 595:b23bebfdfaba
50 #include <QFileDialog> 50 #include <QFileDialog>
51 51
52 #include <iostream> 52 #include <iostream>
53 53
54 SVFileReader::SVFileReader(Document *document, 54 SVFileReader::SVFileReader(Document *document,
55 SVFileReaderPaneCallback &callback, 55 SVFileReaderPaneCallback &callback,
56 QString location) : 56 QString location) :
57 m_document(document), 57 m_document(document),
58 m_paneCallback(callback), 58 m_paneCallback(callback),
59 m_location(location), 59 m_location(location),
60 m_currentPane(0), 60 m_currentPane(0),
97 bool 97 bool
98 SVFileReader::isOK() 98 SVFileReader::isOK()
99 { 99 {
100 return m_ok; 100 return m_ok;
101 } 101 }
102 102
103 SVFileReader::~SVFileReader() 103 SVFileReader::~SVFileReader()
104 { 104 {
105 if (!m_awaitingDatasets.empty()) { 105 if (!m_awaitingDatasets.empty()) {
106 cerr << "WARNING: SV-XML: File ended with " 106 cerr << "WARNING: SV-XML: File ended with "
107 << m_awaitingDatasets.size() << " unfilled model dataset(s)" 107 << m_awaitingDatasets.size() << " unfilled model dataset(s)"
108 << endl; 108 << endl;
109 } 109 }
110 110
111 std::set<Model *> unaddedModels; 111 std::set<Model *> unaddedModels;
112 112
113 for (std::map<int, Model *>::iterator i = m_models.begin(); 113 for (std::map<int, Model *>::iterator i = m_models.begin();
114 i != m_models.end(); ++i) { 114 i != m_models.end(); ++i) {
115 if (m_addedModels.find(i->second) == m_addedModels.end()) { 115 if (m_addedModels.find(i->second) == m_addedModels.end()) {
116 unaddedModels.insert(i->second); 116 unaddedModels.insert(i->second);
117 } 117 }
118 } 118 }
119 119
120 if (!unaddedModels.empty()) { 120 if (!unaddedModels.empty()) {
121 cerr << "WARNING: SV-XML: File contained " 121 cerr << "WARNING: SV-XML: File contained "
122 << unaddedModels.size() << " unused models" 122 << unaddedModels.size() << " unused models"
123 << endl; 123 << endl;
124 while (!unaddedModels.empty()) { 124 while (!unaddedModels.empty()) {
125 delete *unaddedModels.begin(); 125 delete *unaddedModels.begin();
126 unaddedModels.erase(unaddedModels.begin()); 126 unaddedModels.erase(unaddedModels.begin());
127 } 127 }
128 } 128 }
129 } 129 }
130 130
131 bool 131 bool
132 SVFileReader::startElement(const QString &, const QString &, 132 SVFileReader::startElement(const QString &, const QString &,
133 const QString &qName, 133 const QString &qName,
134 const QXmlAttributes &attributes) 134 const QXmlAttributes &attributes)
135 { 135 {
136 QString name = qName.toLower(); 136 QString name = qName.toLower();
137 137
138 bool ok = false; 138 bool ok = false;
139 139
157 // selection 157 // selection
158 // measurement 158 // measurement
159 159
160 if (name == "sv") { 160 if (name == "sv") {
161 161
162 // nothing needed 162 // nothing needed
163 ok = true; 163 ok = true;
164 164
165 } else if (name == "data") { 165 } else if (name == "data") {
166 166
167 // nothing needed 167 // nothing needed
168 m_inData = true; 168 m_inData = true;
169 ok = true; 169 ok = true;
170 170
171 } else if (name == "display") { 171 } else if (name == "display") {
172 172
173 // nothing needed 173 // nothing needed
174 ok = true; 174 ok = true;
175 175
176 } else if (name == "window") { 176 } else if (name == "window") {
177 177
178 ok = readWindow(attributes); 178 ok = readWindow(attributes);
179 179
180 } else if (name == "model") { 180 } else if (name == "model") {
181 181
182 ok = readModel(attributes); 182 ok = readModel(attributes);
183 183
184 } else if (name == "dataset") { 184 } else if (name == "dataset") {
185 185
186 ok = readDatasetStart(attributes); 186 ok = readDatasetStart(attributes);
187 187
188 } else if (name == "bin") { 188 } else if (name == "bin") {
189 189
190 ok = addBinToDataset(attributes); 190 ok = addBinToDataset(attributes);
191 191
192 } else if (name == "point") { 192 } else if (name == "point") {
193 193
194 ok = addPointToDataset(attributes); 194 ok = addPointToDataset(attributes);
195 195
196 } else if (name == "row") { 196 } else if (name == "row") {
197 197
198 ok = addRowToDataset(attributes); 198 ok = addRowToDataset(attributes);
199 199
200 } else if (name == "layer") { 200 } else if (name == "layer") {
201 201
202 addUnaddedModels(); // all models must be specified before first layer 202 addUnaddedModels(); // all models must be specified before first layer
203 ok = readLayer(attributes); 203 ok = readLayer(attributes);
204 204
205 } else if (name == "view") { 205 } else if (name == "view") {
206 206
207 m_inView = true; 207 m_inView = true;
208 ok = readView(attributes); 208 ok = readView(attributes);
209 209
210 } else if (name == "derivation") { 210 } else if (name == "derivation") {
211 211
212 ok = readDerivation(attributes); 212 ok = readDerivation(attributes);
213 213
214 } else if (name == "playparameters") { 214 } else if (name == "playparameters") {
215 215
216 ok = readPlayParameters(attributes); 216 ok = readPlayParameters(attributes);
217 217
218 } else if (name == "plugin") { 218 } else if (name == "plugin") {
219 219
220 ok = readPlugin(attributes); 220 ok = readPlugin(attributes);
221 221
222 } else if (name == "selections") { 222 } else if (name == "selections") {
223 223
224 m_inSelections = true; 224 m_inSelections = true;
225 ok = true; 225 ok = true;
226 226
227 } else if (name == "selection") { 227 } else if (name == "selection") {
228 228
229 ok = readSelection(attributes); 229 ok = readSelection(attributes);
230 230
231 } else if (name == "measurement") { 231 } else if (name == "measurement") {
232 232
233 ok = readMeasurement(attributes); 233 ok = readMeasurement(attributes);
234 234
244 cerr << "WARNING: SV-XML: Unexpected element \"" 244 cerr << "WARNING: SV-XML: Unexpected element \""
245 << name << "\"" << endl; 245 << name << "\"" << endl;
246 } 246 }
247 247
248 if (!ok) { 248 if (!ok) {
249 cerr << "WARNING: SV-XML: Failed to completely process element \"" 249 cerr << "WARNING: SV-XML: Failed to completely process element \""
250 << name << "\"" << endl; 250 << name << "\"" << endl;
251 } 251 }
252 252
253 return true; 253 return true;
254 } 254 }
255 255
257 SVFileReader::characters(const QString &text) 257 SVFileReader::characters(const QString &text)
258 { 258 {
259 bool ok = false; 259 bool ok = false;
260 260
261 if (m_inRow) { 261 if (m_inRow) {
262 ok = readRowData(text); 262 ok = readRowData(text);
263 if (!ok) { 263 if (!ok) {
264 cerr << "WARNING: SV-XML: Failed to read row data content for row " << m_rowNumber << endl; 264 cerr << "WARNING: SV-XML: Failed to read row data content for row " << m_rowNumber << endl;
265 } 265 }
266 } 266 }
267 267
268 return true; 268 return true;
269 } 269 }
270 270
271 bool 271 bool
272 SVFileReader::endElement(const QString &, const QString &, 272 SVFileReader::endElement(const QString &, const QString &,
273 const QString &qName) 273 const QString &qName)
274 { 274 {
275 QString name = qName.toLower(); 275 QString name = qName.toLower();
276 276
277 if (name == "dataset") { 277 if (name == "dataset") {
278 278
279 if (m_currentDataset) { 279 if (m_currentDataset) {
280 280
281 bool foundInAwaiting = false; 281 bool foundInAwaiting = false;
282 282
283 for (std::map<int, int>::iterator i = m_awaitingDatasets.begin(); 283 for (std::map<int, int>::iterator i = m_awaitingDatasets.begin();
284 i != m_awaitingDatasets.end(); ++i) { 284 i != m_awaitingDatasets.end(); ++i) {
285 if (haveModel(i->second) && 285 if (haveModel(i->second) &&
286 m_models[i->second] == m_currentDataset) { 286 m_models[i->second] == m_currentDataset) {
287 m_awaitingDatasets.erase(i); 287 m_awaitingDatasets.erase(i);
288 foundInAwaiting = true; 288 foundInAwaiting = true;
289 break; 289 break;
290 } 290 }
291 } 291 }
292 292
293 if (!foundInAwaiting) { 293 if (!foundInAwaiting) {
294 cerr << "WARNING: SV-XML: Dataset precedes model, or no model uses dataset" << endl; 294 cerr << "WARNING: SV-XML: Dataset precedes model, or no model uses dataset" << endl;
295 } 295 }
296 } 296 }
297 297
298 m_currentDataset = 0; 298 m_currentDataset = 0;
299 299
300 } else if (name == "data") { 300 } else if (name == "data") {
301 301
302 addUnaddedModels(); 302 addUnaddedModels();
303 m_inData = false; 303 m_inData = false;
304 304
305 } else if (name == "derivation") { 305 } else if (name == "derivation") {
306 306
307 if (!m_currentDerivedModel) { 307 if (!m_currentDerivedModel) {
308 if (m_currentDerivedModelId < 0) { 308 if (m_currentDerivedModelId < 0) {
344 m_currentTransformSource = 0; 344 m_currentTransformSource = 0;
345 m_currentTransform = Transform(); 345 m_currentTransform = Transform();
346 m_currentTransformChannel = -1; 346 m_currentTransformChannel = -1;
347 347
348 } else if (name == "row") { 348 } else if (name == "row") {
349 m_inRow = false; 349 m_inRow = false;
350 } else if (name == "layer") { 350 } else if (name == "layer") {
351 m_inLayer = false; 351 m_inLayer = false;
352 } else if (name == "view") { 352 } else if (name == "view") {
353 m_inView = false; 353 m_inView = false;
354 } else if (name == "selections") { 354 } else if (name == "selections") {
355 m_inSelections = false; 355 m_inSelections = false;
356 } else if (name == "playparameters") { 356 } else if (name == "playparameters") {
357 m_currentPlayParameters = 0; 357 m_currentPlayParameters = 0;
358 } 358 }
359 359
360 return true; 360 return true;
362 362
363 bool 363 bool
364 SVFileReader::error(const QXmlParseException &exception) 364 SVFileReader::error(const QXmlParseException &exception)
365 { 365 {
366 m_errorString = 366 m_errorString =
367 QString("ERROR: SV-XML: %1 at line %2, column %3") 367 QString("ERROR: SV-XML: %1 at line %2, column %3")
368 .arg(exception.message()) 368 .arg(exception.message())
369 .arg(exception.lineNumber()) 369 .arg(exception.lineNumber())
370 .arg(exception.columnNumber()); 370 .arg(exception.columnNumber());
371 cerr << m_errorString << endl; 371 cerr << m_errorString << endl;
372 return QXmlDefaultHandler::error(exception); 372 return QXmlDefaultHandler::error(exception);
373 } 373 }
374 374
375 bool 375 bool
376 SVFileReader::fatalError(const QXmlParseException &exception) 376 SVFileReader::fatalError(const QXmlParseException &exception)
377 { 377 {
378 m_errorString = 378 m_errorString =
379 QString("FATAL ERROR: SV-XML: %1 at line %2, column %3") 379 QString("FATAL ERROR: SV-XML: %1 at line %2, column %3")
380 .arg(exception.message()) 380 .arg(exception.message())
381 .arg(exception.lineNumber()) 381 .arg(exception.lineNumber())
382 .arg(exception.columnNumber()); 382 .arg(exception.columnNumber());
383 cerr << m_errorString << endl; 383 cerr << m_errorString << endl;
384 return QXmlDefaultHandler::fatalError(exception); 384 return QXmlDefaultHandler::fatalError(exception);
385 } 385 }
386 386
387 387
388 #define READ_MANDATORY(TYPE, NAME, CONVERSION) \ 388 #define READ_MANDATORY(TYPE, NAME, CONVERSION) \
389 TYPE NAME = attributes.value(#NAME).trimmed().CONVERSION(&ok); \ 389 TYPE NAME = attributes.value(#NAME).trimmed().CONVERSION(&ok); \
390 if (!ok) { \ 390 if (!ok) { \
391 cerr << "WARNING: SV-XML: Missing or invalid mandatory " #TYPE " attribute \"" #NAME "\"" << endl; \ 391 cerr << "WARNING: SV-XML: Missing or invalid mandatory " #TYPE " attribute \"" #NAME "\"" << endl; \
392 return false; \ 392 return false; \
393 } 393 }
394 394
395 bool 395 bool
396 SVFileReader::readWindow(const QXmlAttributes &) 396 SVFileReader::readWindow(const QXmlAttributes &)
397 { 397 {
437 bool ok = false; 437 bool ok = false;
438 438
439 READ_MANDATORY(int, id, toInt); 439 READ_MANDATORY(int, id, toInt);
440 440
441 if (haveModel(id)) { 441 if (haveModel(id)) {
442 cerr << "WARNING: SV-XML: Ignoring duplicate model id " << id 442 cerr << "WARNING: SV-XML: Ignoring duplicate model id " << id
443 << endl; 443 << endl;
444 return false; 444 return false;
445 } 445 }
446 446
447 QString name = attributes.value("name"); 447 QString name = attributes.value("name");
448 448
449 SVDEBUG << "SVFileReader::readModel: model name \"" << name << "\"" << endl; 449 SVDEBUG << "SVFileReader::readModel: model name \"" << name << "\"" << endl;
452 452
453 QString type = attributes.value("type").trimmed(); 453 QString type = attributes.value("type").trimmed();
454 bool isMainModel = (attributes.value("mainModel").trimmed() == "true"); 454 bool isMainModel = (attributes.value("mainModel").trimmed() == "true");
455 455
456 if (type == "wavefile") { 456 if (type == "wavefile") {
457 457
458 WaveFileModel *model = 0; 458 WaveFileModel *model = 0;
459 FileFinder *ff = FileFinder::getInstance(); 459 FileFinder *ff = FileFinder::getInstance();
460 QString originalPath = attributes.value("file"); 460 QString originalPath = attributes.value("file");
461 QString path = ff->find(FileFinder::AudioFile, 461 QString path = ff->find(FileFinder::AudioFile,
462 originalPath, m_location); 462 originalPath, m_location);
495 } 495 }
496 496
497 if (!model) return false; 497 if (!model) return false;
498 498
499 model->setObjectName(name); 499 model->setObjectName(name);
500 m_models[id] = model; 500 m_models[id] = model;
501 if (isMainModel) { 501 if (isMainModel) {
502 m_document->setMainModel(model); 502 m_document->setMainModel(model);
503 m_addedModels.insert(model); 503 m_addedModels.insert(model);
504 } 504 }
505 // Derived models will be added when their derivation 505 // Derived models will be added when their derivation
506 // is found. 506 // is found.
507 507
508 return true; 508 return true;
509 509
510 } else if (type == "dense") { 510 } else if (type == "dense") {
511 511
512 READ_MANDATORY(int, dimensions, toInt); 512 READ_MANDATORY(int, dimensions, toInt);
513 513
514 // Currently the only dense model we support here is the dense 514 // Currently the only dense model we support here is the dense
515 // 3d model. Dense time-value models are always file-backed 515 // 3d model. Dense time-value models are always file-backed
516 // waveform data, at this point, and they come in as wavefile 516 // waveform data, at this point, and they come in as wavefile
517 // models. 517 // models.
518 518
519 if (dimensions == 3) { 519 if (dimensions == 3) {
520 520
521 READ_MANDATORY(int, windowSize, toInt); 521 READ_MANDATORY(int, windowSize, toInt);
522 READ_MANDATORY(int, yBinCount, toInt); 522 READ_MANDATORY(int, yBinCount, toInt);
523 523
524 EditableDenseThreeDimensionalModel *model = 524 EditableDenseThreeDimensionalModel *model =
525 new EditableDenseThreeDimensionalModel 525 new EditableDenseThreeDimensionalModel
526 (sampleRate, windowSize, yBinCount, 526 (sampleRate, windowSize, yBinCount,
527 EditableDenseThreeDimensionalModel::NoCompression); 527 EditableDenseThreeDimensionalModel::NoCompression);
528 528
529 float minimum = attributes.value("minimum").trimmed().toFloat(&ok); 529 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
530 if (ok) model->setMinimumLevel(minimum); 530 if (ok) model->setMinimumLevel(minimum);
531 531
532 float maximum = attributes.value("maximum").trimmed().toFloat(&ok); 532 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
533 if (ok) model->setMaximumLevel(maximum); 533 if (ok) model->setMaximumLevel(maximum);
534 534
535 int dataset = attributes.value("dataset").trimmed().toInt(&ok); 535 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
536 if (ok) m_awaitingDatasets[dataset] = id; 536 if (ok) m_awaitingDatasets[dataset] = id;
537 537
538 int startFrame = attributes.value("startFrame").trimmed().toInt(&ok); 538 int startFrame = attributes.value("startFrame").trimmed().toInt(&ok);
539 if (ok) model->setStartFrame(startFrame); 539 if (ok) model->setStartFrame(startFrame);
540 540
541 model->setObjectName(name); 541 model->setObjectName(name);
542 m_models[id] = model; 542 m_models[id] = model;
543 return true; 543 return true;
544 544
545 } else { 545 } else {
546 546
547 cerr << "WARNING: SV-XML: Unexpected dense model dimension (" 547 cerr << "WARNING: SV-XML: Unexpected dense model dimension ("
548 << dimensions << ")" << endl; 548 << dimensions << ")" << endl;
549 } 549 }
550 } else if (type == "sparse") { 550 } else if (type == "sparse") {
551 551
552 READ_MANDATORY(int, dimensions, toInt); 552 READ_MANDATORY(int, dimensions, toInt);
553 553
554 if (dimensions == 1) { 554 if (dimensions == 1) {
555 555
556 READ_MANDATORY(int, resolution, toInt); 556 READ_MANDATORY(int, resolution, toInt);
557 557
558 if (attributes.value("subtype") == "image") { 558 if (attributes.value("subtype") == "image") {
559 559
560 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true"); 560 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
561 ImageModel *model = new ImageModel(sampleRate, resolution, 561 ImageModel *model = new ImageModel(sampleRate, resolution,
569 (sampleRate, resolution); 569 (sampleRate, resolution);
570 model->setObjectName(name); 570 model->setObjectName(name);
571 m_models[id] = model; 571 m_models[id] = model;
572 } 572 }
573 573
574 int dataset = attributes.value("dataset").trimmed().toInt(&ok); 574 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
575 if (ok) m_awaitingDatasets[dataset] = id; 575 if (ok) m_awaitingDatasets[dataset] = id;
576 576
577 return true; 577 return true;
578 578
579 } else if (dimensions == 2 || dimensions == 3) { 579 } else if (dimensions == 2 || dimensions == 3) {
580 580
581 READ_MANDATORY(int, resolution, toInt); 581 READ_MANDATORY(int, resolution, toInt);
582 582
583 bool haveMinMax = true; 583 bool haveMinMax = true;
584 float minimum = attributes.value("minimum").trimmed().toFloat(&ok); 584 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
585 if (!ok) haveMinMax = false; 585 if (!ok) haveMinMax = false;
586 float maximum = attributes.value("maximum").trimmed().toFloat(&ok); 586 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
587 if (!ok) haveMinMax = false; 587 if (!ok) haveMinMax = false;
588 588
589 float valueQuantization = 589 float valueQuantization =
590 attributes.value("valueQuantization").trimmed().toFloat(&ok); 590 attributes.value("valueQuantization").trimmed().toFloat(&ok);
591 591
592 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true"); 592 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
593 593
594 QString units = attributes.value("units"); 594 QString units = attributes.value("units");
595 595
596 if (dimensions == 2) { 596 if (dimensions == 2) {
597 if (attributes.value("subtype") == "text") { 597 if (attributes.value("subtype") == "text") {
598 TextModel *model = new TextModel 598 TextModel *model = new TextModel
599 (sampleRate, resolution, notifyOnAdd); 599 (sampleRate, resolution, notifyOnAdd);
600 model->setObjectName(name); 600 model->setObjectName(name);
601 m_models[id] = model; 601 m_models[id] = model;
602 } else if (attributes.value("subtype") == "path") { 602 } else if (attributes.value("subtype") == "path") {
603 PathModel *model = new PathModel 603 PathModel *model = new PathModel
604 (sampleRate, resolution, notifyOnAdd); 604 (sampleRate, resolution, notifyOnAdd);
605 model->setObjectName(name); 605 model->setObjectName(name);
606 m_models[id] = model; 606 m_models[id] = model;
607 } else { 607 } else {
608 SparseTimeValueModel *model; 608 SparseTimeValueModel *model;
609 if (haveMinMax) { 609 if (haveMinMax) {
610 model = new SparseTimeValueModel 610 model = new SparseTimeValueModel
611 (sampleRate, resolution, minimum, maximum, notifyOnAdd); 611 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
612 } else { 612 } else {
613 model = new SparseTimeValueModel 613 model = new SparseTimeValueModel
614 (sampleRate, resolution, notifyOnAdd); 614 (sampleRate, resolution, notifyOnAdd);
615 } 615 }
616 model->setScaleUnits(units); 616 model->setScaleUnits(units);
617 model->setObjectName(name); 617 model->setObjectName(name);
618 m_models[id] = model; 618 m_models[id] = model;
619 } 619 }
620 } else { 620 } else {
621 if (attributes.value("subtype") == "region") { 621 if (attributes.value("subtype") == "region") {
622 RegionModel *model; 622 RegionModel *model;
623 if (haveMinMax) { 623 if (haveMinMax) {
624 model = new RegionModel 624 model = new RegionModel
625 (sampleRate, resolution, minimum, maximum, notifyOnAdd); 625 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
660 model->setObjectName(name); 660 model->setObjectName(name);
661 m_models[id] = model; 661 m_models[id] = model;
662 } 662 }
663 } 663 }
664 664
665 int dataset = attributes.value("dataset").trimmed().toInt(&ok); 665 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
666 if (ok) m_awaitingDatasets[dataset] = id; 666 if (ok) m_awaitingDatasets[dataset] = id;
667 667
668 return true; 668 return true;
669 669
670 } else { 670 } else {
671 671
672 cerr << "WARNING: SV-XML: Unexpected sparse model dimension (" 672 cerr << "WARNING: SV-XML: Unexpected sparse model dimension ("
673 << dimensions << ")" << endl; 673 << dimensions << ")" << endl;
674 } 674 }
675 675
676 } else if (type == "alignment") { 676 } else if (type == "alignment") {
677 677
678 READ_MANDATORY(int, reference, toInt); 678 READ_MANDATORY(int, reference, toInt);
679 READ_MANDATORY(int, aligned, toInt); 679 READ_MANDATORY(int, aligned, toInt);
737 { 737 {
738 QString type = attributes.value("type"); 738 QString type = attributes.value("type");
739 m_currentPane = 0; 739 m_currentPane = 0;
740 740
741 if (type != "pane") { 741 if (type != "pane") {
742 cerr << "WARNING: SV-XML: Unexpected view type \"" 742 cerr << "WARNING: SV-XML: Unexpected view type \""
743 << type << "\"" << endl; 743 << type << "\"" << endl;
744 return false; 744 return false;
745 } 745 }
746 746
747 m_currentPane = m_paneCallback.addPane(); 747 m_currentPane = m_paneCallback.addPane();
748 748
749 cerr << "SVFileReader::addPane: pane is " << m_currentPane << endl; 749 cerr << "SVFileReader::addPane: pane is " << m_currentPane << endl;
750 750
751 if (!m_currentPane) { 751 if (!m_currentPane) {
752 cerr << "WARNING: SV-XML: Internal error: Failed to add pane!" 752 cerr << "WARNING: SV-XML: Internal error: Failed to add pane!"
753 << endl; 753 << endl;
754 return false; 754 return false;
755 } 755 }
756 756
757 bool ok = false; 757 bool ok = false;
758 758
759 View *view = m_currentPane; 759 View *view = m_currentPane;
768 768
769 // Specify the follow modes before we set the actual values 769 // Specify the follow modes before we set the actual values
770 view->setFollowGlobalPan(followPan); 770 view->setFollowGlobalPan(followPan);
771 view->setFollowGlobalZoom(followZoom); 771 view->setFollowGlobalZoom(followZoom);
772 view->setPlaybackFollow(tracking == "scroll" ? PlaybackScrollContinuous : 772 view->setPlaybackFollow(tracking == "scroll" ? PlaybackScrollContinuous :
773 tracking == "page" ? PlaybackScrollPageWithCentre : 773 tracking == "page" ? PlaybackScrollPageWithCentre :
774 tracking == "daw" ? PlaybackScrollPage 774 tracking == "daw" ? PlaybackScrollPage
775 : PlaybackIgnore); 775 : PlaybackIgnore);
776 776
777 // Then set these values 777 // Then set these values
778 view->setCentreFrame(centre); 778 view->setCentreFrame(centre);
779 view->setZoomLevel(zoom); 779 view->setZoomLevel(zoom);
780 780
782 READ_MANDATORY(int, centreLineVisible, toInt); 782 READ_MANDATORY(int, centreLineVisible, toInt);
783 m_currentPane->setCentreLineVisible(centreLineVisible); 783 m_currentPane->setCentreLineVisible(centreLineVisible);
784 784
785 int height = attributes.value("height").toInt(&ok); 785 int height = attributes.value("height").toInt(&ok);
786 if (ok) { 786 if (ok) {
787 m_currentPane->resize(m_currentPane->width(), height); 787 m_currentPane->resize(m_currentPane->width(), height);
788 } 788 }
789 789
790 return true; 790 return true;
791 } 791 }
792 792
798 int id; 798 int id;
799 bool ok = false; 799 bool ok = false;
800 id = attributes.value("id").trimmed().toInt(&ok); 800 id = attributes.value("id").trimmed().toInt(&ok);
801 801
802 if (!ok) { 802 if (!ok) {
803 cerr << "WARNING: SV-XML: No layer id for layer of type \"" 803 cerr << "WARNING: SV-XML: No layer id for layer of type \""
804 << type 804 << type
805 << "\"" << endl; 805 << "\"" << endl;
806 return false; 806 return false;
807 } 807 }
808 808
809 Layer *layer = 0; 809 Layer *layer = 0;
810 bool isNewLayer = false; 810 bool isNewLayer = false;
811 811
815 // layer not to exist already; if we're in the view section, we 815 // layer not to exist already; if we're in the view section, we
816 // expect it to exist. 816 // expect it to exist.
817 817
818 if (m_inData) { 818 if (m_inData) {
819 819
820 if (m_layers.find(id) != m_layers.end()) { 820 if (m_layers.find(id) != m_layers.end()) {
821 cerr << "WARNING: SV-XML: Ignoring duplicate layer id " << id 821 cerr << "WARNING: SV-XML: Ignoring duplicate layer id " << id
822 << " in data section" << endl; 822 << " in data section" << endl;
823 return false; 823 return false;
824 } 824 }
825 825
826 layer = m_layers[id] = m_document->createLayer 826 layer = m_layers[id] = m_document->createLayer
827 (LayerFactory::getInstance()->getLayerTypeForName(type)); 827 (LayerFactory::getInstance()->getLayerTypeForName(type));
828 828
829 if (layer) { 829 if (layer) {
830 m_layers[id] = layer; 830 m_layers[id] = layer;
831 isNewLayer = true; 831 isNewLayer = true;
832 } 832 }
833 833
834 } else { 834 } else {
835 835
836 if (!m_currentPane) { 836 if (!m_currentPane) {
837 cerr << "WARNING: SV-XML: No current pane for layer " << id 837 cerr << "WARNING: SV-XML: No current pane for layer " << id
838 << " in view section" << endl; 838 << " in view section" << endl;
839 return false; 839 return false;
840 } 840 }
841 841
842 if (m_layers.find(id) != m_layers.end()) { 842 if (m_layers.find(id) != m_layers.end()) {
843 843
844 layer = m_layers[id]; 844 layer = m_layers[id];
845 845
846 } else { 846 } else {
847 cerr << "WARNING: SV-XML: Layer id " << id 847 cerr << "WARNING: SV-XML: Layer id " << id
848 << " in view section has not been defined -- defining it here" 848 << " in view section has not been defined -- defining it here"
849 << endl; 849 << endl;
850 850
851 layer = m_document->createLayer 851 layer = m_document->createLayer
852 (LayerFactory::getInstance()->getLayerTypeForName(type)); 852 (LayerFactory::getInstance()->getLayerTypeForName(type));
853 853
854 if (layer) { 854 if (layer) {
855 m_layers[id] = layer; 855 m_layers[id] = layer;
856 isNewLayer = true; 856 isNewLayer = true;
857 } 857 }
858 } 858 }
859 } 859 }
860 860
861 if (!layer) { 861 if (!layer) {
862 cerr << "WARNING: SV-XML: Failed to add layer of type \"" 862 cerr << "WARNING: SV-XML: Failed to add layer of type \""
863 << type 863 << type
864 << "\"" << endl; 864 << "\"" << endl;
865 return false; 865 return false;
866 } 866 }
867 867
868 if (isNewLayer) { 868 if (isNewLayer) {
869 869
870 QString name = attributes.value("name"); 870 QString name = attributes.value("name");
871 layer->setObjectName(name); 871 layer->setObjectName(name);
872 872
873 QString presentationName = attributes.value("presentationName"); 873 QString presentationName = attributes.value("presentationName");
874 layer->setPresentationName(presentationName); 874 layer->setPresentationName(presentationName);
875 875
876 int modelId; 876 int modelId;
877 bool modelOk = false; 877 bool modelOk = false;
878 modelId = attributes.value("model").trimmed().toInt(&modelOk); 878 modelId = attributes.value("model").trimmed().toInt(&modelOk);
879 879
880 if (modelOk) { 880 if (modelOk) {
881 if (haveModel(modelId)) { 881 if (haveModel(modelId)) {
882 Model *model = m_models[modelId]; 882 Model *model = m_models[modelId];
883 m_document->setModel(layer, model); 883 m_document->setModel(layer, model);
884 } else { 884 } else {
885 cerr << "WARNING: SV-XML: Unknown model id " << modelId 885 cerr << "WARNING: SV-XML: Unknown model id " << modelId
886 << " in layer definition" << endl; 886 << " in layer definition" << endl;
887 if (!layer->canExistWithoutModel()) { 887 if (!layer->canExistWithoutModel()) {
888 // Don't add a layer with an unknown model id 888 // Don't add a layer with an unknown model id
889 // unless it explicitly supports this state 889 // unless it explicitly supports this state
890 m_document->deleteLayer(layer); 890 m_document->deleteLayer(layer);
891 m_layers[id] = layer = 0; 891 m_layers[id] = layer = 0;
892 return false; 892 return false;
893 } 893 }
894 } 894 }
895 } 895 }
896 896
897 if (layer) layer->setProperties(attributes); 897 if (layer) layer->setProperties(attributes);
898 } 898 }
899 899
900 if (!m_inData && m_currentPane && layer) { 900 if (!m_inData && m_currentPane && layer) {
909 // command sets dormant to false because it assumes it may be 909 // command sets dormant to false because it assumes it may be
910 // restoring a previously dormant layer, so we need to set it 910 // restoring a previously dormant layer, so we need to set it
911 // again afterwards too. Hm 911 // again afterwards too. Hm
912 layer->setLayerDormant(m_currentPane, dormant); 912 layer->setLayerDormant(m_currentPane, dormant);
913 913
914 m_document->addLayerToView(m_currentPane, layer); 914 m_document->addLayerToView(m_currentPane, layer);
915 915
916 layer->setLayerDormant(m_currentPane, dormant); 916 layer->setLayerDormant(m_currentPane, dormant);
917 } 917 }
918 918
919 m_currentLayer = layer; 919 m_currentLayer = layer;
929 929
930 READ_MANDATORY(int, id, toInt); 930 READ_MANDATORY(int, id, toInt);
931 READ_MANDATORY(int, dimensions, toInt); 931 READ_MANDATORY(int, dimensions, toInt);
932 932
933 if (m_awaitingDatasets.find(id) == m_awaitingDatasets.end()) { 933 if (m_awaitingDatasets.find(id) == m_awaitingDatasets.end()) {
934 cerr << "WARNING: SV-XML: Unwanted dataset " << id << endl; 934 cerr << "WARNING: SV-XML: Unwanted dataset " << id << endl;
935 return false; 935 return false;
936 } 936 }
937 937
938 int modelId = m_awaitingDatasets[id]; 938 int modelId = m_awaitingDatasets[id];
939 939
940 Model *model = 0; 940 Model *model = 0;
941 if (haveModel(modelId)) { 941 if (haveModel(modelId)) {
942 model = m_models[modelId]; 942 model = m_models[modelId];
943 } else { 943 } else {
944 cerr << "WARNING: SV-XML: Internal error: Unknown model " << modelId 944 cerr << "WARNING: SV-XML: Internal error: Unknown model " << modelId
945 << " expecting dataset " << id << endl; 945 << " expecting dataset " << id << endl;
946 return false; 946 return false;
947 } 947 }
948 948
949 bool good = false; 949 bool good = false;
950 950
951 switch (dimensions) { 951 switch (dimensions) {
952 case 1: 952 case 1:
953 if (dynamic_cast<SparseOneDimensionalModel *>(model)) good = true; 953 if (dynamic_cast<SparseOneDimensionalModel *>(model)) good = true;
954 else if (dynamic_cast<ImageModel *>(model)) good = true; 954 else if (dynamic_cast<ImageModel *>(model)) good = true;
955 break; 955 break;
956 956
957 case 2: 957 case 2:
958 if (dynamic_cast<SparseTimeValueModel *>(model)) good = true; 958 if (dynamic_cast<SparseTimeValueModel *>(model)) good = true;
959 else if (dynamic_cast<TextModel *>(model)) good = true; 959 else if (dynamic_cast<TextModel *>(model)) good = true;
960 else if (dynamic_cast<PathModel *>(model)) good = true; 960 else if (dynamic_cast<PathModel *>(model)) good = true;
961 break; 961 break;
962 962
963 case 3: 963 case 3:
964 if (dynamic_cast<NoteModel *>(model)) good = true; 964 if (dynamic_cast<NoteModel *>(model)) good = true;
965 else if (dynamic_cast<FlexiNoteModel *>(model)) good = true; 965 else if (dynamic_cast<FlexiNoteModel *>(model)) good = true;
966 else if (dynamic_cast<RegionModel *>(model)) good = true; 966 else if (dynamic_cast<RegionModel *>(model)) good = true;
967 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { 967 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) {
968 m_datasetSeparator = attributes.value("separator"); 968 m_datasetSeparator = attributes.value("separator");
969 good = true; 969 good = true;
970 } 970 }
971 break; 971 break;
972 } 972 }
973 973
974 if (!good) { 974 if (!good) {
975 cerr << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions or inappropriate type for " << dimensions << "-D dataset " << id << endl; 975 cerr << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions or inappropriate type for " << dimensions << "-D dataset " << id << endl;
976 m_currentDataset = 0; 976 m_currentDataset = 0;
977 return false; 977 return false;
978 } 978 }
979 979
980 m_currentDataset = model; 980 m_currentDataset = model;
981 return true; 981 return true;
982 } 982 }
989 READ_MANDATORY(int, frame, toInt); 989 READ_MANDATORY(int, frame, toInt);
990 990
991 // SVDEBUG << "SVFileReader::addPointToDataset: frame = " << frame << endl; 991 // SVDEBUG << "SVFileReader::addPointToDataset: frame = " << frame << endl;
992 992
993 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *> 993 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
994 (m_currentDataset); 994 (m_currentDataset);
995 995
996 if (sodm) { 996 if (sodm) {
997 // cerr << "Current dataset is a sparse one dimensional model" << endl; 997 // cerr << "Current dataset is a sparse one dimensional model" << endl;
998 QString label = attributes.value("label"); 998 QString label = attributes.value("label");
999 sodm->addPoint(SparseOneDimensionalModel::Point(frame, label)); 999 sodm->addPoint(SparseOneDimensionalModel::Point(frame, label));
1000 return true; 1000 return true;
1001 } 1001 }
1002 1002
1003 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *> 1003 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>
1004 (m_currentDataset); 1004 (m_currentDataset);
1005 1005
1006 if (stvm) { 1006 if (stvm) {
1007 // cerr << "Current dataset is a sparse time-value model" << endl; 1007 // cerr << "Current dataset is a sparse time-value model" << endl;
1008 float value = 0.0; 1008 float value = 0.0;
1009 value = attributes.value("value").trimmed().toFloat(&ok); 1009 value = attributes.value("value").trimmed().toFloat(&ok);
1010 QString label = attributes.value("label"); 1010 QString label = attributes.value("label");
1011 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label)); 1011 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label));
1012 return ok; 1012 return ok;
1013 } 1013 }
1014 1014
1015 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset); 1015 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset);
1016 1016
1017 if (nm) { 1017 if (nm) {
1018 // cerr << "Current dataset is a note model" << endl; 1018 // cerr << "Current dataset is a note model" << endl;
1019 float value = 0.0; 1019 float value = 0.0;
1020 value = attributes.value("value").trimmed().toFloat(&ok); 1020 value = attributes.value("value").trimmed().toFloat(&ok);
1021 int duration = 0; 1021 int duration = 0;
1022 duration = attributes.value("duration").trimmed().toInt(&ok); 1022 duration = attributes.value("duration").trimmed().toInt(&ok);
1023 QString label = attributes.value("label"); 1023 QString label = attributes.value("label");
1024 float level = attributes.value("level").trimmed().toFloat(&ok); 1024 float level = attributes.value("level").trimmed().toFloat(&ok);
1025 if (!ok) { // level is optional 1025 if (!ok) { // level is optional
1026 level = 1.f; 1026 level = 1.f;
1027 ok = true; 1027 ok = true;
1028 } 1028 }
1029 nm->addPoint(NoteModel::Point(frame, value, duration, level, label)); 1029 nm->addPoint(NoteModel::Point(frame, value, duration, level, label));
1030 return ok; 1030 return ok;
1031 } 1031 }
1032 1032
1033 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(m_currentDataset); 1033 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(m_currentDataset);
1034 1034
1035 if (fnm) { 1035 if (fnm) {
1036 // cerr << "Current dataset is a flexinote model" << endl; 1036 // cerr << "Current dataset is a flexinote model" << endl;
1037 float value = 0.0; 1037 float value = 0.0;
1038 value = attributes.value("value").trimmed().toFloat(&ok); 1038 value = attributes.value("value").trimmed().toFloat(&ok);
1039 int duration = 0; 1039 int duration = 0;
1040 duration = attributes.value("duration").trimmed().toInt(&ok); 1040 duration = attributes.value("duration").trimmed().toInt(&ok);
1041 QString label = attributes.value("label"); 1041 QString label = attributes.value("label");
1042 float level = attributes.value("level").trimmed().toFloat(&ok); 1042 float level = attributes.value("level").trimmed().toFloat(&ok);
1043 if (!ok) { // level is optional 1043 if (!ok) { // level is optional
1044 level = 1.f; 1044 level = 1.f;
1045 ok = true; 1045 ok = true;
1046 } 1046 }
1047 fnm->addPoint(FlexiNoteModel::Point(frame, value, duration, level, label)); 1047 fnm->addPoint(FlexiNoteModel::Point(frame, value, duration, level, label));
1048 return ok; 1048 return ok;
1049 } 1049 }
1050 1050
1051 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset); 1051 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset);
1052 1052
1053 if (rm) { 1053 if (rm) {
1054 // cerr << "Current dataset is a region model" << endl; 1054 // cerr << "Current dataset is a region model" << endl;
1055 float value = 0.0; 1055 float value = 0.0;
1056 value = attributes.value("value").trimmed().toFloat(&ok); 1056 value = attributes.value("value").trimmed().toFloat(&ok);
1057 int duration = 0; 1057 int duration = 0;
1058 duration = attributes.value("duration").trimmed().toInt(&ok); 1058 duration = attributes.value("duration").trimmed().toInt(&ok);
1059 QString label = attributes.value("label"); 1059 QString label = attributes.value("label");
1060 rm->addPoint(RegionModel::Point(frame, value, duration, label)); 1060 rm->addPoint(RegionModel::Point(frame, value, duration, label));
1061 return ok; 1061 return ok;
1062 } 1062 }
1063 1063
1064 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); 1064 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset);
1065 1065
1066 if (tm) { 1066 if (tm) {
1067 // cerr << "Current dataset is a text model" << endl; 1067 // cerr << "Current dataset is a text model" << endl;
1068 float height = 0.0; 1068 float height = 0.0;
1069 height = attributes.value("height").trimmed().toFloat(&ok); 1069 height = attributes.value("height").trimmed().toFloat(&ok);
1070 QString label = attributes.value("label"); 1070 QString label = attributes.value("label");
1071 // SVDEBUG << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label << ", ok = " << ok << endl; 1071 // SVDEBUG << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label << ", ok = " << ok << endl;
1072 tm->addPoint(TextModel::Point(frame, height, label)); 1072 tm->addPoint(TextModel::Point(frame, height, label));
1073 return ok; 1073 return ok;
1074 } 1074 }
1075 1075
1076 PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset); 1076 PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset);
1077 1077
1078 if (pm) { 1078 if (pm) {
1079 // cerr << "Current dataset is a path model" << endl; 1079 // cerr << "Current dataset is a path model" << endl;
1080 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok); 1080 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok);
1081 // SVDEBUG << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << endl; 1081 // SVDEBUG << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << endl;
1082 pm->addPoint(PathModel::Point(frame, mapframe)); 1082 pm->addPoint(PathModel::Point(frame, mapframe));
1083 return ok; 1083 return ok;
1084 } 1084 }
1085 1085
1086 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset); 1086 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset);
1087 1087
1088 if (im) { 1088 if (im) {
1089 // cerr << "Current dataset is an image model" << endl; 1089 // cerr << "Current dataset is an image model" << endl;
1090 QString image = attributes.value("image"); 1090 QString image = attributes.value("image");
1091 QString label = attributes.value("label"); 1091 QString label = attributes.value("label");
1092 // SVDEBUG << "SVFileReader::addPointToDataset: ImageModel: frame = " << frame << ", image = " << image << ", label = " << label << ", ok = " << ok << endl; 1092 // SVDEBUG << "SVFileReader::addPointToDataset: ImageModel: frame = " << frame << ", image = " << image << ", label = " << label << ", ok = " << ok << endl;
1093 im->addPoint(ImageModel::Point(frame, image, label)); 1093 im->addPoint(ImageModel::Point(frame, image, label));
1094 return ok; 1094 return ok;
1095 } 1095 }
1096 1096
1097 cerr << "WARNING: SV-XML: Point element found in non-point dataset" << endl; 1097 cerr << "WARNING: SV-XML: Point element found in non-point dataset" << endl;
1098 1098
1099 return false; 1099 return false;
1102 bool 1102 bool
1103 SVFileReader::addBinToDataset(const QXmlAttributes &attributes) 1103 SVFileReader::addBinToDataset(const QXmlAttributes &attributes)
1104 { 1104 {
1105 EditableDenseThreeDimensionalModel *dtdm = 1105 EditableDenseThreeDimensionalModel *dtdm =
1106 dynamic_cast<EditableDenseThreeDimensionalModel *> 1106 dynamic_cast<EditableDenseThreeDimensionalModel *>
1107 (m_currentDataset); 1107 (m_currentDataset);
1108 1108
1109 if (dtdm) { 1109 if (dtdm) {
1110 1110
1111 bool ok = false; 1111 bool ok = false;
1112 int n = attributes.value("number").trimmed().toInt(&ok); 1112 int n = attributes.value("number").trimmed().toInt(&ok);
1113 if (!ok) { 1113 if (!ok) {
1114 cerr << "WARNING: SV-XML: Missing or invalid bin number" 1114 cerr << "WARNING: SV-XML: Missing or invalid bin number"
1115 << endl; 1115 << endl;
1116 return false; 1116 return false;
1117 } 1117 }
1118 1118
1119 QString name = attributes.value("name"); 1119 QString name = attributes.value("name");
1120 1120
1121 dtdm->setBinName(n, name); 1121 dtdm->setBinName(n, name);
1122 return true; 1122 return true;
1123 } 1123 }
1124 1124
1125 cerr << "WARNING: SV-XML: Bin definition found in incompatible dataset" << endl; 1125 cerr << "WARNING: SV-XML: Bin definition found in incompatible dataset" << endl;
1126 1126
1127 return false; 1127 return false;
1134 m_inRow = false; 1134 m_inRow = false;
1135 1135
1136 bool ok = false; 1136 bool ok = false;
1137 m_rowNumber = attributes.value("n").trimmed().toInt(&ok); 1137 m_rowNumber = attributes.value("n").trimmed().toInt(&ok);
1138 if (!ok) { 1138 if (!ok) {
1139 cerr << "WARNING: SV-XML: Missing or invalid row number" 1139 cerr << "WARNING: SV-XML: Missing or invalid row number"
1140 << endl; 1140 << endl;
1141 return false; 1141 return false;
1142 } 1142 }
1143 1143
1144 m_inRow = true; 1144 m_inRow = true;
1145 1145
1146 // cerr << "SV-XML: In row " << m_rowNumber << endl; 1146 // cerr << "SV-XML: In row " << m_rowNumber << endl;
1151 bool 1151 bool
1152 SVFileReader::readRowData(const QString &text) 1152 SVFileReader::readRowData(const QString &text)
1153 { 1153 {
1154 EditableDenseThreeDimensionalModel *dtdm = 1154 EditableDenseThreeDimensionalModel *dtdm =
1155 dynamic_cast<EditableDenseThreeDimensionalModel *> 1155 dynamic_cast<EditableDenseThreeDimensionalModel *>
1156 (m_currentDataset); 1156 (m_currentDataset);
1157 1157
1158 bool warned = false; 1158 bool warned = false;
1159 1159
1160 if (dtdm) { 1160 if (dtdm) {
1161 QStringList data = text.split(m_datasetSeparator); 1161 QStringList data = text.split(m_datasetSeparator);
1162 1162
1163 DenseThreeDimensionalModel::Column values; 1163 DenseThreeDimensionalModel::Column values;
1164 1164
1165 for (QStringList::iterator i = data.begin(); i != data.end(); ++i) { 1165 for (QStringList::iterator i = data.begin(); i != data.end(); ++i) {
1166 1166
1167 if (int(values.size()) == dtdm->getHeight()) { 1167 if (int(values.size()) == dtdm->getHeight()) {
1168 if (!warned) { 1168 if (!warned) {
1169 cerr << "WARNING: SV-XML: Too many y-bins in 3-D dataset row " 1169 cerr << "WARNING: SV-XML: Too many y-bins in 3-D dataset row "
1170 << m_rowNumber << endl; 1170 << m_rowNumber << endl;
1171 warned = true; 1171 warned = true;
1172 } 1172 }
1173 } 1173 }
1174 1174
1175 bool ok; 1175 bool ok;
1176 float value = i->toFloat(&ok); 1176 float value = i->toFloat(&ok);
1177 if (!ok) { 1177 if (!ok) {
1178 cerr << "WARNING: SV-XML: Bad floating-point value " 1178 cerr << "WARNING: SV-XML: Bad floating-point value "
1179 << i->toLocal8Bit().data() 1179 << i->toLocal8Bit().data()
1180 << " in row data" << endl; 1180 << " in row data" << endl;
1181 } else { 1181 } else {
1182 values.push_back(value); 1182 values.push_back(value);
1183 } 1183 }
1184 } 1184 }
1185 1185
1186 dtdm->setColumn(m_rowNumber, values); 1186 dtdm->setColumn(m_rowNumber, values);
1187 return true; 1187 return true;
1188 } 1188 }
1189 1189
1190 cerr << "WARNING: SV-XML: Row data found in non-row dataset" << endl; 1190 cerr << "WARNING: SV-XML: Row data found in non-row dataset" << endl;
1191 1191
1192 return false; 1192 return false;
1198 int modelId = 0; 1198 int modelId = 0;
1199 bool modelOk = false; 1199 bool modelOk = false;
1200 modelId = attributes.value("model").trimmed().toInt(&modelOk); 1200 modelId = attributes.value("model").trimmed().toInt(&modelOk);
1201 1201
1202 if (!modelOk) { 1202 if (!modelOk) {
1203 cerr << "WARNING: SV-XML: No model id specified for derivation" << endl; 1203 cerr << "WARNING: SV-XML: No model id specified for derivation" << endl;
1204 return false; 1204 return false;
1205 } 1205 }
1206 1206
1207 if (haveModel(modelId)) { 1207 if (haveModel(modelId)) {
1208 m_currentDerivedModel = m_models[modelId]; 1208 m_currentDerivedModel = m_models[modelId];
1209 } else { 1209 } else {
1292 int modelId = 0; 1292 int modelId = 0;
1293 bool modelOk = false; 1293 bool modelOk = false;
1294 modelId = attributes.value("model").trimmed().toInt(&modelOk); 1294 modelId = attributes.value("model").trimmed().toInt(&modelOk);
1295 1295
1296 if (!modelOk) { 1296 if (!modelOk) {
1297 cerr << "WARNING: SV-XML: No model id specified for play parameters" << endl; 1297 cerr << "WARNING: SV-XML: No model id specified for play parameters" << endl;
1298 return false; 1298 return false;
1299 } 1299 }
1300 1300
1301 if (haveModel(modelId)) { 1301 if (haveModel(modelId)) {
1302 1302
1303 bool ok = false; 1303 bool ok = false;
1329 1329
1330 // cerr << "Current play parameters for model: " << m_models[modelId] << ": " << m_currentPlayParameters << endl; 1330 // cerr << "Current play parameters for model: " << m_models[modelId] << ": " << m_currentPlayParameters << endl;
1331 1331
1332 } else { 1332 } else {
1333 1333
1334 cerr << "WARNING: SV-XML: Unknown model " << modelId 1334 cerr << "WARNING: SV-XML: Unknown model " << modelId
1335 << " for play parameters" << endl; 1335 << " for play parameters" << endl;
1336 return false; 1336 return false;
1337 } 1337 }
1338 1338
1339 return true; 1339 return true;
1340 } 1340 }
1475 } 1475 }
1476 1476
1477 SVFileReader::FileType getType() const { return m_type; } 1477 SVFileReader::FileType getType() const { return m_type; }
1478 1478
1479 virtual bool startElement(const QString &, 1479 virtual bool startElement(const QString &,
1480 const QString &, 1480 const QString &,
1481 const QString &qName, 1481 const QString &qName,
1482 const QXmlAttributes& atts) 1482 const QXmlAttributes& atts)
1483 { 1483 {
1484 QString name = qName.toLower(); 1484 QString name = qName.toLower();
1485 1485
1486 // SV session files have an sv element containing a data 1486 // SV session files have an sv element containing a data
1487 // element containing a model element with mainModel="true". 1487 // element containing a model element with mainModel="true".
1511 } 1511 }
1512 return true; 1512 return true;
1513 } 1513 }
1514 1514
1515 virtual bool endElement(const QString &, 1515 virtual bool endElement(const QString &,
1516 const QString &, 1516 const QString &,
1517 const QString &qName) 1517 const QString &qName)
1518 { 1518 {
1519 QString name = qName.toLower(); 1519 QString name = qName.toLower();
1520 1520
1521 if (name == "sv") { 1521 if (name == "sv") {
1522 if (m_inSv) { 1522 if (m_inSv) {