Mercurial > hg > svapp
comparison framework/Document.cpp @ 672:ae7584dbd668 tuning-difference
Provide facility to re-align models
author | Chris Cannam |
---|---|
date | Fri, 17 May 2019 09:45:12 +0100 |
parents | 0960e27c3232 |
children | 0d4236961c97 |
comparison
equal
deleted
inserted
replaced
671:b6cafe05017d | 672:ae7584dbd668 |
---|---|
865 Document::deleteLayer(Layer *layer, bool force) | 865 Document::deleteLayer(Layer *layer, bool force) |
866 { | 866 { |
867 if (m_layerViewMap.find(layer) != m_layerViewMap.end() && | 867 if (m_layerViewMap.find(layer) != m_layerViewMap.end() && |
868 m_layerViewMap[layer].size() > 0) { | 868 m_layerViewMap[layer].size() > 0) { |
869 | 869 |
870 SVCERR << "WARNING: Document::deleteLayer: Layer " | |
871 << layer << " [" << layer->objectName() << "]" | |
872 << " is still used in " << m_layerViewMap[layer].size() | |
873 << " views!" << endl; | |
874 | |
875 if (force) { | 870 if (force) { |
876 | 871 |
877 #ifdef DEBUG_DOCUMENT | 872 SVDEBUG << "NOTE: Document::deleteLayer: Layer " |
878 SVCERR << "(force flag set -- deleting from all views)" << endl; | 873 << layer << " [" << layer->objectName() << "]" |
879 #endif | 874 << " is still used in " << m_layerViewMap[layer].size() |
880 | 875 << " views. Force flag set, so removing from them" << endl; |
876 | |
881 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin(); | 877 for (std::set<View *>::iterator j = m_layerViewMap[layer].begin(); |
882 j != m_layerViewMap[layer].end(); ++j) { | 878 j != m_layerViewMap[layer].end(); ++j) { |
883 // don't use removeLayerFromView, as it issues a command | 879 // don't use removeLayerFromView, as it issues a command |
884 layer->setLayerDormant(*j, true); | 880 layer->setLayerDormant(*j, true); |
885 (*j)->removeLayer(layer); | 881 (*j)->removeLayer(layer); |
886 } | 882 } |
887 | 883 |
888 m_layerViewMap.erase(layer); | 884 m_layerViewMap.erase(layer); |
889 | 885 |
890 } else { | 886 } else { |
887 | |
888 SVCERR << "WARNING: Document::deleteLayer: Layer " | |
889 << layer << " [" << layer->objectName() << "]" | |
890 << " is still used in " << m_layerViewMap[layer].size() | |
891 << " views! Force flag is not set, so not deleting" << endl; | |
892 | |
891 return; | 893 return; |
892 } | 894 } |
893 } | 895 } |
894 | 896 |
895 bool found = false; | 897 bool found = false; |
1099 { | 1101 { |
1100 return Align::canAlign(); | 1102 return Align::canAlign(); |
1101 } | 1103 } |
1102 | 1104 |
1103 void | 1105 void |
1104 Document::alignModel(Model *model) | 1106 Document::alignModel(Model *model, bool forceRecalculate) |
1105 { | 1107 { |
1106 SVDEBUG << "Document::alignModel(" << model << ") (main model is " << m_mainModel << ")" << endl; | 1108 SVDEBUG << "Document::alignModel(" << model << ", " << forceRecalculate |
1107 | 1109 << ") (main model is " << m_mainModel << ")" << endl; |
1108 if (!m_mainModel) { | |
1109 SVDEBUG << "(no main model to align to)" << endl; | |
1110 return; | |
1111 } | |
1112 | 1110 |
1113 RangeSummarisableTimeValueModel *rm = | 1111 RangeSummarisableTimeValueModel *rm = |
1114 dynamic_cast<RangeSummarisableTimeValueModel *>(model); | 1112 dynamic_cast<RangeSummarisableTimeValueModel *>(model); |
1115 if (!rm) { | 1113 if (!rm) { |
1116 SVDEBUG << "(model " << rm << " is not an alignable sort)" << endl; | 1114 SVDEBUG << "(model " << rm << " is not an alignable sort)" << endl; |
1117 return; | 1115 return; |
1118 } | 1116 } |
1119 | 1117 |
1118 if (!m_mainModel) { | |
1119 SVDEBUG << "(no main model to align to)" << endl; | |
1120 if (forceRecalculate && rm->getAlignment()) { | |
1121 SVDEBUG << "(but model is aligned, and forceRecalculate is true, " | |
1122 << "so resetting alignment to nil)" << endl; | |
1123 rm->setAlignment(nullptr); | |
1124 } | |
1125 return; | |
1126 } | |
1127 | |
1120 if (rm->getAlignmentReference() == m_mainModel) { | 1128 if (rm->getAlignmentReference() == m_mainModel) { |
1121 SVDEBUG << "(model " << rm << " is already aligned to main model " << m_mainModel << ")" << endl; | 1129 SVDEBUG << "(model " << rm << " is already aligned to main model " |
1122 return; | 1130 << m_mainModel << ")" << endl; |
1131 if (!forceRecalculate) { | |
1132 return; | |
1133 } else { | |
1134 SVDEBUG << "(but forceRecalculate is true, so realigning anyway)" | |
1135 << endl; | |
1136 } | |
1123 } | 1137 } |
1124 | 1138 |
1125 if (model == m_mainModel) { | 1139 if (model == m_mainModel) { |
1126 // The reference has an empty alignment to itself. This makes | 1140 // The reference has an empty alignment to itself. This makes |
1127 // it possible to distinguish between the reference and any | 1141 // it possible to distinguish between the reference and any |
1128 // unaligned model just by looking at the model itself, | 1142 // unaligned model just by looking at the model itself, |
1129 // without also knowing what the main model is | 1143 // without also knowing what the main model is |
1130 SVDEBUG << "Document::alignModel(" << model << "): is main model, setting alignment to itself appropriately" << endl; | 1144 SVDEBUG << "Document::alignModel(" << model |
1145 << "): is main model, setting alignment to itself" << endl; | |
1131 rm->setAlignment(new AlignmentModel(model, model, nullptr)); | 1146 rm->setAlignment(new AlignmentModel(model, model, nullptr)); |
1132 return; | 1147 return; |
1133 } | 1148 } |
1134 | 1149 |
1135 SVDEBUG << "Document::alignModel: aligning..." << endl; | 1150 SVDEBUG << "Document::alignModel: aligning..." << endl; |
1149 void | 1164 void |
1150 Document::alignModels() | 1165 Document::alignModels() |
1151 { | 1166 { |
1152 for (const ModelRecord &rec: m_models) { | 1167 for (const ModelRecord &rec: m_models) { |
1153 alignModel(rec.model); | 1168 alignModel(rec.model); |
1169 } | |
1170 alignModel(m_mainModel); | |
1171 } | |
1172 | |
1173 void | |
1174 Document::realignModels() | |
1175 { | |
1176 for (const ModelRecord &rec: m_models) { | |
1177 alignModel(rec.model, true); | |
1154 } | 1178 } |
1155 alignModel(m_mainModel); | 1179 alignModel(m_mainModel); |
1156 } | 1180 } |
1157 | 1181 |
1158 Document::AddLayerCommand::AddLayerCommand(Document *d, | 1182 Document::AddLayerCommand::AddLayerCommand(Document *d, |