comparison document/SVFileReader.cpp @ 186:7b943924b8d3

* Phase 1 of an image layer.
author Chris Cannam
date Thu, 04 Oct 2007 16:34:11 +0000
parents ebd906049fb6
children c08c312b2399
comparison
equal deleted inserted replaced
185:f3191ab6d564 186:7b943924b8d3
28 #include "data/model/EditableDenseThreeDimensionalModel.h" 28 #include "data/model/EditableDenseThreeDimensionalModel.h"
29 #include "data/model/SparseOneDimensionalModel.h" 29 #include "data/model/SparseOneDimensionalModel.h"
30 #include "data/model/SparseTimeValueModel.h" 30 #include "data/model/SparseTimeValueModel.h"
31 #include "data/model/NoteModel.h" 31 #include "data/model/NoteModel.h"
32 #include "data/model/TextModel.h" 32 #include "data/model/TextModel.h"
33 #include "data/model/ImageModel.h"
33 34
34 #include "view/Pane.h" 35 #include "view/Pane.h"
35 36
36 #include "Document.h" 37 #include "Document.h"
37 38
491 492
492 if (dimensions == 1) { 493 if (dimensions == 1) {
493 494
494 READ_MANDATORY(int, resolution, toInt); 495 READ_MANDATORY(int, resolution, toInt);
495 496
496 SparseOneDimensionalModel *model = new SparseOneDimensionalModel 497 if (attributes.value("subtype") == "image") {
497 (sampleRate, resolution); 498
498 model->setObjectName(name); 499 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
499 m_models[id] = model; 500 ImageModel *model = new ImageModel(sampleRate, resolution,
501 notifyOnAdd);
502 model->setObjectName(name);
503 m_models[id] = model;
504
505 } else {
506
507 SparseOneDimensionalModel *model = new SparseOneDimensionalModel
508 (sampleRate, resolution);
509 model->setObjectName(name);
510 m_models[id] = model;
511 }
500 512
501 int dataset = attributes.value("dataset").trimmed().toInt(&ok); 513 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
502 if (ok) m_awaitingDatasets[dataset] = id; 514 if (ok) m_awaitingDatasets[dataset] = id;
503 515
504 return true; 516 return true;
777 bool good = false; 789 bool good = false;
778 790
779 switch (dimensions) { 791 switch (dimensions) {
780 case 1: 792 case 1:
781 if (dynamic_cast<SparseOneDimensionalModel *>(model)) good = true; 793 if (dynamic_cast<SparseOneDimensionalModel *>(model)) good = true;
794 else if (dynamic_cast<ImageModel *>(model)) good = true;
782 break; 795 break;
783 796
784 case 2: 797 case 2:
785 if (dynamic_cast<SparseTimeValueModel *>(model)) good = true; 798 if (dynamic_cast<SparseTimeValueModel *>(model)) good = true;
786 else if (dynamic_cast<TextModel *>(model)) good = true; 799 else if (dynamic_cast<TextModel *>(model)) good = true;
794 } 807 }
795 break; 808 break;
796 } 809 }
797 810
798 if (!good) { 811 if (!good) {
799 std::cerr << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions for " << dimensions << "-D dataset " << id << std::endl; 812 std::cerr << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions or inappropriate type for " << dimensions << "-D dataset " << id << std::endl;
800 m_currentDataset = 0; 813 m_currentDataset = 0;
801 return false; 814 return false;
802 } 815 }
803 816
804 m_currentDataset = model; 817 m_currentDataset = model;
856 float height = 0.0; 869 float height = 0.0;
857 height = attributes.value("height").trimmed().toFloat(&ok); 870 height = attributes.value("height").trimmed().toFloat(&ok);
858 QString label = attributes.value("label"); 871 QString label = attributes.value("label");
859 // std::cerr << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label.toStdString() << ", ok = " << ok << std::endl; 872 // std::cerr << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label.toStdString() << ", ok = " << ok << std::endl;
860 tm->addPoint(TextModel::Point(frame, height, label)); 873 tm->addPoint(TextModel::Point(frame, height, label));
874 return ok;
875 }
876
877 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset);
878
879 if (im) {
880 // std::cerr << "Current dataset is an image model" << std::endl;
881 QString image = attributes.value("image");
882 QString label = attributes.value("label");
883 // std::cerr << "SVFileReader::addPointToDataset: ImageModel: frame = " << frame << ", image = " << image.toStdString() << ", label = " << label.toStdString() << ", ok = " << ok << std::endl;
884 im->addPoint(ImageModel::Point(frame, image, label));
861 return ok; 885 return ok;
862 } 886 }
863 887
864 std::cerr << "WARNING: SV-XML: Point element found in non-point dataset" << std::endl; 888 std::cerr << "WARNING: SV-XML: Point element found in non-point dataset" << std::endl;
865 889