diff --git a/include/vrv/editortoolkit_neume.h b/include/vrv/editortoolkit_neume.h index a31242d2970..108b50e5266 100644 --- a/include/vrv/editortoolkit_neume.h +++ b/include/vrv/editortoolkit_neume.h @@ -31,8 +31,8 @@ namespace vrv { class EditorToolkitNeume : public EditorToolkit { public: EditorToolkitNeume(Doc *doc, View *view) : EditorToolkit(doc, view) {} - bool ParseEditorAction(const std::string &json_editorAction); - virtual std::string EditInfo() { return m_infoObject.json(); }; + bool ParseEditorAction(const std::string &json_editorAction) override; + std::string EditInfo() override; /** * Experimental editor functions. @@ -100,9 +100,6 @@ class EditorToolkitNeume : public EditorToolkit { bool AdjustPitchFromPosition(Object *obj, Clef *clef = NULL); bool AdjustClefLineFromPosition(Clef *clef, Staff *staff = NULL); ///@} - -private: - jsonxx::Object m_infoObject; }; //-------------------------------------------------------------------------------- diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 72745a2a16d..cb1432194b4 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -40,25 +40,29 @@ //-------------------------------------------------------------------------------- namespace vrv { +std::string EditorToolkitNeume::EditInfo() +{ + return m_editInfo.json(); +} bool EditorToolkitNeume::ParseEditorAction(const std::string &json_editorAction) { jsonxx::Object json; - m_infoObject.reset(); + m_editInfo.reset(); // Read JSON actions if (!json.parse(json_editorAction)) { LogError("Cannot parse JSON std::string."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Cannot parse JSON from std::string " + json_editorAction); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Cannot parse JSON from std::string " + json_editorAction); return false; } if (!json.has("action") || (!json.has("param") && !json.has("param"))) { LogWarning("Incorrectly formatted JSON action"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "JSON action misformatted."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "JSON action misformatted."); return false; } @@ -66,8 +70,8 @@ bool EditorToolkitNeume::ParseEditorAction(const std::string &json_editorAction) if (action != "chain" && json.has("param")) { LogWarning("Only 'chain' uses 'param' as an array."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "'param' can only be an array for a chain action."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "'param' can only be an array for a chain action."); return false; } @@ -238,8 +242,8 @@ bool EditorToolkitNeume::ParseEditorAction(const std::string &json_editorAction) else { LogWarning("Unknown action type '%s'.", action.c_str()); } - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Action " + action + " could not be parsed or is unknown."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Action " + action + " could not be parsed or is unknown."); return false; } @@ -251,15 +255,15 @@ bool EditorToolkitNeume::Chain(jsonxx::Array actions) for (int i = 0; i < (int)actions.size(); i++) { if (!actions.has(0)) { LogError("Action %d was not an object", i); - m_infoObject.reset(); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Action " + std::to_string(i) + " was not an object."); + m_editInfo.reset(); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Action " + std::to_string(i) + " was not an object."); return false; } status |= this->ParseEditorAction(actions.get(i).json()); - results.import(std::to_string(i), m_infoObject); + results.import(std::to_string(i), m_editInfo); } - m_infoObject = results; + m_editInfo = results; return status; } @@ -480,8 +484,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) std::string status = "OK", message = ""; if (!m_doc->GetDrawingPage()) { LogError("Could not get drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get drawing page."); return false; } @@ -513,8 +517,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) Layer *layer = dynamic_cast(element->GetFirstAncestor(LAYER)); if (!layer) { LogError("Element does not have Layer parent. This should not happen."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Element does not have Layer parent."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element does not have Layer parent."); return false; } @@ -593,8 +597,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) Clef *clef = dynamic_cast(element); if (!clef->HasFacs()) { LogError("Clef dragging is only supported for clefs with facsimiles!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Clef dragging is only supported for clefs with facsimiles."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Clef dragging is only supported for clefs with facsimiles."); return false; } FacsimileInterface *fi = (*clef).GetFacsimileInterface(); @@ -645,8 +649,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) Staff *staff = vrv_cast(element); if (!staff->HasFacs()) { LogError("Staff dragging is only supported for staves with facsimiles!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Staff dragging is only supported for staves with facsimiles."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Staff dragging is only supported for staves with facsimiles."); return false; } @@ -674,8 +678,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) Syl *syl = dynamic_cast(element); if (!syl->HasFacs()) { LogError("Syl (boundingbox) dragging is only supported for syls with facsimiles!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Syl dragging is only supported for syls with facsimiles."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Syl dragging is only supported for syls with facsimiles."); return false; } FacsimileInterface *fi = (*syl).GetFacsimileInterface(); @@ -688,8 +692,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) Accid *accid = dynamic_cast(element); if (!accid->HasFacs()) { LogError("Accid dragging is only supported for accid with facsimiles!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Accid dragging is only supported for accid with facsimiles."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Accid dragging is only supported for accid with facsimiles."); return false; } FacsimileInterface *fi = (*accid).GetFacsimileInterface(); @@ -705,8 +709,8 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) DivLine *divLine = dynamic_cast(element); if (!divLine->HasFacs()) { LogError("DivLine dragging is only supported for divLine with facsimiles!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "DivLine dragging is only supported for divLine with facsimiles."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "DivLine dragging is only supported for divLine with facsimiles."); return false; } FacsimileInterface *fi = (*divLine).GetFacsimileInterface(); @@ -720,14 +724,14 @@ bool EditorToolkitNeume::Drag(std::string elementId, int x, int y) } else { LogWarning("Unsupported element for dragging."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Unsupported element for dragging."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Unsupported element for dragging."); return false; } Layer *layer = vrv_cast(element->GetFirstAncestor(LAYER)); layer->ReorderByXPos(); // Reflect position order of elements internally (and in the resulting output file) - m_infoObject.import("status", status); - m_infoObject.import("message", message); + m_editInfo.import("status", status); + m_editInfo.import("message", message); return true; } @@ -736,14 +740,14 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in { if (!m_doc->GetDrawingPage()) { LogError("Could not get drawing page"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get drawing page."); return false; } if (m_doc->GetType() != Facs) { LogError("Drawing page without facsimile"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Drawing page without facsimile is unsupported."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Drawing page without facsimile is unsupported."); return false; } @@ -820,9 +824,9 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in parent->InsertChild(newStaff, i); parent->Modify(); - m_infoObject.import("uuid", newStaff->GetID()); - m_infoObject.import("status", status); - m_infoObject.import("message", message); + m_editInfo.import("uuid", newStaff->GetID()); + m_editInfo.import("status", status); + m_editInfo.import("message", message); return true; } @@ -832,17 +836,17 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in parent->AddChild(newStaff); parent->Modify(); - m_infoObject.import("uuid", newStaff->GetID()); - m_infoObject.import("status", status); - m_infoObject.import("message", message); + m_editInfo.import("uuid", newStaff->GetID()); + m_editInfo.import("status", status); + m_editInfo.import("message", message); return true; } if (staff == NULL) { LogError("A staff must exist in the page to add a non-staff element."); delete zone; - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "A staff must exist in the page to add a non-staff element."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "A staff must exist in the page to add a non-staff element."); return false; } Layer *layer = vrv_cast(staff->FindDescendantByType(LAYER)); @@ -929,8 +933,8 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in delete nc; LogError("Failed to set pitch."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to set pitch."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to set pitch."); return false; } @@ -992,8 +996,8 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in LogError("Unsupported character in contour."); delete newNc; delete newZone; - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Unsupported character in contour."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Unsupported character in contour."); return false; } @@ -1018,10 +1022,10 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in } } if (elementType == "nc") { - m_infoObject.import("uuid", nc->GetID()); + m_editInfo.import("uuid", nc->GetID()); } else { - m_infoObject.import("uuid", neume->GetID()); + m_editInfo.import("uuid", neume->GetID()); } } else if (elementType == "clef") { @@ -1046,8 +1050,8 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in LogError("A clef shape must be specified."); delete clef; - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "A clef shape must be specified."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "A clef shape must be specified."); return false; } clef->SetShape(clefShape); @@ -1068,7 +1072,7 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in assert(surface); surface->AddChild(zone); layer->AddChild(clef); - m_infoObject.import("uuid", clef->GetID()); + m_editInfo.import("uuid", clef->GetID()); layer->ReorderByXPos(); // ensure pitched elements associated with this clef keep their x,y positions @@ -1119,11 +1123,11 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in if (!AdjustPitchFromPosition(custos)) { LogError("Failed to set pitch."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to set pitch."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to set pitch."); return false; } - m_infoObject.import("uuid", custos->GetID()); + m_editInfo.import("uuid", custos->GetID()); } else if (elementType == "accid") { Accid *accid = new Accid(); @@ -1144,8 +1148,8 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in LogError("A accid type must be specified."); delete accid; - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "A accid type must be specified."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "A accid type must be specified."); return false; } @@ -1170,7 +1174,7 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in zone->SetLry(uly + noteHeight); layer->ReorderByXPos(); - m_infoObject.import("uuid", accid->GetID()); + m_editInfo.import("uuid", accid->GetID()); } else if (elementType == "divLine") { DivLine *divLine = new DivLine(); @@ -1208,8 +1212,8 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in LogError("A divLine type must be specified."); delete divLine; - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "A divLine type must be specified."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "A divLine type must be specified."); return false; } @@ -1234,18 +1238,18 @@ bool EditorToolkitNeume::Insert(std::string elementType, std::string staffId, in zone->SetLry(uly + noteHeight); layer->ReorderByXPos(); - m_infoObject.import("uuid", divLine->GetID()); + m_editInfo.import("uuid", divLine->GetID()); } else { delete zone; LogError("Unsupported type '%s' for insertion", elementType.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Unsupported type '" + elementType + "' for insertion."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Unsupported type '" + elementType + "' for insertion."); return false; } layer->ReorderByXPos(); - m_infoObject.import("status", status); - m_infoObject.import("message", message); + m_editInfo.import("status", status); + m_editInfo.import("message", message); return true; } @@ -1253,14 +1257,14 @@ bool EditorToolkitNeume::InsertToSyllable(std::string elementId) { if (!m_doc->GetDrawingPage()) { LogError("Could not get drawing page"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get drawing page."); return false; } if (m_doc->GetType() != Facs) { LogError("Drawing page without facsimile"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Drawing page without facsimile is unsupported."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Drawing page without facsimile is unsupported."); return false; } @@ -1271,23 +1275,23 @@ bool EditorToolkitNeume::InsertToSyllable(std::string elementId) if (element == NULL) { LogError("No element exists with ID '%s'.", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No element exists with ID" + elementId + "."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No element exists with ID" + elementId + "."); return false; } if (!(element->Is(DIVLINE) || element->Is(ACCID) || element->Is(CLEF))) { LogError("Element is of type %s, but only Divlines and Accids can be inserted into syllables.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element is of type " + element->GetClassName() + ", but only DivLines, Accids, and Clefs can be inserted into syllables."); return false; } if (!parent->Is(LAYER)) { LogError("The selected %s is not a child of layer.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "The selected " + element->GetClassName() + "is not a child of layer."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "The selected " + element->GetClassName() + "is not a child of layer."); return false; } @@ -1300,8 +1304,8 @@ bool EditorToolkitNeume::InsertToSyllable(std::string elementId) } else { LogError("Selected '%s' without facsimile", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Selected '" + element->GetClassName() + "' without facsimile is unsupported."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Selected '" + element->GetClassName() + "' without facsimile is unsupported."); return false; } @@ -1325,8 +1329,8 @@ bool EditorToolkitNeume::InsertToSyllable(std::string elementId) } else { LogError("A syllable must exist in the staff to insert a '%s' into.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import( + m_editInfo.import("status", "FAILURE"); + m_editInfo.import( "message", "A syllable must exist in the staff to insert a '" + element->GetClassName() + "' into."); return false; } @@ -1396,8 +1400,8 @@ bool EditorToolkitNeume::InsertToSyllable(std::string elementId) } } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } @@ -1405,14 +1409,14 @@ bool EditorToolkitNeume::MoveOutsideSyllable(std::string elementId) { if (!m_doc->GetDrawingPage()) { LogError("Could not get drawing page"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get drawing page."); return false; } if (m_doc->GetType() != Facs) { LogError("Drawing page without facsimile"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Drawing page without facsimile is unsupported."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Drawing page without facsimile is unsupported."); return false; } @@ -1423,23 +1427,23 @@ bool EditorToolkitNeume::MoveOutsideSyllable(std::string elementId) if (element == NULL) { LogError("No element exists with ID '%s'.", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No element exists with ID" + elementId + "."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No element exists with ID" + elementId + "."); return false; } if (!(element->Is(DIVLINE) || element->Is(ACCID) || element->Is(CLEF))) { LogError("Element is of type %s, but only Divlines, Accids, and Clefs can be moved out of syllables.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element is of type " + element->GetClassName() + ", but only DivLines and Accids can be inserted into syllables."); return false; } if (!parent->Is(SYLLABLE)) { LogError("The selected %s is not a child of syllable.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "The selected " + element->GetClassName() + "is not a child of syllable."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "The selected " + element->GetClassName() + "is not a child of syllable."); return false; } @@ -1519,8 +1523,8 @@ bool EditorToolkitNeume::MoveOutsideSyllable(std::string elementId) // INSIDE do nothing } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } @@ -1528,15 +1532,15 @@ bool EditorToolkitNeume::DisplaceClefOctave(std::string elementId, std::string d { if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } if (direction != "above" && direction != "below") { LogError("Direction can only be either \"above\" or \"below\"."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Direction can only be either \"above\" or \"below\"."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Direction can only be either \"above\" or \"below\"."); return false; } @@ -1544,8 +1548,8 @@ bool EditorToolkitNeume::DisplaceClefOctave(std::string elementId, std::string d Object *obj = page->FindDescendantByID(elementId); if (obj == NULL || !obj->Is(CLEF)) { LogError("This action can only be done on clefs!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "This action can only be done on clefs!"); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "This action can only be done on clefs!"); return false; } @@ -1560,8 +1564,8 @@ bool EditorToolkitNeume::DisplaceClefOctave(std::string elementId, std::string d if (octaveDis > 3 || octaveDis < -3) { LogError("Clefs can only be displaced 3 octaves."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Clefs can only be displaced 3 octaves."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Clefs can only be displaced 3 octaves."); return false; } @@ -1596,8 +1600,8 @@ bool EditorToolkitNeume::DisplaceClefOctave(std::string elementId, std::string d nc->SetOct(nc->GetOct() + move); }); - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } @@ -1605,14 +1609,14 @@ bool EditorToolkitNeume::MatchHeight(std::string elementId) { if (!m_doc->GetDrawingPage()) { LogError("Could not get drawing page"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get drawing page."); return false; } if (m_doc->GetType() != Facs) { LogError("Drawing page without facsimile"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Drawing page without facsimile is unsupported."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Drawing page without facsimile is unsupported."); return false; } @@ -1621,14 +1625,14 @@ bool EditorToolkitNeume::MatchHeight(std::string elementId) Object *staffParent = element->GetFirstAncestor(STAFF); if (element == NULL) { LogError("No element exists with ID '%s'.", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No element exists with ID" + elementId + "."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No element exists with ID" + elementId + "."); return false; } if (!element->Is(SYL)) { LogError("Element is of type %s, but only element can match height.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import( + m_editInfo.import("status", "FAILURE"); + m_editInfo.import( "message", "Element is of type " + element->GetClassName() + ", but only element can match height."); return false; } @@ -1637,17 +1641,15 @@ bool EditorToolkitNeume::MatchHeight(std::string elementId) int ulx; int uly; int height; - int lrx; if (dynamic_cast(element)->HasFacs()) { ulx = element->GetFacsimileInterface()->GetZone()->GetUlx(); uly = element->GetFacsimileInterface()->GetZone()->GetUly(); - lrx = element->GetFacsimileInterface()->GetZone()->GetLrx(); height = element->GetFacsimileInterface()->GetZone()->GetLry() - uly; } else { LogError("Selected '%s' without facsimile", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Selected '" + element->GetClassName() + "' without facsimile is unsupported."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Selected '" + element->GetClassName() + "' without facsimile is unsupported."); return false; } @@ -1689,8 +1691,8 @@ bool EditorToolkitNeume::MatchHeight(std::string elementId) zone->SetLry(uly + offsetY + height); } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } @@ -1707,15 +1709,15 @@ bool EditorToolkitNeume::Merge(std::vector elementIds) } else { LogError("Staff with ID '%s' does not exist!", it->c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Staff with ID '" + *it + "' does not exist."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Staff with ID '" + *it + "' does not exist."); return false; } } if (staves.size() < 2) { LogError("At least two staves must be provided."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "At least two staves must be provided."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "At least two staves must be provided."); return false; } @@ -1776,9 +1778,9 @@ bool EditorToolkitNeume::Merge(std::vector elementIds) fillLayer->ReorderByXPos(); - m_infoObject.import("uuid", fillStaff->GetID()); - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("uuid", fillStaff->GetID()); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); // TODO change zones for staff children @@ -1820,8 +1822,8 @@ bool EditorToolkitNeume::Set(std::string elementId, std::string attrType, std::s m_doc->PrepareData(); m_doc->GetDrawingPage()->LayOut(true); } - m_infoObject.import("status", success ? "OK" : "FAILURE"); - m_infoObject.import("message", success ? "" : "Could not set attribute '" + attrType + "' to '" + attrValue + "'."); + m_editInfo.import("status", success ? "OK" : "FAILURE"); + m_editInfo.import("message", success ? "" : "Could not set attribute '" + attrType + "' to '" + attrValue + "'."); return success; } @@ -1831,15 +1833,15 @@ bool EditorToolkitNeume::SetText(std::string elementId, const std::string &text) std::string status = "OK", message = ""; const std::u32string wtext = UTF8to32(text); if (!m_doc->GetDrawingPage()) { - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not find drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not find drawing page."); return false; } Object *element = m_doc->GetDrawingPage()->FindDescendantByID(elementId); if (element == NULL) { LogWarning("No element with ID '%s' exists", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No element with ID '" + elementId + "' exists."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No element with ID '" + elementId + "' exists."); return false; } @@ -1923,12 +1925,12 @@ bool EditorToolkitNeume::SetText(std::string elementId, const std::string &text) } else { LogError("Element type '%s' is unsupported for SetText", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Element type '" + element->GetClassName() + "' is unsupported for SetText."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element type '" + element->GetClassName() + "' is unsupported for SetText."); return false; } - m_infoObject.import("status", success ? status : "FAILURE"); - m_infoObject.import("message", success ? message : "SetText method failed."); + m_editInfo.import("status", success ? status : "FAILURE"); + m_editInfo.import("message", success ? message : "SetText method failed."); return success; } @@ -1936,8 +1938,8 @@ bool EditorToolkitNeume::SetClef(std::string elementId, std::string shape) { if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } ListOfObjects objects; @@ -1960,8 +1962,8 @@ bool EditorToolkitNeume::SetClef(std::string elementId, std::string shape) success = AttModule::SetShared(clef, "shape", shape); if (!success) { LogError("Unable to set clef shape"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Unable to set clef shape."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Unable to set clef shape."); return false; } @@ -1988,8 +1990,8 @@ bool EditorToolkitNeume::SetClef(std::string elementId, std::string shape) m_doc->PrepareData(); m_doc->GetDrawingPage()->LayOut(true); } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } @@ -1997,23 +1999,23 @@ bool EditorToolkitNeume::Split(std::string elementId, int x) { if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } Staff *staff = dynamic_cast(m_doc->GetDrawingPage()->FindDescendantByID(elementId)); // Validate parameters if (staff == NULL) { LogError("Either no element exists with ID '%s' or it is not a staff.", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Either no element exists with ID '" + elementId + "' or it is not a staff."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Either no element exists with ID '" + elementId + "' or it is not a staff."); return false; } if (staff->GetZone()->GetUlx() > x || staff->GetZone()->GetLrx() < x) { LogError("The 'x' parameter is not within the bounds of the original staff."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "The 'x' parameter is not within bounds of the original staff."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "The 'x' parameter is not within bounds of the original staff."); return false; } @@ -2027,19 +2029,19 @@ bool EditorToolkitNeume::Split(std::string elementId, int x) if (!this->Insert("staff", "auto", newUlx, newUly, newLrx, newLry, v)) { LogError("Failed to create a second staff."); - m_infoObject.reset(); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to create a second staff."); + m_editInfo.reset(); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to create a second staff."); return false; } Staff *splitStaff - = dynamic_cast(m_doc->GetDrawingPage()->FindDescendantByID(m_infoObject.get("uuid"))); + = dynamic_cast(m_doc->GetDrawingPage()->FindDescendantByID(m_editInfo.get("uuid"))); assert(splitStaff); if (splitStaff == NULL) { LogError("Split staff is null"); - m_infoObject.reset(); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Split staff is null."); + m_editInfo.reset(); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Split staff is null."); return false; } @@ -2081,9 +2083,9 @@ bool EditorToolkitNeume::Split(std::string elementId, int x) } } layer->ClearRelinquishedChildren(); - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); - m_infoObject.import("uuid", splitStaff->GetID()); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); + m_editInfo.import("uuid", splitStaff->GetID()); return true; } @@ -2091,8 +2093,8 @@ bool EditorToolkitNeume::Remove(std::string elementId) { if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } Object *obj = m_doc->GetDrawingPage()->FindDescendantByID(elementId); @@ -2104,7 +2106,7 @@ bool EditorToolkitNeume::Remove(std::string elementId) isClef = obj->Is(CLEF); Object *parent = obj->GetParent(); assert(parent); - m_infoObject.import("uuid", elementId); + m_editInfo.import("uuid", elementId); // Remove Zone for element (if any) InterfaceComparison ic(INTERFACE_FACSIMILE); ListOfObjects fiChildren; @@ -2145,9 +2147,9 @@ bool EditorToolkitNeume::Remove(std::string elementId) if (!result) { LogError("Failed to delete the desired element (%s)", elementId.c_str()); - m_infoObject.reset(); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to delete the desired element (" + elementId + ")."); + m_editInfo.reset(); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to delete the desired element (" + elementId + ")."); return false; } @@ -2165,9 +2167,9 @@ bool EditorToolkitNeume::Remove(std::string elementId) if (!result) { LogError("Failed to delete the desired element (%s)", elementId.c_str()); - m_infoObject.reset(); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to delete the desired element (" + elementId + ")."); + m_editInfo.reset(); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to delete the desired element (" + elementId + ")."); return false; } // Check if this leaves any containers empty and delete them @@ -2181,9 +2183,9 @@ bool EditorToolkitNeume::Remove(std::string elementId) result &= parent->DeleteChild(obj); if (!result) { LogError("Failed to delete empty neume (%s)", neumeId.c_str()); - m_infoObject.reset(); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to delete empty neume (" + neumeId + ")."); + m_editInfo.reset(); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to delete empty neume (" + neumeId + ")."); return false; } } @@ -2211,16 +2213,16 @@ bool EditorToolkitNeume::Remove(std::string elementId) result &= parent->DeleteChild(obj); if (!result) { LogError("Failed to delete empty syllable (%s)", syllableId.c_str()); - m_infoObject.reset(); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to delete empty syllable (" + syllableId + ")."); + m_editInfo.reset(); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to delete empty syllable (" + syllableId + ")."); return false; } } } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } @@ -2228,22 +2230,22 @@ bool EditorToolkitNeume::Resize(std::string elementId, int ulx, int uly, int lrx { if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } if (m_doc->GetType() != Facs) { LogWarning("Resizing is only available in facsimile mode."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Resizing is only available in facsimile mode."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Resizing is only available in facsimile mode."); return false; } Object *obj = m_doc->GetDrawingPage()->FindDescendantByID(elementId); if (obj == NULL) { LogError("Object with ID '%s' not found.", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Object with ID '" + elementId + "' could not be found."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Object with ID '" + elementId + "' could not be found."); return false; } if (obj->Is(STAFF)) { @@ -2251,8 +2253,8 @@ bool EditorToolkitNeume::Resize(std::string elementId, int ulx, int uly, int lrx assert(staff); if (!staff->HasFacs()) { LogError("This staff does not have a facsimile."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "This staff does not have a facsimile."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "This staff does not have a facsimile."); return false; } Zone *zone = staff->GetZone(); @@ -2272,8 +2274,8 @@ bool EditorToolkitNeume::Resize(std::string elementId, int ulx, int uly, int lrx assert(syl); if (!syl->HasFacs()) { LogError("This syl (bounding box) does not have a facsimile"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "This syl does not have a facsimile."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "This syl does not have a facsimile."); return false; } Zone *zone = syl->GetZone(); @@ -2303,21 +2305,20 @@ bool EditorToolkitNeume::Resize(std::string elementId, int ulx, int uly, int lrx } else { LogError("Element of type '%s' is unsupported.", obj->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Element of type '" + obj->GetClassName() + "' is unsupported."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element of type '" + obj->GetClassName() + "' is unsupported."); return false; } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } bool EditorToolkitNeume::Group(std::string groupType, std::vector elementIds) { - Object *parent = NULL, *doubleParent = NULL; + Object *parent = NULL, *secondParent = NULL; std::map parents; - std::set elements; - std::vector sortedElements; + ListOfObjects elements; std::vector fullParents; std::map clefsBefore; @@ -2326,16 +2327,16 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e // Get the current drawing page if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } if (elementIds.size() == 0) { LogWarning("No element IDs to group!"); status = "WARNING"; message = "No element IDs to group!"; - m_infoObject.import("status", status); - m_infoObject.import("message", message); + m_editInfo.import("status", status); + m_editInfo.import("message", message); return true; } ClassId elementClass; @@ -2347,8 +2348,8 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e } else { LogError("Invalid groupType: %s", groupType.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Invalid groupType: " + groupType); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Invalid groupType: " + groupType); return false; } @@ -2358,15 +2359,15 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e Object *el = m_doc->GetDrawingPage()->FindDescendantByID(*it); if (el == NULL) { LogError("Could not get element with ID %s", it->c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get element with ID " + *it); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get element with ID " + *it); return false; } if (el->GetClassId() != elementClass) { LogError("Element %s was of class %s. Expected class %s", el->GetID().c_str(), el->GetClassName().c_str(), groupType.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element " + el->GetID() + " was of class " + el->GetClassName() + " but expected class " + groupType + "."); return false; @@ -2376,8 +2377,8 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e Object *par = el->GetParent(); if (par == NULL) { LogError("Parent of %s is null!", el->GetID().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Parent of " + el->GetID() + " is null."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Parent of " + el->GetID() + " is null."); return false; } @@ -2400,25 +2401,22 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e std::string resultId0; std::string resultId1; - // LogMessage("%s", chainArray.get(0).json().c_str()); - // for_each(elementIds.begin(), elementIds.begin()+idx,[](std::string s){LogMessage("%s", s.c_str());}); - std::vector elementIds0 = { elementIds.begin(), elementIds.begin() + idx }; Group("neume", elementIds0); - if (m_infoObject.get("status") == "FAILURE") { + if (m_editInfo.get("status") == "FAILURE") { resultId0 = linkedID; } else { - resultId0 = m_infoObject.get("uuid"); + resultId0 = m_editInfo.get("uuid"); } std::vector elementIds1 = { elementIds.begin() + idx, elementIds.end() }; Group("neume", elementIds1); - if (m_infoObject.get("status") == "FAILURE") { + if (m_editInfo.get("status") == "FAILURE") { resultId1 = par->GetID(); } else { - resultId1 = m_infoObject.get("uuid"); + resultId1 = m_editInfo.get("uuid"); par = m_doc->GetDrawingPage()->FindDescendantByID(resultId1); } @@ -2434,91 +2432,53 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e uuidArray << resultId0; uuidArray << resultId1; - m_infoObject.import("uuid", uuidArray); - m_infoObject.import("status", status); - m_infoObject.import("message", message); + m_editInfo.import("uuid", uuidArray); + m_editInfo.import("status", status); + m_editInfo.import("message", message); return true; } } - if (doubleParent == NULL) { - doubleParent = par->GetParent(); - if (doubleParent == NULL) { - LogError("No second level parent!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No second level parent."); - return false; - } - } - else { - if (par->GetParent() != doubleParent) { - LogError("No shared second level parent!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No shared second level parent."); - return false; - } - } - auto possibleEntry = parents.find(el->GetParent()); - if (possibleEntry == parents.end()) { - parents.emplace(el->GetParent(), 1); - } - else { - possibleEntry->second += 1; - } - elements.insert(el); + parents[par]++; + elements.push_back(el); } if (parents.size() == 0) { LogError("Could not get the parent."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the parent."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the parent."); return false; } else if (parents.size() == 1) { LogError("The selected elements are already grouped."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "The selected elements are already grouped."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "The selected elements are already grouped."); return false; } - // auto it = elementIds.begin(); - // Object *el = m_doc->GetDrawingPage()->FindDescendantByID(*it); - // Layer *layer = dynamic_cast(el->GetFirstAncestor(LAYER)); - // if (!layer) { - // LogError("Elements does not have Layer parent. This should not happen."); - // m_infoObject.import("status", "FAILURE"); - // m_infoObject.import("message", "Elements does not have Layer parent."); - // return false; - // } - - std::copy(elements.begin(), elements.end(), std::back_inserter(sortedElements)); - std::stable_sort(sortedElements.begin(), sortedElements.end(), Object::sortByUlx); - ListOfObjects clefs; - std::set syllables; - ListOfObjects sortedSyllables; + ListOfObjects syllables; ClassIdComparison clefComp(CLEF); InterfaceComparison pitchComp(INTERFACE_PITCH); Clef *newClef = NULL; - m_doc->GetDrawingPage()->FindAllDescendantsBetween(&clefs, &clefComp, - sortedElements.front()->GetFirstAncestor(SYLLABLE), sortedElements.back()->GetFirstAncestor(SYLLABLE)); + m_doc->GetDrawingPage()->FindAllDescendantsBetween( + &clefs, &clefComp, elements.front()->GetFirstAncestor(SYLLABLE), elements.back()->GetFirstAncestor(SYLLABLE)); // if there are clefs between the elements getting grouped // some elements will need their pitch adjusted for the new clef // clefsBefore maps the syllable parent to its clef before the group // so we can reassociate any pitched children from their old clef to the new one if (clefs.size() != 0) { - for (auto it = sortedElements.begin(); it != sortedElements.end(); ++it) { + for (auto it = elements.begin(); it != elements.end(); ++it) { if ((*it)->Is(SYLLABLE)) { - syllables.insert(dynamic_cast(*it)); + syllables.push_back(dynamic_cast(*it)); } else { - syllables.insert((*it)->GetFirstAncestor(SYLLABLE)); + syllables.push_back((*it)->GetFirstAncestor(SYLLABLE)); } } - std::copy(syllables.begin(), syllables.end(), std::back_inserter(sortedSyllables)); - for (auto it = sortedSyllables.begin(); it != sortedSyllables.end(); ++it) { + for (auto it = syllables.begin(); it != syllables.end(); ++it) { Clef *tempClef = dynamic_cast(m_doc->GetDrawingPage()->FindPreviousChild(&clefComp, (*it))); if (tempClef == NULL) { Layer *layer = vrv_cast((*it)->GetFirstAncestor(LAYER)); @@ -2526,14 +2486,28 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e } clefsBefore.insert(std::pair(dynamic_cast(*it), tempClef)); } - newClef = clefsBefore[dynamic_cast(sortedSyllables.front())]; + newClef = clefsBefore[dynamic_cast(syllables.front())]; } + // check if share second level parent + secondParent = (*parents.begin()).first->GetParent(); + if (secondParent == NULL) { + LogError("No second level parent!"); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No second level parent."); + return false; + } // find parents where all of their children are being grouped for (auto it = parents.begin(); it != parents.end(); ++it) { auto parentPair = *it; Object *par = parentPair.first; int expected; + if (par->GetParent() != secondParent) { + LogError("No shared second level parent!"); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No shared second level parent."); + return false; + } if (par->GetClassId() == SYLLABLE) { expected = par->GetChildCount(NEUME); } @@ -2544,6 +2518,7 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e fullParents.push_back(parentPair.first); } } + // if there are no full parents we need to make a new one to attach everything to if (fullParents.empty()) { if (elementClass == NC) { @@ -2551,9 +2526,10 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e } else if (elementClass == NEUME) { parent = new Syllable(); + Object *oldSyl = (*elements.begin())->GetFirstAncestor(SYLLABLE)->GetFirst(SYL); for (auto it = elements.begin(); it != elements.end(); ++it) { - if ((*it)->GetParent() != parent && !(*it)->Is(SYL)) { + if (!(*it)->Is(SYL)) { (*it)->MoveItselfTo(parent); } } @@ -2570,64 +2546,25 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e if (m_doc->GetType() == Facs) { Zone *zone = new Zone(); - // if it's syllable parent has position values just use those - FacsimileInterface *syllableFi = NULL; - if (syl->GetFirstAncestor(SYLLABLE)->GetFacsimileInterface()->HasFacs()) { - syllableFi = syl->GetFirstAncestor(SYLLABLE)->GetFacsimileInterface(); - Zone *tempZone = dynamic_cast(syllableFi->GetZone()); - zone->SetUlx(tempZone->GetUlx()); - zone->SetUly(tempZone->GetUly()); - zone->SetLrx(tempZone->GetLrx()); - zone->SetLry(tempZone->GetLry()); - } - // otherwise get a boundingbox that comprises all the neumes in the syllable - else { - ListOfObjects children; - InterfaceComparison comp(INTERFACE_FACSIMILE); - syl->GetFirstAncestor(SYLLABLE)->FindAllDescendantsByComparison(&children, &comp); - for (auto iter2 = children.begin(); iter2 != children.end(); ++iter2) { - FacsimileInterface *temp = (*iter2)->GetFacsimileInterface(); - assert(temp); - Zone *tempZone = vrv_cast(temp->GetZone()); - assert(tempZone); - if (temp->HasFacs()) { - zone->SetUlx(tempZone->GetUlx()); - zone->SetUly(tempZone->GetUly()); - zone->SetLrx(tempZone->GetLrx()); - zone->SetLry(tempZone->GetLry()); - } - } - } - - // make the bounding box a little bigger and lower so it's easier to edit - const int offSetUly = 100; - const int offSetLrx = 100; - const int offSetLry = 200; + zone->SetUlx(parent->GetFirst(NEUME)->GetFirst(NC)->GetFacsimileInterface()->GetZone()->GetUlx()); + zone->SetUly(oldSyl->GetFacsimileInterface()->GetZone()->GetUly()); + zone->SetLrx(parent->GetLast(NEUME)->GetLast(NC)->GetFacsimileInterface()->GetZone()->GetLrx()); + zone->SetLry(oldSyl->GetFacsimileInterface()->GetZone()->GetLry()); - zone->SetUly(zone->GetUly() + offSetUly); - zone->SetLrx(zone->GetLrx() + offSetLrx); - zone->SetLry(zone->GetLry() + offSetLry); + // Make bbox larger if it has less than 2 ncs + if (parent->GetChildCount(NC, 2) <= 2) { + zone->SetLrx(zone->GetLrx() + 50); + } assert(m_doc->GetFacsimile()); m_doc->GetFacsimile()->FindDescendantByType(SURFACE)->AddChild(zone); - FacsimileInterface *fi = vrv_cast((*syl).GetFacsimileInterface()); + FacsimileInterface *fi = syl->GetFacsimileInterface(); assert(fi); fi->AttachZone(zone); - - // syl->ResetFacsimile(); - // syl->SetFacs(zone->GetID()); } } - parent->ReorderByXPos(); - if (doubleParent == NULL) { - return false; - } - doubleParent->AddChild(parent); - - Layer *layer = vrv_cast(parent->GetFirstAncestor(LAYER)); - assert(layer); - layer->ReorderByXPos(); + secondParent->AddChild(parent); } // if there's only one full parent we just add the other elements to it @@ -2640,7 +2577,6 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e (*it)->MoveItselfTo(parent); } } - parent->ReorderByXPos(); } // if there is more than 1 full parent we need to concat syl's @@ -2648,39 +2584,32 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e // also in this case we need to make sure that the facsimile of the resulting syl is correct else { if (elementClass == NC) { - if (doubleParent) { - parent = new Neume(); - for (auto it = elements.begin(); it != elements.end(); ++it) { - if ((*it)->GetParent() != parent && !(*it)->Is(SYL)) { - (*it)->MoveItselfTo(parent); - parent->ReorderByXPos(); - } + parent = new Neume(); + for (auto it = elements.begin(); it != elements.end(); ++it) { + if ((*it)->GetParent() != parent && !(*it)->Is(SYL)) { + (*it)->MoveItselfTo(parent); } - doubleParent->AddChild(parent); } - - Layer *layer = dynamic_cast(parent->GetFirstAncestor(LAYER)); - if (!layer) { - LogError("Elements does not have Layer parent. This should not happen."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Elements does not have Layer parent."); - return false; - } - - layer->ReorderByXPos(); + secondParent->AddChild(parent); } else { - std::sort(fullParents.begin(), fullParents.end(), Object::sortByUlx); - Syllable *fullSyllable = new Syllable(); + parent = new Syllable(); Syl *fullSyl = NULL; + int ulx, uly, lrx, lry; // construct concatenated string of all the syls std::u32string fullString = U""; for (auto it = fullParents.begin(); it != fullParents.end(); ++it) { Syl *syl = dynamic_cast((*it)->FindDescendantByType(SYL)); - if (syl != NULL) { + if (syl != NULL && m_doc->GetType() == Facs) { + Zone *zone = dynamic_cast(syl->GetFacsimileInterface()->GetZone()); + if (fullSyl == NULL) { fullSyl = syl; + ulx = zone->GetUlx(); + uly = zone->GetUly(); + lrx = zone->GetLrx(); + lry = zone->GetLry(); } Text *text = dynamic_cast(syl->FindDescendantByType(TEXT)); @@ -2688,84 +2617,41 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e std::u32string currentString = text->GetText(); fullString = fullString + currentString; } + + ulx = zone->GetUlx() < ulx ? zone->GetUlx() : ulx; + uly = zone->GetUly() < uly ? zone->GetUly() : uly; + lrx = zone->GetLrx() > lrx ? zone->GetLrx() : lrx; + lry = zone->GetLry() > lry ? zone->GetLry() : lry; } } - // find the new boundingbox comprising all of the text - int ulx = -1, uly = -1, lrx = -1, lry = -1; - for (auto it = fullParents.begin(); it != fullParents.end(); ++it) { - Object *par = vrv_cast(*it); - assert(par); - Syl *descSyl = vrv_cast(par->FindDescendantByType(SYL)); - assert(descSyl); - // FacsimileInterface *facsInter = dynamic_cast - // ((*it)->FindDescendantByType(SYL)->GetFacsimileInterface()); - if (descSyl != NULL) { - FacsimileInterface *facsInter - = dynamic_cast(descSyl->GetFacsimileInterface()); - - if (facsInter != NULL) { - if (ulx == -1 || ulx > facsInter->GetDrawingX()) { - ulx = facsInter->GetDrawingX(); - } - - if (lrx < facsInter->GetWidth() + facsInter->GetDrawingX()) { - lrx = facsInter->GetWidth() + facsInter->GetDrawingX(); - } - - if (uly == -1 || uly > facsInter->GetDrawingY()) { - uly = facsInter->GetDrawingY(); - } - if (lry < facsInter->GetHeight() + facsInter->GetDrawingY()) { - lry = facsInter->GetHeight() + facsInter->GetDrawingY(); - } - } - } - } - assert(fullSyl); - Text *text = vrv_cast(fullSyl->FindDescendantByType(TEXT)); - assert(text); - text->SetText(fullString); - assert(fullSyllable); - fullSyllable->AddChild(fullSyl); - // Move elements to the new group syllable for (auto it = elements.begin(); it != elements.end(); ++it) { - if ((*it)->GetParent() != fullSyllable && !(*it)->Is(SYL)) { - (*it)->MoveItselfTo(fullSyllable); + if ((*it)->GetParent() != parent && !(*it)->Is(SYL)) { + (*it)->MoveItselfTo(parent); } } - if (doubleParent == NULL) { - LogError("No second level parent!"); - return false; - } - doubleParent->AddChild(fullSyllable); - Layer *layer = vrv_cast(fullSyllable->GetFirstAncestor(LAYER)); - assert(layer); - if (ulx >= 0 && uly >= 0 && lrx >= 0 && lry >= 0) { - FacsimileInterface *facsInter = vrv_cast(fullSyl->GetFacsimileInterface()); - assert(facsInter); - Zone *zone = vrv_cast(facsInter->GetZone()); - assert(zone); - assert(ulx >= 0); + Text *fullText = dynamic_cast(fullSyl->FindDescendantByType(TEXT)); + fullText->SetText(fullString); + parent->AddChild(fullSyl); + + if (m_doc->GetType() == Facs) { + Zone *zone = dynamic_cast(fullSyl->GetFacsimileInterface()->GetZone()); zone->SetUlx(ulx); - assert(uly >= 0); zone->SetUly(uly); - assert(lrx >= 0); zone->SetLrx(lrx); - assert(lry >= 0); zone->SetLry(lry); } - layer->ReorderByXPos(); - parent = fullSyllable; + + secondParent->AddChild(parent); } } // change the pitch of any pitched elements whose clef may have changed assert(newClef); ListOfObjects pitchedChildren; - if (sortedSyllables.size()) { - for (auto it = sortedSyllables.begin(); it != sortedSyllables.end(); ++it) { + if (syllables.size()) { + for (auto it = syllables.begin(); it != syllables.end(); ++it) { Syllable *syllable = dynamic_cast(*it); if (clefsBefore[syllable] != newClef) { syllable->FindAllDescendantsByComparison(&pitchedChildren, &pitchComp); @@ -2781,11 +2667,7 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e Object *obj = (*it).first; obj->ClearRelinquishedChildren(); if (obj->GetChildCount() == 0) { - if (doubleParent == NULL) { - LogError("No second level parent!"); - return false; - } - doubleParent->DeleteChild(obj); + secondParent->DeleteChild(obj); } else if (obj->GetChildCount() == (obj->GetChildCount(SYL) + obj->GetChildCount(DIVLINE) + obj->GetChildCount(ACCID) @@ -2796,30 +2678,25 @@ bool EditorToolkitNeume::Group(std::string groupType, std::vector e } while ((leftover = obj->FindDescendantByType(DIVLINE)) != NULL) { leftover->MoveItselfTo(parent); - parent->ReorderByXPos(); obj->ClearRelinquishedChildren(); } while ((leftover = obj->FindDescendantByType(ACCID)) != NULL) { leftover->MoveItselfTo(parent); - parent->ReorderByXPos(); obj->ClearRelinquishedChildren(); } while ((leftover = obj->FindDescendantByType(CLEF)) != NULL) { leftover->MoveItselfTo(parent); - parent->ReorderByXPos(); obj->ClearRelinquishedChildren(); } - if (doubleParent == NULL) { - LogError("No second level parent!"); - return false; - } - doubleParent->DeleteChild(obj); + secondParent->DeleteChild(obj); } } - m_infoObject.import("uuid", parent->GetID()); - m_infoObject.import("status", status); - m_infoObject.import("message", message); + secondParent->ReorderByXPos(); + + m_editInfo.import("uuid", parent->GetID()); + m_editInfo.import("status", status); + m_editInfo.import("message", message); return true; } @@ -2854,8 +2731,8 @@ bool EditorToolkitNeume::Ungroup(std::string groupType, std::vector // Check if you can get drawing page if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } @@ -2917,8 +2794,8 @@ bool EditorToolkitNeume::Ungroup(std::string groupType, std::vector } else { LogError("Unable to toggle ligature within ungroup ncs!"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Unable to toggle ligature within ungroup ncs."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Unable to toggle ligature within ungroup ncs."); return false; } } @@ -2934,6 +2811,7 @@ bool EditorToolkitNeume::Ungroup(std::string groupType, std::vector fparent->ReorderByXPos(); uuidArray << (*it); it = elementIds.erase(it); + if (it == elementIds.end()) break; el = m_doc->GetDrawingPage()->FindDescendantByID(*it); } } @@ -2989,8 +2867,8 @@ bool EditorToolkitNeume::Ungroup(std::string groupType, std::vector else { LogError("Invalid groupType for ungrouping"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Invalid groupType for ungrouping."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Invalid groupType for ungrouping."); return false; } } @@ -3092,9 +2970,9 @@ bool EditorToolkitNeume::Ungroup(std::string groupType, std::vector } } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); - m_infoObject.import("uuid", uuidArray); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); + m_editInfo.import("uuid", uuidArray); return true; } @@ -3103,8 +2981,8 @@ bool EditorToolkitNeume::SplitNeume(std::string neumeId, std::string ncId) // Check if you can get drawing page if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } @@ -3126,8 +3004,8 @@ bool EditorToolkitNeume::SplitNeume(std::string neumeId, std::string ncId) int nLen = fparent->GetChildCount(); if (nLen == 0) { LogError("The selected neume has no children."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "The selected neume has no children."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "The selected neume has no children."); return false; } @@ -3135,8 +3013,8 @@ bool EditorToolkitNeume::SplitNeume(std::string neumeId, std::string ncId) int fIdx = fparent->GetChildIndex(elNc); if (fIdx == -1) { LogError("The selected neume component is not a child of the selected neume."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "The selected neume component is not a child of the selected neume."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "The selected neume component is not a child of the selected neume."); return false; } // if click on a ligature, ncId point to the second nc in the ligature, thus minus 1 @@ -3170,9 +3048,9 @@ bool EditorToolkitNeume::SplitNeume(std::string neumeId, std::string ncId) // insert newParent to sparent sparent->InsertAfter(fparent, newParent); - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); - m_infoObject.import("uuid", uuidArray); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); + m_editInfo.import("uuid", uuidArray); return true; } @@ -3181,15 +3059,15 @@ bool EditorToolkitNeume::ChangeGroup(std::string elementId, std::string contour) // Check if you can get drawing page if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } Neume *el = dynamic_cast(m_doc->GetDrawingPage()->FindDescendantByID(elementId)); if (el == NULL) { LogError("Unable to find neume with id %s", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Unable to find neume with id " + elementId + "."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Unable to find neume with id " + elementId + "."); return false; } Nc *firstChild = NULL; @@ -3253,8 +3131,8 @@ bool EditorToolkitNeume::ChangeGroup(std::string elementId, std::string contour) LogError("Unsupported character in contour."); delete newNc; delete zone; - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Unsupported character in contour."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Unsupported character in contour."); return false; } zone->SetUlx(newUlx); @@ -3277,9 +3155,9 @@ bool EditorToolkitNeume::ChangeGroup(std::string elementId, std::string contour) initialLry = newLry; prevNc = newNc; } - m_infoObject.import("uuid", el->GetID()); - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("uuid", el->GetID()); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; } @@ -3297,8 +3175,8 @@ bool EditorToolkitNeume::ToggleLigature(std::vector elementIds) // Check if you can get drawing page if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } @@ -3312,8 +3190,8 @@ bool EditorToolkitNeume::ToggleLigature(std::vector elementIds) int secondIdx = secondNc->GetIdx(); if (std::abs(firstIdx - secondIdx) != 1) { LogError("The selected ncs are not adjacent."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "The selected ncs are not adjacent."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "The selected ncs are not adjacent."); return false; } @@ -3371,20 +3249,20 @@ bool EditorToolkitNeume::ToggleLigature(std::vector elementIds) } // else { // LogError("isLigature is invalid!"); - // m_infoObject.import("status", "FAILURE"); - // m_infoObject.import("message", "isLigature value '" + isLigature + "' is invalid."); + // m_editInfo.import("status", "FAILURE"); + // m_editInfo.import("message", "isLigature value '" + isLigature + "' is invalid."); // return false; // } if (success1 && success2 && m_doc->GetType() != Facs) { m_doc->PrepareData(); m_doc->GetDrawingPage()->LayOut(true); } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); if (!(success1 && success2)) { LogWarning("Unable to update ligature attribute"); - m_infoObject.import("message", "Unable to update ligature attribute."); - m_infoObject.import("status", "WARNING"); + m_editInfo.import("message", "Unable to update ligature attribute."); + m_editInfo.import("status", "WARNING"); } surface->AddChild(zone); @@ -3395,15 +3273,15 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) { if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } if (m_doc->GetType() != Facs) { LogWarning("Staff re-association is only available in facsimile mode."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Staff re-association is only available in facsimile mode."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Staff re-association is only available in facsimile mode."); return false; } @@ -3411,8 +3289,8 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) assert(element); if (element == NULL) { LogError("No element exists with ID '%s'.", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No element exists with ID" + elementId + "."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No element exists with ID" + elementId + "."); return false; } @@ -3420,8 +3298,8 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) || element->Is(ACCID))) { LogError("Element is of type %s, but only Syllables, Custos, Clefs, Divlines, and Accids can change staves.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element is of type " + element->GetClassName() + ", but only Syllables, Custos, Clefs, DivLines, and Accids can change staves."); return false; @@ -3442,8 +3320,8 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) LayerElement *layerElement = dynamic_cast(element); if (!layerElement->GenerateZoneBounds(&ulx, &uly, &lrx, &lry)) { LogError("Couldn't generate bounding box for syllable."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Couldn't generate bounding box for syllable."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Couldn't generate bounding box for syllable."); return false; } comp.x = (lrx + ulx) / 2; @@ -3451,8 +3329,8 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) } else { LogError("This element does not have a facsimile."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "This element does not have a facsimile."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "This element does not have a facsimile."); return false; } @@ -3465,8 +3343,8 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) } else { LogError("Could not find any staves. This should not happen"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not find any staves. This should not happen"); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not find any staves. This should not happen"); return false; } @@ -3475,8 +3353,8 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) assert(parent); if (parent == NULL || sParent == NULL) { LogError("Couldn't find staff parent of element with id '%s'", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Couldn't find staff parent of element with id " + elementId); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Couldn't find staff parent of element with id " + elementId); return false; } @@ -3484,16 +3362,16 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) assert(LAYER); if (layer == NULL) { LogError("Couldn't find layer child of staff. This should not happen"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Couldn't find layer child of staff. This should not happen"); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Couldn't find layer child of staff. This should not happen"); return false; } if (layer == parent) { - m_infoObject.import("status", "WARNING"); - m_infoObject.import("message", "Moving to the same staff as before."); - m_infoObject.import("elementId", elementId); - m_infoObject.import("newStaffId", staff->GetID()); + m_editInfo.import("status", "WARNING"); + m_editInfo.import("message", "Moving to the same staff as before."); + m_editInfo.import("elementId", elementId); + m_editInfo.import("newStaffId", staff->GetID()); return true; } @@ -3551,8 +3429,8 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) // Adjust clefline if (!AdjustClefLineFromPosition(dynamic_cast(element), staff)) { LogError("Could not adjust clef line of %s", element->GetID().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to set clef line from facsimile."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to set clef line from facsimile."); return false; } @@ -3580,19 +3458,19 @@ bool EditorToolkitNeume::ChangeStaff(std::string elementId) if (!(element->Is(ACCID) || element->Is(DIVLINE))) { if (!AdjustPitchFromPosition(element)) { LogError("Could not adjust pitch of %s", element->GetID().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to properly set pitch."); - m_infoObject.import("elementId", element->GetID()); - m_infoObject.import("newStaffId", staff->GetID()); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to properly set pitch."); + m_editInfo.import("elementId", element->GetID()); + m_editInfo.import("newStaffId", staff->GetID()); return false; } } } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); - m_infoObject.import("elementId", elementId); - m_infoObject.import("newStaffId", staff->GetID()); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); + m_editInfo.import("elementId", elementId); + m_editInfo.import("newStaffId", staff->GetID()); return true; } @@ -3600,15 +3478,15 @@ bool EditorToolkitNeume::ChangeStaffTo(std::string elementId, std::string staffI { if (!m_doc->GetDrawingPage()) { LogError("Could not get the drawing page"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not get the drawing page."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not get the drawing page."); return false; } if (m_doc->GetType() != Facs) { LogWarning("Staff re-association is only available in facsimile mode."); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Staff re-association is only available in facsimile mode."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Staff re-association is only available in facsimile mode."); return false; } @@ -3616,16 +3494,16 @@ bool EditorToolkitNeume::ChangeStaffTo(std::string elementId, std::string staffI assert(element); if (element == NULL) { LogError("No element exists with ID '%s'.", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "No element exists with ID" + elementId + "."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "No element exists with ID" + elementId + "."); return false; } if (!(element->Is(CLEF) || element->Is(DIVLINE) || element->Is(ACCID))) { LogError("Element is of type %s, but only Clefs, Divlines, and Accids can change to a specified staff.", element->GetClassName().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Element is of type " + element->GetClassName() + ", but only Clefs, Divlines, and Accids can change to a specified staff."); return false; @@ -3635,8 +3513,8 @@ bool EditorToolkitNeume::ChangeStaffTo(std::string elementId, std::string staffI if (!staff) { LogError("Could not find any staves. This should not happen"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Could not find any staves. This should not happen"); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Could not find any staves. This should not happen"); return false; } @@ -3645,8 +3523,8 @@ bool EditorToolkitNeume::ChangeStaffTo(std::string elementId, std::string staffI assert(parent); if (parent == NULL || sParent == NULL) { LogError("Couldn't find staff parent of element with id '%s'", elementId.c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Couldn't find staff parent of element with id " + elementId); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Couldn't find staff parent of element with id " + elementId); return false; } @@ -3654,16 +3532,16 @@ bool EditorToolkitNeume::ChangeStaffTo(std::string elementId, std::string staffI assert(LAYER); if (layer == NULL) { LogError("Couldn't find layer child of staff. This should not happen"); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Couldn't find layer child of staff. This should not happen"); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Couldn't find layer child of staff. This should not happen"); return false; } if (layer == parent) { - m_infoObject.import("status", "WARNING"); - m_infoObject.import("message", "Moving to the same staff as before."); - m_infoObject.import("elementId", elementId); - m_infoObject.import("newStaffId", staff->GetID()); + m_editInfo.import("status", "WARNING"); + m_editInfo.import("message", "Moving to the same staff as before."); + m_editInfo.import("elementId", elementId); + m_editInfo.import("newStaffId", staff->GetID()); return true; } @@ -3721,8 +3599,8 @@ bool EditorToolkitNeume::ChangeStaffTo(std::string elementId, std::string staffI // Adjust clefline if (!AdjustClefLineFromPosition(dynamic_cast(element), staff)) { LogError("Could not adjust clef line of %s", element->GetID().c_str()); - m_infoObject.import("status", "FAILURE"); - m_infoObject.import("message", "Failed to set clef line from facsimile."); + m_editInfo.import("status", "FAILURE"); + m_editInfo.import("message", "Failed to set clef line from facsimile."); return false; } @@ -3749,10 +3627,10 @@ bool EditorToolkitNeume::ChangeStaffTo(std::string elementId, std::string staffI parent->ReorderByXPos(); } - m_infoObject.import("status", "OK"); - m_infoObject.import("message", ""); - m_infoObject.import("elementId", elementId); - m_infoObject.import("newStaffId", staff->GetID()); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); + m_editInfo.import("elementId", elementId); + m_editInfo.import("newStaffId", staff->GetID()); return true; } diff --git a/src/object.cpp b/src/object.cpp index 17b6f97426c..63e8fa0ca2d 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -1298,7 +1298,12 @@ bool Object::sortByUlx(Object *a, Object *b) if (a->Is(NC) && b->Is(NC)) { Nc *nca = dynamic_cast(a); Nc *ncb = dynamic_cast(b); - if (nca->HasLigated() && ncb->HasLigated() && (a->GetParent() == b->GetParent())) { + Zone *zonea = dynamic_cast(nca->GetFacsimileInterface()->GetZone()); + assert(zonea); + Zone *zoneb = dynamic_cast(ncb->GetFacsimileInterface()->GetZone()); + assert(zoneb); + if (nca->HasLigated() && ncb->HasLigated() && (a->GetParent() == b->GetParent()) + && (zonea->GetUlx() == zoneb->GetUlx())) { Object *parent = a->GetParent(); assert(parent); if (abs(parent->GetChildIndex(a) - parent->GetChildIndex(b)) == 1) {