OpenASIP  2.0
SetCostFunctionPluginCmd.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file SetCostFunctionPluginCmd.cc
26  *
27  * Implementation of SetCostFunctionPluginCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
34 #include "WxConversion.hh"
35 #include "HDBEditorConstants.hh"
36 #include "HDBEditor.hh"
37 #include "HDBEditorMainFrame.hh"
38 #include "HDBManager.hh"
39 #include "HDBBrowserWindow.hh"
40 #include "Conversion.hh"
41 #include "CostFunctionPlugin.hh"
42 
43 using namespace HDB;
44 
45 /**
46  * The Constructor.
47  */
49  GUICommand(HDBEditorConstants::COMMAND_NAME_SET_COST_PLUGIN, NULL) {
50 }
51 
52 
53 /**
54  * The Destructor.
55  */
57 }
58 
59 /**
60  * Executes the command.
61  */
62 bool
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 }
134 
135 /**
136  * Returns name of the command icon file.
137  *
138  * @return Command icon file name.
139  */
140 std::string
142  return "";
143 
144 }
145 
146 
147 /**
148  * Returns the command id.
149  *
150  * @return Command identifier for this command.
151  */
152 int
155 }
156 
157 
158 /**
159  * Creates and returns a new instance of the command.
160  *
161  * @return Newly created instance of this command.
162  */
165  return new SetCostFunctionPluginCmd();
166 }
167 
168 /**
169  * Returns true if the command should be enabled in the menu/toolbar.
170  *
171  * @return True if the command is enabled, false if not.
172  */
173 bool
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 }
190 
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDBEditorConstants::COMMAND_SET_COST_PLUGIN
@ COMMAND_SET_COST_PLUGIN
Definition: HDBEditorConstants.hh:58
HDBBrowserWindow.hh
HDB
Definition: CostDatabase.hh:49
HDBBrowserWindow
Definition: HDBBrowserWindow.hh:59
HDBEditor.hh
HDB::HDBManager::costFunctionPluginIDs
std::set< RowID > costFunctionPluginIDs() const
Definition: HDBManager.cc:6553
HDBEditorConstants.hh
SetCostFunctionPluginCmd::Do
virtual bool Do()
Definition: SetCostFunctionPluginCmd.cc:63
HDB::HDBManager::costFunctionPluginByID
CostFunctionPlugin * costFunctionPluginByID(RowID pluginID) const
Definition: HDBManager.cc:6631
HDB::HDBManager::unsetCostFunctionPluginForFU
void unsetCostFunctionPluginForFU(RowID fuID) const
Definition: HDBManager.cc:1971
SetCostFunctionPluginCmd::isEnabled
virtual bool isEnabled()
Definition: SetCostFunctionPluginCmd.cc:174
HDBBrowserWindow::selectFUEntry
void selectFUEntry(int id)
Definition: HDBBrowserWindow.cc:649
GUICommand
Definition: GUICommand.hh:43
HDBBrowserWindow::isFUEntrySelected
bool isFUEntrySelected()
Definition: HDBBrowserWindow.cc:387
Conversion.hh
HDBEditorMainFrame.hh
HDB::HDBManager
Definition: HDBManager.hh:82
SetCostFunctionPluginCmd
Definition: SetCostFunctionPluginCmd.hh:41
HDB::HDBManager::setCostFunctionPluginForFU
void setCostFunctionPluginForFU(RowID fuID, RowID pluginID) const
Definition: HDBManager.cc:1950
SetCostFunctionPluginCmd::id
virtual int id() const
Definition: SetCostFunctionPluginCmd.cc:153
SetCostFunctionPluginCmd::SetCostFunctionPluginCmd
SetCostFunctionPluginCmd()
Definition: SetCostFunctionPluginCmd.cc:48
HDBEditorConstants
Definition: HDBEditorConstants.hh:42
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
SetCostFunctionPluginCmd::~SetCostFunctionPluginCmd
virtual ~SetCostFunctionPluginCmd()
Definition: SetCostFunctionPluginCmd.cc:56
CostFunctionPlugin.hh
WxConversion.hh
SetCostFunctionPluginCmd.hh
HDBManager.hh
SetCostFunctionPluginCmd::create
virtual SetCostFunctionPluginCmd * create() const
Definition: SetCostFunctionPluginCmd.cc:164
SetCostFunctionPluginCmd::icon
virtual std::string icon() const
Definition: SetCostFunctionPluginCmd.cc:141
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