From 3e5ba64599352a29bee3d05d260b007736469440 Mon Sep 17 00:00:00 2001 From: Yinan Zhou Date: Mon, 4 Dec 2023 20:38:54 -0500 Subject: [PATCH] Unlink syllable when removed --- include/vrv/editortoolkit_neume.h | 1 + src/editortoolkit_neume.cpp | 108 +++++++++++++++++------------- 2 files changed, 62 insertions(+), 47 deletions(-) diff --git a/include/vrv/editortoolkit_neume.h b/include/vrv/editortoolkit_neume.h index 108b50e5266..11828f083cb 100644 --- a/include/vrv/editortoolkit_neume.h +++ b/include/vrv/editortoolkit_neume.h @@ -55,6 +55,7 @@ class EditorToolkitNeume : public EditorToolkit { bool Remove(std::string elementId); bool Resize(std::string elementId, int ulx, int uly, int lrx, int lry, float resize = NAN); bool Group(std::string groupType, std::vector elementIds); + void UnlinkSyllable(Syllable *syllable); bool Ungroup(std::string groupType, std::vector elementIds); bool ChangeGroup(std::string elementId, std::string contour); bool ToggleLigature(std::vector elementIds); diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 048d90eba4c..3eb7ec10a7e 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -2084,6 +2084,58 @@ bool EditorToolkitNeume::Split(std::string elementId, int x) return true; } +void EditorToolkitNeume::UnlinkSyllable(Syllable *syllable) +{ + if (!m_doc->GetDrawingPage()) { + LogError("Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); + return; + } + + assert(syllable); + + std::string linkedID = (syllable->HasPrecedes() ? syllable->GetPrecedes() : syllable->GetFollows()); + if (linkedID.compare(0, 1, "#") == 0) linkedID.erase(0, 1); + Syllable *linkedSyllable = dynamic_cast(m_doc->GetDrawingPage()->FindDescendantByID(linkedID)); + if (linkedSyllable != NULL) { + if (linkedSyllable->HasPrecedes()) linkedSyllable->SetPrecedes(""); + if (linkedSyllable->HasFollows()) { + linkedSyllable->SetFollows(""); + + // Create an empty syl for the second part + Syl *syl = new Syl(); + Text *text = new Text(); + std::u32string str = U""; + text->SetText(str); + syl->AddChild(text); + linkedSyllable->AddChild(syl); + + // Create default bounding box if facs + if (m_doc->GetType() == Facs) { + Zone *zone = new Zone(); + + zone->SetUlx( + linkedSyllable->GetFirst(NEUME)->GetFirst(NC)->GetFacsimileInterface()->GetZone()->GetUlx()); + zone->SetUly(linkedSyllable->GetAncestorStaff()->GetFacsimileInterface()->GetZone()->GetLry()); + zone->SetLrx(linkedSyllable->GetLast(NEUME)->GetLast(NC)->GetFacsimileInterface()->GetZone()->GetLrx()); + zone->SetLry(zone->GetUly() + 100); + + // Make bbox larger if it has less than 2 ncs + if (linkedSyllable->GetChildCount(NC, 2) <= 2) { + zone->SetLrx(zone->GetLrx() + 50); + } + + assert(m_doc->GetFacsimile()); + m_doc->GetFacsimile()->FindDescendantByType(SURFACE)->AddChild(zone); + FacsimileInterface *fi = syl->GetFacsimileInterface(); + assert(fi); + fi->AttachZone(zone); + } + } + } +} + bool EditorToolkitNeume::Remove(std::string elementId) { if (!m_doc->GetDrawingPage()) { @@ -2156,6 +2208,14 @@ bool EditorToolkitNeume::Remove(std::string elementId) } } + if (obj->Is(SYLLABLE)) { + Syllable *syllable = dynamic_cast(obj); + assert(syllable); + if (syllable->HasPrecedes() || syllable->HasFollows()) { + UnlinkSyllable(syllable); + } + } + if (!result) { result = parent->DeleteChild(obj); } @@ -2194,53 +2254,7 @@ bool EditorToolkitNeume::Remove(std::string elementId) Syllable *li = dynamic_cast(obj); assert(li); if (li->HasPrecedes() || li->HasFollows()) { - std::string linkedID = (li->HasPrecedes() ? li->GetPrecedes() : li->GetFollows()); - if (linkedID.compare(0, 1, "#") == 0) linkedID.erase(0, 1); - Syllable *linkedSyllable - = dynamic_cast(m_doc->GetDrawingPage()->FindDescendantByID(linkedID)); - if (linkedSyllable != NULL) { - if (linkedSyllable->HasPrecedes()) linkedSyllable->SetPrecedes(""); - if (linkedSyllable->HasFollows()) { - linkedSyllable->SetFollows(""); - // Create an empty syl for the second part - Syl *syl = new Syl(); - Text *text = new Text(); - std::u32string str = U""; - text->SetText(str); - syl->AddChild(text); - linkedSyllable->AddChild(syl); - - // Create default bounding box if facs - if (m_doc->GetType() == Facs) { - Zone *zone = new Zone(); - - zone->SetUlx(linkedSyllable->GetFirst(NEUME) - ->GetFirst(NC) - ->GetFacsimileInterface() - ->GetZone() - ->GetUlx()); - zone->SetUly( - linkedSyllable->GetAncestorStaff()->GetFacsimileInterface()->GetZone()->GetLry()); - zone->SetLrx(linkedSyllable->GetLast(NEUME) - ->GetLast(NC) - ->GetFacsimileInterface() - ->GetZone() - ->GetLrx()); - zone->SetLry(zone->GetUly() + 100); - - // Make bbox larger if it has less than 2 ncs - if (linkedSyllable->GetChildCount(NC, 2) <= 2) { - zone->SetLrx(zone->GetLrx() + 50); - } - - assert(m_doc->GetFacsimile()); - m_doc->GetFacsimile()->FindDescendantByType(SURFACE)->AddChild(zone); - FacsimileInterface *fi = syl->GetFacsimileInterface(); - assert(fi); - fi->AttachZone(zone); - } - }; - } + UnlinkSyllable(li); } // Delete the syllable empty of neumes std::string syllableId = obj->GetID();