Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
ElementsToolBar.cpp
1#include "ElementsToolBar.h"
2#include "../MainFrame.h"
3#include "../utils/Path.h"
4#include <wx/sizer.h>
5#include <wx/bitmap.h>
6
7ElementsToolBar::ElementsToolBar(MainFrame* parent, bool vertical)
8 : wxFrame(parent, wxID_ANY, _("Power Elements"), wxDefaultPosition, wxDefaultSize,
9 wxCAPTION | wxCLOSE_BOX | wxFRAME_FLOAT_ON_PARENT | wxFRAME_TOOL_WINDOW | wxFRAME_NO_TASKBAR),
10 m_mainFrame(parent)
11{
12 InitToolBar(vertical);
13
14 Bind(wxEVT_CLOSE_WINDOW, &ElementsToolBar::OnClose, this);
15}
16
17ElementsToolBar::~ElementsToolBar()
18{
19}
20
21void ElementsToolBar::InitToolBar(bool vertical)
22{
23 m_toolBar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
24 (vertical ? wxTB_VERTICAL : wxTB_HORIZONTAL) | wxTB_FLAT | wxTB_NODIVIDER);
25 m_toolBar->SetToolBitmapSize(wxSize(32, 32));
26
27 wxString imgPath = Paths::GetDataPath() + "/images/elements/";
28
29 m_toolBar->AddTool(ID_ADDMENU_BUS, _("Bus"), wxBitmap(imgPath + "bus.png", wxBITMAP_TYPE_PNG), _("Add a bus at the circuit"));
30 m_toolBar->AddSeparator();
31
32 m_toolBar->AddTool(ID_ADDMENU_LINE, _("Line"), wxBitmap(imgPath + "line.png", wxBITMAP_TYPE_PNG), _("Add a power line at the circuit"));
33 m_toolBar->AddTool(ID_ADDMENU_TRANSFORMER, _("Transformer"), wxBitmap(imgPath + "transformer.png", wxBITMAP_TYPE_PNG), _("Add a transformer at the circuit"));
34
35
36 m_toolBar->AddTool(ID_ADDMENU_GENERATOR, _("Generator"), wxBitmap(imgPath + "generator.png", wxBITMAP_TYPE_PNG), _("Add a generator at the circuit"));
37 m_toolBar->AddTool(ID_ADDMENU_INDMOTOR, _("Induction motor"), wxBitmap(imgPath + "indmotor.png", wxBITMAP_TYPE_PNG), _("Add an induction motor at the circuit"));
38 m_toolBar->AddTool(ID_ADDMENU_SYNCCOMP, _("Synchronous compensator"), wxBitmap(imgPath + "synccomp.png", wxBITMAP_TYPE_PNG), _("Add a synchronous compensator at the circuit"));
39 m_toolBar->AddSeparator();
40
41 m_toolBar->AddTool(ID_ADDMENU_LOAD, _("Load"), wxBitmap(imgPath + "load.png", wxBITMAP_TYPE_PNG), _("Add a load at the circuit"));
42 m_toolBar->AddTool(ID_ADDMENU_CAPACITOR, _("Capacitor"), wxBitmap(imgPath + "capacitor.png", wxBITMAP_TYPE_PNG), _("Add a shunt capacitor at the circuit"));
43 m_toolBar->AddTool(ID_ADDMENU_INDUCTOR, _("Inductor"), wxBitmap(imgPath + "inductor.png", wxBITMAP_TYPE_PNG), _("Add a shunt inductor at the circuit"));
44 m_toolBar->AddSeparator();
45
46 m_toolBar->AddTool(ID_ADDMENU_HARMCURRENT, _("Harmonic current"), wxBitmap(imgPath + "harmcurrent.png", wxBITMAP_TYPE_PNG), _("Add a harmonic current source at the circuit"));
47 m_toolBar->AddTool(ID_ADDMENU_EMTELEMENT, _("EMT Element"), wxBitmap(imgPath + "emtelement.png", wxBITMAP_TYPE_PNG), _("Add an electromagnetic transient element"));
48 m_toolBar->AddSeparator();
49
50 m_toolBar->AddTool(ID_ADDMENU_TEXT, _("Label"), wxBitmap(imgPath + "text.png", wxBITMAP_TYPE_PNG), _("Add a linked element label"));
51
52 m_toolBar->Realize();
53
54 m_toolBar->Bind(wxEVT_TOOL, &ElementsToolBar::OnToolClicked, this);
55
56 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
57 sizer->Add(m_toolBar, 1, wxEXPAND);
58 SetSizerAndFit(sizer);
59}
60
61void ElementsToolBar::EnableTools(bool enable)
62{
63 if (!m_toolBar) return;
64 int ids[] = {
65 ID_ADDMENU_BUS, ID_ADDMENU_LINE, ID_ADDMENU_TRANSFORMER,
66 ID_ADDMENU_GENERATOR, ID_ADDMENU_INDMOTOR, ID_ADDMENU_SYNCCOMP,
67 ID_ADDMENU_LOAD, ID_ADDMENU_CAPACITOR, ID_ADDMENU_INDUCTOR,
68 ID_ADDMENU_HARMCURRENT, ID_ADDMENU_EMTELEMENT, ID_ADDMENU_TEXT
69 };
70 for (int id : ids) {
71 m_toolBar->EnableTool(id, enable);
72 }
73}
74
75void ElementsToolBar::OnToolClicked(wxCommandEvent& event)
76{
77 if (m_mainFrame) {
78 m_mainFrame->OnAddElementsClick(event);
79 }
80}
81
82void ElementsToolBar::OnClose(wxCloseEvent& event)
83{
84 Hide();
85 if (m_mainFrame) {
86 m_mainFrame->OnElementsToolBarClosed();
87 }
88}
Main frame of the program. This class manage the ribbon menu and the notebook behavior.
Definition MainFrame.h:71