OpenASIP  2.0
SetFUArchitectureCmd.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 SetFUArchitectureCmd.cc
26  *
27  * Implementation of SetFUArchitectureCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "SetFUArchitectureCmd.hh"
34 #include "WxConversion.hh"
35 #include "HDBEditorConstants.hh"
36 #include "HDBEditor.hh"
37 #include "HDBEditorMainFrame.hh"
38 #include "HDBManager.hh"
39 #include "FUEntry.hh"
40 #include "HDBBrowserWindow.hh"
41 #include "Conversion.hh"
42 
43 using namespace HDB;
44 
45 /**
46  * The Constructor.
47  */
49  GUICommand(HDBEditorConstants::COMMAND_NAME_SET_FU_ARCH, NULL) {
50 }
51 
52 
53 /**
54  * The Destructor.
55  */
57 }
58 
59 /**
60  * Executes the command.
61  */
62 bool
64  HDBManager* manager = wxGetApp().mainFrame().hdbManager();
65 
66  if (manager == NULL) {
67  return false;
68  }
69 
70  const FUEntry* entry = manager->fuByID(
71  wxGetApp().mainFrame().browser()->selectedFUEntry());
72 
73  wxString fus[1000];
74  const std::set<RowID> fuIDs = manager->fuArchitectureIDs();
75  std::set<RowID>::iterator iter = fuIDs.begin();
76  int i = 0;
77  for (;iter != fuIDs.end(); iter++) {
78  fus[i] = WxConversion::toWxString(*iter);
79  i++;
80  }
81 
82  wxSingleChoiceDialog choicer(
83  parentWindow(), _T("Choose Architecture"), _T("Choose Architecture"),
84  i, fus);
85 
86  if (choicer.ShowModal() != wxID_OK) {
87  return false;
88  }
89 
90 
91  std::string archID = WxConversion::toString(choicer.GetStringSelection());
92  RowID rowID = Conversion::toInt(archID);
93  manager->unsetArchitectureForFU(entry->id());
94  manager->setArchitectureForFU(entry->id(), rowID);
95 
96  wxGetApp().mainFrame().update();
97  wxGetApp().mainFrame().browser()->selectFUEntry(entry->id());
98 
99  return true;
100 }
101 
102 /**
103  * Returns name of the command icon file.
104  *
105  * @return Command icon file name.
106  */
107 std::string
109  return "";
110 
111 }
112 
113 
114 /**
115  * Returns the command id.
116  *
117  * @return Command identifier for this command.
118  */
119 int
122 }
123 
124 
125 /**
126  * Creates and returns a new instance of the command.
127  *
128  * @return Newly created instance of this command.
129  */
132  return new SetFUArchitectureCmd();
133 }
134 
135 /**
136  * Returns true if the command should be enabled in the menu/toolbar.
137  *
138  * @return True if the command is enabled, false if not.
139  */
140 bool
142  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
143 
144  if (manager == NULL) {
145  return false;
146  }
147 
148  HDBBrowserWindow* browser = wxGetApp().mainFrame().browser();
149 
150  if (!browser->isFUEntrySelected() ||
151  manager->fuByID(browser->selectedFUEntry())->hasArchitecture()) {
152 
153  return false;
154  }
155  return true;
156 }
157 
SetFUArchitectureCmd.hh
HDB::FUEntry
Definition: FUEntry.hh:49
SetFUArchitectureCmd::~SetFUArchitectureCmd
virtual ~SetFUArchitectureCmd()
Definition: SetFUArchitectureCmd.cc:56
SetFUArchitectureCmd::icon
virtual std::string icon() const
Definition: SetFUArchitectureCmd.cc:108
WxConversion::toWxString
static wxString toWxString(const std::string &source)
SetFUArchitectureCmd::isEnabled
virtual bool isEnabled()
Definition: SetFUArchitectureCmd.cc:141
HDBBrowserWindow.hh
HDB
Definition: CostDatabase.hh:49
HDBBrowserWindow
Definition: HDBBrowserWindow.hh:59
HDBEditor.hh
HDB::HDBEntry::id
RowID id() const
Definition: HDBEntry.cc:85
HDBEditorConstants.hh
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
GUICommand
Definition: GUICommand.hh:43
HDB::HDBManager::fuArchitectureIDs
std::set< RowID > fuArchitectureIDs() const
Definition: HDBManager.cc:2163
HDBBrowserWindow::isFUEntrySelected
bool isFUEntrySelected()
Definition: HDBBrowserWindow.cc:387
Conversion.hh
HDBEditorMainFrame.hh
FUEntry.hh
HDB::HDBManager
Definition: HDBManager.hh:82
SetFUArchitectureCmd
Definition: SetFUArchitectureCmd.hh:41
SetFUArchitectureCmd::id
virtual int id() const
Definition: SetFUArchitectureCmd.cc:120
HDBEditorConstants::COMMAND_SET_FU_ARCH
@ COMMAND_SET_FU_ARCH
Definition: HDBEditorConstants.hh:49
HDBEditorConstants
Definition: HDBEditorConstants.hh:42
WxConversion.hh
Conversion::toInt
static int toInt(const T &source)
SetFUArchitectureCmd::SetFUArchitectureCmd
SetFUArchitectureCmd()
Definition: SetFUArchitectureCmd.cc:48
HDBManager.hh
WxConversion::toString
static std::string toString(const wxString &source)
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
HDB::HDBManager::unsetArchitectureForFU
void unsetArchitectureForFU(RowID fuID) const
Definition: HDBManager.cc:1432
HDBBrowserWindow::selectedFUEntry
RowID selectedFUEntry()
Definition: HDBBrowserWindow.cc:533
SetFUArchitectureCmd::Do
virtual bool Do()
Definition: SetFUArchitectureCmd.cc:63
SetFUArchitectureCmd::create
virtual SetFUArchitectureCmd * create() const
Definition: SetFUArchitectureCmd.cc:131
HDB::HDBManager::setArchitectureForFU
void setArchitectureForFU(RowID fuID, RowID archID) const
Definition: HDBManager.cc:1401