Debian Codegraph @

plugins/dm.objectives/ce/specpanel/EntityNameSpecifierPanel.cpp

raw
1 #include "EntityNameSpecifierPanel.h"
2
3 #include <wx/sizer.h>
4 #include "inode.h"
5 #include "imap.h"
6 #include "ientity.h"
7
8 namespace objectives
9 {
10
11 namespace ce
12 {
13
14 EntityNameSpecifierPanel::EntityNameSpecifierPanel() :
15 _editCombo(nullptr)
16 {}
17
18 EntityNameSpecifierPanel::EntityNameSpecifierPanel(wxWindow* parent) :
19 _editCombo(nullptr)
20 {
21 _editCombo = new wxComboBox(parent, wxID_ANY);
22
23 // Bind both events to the same callback
24 _editCombo->Bind(wxEVT_TEXT, &EntityNameSpecifierPanel::onComboBoxChanged, this);
25 _editCombo->Bind(wxEVT_COMBOBOX, &EntityNameSpecifierPanel::onComboBoxChanged, this);
26
27 // Collect all entity names in the scene
28 wxArrayString names;
29 GlobalMapModule().getRoot()->foreachNode([&](const scene::INodePtr& node)
30 {
31 if (Node_isEntity(node))
32 {
33 names.push_back(Node_getEntity(node)->getKeyValue("name"));
34 }
35
36 return true;
37 });
38
39 names.Sort();
40 _editCombo->Append(names);
41 }
42
43 EntityNameSpecifierPanel::~EntityNameSpecifierPanel()
44 {
45 delete _editCombo;
46 _editCombo = nullptr;
47 }
48
49 wxWindow* EntityNameSpecifierPanel::getWidget()
50 {
51 return _editCombo;
52 }
53
54 void EntityNameSpecifierPanel::setValue(const std::string& value)
55 {
56 _editCombo->SetValue(value);
57 }
58
59 std::string EntityNameSpecifierPanel::getValue() const
60 {
61 return _editCombo->GetValue().ToStdString();
62 }
63
64 void EntityNameSpecifierPanel::onComboBoxChanged(wxCommandEvent& ev)
65 {
66 if (_valueChanged)
67 {
68 _valueChanged(); // usually points to the abstract ComponentEditor::writeToComponent
69 }
70 }
71
72 // Reg helper
73 EntityNameSpecifierPanel::RegHelper EntityNameSpecifierPanel::_regHelper;
74
75 }
76
77 }
78