Several cases should be handled while saving changes: 1) a feature is not in editor's cache I. a feature was created save it and mark as `Created' II. a feature was modified save it and mark as `Modified' 2) a feature is in editor's cache I. a feature was created save it and mark as `Created' II. a feature was modified and equals to the one in cache ignore it III. a feature was modified and equals
| 338 | /// III. a feature was modified and equals to the one in mwm |
| 339 | /// either delete it or save and mark as `Modified' depending on upload status |
| 340 | Editor::SaveResult Editor::SaveEditedFeature(EditableMapObject const & emo) |
| 341 | { |
| 342 | CHECK_THREAD_CHECKER(MainThreadChecker, ("")); |
| 343 | |
| 344 | FeatureID const & fid = emo.GetID(); |
| 345 | FeatureTypeInfo fti; |
| 346 | |
| 347 | auto const features = m_features.Get(); |
| 348 | |
| 349 | auto const featureStatus = GetFeatureStatusImpl(*features, fid.m_mwmId, fid.m_index); |
| 350 | ASSERT_NOT_EQUAL(featureStatus, FeatureStatus::Obsolete, ("Obsolete feature cannot be modified.")); |
| 351 | ASSERT_NOT_EQUAL(featureStatus, FeatureStatus::Deleted, ("Unexpected feature status.")); |
| 352 | |
| 353 | bool const wasCreatedByUser = IsCreatedFeature(fid); |
| 354 | if (wasCreatedByUser) |
| 355 | { |
| 356 | fti.m_status = FeatureStatus::Created; |
| 357 | fti.m_object = emo; |
| 358 | |
| 359 | if (featureStatus == FeatureStatus::Created) |
| 360 | { |
| 361 | auto const & editedFeatureInfo = features->at(fid.m_mwmId).at(fid.m_index); |
| 362 | if (AreObjectsEqualIgnoringStreet(fti.m_object, editedFeatureInfo.m_object) && |
| 363 | emo.GetStreet().m_defaultName == editedFeatureInfo.m_street) |
| 364 | { |
| 365 | return SaveResult::NothingWasChanged; |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | auto const originalObjectPtr = GetOriginalMapObject(fid); |
| 372 | if (!originalObjectPtr) |
| 373 | { |
| 374 | LOG(LERROR, ("A feature with id", fid, "cannot be loaded.")); |
| 375 | return SaveResult::SavingError; |
| 376 | } |
| 377 | fti.m_object = emo; |
| 378 | bool const sameAsInMWM = AreObjectsEqualIgnoringStreet(fti.m_object, *originalObjectPtr) && |
| 379 | emo.GetStreet().m_defaultName == GetOriginalFeatureStreet(fti.m_object.GetID()); |
| 380 | |
| 381 | if (featureStatus != FeatureStatus::Untouched) |
| 382 | { |
| 383 | // A feature was modified and equals to the one in editor. |
| 384 | auto const & editedFeatureInfo = features->at(fid.m_mwmId).at(fid.m_index); |
| 385 | if (AreObjectsEqualIgnoringStreet(fti.m_object, editedFeatureInfo.m_object) && |
| 386 | emo.GetStreet().m_defaultName == editedFeatureInfo.m_street) |
| 387 | { |
| 388 | return SaveResult::NothingWasChanged; |
| 389 | } |
| 390 | |
| 391 | // A feature was modified and equals to the one in mwm (changes are rolled back). |
| 392 | if (sameAsInMWM) |
| 393 | { |
| 394 | // Feature was not yet uploaded. Since it's equal to one mwm we can remove changes. |
| 395 | if (editedFeatureInfo.m_uploadStatus != kUploaded) |
| 396 | { |
| 397 | if (!RemoveFeature(fid)) |