OpenASIP  2.0
TemplateSlotDialog.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 TemplateSlotDialog.cc
26  *
27  * Implementation of TemplateSlotDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/wx.h>
34 #include <wx/spinctrl.h>
35 #include <wx/statline.h>
36 #include <wx/valgen.h>
37 #include <boost/format.hpp>
38 
39 #include "TemplateSlotDialog.hh"
40 #include "Machine.hh"
41 #include "InstructionTemplate.hh"
42 #include "WxConversion.hh"
43 #include "AssocTools.hh"
44 #include "WidgetTools.hh"
45 #include "InformationDialog.hh"
46 #include "ModelConstants.hh"
47 #include "WidgetTools.hh"
48 #include "GUITextGenerator.hh"
49 #include "ProDeTextGenerator.hh"
50 #include "Application.hh"
51 #include "ImmediateSlot.hh"
52 #include "TemplateSlot.hh"
53 
54 using boost::format;
55 using std::string;
56 using namespace TTAMachine;
57 
58 BEGIN_EVENT_TABLE(TemplateSlotDialog, wxDialog)
61 
62 /**
63  * The Constructor.
64  *
65  * @param parent Parent window of the dialog.
66  * @param temp InstructionTemplate to edit.
67  * @param slot Slot to edit, NULL if a new slot is being added.
68  */
70  wxWindow* parent,
72  TemplateSlot* slot) :
73  wxDialog(parent, -1, _T(""), wxDefaultPosition),
74  slot_(slot),
75  it_(it),
77  destination_(NULL) {
78 
79  createContents(this, true, true);
80 
81  slotChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_SLOT));
82  destinationChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_DESTINATION));
83  widthCtrl_ = dynamic_cast<wxSpinCtrl*>(FindWindow(ID_WIDTH));
84 
85  widthCtrl_->SetValidator(wxGenericValidator(&width_));
86 
87  // Read slot attributes.
88  if (slot_ != NULL) {
89  width_ = it_->supportedWidth(slot_->slot());
91  it_->machine()->immediateUnitNavigator();
92  for (int i = 0; i < navigator.count(); i++) {
93  if (it_->destinationUsesSlot(
94  slot_->slot(), *navigator.item(i))) {
95  destination_ = navigator.item(i);
96  }
97  }
98  }
99 
100  // set widget texts
101  setTexts();
102 }
103 
104 
105 /**
106  * The Destructor.
107  */
109 }
110 
111 
112 /**
113  * Sets texts for widgets.
114  */
115 void
119 
120  // Dialog title
121  format fmt = prodeTexts->text(
123  SetTitle(WxConversion::toWxString(fmt.str()));
124 
125  // buttons
126  WidgetTools::setLabel(generator, FindWindow(wxID_OK),
128 
129  WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
131 
132  WidgetTools::setLabel(generator, FindWindow(ID_HELP),
134 
135 
136  // widget labels
137  WidgetTools::setLabel(prodeTexts, FindWindow(ID_LABEL_SLOT),
139 
140  WidgetTools::setLabel(prodeTexts, FindWindow(ID_LABEL_DESTINATION),
142 
143  WidgetTools::setLabel(prodeTexts, FindWindow(ID_LABEL_WIDTH),
145 }
146 
147 
148 /**
149  * Transfers data from the InstructionTemplate object to the dialog widgets.
150  *
151  * @return true, if the transfer was succesful, false otherwise.
152  */
153 bool
155 
156  // Set slot choicer.
157  slotChoice_->Clear();
158 
159  if (slot_ == NULL) {
160  // A new slot is being added, set all available busses to the
161  // slot choice.
162  Machine::BusNavigator navigator = it_->machine()->busNavigator();
163  for (int i = 0; i < navigator.count(); i++) {
164  if (!(it_->usesSlot(navigator.item(i)->name()))) {
165  wxString name =
166  WxConversion::toWxString(navigator.item(i)->name());
167  slotChoice_->Append(name);
168  }
169  }
170  // Add immediate slots.
171  Machine::ImmediateSlotNavigator immSlotNavigator =
172  it_->machine()->immediateSlotNavigator();
173  for (int i = 0; i < immSlotNavigator.count(); i++) {
174  if (!(it_->usesSlot(immSlotNavigator.item(i)->name()))) {
175  wxString name =
176  WxConversion::toWxString(immSlotNavigator.item(i)->name());
177  slotChoice_->Append(name);
178  }
179  }
180  } else {
181  // An old slot is being modified, set the slot and disable the control.
182  slotChoice_->Append(WxConversion::toWxString(slot_->slot()));
183  slotChoice_->Disable();
184  }
185 
186  // Set destination choicer.
187  destinationChoice_->Clear();
189  it_->machine()->immediateUnitNavigator();
190  for (int i = 0; i < navigator.count(); i++) {
191  wxString name =
192  WxConversion::toWxString(navigator.item(i)->name());
193  destinationChoice_->Append(name);
194  }
195  // Set selections for editing slot
196  if(slot_ != NULL) {
197  wxString name = WxConversion::toWxString(slot_->destination()->name());
198  assert(!name.empty());
199  destinationChoice_->SetSelection(destinationChoice_->FindString(name));
200  widthCtrl_->SetValue(slot_->width());
201  }
202 
203 
204  // Set choicer selections.
205  slotChoice_->SetSelection(0);
206  if (destination_ == NULL) {
207  destinationChoice_->SetSelection(0);
208  } else {
209  wxString name = WxConversion::toWxString(destination_->name());
210  destinationChoice_->SetStringSelection(name);
211  }
212  return wxDialog::TransferDataToWindow();
213 }
214 
215 
216 /**
217  * Creates a new tempalte slot based on the dialog widget values.
218  */
219 void
220 TemplateSlotDialog::onOK(wxCommandEvent&) {
221 
222  string slotName = WxConversion::toString(slotChoice_->GetStringSelection());
223 
224  // Commit edit as new slot. Delete old slot.
225  if (slot_ != NULL) {
226  it_->removeSlot(slotName);
227  }
228  TransferDataFromWindow();
229 
230  const Machine::BusNavigator busNavigator = it_->machine()->busNavigator();
231  const Machine::ImmediateSlotNavigator immsNavigator =
232  it_->machine()->immediateSlotNavigator();
233 
234  destination_ = it_->machine()->immediateUnitNavigator().item(
235  WxConversion::toString(destinationChoice_->GetStringSelection()));
236 
237  if (busNavigator.hasItem(slotName)) {
238  Bus* slot = it_->machine()->busNavigator().item(slotName);
239  // create the new slot
240  it_->addSlot(slot->name(), width_, *destination_);
241  } else if (immsNavigator.hasItem(slotName)) {
242  ImmediateSlot* slot = immsNavigator.item(slotName);
243  // create the new slot
244  it_->addSlot(slot->name(), width_, *destination_);
245  } else {
246  assert(false);
247  }
248 
249  EndModal(wxID_OK);
250 }
251 
252 
253 /**
254  * Creates the dialog window contents.
255  *
256  * This method was generated with wxDesigner.
257  *
258  * @return Main sizer of the created contents.
259  * @param parent The dialog window.
260  * @param call_fit If true, fits the contents inside the dialog.
261  * @param set_sizer If true, sets the main sizer as dialog contents.
262  */
263 wxSizer*
265  wxWindow *parent, bool call_fit, bool set_sizer) {
266 
267  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
268 
269  wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
270 
271  wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_SLOT, wxT("Slot:"), wxDefaultPosition, wxDefaultSize, 0 );
272  item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
273 
274  wxString *strs3 = (wxString*) NULL;
275  wxChoice *item3 = new wxChoice( parent, ID_SLOT, wxDefaultPosition, wxSize(150,-1), 0, strs3, 0 );
276  item1->Add( item3, 0, wxGROW|wxALL, 5 );
277 
278  wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_DESTINATION, wxT("Destination:"), wxDefaultPosition, wxDefaultSize, 0 );
279  item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
280 
281  wxString *strs5 = (wxString*) NULL;
282  wxChoice *item5 = new wxChoice( parent, ID_DESTINATION, wxDefaultPosition, wxSize(100,-1), 0, strs5, 0 );
283  item1->Add( item5, 0, wxGROW|wxALL, 5 );
284 
285  wxStaticText *item6 = new wxStaticText( parent, ID_LABEL_WIDTH, wxT("Width:"), wxDefaultPosition, wxDefaultSize, 0 );
286  item1->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
287 
288  wxSpinCtrl *item7 = new wxSpinCtrl( parent, ID_WIDTH, wxT("1"), wxDefaultPosition, wxSize(-1,-1), 0, 1, 10000, 1 );
289  item1->Add( item7, 0, wxALL, 5 );
290 
291  item0->Add( item1, 0, wxGROW|wxALL, 5 );
292 
293  wxStaticLine *item8 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
294  item0->Add( item8, 0, wxGROW|wxALL, 5 );
295 
296  wxFlexGridSizer *item9 = new wxFlexGridSizer( 2, 0, 0 );
297 
298  wxButton *item10 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
299  item9->Add( item10, 0, wxALL, 5 );
300 
301  wxBoxSizer *item11 = new wxBoxSizer( wxHORIZONTAL );
302 
303  wxButton *item12 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
304  item11->Add( item12, 0, wxALIGN_CENTER|wxALL, 5 );
305 
306  wxButton *item13 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
307  item11->Add( item13, 0, wxALIGN_CENTER|wxALL, 5 );
308 
309  item9->Add( item11, 0, 0, 5 );
310 
311  item0->Add( item9, 0, wxGROW|wxALL, 5 );
312 
313  if (set_sizer)
314  {
315  parent->SetSizer( item0 );
316  if (call_fit)
317  item0->SetSizeHints( parent );
318  }
319 
320  return item0;
321 }
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TemplateSlotDialog.hh
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
DEFAULT_WIDTH
const int DEFAULT_WIDTH
Default window width.
Definition: GUIOptionsSerializer.cc:98
WidgetTools::setLabel
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
Definition: WidgetTools.cc:92
TTAMachine::Bus
Definition: Bus.hh:53
GUITextGenerator::instance
static GUITextGenerator * instance()
Definition: GUITextGenerator.cc:67
TemplateSlotDialog::~TemplateSlotDialog
virtual ~TemplateSlotDialog()
Definition: TemplateSlotDialog.cc:108
GUITextGenerator
Definition: GUITextGenerator.hh:46
GUITextGenerator::TXT_BUTTON_HELP
@ TXT_BUTTON_HELP
Label for help button.
Definition: GUITextGenerator.hh:60
ModelConstants
Definition: ModelConstants.hh:40
ProDeTextGenerator::TXT_LABEL_SLOT
@ TXT_LABEL_SLOT
Label for slot widget.
Definition: ProDeTextGenerator.hh:71
WidgetTools.hh
FindWindow
Definition: FindWindow.hh:49
TTAMachine::Machine::Navigator::count
int count() const
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ProDeTextGenerator.hh
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
TemplateSlotDialog::setTexts
void setTexts()
Definition: TemplateSlotDialog.cc:116
ProDeTextGenerator::TXT_LABEL_DESTINATION
@ TXT_LABEL_DESTINATION
Label for destination widget.
Definition: ProDeTextGenerator.hh:73
TTAMachine::InstructionTemplate
Definition: InstructionTemplate.hh:49
assert
#define assert(condition)
Definition: Application.hh:86
TemplateSlot.hh
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
ProDeTextGenerator::TXT_TEMPLATE_SLOT_DIALOG_TITLE
@ TXT_TEMPLATE_SLOT_DIALOG_TITLE
Template Slot dialog title.
Definition: ProDeTextGenerator.hh:167
InstructionTemplate.hh
ImmediateSlot.hh
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
InformationDialog.hh
TTAMachine::TemplateSlot
Definition: TemplateSlot.hh:55
Application.hh
TemplateSlotDialog
Definition: TemplateSlotDialog.hh:49
ModelConstants.hh
Machine.hh
TemplateSlotDialog::onOK
void onOK(wxCommandEvent &event)
Definition: TemplateSlotDialog.cc:220
GUITextGenerator.hh
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
TemplateSlotDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: TemplateSlotDialog.cc:264
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
TTAMachine::Component::machine
virtual Machine * machine() const
AssocTools.hh
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TemplateSlotDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: TemplateSlotDialog.cc:154
TTAMachine
Definition: Assembler.hh:48
ProDeTextGenerator::TXT_LABEL_WIDTH
@ TXT_LABEL_WIDTH
Label for bit width widget.
Definition: ProDeTextGenerator.hh:57
WxConversion::toString
static std::string toString(const wxString &source)
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
TTAMachine::ImmediateSlot
Definition: ImmediateSlot.hh:44
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59