From c5ac4735e46bc8043a96e9e8db6c112cce2947a3 Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Sun, 4 Apr 2021 18:18:17 -0700 Subject: [PATCH] Instrument picker. Instrument picker allows us to assign the different instruments on field. Making toolbars more modular, layout out to the side by default. incrementing Layout configuration value so it gets refreshed Putting instrument into status. Making symbol buttons a selector. --- CMakeLists.txt | 6 +- src/CalChartDoc.cpp | 16 +- src/CalChartDoc.h | 15 +- src/CalChartDocCommand.cpp | 2 - src/CalChartFrame.cpp | 178 ++++++++++---- src/CalChartFrame.h | 15 +- src/CalChartToolBar.cpp | 25 +- src/CalChartToolBar.h | 3 +- src/CalChartView.cpp | 39 ++- src/CalChartView.h | 3 +- src/ColorSetupCanvas.cpp | 20 +- src/FieldControlsToolBar.cpp | 26 ++ src/FieldControlsToolBar.h | 3 + src/PointPicker.cpp | 72 +++--- src/PointPicker.h | 13 +- src/PreferencesGeneralSetup.cpp | 2 +- src/PrintContinuityEditor.h | 2 +- src/SetupInstruments.cpp | 319 +++++++++++++++++++++++++ src/SetupInstruments.h | 71 ++++++ src/{show_ui.cpp => SetupMarchers.cpp} | 222 +++++++++-------- src/{show_ui.h => SetupMarchers.h} | 29 ++- src/basic_ui.h | 30 +++ src/confgr.cpp | 3 +- src/confgr.h | 2 +- src/core/animate.cpp | 2 +- src/core/cc_fileformat.h | 1 + src/core/cc_point.cpp | 8 +- src/core/cc_point.h | 22 +- src/core/cc_sheet.cpp | 30 ++- src/core/cc_sheet.h | 3 + src/core/cc_show.cpp | 183 +++++++++++--- src/core/cc_show.h | 23 +- src/core/print_ps.cpp | 2 +- src/draw.cpp | 22 +- src/print_ps_dialog.cpp | 3 +- src/ui_enums.h | 12 +- 36 files changed, 1083 insertions(+), 344 deletions(-) create mode 100644 src/SetupInstruments.cpp create mode 100644 src/SetupInstruments.h rename src/{show_ui.cpp => SetupMarchers.cpp} (59%) rename src/{show_ui.h => SetupMarchers.h} (73%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50db9d9e..42e0bcbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,6 +244,10 @@ add_executable ( ${CMAKE_CURRENT_SOURCE_DIR}/src/PreferencesUtils.h ${CMAKE_CURRENT_SOURCE_DIR}/src/PrintContinuityEditor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/PrintContinuityEditor.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/SetupInstruments.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/SetupInstruments.h + ${CMAKE_CURRENT_SOURCE_DIR}/src/SetupMarchers.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/SetupMarchers.h ${CMAKE_CURRENT_SOURCE_DIR}/src/TopFrame.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/TopFrame.h ${CMAKE_CURRENT_SOURCE_DIR}/src/TransitionSolverFrame.cpp @@ -280,8 +284,6 @@ add_executable ( ${CMAKE_CURRENT_SOURCE_DIR}/src/print_ps_dialog.h ${CMAKE_CURRENT_SOURCE_DIR}/src/setup_wizards.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/setup_wizards.h - ${CMAKE_CURRENT_SOURCE_DIR}/src/show_ui.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/show_ui.h ${CMAKE_CURRENT_SOURCE_DIR}/src/single_instance_ipc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/single_instance_ipc.h ${CMAKE_CURRENT_SOURCE_DIR}/src/ui_enums.h diff --git a/src/CalChartDoc.cpp b/src/CalChartDoc.cpp index 5d1cc9f1..3dd7a9f7 100644 --- a/src/CalChartDoc.cpp +++ b/src/CalChartDoc.cpp @@ -325,9 +325,9 @@ CalChartDoc::GetAnimation() const return mAnimation ? mAnimation.get() : nullptr; } -void CalChartDoc::WizardSetupNewShow(std::vector const& labels, int columns, ShowMode const& newmode) +void CalChartDoc::WizardSetupNewShow(std::vector> const& labelsAndInstruments, int columns, ShowMode const& newmode) { - mShow = Show::Create_CC_show(newmode, labels, columns); + mShow = Show::Create_CC_show(newmode, labelsAndInstruments, columns); UpdateAllViews(); } @@ -425,13 +425,19 @@ std::unique_ptr CalChartDoc::Create_SetShowModeCommand(CalChart::Show return std::make_unique(*this, wxT("Set Mode"), cmds); } -std::unique_ptr CalChartDoc::Create_SetShowInfoCommand(std::vector const& labels, int numColumns) +std::unique_ptr CalChartDoc::Create_SetupMarchersCommand(std::vector> const& labelsAndInstruments, int numColumns) { - auto tlabels = std::vector(labels.begin(), labels.end()); - auto show_cmds = Inject_CalChartDocArg(mShow->Create_SetShowInfoCommand(tlabels, numColumns, GetShowMode().FieldOffset())); + auto tlabels = std::vector(labelsAndInstruments.begin(), labelsAndInstruments.end()); + auto show_cmds = Inject_CalChartDocArg(mShow->Create_SetupMarchersCommand(tlabels, numColumns, GetShowMode().FieldOffset())); return std::make_unique(*this, wxT("Set show info"), show_cmds); } +std::unique_ptr CalChartDoc::Create_SetInstrumentsCommand(std::map const& dotToInstrument) +{ + auto show_cmds = Inject_CalChartDocArg(mShow->Create_SetInstrumentsCommand(dotToInstrument)); + return std::make_unique(*this, wxT("Set instruments"), show_cmds); +} + std::unique_ptr CalChartDoc::Create_SetSheetTitleCommand(const wxString& newname) { auto cmds = Create_SetSheetPair(); diff --git a/src/CalChartDoc.h b/src/CalChartDoc.h index 5705097c..10e2f986 100644 --- a/src/CalChartDoc.h +++ b/src/CalChartDoc.h @@ -120,7 +120,7 @@ class CalChartDoc : public wxDocument { void FlushAllTextWindows(); - void WizardSetupNewShow(std::vector const& labels, int columns, CalChart::ShowMode const& newmode); + void WizardSetupNewShow(std::vector> const& labelsAndInstruments, int columns, CalChart::ShowMode const& newmode); auto GetNumSheets() const { return mShow ? mShow->GetNumSheets() : 0; } @@ -136,8 +136,11 @@ class CalChartDoc : public wxDocument { std::pair> GetRelabelMapping(CalChart::Show::const_Sheet_iterator_t source_sheet, CalChart::Show::const_Sheet_iterator_t target_sheets, CalChart::Coord::units tolerance) const; auto GetPointLabel(int i) const { return mShow->GetPointLabel(i); } - - auto GetPointLabels() const { return mShow->GetPointLabels(); } + auto GetPointsLabel() const { return mShow->GetPointsLabel(); } + auto GetPointInstrument(int i) const { return mShow->GetPointInstrument(i); } + auto GetPointsInstrument() const { return mShow->GetPointsInstrument(); } + auto GetPointSymbol(int i) const { return mShow->GetPointSymbol(i); } + auto GetPointsSymbol() const { return mShow->GetPointsSymbol(); } // how to select points // Utility functions for constructing new selection lists @@ -148,6 +151,9 @@ class CalChartDoc : public wxDocument { auto MakeRemoveFromSelection(const SelectionList& sl) const { return mShow->MakeRemoveFromSelection(sl); } auto MakeToggleSelection(const SelectionList& sl) const { return mShow->MakeToggleSelection(sl); } auto MakeSelectWithLasso(const CalChart::Lasso& lasso, int ref) const { return mShow->MakeSelectWithLasso(lasso, ref); } + auto MakeSelectBySymbol(SYMBOL_TYPE symbol) const { return mShow->MakeSelectBySymbol(symbol); } + auto MakeSelectByInstrument(std::string const& instrument) const { return mShow->MakeSelectByInstrument(instrument); } + auto MakeSelectByLabel(std::string const& label) const { return mShow->MakeSelectByLabel(label); } void SetSelection(const SelectionList& sl); @@ -167,7 +173,8 @@ class CalChartDoc : public wxDocument { std::unique_ptr Create_SetSelectionCommand(const SelectionList& sl); std::unique_ptr Create_SetCurrentSheetAndSelectionCommand(int n, const SelectionList& sl); std::unique_ptr Create_SetShowModeCommand(CalChart::ShowMode const& newmode); - std::unique_ptr Create_SetShowInfoCommand(std::vector const& labels, int numColumns); + std::unique_ptr Create_SetupMarchersCommand(std::vector> const& labels, int numColumns); + std::unique_ptr Create_SetInstrumentsCommand(std::map const& dotToInstrument); std::unique_ptr Create_SetSheetTitleCommand(const wxString& newname); std::unique_ptr Create_SetSheetBeatsCommand(int beats); std::unique_ptr Create_AddSheetsCommand(const CalChart::Show::Sheet_container_t& sheets, int where); diff --git a/src/CalChartDocCommand.cpp b/src/CalChartDocCommand.cpp index 38454acf..5612826a 100644 --- a/src/CalChartDocCommand.cpp +++ b/src/CalChartDocCommand.cpp @@ -23,8 +23,6 @@ #include "CalChartDocCommand.h" #include "CalChartDoc.h" -// SetDescriptionCommand -// Set the description of this show CalChartDocCommand::CalChartDocCommand(CalChartDoc& doc, const wxString& cmd_descr, CC_doc_command_pair const& cmds) : CalChartDocCommand(doc, cmd_descr, std::vector{ cmds }) { diff --git a/src/CalChartFrame.cpp b/src/CalChartFrame.cpp index 750c2f30..57f76e9a 100644 --- a/src/CalChartFrame.cpp +++ b/src/CalChartFrame.cpp @@ -38,6 +38,8 @@ #include "FieldThumbnailBrowser.h" #include "PointPicker.h" #include "PrintContinuityEditor.h" +#include "SetupInstruments.h" +#include "SetupMarchers.h" #include "TopFrame.h" #include "TransitionSolverFrame.h" #include "TransitionSolverView.h" @@ -53,7 +55,6 @@ #include "modes.h" #include "platconf.h" #include "print_ps_dialog.h" -#include "show_ui.h" #include "ui_enums.h" #include @@ -79,7 +80,8 @@ static std::map kAUIEnumToString = { { CALCHART__ViewAnimationErrors, "Marching Errors" }, { CALCHART__ViewAnimation, "Animation" }, { CALCHART__ViewPrintContinuity, "Print Continuity" }, - { CALCHART__ViewToolBar, "ToolBar" }, + { CALCHART__ViewLassosToolBar, "Lassos ToolBar" }, + { CALCHART__ViewMarcherToolBar, "Marcher ToolBar" }, }; BEGIN_EVENT_TABLE(CalChartFrame, wxDocChildFrame) @@ -100,9 +102,10 @@ EVT_MENU(CALCHART__RELABEL, CalChartFrame::OnCmdRelabel) EVT_MENU(CALCHART__PRINT_EDIT_CONTINUITY, CalChartFrame::OnCmdEditPrintCont) EVT_MENU(CALCHART__SET_SHEET_TITLE, CalChartFrame::OnCmdSetSheetTitle) EVT_MENU(CALCHART__SET_BEATS, CalChartFrame::OnCmdSetBeats) -EVT_MENU(CALCHART__SETUP, CalChartFrame::OnCmdSetup) +EVT_MENU(CALCHART__SETUPMARCHERS, CalChartFrame::OnCmdSetupMarchers) +EVT_MENU(CALCHART__SETUPINSTRUMENTS, CalChartFrame::OnCmdSetupInstruments) EVT_MENU(CALCHART__SETMODE, CalChartFrame::OnCmdSetMode) -EVT_MENU(CALCHART__POINTS, CalChartFrame::OnCmdPoints) +EVT_MENU(CALCHART__POINTPICKER, CalChartFrame::OnCmdPointPicker) EVT_MENU(CALCHART__SELECT_ALL, CalChartFrame::OnCmdSelectAll) EVT_MENU(wxID_ABOUT, CalChartFrame::OnCmdAbout) EVT_MENU(wxID_HELP, CalChartFrame::OnCmdHelp) @@ -119,7 +122,8 @@ EVT_MENU(CALCHART__ViewContinuityInfo, CalChartFrame::OnCmd_AdjustViews) EVT_MENU(CALCHART__ViewAnimationErrors, CalChartFrame::OnCmd_AdjustViews) EVT_MENU(CALCHART__ViewAnimation, CalChartFrame::OnCmd_AdjustViews) EVT_MENU(CALCHART__ViewPrintContinuity, CalChartFrame::OnCmd_AdjustViews) -EVT_MENU(CALCHART__ViewToolBar, CalChartFrame::OnCmd_AdjustViews) +EVT_MENU(CALCHART__ViewLassosToolBar, CalChartFrame::OnCmd_AdjustViews) +EVT_MENU(CALCHART__ViewMarcherToolBar, CalChartFrame::OnCmd_AdjustViews) EVT_MENU(CALCHART__ViewSwapFieldAndAnimate, CalChartFrame::OnCmd_SwapAnimation) EVT_MENU(CALCHART__ViewZoomFit, CalChartFrame::OnCmd_ZoomFit) EVT_MENU(CALCHART__ViewZoomIn, CalChartFrame::OnCmd_ZoomIn) @@ -165,6 +169,9 @@ EVT_MENU(CALCHART__draw_paths, CalChartFrame::OnCmd_DrawPaths) EVT_SLIDER(CALCHART__slider_zoom, CalChartFrame::zoom_callback) EVT_CHOICE(CALCHART__refnum_callback, CalChartFrame::OnCmd_ReferenceNumber) EVT_CHOICE(CALCHART__GhostControls, CalChartFrame::OnCmd_GhostOption) +EVT_CHOICE(CALCHART__InstrumentChoice, CalChartFrame::OnCmd_InstrumentSelection) +EVT_CHOICE(CALCHART__SymbolChoice, CalChartFrame::OnCmd_SymbolSelection) +EVT_CHOICE(CALCHART__MarcherChoice, CalChartFrame::OnCmd_MarcherSelection) EVT_CHECKBOX(CALCHART__draw_paths, CalChartFrame::OnEnableDrawPaths) EVT_MENU(CALCHART__ResetReferencePoint, CalChartFrame::OnCmd_ResetReferencePoint) EVT_BUTTON(CALCHART__ResetReferencePoint, CalChartFrame::OnCmd_ResetReferencePoint) @@ -229,7 +236,7 @@ CalChartFrame::CalChartFrame(wxDocument* doc, wxView* view, wxMenu* file_menu = new wxMenu; file_menu->Append(wxID_NEW, wxT("&New Show\tCTRL-N"), wxT("Create a new show")); file_menu->Append(wxID_OPEN, wxT("&Open...\tCTRL-O"), wxT("Load a saved show")); - file_menu->Append(CALCHART__IMPORT_CONT_FILE, wxT("&Import Continuity...\tCTRL-I"), wxT("Import continuity text")); + file_menu->Append(CALCHART__IMPORT_CONT_FILE, wxT("&Import Continuity...\tCTRL-SHIFT-I"), wxT("Import continuity text")); file_menu->Append(wxID_SAVE, wxT("&Save\tCTRL-S"), wxT("Save show")); file_menu->Append(wxID_SAVEAS, wxT("Save &As...\tCTRL-SHIFT-S"), wxT("Save show as a new name")); file_menu->Append(CALCHART__wxID_PRINT, wxT("&Print...\tCTRL-P"), wxT("Print this show")); @@ -258,10 +265,11 @@ CalChartFrame::CalChartFrame(wxDocument* doc, wxView* view, edit_menu->Append(CALCHART__RELABEL, wxT("&Relabel Sheets\tCTRL-R"), wxT("Relabel all stuntsheets after this one")); edit_menu->Append(CALCHART__APPEND_FILE, wxT("Append Show..."), wxT("Append a show to the end")); edit_menu->AppendSeparator(); - edit_menu->Append(CALCHART__SETUP, wxT("Set &Up Marchers...\tCTRL-U"), wxT("Setup number of marchers")); + edit_menu->Append(CALCHART__SETUPMARCHERS, wxT("Set &Up Marchers...\tCTRL-U"), wxT("Setup number of marchers")); + edit_menu->Append(CALCHART__SETUPINSTRUMENTS, wxT("Set &Instruments...\tCTRL-I"), wxT("Set instruments")); edit_menu->Append(CALCHART__SETMODE, wxT("Set Show &Mode..."), wxT("Set the show mode")); edit_menu->AppendSeparator(); - edit_menu->Append(CALCHART__POINTS, wxT("&Point Selections..."), wxT("Select Points")); + edit_menu->Append(CALCHART__POINTPICKER, wxT("Point Picker...\tCTRL-SHIFT-A"), wxT("Point Picker")); edit_menu->Append(CALCHART__SELECT_ALL, wxT("Select &All...\tCTRL-A"), wxT("Select All Points")); edit_menu->AppendSeparator(); edit_menu->Append(CALCHART__SET_SHEET_TITLE, wxT("Set Sheet &Title...\tCTRL-T"), wxT("Change the title of this stuntsheet")); @@ -282,7 +290,7 @@ CalChartFrame::CalChartFrame(wxDocument* doc, wxView* view, wxMenu* view_menu = new wxMenu; view_menu->Append(CALCHART__ViewSwapFieldAndAnimate, wxT("View Animation\tCTRL-RETURN"), wxT("View Animation or Field")); view_menu->AppendSeparator(); - for (int i = CALCHART__ViewFieldThumbnail; i <= CALCHART__ViewToolBar; ++i) { + for (int i = CALCHART__ViewFieldThumbnail; i <= CALCHART__ViewMarcherToolBar; ++i) { view_menu->Append(i, std::string("Show ") + kAUIEnumToString[i], std::string("Controls Displaying ") + kAUIEnumToString[i]); } view_menu->AppendSeparator(); @@ -313,8 +321,10 @@ CalChartFrame::CalChartFrame(wxDocument* doc, wxView* view, refreshGhostOptionStates(); // Add a toolbar - mToolBar = CreateMainAuiToolBar(this, wxID_ANY, wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_OVERFLOW); - mToolBar->SetFont(ResizeFont(mToolBar->GetFont(), GetToolBarFontSize())); + mLassosToolBar = CreateLassosAndMoves(this, wxID_ANY, wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_OVERFLOW); + mLassosToolBar->SetFont(ResizeFont(mLassosToolBar->GetFont(), GetToolBarFontSize())); + mMarcherToolBar = CreateDotModifiers(this, wxID_ANY, wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_OVERFLOW); + mMarcherToolBar->SetFont(ResizeFont(mMarcherToolBar->GetFont(), GetToolBarFontSize())); SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENU)); // sanity: Don't let the user zoom too low @@ -350,7 +360,9 @@ CalChartFrame::CalChartFrame(wxDocument* doc, wxView* view, mLookupEnumToSubWindow[CALCHART__ViewAnimationErrors] = mAnimationErrorsPanel; mLookupEnumToSubWindow[CALCHART__ViewAnimation] = mAnimationPanel; mLookupEnumToSubWindow[CALCHART__ViewPrintContinuity] = mPrintContinuityEditor; - mLookupEnumToSubWindow[CALCHART__ViewToolBar] = mToolBar; + mLookupEnumToSubWindow[CALCHART__ViewLassosToolBar] = mLassosToolBar; + mLookupEnumToSubWindow[CALCHART__ViewMarcherToolBar] = mMarcherToolBar; + for (auto&& i : mLookupEnumToSubWindow) { mLookupSubWindowToEnum[i.second] = i.first; } @@ -371,17 +383,18 @@ CalChartFrame::CalChartFrame(wxDocument* doc, wxView* view, mAUIManager->AddPane(mAnimationErrorsPanel, wxAuiPaneInfo().Name(kAUIEnumToString[CALCHART__ViewAnimationErrors]).Caption(kAUIEnumToString[CALCHART__ViewAnimationErrors]).Right().BestSize(GetAnimationErrorsSize())); mAUIManager->AddPane(mPrintContinuityEditor, wxAuiPaneInfo().Name(kAUIEnumToString[CALCHART__ViewPrintContinuity]).Caption(kAUIEnumToString[CALCHART__ViewPrintContinuity]).Right().BestSize(GetPrintContinuitySize())); mAUIManager->AddPane(mControls, wxAuiPaneInfo().Name(kAUIEnumToString[CALCHART__ViewFieldControls]).Caption(kAUIEnumToString[CALCHART__ViewFieldControls]).ToolbarPane().Top()); - mAUIManager->AddPane(mToolBar, wxAuiPaneInfo().Name(kAUIEnumToString[CALCHART__ViewToolBar]).Caption(kAUIEnumToString[CALCHART__ViewToolBar]).ToolbarPane().Top()); + mAUIManager->AddPane(mLassosToolBar, wxAuiPaneInfo().Name(kAUIEnumToString[CALCHART__ViewLassosToolBar]).Caption(kAUIEnumToString[CALCHART__ViewLassosToolBar]).ToolbarPane().Left()); + mAUIManager->AddPane(mMarcherToolBar, wxAuiPaneInfo().Name(kAUIEnumToString[CALCHART__ViewMarcherToolBar]).Caption(kAUIEnumToString[CALCHART__ViewMarcherToolBar]).ToolbarPane().Top()); mAUIManager->Update(); // restore the manager with the Current visability - if (auto lastLayout = mConfig.Get_CalChartFrameAUILayout_3_6_0(); lastLayout != wxT("")) { + if (auto lastLayout = mConfig.Get_CalChartFrameAUILayout_3_6_1(); lastLayout != wxT("")) { mAUIManager->LoadPerspective(lastLayout, true); } // adjust the menu items to reflect. - for (int i = CALCHART__ViewFieldThumbnail; i <= CALCHART__ViewToolBar; ++i) { + for (int i = CALCHART__ViewFieldThumbnail; i <= CALCHART__ViewMarcherToolBar; ++i) { ChangeVisibility(mAUIManager->GetPane(mLookupEnumToSubWindow[i]).IsShown(), i); } @@ -427,7 +440,7 @@ void CalChartFrame::OnClose() // just to make sure we never end up hiding the Field ShowFieldAndHideAnimation(true); - mConfig.Set_CalChartFrameAUILayout_3_6_0(mAUIManager->SavePerspective()); + mConfig.Set_CalChartFrameAUILayout_3_6_1(mAUIManager->SavePerspective()); SetViewsOnComponents(nullptr); } @@ -698,16 +711,35 @@ void CalChartFrame::OnCmdSetBeats(wxCommandEvent& event) } } -void CalChartFrame::OnCmdSetup(wxCommandEvent& event) { Setup(); } +void CalChartFrame::OnCmdSetupMarchers(wxCommandEvent& event) +{ + if (GetShow()) { + SetupMarchers dialog(*GetShow(), this); + if (dialog.ShowModal() == wxID_OK) { + GetFieldView()->DoSetupMarchers(dialog.GetLabelsAndInstruments(), dialog.GetNumberColumns()); + } + } +} + +void CalChartFrame::OnCmdSetupInstruments(wxCommandEvent& event) +{ + if (GetShow()) { + SetupInstruments dialog(*GetShow(), this); + if (dialog.ShowModal() == wxID_OK) { + GetFieldView()->DoSetInstruments(dialog.GetInstruments()); + } + } +} void CalChartFrame::OnCmdSetMode(wxCommandEvent& event) { SetMode(); } -void CalChartFrame::OnCmdPoints(wxCommandEvent& event) +void CalChartFrame::OnCmdPointPicker(wxCommandEvent& event) { if (GetShow()) { - PointPicker* pp = new PointPicker(*GetShow(), this); - // make it modeless: - pp->Show(); + PointPicker dialog(*GetShow(), this); + if (dialog.ShowModal() == wxID_OK) { + GetShow()->SetSelection(dialog.GetSelection()); + } } } @@ -1001,12 +1033,50 @@ void CalChartFrame::OnCmd_GhostOption(wxCommandEvent& event) GetCanvas()->Refresh(); } +void CalChartFrame::OnCmd_InstrumentSelection(wxCommandEvent& event) +{ + auto choice = static_cast(FindWindow(CALCHART__InstrumentChoice)); + auto selection = choice->GetString(choice->GetSelection()); + if (selection != "" && GetShow()) { + GetShow()->SetSelection(GetShow()->MakeSelectByInstrument(selection)); + } +} + +void CalChartFrame::OnCmd_SymbolSelection(wxCommandEvent& event) +{ + auto choice = static_cast(FindWindow(CALCHART__SymbolChoice)); + auto selection = choice->GetString(choice->GetSelection()); + if (selection != "" && GetShow()) { + GetShow()->SetSelection(GetShow()->MakeSelectByInstrument(selection)); + } +} + +void CalChartFrame::OnCmd_MarcherSelection(wxCommandEvent& event) +{ + auto choice = static_cast(FindWindow(CALCHART__MarcherChoice)); + auto selection = choice->GetString(choice->GetSelection()); + if (selection != "" && GetShow()) { + GetShow()->SetSelection(GetShow()->MakeSelectByLabel(selection)); + } +} + void CalChartFrame::refreshGhostOptionStates() { bool active = GetFieldView()->getGhostModule().isActive(); GetMenuBar()->FindItem(CALCHART__GhostOff)->Enable(active); } +void CalChartFrame::refreshInUse() +{ + // handle any changes to the instrument, and update the instrument selector + auto instruments = GetShow()->GetPointsInstrument(); + auto currentInstruments = std::set(instruments.begin(), instruments.end()); + FieldControls::SetInstrumentsInUse(this, { currentInstruments.begin(), currentInstruments.end() }); + auto symbols = GetShow()->GetPointsSymbol(); + auto currentsymbols = std::set(symbols.begin(), symbols.end()); + FieldControls::SetLabelsInUse(this, GetShow()->GetPointsLabel()); +} + void CalChartFrame::OnCmd_AdjustViews(wxCommandEvent& event) { ChangeVisibility(!mAUIManager->GetPane(mLookupEnumToSubWindow[event.GetId()]).IsShown(), event.GetId()); @@ -1025,7 +1095,7 @@ void CalChartFrame::AUIIsClose(wxAuiManagerEvent& event) void CalChartFrame::ChangeVisibility(bool show, int itemid) { - if (itemid < CALCHART__ViewFieldThumbnail || itemid > CALCHART__ViewToolBar) { + if (itemid < CALCHART__ViewFieldThumbnail || itemid > CALCHART__ViewMarcherToolBar) { return; } auto name = kAUIEnumToString[itemid]; @@ -1114,7 +1184,7 @@ void CalChartFrame::SetCurrentLasso(CC_DRAG type) int toggleID = (type == CC_DRAG::POLY) ? CALCHART__poly : (type == CC_DRAG::LASSO) ? CALCHART__lasso : (type == CC_DRAG::SWAP) ? CALCHART__swap : CALCHART__box; - mToolBar->ToggleTool(toggleID, true); + mLassosToolBar->ToggleTool(toggleID, true); mCanvas->SetCurrentLasso(type); } @@ -1129,17 +1199,7 @@ void CalChartFrame::SetCurrentMove(CC_MOVE_MODES type) void CalChartFrame::ToolBarSetCurrentMove(CC_MOVE_MODES type) { // retoggle the tool because we want it to draw as selected - mToolBar->ToggleTool(CALCHART__move + type, true); -} - -void CalChartFrame::Setup() -{ - if (GetShow()) { - ShowInfoReq dialog(*GetShow(), this); - if (dialog.ShowModal() == wxID_OK) { - GetFieldView()->DoSetShowInfo(dialog.GetLabels(), dialog.GetNumberColumns()); - } - } + mLassosToolBar->ToggleTool(CALCHART__move + type, true); } void CalChartFrame::SetMode() @@ -1236,23 +1296,51 @@ float CalChartFrame::ToolBarSetZoom(float zoom_amount) return zoom_amount; } -void CalChartFrame::OnUpdate() +wxString CalChartFrame::BeatStatusText() const { - wxString tempbuf; + wxString result; auto sht = GetShow()->GetCurrentSheet(); - unsigned num = GetShow()->GetNumSheets(); - unsigned curr = GetFieldView()->GetCurrentSheetNum() + 1; + auto num = GetShow()->GetNumSheets(); + auto curr = GetFieldView()->GetCurrentSheetNum() + 1; - tempbuf.sprintf(wxT("%s%d of %d \"%.32s\" %d beats"), + result.sprintf(wxT("%s%d of %d \"%.32s\" %d beats"), GetShow()->IsModified() ? wxT("* ") : wxT(""), curr, num, (sht != GetShow()->GetSheetEnd()) ? wxString(sht->GetName()) : wxT(""), (sht != GetShow()->GetSheetEnd()) ? sht->GetBeats() : 0); - SetStatusText(tempbuf, 1); - tempbuf.Clear(); - tempbuf << GetShow()->GetSelectionList().size() << wxT(" of ") - << GetShow()->GetNumPoints() << wxT(" selected"); - SetStatusText(tempbuf, 2); + return result; +} + +wxString CalChartFrame::PointStatusText() const +{ + auto show = GetShow(); + wxString result; + auto sl = show->GetSelectionList(); + result << show->GetSelectionList().size() << wxT(" of ") + << show->GetNumPoints() << wxT(" selected"); + std::set instruments; + std::transform(sl.begin(), sl.end(), std::inserter(instruments, instruments.begin()), [&show](auto&& i) { + return show->GetPointInstrument(i); + }); + if (instruments.size()) { + result << " [ "; + auto firstTime = true; + for (auto&& i : instruments) { + if (!firstTime) { + result << ", "; + } + firstTime = false; + result << i; + } + result << " ]"; + } + return result; +} + +void CalChartFrame::OnUpdate() +{ + SetStatusText(BeatStatusText(), 1); + SetStatusText(PointStatusText(), 2); SetTitle(GetDocument()->GetUserReadableName()); mCanvas->Refresh(); @@ -1264,6 +1352,8 @@ void CalChartFrame::OnUpdate() mPrintContinuityEditor->OnUpdate(); mShadowAnimationPanel->OnUpdate(); + + refreshInUse(); } const CalChartView* CalChartFrame::GetFieldView() const diff --git a/src/CalChartFrame.h b/src/CalChartFrame.h index c5fc7211..ac442b26 100644 --- a/src/CalChartFrame.h +++ b/src/CalChartFrame.h @@ -73,9 +73,10 @@ class CalChartFrame : public wxDocChildFrame { void OnCmdEditPrintCont(wxCommandEvent& event); void OnCmdSetSheetTitle(wxCommandEvent& event); void OnCmdSetBeats(wxCommandEvent& event); - void OnCmdSetup(wxCommandEvent& event); + void OnCmdSetupMarchers(wxCommandEvent& event); + void OnCmdSetupInstruments(wxCommandEvent& event); void OnCmdSetMode(wxCommandEvent& event); - void OnCmdPoints(wxCommandEvent& event); + void OnCmdPointPicker(wxCommandEvent& event); void OnCmdSelectAll(wxCommandEvent& event); void OnCmdAbout(wxCommandEvent& event); void OnCmdHelp(wxCommandEvent& event); @@ -121,6 +122,9 @@ class CalChartFrame : public wxDocChildFrame { void OnCmd_ShowBackgroundImages(wxCommandEvent& event); void OnCmd_GhostOption(wxCommandEvent& event); + void OnCmd_InstrumentSelection(wxCommandEvent& event); + void OnCmd_SymbolSelection(wxCommandEvent& event); + void OnCmd_MarcherSelection(wxCommandEvent& event); void OnCmd_AdjustViews(wxCommandEvent& event); void OnCmd_SwapAnimation(wxCommandEvent& event); void OnCmd_DrawPaths(wxCommandEvent& event); @@ -156,7 +160,6 @@ class CalChartFrame : public wxDocChildFrame { void do_zoom(float zoom_amount); - void Setup(); void SetMode(); const FieldCanvas* GetCanvas() const { return mCanvas; } @@ -172,6 +175,7 @@ class CalChartFrame : public wxDocChildFrame { private: void refreshGhostOptionStates(); + void refreshInUse(); void ChangeFieldThumbnailVisibility(bool show); void ChangeVisibility(wxWindow* window, bool show, int itemid, std::string const& name); void ChangeVisibility(bool show, int itemid); @@ -181,6 +185,8 @@ class CalChartFrame : public wxDocChildFrame { void ShowFieldAndHideAnimation(bool showField); void SetViewsOnComponents(CalChartView* showField); + wxString BeatStatusText() const; + wxString PointStatusText() const; // the components FieldCanvas* mCanvas{}; @@ -190,8 +196,9 @@ class CalChartFrame : public wxDocChildFrame { AnimationPanel* mAnimationPanel{}; AnimationPanel* mShadowAnimationPanel{}; PrintContinuityEditor* mPrintContinuityEditor{}; - wxAuiToolBar* mToolBar; wxAuiToolBar* mControls; + wxAuiToolBar* mLassosToolBar; + wxAuiToolBar* mMarcherToolBar; std::map mLookupEnumToSubWindow; std::map mLookupSubWindowToEnum; diff --git a/src/CalChartToolBar.cpp b/src/CalChartToolBar.cpp index 6a7b6906..57180f7b 100644 --- a/src/CalChartToolBar.cpp +++ b/src/CalChartToolBar.cpp @@ -132,12 +132,10 @@ std::vector GetSecondHalfOfMainToolBar() return tb; } -std::vector GetMainToolBar() +auto GetSymbolsToolbar() { - auto first_half = GetHalfOfMainToolBar(); - auto second_half = GetSymbolsToolBar(); - first_half.insert(first_half.end(), second_half.begin(), second_half.end()); - second_half = GetSecondHalfOfMainToolBar(); + auto first_half = GetSymbolsToolBar(); + auto second_half = GetSecondHalfOfMainToolBar(); first_half.insert(first_half.end(), second_half.begin(), second_half.end()); return first_half; } @@ -151,11 +149,10 @@ std::vector GetSymbolsBitmap() return result; } -wxAuiToolBar* CreateMainAuiToolBar(wxWindow* parent, wxWindowID id, long style) +template +auto CreateAuiToolBar(wxAuiToolBar* tb, T toolbarBits) { - auto tb = new wxAuiToolBar(parent, id, wxDefaultPosition, wxDefaultSize, style); - - for (auto&& i : GetMainToolBar()) { + for (auto&& i : toolbarBits) { tb->AddTool(i.id, i.caption, i.bm, i.desc, i.kind); if (i.space) { tb->AddSeparator(); @@ -164,3 +161,13 @@ wxAuiToolBar* CreateMainAuiToolBar(wxWindow* parent, wxWindowID id, long style) tb->Realize(); return tb; } + +wxAuiToolBar* CreateLassosAndMoves(wxWindow* parent, wxWindowID id, long style) +{ + return CreateAuiToolBar(new wxAuiToolBar(parent, id, wxDefaultPosition, wxDefaultSize, style), GetHalfOfMainToolBar()); +} + +wxAuiToolBar* CreateDotModifiers(wxWindow* parent, wxWindowID id, long style) +{ + return CreateAuiToolBar(new wxAuiToolBar(parent, id, wxDefaultPosition, wxDefaultSize, style), GetSymbolsToolbar()); +} diff --git a/src/CalChartToolBar.h b/src/CalChartToolBar.h index 578e21d6..6bdb9eb0 100644 --- a/src/CalChartToolBar.h +++ b/src/CalChartToolBar.h @@ -32,4 +32,5 @@ struct ToolBarEntry; std::vector GetSymbolsBitmap(); -wxAuiToolBar* CreateMainAuiToolBar(wxWindow* parent, wxWindowID id = wxID_ANY, long style = 0); +wxAuiToolBar* CreateLassosAndMoves(wxWindow* parent, wxWindowID id = wxID_ANY, long style = 0); +wxAuiToolBar* CreateDotModifiers(wxWindow* parent, wxWindowID id = wxID_ANY, long style = 0); diff --git a/src/CalChartView.cpp b/src/CalChartView.cpp index bcf355d2..6ab2acc2 100644 --- a/src/CalChartView.cpp +++ b/src/CalChartView.cpp @@ -25,6 +25,8 @@ #include "CalChartDocCommand.h" #include "CalChartFrame.h" #include "FieldCanvas.h" +#include "SetupInstruments.h" +#include "SetupMarchers.h" #include "animate.h" #include "animate_types.h" #include "animatecommand.h" @@ -37,7 +39,6 @@ #include "draw.h" #include "ghost_module.h" #include "setup_wizards.h" -#include "show_ui.h" #include #include @@ -78,7 +79,7 @@ void CalChartView::OnDraw(wxDC* dc) if (ghostSheet != nullptr) { DrawGhostSheet(*dc, mConfig, origin, SelectionList(), - mShow->GetNumPoints(), mShow->GetPointLabels(), + mShow->GetNumPoints(), mShow->GetPointsLabel(), *ghostSheet, 0); } @@ -86,14 +87,14 @@ void CalChartView::OnDraw(wxDC* dc) if (sheet != mShow->GetSheetEnd()) { if (mCurrentReferencePoint > 0) { DrawPoints(*dc, mConfig, origin, mShow->GetSelectionList(), - mShow->GetNumPoints(), mShow->GetPointLabels(), + mShow->GetNumPoints(), mShow->GetPointsLabel(), *mShow->GetCurrentSheet(), 0, false); DrawPoints(*dc, mConfig, origin, mShow->GetSelectionList(), - mShow->GetNumPoints(), mShow->GetPointLabels(), + mShow->GetNumPoints(), mShow->GetPointsLabel(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } else { DrawPoints(*dc, mConfig, origin, mShow->GetSelectionList(), - mShow->GetNumPoints(), mShow->GetPointLabels(), + mShow->GetNumPoints(), mShow->GetPointsLabel(), *mShow->GetCurrentSheet(), mCurrentReferencePoint, true); } DrawPaths(*dc, *sheet); @@ -163,7 +164,7 @@ void CalChartView::OnWizardSetup(CalChartDoc& show) wxWizard* wizard = new wxWizard(mFrame, wxID_ANY, wxT("New Show Setup Wizard")); // page 1: // set the number of points and the labels - ShowInfoReqWizard* page1 = new ShowInfoReqWizard(wizard); + SetupMarchersWizard* page1 = new SetupMarchersWizard(wizard); // page 2: // choose the show mode @@ -174,12 +175,19 @@ void CalChartView::OnWizardSetup(CalChartDoc& show) wizard->GetPageAreaSizer()->Add(page1); if (wizard->RunWizard(page1)) { - auto labels = page1->GetLabels(); + auto labels = page1->GetLabelsAndInstruments(); auto columns = page1->GetNumberColumns(); - std::vector tlabels(labels.begin(), labels.end()); auto newmode = wxGetApp().GetShowMode(page2->GetValue()); - show.WizardSetupNewShow(tlabels, columns, newmode); + show.WizardSetupNewShow(labels, columns, newmode); + SetupInstruments dialog(show, mFrame); + if (dialog.ShowModal() == wxID_OK) { + auto instrumentMapping = dialog.GetInstruments(); + for (auto& i : instrumentMapping) { + labels.at(i.first).second = i.second; + } + show.WizardSetupNewShow(labels, columns, newmode); + } } else { wxMessageBox(wxT("Show setup not completed.\n") wxT("You can change the number of marchers\n") @@ -232,7 +240,8 @@ bool CalChartView::DoResetReferencePoint() bool CalChartView::DoSetPointsSymbol(SYMBOL_TYPE sym) { if (mShow->GetSelectionList().size() == 0) { - return false; + SetSelection(mShow->MakeSelectBySymbol(sym)); + return true; } auto cmd = mShow->Create_SetSymbolCommand(sym); GetDocument()->GetCommandProcessor()->Submit(cmd.release()); @@ -245,9 +254,15 @@ void CalChartView::DoSetMode(CalChart::ShowMode const& mode) GetDocument()->GetCommandProcessor()->Submit(cmd.release()); } -void CalChartView::DoSetShowInfo(const std::vector& labels, int numColumns) +void CalChartView::DoSetupMarchers(const std::vector>& labelsAndInstruments, int numColumns) +{ + auto cmd = mShow->Create_SetupMarchersCommand(labelsAndInstruments, numColumns); + GetDocument()->GetCommandProcessor()->Submit(cmd.release()); +} + +void CalChartView::DoSetInstruments(std::map const& dotToInstrument) { - auto cmd = mShow->Create_SetShowInfoCommand(labels, numColumns); + auto cmd = mShow->Create_SetInstrumentsCommand(dotToInstrument); GetDocument()->GetCommandProcessor()->Submit(cmd.release()); } diff --git a/src/CalChartView.h b/src/CalChartView.h index ccba8f51..2064a355 100644 --- a/src/CalChartView.h +++ b/src/CalChartView.h @@ -61,7 +61,8 @@ class CalChartView : public wxView { bool DoResetReferencePoint(); bool DoSetPointsSymbol(SYMBOL_TYPE sym); void DoSetMode(CalChart::ShowMode const& mode); - void DoSetShowInfo(std::vector const& labels, int numColumns); + void DoSetupMarchers(std::vector> const& labelsAndInstruments, int numColumns); + void DoSetInstruments(std::map const& dotToInstrument); void DoSetSheetTitle(wxString const& descr); bool DoSetSheetBeats(int beats); bool DoSetPointsLabel(bool right); diff --git a/src/ColorSetupCanvas.cpp b/src/ColorSetupCanvas.cpp index bb500a10..f7e28507 100644 --- a/src/ColorSetupCanvas.cpp +++ b/src/ColorSetupCanvas.cpp @@ -71,14 +71,14 @@ ColorSetupCanvas::ColorSetupCanvas(CalChartConfiguration& config, wxWindow* pare // Create a fake show with some points and selections to draw an example for // the user - auto labels = std::vector{ - "unsel", - "unsel", - "sel", - "sel", + auto labels = std::vector>{ + { "unsel", "" }, + { "unsel", "" }, + { "sel", "" }, + { "sel", "" }, }; - mShow->Create_SetShowInfoCommand(labels, 4, field_offset).first(*mShow); - mShow->Create_SetShowInfoCommand(labels, 4, field_offset).first(*mShow); + mShow->Create_SetupMarchersCommand(labels, 4, field_offset).first(*mShow); + mShow->Create_SetupMarchersCommand(labels, 4, field_offset).first(*mShow); mShow->Create_SetSelectionCommand(SelectionList{ 0, 2 }).first(*mShow); mShow->Create_SetSymbolCommand(SYMBOL_X).first(*mShow); mShow->Create_SetSelectionCommand(SelectionList{ 1, 3 }).first(*mShow); @@ -142,11 +142,11 @@ void ColorSetupCanvas::OnPaint(wxPaintEvent& event) list.insert(3); // draw the ghost sheet - DrawGhostSheet(dc, mConfig, mMode.Offset(), list, mShow->GetNumPoints(), mShow->GetPointLabels(), *nextSheet, 0); + DrawGhostSheet(dc, mConfig, mMode.Offset(), list, mShow->GetNumPoints(), mShow->GetPointsLabel(), *nextSheet, 0); // Draw the points - DrawPoints(dc, mConfig, mMode.Offset(), list, mShow->GetNumPoints(), mShow->GetPointLabels(), *sheet, 0, true); - DrawPoints(dc, mConfig, mMode.Offset(), list, mShow->GetNumPoints(), mShow->GetPointLabels(), *sheet, 1, false); + DrawPoints(dc, mConfig, mMode.Offset(), list, mShow->GetNumPoints(), mShow->GetPointsLabel(), *sheet, 0, true); + DrawPoints(dc, mConfig, mMode.Offset(), list, mShow->GetNumPoints(), mShow->GetPointsLabel(), *sheet, 1, false); // draw the path DrawPath(dc, mConfig, mPath, mPathEnd); diff --git a/src/FieldControlsToolBar.cpp b/src/FieldControlsToolBar.cpp index 0c808b84..c74e374b 100644 --- a/src/FieldControlsToolBar.cpp +++ b/src/FieldControlsToolBar.cpp @@ -21,6 +21,7 @@ #include "FieldControlsToolBar.h" #include "CalChartSizes.h" +#include "CalChartToolBar.h" #include "ColorPalette.h" #include "basic_ui.h" #include "cc_point.h" @@ -29,6 +30,7 @@ #include #include +#include #include #include @@ -123,6 +125,16 @@ wxAuiToolBar* CreateToolBar(wxWindow* parent, wxWindowID id, long style) ghostChioce->SetSelection(0); tb->AddControl(ghostChioce, "Ghost"); + auto instrumentChoice = new wxChoice(tb, CALCHART__InstrumentChoice); + instrumentChoice->SetMaxSize(wxSize{ StringSizeX(instrumentChoice, "Instrument"), -1 }); + instrumentChoice->SetSelection(wxNOT_FOUND); + tb->AddControl(instrumentChoice, "Instruments"); + + auto marcherChoice = new wxChoice(tb, CALCHART__MarcherChoice); + marcherChoice->SetMaxSize(wxSize{ StringSizeX(marcherChoice, "Marcher"), -1 }); + marcherChoice->SetSelection(wxNOT_FOUND); + tb->AddControl(marcherChoice, "Marcher"); + tb->SetFont(ResizeFont(tb->GetFont(), GetToolBarFontSize())); tb->Realize(); @@ -172,4 +184,18 @@ void SetGhostChoice(wxWindow* target, int which) static_cast(target->FindWindow(CALCHART__GhostControls))->SetSelection(which); } +void SetInstrumentsInUse(wxWindow* target, std::vector const& instruments) +{ + auto instrumentChoice = static_cast(target->FindWindow(CALCHART__InstrumentChoice)); + instrumentChoice->Set(std::vector(instruments.begin(), instruments.end())); + instrumentChoice->SetSelection(wxNOT_FOUND); +} + +void SetLabelsInUse(wxWindow* target, std::vector const& labels) +{ + auto choice = static_cast(target->FindWindow(CALCHART__MarcherChoice)); + choice->Set(std::vector(labels.begin(), labels.end())); + choice->SetSelection(wxNOT_FOUND); +} + } diff --git a/src/FieldControlsToolBar.h b/src/FieldControlsToolBar.h index 9a23d974..d70fcd4c 100644 --- a/src/FieldControlsToolBar.h +++ b/src/FieldControlsToolBar.h @@ -22,6 +22,7 @@ */ #include "cc_coord.h" +#include "cc_types.h" #include class wxAuiToolBar; @@ -36,5 +37,7 @@ void SetZoomAmount(wxWindow* target, double zoom); int GetRefChoice(wxWindow* target); int GetGhostChoice(wxWindow* target); void SetGhostChoice(wxWindow* target, int which); +void SetInstrumentsInUse(wxWindow* target, std::vector const& instruments); +void SetLabelsInUse(wxWindow* target, std::vector const& labels); } diff --git a/src/PointPicker.cpp b/src/PointPicker.cpp index 43104e27..d048adfc 100644 --- a/src/PointPicker.cpp +++ b/src/PointPicker.cpp @@ -28,19 +28,6 @@ #include #include -class PointPickerView : public wxView { -public: - PointPickerView() = default; - ~PointPickerView() = default; - virtual void OnDraw(wxDC* dc) { } - virtual void OnUpdate(wxView* sender, wxObject* hint = (wxObject*)NULL); -}; - -void PointPickerView::OnUpdate(wxView* sender, wxObject* hint) -{ - static_cast(GetFrame())->Update(); -} - enum { PointPicker_PointPickerList = 1100, }; @@ -50,17 +37,12 @@ EVT_LISTBOX(PointPicker_PointPickerList, PointPicker::PointPickerSelect) EVT_LISTBOX_DCLICK(PointPicker_PointPickerList, PointPicker::PointPickerAll) END_EVENT_TABLE() -PointPicker::PointPicker(CalChartDoc& shw, wxWindow* parent, wxWindowID id, +PointPicker::PointPicker(CalChartDoc const& shw, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style) : super(parent, id, caption, pos, size, style) , mShow(shw) - , mView(new PointPickerView) { - // give this a view so it can pick up document changes - mView->SetDocument(&mShow); - mView->SetFrame(this); - CreateControls(); // This fits the dalog to the minimum size dictated by the sizers @@ -75,28 +57,45 @@ void PointPicker::CreateControls() { SetSizer(VStack([this](auto sizer) { HStack(sizer, BasicSizerFlags(), [this](auto sizer) { - auto button = CreateButton(this, sizer, BasicSizerFlags(), wxID_OK, "&Close"); - button->SetDefault(); CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&All", [this]() { - mShow.SetSelection(mShow.MakeSelectAll()); + mSelection = mShow.MakeSelectAll(); + EndModal(wxID_OK); }); CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&None", [this]() { - mShow.SetSelection(mShow.MakeUnselectAll()); + mSelection = mShow.MakeUnselectAll(); + EndModal(wxID_OK); }); + auto button = CreateButton(this, sizer, BasicSizerFlags(), wxID_OK); + button->SetDefault(); }); HStack(sizer, BasicSizerFlags(), [this](auto sizer) { auto counter = 0; for (auto&& i : GetSymbolsBitmap()) { auto which = static_cast(counter++); - CreateBitmapButtonWithHandler(this, sizer, BasicSizerFlags(), i, [this, which]() { - mShow.SetSelection(mShow.GetCurrentSheet()->MakeSelectPointsBySymbol(which)); - }); + if (mShow.MakeSelectBySymbol(which).size()) { + CreateBitmapButtonWithHandler(this, sizer, BasicSizerFlags(), i, [this, which]() { + mSelection = mShow.MakeSelectBySymbol(which); + EndModal(wxID_OK); + }); + } } }); + HStack(sizer, BasicSizerFlags(), [this](auto sizer) { + CreateText(this, sizer, BasicSizerFlags(), "Select Instrument"); + + auto instruments = mShow.GetPointsInstrument(); + auto currentInstruments = std::set(instruments.begin(), instruments.end()); + auto choice = CreateChoiceWithHandler(this, sizer, BasicSizerFlags(), wxID_ANY, { currentInstruments.begin(), currentInstruments.end() }, [this](wxCommandEvent& e) { + mSelection = mShow.MakeSelectByInstrument(e.GetString()); + EndModal(wxID_OK); + }); + choice->SetSelection(wxNOT_FOUND); + }); + mList = new wxListBox(this, PointPicker_PointPickerList, wxDefaultPosition, - wxSize(50, 500), 0, NULL, wxLB_EXTENDED); + wxSize(50, 250), 0, NULL, wxLB_EXTENDED); sizer->Add(mList, wxSizerFlags(0).Border(wxALL, 5).Center()); })); @@ -105,7 +104,7 @@ void PointPicker::CreateControls() void PointPicker::PointPickerAll(wxCommandEvent&) { - mShow.SetSelection(mShow.MakeSelectAll()); + mSelection = mShow.MakeSelectAll(); } void PointPicker::PointPickerSelect(wxCommandEvent&) @@ -113,15 +112,15 @@ void PointPicker::PointPickerSelect(wxCommandEvent&) wxArrayInt selections; size_t n = mList->GetSelections(selections); - mCachedSelection.clear(); - for (size_t i = 0; i < n; ++i) - mCachedSelection.insert(selections[i]); - mShow.SetSelection(mCachedSelection); + mSelection.clear(); + for (size_t i = 0; i < n; ++i) { + mSelection.insert(selections[i]); + } } void PointPicker::Update() { - auto&& tshowLabels = mShow.GetPointLabels(); + auto&& tshowLabels = mShow.GetPointsLabel(); std::vector showLabels(tshowLabels.begin(), tshowLabels.end()); if (mCachedLabels != showLabels) { mCachedLabels = showLabels; @@ -129,12 +128,11 @@ void PointPicker::Update() mList->Set(wxArrayString{ mCachedLabels.size(), &mCachedLabels[0] }); } auto showSelectionList = mShow.GetSelectionList(); - if (mCachedSelection != showSelectionList) { + if (mSelection != showSelectionList) { mList->DeselectAll(); - mCachedSelection = showSelectionList; - for (auto n = mCachedSelection.begin(); n != mCachedSelection.end(); ++n) { + mSelection = showSelectionList; + for (auto n = mSelection.begin(); n != mSelection.end(); ++n) { mList->SetSelection(*n); } } } - diff --git a/src/PointPicker.h b/src/PointPicker.h index 8caf08f9..5ccd8aab 100644 --- a/src/PointPicker.h +++ b/src/PointPicker.h @@ -28,33 +28,30 @@ #include -class PointPickerView; - class PointPicker : public wxDialog { using super = wxDialog; public: - PointPicker(CalChartDoc& shw, wxWindow* parent, wxWindowID id = wxID_ANY, + PointPicker(CalChartDoc const& shw, wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& caption = wxT("Select Points"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU); ~PointPicker() = default; - void Update(); + SelectionList GetSelection() const { return mSelection; } private: - CalChartDoc& mShow; - PointPickerView* mView; + CalChartDoc const& mShow; wxListBox* mList; std::vector mCachedLabels; - SelectionList mCachedSelection; + SelectionList mSelection; void CreateControls(); + void Update(); void PointPickerAll(wxCommandEvent&); void PointPickerSelect(wxCommandEvent&); DECLARE_EVENT_TABLE() }; - diff --git a/src/PreferencesGeneralSetup.cpp b/src/PreferencesGeneralSetup.cpp index ad2bd9fa..b2a8b6c4 100644 --- a/src/PreferencesGeneralSetup.cpp +++ b/src/PreferencesGeneralSetup.cpp @@ -100,7 +100,7 @@ bool GeneralSetup::TransferDataFromWindow() bool GeneralSetup::ClearValuesToDefault() { mConfig.Clear_AutosaveInterval(); - mConfig.Clear_CalChartFrameAUILayout_3_6_0(); + mConfig.Clear_CalChartFrameAUILayout_3_6_1(); mConfig.Clear_FieldFrameZoom_3_6_0(); mConfig.Clear_FieldFrameWidth(); mConfig.Clear_FieldFrameHeight(); diff --git a/src/PrintContinuityEditor.h b/src/PrintContinuityEditor.h index 6948142f..61e6ca30 100644 --- a/src/PrintContinuityEditor.h +++ b/src/PrintContinuityEditor.h @@ -53,7 +53,7 @@ class PrintContinuityEditor : public wxPanel { void SetView(CalChartView* view) { mView = view; } void OnUpdate() { Update(); } - void Update(); // Refresh all window controls + void Update() override; // Refresh all window controls // Update text window to current continuity // quick doesn't flush other windows void UpdateText(); diff --git a/src/SetupInstruments.cpp b/src/SetupInstruments.cpp new file mode 100644 index 00000000..08e606e0 --- /dev/null +++ b/src/SetupInstruments.cpp @@ -0,0 +1,319 @@ +/* + * SetupInstruments.cpp + */ + +/* + Copyright (C) 1995-2011 Garrick Brian Meeker, Richard Michael Powell + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "SetupInstruments.h" +#include "CalChartToolBar.h" +#include "basic_ui.h" +#include "cc_sheet.h" +#include +#include +#include +#include + +enum { + SetupInstruments_SetupInstrumentsList = 1000, + SetupInstruments_SetInstrumentChoice, + SetupInstruments_SelectInstrument, +}; + +BEGIN_EVENT_TABLE(SetupInstruments, wxDialog) +EVT_LISTBOX(SetupInstruments_SetupInstrumentsList, SetupInstruments::Select) +EVT_LISTBOX_DCLICK(SetupInstruments_SetupInstrumentsList, SetupInstruments::SelectAll) +END_EVENT_TABLE() + +IMPLEMENT_CLASS(SetupInstruments, wxDialog) + +// how does SetupInstruments work? +// First we read the list of instruments currently set on a show +// we then supplement the list of instruments with the default list +// we have. +// +// When no points are selected we set the choice as the unselected. +// When multiple points are selected with multiple instruments, we +// add the selection kMultiple + +SetupInstruments::SetupInstruments(CalChartDoc const& shw, wxWindow* parent, wxWindowID id, + const wxString& caption, const wxPoint& pos, + const wxSize& size, long style) + : mShow(shw) +{ + auto selection = mShow.GetSelectionList(); + auto dotSymbols = mShow.GetCurrentSheet()->GetSymbols(); + mDotIndices.assign(selection.begin(), selection.end()); + // if nothing is selected, then everything is selected. + if (selection.size() == 0) { + mDotIndices.resize(shw.GetNumPoints()); + std::iota(mDotIndices.begin(), mDotIndices.end(), 0); + } + + std::transform(mDotIndices.begin(), mDotIndices.end(), std::back_inserter(mLabels), [&shw](auto&& i) { + return shw.GetPointLabel(i); + }); + + std::transform(mDotIndices.begin(), mDotIndices.end(), std::back_inserter(mInstruments), [&shw](auto&& i) { + return shw.GetPointInstrument(i); + }); + std::transform(mDotIndices.begin(), mDotIndices.end(), std::back_inserter(mSymbols), [&shw, dotSymbols](auto&& i) { + return dotSymbols.at(i); + }); + + // we construct a new list of instrument choices. + std::set currentInstruments(mInstruments.begin(), mInstruments.end()); + mInstrumentChoices.assign(currentInstruments.begin(), currentInstruments.end()); + for (auto& i : kInstruments) { + if (currentInstruments.count(i) == 0) { + mInstrumentChoices.push_back(i); + } + } + + Create(parent, id, caption, pos, size, style); + + SelectAllPoints(); +} + +bool SetupInstruments::Create(wxWindow* parent, wxWindowID id, + const wxString& caption, const wxPoint& pos, + const wxSize& size, long style) +{ + if (!wxDialog::Create(parent, id, caption, pos, size, style)) + return false; + + CreateControls(); + + // This fits the dalog to the minimum size dictated by the sizers + GetSizer()->Fit(this); + // This ensures that the dialog cannot be smaller than the minimum size + GetSizer()->SetSizeHints(this); + + // now populate + wxListBox* list = static_cast(FindWindow(SetupInstruments_SetupInstrumentsList)); + std::vector tlabel; + std::transform(mLabels.begin(), mLabels.end(), std::back_inserter(tlabel), [](auto&& i) { return i; }); + list->Set(tlabel); + + Center(); + + return true; +} + +void SetupInstruments::CreateControls() +{ + SetSizer(VStack([this](auto sizer) { + HStack(sizer, BasicSizerFlags(), [this](auto sizer) { + CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&All", [this]() { + SelectAllPoints(); + }); + CreateButtonWithHandler(this, sizer, BasicSizerFlags(), "&None", [this]() { + SelectNone(); + }); + }); + + HStack(sizer, BasicSizerFlags(), [this](auto sizer) { + auto counter = 0; + for (auto&& i : GetSymbolsBitmap()) { + auto which = static_cast(counter++); + if (std::count(mSymbols.begin(), mSymbols.end(), which)) { + CreateBitmapButtonWithHandler(this, sizer, BasicSizerFlags(), i, [this, which]() { + SelectSymbol(which); + }); + } + } + }); + + HStack(sizer, BasicSizerFlags(), [this](auto sizer) { + CreateText(this, sizer, BasicSizerFlags(), "Select Instrument"); + auto currentInstruments = std::set(mInstruments.begin(), mInstruments.end()); + auto choices = std::vector(currentInstruments.begin(), currentInstruments.end()); + auto choice = CreateChoiceWithHandler(this, sizer, BasicSizerFlags(), SetupInstruments_SelectInstrument, choices, [this](wxCommandEvent& e) { + SelectInstrument(); + }); + choice->SetSelection(wxNOT_FOUND); + }); + + CreateHLine(this, sizer); + + HStack(sizer, BasicSizerFlags(), [this](auto sizer) { + auto list = new wxListBox(this, SetupInstruments_SetupInstrumentsList, wxDefaultPosition, wxSize(50, 200), 0, NULL, wxLB_EXTENDED); + sizer->Add(list, wxSizerFlags(0).Border(wxALL, 5).Center()); + VStack(sizer, BasicSizerFlags(), [this](auto sizer) { + CreateText(this, sizer, BasicSizerFlags(), "Set Instrument"); + std::vector choices; + choices.insert(choices.end(), mInstrumentChoices.begin(), mInstrumentChoices.end()); + choices.push_back(kCustom); + auto choice = CreateChoiceWithHandler(this, sizer, BasicSizerFlags(), SetupInstruments_SetInstrumentChoice, choices, [this](wxCommandEvent& e) { + OnCmdChoice(); + }); + }); + }); + + HStack(sizer, BasicSizerFlags(), [this](auto sizer) { + CreateButton(this, sizer, BasicSizerFlags(), wxID_CANCEL); + CreateButton(this, sizer, BasicSizerFlags(), wxID_OK); + }); + })); +} + +std::map SetupInstruments::GetInstruments() const +{ + auto result = std::vector>{}; + std::transform(mDotIndices.begin(), mDotIndices.end(), mInstruments.begin(), std::back_inserter(result), [](auto&& a, auto&& b) -> std::pair { return { a, b }; }); + return { result.begin(), result.end() }; +} + +// the list of selected dots has changed, update the controls +// Specifically, set the instrument selector to not found, +// If nothing is selected, set the set instrument choice to not found +// if 1 instrument selected, set the instrument choice to that +// if more than 1 instrument is selected, add a " +void SetupInstruments::SelectionListChanged() +{ + static_cast(FindWindow(SetupInstruments_SelectInstrument))->SetSelection(wxNOT_FOUND); + + auto list = static_cast(FindWindow(SetupInstruments_SetupInstrumentsList)); + auto choice = static_cast(FindWindow(SetupInstruments_SetInstrumentChoice)); + + wxArrayInt selections; + auto n = list->GetSelections(selections); + // if nothing is selected, remove the choice + if (n == 0) { + choice->SetSelection(wxNOT_FOUND); + return; + } + + std::vector totalList; + std::transform(selections.begin(), selections.end(), std::back_inserter(totalList), [this](auto& i) { return mInstruments[i]; }); + std::sort(totalList.begin(), totalList.end()); + totalList.erase(std::unique(totalList.begin(), totalList.end()), totalList.end()); + if (totalList.size() == 1) { + std::vector choices; + choices.insert(choices.end(), mInstrumentChoices.begin(), mInstrumentChoices.end()); + choices.push_back(kCustom); + choice->Set(choices); + choice->SetSelection(choice->FindString(totalList[0])); + } else { + std::vector choices; + choices.push_back(kMultiple); + choices.insert(choices.end(), mInstrumentChoices.begin(), mInstrumentChoices.end()); + choices.push_back(kCustom); + choice->Set(choices); + choice->SetSelection(0); + } +} + +void SetupInstruments::SelectAll(wxCommandEvent&) +{ + SelectAllPoints(); +} + +void SetupInstruments::SelectAllPoints() +{ + auto list = static_cast(FindWindow(SetupInstruments_SetupInstrumentsList)); + for (auto i = 0; i < list->GetCount(); ++i) { + list->SetSelection(i); + } + SelectionListChanged(); +} + +void SetupInstruments::Select(wxCommandEvent&) +{ + SelectionListChanged(); +} + +void SetupInstruments::SelectNone() +{ + static_cast(FindWindow(SetupInstruments_SetupInstrumentsList))->DeselectAll(); + SelectionListChanged(); +} + +void SetupInstruments::SelectSymbol(SYMBOL_TYPE sym) +{ + auto list = static_cast(FindWindow(SetupInstruments_SetupInstrumentsList)); + list->DeselectAll(); + for (auto i = 0ul; i < mSymbols.size(); ++i) { + if (mSymbols[i] == sym) { + list->SetSelection(i); + } + } + SelectionListChanged(); +} + +void SetupInstruments::SelectInstrument() +{ + // from the current select, mark all the instruments that match + auto choice = static_cast(FindWindow(SetupInstruments_SelectInstrument)); + auto result = choice->GetString(choice->GetSelection()); + + auto list = static_cast(FindWindow(SetupInstruments_SetupInstrumentsList)); + list->DeselectAll(); + wxArrayInt selections; + for (auto i = 0ul; i < mInstruments.size(); ++i) { + if (result == mInstruments[i]) { + list->SetSelection(i); + } + } + SelectionListChanged(); +} + +// now we set the instruments to be different +void SetupInstruments::OnCmdChoice() +{ + auto list = static_cast(FindWindow(SetupInstruments_SetupInstrumentsList)); + auto choice = static_cast(FindWindow(SetupInstruments_SetInstrumentChoice)); + wxArrayInt selections; + auto n = list->GetSelections(selections); + if (n == 0) { + choice->SetSelection(wxNOT_FOUND); + return; + } + auto result = choice->GetString(choice->GetSelection()); + if (result == kMultiple) { + return; + } + + if (result == kCustom) { + auto newInstrument = wxGetTextFromUser("Enter Custom Instrument", "Setup Instrument", "", this); + if (newInstrument != "") { + // we have a new instrument. + result = newInstrument; + mInstrumentChoices.push_back(result); + } + } + + for (auto& i : selections) { + mInstruments[i] = result; + } + // update the list of choices for the instrument selector and set to + { + auto choice = static_cast(FindWindow(SetupInstruments_SelectInstrument)); + auto currentInstruments = std::set(mInstruments.begin(), mInstruments.end()); + auto choices = std::vector(currentInstruments.begin(), currentInstruments.end()); + choice->Set(choices); + choice->SetSelection(wxNOT_FOUND); + } + // now remove the multiple from the list. + { + std::vector choices; + choices.insert(choices.end(), mInstrumentChoices.begin(), mInstrumentChoices.end()); + choices.push_back(kCustom); + choice->Set(choices); + choice->SetSelection(choice->FindString(result)); + } +} diff --git a/src/SetupInstruments.h b/src/SetupInstruments.h new file mode 100644 index 00000000..7eeab888 --- /dev/null +++ b/src/SetupInstruments.h @@ -0,0 +1,71 @@ +/* + * SetupInstruments.h + */ + +/* + Copyright (C) 1995-2011 Garrick Brian Meeker, Richard Michael Powell + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include "CalChartDoc.h" +#include +#include + +#include + +class SetupInstruments : public wxDialog { + DECLARE_CLASS(SetupInstruments) + DECLARE_EVENT_TABLE() + +public: + SetupInstruments(CalChartDoc const& shw, wxWindow* parent, wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Set Instruments"), + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU); + ~SetupInstruments() = default; + + // returns label, symbol, instrument + std::map GetInstruments() const; + +private: + bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Set Instruments"), + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU); + + void CreateControls(); + +private: + CalChartDoc const& mShow; + std::vector mDotIndices; + std::vector mLabels; + std::vector mInstruments; + std::vector mInstrumentChoices; + std::vector mSymbols; + + void SelectAll(wxCommandEvent&); + void SelectAllPoints(); + void Select(wxCommandEvent&); + void SelectNone(); + void SelectSymbol(SYMBOL_TYPE); + void SelectInstrument(); + void OnCmdChoice(); + + void SelectionListChanged(); +}; diff --git a/src/show_ui.cpp b/src/SetupMarchers.cpp similarity index 59% rename from src/show_ui.cpp rename to src/SetupMarchers.cpp index b44e103f..e04ebaf1 100644 --- a/src/show_ui.cpp +++ b/src/SetupMarchers.cpp @@ -1,6 +1,5 @@ /* - * show_ui.cpp - * Classes for interacting with shows + * SetupMarchers.cpp */ /* @@ -20,7 +19,7 @@ along with this program. If not, see . */ -#include "show_ui.h" +#include "SetupMarchers.h" #include "CalChartToolBar.h" #include "basic_ui.h" #include "cc_sheet.h" @@ -31,54 +30,26 @@ static const size_t kMaxPoints = 1000; -static void CalculateLabels(const CalChartDoc& show, - std::set& letters, bool& use_letters, - long& maxnum) -{ - use_letters = false; - maxnum = 1; - for (auto i = 0; i < show.GetNumPoints(); ++i) { - wxString tmp = show.GetPointLabel(i); - unsigned letterIndex = 0; - if (!isdigit(tmp[0])) { - use_letters = true; - letterIndex += tmp[0] - 'A'; - tmp.Remove(0, 1); - if (!isdigit(tmp[0])) { - tmp.Remove(0, 1); - letterIndex += 26; - } - } - long num = 0; - if (tmp.ToLong(&num)) { - maxnum = std::max(maxnum, num + 1); - } - if (use_letters) { - letters.insert(letterIndex); - } - } - if (use_letters == false) { - maxnum = 10; - } -} +// returns [letters, use_letters, maxnum] +static std::tuple, bool, long> CalculateLabels(std::vector labels); enum { - ShowInfoReq_ID_POINTS_SPIN = 1000, - ShowInfoReq_ID_COLUMNS_SPIN, - ShowInfoReq_ID_LABEL_TYPE, - ShowInfoReq_ID_POINTS_PER_LETTER, - ShowInfoReq_ID_LABEL_LETTERS, - ShowInfoReq_ID_RESET, + SetupMarchers_ID_POINTS_SPIN = 1000, + SetupMarchers_ID_COLUMNS_SPIN, + SetupMarchers_ID_LABEL_TYPE, + SetupMarchers_ID_POINTS_PER_LETTER, + SetupMarchers_ID_LABEL_LETTERS, + SetupMarchers_ID_RESET, }; -BEGIN_EVENT_TABLE(ShowInfoReq, wxDialog) -EVT_BUTTON(wxID_RESET, ShowInfoReq::OnReset) -EVT_CHOICE(ShowInfoReq_ID_LABEL_TYPE, ShowInfoReq::OnCmd_label_type) +BEGIN_EVENT_TABLE(SetupMarchers, wxDialog) +EVT_BUTTON(wxID_RESET, SetupMarchers::OnReset) +EVT_CHOICE(SetupMarchers_ID_LABEL_TYPE, SetupMarchers::OnCmd_label_type) END_EVENT_TABLE() -IMPLEMENT_CLASS(ShowInfoReq, wxDialog) +IMPLEMENT_CLASS(SetupMarchers, wxDialog) -ShowInfoReq::ShowInfoReq(CalChartDoc& shw, wxWindow* parent, wxWindowID id, +SetupMarchers::SetupMarchers(CalChartDoc& shw, wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style) : mNumberColumns(8) @@ -87,9 +58,9 @@ ShowInfoReq::ShowInfoReq(CalChartDoc& shw, wxWindow* parent, wxWindowID id, Create(parent, id, caption, pos, size, style); } -ShowInfoReq::~ShowInfoReq() { } +SetupMarchers::~SetupMarchers() { } -bool ShowInfoReq::Create(wxWindow* parent, wxWindowID id, +bool SetupMarchers::Create(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style) { @@ -108,17 +79,17 @@ bool ShowInfoReq::Create(wxWindow* parent, wxWindowID id, return true; } -void EnableLetter(wxWindow& window, bool letters) +static void EnableLetter(wxWindow& window, bool letters) { // on first time, we need to set up values - window.FindWindow(ShowInfoReq_ID_POINTS_PER_LETTER)->Enable(letters); - window.FindWindow(ShowInfoReq_ID_LABEL_LETTERS)->Enable(letters); + window.FindWindow(SetupMarchers_ID_POINTS_PER_LETTER)->Enable(letters); + window.FindWindow(SetupMarchers_ID_LABEL_LETTERS)->Enable(letters); } // Layout is to give a consistent show layout to both wizard and dialog // layout requires a parent // wxSlider *lettersize; -void LayoutShowInfo(wxWindow* parent, bool putLastRowButtons) +static void LayoutShowInfo(wxWindow* parent, bool putLastRowButtons) { parent->SetSizer(VStack([parent, putLastRowButtons](auto sizer) { // now we add a left and a right side, putting boxes around things @@ -133,7 +104,7 @@ void LayoutShowInfo(wxWindow* parent, bool putLastRowButtons) HStack(sizer, BasicSizerFlags(), [parent](auto sizer) { CreateText(parent, sizer, "&Points:"); wxSpinCtrl* numPoints = new wxSpinCtrl( - parent, ShowInfoReq_ID_POINTS_SPIN, wxEmptyString, wxDefaultPosition, + parent, SetupMarchers_ID_POINTS_SPIN, wxEmptyString, wxDefaultPosition, wxSize(60, -1), wxSP_ARROW_KEYS, 1, kMaxPoints, 10); sizer->Add(numPoints, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); }); @@ -141,12 +112,12 @@ void LayoutShowInfo(wxWindow* parent, bool putLastRowButtons) HStack(sizer, BasicSizerFlags(), [parent](auto sizer) { CreateText(parent, sizer, "&Columns:"); wxSpinCtrl* numberColumns = new wxSpinCtrl( - parent, ShowInfoReq_ID_COLUMNS_SPIN, wxEmptyString, wxDefaultPosition, + parent, SetupMarchers_ID_COLUMNS_SPIN, wxEmptyString, wxDefaultPosition, wxSize(60, -1), wxSP_ARROW_KEYS, 0, kMaxPoints, 10); sizer->Add(numberColumns, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); }); - auto label_type = CreateChoiceWithHandler(parent, sizer, BasicSizerFlags(), ShowInfoReq_ID_LABEL_TYPE, { wxT("Numbers"), wxT("Letters") }, [parent](auto& event) { + auto label_type = CreateChoiceWithHandler(parent, sizer, BasicSizerFlags(), SetupMarchers_ID_LABEL_TYPE, { wxT("Numbers"), wxT("Letters") }, [parent](auto& event) { EnableLetter(*parent, event.GetInt() == 1); parent->Refresh(); }); @@ -154,7 +125,7 @@ void LayoutShowInfo(wxWindow* parent, bool putLastRowButtons) HStack(sizer, BasicSizerFlags(), [parent](auto sizer) { CreateText(parent, sizer, "P&oints per letter"); wxSpinCtrl* lettersize = new wxSpinCtrl( - parent, ShowInfoReq_ID_POINTS_PER_LETTER, wxEmptyString, + parent, SetupMarchers_ID_POINTS_PER_LETTER, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 99, 10); sizer->Add(lettersize, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); }); @@ -163,7 +134,7 @@ void LayoutShowInfo(wxWindow* parent, bool putLastRowButtons) VStack(sizer, [parent](auto sizer) { // now add right side NamedHBoxStack(parent, sizer, "&Letters", [parent](auto sizer) { - wxListBox* labels = new wxListBox(parent, ShowInfoReq_ID_LABEL_LETTERS, wxDefaultPosition, + wxListBox* labels = new wxListBox(parent, SetupMarchers_ID_LABEL_LETTERS, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_EXTENDED); for (int i = 0; i < 26; ++i) { wxString buf(static_cast('A' + i)); @@ -194,19 +165,16 @@ void LayoutShowInfo(wxWindow* parent, bool putLastRowButtons) })); } -std::vector GenNumberLabels(int num) +static auto GenNumberLabels(int num) { - std::vector results; + std::vector> results; for (auto i = 0; i < num; ++i) { - // Begin with 1, not 0 - wxString buffer; - buffer.Printf(wxT("%u"), i); - results.push_back(buffer); + results.push_back({ std::to_string(i), kDefaultInstrument }); } return results; } -auto NumberLabelsSet(wxListBox const* label_letters) +static auto NumberLabelsSet(wxListBox const* label_letters) { auto numlabels = 0; for (auto i = 0u; i < label_letters->GetCount(); i++) { @@ -217,9 +185,9 @@ auto NumberLabelsSet(wxListBox const* label_letters) return numlabels; } -std::vector GenLetterLabels(int numPerLetter, int num, wxListBox const* label_letters) +static auto GenLetterLabels(int numPerLetter, int num, wxListBox const* label_letters) { - std::vector results; + std::vector> results; // Letters if (NumberLabelsSet(label_letters)) { auto letr = 0; @@ -229,7 +197,7 @@ std::vector GenLetterLabels(int numPerLetter, int num, wxListBox const for (int i = 0; i < n; ++i) { wxString buffer; buffer.Printf(wxT("%s%u"), label_letters->GetString(letr), i); - results.push_back(buffer); + results.push_back({ buffer, kDefaultInstrument }); } num -= n; } @@ -246,7 +214,7 @@ std::vector GenLetterLabels(int numPerLetter, int num, wxListBox const } else { buffer.Printf(wxT("%c%u"), 'A' + letr, i); } - results.push_back(buffer); + results.push_back({ buffer, "" }); } num -= n; ++letr; @@ -256,15 +224,15 @@ std::vector GenLetterLabels(int numPerLetter, int num, wxListBox const } // Validate is to give verify show layout to both wizard and dialog -bool ValidateInfo(wxWindow* parent) +static bool ValidateInfo(wxWindow* parent) { - wxChoice* labelType = (wxChoice*)parent->FindWindow(ShowInfoReq_ID_LABEL_TYPE); + wxChoice* labelType = (wxChoice*)parent->FindWindow(SetupMarchers_ID_LABEL_TYPE); if (labelType->GetSelection() == 0) { return true; } - wxSpinCtrl* pointsCtrl = (wxSpinCtrl*)parent->FindWindow(ShowInfoReq_ID_POINTS_SPIN); - wxSpinCtrl* pointsPerLine = (wxSpinCtrl*)parent->FindWindow(ShowInfoReq_ID_POINTS_PER_LETTER); - wxListBox* label_letters = (wxListBox*)parent->FindWindow(ShowInfoReq_ID_LABEL_LETTERS); + wxSpinCtrl* pointsCtrl = (wxSpinCtrl*)parent->FindWindow(SetupMarchers_ID_POINTS_SPIN); + wxSpinCtrl* pointsPerLine = (wxSpinCtrl*)parent->FindWindow(SetupMarchers_ID_POINTS_PER_LETTER); + wxListBox* label_letters = (wxListBox*)parent->FindWindow(SetupMarchers_ID_LABEL_LETTERS); int num = pointsPerLine->GetValue(); int numlabels = NumberLabelsSet(label_letters); @@ -275,20 +243,20 @@ bool ValidateInfo(wxWindow* parent) return canDo; } -void ShowInfoReq::CreateControls() { LayoutShowInfo(this, true); } +void SetupMarchers::CreateControls() +{ + LayoutShowInfo(this, true); +} -bool ShowInfoReq::TransferDataToWindow() +bool SetupMarchers::TransferDataToWindow() { - std::set letters; - bool use_letters; - long maxnum; - CalculateLabels(mShow, letters, use_letters, maxnum); + auto [letters, use_letters, maxnum] = CalculateLabels(mShow.GetPointsLabel()); - wxSpinCtrl* pointsCtrl = (wxSpinCtrl*)FindWindow(ShowInfoReq_ID_POINTS_SPIN); - wxSpinCtrl* columnsCtrl = (wxSpinCtrl*)FindWindow(ShowInfoReq_ID_COLUMNS_SPIN); - wxChoice* labelType = (wxChoice*)FindWindow(ShowInfoReq_ID_LABEL_TYPE); - wxSpinCtrl* pointsPerLine = (wxSpinCtrl*)FindWindow(ShowInfoReq_ID_POINTS_PER_LETTER); - wxListBox* label_letters = (wxListBox*)FindWindow(ShowInfoReq_ID_LABEL_LETTERS); + wxSpinCtrl* pointsCtrl = (wxSpinCtrl*)FindWindow(SetupMarchers_ID_POINTS_SPIN); + wxSpinCtrl* columnsCtrl = (wxSpinCtrl*)FindWindow(SetupMarchers_ID_COLUMNS_SPIN); + wxChoice* labelType = (wxChoice*)FindWindow(SetupMarchers_ID_LABEL_TYPE); + wxSpinCtrl* pointsPerLine = (wxSpinCtrl*)FindWindow(SetupMarchers_ID_POINTS_PER_LETTER); + wxListBox* label_letters = (wxListBox*)FindWindow(SetupMarchers_ID_LABEL_LETTERS); pointsCtrl->SetValue(mShow.GetNumPoints()); columnsCtrl->SetValue(mNumberColumns); @@ -304,43 +272,71 @@ bool ShowInfoReq::TransferDataToWindow() return true; } -bool ShowInfoReq::TransferDataFromWindow() +bool SetupMarchers::TransferDataFromWindow() { - auto pointsCtrl = (wxSpinCtrl const*)FindWindow(ShowInfoReq_ID_POINTS_SPIN); - auto columnsCtrl = (wxSpinCtrl const*)FindWindow(ShowInfoReq_ID_COLUMNS_SPIN); - auto labelType = (wxChoice const*)FindWindow(ShowInfoReq_ID_LABEL_TYPE); - auto pointsPerLine = (wxSpinCtrl const*)FindWindow(ShowInfoReq_ID_POINTS_PER_LETTER); - auto label_letters = (wxListBox const*)FindWindow(ShowInfoReq_ID_LABEL_LETTERS); + auto pointsCtrl = (wxSpinCtrl const*)FindWindow(SetupMarchers_ID_POINTS_SPIN); + auto columnsCtrl = (wxSpinCtrl const*)FindWindow(SetupMarchers_ID_COLUMNS_SPIN); + auto labelType = (wxChoice const*)FindWindow(SetupMarchers_ID_LABEL_TYPE); + auto pointsPerLine = (wxSpinCtrl const*)FindWindow(SetupMarchers_ID_POINTS_PER_LETTER); + auto label_letters = (wxListBox const*)FindWindow(SetupMarchers_ID_LABEL_LETTERS); auto numberPoints = pointsCtrl->GetValue(); mNumberColumns = columnsCtrl->GetValue(); if (labelType->GetSelection() == 0) { - mLabels = GenNumberLabels(numberPoints); + mLabelsAndInstruments = GenNumberLabels(numberPoints); } else { // Letters - mLabels = GenLetterLabels(pointsPerLine->GetValue(), numberPoints, label_letters); + mLabelsAndInstruments = GenLetterLabels(pointsPerLine->GetValue(), numberPoints, label_letters); } return true; } -bool ShowInfoReq::Validate() { return ValidateInfo(this); } +bool SetupMarchers::Validate() { return ValidateInfo(this); } -void ShowInfoReq::OnReset(wxCommandEvent&) { TransferDataToWindow(); } +void SetupMarchers::OnReset(wxCommandEvent&) { TransferDataToWindow(); } -void ShowInfoReq::OnCmd_label_type(wxCommandEvent& event) +void SetupMarchers::OnCmd_label_type(wxCommandEvent& event) { EnableLetter(*this, event.GetInt() == 1); Refresh(); } -IMPLEMENT_CLASS(ShowInfoReqWizard, wxWizardPageSimple) +// common utilities +static std::tuple, bool, long> CalculateLabels(std::vector labels) +{ + auto letters = std::set{}; + auto use_letters = false; + auto maxnum = 1; + for (auto tmp : labels) { + auto letterIndex = 0; + if (!isdigit(tmp[0])) { + use_letters = true; + letterIndex += tmp[0] - 'A'; + tmp.erase(0, 1); + if (!isdigit(tmp[0])) { + tmp.erase(0, 1); + letterIndex += 26; + } + } + maxnum = std::max(maxnum, std::stol(tmp) + 1); + if (use_letters) { + letters.insert(letterIndex); + } + } + if (use_letters == false) { + maxnum = 10; + } + return { letters, use_letters, maxnum }; +} + +IMPLEMENT_CLASS(SetupMarchersWizard, wxWizardPageSimple) -BEGIN_EVENT_TABLE(ShowInfoReqWizard, wxWizardPageSimple) -EVT_CHOICE(ShowInfoReq_ID_LABEL_TYPE, ShowInfoReqWizard::OnCmd_label_type) +BEGIN_EVENT_TABLE(SetupMarchersWizard, wxWizardPageSimple) +EVT_CHOICE(SetupMarchers_ID_LABEL_TYPE, SetupMarchersWizard::OnCmd_label_type) END_EVENT_TABLE() -ShowInfoReqWizard::ShowInfoReqWizard(wxWizard* parent) +SetupMarchersWizard::SetupMarchersWizard(wxWizard* parent) : wxWizardPageSimple(parent) , mTransferDataToWindowFirstTime(true) , mNumberColumns(8) @@ -349,15 +345,15 @@ ShowInfoReqWizard::ShowInfoReqWizard(wxWizard* parent) GetSizer()->Fit(this); } -bool ShowInfoReqWizard::TransferDataToWindow() +bool SetupMarchersWizard::TransferDataToWindow() { // on first time, we need to set up values if (mTransferDataToWindowFirstTime) { - wxSpinCtrl* pointsCtrl = (wxSpinCtrl*)FindWindow(ShowInfoReq_ID_POINTS_SPIN); - wxSpinCtrl* columnsCtrl = (wxSpinCtrl*)FindWindow(ShowInfoReq_ID_COLUMNS_SPIN); - wxChoice* labelType = (wxChoice*)FindWindow(ShowInfoReq_ID_LABEL_TYPE); - wxSpinCtrl* pointsPerLine = (wxSpinCtrl*)FindWindow(ShowInfoReq_ID_POINTS_PER_LETTER); - wxListBox* label_letters = (wxListBox*)FindWindow(ShowInfoReq_ID_LABEL_LETTERS); + wxSpinCtrl* pointsCtrl = (wxSpinCtrl*)FindWindow(SetupMarchers_ID_POINTS_SPIN); + wxSpinCtrl* columnsCtrl = (wxSpinCtrl*)FindWindow(SetupMarchers_ID_COLUMNS_SPIN); + wxChoice* labelType = (wxChoice*)FindWindow(SetupMarchers_ID_LABEL_TYPE); + wxSpinCtrl* pointsPerLine = (wxSpinCtrl*)FindWindow(SetupMarchers_ID_POINTS_PER_LETTER); + wxListBox* label_letters = (wxListBox*)FindWindow(SetupMarchers_ID_LABEL_LETTERS); pointsCtrl->SetValue(1); columnsCtrl->SetValue(mNumberColumns); @@ -370,29 +366,29 @@ bool ShowInfoReqWizard::TransferDataToWindow() return true; } -bool ShowInfoReqWizard::TransferDataFromWindow() +bool SetupMarchersWizard::TransferDataFromWindow() { - auto pointsCtrl = (wxSpinCtrl const*)FindWindow(ShowInfoReq_ID_POINTS_SPIN); - auto columnsCtrl = (wxSpinCtrl const*)FindWindow(ShowInfoReq_ID_COLUMNS_SPIN); - auto labelType = (wxChoice const*)FindWindow(ShowInfoReq_ID_LABEL_TYPE); - auto pointsPerLine = (wxSpinCtrl const*)FindWindow(ShowInfoReq_ID_POINTS_PER_LETTER); - auto label_letters = (wxListBox const*)FindWindow(ShowInfoReq_ID_LABEL_LETTERS); + auto pointsCtrl = (wxSpinCtrl const*)FindWindow(SetupMarchers_ID_POINTS_SPIN); + auto columnsCtrl = (wxSpinCtrl const*)FindWindow(SetupMarchers_ID_COLUMNS_SPIN); + auto labelType = (wxChoice const*)FindWindow(SetupMarchers_ID_LABEL_TYPE); + auto pointsPerLine = (wxSpinCtrl const*)FindWindow(SetupMarchers_ID_POINTS_PER_LETTER); + auto label_letters = (wxListBox const*)FindWindow(SetupMarchers_ID_LABEL_LETTERS); auto numberPoints = pointsCtrl->GetValue(); mNumberColumns = columnsCtrl->GetValue(); if (labelType->GetSelection() == 0) { - mLabels = GenNumberLabels(numberPoints); + mLabelsAndInstruments = GenNumberLabels(numberPoints); } else { // Letters - mLabels = GenLetterLabels(pointsPerLine->GetValue(), numberPoints, label_letters); + mLabelsAndInstruments = GenLetterLabels(pointsPerLine->GetValue(), numberPoints, label_letters); } return true; } -bool ShowInfoReqWizard::Validate() { return ValidateInfo(this); } +bool SetupMarchersWizard::Validate() { return ValidateInfo(this); } -void ShowInfoReqWizard::OnCmd_label_type(wxCommandEvent& event) +void SetupMarchersWizard::OnCmd_label_type(wxCommandEvent& event) { EnableLetter(*this, event.GetInt() == 1); Refresh(); diff --git a/src/show_ui.h b/src/SetupMarchers.h similarity index 73% rename from src/show_ui.h rename to src/SetupMarchers.h index 223bb48f..b63d8a03 100644 --- a/src/show_ui.h +++ b/src/SetupMarchers.h @@ -1,6 +1,5 @@ /* - * show_ui.h - * Classes for interacting with shows + * SetupMarchers.h */ /* @@ -28,21 +27,21 @@ #include -class ShowInfoReq : public wxDialog { - DECLARE_CLASS(ShowInfoReq) +class SetupMarchers : public wxDialog { + DECLARE_CLASS(SetupMarchers) DECLARE_EVENT_TABLE() public: - ShowInfoReq(CalChartDoc& shw, wxWindow* parent, wxWindowID id = wxID_ANY, - const wxString& caption = wxT("Show Info"), + SetupMarchers(CalChartDoc& shw, wxWindow* parent, wxWindowID id = wxID_ANY, + const wxString& caption = wxT("Setup Marchers"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU); - ~ShowInfoReq(); + ~SetupMarchers(); private: bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, - const wxString& caption = wxT("Show Info"), + const wxString& caption = wxT("Setup Marchers"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxCAPTION | wxRESIZE_BORDER | wxSYSTEM_MENU); @@ -56,23 +55,23 @@ class ShowInfoReq : public wxDialog { // The data this dialog sets for the user private: unsigned mNumberColumns; - std::vector mLabels; + std::vector> mLabelsAndInstruments; void OnCmd_label_type(wxCommandEvent& event); public: auto GetNumberColumns() const { return mNumberColumns; } - auto GetLabels() const { return mLabels; } + auto GetLabelsAndInstruments() const { return mLabelsAndInstruments; } private: CalChartDoc& mShow; void OnReset(wxCommandEvent&); }; -class ShowInfoReqWizard : public wxWizardPageSimple { - DECLARE_CLASS(ShowInfoReqWizard) +class SetupMarchersWizard : public wxWizardPageSimple { + DECLARE_CLASS(SetupMarchersWizard) DECLARE_EVENT_TABLE() public: - ShowInfoReqWizard(wxWizard* parent); + SetupMarchersWizard(wxWizard* parent); virtual bool TransferDataToWindow(); virtual bool TransferDataFromWindow(); @@ -82,10 +81,10 @@ class ShowInfoReqWizard : public wxWizardPageSimple { private: bool mTransferDataToWindowFirstTime; unsigned mNumberColumns; - std::vector mLabels; + std::vector> mLabelsAndInstruments; void OnCmd_label_type(wxCommandEvent& event); public: auto GetNumberColumns() const { return mNumberColumns; } - auto GetLabels() const { return mLabels; } + auto GetLabelsAndInstruments() const { return mLabelsAndInstruments; } }; diff --git a/src/basic_ui.h b/src/basic_ui.h index 029b7b47..a9963ca0 100644 --- a/src/basic_ui.h +++ b/src/basic_ui.h @@ -32,6 +32,30 @@ class CalChartView; +static constexpr auto kMultiple = "[multiple]"; +static constexpr auto kDefaultInstrument = "default"; +static constexpr auto kCustom = "custom..."; + +static constexpr auto kInstruments = { + kDefaultInstrument, // this is the same as a blank + "Picc", + "Clarinet", + "Alto Sax", + "Tenor Sax", + "Trumpet", + "Mello", + "Trombone", + "Baritone", + "Basses", + "Snare", + "Bass Drum", + "Quad Drum", + "Cymbals", + "Glock", + "Perc", + "Drum Major", +}; + // Set icon to band's insignia void SetBandIcon(wxFrame* frame); @@ -197,6 +221,12 @@ void CreateAndSetItemBitmap(T* target, Int which, Brush const& brush) wxFont CreateFont(int pixelSize, wxFontFamily family = wxFONTFAMILY_SWISS, wxFontStyle style = wxFONTSTYLE_NORMAL, wxFontWeight weight = wxFONTWEIGHT_NORMAL); wxFont ResizeFont(wxFont const& font, int pixelSize); +template +inline auto StringSizeX(wxControl* controller, String const& string) +{ + return controller->GetTextExtent(string).x; +} + template inline auto BestSizeX(wxControl* controller, Strings const& strings) { diff --git a/src/confgr.cpp b/src/confgr.cpp index 6578f277..9d50ccd5 100644 --- a/src/confgr.cpp +++ b/src/confgr.cpp @@ -460,7 +460,8 @@ IMPLEMENT_CONFIGURATION_FUNCTIONS(CommandUndoSelection, bool, false); IMPLEMENT_CONFIGURATION_FUNCTIONS(BeepOnCollisions, bool, true); -IMPLEMENT_CONFIGURATION_FUNCTIONS(CalChartFrameAUILayout_3_6_0, wxString, wxT("")); +// if the layout changes, this is what you increment in order to force a refresh of the layout +IMPLEMENT_CONFIGURATION_FUNCTIONS(CalChartFrameAUILayout_3_6_1, wxString, wxT("")); IMPLEMENT_CONFIGURATION_FUNCTIONS(ContCellLongForm, bool, false); IMPLEMENT_CONFIGURATION_FUNCTIONS(ContCellFontSize, long, 14); diff --git a/src/confgr.h b/src/confgr.h index eaccd38f..13c342f2 100644 --- a/src/confgr.h +++ b/src/confgr.h @@ -214,7 +214,7 @@ private: \ DECLARE_CONFIGURATION_FUNCTIONS(BeepOnCollisions, bool); - DECLARE_CONFIGURATION_FUNCTIONS(CalChartFrameAUILayout_3_6_0, wxString); + DECLARE_CONFIGURATION_FUNCTIONS(CalChartFrameAUILayout_3_6_1, wxString); DECLARE_CONFIGURATION_FUNCTIONS(ContCellLongForm, bool); DECLARE_CONFIGURATION_FUNCTIONS(ContCellFontSize, long); diff --git a/src/core/animate.cpp b/src/core/animate.cpp index 88117da5..553f9202 100644 --- a/src/core/animate.cpp +++ b/src/core/animate.cpp @@ -152,7 +152,7 @@ Animation::Animation(const Show& show) } #endif for (unsigned j = 0; j < mPoints.size(); j++) { - if (curr_sheet->GetPoint(j).GetSymbol() == current_symbol) { + if (curr_sheet->GetSymbol(j) == current_symbol) { theCommands[j] = AnimateCompile::Compile(show, variablesStates, errors, curr_sheet, j, current_symbol, continuity); } } diff --git a/src/core/cc_fileformat.h b/src/core/cc_fileformat.h index 608489ca..d7f32001 100644 --- a/src/core/cc_fileformat.h +++ b/src/core/cc_fileformat.h @@ -209,6 +209,7 @@ struct Current_version_and_later { #define INGL_SIZE Make4CharWord('S', 'I', 'Z', 'E') #define INGL_CURR Make4CharWord('C', 'U', 'R', 'R') #define INGL_LABL Make4CharWord('L', 'A', 'B', 'L') +#define INGL_INST Make4CharWord('I', 'N', 'S', 'T') #define INGL_MODE Make4CharWord('M', 'O', 'D', 'E') #define INGL_DESC Make4CharWord('D', 'E', 'S', 'C') #define INGL_NAME Make4CharWord('N', 'A', 'M', 'E') diff --git a/src/core/cc_point.cpp b/src/core/cc_point.cpp index d2a211f5..5110e259 100644 --- a/src/core/cc_point.cpp +++ b/src/core/cc_point.cpp @@ -38,9 +38,7 @@ Point::Point(const Coord& p) : mSym(SYMBOL_PLAIN) , mPos(p) { - for (unsigned j = 0; j < Point::kNumRefPoints; j++) { - mRef[j] = mPos; - } + mRef.fill(mPos); } // EACH_POINT_DATA = BigEndianInt8(Size_rest_of_EACH_POINT_DATA) , @@ -97,7 +95,7 @@ std::vector Point::Serialize() const // Point positions // Write block size - // Write POSITIONw + // Write POSITION Parser::Append(result, uint16_t(GetPos().x)); Parser::Append(result, uint16_t(GetPos().y)); @@ -113,7 +111,7 @@ std::vector Point::Serialize() const } } - // Write POSITION + // Write SYMBOL Parser::Append(result, uint8_t(GetSymbol())); // Point labels (left or right) diff --git a/src/core/cc_point.h b/src/core/cc_point.h index 59372606..f9dd7f0a 100644 --- a/src/core/cc_point.h +++ b/src/core/cc_point.h @@ -24,11 +24,21 @@ #include "cc_coord.h" #include "cc_types.h" +#include #include #include namespace CalChart { +// A point in CalChart is a marcher on the field +// It maintains the reference points positions, and it's positions, as well as Symbol and some visualization +// information (like Flipped). +// +// In general we should try to keep point simple, and instead have the visualization data and other concepts +// maintained in the larger container, such as instrument or name, which should be per show. Symbol should +// probably be in per show, but as such the serialization code would make this difficult to restructure, so +// it will likely need to continue to be in Point. + class Point { public: static constexpr auto kNumRefPoints = 3; @@ -44,9 +54,6 @@ class Point { auto LabelIsVisible() const { return !mFlags.test(kLabelIsInvisible); } void SetLabelVisibility(bool isVisible); - auto GetSymbol() const { return mSym; } - void SetSymbol(SYMBOL_TYPE sym); - // reference points 0 is the point, refs are [1, kNumRefPoints] Coord GetPos(unsigned ref = 0) const; void SetPos(const Coord& c, unsigned ref = 0); @@ -57,11 +64,14 @@ class Point { kTotalBits }; std::bitset mFlags; - // by having both a sym type and cont index, we can have several - // points share the same symbol but have different continuities. SYMBOL_TYPE mSym; Coord mPos; - Coord mRef[kNumRefPoints]; + std::array mRef; + + auto GetSymbol() const { return mSym; } + void SetSymbol(SYMBOL_TYPE sym); + + friend class Sheet; friend struct Point_values; friend bool Check_Point(const Point&, const struct Point_values&); diff --git a/src/core/cc_sheet.cpp b/src/core/cc_sheet.cpp index ba3d5bf9..96f612ae 100644 --- a/src/core/cc_sheet.cpp +++ b/src/core/cc_sheet.cpp @@ -209,7 +209,7 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c } uint8_t* d = &data[0]; for (unsigned i = 0; i < mPoints.size(); i++) { - mPoints.at(i).SetSymbol((SYMBOL_TYPE)(*(d++))); + SetSymbol(i, (SYMBOL_TYPE)(*(d++))); } name = ReadLong(stream); } @@ -225,7 +225,7 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c } uint8_t* d = &data[0]; for (unsigned i = 0; i < mPoints.size(); i++) { - CheckInconsistancy(mPoints[i].GetSymbol(), *(d++), continity_for_symbol, + CheckInconsistancy(GetSymbol(i), *(d++), continity_for_symbol, symbol_for_continuity, mName, i); } name = ReadLong(stream); @@ -235,7 +235,7 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c if (!has_type) { // when a point doesn't have a cont_index, it is assumed to be 0 for (unsigned i = 0; i < mPoints.size(); i++) { - CheckInconsistancy(mPoints[i].GetSymbol(), 0, continity_for_symbol, + CheckInconsistancy(GetSymbol(i), 0, continity_for_symbol, symbol_for_continuity, mName, i); } } @@ -544,7 +544,7 @@ SelectionList Sheet::MakeSelectPointsBySymbol(SYMBOL_TYPE i) const { SelectionList select; for (auto j = 0; j < static_cast(mPoints.size()); j++) { - if (mPoints.at(j).GetSymbol() == i) { + if (GetSymbol(j) == i) { select.insert(j); } } @@ -601,9 +601,11 @@ void Sheet::SetContinuity(SYMBOL_TYPE which, Continuity const& new_cont) bool Sheet::ContinuityInUse(SYMBOL_TYPE idx) const { + auto points = std::vector(mPoints.size()); + std::iota(points.begin(), points.end(), 0); // is any point using this symbol? - for (auto& point : mPoints) { - if (point.GetSymbol() == idx) { + for (auto& point : points) { + if (GetSymbol(point) == idx) { return true; } } @@ -692,8 +694,22 @@ const Point& Sheet::GetPoint(unsigned i) const { return mPoints[i]; } Point& Sheet::GetPoint(unsigned i) { return mPoints[i]; } +SYMBOL_TYPE Sheet::GetSymbol(unsigned i) const { return mPoints[i].GetSymbol(); } + +void Sheet::SetSymbol(unsigned i, SYMBOL_TYPE sym) +{ + mPoints[i].SetSymbol(sym); +} + std::vector Sheet::GetPoints() const { return mPoints; } +std::vector Sheet::GetSymbols() const +{ + std::vector result; + std::transform(mPoints.begin(), mPoints.end(), std::back_inserter(result), [](auto&& i) { return i.GetSymbol(); }); + return result; +} + nlohmann::json Sheet::toOnlineViewerJSON(unsigned sheetNum, std::vector dotLabels, const AnimateSheet& compiledSheet) const { nlohmann::json j; @@ -709,7 +725,7 @@ nlohmann::json Sheet::toOnlineViewerJSON(unsigned sheetNum, std::vector> continuities; for (unsigned i = 0; i < mPoints.size(); i++) { - auto symbolName = ToOnlineViewer::symbolName(mPoints[i].GetSymbol()); + auto symbolName = ToOnlineViewer::symbolName(GetSymbol(i)); uniqueDotTypes.insert(symbolName); labelToSymbol[dotLabels[i]] = symbolName; continuities[symbolName] = boilerplate; diff --git a/src/core/cc_sheet.h b/src/core/cc_sheet.h index 6226001b..1a1312a9 100644 --- a/src/core/cc_sheet.h +++ b/src/core/cc_sheet.h @@ -81,7 +81,10 @@ class Sheet { // points const Point& GetPoint(unsigned i) const; Point& GetPoint(unsigned i); + SYMBOL_TYPE GetSymbol(unsigned i) const; + void SetSymbol(unsigned i, SYMBOL_TYPE sym); std::vector GetPoints() const; + std::vector GetSymbols() const; void SetPoints(const std::vector& points); int FindPoint(Coord where, Coord::units searchBound, unsigned ref = 0) const; std::vector RemapPoints(const std::vector& table) const; diff --git a/src/core/cc_show.cpp b/src/core/cc_show.cpp index 83be2770..4deaba29 100644 --- a/src/core/cc_show.cpp +++ b/src/core/cc_show.cpp @@ -36,6 +36,7 @@ #include namespace CalChart { +static constexpr auto kDefault = "default"; static const std::string k_nofile_str = "Unable to open file"; static const std::string k_badcont_str = "Error in continuity file"; static const std::string k_contnohead_str = "Continuity file doesn't begin with header"; @@ -49,10 +50,10 @@ std::unique_ptr Show::Create_CC_show(ShowMode const& mode) return show; } -std::unique_ptr Show::Create_CC_show(ShowMode const& mode, std::vector const& labels, unsigned columns) +std::unique_ptr Show::Create_CC_show(ShowMode const& mode, std::vector> const& labelsAndInstruments, unsigned columns) { auto show = Create_CC_show(mode); - show->SetNumPoints(labels, columns, mode.FieldOffset()); + show->SetNumPoints(labelsAndInstruments, columns, mode.FieldOffset()); return show; } @@ -101,7 +102,7 @@ Show::Show(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* // read in the size: // <4><# points> auto numpoints = ReadCheckIDandSize(stream, INGL_SIZE); - mPtLabels.assign(numpoints, std::string()); + mDotLabelAndInstrument.assign(numpoints, std::pair{ "", kDefault }); uint32_t name = ReadLong(stream); // Optional: read in the point labels @@ -114,7 +115,9 @@ Show::Show(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* labels.push_back(str); str += strlen(str) + 1; } - SetPointLabel(labels); + std::vector> labelsAndInstruments; + std::transform(labels.begin(), labels.end(), std::back_inserter(labelsAndInstruments), [](auto&& i) { return std::pair{ i, kDefault }; }); + SetPointLabelAndInstrument(labelsAndInstruments); // peek for the next name name = ReadLong(stream); } else { @@ -165,17 +168,17 @@ Show::Show(ShowMode const& mode, const uint8_t* ptr, size_t size, ParseErrorHand throw CC_FileException("Incorrect size", INGL_SIZE); } auto numpoints = get_big_long(ptr); - show->mPtLabels.assign(numpoints, std::string()); + show->mDotLabelAndInstrument.assign(numpoints, std::pair{ "", kDefault }); }; auto parse_INGL_LABL = [](Show* show, const uint8_t* ptr, size_t size) { - std::vector labels; + std::vector> labels; if (!size && show->GetNumPoints()) { throw CC_FileException("Label the wrong size", INGL_LABL); } // restrict search to the size we're given auto str = (const char*)ptr; for (auto i = 0; i < show->GetNumPoints(); i++) { - labels.push_back(str); + labels.push_back({ str, kDefault }); auto length = strlen(str) + 1; if (length > size) { throw CC_FileException("Label too large", INGL_LABL); @@ -186,7 +189,29 @@ Show::Show(ShowMode const& mode, const uint8_t* ptr, size_t size, ParseErrorHand if (size != 0) { throw CC_FileException("Label the wrong size", INGL_LABL); } - show->SetPointLabel(labels); + show->SetPointLabelAndInstrument(labels); + }; + auto parse_INGL_INST = [](Show* show, const uint8_t* ptr, size_t size) { + auto currentLabels = show->mDotLabelAndInstrument; + if (!size && show->GetNumPoints()) { + throw CC_FileException("Label the wrong size", INGL_LABL); + } + // restrict search to the size we're given + auto str = (const char*)ptr; + for (auto i = 0; i < show->GetNumPoints(); i++) { + auto thisInst = std::string{ str }; + currentLabels.at(i).second = thisInst == "" ? kDefault : thisInst; + auto length = strlen(str) + 1; + if (length > size) { + throw CC_FileException("Label too large", INGL_LABL); + } + str += length; + size -= length; + } + if (size != 0) { + throw CC_FileException("Label the wrong size", INGL_LABL); + } + show->SetPointLabelAndInstrument(currentLabels); }; auto parse_INGL_DESC = [](Show* show, const uint8_t* ptr, size_t size) { auto str = (const char*)ptr; @@ -226,6 +251,7 @@ Show::Show(ShowMode const& mode, const uint8_t* ptr, size_t size, ParseErrorHand parser = { { INGL_SIZE, parse_INGL_SIZE }, { INGL_LABL, parse_INGL_LABL }, + { INGL_INST, parse_INGL_INST }, { INGL_DESC, parse_INGL_DESC }, { INGL_SHET, parse_INGL_SHET }, { INGL_SELE, parse_INGL_SELE }, @@ -257,6 +283,14 @@ Show::Show(ShowMode const& mode, const uint8_t* ptr, size_t size, ParseErrorHand // Destroy a show Show::~Show() { } +template +auto anyInstrumentsBesidesDefault(T const& all) +{ + auto instruments = std::set(all.begin(), all.end()); + instruments.erase(kDefault); + return instruments.size(); +} + std::vector Show::SerializeShowData() const { using Parser::Append; @@ -269,11 +303,20 @@ std::vector Show::SerializeShowData() const // Write LABEL std::vector labels; - for (auto& i : mPtLabels) { - AppendAndNullTerminate(labels, i); + for (auto& i : mDotLabelAndInstrument) { + AppendAndNullTerminate(labels, i.first); } Append(result, Construct_block(INGL_LABL, labels)); + // Write INSTRUMENTS + if (anyInstrumentsBesidesDefault(GetPointsInstrument())) { + std::vector instruments; + for (auto& i : mDotLabelAndInstrument) { + AppendAndNullTerminate(instruments, i.second == kDefault ? "" : i.second); + } + Append(result, Construct_block(INGL_INST, instruments)); + } + // write Description if (!GetDescr().empty()) { std::vector descr; @@ -358,28 +401,28 @@ void Show::InsertSheet(const Sheet_container_t& sheet, } // warning, the labels might not match up -void Show::SetNumPoints(std::vector const& labels, int columns, Coord const& new_march_position) +void Show::SetNumPoints(std::vector> const& labelsAndInstruments, int columns, Coord const& new_march_position) { for (auto sht = GetSheetBegin(); sht != GetSheetEnd(); ++sht) { - auto pts = sht->NewNumPointsPositions(static_cast(labels.size()), columns, new_march_position); + auto pts = sht->NewNumPointsPositions(static_cast(labelsAndInstruments.size()), columns, new_march_position); sht->SetPoints(pts); } - SetPointLabel(labels); + SetPointLabelAndInstrument(labelsAndInstruments); } void Show::DeletePoints(SelectionList const& sl) { for (auto iter = sl.rbegin(); iter != sl.rend(); ++iter) { - mPtLabels.erase(mPtLabels.begin() + *iter); + mDotLabelAndInstrument.erase(mDotLabelAndInstrument.begin() + *iter); } for (auto&& sht : mSheets) { sht.DeletePoints(sl); } } -void Show::SetPointLabel(const std::vector& labels) +void Show::SetPointLabelAndInstrument(std::vector> const& labels) { - mPtLabels = labels; + mDotLabelAndInstrument = labels; } // A relabel mapping is the mapping you would need to apply to sheet_next (and all following sheets) @@ -411,9 +454,42 @@ std::pair> Show::GetRelabelMapping(const_Sheet_iterato std::string Show::GetPointLabel(int i) const { - if (i >= static_cast(mPtLabels.size())) + if (i >= static_cast(mDotLabelAndInstrument.size())) return ""; - return mPtLabels.at(i); + return mDotLabelAndInstrument.at(i).first; +} + +std::vector Show::GetPointsLabel() const +{ + std::vector labels; + std::transform(mDotLabelAndInstrument.begin(), mDotLabelAndInstrument.end(), std::back_inserter(labels), [](auto&& i) { return i.first; }); + return labels; +} + +std::string Show::GetPointInstrument(int i) const +{ + if (i >= static_cast(mDotLabelAndInstrument.size())) + return ""; + return mDotLabelAndInstrument.at(i).second; +} + +std::vector Show::GetPointsInstrument() const +{ + std::vector instruments; + std::transform(mDotLabelAndInstrument.begin(), mDotLabelAndInstrument.end(), std::back_inserter(instruments), [](auto&& i) { return i.second; }); + return instruments; +} + +SYMBOL_TYPE Show::GetPointSymbol(int i) const +{ + if (i >= static_cast(mDotLabelAndInstrument.size())) + return SYMBOL_PLAIN; + return GetCurrentSheet()->GetSymbol(i); +} + +std::vector Show::GetPointsSymbol() const +{ + return GetCurrentSheet()->GetSymbols(); } bool Show::AlreadyHasPrintContinuity() const @@ -450,7 +526,7 @@ void Show::SetShowMode(ShowMode const& mode) SelectionList Show::MakeSelectAll() const { SelectionList sl; - for (auto i = 0u; i < mPtLabels.size(); ++i) + for (auto i = 0u; i < mDotLabelAndInstrument.size(); ++i) sl.insert(i); return sl; } @@ -510,6 +586,33 @@ SelectionList Show::MakeSelectWithLasso(const Lasso& lasso, int ref) const return sl; } +SelectionList Show::MakeSelectBySymbol(SYMBOL_TYPE symbol) const +{ + return GetCurrentSheet()->MakeSelectPointsBySymbol(symbol); +} + +SelectionList Show::MakeSelectByInstrument(std::string const& instrumentName) const +{ + SelectionList sl; + for (auto i = 0ul; i < mDotLabelAndInstrument.size(); ++i) { + if (mDotLabelAndInstrument[i].second == instrumentName) { + sl.insert(i); + } + } + return sl; +} + +SelectionList Show::MakeSelectByLabel(std::string const& label) const +{ + SelectionList sl; + for (auto i = 0ul; i < mDotLabelAndInstrument.size(); ++i) { + if (mDotLabelAndInstrument[i].first == label) { + sl.insert(i); + } + } + return sl; +} + nlohmann::json Show::toOnlineViewerJSON(const Animation& compiledShow) const { nlohmann::json j; @@ -518,13 +621,15 @@ nlohmann::json Show::toOnlineViewerJSON(const Animation& compiledShow) const j["title"] = "(MANUAL) the show title that you want people to see goes here"; // TODO; For now, this will be manually added to the exported file j["year"] = "(MANUAL) enter show year (e.g. 2017)"; // TODO; Should eventually save automatically j["description"] = mDescr; - j["labels"] = mPtLabels; + std::vector ptLabels; + std::transform(mDotLabelAndInstrument.begin(), mDotLabelAndInstrument.end(), std::back_inserter(ptLabels), [](auto&& i) { return i.first; }); + j["labels"] = ptLabels; std::vector sheetData; auto animateSheetIter = compiledShow.sheetsBegin(); auto sheetIndex = 0; for (auto showSheetIter = GetSheetBegin(); showSheetIter != GetSheetEnd(); ++showSheetIter) { - sheetData.push_back(showSheetIter->toOnlineViewerJSON(sheetIndex + 1, mPtLabels, *animateSheetIter)); + sheetData.push_back(showSheetIter->toOnlineViewerJSON(sheetIndex + 1, ptLabels, *animateSheetIter)); ++animateSheetIter; ++sheetIndex; } @@ -566,11 +671,11 @@ Show_command_pair Show::Create_SetShowModeCommand(CalChart::ShowMode const& newm return { action, reaction }; } -Show_command_pair Show::Create_SetShowInfoCommand(std::vector const& labels, int numColumns, Coord const& new_march_position) const +Show_command_pair Show::Create_SetupMarchersCommand(std::vector> const& labelsAndInstruments, int numColumns, Coord const& new_march_position) const { - auto action = [labels, numColumns, new_march_position](Show& show) { show.SetNumPoints(labels, numColumns, new_march_position); }; + auto action = [labelsAndInstruments, numColumns, new_march_position](Show& show) { show.SetNumPoints(labelsAndInstruments, numColumns, new_march_position); }; // need to go through and save all the positions and labels for later - auto old_labels = mPtLabels; + auto old_labels = mDotLabelAndInstrument; std::vector> old_points; for (auto&& sheet : mSheets) { old_points.emplace_back(sheet.GetPoints()); @@ -579,7 +684,23 @@ Show_command_pair Show::Create_SetShowInfoCommand(std::vector const for (auto i = 0ul; i < show.mSheets.size(); ++i) { show.mSheets.at(i).SetPoints(old_points.at(i)); } - show.SetPointLabel(old_labels); + show.SetPointLabelAndInstrument(old_labels); + }; + return { action, reaction }; +} + +Show_command_pair Show::Create_SetInstrumentsCommand(std::map const& dotToInstrument) const +{ + auto old_labels = mDotLabelAndInstrument; + auto new_labels = old_labels; + std::for_each(dotToInstrument.begin(), dotToInstrument.end(), [&new_labels](auto&& i) { + new_labels.at(i.first).second = i.second; + }); + auto action = [new_labels](Show& show) { + show.SetPointLabelAndInstrument(new_labels); + }; + auto reaction = [old_labels](Show& show) { + show.SetPointLabelAndInstrument(old_labels); }; return { action, reaction }; } @@ -692,7 +813,7 @@ Show_command_pair Show::Create_DeletePointsCommand() const show.SetSelection({}); }; // need to go through and save all the positions and labels for later - auto old_labels = mPtLabels; + auto old_labels = mDotLabelAndInstrument; std::vector> old_points; for (auto&& sheet : mSheets) { old_points.emplace_back(sheet.GetPoints()); @@ -701,7 +822,7 @@ Show_command_pair Show::Create_DeletePointsCommand() const for (auto i = 0ul; i < show.mSheets.size(); ++i) { show.mSheets.at(i).SetPoints(old_points.at(i)); } - show.SetPointLabel(old_labels); + show.SetPointLabelAndInstrument(old_labels); }; return { action, reaction }; } @@ -754,21 +875,21 @@ Show_command_pair Show::Create_SetSymbolCommand(const SelectionList& selectionLi auto sheet = GetCurrentSheet(); for (auto&& i : selectionList) { // Only do work on points that have different symbols - if (sym != sheet->GetPoint(i).GetSymbol()) { + if (sym != sheet->GetSymbol(i)) { new_sym[i] = sym; - original_sym[i] = sheet->GetPoint(i).GetSymbol(); + original_sym[i] = sheet->GetSymbol(i); } } auto action = [sheet_num = mSheetNum, new_sym](Show& show) { auto sheet = show.GetNthSheet(sheet_num); for (auto&& i : new_sym) { - sheet->GetPoint(i.first).SetSymbol(i.second); + sheet->SetSymbol(i.first, i.second); } }; auto reaction = [sheet_num = mSheetNum, original_sym](Show& show) { auto sheet = show.GetNthSheet(sheet_num); for (auto&& i : original_sym) { - sheet->GetPoint(i.first).SetSymbol(i.second); + sheet->SetSymbol(i.first, i.second); } }; return { action, reaction }; diff --git a/src/core/cc_show.h b/src/core/cc_show.h index e595688e..7e71986c 100644 --- a/src/core/cc_show.h +++ b/src/core/cc_show.h @@ -58,7 +58,7 @@ class Show { // you can create a show in two ways, from nothing, or from an input stream static std::unique_ptr Create_CC_show(ShowMode const& mode); - static std::unique_ptr Create_CC_show(ShowMode const& mode, std::vector const& labels, unsigned columns); + static std::unique_ptr Create_CC_show(ShowMode const& mode, std::vector> const& labelsAndInstruments, unsigned columns); static std::unique_ptr Create_CC_show(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* correction = nullptr); private: @@ -80,7 +80,8 @@ class Show { Show_command_pair Create_SetSelectionCommand(const SelectionList& sl) const; Show_command_pair Create_SetCurrentSheetAndSelectionCommand(int n, const SelectionList& sl) const; Show_command_pair Create_SetShowModeCommand(CalChart::ShowMode const& newmode) const; - Show_command_pair Create_SetShowInfoCommand(std::vector const& labels, int numColumns, Coord const& new_march_position) const; + Show_command_pair Create_SetupMarchersCommand(std::vector> const& labelsAndInstruments, int numColumns, Coord const& new_march_position) const; + Show_command_pair Create_SetInstrumentsCommand(std::map const& dotToInstrument) const; Show_command_pair Create_SetSheetTitleCommand(std::string const& newname) const; Show_command_pair Create_SetSheetBeatsCommand(int beats) const; Show_command_pair Create_AddSheetsCommand(const Show::Sheet_container_t& sheets, int where) const; @@ -112,9 +113,13 @@ class Show { auto GetCurrentSheet() const { return GetNthSheet(mSheetNum); } int GetNumSheets() const; auto GetCurrentSheetNum() const { return mSheetNum; } - auto GetNumPoints() const { return static_cast(mPtLabels.size()); } + auto GetNumPoints() const { return static_cast(mDotLabelAndInstrument.size()); } std::string GetPointLabel(int i) const; - auto GetPointLabels() const { return mPtLabels; } + std::vector GetPointsLabel() const; + std::string GetPointInstrument(int i) const; + std::vector GetPointsInstrument() const; + SYMBOL_TYPE GetPointSymbol(int i) const; + std::vector GetPointsSymbol() const; bool AlreadyHasPrintContinuity() const; @@ -130,6 +135,9 @@ class Show { SelectionList MakeRemoveFromSelection(const SelectionList& sl) const; SelectionList MakeToggleSelection(const SelectionList& sl) const; SelectionList MakeSelectWithLasso(const Lasso& lasso, int ref) const; + SelectionList MakeSelectBySymbol(SYMBOL_TYPE i) const; + SelectionList MakeSelectByInstrument(std::string const& instrumentName) const; + SelectionList MakeSelectByLabel(std::string const& labelName) const; // Point selection auto IsSelected(int i) const { return mSelectionList.count(i) != 0; } @@ -152,9 +160,9 @@ class Show { void SetCurrentSheet(int n); void SetSelection(const SelectionList& sl); - void SetNumPoints(std::vector const& labels, int columns, Coord const& new_march_position); + void SetNumPoints(std::vector> const& labelsAndInstruments, int columns, Coord const& new_march_position); void DeletePoints(SelectionList const& sl); - void SetPointLabel(const std::vector& labels); + void SetPointLabelAndInstrument(std::vector> const& labels); // Descriptions aren't used, but keeping this alive. See issue #203 auto GetDescr() const { return mDescr; } @@ -173,7 +181,8 @@ class Show { // members std::string mDescr; Sheet_container_t mSheets; - std::vector mPtLabels; + // labels and instruments go hand in hand, put them together to make sure we don't have extras or missing + std::vector> mDotLabelAndInstrument; SelectionList mSelectionList; // order of selections int mSheetNum; ShowMode mMode; diff --git a/src/core/print_ps.cpp b/src/core/print_ps.cpp index cdec41e7..bc8f5396 100644 --- a/src/core/print_ps.cpp +++ b/src/core/print_ps.cpp @@ -652,7 +652,7 @@ void PrintShowToPS::PrintStandard(std::ostream& buffer, const Sheet& sheet, float dot_x = (CoordUnits2Float(sheet.GetPoint(i).GetPos().x) - fieldoffx - step_offset) / step_width * field_w; float dot_y = (1.0 - (CoordUnits2Float(sheet.GetPoint(i).GetPos().y) - fieldoffy) / fieldheight) * field_h; buffer << dot_x << " " << dot_y << " " - << dot_routines[sheet.GetPoint(i).GetSymbol()] << "\n"; + << dot_routines[sheet.GetSymbol(i)] << "\n"; buffer << "(" << mShow.GetPointLabel(i) << ") " << dot_x << " " << dot_y << " " << (sheet.GetPoint(i).GetFlip() ? "donumber2" : "donumber") << "\n"; diff --git a/src/draw.cpp b/src/draw.cpp index ffce711a..6676e9b5 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -183,8 +183,8 @@ static const double kLowerNorthArrow[2][3] = { static const double kContinuityStart[2] = { 606 / kSizeY, 556 / kSizeYLandscape }; -static void DrawPoint(wxDC& dc, CalChartConfiguration const& config, CalChart::Point const& point, int reference, CalChart::Coord const& origin, wxString const& label); -static void DrawPointHelper(wxDC& dc, CalChartConfiguration const& config, CalChart::Coord const& pos, CalChart::Point const& point, wxString const& label); +static void DrawPoint(wxDC& dc, CalChartConfiguration const& config, CalChart::Point const& point, SYMBOL_TYPE symbol, int reference, CalChart::Coord const& origin, wxString const& label); +static void DrawPointHelper(wxDC& dc, CalChartConfiguration const& config, CalChart::Coord const& pos, CalChart::Point const& point, SYMBOL_TYPE symbol, wxString const& label); void DrawSheetPoints(wxDC& dc, CalChartConfiguration const& config, CalChart::Coord origin, SelectionList const& selection_list, int numberPoints, std::vector const& labels, CalChart::Sheet const& sheet, int ref, CalChartColors unselectedColor, CalChartColors selectedColor, CalChartColors unselectedTextColor, CalChartColors selectedTextColor) { @@ -203,7 +203,7 @@ void DrawSheetPoints(wxDC& dc, CalChartConfiguration const& config, CalChart::Co dc.SetPen(brushAndPen.second); dc.SetTextForeground(config.Get_CalChartBrushAndPen(unselectedTextColor).second.GetColour()); } - DrawPoint(dc, config, sheet.GetPoint(i), ref, origin, labels.at(i)); + DrawPoint(dc, config, sheet.GetPoint(i), sheet.GetSymbol(i), ref, origin, labels.at(i)); } } @@ -458,7 +458,7 @@ void DrawForPrintingHelper(wxDC& dc, CalChartConfiguration const& config, CalCha const auto point = pts.at(i); const auto pos = point.GetPos(ref) + mode.Offset(); dc.SetBrush(*wxBLACK_BRUSH); - DrawPointHelper(dc, config, pos, point, show.GetPointLabel(i)); + DrawPointHelper(dc, config, pos, point, sheet.GetSymbol(i), show.GetPointLabel(i)); } // now reset everything to draw the rest of the text @@ -532,10 +532,10 @@ void DrawForPrinting(wxDC* printerdc, CalChartConfiguration const& config, CalCh printerdc->Blit(0, 0, rotate_membm.GetWidth(), rotate_membm.GetHeight(), &tmemdc, 0, 0); } -void DrawPointHelper(wxDC& dc, CalChartConfiguration const& config, CalChart::Coord const& pos, CalChart::Point const& point, wxString const& label) +void DrawPointHelper(wxDC& dc, CalChartConfiguration const& config, CalChart::Coord const& pos, CalChart::Point const& point, SYMBOL_TYPE symbol, wxString const& label) { SaveAndRestore_Brush restore(dc); - switch (point.GetSymbol()) { + switch (symbol) { case SYMBOL_SOL: case SYMBOL_SOLBKSL: case SYMBOL_SOLSL: @@ -552,7 +552,7 @@ void DrawPointHelper(wxDC& dc, CalChartConfiguration const& config, CalChart::Co auto where = fDIP(wxPoint{ pos.x, pos.y }); dc.DrawCircle(where, circ_r); - switch (point.GetSymbol()) { + switch (symbol) { case SYMBOL_SL: case SYMBOL_X: dc.DrawLine(where.x - plineoff, where.y + plineoff, where.x + plineoff, where.y - plineoff); @@ -564,7 +564,7 @@ void DrawPointHelper(wxDC& dc, CalChartConfiguration const& config, CalChart::Co default: break; } - switch (point.GetSymbol()) { + switch (symbol) { case SYMBOL_BKSL: case SYMBOL_X: dc.DrawLine(where.x - plineoff, where.y - plineoff, where.x + plineoff, where.y + plineoff); @@ -583,9 +583,9 @@ void DrawPointHelper(wxDC& dc, CalChartConfiguration const& config, CalChart::Co } } -static void DrawPoint(wxDC& dc, CalChartConfiguration const& config, CalChart::Point const& point, int reference, CalChart::Coord const& origin, wxString const& label) +static void DrawPoint(wxDC& dc, CalChartConfiguration const& config, CalChart::Point const& point, SYMBOL_TYPE symbol, int reference, CalChart::Coord const& origin, wxString const& label) { - DrawPointHelper(dc, config, point.GetPos(reference) + origin, point, label); + DrawPointHelper(dc, config, point.GetPos(reference) + origin, point, symbol, label); } void DrawPhatomPoints(wxDC& dc, const CalChartConfiguration& config, @@ -602,7 +602,7 @@ void DrawPhatomPoints(wxDC& dc, const CalChartConfiguration& config, dc.SetTextForeground(config.Get_CalChartBrushAndPen(COLOR_GHOST_POINT_TEXT).first.GetColour()); for (auto& i : positions) { - DrawPointHelper(dc, config, i.second + origin, sheet.GetPoint(i.first), show.GetPointLabel(i.first)); + DrawPointHelper(dc, config, i.second + origin, sheet.GetPoint(i.first), sheet.GetSymbol(i.first), show.GetPointLabel(i.first)); } } diff --git a/src/print_ps_dialog.cpp b/src/print_ps_dialog.cpp index f5763080..673d30ca 100644 --- a/src/print_ps_dialog.cpp +++ b/src/print_ps_dialog.cpp @@ -23,12 +23,13 @@ #include "print_ps_dialog.h" +#include "CalChartDoc.h" #include "basic_ui.h" #include "cc_sheet.h" #include "cc_show.h" #include "confgr.h" #include "print_ps.h" -#include "show_ui.h" + #include #include diff --git a/src/ui_enums.h b/src/ui_enums.h index 535662a1..948f99f3 100644 --- a/src/ui_enums.h +++ b/src/ui_enums.h @@ -39,9 +39,10 @@ enum { CALCHART__PRINT_EDIT_CONTINUITY, CALCHART__SET_SHEET_TITLE, CALCHART__SET_BEATS, - CALCHART__SETUP, + CALCHART__SETUPMARCHERS, + CALCHART__SETUPINSTRUMENTS, CALCHART__SETMODE, - CALCHART__POINTS, + CALCHART__POINTPICKER, CALCHART__SELECT_ALL, CALCHART__ANIMATE, CALCHART__OMNIVIEW, @@ -99,6 +100,10 @@ enum { CALCHART__GhostNthSheet, CALCHART__GhostControls, + CALCHART__InstrumentChoice, + CALCHART__SymbolChoice, + CALCHART__MarcherChoice, + CALCHART__anim_reanimate, CALCHART__anim_select_coll, CALCHART__anim_next_beat_timer, @@ -128,7 +133,8 @@ enum { CALCHART__ViewAnimationErrors, CALCHART__ViewAnimation, CALCHART__ViewPrintContinuity, - CALCHART__ViewToolBar, + CALCHART__ViewLassosToolBar, + CALCHART__ViewMarcherToolBar, CALCHART__ViewSwapFieldAndAnimate, CALCHART__ViewZoomFit,