Mercurial > hg > svapp
comparison framework/SVFileReader.cpp @ 111:c82913d31a53
* Save alignments to session file. Needs much testing.
author | Chris Cannam |
---|---|
date | Tue, 29 Apr 2008 15:34:17 +0000 |
parents | 2dd30a7cd21a |
children | 9554c19c42fd |
comparison
equal
deleted
inserted
replaced
110:f57047e0522b | 111:c82913d31a53 |
---|---|
30 #include "data/model/SparseOneDimensionalModel.h" | 30 #include "data/model/SparseOneDimensionalModel.h" |
31 #include "data/model/SparseTimeValueModel.h" | 31 #include "data/model/SparseTimeValueModel.h" |
32 #include "data/model/NoteModel.h" | 32 #include "data/model/NoteModel.h" |
33 #include "data/model/TextModel.h" | 33 #include "data/model/TextModel.h" |
34 #include "data/model/ImageModel.h" | 34 #include "data/model/ImageModel.h" |
35 #include "data/model/AlignmentModel.h" | |
35 | 36 |
36 #include "transform/TransformFactory.h" | 37 #include "transform/TransformFactory.h" |
37 | 38 |
38 #include "view/Pane.h" | 39 #include "view/Pane.h" |
39 | 40 |
561 if (attributes.value("subtype") == "text") { | 562 if (attributes.value("subtype") == "text") { |
562 TextModel *model = new TextModel | 563 TextModel *model = new TextModel |
563 (sampleRate, resolution, notifyOnAdd); | 564 (sampleRate, resolution, notifyOnAdd); |
564 model->setObjectName(name); | 565 model->setObjectName(name); |
565 m_models[id] = model; | 566 m_models[id] = model; |
567 } else if (attributes.value("subtype") == "path") { | |
568 PathModel *model = new PathModel | |
569 (sampleRate, resolution, notifyOnAdd); | |
570 model->setObjectName(name); | |
571 m_models[id] = model; | |
566 } else { | 572 } else { |
567 SparseTimeValueModel *model; | 573 SparseTimeValueModel *model; |
568 if (haveMinMax) { | 574 if (haveMinMax) { |
569 model = new SparseTimeValueModel | 575 model = new SparseTimeValueModel |
570 (sampleRate, resolution, minimum, maximum, notifyOnAdd); | 576 (sampleRate, resolution, minimum, maximum, notifyOnAdd); |
599 } else { | 605 } else { |
600 | 606 |
601 std::cerr << "WARNING: SV-XML: Unexpected sparse model dimension (" | 607 std::cerr << "WARNING: SV-XML: Unexpected sparse model dimension (" |
602 << dimensions << ")" << std::endl; | 608 << dimensions << ")" << std::endl; |
603 } | 609 } |
610 | |
611 } else if (type == "alignment") { | |
612 | |
613 READ_MANDATORY(int, reference, toInt); | |
614 READ_MANDATORY(int, aligned, toInt); | |
615 READ_MANDATORY(int, path, toInt); | |
616 | |
617 Model *refModel = 0, *alignedModel = 0, *pathModel = 0; | |
618 | |
619 if (m_models.find(reference) != m_models.end()) { | |
620 refModel = m_models[reference]; | |
621 } else { | |
622 std::cerr << "WARNING: SV-XML: Unknown reference model id " | |
623 << reference << " in alignment model id " << id | |
624 << std::endl; | |
625 } | |
626 | |
627 if (m_models.find(aligned) != m_models.end()) { | |
628 alignedModel = m_models[aligned]; | |
629 } else { | |
630 std::cerr << "WARNING: SV-XML: Unknown aligned model id " | |
631 << aligned << " in alignment model id " << id | |
632 << std::endl; | |
633 } | |
634 | |
635 if (m_models.find(path) != m_models.end()) { | |
636 pathModel = m_models[path]; | |
637 } else { | |
638 std::cerr << "WARNING: SV-XML: Unknown path model id " | |
639 << path << " in alignment model id " << id | |
640 << std::endl; | |
641 } | |
642 | |
643 if (refModel && alignedModel && pathModel) { | |
644 AlignmentModel *model = new AlignmentModel | |
645 (refModel, alignedModel, 0, 0); | |
646 PathModel *pm = dynamic_cast<PathModel *>(pathModel); | |
647 if (!pm) { | |
648 std::cerr << "WARNING: SV-XML: Model id " << path | |
649 << " referenced as path for alignment " << id | |
650 << " is not a path model" << std::endl; | |
651 } else { | |
652 model->setPath(pm); | |
653 pm->setCompletion(100); | |
654 } | |
655 model->setObjectName(name); | |
656 m_models[id] = model; | |
657 alignedModel->setAlignment(model); | |
658 return true; | |
659 } | |
660 | |
604 } else { | 661 } else { |
605 | 662 |
606 std::cerr << "WARNING: SV-XML: Unexpected model type \"" | 663 std::cerr << "WARNING: SV-XML: Unexpected model type \"" |
607 << type.toLocal8Bit().data() << "\" for model id " << id << std::endl; | 664 << type.toLocal8Bit().data() << "\" for model id " << id << std::endl; |
608 } | 665 } |
823 break; | 880 break; |
824 | 881 |
825 case 2: | 882 case 2: |
826 if (dynamic_cast<SparseTimeValueModel *>(model)) good = true; | 883 if (dynamic_cast<SparseTimeValueModel *>(model)) good = true; |
827 else if (dynamic_cast<TextModel *>(model)) good = true; | 884 else if (dynamic_cast<TextModel *>(model)) good = true; |
885 else if (dynamic_cast<PathModel *>(model)) good = true; | |
828 break; | 886 break; |
829 | 887 |
830 case 3: | 888 case 3: |
831 if (dynamic_cast<NoteModel *>(model)) good = true; | 889 if (dynamic_cast<NoteModel *>(model)) good = true; |
832 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { | 890 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) { |
902 float height = 0.0; | 960 float height = 0.0; |
903 height = attributes.value("height").trimmed().toFloat(&ok); | 961 height = attributes.value("height").trimmed().toFloat(&ok); |
904 QString label = attributes.value("label"); | 962 QString label = attributes.value("label"); |
905 // std::cerr << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label.toStdString() << ", ok = " << ok << std::endl; | 963 // std::cerr << "SVFileReader::addPointToDataset: TextModel: frame = " << frame << ", height = " << height << ", label = " << label.toStdString() << ", ok = " << ok << std::endl; |
906 tm->addPoint(TextModel::Point(frame, height, label)); | 964 tm->addPoint(TextModel::Point(frame, height, label)); |
965 return ok; | |
966 } | |
967 | |
968 PathModel *pm = dynamic_cast<PathModel *>(m_currentDataset); | |
969 | |
970 if (pm) { | |
971 // std::cerr << "Current dataset is a path model" << std::endl; | |
972 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok); | |
973 // std::cerr << "SVFileReader::addPointToDataset: PathModel: frame = " << frame << ", mapframe = " << mapframe << ", ok = " << ok << std::endl; | |
974 pm->addPoint(PathModel::Point(frame, mapframe)); | |
907 return ok; | 975 return ok; |
908 } | 976 } |
909 | 977 |
910 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset); | 978 ImageModel *im = dynamic_cast<ImageModel *>(m_currentDataset); |
911 | 979 |