comparison framework/SVFileReader.cpp @ 601:021d42e6c8cb

Avoid setting the session file path when loading an incomplete document, so that the default-file save-on-exit and File->Save are not activated (to avoid losing references to unfound audio files)
author Chris Cannam
date Mon, 18 Jun 2018 14:16:06 +0100
parents b23bebfdfaba
children 15a566f26114
comparison
equal deleted inserted replaced
600:ca96a514fbbb 601:021d42e6c8cb
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 SVCERR << "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;
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 SVCERR << "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());
239 } else if (name == "parameter") { 239 } else if (name == "parameter") {
240 240
241 ok = readParameter(attributes); 241 ok = readParameter(attributes);
242 242
243 } else { 243 } else {
244 cerr << "WARNING: SV-XML: Unexpected element \"" 244 SVCERR << "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 SVCERR << "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 }
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 SVCERR << "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 }
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 SVCERR << "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
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) {
309 cerr << "WARNING: SV-XML: Bad derivation output model id " 309 SVCERR << "WARNING: SV-XML: Bad derivation output model id "
310 << m_currentDerivedModelId << endl; 310 << m_currentDerivedModelId << endl;
311 } else if (haveModel(m_currentDerivedModelId)) { 311 } else if (haveModel(m_currentDerivedModelId)) {
312 cerr << "WARNING: SV-XML: Derivation has existing model " 312 SVCERR << "WARNING: SV-XML: Derivation has existing model "
313 << m_currentDerivedModelId 313 << m_currentDerivedModelId
314 << " as target, not regenerating" << endl; 314 << " as target, not regenerating" << endl;
315 } else { 315 } else {
316 QString message; 316 QString message;
317 m_currentDerivedModel = m_models[m_currentDerivedModelId] = 317 m_currentDerivedModel = m_models[m_currentDerivedModelId] =
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 SVCERR << 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)
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 SVCERR << 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 SVCERR << "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 &)
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 SVCERR << "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");
467 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000); 467 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000);
468 FileSource file(path, &dialog); 468 FileSource file(path, &dialog);
469 file.waitForStatus(); 469 file.waitForStatus();
470 470
471 if (!file.isOK()) { 471 if (!file.isOK()) {
472 cerr << "SVFileReader::readModel: Failed to retrieve file \"" << path << "\" for wave file model: " << file.getErrorString() << endl; 472 SVCERR << "SVFileReader::readModel: Failed to retrieve file \"" << path << "\" for wave file model: " << file.getErrorString() << endl;
473 } else if (!file.isAvailable()) { 473 } else if (!file.isAvailable()) {
474 cerr << "SVFileReader::readModel: Failed to retrieve file \"" << path << "\" for wave file model: Source unavailable" << endl; 474 SVCERR << "SVFileReader::readModel: Failed to retrieve file \"" << path << "\" for wave file model: Source unavailable" << endl;
475 } else { 475 } else {
476 476
477 file.waitForData(); 477 file.waitForData();
478 478
479 sv_samplerate_t rate = sampleRate; 479 sv_samplerate_t rate = sampleRate;
492 delete model; 492 delete model;
493 model = 0; 493 model = 0;
494 } 494 }
495 } 495 }
496 496
497 if (!model) return false; 497 if (!model) {
498 m_document->setIncomplete(true);
499 return false;
500 }
498 501
499 model->setObjectName(name); 502 model->setObjectName(name);
500 m_models[id] = model; 503 m_models[id] = model;
501 if (isMainModel) { 504 if (isMainModel) {
502 m_document->setMainModel(model); 505 m_document->setMainModel(model);
542 m_models[id] = model; 545 m_models[id] = model;
543 return true; 546 return true;
544 547
545 } else { 548 } else {
546 549
547 cerr << "WARNING: SV-XML: Unexpected dense model dimension (" 550 SVCERR << "WARNING: SV-XML: Unexpected dense model dimension ("
548 << dimensions << ")" << endl; 551 << dimensions << ")" << endl;
549 } 552 }
550 } else if (type == "sparse") { 553 } else if (type == "sparse") {
551 554
552 READ_MANDATORY(int, dimensions, toInt); 555 READ_MANDATORY(int, dimensions, toInt);
667 670
668 return true; 671 return true;
669 672
670 } else { 673 } else {
671 674
672 cerr << "WARNING: SV-XML: Unexpected sparse model dimension (" 675 SVCERR << "WARNING: SV-XML: Unexpected sparse model dimension ("
673 << dimensions << ")" << endl; 676 << dimensions << ")" << endl;
674 } 677 }
675 678
676 } else if (type == "alignment") { 679 } else if (type == "alignment") {
677 680
682 Model *refModel = 0, *alignedModel = 0, *pathModel = 0; 685 Model *refModel = 0, *alignedModel = 0, *pathModel = 0;
683 686
684 if (m_models.find(reference) != m_models.end()) { 687 if (m_models.find(reference) != m_models.end()) {
685 refModel = m_models[reference]; 688 refModel = m_models[reference];
686 } else { 689 } else {
687 cerr << "WARNING: SV-XML: Unknown reference model id " 690 SVCERR << "WARNING: SV-XML: Unknown reference model id "
688 << reference << " in alignment model id " << id 691 << reference << " in alignment model id " << id
689 << endl; 692 << endl;
690 } 693 }
691 694
692 if (m_models.find(aligned) != m_models.end()) { 695 if (m_models.find(aligned) != m_models.end()) {
693 alignedModel = m_models[aligned]; 696 alignedModel = m_models[aligned];
694 } else { 697 } else {
695 cerr << "WARNING: SV-XML: Unknown aligned model id " 698 SVCERR << "WARNING: SV-XML: Unknown aligned model id "
696 << aligned << " in alignment model id " << id 699 << aligned << " in alignment model id " << id
697 << endl; 700 << endl;
698 } 701 }
699 702
700 if (m_models.find(path) != m_models.end()) { 703 if (m_models.find(path) != m_models.end()) {
701 pathModel = m_models[path]; 704 pathModel = m_models[path];
702 } else { 705 } else {
703 cerr << "WARNING: SV-XML: Unknown path model id " 706 SVCERR << "WARNING: SV-XML: Unknown path model id "
704 << path << " in alignment model id " << id 707 << path << " in alignment model id " << id
705 << endl; 708 << endl;
706 } 709 }
707 710
708 if (refModel && alignedModel && pathModel) { 711 if (refModel && alignedModel && pathModel) {
709 AlignmentModel *model = new AlignmentModel 712 AlignmentModel *model = new AlignmentModel
710 (refModel, alignedModel, 0, 0); 713 (refModel, alignedModel, 0, 0);
711 PathModel *pm = dynamic_cast<PathModel *>(pathModel); 714 PathModel *pm = dynamic_cast<PathModel *>(pathModel);
712 if (!pm) { 715 if (!pm) {
713 cerr << "WARNING: SV-XML: Model id " << path 716 SVCERR << "WARNING: SV-XML: Model id " << path
714 << " referenced as path for alignment " << id 717 << " referenced as path for alignment " << id
715 << " is not a path model" << endl; 718 << " is not a path model" << endl;
716 } else { 719 } else {
717 model->setPath(pm); 720 model->setPath(pm);
718 pm->setCompletion(100); 721 pm->setCompletion(100);
737 { 740 {
738 QString type = attributes.value("type"); 741 QString type = attributes.value("type");
739 m_currentPane = 0; 742 m_currentPane = 0;
740 743
741 if (type != "pane") { 744 if (type != "pane") {
742 cerr << "WARNING: SV-XML: Unexpected view type \"" 745 SVCERR << "WARNING: SV-XML: Unexpected view type \""
743 << type << "\"" << endl; 746 << type << "\"" << endl;
744 return false; 747 return false;
745 } 748 }
746 749
747 m_currentPane = m_paneCallback.addPane(); 750 m_currentPane = m_paneCallback.addPane();
748 751
749 cerr << "SVFileReader::addPane: pane is " << m_currentPane << endl; 752 SVCERR << "SVFileReader::addPane: pane is " << m_currentPane << endl;
750 753
751 if (!m_currentPane) { 754 if (!m_currentPane) {
752 cerr << "WARNING: SV-XML: Internal error: Failed to add pane!" 755 SVCERR << "WARNING: SV-XML: Internal error: Failed to add pane!"
753 << endl; 756 << endl;
754 return false; 757 return false;
755 } 758 }
756 759
757 bool ok = false; 760 bool ok = false;
798 int id; 801 int id;
799 bool ok = false; 802 bool ok = false;
800 id = attributes.value("id").trimmed().toInt(&ok); 803 id = attributes.value("id").trimmed().toInt(&ok);
801 804
802 if (!ok) { 805 if (!ok) {
803 cerr << "WARNING: SV-XML: No layer id for layer of type \"" 806 SVCERR << "WARNING: SV-XML: No layer id for layer of type \""
804 << type 807 << type
805 << "\"" << endl; 808 << "\"" << endl;
806 return false; 809 return false;
807 } 810 }
808 811
816 // expect it to exist. 819 // expect it to exist.
817 820
818 if (m_inData) { 821 if (m_inData) {
819 822
820 if (m_layers.find(id) != m_layers.end()) { 823 if (m_layers.find(id) != m_layers.end()) {
821 cerr << "WARNING: SV-XML: Ignoring duplicate layer id " << id 824 SVCERR << "WARNING: SV-XML: Ignoring duplicate layer id " << id
822 << " in data section" << endl; 825 << " in data section" << endl;
823 return false; 826 return false;
824 } 827 }
825 828
826 layer = m_layers[id] = m_document->createLayer 829 layer = m_layers[id] = m_document->createLayer
832 } 835 }
833 836
834 } else { 837 } else {
835 838
836 if (!m_currentPane) { 839 if (!m_currentPane) {
837 cerr << "WARNING: SV-XML: No current pane for layer " << id 840 SVCERR << "WARNING: SV-XML: No current pane for layer " << id
838 << " in view section" << endl; 841 << " in view section" << endl;
839 return false; 842 return false;
840 } 843 }
841 844
842 if (m_layers.find(id) != m_layers.end()) { 845 if (m_layers.find(id) != m_layers.end()) {
843 846
844 layer = m_layers[id]; 847 layer = m_layers[id];
845 848
846 } else { 849 } else {
847 cerr << "WARNING: SV-XML: Layer id " << id 850 SVCERR << "WARNING: SV-XML: Layer id " << id
848 << " in view section has not been defined -- defining it here" 851 << " in view section has not been defined -- defining it here"
849 << endl; 852 << endl;
850 853
851 layer = m_document->createLayer 854 layer = m_document->createLayer
852 (LayerFactory::getInstance()->getLayerTypeForName(type)); 855 (LayerFactory::getInstance()->getLayerTypeForName(type));
857 } 860 }
858 } 861 }
859 } 862 }
860 863
861 if (!layer) { 864 if (!layer) {
862 cerr << "WARNING: SV-XML: Failed to add layer of type \"" 865 SVCERR << "WARNING: SV-XML: Failed to add layer of type \""
863 << type 866 << type
864 << "\"" << endl; 867 << "\"" << endl;
865 return false; 868 return false;
866 } 869 }
867 870
880 if (modelOk) { 883 if (modelOk) {
881 if (haveModel(modelId)) { 884 if (haveModel(modelId)) {
882 Model *model = m_models[modelId]; 885 Model *model = m_models[modelId];
883 m_document->setModel(layer, model); 886 m_document->setModel(layer, model);
884 } else { 887 } else {
885 cerr << "WARNING: SV-XML: Unknown model id " << modelId 888 SVCERR << "WARNING: SV-XML: Unknown model id " << modelId
886 << " in layer definition" << endl; 889 << " in layer definition" << endl;
887 if (!layer->canExistWithoutModel()) { 890 if (!layer->canExistWithoutModel()) {
888 // Don't add a layer with an unknown model id 891 // Don't add a layer with an unknown model id
889 // unless it explicitly supports this state 892 // unless it explicitly supports this state
890 m_document->deleteLayer(layer); 893 m_document->deleteLayer(layer);
929 932
930 READ_MANDATORY(int, id, toInt); 933 READ_MANDATORY(int, id, toInt);
931 READ_MANDATORY(int, dimensions, toInt); 934 READ_MANDATORY(int, dimensions, toInt);
932 935
933 if (m_awaitingDatasets.find(id) == m_awaitingDatasets.end()) { 936 if (m_awaitingDatasets.find(id) == m_awaitingDatasets.end()) {
934 cerr << "WARNING: SV-XML: Unwanted dataset " << id << endl; 937 SVCERR << "WARNING: SV-XML: Unwanted dataset " << id << endl;
935 return false; 938 return false;
936 } 939 }
937 940
938 int modelId = m_awaitingDatasets[id]; 941 int modelId = m_awaitingDatasets[id];
939 942
940 Model *model = 0; 943 Model *model = 0;
941 if (haveModel(modelId)) { 944 if (haveModel(modelId)) {
942 model = m_models[modelId]; 945 model = m_models[modelId];
943 } else { 946 } else {
944 cerr << "WARNING: SV-XML: Internal error: Unknown model " << modelId 947 SVCERR << "WARNING: SV-XML: Internal error: Unknown model " << modelId
945 << " expecting dataset " << id << endl; 948 << " expecting dataset " << id << endl;
946 return false; 949 return false;
947 } 950 }
948 951
949 bool good = false; 952 bool good = false;
970 } 973 }
971 break; 974 break;
972 } 975 }
973 976
974 if (!good) { 977 if (!good) {
975 cerr << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions or inappropriate type for " << dimensions << "-D dataset " << id << endl; 978 SVCERR << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions or inappropriate type for " << dimensions << "-D dataset " << id << endl;
976 m_currentDataset = 0; 979 m_currentDataset = 0;
977 return false; 980 return false;
978 } 981 }
979 982
980 m_currentDataset = model; 983 m_currentDataset = model;
992 995
993 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *> 996 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
994 (m_currentDataset); 997 (m_currentDataset);
995 998
996 if (sodm) { 999 if (sodm) {
997 // cerr << "Current dataset is a sparse one dimensional model" << endl; 1000 // SVCERR << "Current dataset is a sparse one dimensional model" << endl;
998 QString label = attributes.value("label"); 1001 QString label = attributes.value("label");
999 sodm->addPoint(SparseOneDimensionalModel::Point(frame, label)); 1002 sodm->addPoint(SparseOneDimensionalModel::Point(frame, label));
1000 return true; 1003 return true;
1001 } 1004 }
1002 1005
1003 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *> 1006 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>
1004 (m_currentDataset); 1007 (m_currentDataset);
1005 1008
1006 if (stvm) { 1009 if (stvm) {
1007 // cerr << "Current dataset is a sparse time-value model" << endl; 1010 // SVCERR << "Current dataset is a sparse time-value model" << endl;
1008 float value = 0.0; 1011 float value = 0.0;
1009 value = attributes.value("value").trimmed().toFloat(&ok); 1012 value = attributes.value("value").trimmed().toFloat(&ok);
1010 QString label = attributes.value("label"); 1013 QString label = attributes.value("label");
1011 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label)); 1014 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label));
1012 return ok; 1015 return ok;
1013 } 1016 }
1014 1017
1015 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset); 1018 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset);
1016 1019
1017 if (nm) { 1020 if (nm) {
1018 // cerr << "Current dataset is a note model" << endl; 1021 // SVCERR << "Current dataset is a note model" << endl;
1019 float value = 0.0; 1022 float value = 0.0;
1020 value = attributes.value("value").trimmed().toFloat(&ok); 1023 value = attributes.value("value").trimmed().toFloat(&ok);
1021 int duration = 0; 1024 int duration = 0;
1022 duration = attributes.value("duration").trimmed().toInt(&ok); 1025 duration = attributes.value("duration").trimmed().toInt(&ok);
1023 QString label = attributes.value("label"); 1026 QString label = attributes.value("label");
1031 } 1034 }
1032 1035
1033 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(m_currentDataset); 1036 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(m_currentDataset);
1034 1037
1035 if (fnm) { 1038 if (fnm) {
1036 // cerr << "Current dataset is a flexinote model" << endl; 1039 // SVCERR << "Current dataset is a flexinote model" << endl;
1037 float value = 0.0; 1040 float value = 0.0;
1038 value = attributes.value("value").trimmed().toFloat(&ok); 1041 value = attributes.value("value").trimmed().toFloat(&ok);
1039 int duration = 0; 1042 int duration = 0;
1040 duration = attributes.value("duration").trimmed().toInt(&ok); 1043 duration = attributes.value("duration").trimmed().toInt(&ok);
1041 QString label = attributes.value("label"); 1044 QString label = attributes.value("label");
1049 } 1052 }
1050 1053
1051 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset); 1054 RegionModel *rm = dynamic_cast<RegionModel *>(m_currentDataset);
1052 1055
1053 if (rm) { 1056 if (rm) {
1054 // cerr << "Current dataset is a region model" << endl; 1057 // SVCERR << "Current dataset is a region model" << endl;
1055 float value = 0.0; 1058 float value = 0.0;
1056 value = attributes.value("value").trimmed().toFloat(&ok); 1059 value = attributes.value("value").trimmed().toFloat(&ok);
1057 int duration = 0; 1060 int duration = 0;
1058 duration = attributes.value("duration").trimmed().toInt(&ok); 1061 duration = attributes.value("duration").trimmed().toInt(&ok);
1059 QString label = attributes.value("label"); 1062 QString label = attributes.value("label");
1062 } 1065 }
1063 1066
1064 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); 1067 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset);
1065 1068
1066 if (tm) { 1069 if (tm) {
1067 // cerr << "Current dataset is a text model" << endl; 1070 // SVCERR << "Current dataset is a text model" << endl;
1068 float height = 0.0; 1071 float height = 0.0;
1069 height = attributes.value("height").trimmed().toFloat(&ok); 1072 height = attributes.value("height").trimmed().toFloat(&ok);
1070 QString label = attributes.value("label"); 1073 QString label = attributes.value("label");
1071 // SVDEBUG << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label << ", ok = " << ok << endl; 1074 // SVDEBUG << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label << ", ok = " << ok << endl;
1072 tm->addPoint(TextModel::Point(frame, height, label)); 1075 tm->addPoint(TextModel::Point(frame, height, label));
1074 } 1077 }
1075 1078
1076 PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset); 1079 PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset);
1077 1080
1078 if (pm) { 1081 if (pm) {
1079 // cerr << "Current dataset is a path model" << endl; 1082 // SVCERR << "Current dataset is a path model" << endl;
1080 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok); 1083 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok);
1081 // SVDEBUG << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << endl; 1084 // SVDEBUG << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << endl;
1082 pm->addPoint(PathModel::Point(frame, mapframe)); 1085 pm->addPoint(PathModel::Point(frame, mapframe));
1083 return ok; 1086 return ok;
1084 } 1087 }
1085 1088
1086 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset); 1089 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset);
1087 1090
1088 if (im) { 1091 if (im) {
1089 // cerr << "Current dataset is an image model" << endl; 1092 // SVCERR << "Current dataset is an image model" << endl;
1090 QString image = attributes.value("image"); 1093 QString image = attributes.value("image");
1091 QString label = attributes.value("label"); 1094 QString label = attributes.value("label");
1092 // SVDEBUG << "SVFileReader::addPointToDataset: ImageModel: frame = " << frame << ", image = " << image << ", label = " << label << ", ok = " << ok << endl; 1095 // SVDEBUG << "SVFileReader::addPointToDataset: ImageModel: frame = " << frame << ", image = " << image << ", label = " << label << ", ok = " << ok << endl;
1093 im->addPoint(ImageModel::Point(frame, image, label)); 1096 im->addPoint(ImageModel::Point(frame, image, label));
1094 return ok; 1097 return ok;
1095 } 1098 }
1096 1099
1097 cerr << "WARNING: SV-XML: Point element found in non-point dataset" << endl; 1100 SVCERR << "WARNING: SV-XML: Point element found in non-point dataset" << endl;
1098 1101
1099 return false; 1102 return false;
1100 } 1103 }
1101 1104
1102 bool 1105 bool
1109 if (dtdm) { 1112 if (dtdm) {
1110 1113
1111 bool ok = false; 1114 bool ok = false;
1112 int n = attributes.value("number").trimmed().toInt(&ok); 1115 int n = attributes.value("number").trimmed().toInt(&ok);
1113 if (!ok) { 1116 if (!ok) {
1114 cerr << "WARNING: SV-XML: Missing or invalid bin number" 1117 SVCERR << "WARNING: SV-XML: Missing or invalid bin number"
1115 << endl; 1118 << endl;
1116 return false; 1119 return false;
1117 } 1120 }
1118 1121
1119 QString name = attributes.value("name"); 1122 QString name = attributes.value("name");
1120 1123
1121 dtdm->setBinName(n, name); 1124 dtdm->setBinName(n, name);
1122 return true; 1125 return true;
1123 } 1126 }
1124 1127
1125 cerr << "WARNING: SV-XML: Bin definition found in incompatible dataset" << endl; 1128 SVCERR << "WARNING: SV-XML: Bin definition found in incompatible dataset" << endl;
1126 1129
1127 return false; 1130 return false;
1128 } 1131 }
1129 1132
1130 1133
1134 m_inRow = false; 1137 m_inRow = false;
1135 1138
1136 bool ok = false; 1139 bool ok = false;
1137 m_rowNumber = attributes.value("n").trimmed().toInt(&ok); 1140 m_rowNumber = attributes.value("n").trimmed().toInt(&ok);
1138 if (!ok) { 1141 if (!ok) {
1139 cerr << "WARNING: SV-XML: Missing or invalid row number" 1142 SVCERR << "WARNING: SV-XML: Missing or invalid row number"
1140 << endl; 1143 << endl;
1141 return false; 1144 return false;
1142 } 1145 }
1143 1146
1144 m_inRow = true; 1147 m_inRow = true;
1145 1148
1146 // cerr << "SV-XML: In row " << m_rowNumber << endl; 1149 // SVCERR << "SV-XML: In row " << m_rowNumber << endl;
1147 1150
1148 return true; 1151 return true;
1149 } 1152 }
1150 1153
1151 bool 1154 bool
1164 1167
1165 for (QStringList::iterator i = data.begin(); i != data.end(); ++i) { 1168 for (QStringList::iterator i = data.begin(); i != data.end(); ++i) {
1166 1169
1167 if (int(values.size()) == dtdm->getHeight()) { 1170 if (int(values.size()) == dtdm->getHeight()) {
1168 if (!warned) { 1171 if (!warned) {
1169 cerr << "WARNING: SV-XML: Too many y-bins in 3-D dataset row " 1172 SVCERR << "WARNING: SV-XML: Too many y-bins in 3-D dataset row "
1170 << m_rowNumber << endl; 1173 << m_rowNumber << endl;
1171 warned = true; 1174 warned = true;
1172 } 1175 }
1173 } 1176 }
1174 1177
1175 bool ok; 1178 bool ok;
1176 float value = i->toFloat(&ok); 1179 float value = i->toFloat(&ok);
1177 if (!ok) { 1180 if (!ok) {
1178 cerr << "WARNING: SV-XML: Bad floating-point value " 1181 SVCERR << "WARNING: SV-XML: Bad floating-point value "
1179 << i->toLocal8Bit().data() 1182 << i->toLocal8Bit().data()
1180 << " in row data" << endl; 1183 << " in row data" << endl;
1181 } else { 1184 } else {
1182 values.push_back(value); 1185 values.push_back(value);
1183 } 1186 }
1185 1188
1186 dtdm->setColumn(m_rowNumber, values); 1189 dtdm->setColumn(m_rowNumber, values);
1187 return true; 1190 return true;
1188 } 1191 }
1189 1192
1190 cerr << "WARNING: SV-XML: Row data found in non-row dataset" << endl; 1193 SVCERR << "WARNING: SV-XML: Row data found in non-row dataset" << endl;
1191 1194
1192 return false; 1195 return false;
1193 } 1196 }
1194 1197
1195 bool 1198 bool
1198 int modelId = 0; 1201 int modelId = 0;
1199 bool modelOk = false; 1202 bool modelOk = false;
1200 modelId = attributes.value("model").trimmed().toInt(&modelOk); 1203 modelId = attributes.value("model").trimmed().toInt(&modelOk);
1201 1204
1202 if (!modelOk) { 1205 if (!modelOk) {
1203 cerr << "WARNING: SV-XML: No model id specified for derivation" << endl; 1206 SVCERR << "WARNING: SV-XML: No model id specified for derivation" << endl;
1204 return false; 1207 return false;
1205 } 1208 }
1206 1209
1207 if (haveModel(modelId)) { 1210 if (haveModel(modelId)) {
1208 m_currentDerivedModel = m_models[modelId]; 1211 m_currentDerivedModel = m_models[modelId];
1292 int modelId = 0; 1295 int modelId = 0;
1293 bool modelOk = false; 1296 bool modelOk = false;
1294 modelId = attributes.value("model").trimmed().toInt(&modelOk); 1297 modelId = attributes.value("model").trimmed().toInt(&modelOk);
1295 1298
1296 if (!modelOk) { 1299 if (!modelOk) {
1297 cerr << "WARNING: SV-XML: No model id specified for play parameters" << endl; 1300 SVCERR << "WARNING: SV-XML: No model id specified for play parameters" << endl;
1298 return false; 1301 return false;
1299 } 1302 }
1300 1303
1301 if (haveModel(modelId)) { 1304 if (haveModel(modelId)) {
1302 1305
1304 1307
1305 PlayParameters *parameters = PlayParameterRepository::getInstance()-> 1308 PlayParameters *parameters = PlayParameterRepository::getInstance()->
1306 getPlayParameters(m_models[modelId]); 1309 getPlayParameters(m_models[modelId]);
1307 1310
1308 if (!parameters) { 1311 if (!parameters) {
1309 cerr << "WARNING: SV-XML: Play parameters for model " 1312 SVCERR << "WARNING: SV-XML: Play parameters for model "
1310 << modelId 1313 << modelId
1311 << " not found - has model been added to document?" 1314 << " not found - has model been added to document?"
1312 << endl; 1315 << endl;
1313 return false; 1316 return false;
1314 } 1317 }
1325 QString clipId = attributes.value("clipId"); 1328 QString clipId = attributes.value("clipId");
1326 if (clipId != "") parameters->setPlayClipId(clipId); 1329 if (clipId != "") parameters->setPlayClipId(clipId);
1327 1330
1328 m_currentPlayParameters = parameters; 1331 m_currentPlayParameters = parameters;
1329 1332
1330 // cerr << "Current play parameters for model: " << m_models[modelId] << ": " << m_currentPlayParameters << endl; 1333 // SVCERR << "Current play parameters for model: " << m_models[modelId] << ": " << m_currentPlayParameters << endl;
1331 1334
1332 } else { 1335 } else {
1333 1336
1334 cerr << "WARNING: SV-XML: Unknown model " << modelId 1337 SVCERR << "WARNING: SV-XML: Unknown model " << modelId
1335 << " for play parameters" << endl; 1338 << " for play parameters" << endl;
1336 return false; 1339 return false;
1337 } 1340 }
1338 1341
1339 return true; 1342 return true;
1345 if (m_currentDerivedModelId >= 0) { 1348 if (m_currentDerivedModelId >= 0) {
1346 return readPluginForTransform(attributes); 1349 return readPluginForTransform(attributes);
1347 } else if (m_currentPlayParameters) { 1350 } else if (m_currentPlayParameters) {
1348 return readPluginForPlayback(attributes); 1351 return readPluginForPlayback(attributes);
1349 } else { 1352 } else {
1350 cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << endl; 1353 SVCERR << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << endl;
1351 return false; 1354 return false;
1352 } 1355 }
1353 } 1356 }
1354 1357
1355 bool 1358 bool
1392 1395
1393 bool 1396 bool
1394 SVFileReader::readTransform(const QXmlAttributes &attributes) 1397 SVFileReader::readTransform(const QXmlAttributes &attributes)
1395 { 1398 {
1396 if (m_currentDerivedModelId < 0) { 1399 if (m_currentDerivedModelId < 0) {
1397 cerr << "WARNING: SV-XML: Transform found outside derivation" << endl; 1400 SVCERR << "WARNING: SV-XML: Transform found outside derivation" << endl;
1398 return false; 1401 return false;
1399 } 1402 }
1400 1403
1401 m_currentTransform = Transform(); 1404 m_currentTransform = Transform();
1402 m_currentTransform.setFromXmlAttributes(attributes); 1405 m_currentTransform.setFromXmlAttributes(attributes);
1405 1408
1406 bool 1409 bool
1407 SVFileReader::readParameter(const QXmlAttributes &attributes) 1410 SVFileReader::readParameter(const QXmlAttributes &attributes)
1408 { 1411 {
1409 if (m_currentDerivedModelId < 0) { 1412 if (m_currentDerivedModelId < 0) {
1410 cerr << "WARNING: SV-XML: Parameter found outside derivation" << endl; 1413 SVCERR << "WARNING: SV-XML: Parameter found outside derivation" << endl;
1411 return false; 1414 return false;
1412 } 1415 }
1413 1416
1414 QString name = attributes.value("name"); 1417 QString name = attributes.value("name");
1415 if (name == "") { 1418 if (name == "") {
1416 cerr << "WARNING: SV-XML: Ignoring nameless transform parameter" 1419 SVCERR << "WARNING: SV-XML: Ignoring nameless transform parameter"
1417 << endl; 1420 << endl;
1418 return false; 1421 return false;
1419 } 1422 }
1420 1423
1421 float value = attributes.value("value").trimmed().toFloat(); 1424 float value = attributes.value("value").trimmed().toFloat();
1442 { 1445 {
1443 SVDEBUG << "SVFileReader::readMeasurement: inLayer " 1446 SVDEBUG << "SVFileReader::readMeasurement: inLayer "
1444 << m_inLayer << ", layer " << m_currentLayer << endl; 1447 << m_inLayer << ", layer " << m_currentLayer << endl;
1445 1448
1446 if (!m_inLayer) { 1449 if (!m_inLayer) {
1447 cerr << "WARNING: SV-XML: Measurement found outside layer" << endl; 1450 SVCERR << "WARNING: SV-XML: Measurement found outside layer" << endl;
1448 return false; 1451 return false;
1449 } 1452 }
1450 1453
1451 m_currentLayer->addMeasurementRect(attributes); 1454 m_currentLayer->addMeasurementRect(attributes);
1452 return true; 1455 return true;