OpenASIP 2.2
Loading...
Searching...
No Matches
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"
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
54using boost::format;
55using std::string;
56using namespace TTAMachine;
57
58BEGIN_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 */
110
111
112/**
113 * Sets texts for widgets.
114 */
115void
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 */
153bool
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.
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 =
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.
183 slotChoice_->Disable();
184 }
185
186 // Set destination choicer.
187 destinationChoice_->Clear();
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 */
219void
220TemplateSlotDialog::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 =
233
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 */
263wxSizer*
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}
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
const int DEFAULT_WIDTH
Default window width.
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
static ProDeTextGenerator * instance()
@ TXT_LABEL_WIDTH
Label for bit width widget.
@ TXT_LABEL_DESTINATION
Label for destination widget.
@ TXT_TEMPLATE_SLOT_DIALOG_TITLE
Template Slot dialog title.
@ TXT_LABEL_SLOT
Label for slot widget.
virtual Machine * machine() const
virtual TCEString name() const
virtual bool usesSlot(const std::string &slotName) const
virtual void addSlot(const std::string &slotName, int width, ImmediateUnit &dstUnit)
virtual void removeSlot(const std::string &slotName)
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition Machine.cc:462
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
std::string slot() const
ImmediateUnit * destination() const
TTAMachine::ImmediateUnit * destination_
Destination immediate unit.
wxChoice * destinationChoice_
Choice control fot the destination IU.
TTAMachine::TemplateSlot * slot_
Instruction template slot to edit.
virtual bool TransferDataToWindow()
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxSpinCtrl * widthCtrl_
Spin control for the width.
int width_
Bit width of the slot.
wxChoice * slotChoice_
Choice control for the slot.
TTAMachine::InstructionTemplate * it_
Parent instruction template of the slot.
void onOK(wxCommandEvent &event)
virtual boost::format text(int textId)
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)