OpenASIP  2.0
AddFUArchFromADFCmd.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 AddFUArchFromADFCmd.cc
26  *
27  * Implementation of AddFUArchFromADFCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "AddFUArchFromADFCmd.hh"
34 #include "WxConversion.hh"
35 
36 #include "HDBEditorConstants.hh"
37 #include "HDBEditor.hh"
38 #include "HDBEditorMainFrame.hh"
39 #include "HDBBrowserWindow.hh"
40 
41 #include "HDBManager.hh"
42 #include "ADFSerializer.hh"
43 #include "Machine.hh"
44 #include "ErrorDialog.hh"
45 #include "FUArchitecture.hh"
46 #include "FUArchitectureDialog.hh"
47 
48 #if wxCHECK_VERSION(3, 0, 0)
49  #define wxOPEN wxFD_OPEN
50 #endif
51 
52 /**
53  * The Constructor.
54  */
56  GUICommand(HDBEditorConstants::COMMAND_NAME_ADD_FU_FROM_ADF, NULL) {
57 }
58 
59 
60 /**
61  * The Destructor.
62  */
64 }
65 
66 /**
67  * Executes the command.
68  *
69  * @return True, if the command was succesfully executed.
70  */
71 bool
73  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
74 
75  if (manager == NULL) {
76  return false;
77  }
78 
79  wxString wildcard = _T("Architecture Definition Files (*.adf)|*.adf");
80  wildcard.Append(_T("|All files|*.*"));
81 
82  wxFileDialog dialog(
83  parentWindow(), _T("Choose a file."), _T(""), _T(""),
84  wildcard, wxOPEN);
85 
86  if (dialog.ShowModal() == wxID_CANCEL) {
87  return false;
88  }
89 
90  wxString fileName = dialog.GetPath();
91 
92  ADFSerializer reader;
93  reader.setSourceFile(WxConversion::toString(fileName));
95 
96  try {
97  machine = reader.readMachine();
98  } catch (Exception& e) {
99  wxString message = _T("Error opening ");
100  message.Append(fileName);
101  message.Append(_T(":\n\n"));
102  message.Append(WxConversion::toWxString(e.errorMessage()));
103  ErrorDialog dialog(parentWindow(), message);
104  dialog.ShowModal();
105  return false;
106  }
107 
110 
111  if (nav.count() == 0) {
112  wxString message = _T("The file ");
113  message.Append(fileName);
114  message.Append(_T(" doesn't contain any function units."));
115  ErrorDialog dialog(parentWindow(), message);
116  dialog.ShowModal();
117  delete machine;
118  return false;
119  }
120 
121  wxString fus[1000];
122 
123  for (int i = 0; i < nav.count(); i++) {
124  fus[i] = WxConversion::toWxString(nav.item(i)->name());
125  }
126 
127  wxSingleChoiceDialog choicer(
128  parentWindow(), _T("Choose Function Unit"), _T("Choose Function Unit"),
129  nav.count(), fus);
130 
131  if (choicer.ShowModal() != wxID_OK) {
132  delete machine;
133  return false;
134  }
135 
136 
137  TTAMachine::FunctionUnit* fu = nav.item(choicer.GetSelection());
138  fu->unsetMachine();
139  delete machine;
140 
141  HDB::FUArchitecture fuArch(fu);
142 
143  FUArchitectureDialog paramDialog(parentWindow(), -1 , fuArch);
144 
145  if (paramDialog.ShowModal() != wxID_OK) {
146  return false;
147  }
148 
149  int id = -1;
150  try {
151  id = manager->addFUArchitecture(fuArch);
152  } catch (Exception& e) {
153  wxString message = _T("Erroneous function unit architecture:\n\n");
154  message.Append(WxConversion::toWxString(e.errorMessage()));
155  ErrorDialog dialog(parentWindow(), message);
156  dialog.ShowModal();
157  return false;
158  }
159 
160  wxGetApp().mainFrame().update();
161  wxGetApp().mainFrame().browser()->selectFUArchitecture(id);
162 
163  return true;
164 }
165 
166 /**
167  * Returns name of the command icon file.
168  *
169  * @return Command icon file name.
170  */
171 std::string
173  return "";
174 }
175 
176 /**
177  * Returns the command id.
178  *
179  * @return Command identifier.
180  */
181 int
184 }
185 
186 
187 /**
188  * Creates a new instance of this command.
189  *
190  * @return Newly created instance of this command.
191  */
194  return new AddFUArchFromADFCmd();
195 }
196 
197 
198 /**
199  * Returns true if the command should be enabled in the menu/toolbar.
200  *
201  * @return True, if the command is enabled, false if not.
202  */
203 bool
205  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
206 
207  if (manager == NULL) {
208  return false;
209  }
210 
211  return true;
212 }
213 
AddFUArchFromADFCmd::~AddFUArchFromADFCmd
virtual ~AddFUArchFromADFCmd()
Definition: AddFUArchFromADFCmd.cc:63
HDB::FUArchitecture
Definition: FUArchitecture.hh:55
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDBBrowserWindow.hh
XMLSerializer::setSourceFile
void setSourceFile(const std::string &fileName)
Definition: XMLSerializer.cc:115
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
HDBEditor.hh
AddFUArchFromADFCmd.hh
FUArchitecture.hh
HDBEditorConstants.hh
HDB::HDBManager::addFUArchitecture
RowID addFUArchitecture(const FUArchitecture &architecture) const
Definition: HDBManager.cc:717
AddFUArchFromADFCmd
Definition: AddFUArchFromADFCmd.hh:41
TTAMachine::FunctionUnit::unsetMachine
virtual void unsetMachine()
Definition: FunctionUnit.cc:648
FUArchitectureDialog.hh
TTAMachine::Machine::Navigator::count
int count() const
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
AddFUArchFromADFCmd::AddFUArchFromADFCmd
AddFUArchFromADFCmd()
Definition: AddFUArchFromADFCmd.cc:55
AddFUArchFromADFCmd::isEnabled
virtual bool isEnabled()
Definition: AddFUArchFromADFCmd.cc:204
GUICommand
Definition: GUICommand.hh:43
ErrorDialog
Definition: ErrorDialog.hh:42
ErrorDialog.hh
HDBEditorMainFrame.hh
AddFUArchFromADFCmd::icon
virtual std::string icon() const
Definition: AddFUArchFromADFCmd.cc:172
ADFSerializer
Definition: ADFSerializer.hh:49
AddFUArchFromADFCmd::create
virtual AddFUArchFromADFCmd * create() const
Definition: AddFUArchFromADFCmd.cc:193
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
HDB::HDBManager
Definition: HDBManager.hh:82
Machine.hh
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
FUArchitectureDialog
Definition: FUArchitectureDialog.hh:46
AddFUArchFromADFCmd::id
virtual int id() const
Definition: AddFUArchFromADFCmd.cc:182
ADFSerializer.hh
HDBEditorConstants::COMMAND_ADD_FU_FROM_ADF
@ COMMAND_ADD_FU_FROM_ADF
Definition: HDBEditorConstants.hh:47
HDBEditorConstants
Definition: HDBEditorConstants.hh:42
ADFSerializer::readMachine
TTAMachine::Machine * readMachine()
Definition: ADFSerializer.cc:275
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
HDBManager.hh
WxConversion::toString
static std::string toString(const wxString &source)
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
TTAMachine::Machine
Definition: Machine.hh:73
AddFUArchFromADFCmd::Do
virtual bool Do()
Definition: AddFUArchFromADFCmd.cc:72