OpenASIP 2.2
Loading...
Searching...
No Matches
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
43using namespace HDB;
44
45/**
46 * The Constructor.
47 */
51
52
53/**
54 * The Destructor.
55 */
58
59/**
60 * Executes the command.
61 */
62bool
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 */
140std::string
142 return "";
143
144}
145
146
147/**
148 * Returns the command id.
149 *
150 * @return Command identifier for this command.
151 */
152int
156
157
158/**
159 * Creates and returns a new instance of the command.
160 *
161 * @return Newly created instance of this command.
162 */
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 */
173bool
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
wxWindow * parentWindow() const
Definition GUICommand.cc:75
void selectRFEntry(int id)
void selectFUEntry(int id)
CostFunctionPlugin * costFunctionPluginByID(RowID pluginID) const
void setCostFunctionPluginForFU(RowID fuID, RowID pluginID) const
void unsetCostFunctionPluginForFU(RowID fuID) const
void setCostFunctionPluginForRF(RowID rfID, RowID pluginID) const
void unsetCostFunctionPluginForRF(RowID rfID) const
std::set< RowID > costFunctionPluginIDs() const
virtual std::string icon() const
virtual SetCostFunctionPluginCmd * create() const
static wxString toWxString(const std::string &source)