OpenASIP  2.0
Public Member Functions | List of all members
SetCostFunctionPluginCmd Class Reference

#include <SetCostFunctionPluginCmd.hh>

Inheritance diagram for SetCostFunctionPluginCmd:
Inheritance graph
Collaboration diagram for SetCostFunctionPluginCmd:
Collaboration graph

Public Member Functions

 SetCostFunctionPluginCmd ()
 
virtual ~SetCostFunctionPluginCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual SetCostFunctionPluginCmdcreate () const
 
virtual std::string icon () const
 
virtual bool isEnabled ()
 
- Public Member Functions inherited from GUICommand
 GUICommand (std::string name, wxWindow *parent)
 
virtual ~GUICommand ()
 
virtual bool isChecked () const
 
virtual std::string shortName () const
 
void setParentWindow (wxWindow *view)
 
wxWindow * parentWindow () const
 
std::string name () const
 

Detailed Description

Command for setting cost function plugin for HDB entries.

Definition at line 41 of file SetCostFunctionPluginCmd.hh.

Constructor & Destructor Documentation

◆ SetCostFunctionPluginCmd()

SetCostFunctionPluginCmd::SetCostFunctionPluginCmd ( )

The Constructor.

Definition at line 48 of file SetCostFunctionPluginCmd.cc.

Referenced by create().

◆ ~SetCostFunctionPluginCmd()

SetCostFunctionPluginCmd::~SetCostFunctionPluginCmd ( )
virtual

The Destructor.

Definition at line 56 of file SetCostFunctionPluginCmd.cc.

56  {
57 }

Member Function Documentation

◆ create()

SetCostFunctionPluginCmd * SetCostFunctionPluginCmd::create ( ) const
virtual

Creates and returns a new instance of the command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 164 of file SetCostFunctionPluginCmd.cc.

164  {
165  return new SetCostFunctionPluginCmd();
166 }

References SetCostFunctionPluginCmd().

Here is the call graph for this function:

◆ Do()

bool SetCostFunctionPluginCmd::Do ( )
virtual

Executes the command.

Implements GUICommand.

Definition at line 63 of file SetCostFunctionPluginCmd.cc.

63  {
64 
65  HDBManager* manager = wxGetApp().mainFrame().hdbManager();
66 
67  if (manager == NULL) {
68  return false;
69  }
70 
71  HDBBrowserWindow& browser = *wxGetApp().mainFrame().browser();
72 
73  const std::set<RowID> pluginIDs = manager->costFunctionPluginIDs();
74  wxString plugins[100];
75 
76  std::map<int, RowID> rowIDs;
77  std::set<RowID>::iterator iter = pluginIDs.begin();
78  plugins[0] = _T("NONE");
79  int i = 1;
80 
81  // Append plugin names to an array for the choicer dialog.
82  for (;iter != pluginIDs.end(); iter++) {
83 
84  const CostFunctionPlugin* plugin =
85  manager->costFunctionPluginByID(*iter);
86 
87  plugins[i] = WxConversion::toWxString(plugin->name());
88  delete plugin;
89  plugin = NULL;
90 
91  rowIDs[i] = *iter;
92  i++;
93  }
94 
95  // Display single choice dialog of cost function plugins.
96  wxSingleChoiceDialog dialog(
97  parentWindow(), _T("Choose Cost Function Plugin"),
98  _T("Choose Cost Function Pluhin"),
99  i, plugins);
100 
101  if (dialog.ShowModal() != wxID_OK) {
102  return false;
103  }
104 
105  // Set the selected plugin as the entry plugin.
106  if (browser.isFUEntrySelected()) {
107  // FU entry.
108  int entryID = browser.selectedFUEntry();
109  if (dialog.GetSelection() > 0) {
111  entryID, rowIDs[dialog.GetSelection()]);
112  } else {
113  manager->unsetCostFunctionPluginForFU(entryID);
114  }
115  wxGetApp().mainFrame().update();
116  browser.selectFUEntry(entryID);
117  return true;
118  } else if (browser.isRFEntrySelected()) {
119  // RF entry.
120  int entryID = browser.selectedRFEntry();
121  if (dialog.GetSelection() > 0) {
123  entryID, rowIDs[dialog.GetSelection()]);
124  } else {
125  manager->unsetCostFunctionPluginForRF(entryID);
126  }
127  wxGetApp().mainFrame().update();
128  browser.selectRFEntry(entryID);
129  return true;
130  }
131 
132  return false;
133 }

References HDB::HDBManager::costFunctionPluginByID(), HDB::HDBManager::costFunctionPluginIDs(), HDBBrowserWindow::isFUEntrySelected(), HDBBrowserWindow::isRFEntrySelected(), HDB::CostFunctionPlugin::name(), GUICommand::parentWindow(), HDBBrowserWindow::selectedFUEntry(), HDBBrowserWindow::selectedRFEntry(), HDBBrowserWindow::selectFUEntry(), HDBBrowserWindow::selectRFEntry(), HDB::HDBManager::setCostFunctionPluginForFU(), HDB::HDBManager::setCostFunctionPluginForRF(), WxConversion::toWxString(), HDB::HDBManager::unsetCostFunctionPluginForFU(), and HDB::HDBManager::unsetCostFunctionPluginForRF().

Here is the call graph for this function:

◆ icon()

std::string SetCostFunctionPluginCmd::icon ( ) const
virtual

Returns name of the command icon file.

Returns
Command icon file name.

Implements GUICommand.

Definition at line 141 of file SetCostFunctionPluginCmd.cc.

141  {
142  return "";
143 
144 }

◆ id()

int SetCostFunctionPluginCmd::id ( ) const
virtual

Returns the command id.

Returns
Command identifier for this command.

Implements GUICommand.

Definition at line 153 of file SetCostFunctionPluginCmd.cc.

153  {
155 }

References HDBEditorConstants::COMMAND_SET_COST_PLUGIN.

◆ isEnabled()

bool SetCostFunctionPluginCmd::isEnabled ( )
virtual

Returns true if the command should be enabled in the menu/toolbar.

Returns
True if the command is enabled, false if not.

Implements GUICommand.

Definition at line 174 of file SetCostFunctionPluginCmd.cc.

174  {
175  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
176 
177  if (manager == NULL) {
178  return false;
179  }
180 
181  HDBBrowserWindow* browser = wxGetApp().mainFrame().browser();
182 
183  if (browser->isFUEntrySelected() ||
184  browser->isRFEntrySelected()) {
185 
186  return true;
187  }
188  return false;
189 }

References HDBBrowserWindow::isFUEntrySelected(), and HDBBrowserWindow::isRFEntrySelected().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDBEditorConstants::COMMAND_SET_COST_PLUGIN
@ COMMAND_SET_COST_PLUGIN
Definition: HDBEditorConstants.hh:58
HDBBrowserWindow
Definition: HDBBrowserWindow.hh:59
HDB::HDBManager::costFunctionPluginIDs
std::set< RowID > costFunctionPluginIDs() const
Definition: HDBManager.cc:6553
HDB::HDBManager::costFunctionPluginByID
CostFunctionPlugin * costFunctionPluginByID(RowID pluginID) const
Definition: HDBManager.cc:6631
HDB::HDBManager::unsetCostFunctionPluginForFU
void unsetCostFunctionPluginForFU(RowID fuID) const
Definition: HDBManager.cc:1971
HDBBrowserWindow::selectFUEntry
void selectFUEntry(int id)
Definition: HDBBrowserWindow.cc:649
HDBBrowserWindow::isFUEntrySelected
bool isFUEntrySelected()
Definition: HDBBrowserWindow.cc:387
HDB::HDBManager
Definition: HDBManager.hh:82
HDB::HDBManager::setCostFunctionPluginForFU
void setCostFunctionPluginForFU(RowID fuID, RowID pluginID) const
Definition: HDBManager.cc:1950
HDBEditorConstants::COMMAND_NAME_SET_COST_PLUGIN
static const std::string COMMAND_NAME_SET_COST_PLUGIN
Name of the set cost function plugin command.
Definition: HDBEditorConstants.hh:94
GUICommand::GUICommand
GUICommand(std::string name, wxWindow *parent)
Definition: GUICommand.cc:42
SetCostFunctionPluginCmd::SetCostFunctionPluginCmd
SetCostFunctionPluginCmd()
Definition: SetCostFunctionPluginCmd.cc:48
HDBBrowserWindow::selectRFEntry
void selectRFEntry(int id)
Definition: HDBBrowserWindow.cc:664
HDBBrowserWindow::selectedRFEntry
RowID selectedRFEntry()
Definition: HDBBrowserWindow.cc:549
HDB::HDBManager::unsetCostFunctionPluginForRF
void unsetCostFunctionPluginForRF(RowID rfID) const
Definition: HDBManager.cc:2014
HDB::CostFunctionPlugin::name
std::string name() const
Definition: CostFunctionPlugin.cc:84
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
HDB::CostFunctionPlugin
Definition: CostFunctionPlugin.hh:43
HDBBrowserWindow::selectedFUEntry
RowID selectedFUEntry()
Definition: HDBBrowserWindow.cc:533
HDBBrowserWindow::isRFEntrySelected
bool isRFEntrySelected()
Definition: HDBBrowserWindow.cc:397
HDB::HDBManager::setCostFunctionPluginForRF
void setCostFunctionPluginForRF(RowID rfID, RowID pluginID) const
Definition: HDBManager.cc:1993