Skip to content

Commit

Permalink
[ANT-2381] Legacy GUI : Restore grid statistics (#2478)
Browse files Browse the repository at this point in the history
Related ticket is
[here](https://gopro-tickets.rte-france.com/browse/ANT-2381).

**What was done** :

- Restore the functionality of statistics computation on grids (number
of cells selected, sum of their content, min of their content, ...),
previously removed.
- Fix the issue previously noticed : select a column, stats are wrong,
especially the number of selected cells, which is twice the number it
should be.

---------

Co-authored-by: Vincent Payet <[email protected]>
  • Loading branch information
guilpier-code and payetvin authored Nov 12, 2024
1 parent c18e628 commit 827a7f2
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/ui/simulator/application/main/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ void ApplWnd::internalInitialize()
statusbar->SetStatusStyles(2, styles);

statusbar->SetMinHeight(14);
statusbar->SetStatusText(wxT(""), 1);
statusbar->Connect(statusbar->GetId(),
wxEVT_CONTEXT_MENU,
wxContextMenuEventHandler(ApplWnd::evtOnContextMenuStatusBar),
nullptr,
this);

statusbar->SetStatusText(wxT("| "), 1);

wxFont f = statusbar->GetFont();
f.SetPointSize(f.GetPointSize() - 1);
Expand Down
10 changes: 10 additions & 0 deletions src/ui/simulator/application/main/internal-ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ enum MenusID
mnIDLaunchAnalyzer,
mnIDLaunchConstraintsBuilder,

//! \name Popup Menu Operator for selected cells on any grid
//@{
mnIDPopupOpNone,
mnIDPopupOpAverage,
mnIDPopupOpCellCount,
mnIDPopupOpMinimum,
mnIDPopupOpMaximum,
mnIDPopupOpSum,
//@}

//! \name Popup Menu Operator for selected nodes on any layer
//@{
mnIDPopupSelectionHide,
Expand Down
65 changes: 65 additions & 0 deletions src/ui/simulator/application/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ EVT_MENU(mnInternalLogMessage, ApplWnd::onLogMessage)
EVT_MENU(mnIDLaunchAnalyzer, ApplWnd::evtLaunchAnalyzer)
EVT_MENU(mnIDLaunchConstraintsBuilder, ApplWnd::evtLaunchConstraintsBuilder)

// Context menu : Operator for selected cells (grid)
EVT_MENU(mnIDPopupOpNone, ApplWnd::evtOnContextMenuChangeOperator)
EVT_MENU(mnIDPopupOpAverage, ApplWnd::evtOnContextMenuChangeOperator)
EVT_MENU(mnIDPopupOpCellCount, ApplWnd::evtOnContextMenuChangeOperator)
EVT_MENU(mnIDPopupOpMinimum, ApplWnd::evtOnContextMenuChangeOperator)
EVT_MENU(mnIDPopupOpMaximum, ApplWnd::evtOnContextMenuChangeOperator)
EVT_MENU(mnIDPopupOpSum, ApplWnd::evtOnContextMenuChangeOperator)

EVT_MENU_OPEN(ApplWnd::evtOnMenuOpen)
EVT_MENU_CLOSE(ApplWnd::evtOnMenuClose)

Expand Down Expand Up @@ -253,6 +261,8 @@ ApplWnd::ApplWnd() :
pageRenewableCommon(nullptr),
pageNodalOptim(nullptr),
pWndBindingConstraints(nullptr),
pGridSelectionOperator(new Component::Datagrid::Selection::CellCount()),
pGridSelectionAttachedGrid(nullptr),
pMapContextMenu(nullptr),
pUserNotes(nullptr),
pMainNotebookAlreadyHasItsComponents(false),
Expand Down Expand Up @@ -316,6 +326,13 @@ ApplWnd::~ApplWnd()
OnStudyAreasChanged.clear();
OnStudyAreaDelete.clear();

// Delete the grid operator
if (pGridSelectionOperator)
{
delete pGridSelectionOperator;
pGridSelectionOperator = nullptr; // May be needed in some cases
}

// Disconnect all events
destroyBoundEvents();
// Unregister the global pointer to the instance
Expand Down Expand Up @@ -354,6 +371,34 @@ void ApplWnd::selectSystem()
pNotebook->select(wxT("sys"), true);
}

void ApplWnd::evtOnContextMenuChangeOperator(wxCommandEvent& evt)
{
switch (evt.GetId())
{
case mnIDPopupOpNone:
gridOperatorSelectedCells(nullptr);
break;
case mnIDPopupOpAverage:
gridOperatorSelectedCells(new Component::Datagrid::Selection::Average());
break;
case mnIDPopupOpCellCount:
gridOperatorSelectedCells(new Component::Datagrid::Selection::CellCount());
break;
case mnIDPopupOpMinimum:
gridOperatorSelectedCells(new Component::Datagrid::Selection::Minimum());
break;
case mnIDPopupOpMaximum:
gridOperatorSelectedCells(new Component::Datagrid::Selection::Maximum());
break;
case mnIDPopupOpSum:
gridOperatorSelectedCells(new Component::Datagrid::Selection::Sum());
break;
default:
break;
}
evt.Skip();
}

static inline void EnableItem(wxMenuBar* menu, int id, bool opened)
{
auto* item = menu->FindItem(id);
Expand Down Expand Up @@ -502,6 +547,7 @@ void ApplWnd::evtOnUpdateGUIAfterStudyIO(bool opened)

// Reset the status bar
resetDefaultStatusBarText();
gridOperatorSelectedCellsUpdateResult(pGridSelectionAttachedGrid);

// reload the user notes and districts
if (not aboutToQuit and study)
Expand All @@ -527,6 +573,7 @@ void ApplWnd::evtOnUpdateGUIAfterStudyIO(bool opened)
{
GetSizer()->Clear(true);
pUserNotes = nullptr;
pGridSelectionAttachedGrid = nullptr;
pBigDaddy = nullptr;
pMainSizer = nullptr;
pData->wipPanel = nullptr;
Expand Down Expand Up @@ -786,6 +833,24 @@ void ApplWnd::onRenewableGenerationModellingChanged(bool init)
refreshInputMenuOnRenewableModellingChanged(aggregated);
}

void ApplWnd::gridOperatorSelectedCells(Component::Datagrid::Selection::IOperator* v)
{
delete pGridSelectionOperator;
pGridSelectionOperator = v;
gridOperatorSelectedCellsUpdateResult(pGridSelectionAttachedGrid);
}

Component::Datagrid::Selection::IOperator* ApplWnd::gridOperatorSelectedCells() const
{
return pGridSelectionOperator;
}

void ApplWnd::disableGridOperatorIfGrid(wxGrid* grid)
{
if (pGridSelectionAttachedGrid == grid)
gridOperatorSelectedCellsUpdateResult(nullptr);
}

void ApplWnd::title()
{
assert(wxIsMainThread() == true and "Must be ran from the main thread");
Expand Down
45 changes: 45 additions & 0 deletions src/ui/simulator/application/main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <wx/aui/aui.h>

#include "../../toolbox/components/notebook/notebook.h"
#include "../../toolbox/components/datagrid/selectionoperation.h"
#include "../../toolbox/components/map/settings.h"
#include <list>
#include "fwd.h"
Expand Down Expand Up @@ -111,6 +112,41 @@ class ApplWnd final : public Component::Frame::WxLocalFrame, public Yuni::IEvent
*/
Map::Component* map() const;

/*!
** \name Grid operator (for selected cells)
**
** A grid operator computes an operation (Sum, average...) on all selected
** cells of the grid that currently has the focus. The result of this
** computation is displayed in the status bar.
**
** \see Antares::Component::Datagrid::Component::onGridEnter()
** \see Antares::Component::Datagrid::Component::onGridLeave()
*/
//@{
/*!
** \brief Get the current grid operator for selected cells
*/
Component::Datagrid::Selection::IOperator* gridOperatorSelectedCells() const;

/*!
** \brief Set the grid operator for selected cells
*/
void gridOperatorSelectedCells(Component::Datagrid::Selection::IOperator* v);

/*!
** \brief Update the GUI to display the result of the grid operator
**
** This method should be called each time the cells selection changes.
** \param grid The `wxGrid` that has currently the focus (may be NULL)
*/
void gridOperatorSelectedCellsUpdateResult(wxGrid* grid);

/*!
** \brief Disable the grid operator
*/
void disableGridOperatorIfGrid(wxGrid* grid);
//@}

//! \name Title of the Window
//@{
void title();
Expand Down Expand Up @@ -333,6 +369,8 @@ class ApplWnd final : public Component::Frame::WxLocalFrame, public Yuni::IEvent

//! Create a complete menu for the window
wxMenuBar* createMenu();
//! Create a popup menu for all available operators on selected cells (grid)
wxMenu* createPopupMenuOperatorsOnGrid();

//! Create menu: File
wxMenu* createMenuFiles();
Expand Down Expand Up @@ -404,6 +442,9 @@ class ApplWnd final : public Component::Frame::WxLocalFrame, public Yuni::IEvent

//! \name Event: Context menu
//@{
//! Show the context menu associated to the status bar
void evtOnContextMenuStatusBar(wxContextMenuEvent& evt);
void evtOnContextMenuChangeOperator(wxCommandEvent& evt);
void evtOnContextMenuMap(int x, int y);
//@}

Expand Down Expand Up @@ -705,6 +746,10 @@ class ApplWnd final : public Component::Frame::WxLocalFrame, public Yuni::IEvent
Component::Notebook::Page* pageScBuilderRenewable;
Component::Notebook::Page* pageScBuilderHydroLevels;

//! The current grid operator to use on selected cells
Component::Datagrid::Selection::IOperator* pGridSelectionOperator;
wxGrid* pGridSelectionAttachedGrid;

//! A context menu for the map
wxMenu* pMapContextMenu;

Expand Down
15 changes: 15 additions & 0 deletions src/ui/simulator/application/main/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ wxMenuBar* ApplWnd::createMenu()
return ret;
}

wxMenu* ApplWnd::createPopupMenuOperatorsOnGrid()
{
auto* menu = new wxMenu();

// Wizard
Menu::CreateItem(menu, mnIDPopupOpNone, wxT("None"), "images/16x16/empty.png");
menu->AppendSeparator();
Menu::CreateItem(menu, mnIDPopupOpAverage, wxT("Average "));
Menu::CreateItem(menu, mnIDPopupOpCellCount, wxT("Cell count "));
Menu::CreateItem(menu, mnIDPopupOpMinimum, wxT("Minimum "));
Menu::CreateItem(menu, mnIDPopupOpMaximum, wxT("Maximum "));
Menu::CreateItem(menu, mnIDPopupOpSum, wxT("Sum "));
return menu;
}

wxMenu* ApplWnd::createMenuFiles()
{
delete pMenuFile;
Expand Down
Loading

0 comments on commit 827a7f2

Please sign in to comment.