OpenASIP 2.2
Loading...
Searching...
No Matches
BridgeDialog.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 BridgeDialog.cc
26 *
27 * Definition of BridgeDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include <boost/format.hpp>
35
36#include "BridgeDialog.hh"
37#include "ProDeConstants.hh"
38#include "WxConversion.hh"
39#include "ModelConstants.hh"
40#include "Conversion.hh"
41#include "WarningDialog.hh"
42#include "ErrorDialog.hh"
43#include "InformationDialog.hh"
44#include "Machine.hh"
45#include "Bridge.hh"
46#include "Bus.hh"
47#include "UserManualCmd.hh"
48#include "MachineTester.hh"
49#include "ProDeTextGenerator.hh"
50#include "MDFView.hh"
51#include "ProDe.hh"
52#include "MachineCanvasTool.hh"
53#include "WidgetTools.hh"
54#include "GUITextGenerator.hh"
55#include "MachineCanvas.hh"
56
57using std::string;
58using boost::format;
59using namespace TTAMachine;
60
61BEGIN_EVENT_TABLE(BridgeDialog, wxDialog)
62 EVT_TEXT(ID_NAME, BridgeDialog::onName)
63 EVT_TEXT(ID_OPPOSITE_BRIDGE, BridgeDialog::onName)
66 EVT_CHOICE(ID_INPUT_BUS, BridgeDialog::onInputBus)
67 EVT_CHOICE(ID_OUTPUT_BUS, BridgeDialog::onOutputBus)
68 EVT_CHECKBOX(ID_BIDIRECTIONAL, BridgeDialog::onBidirectional)
69
71
72/**
73 * The Constructor.
74 *
75 * @param parent Parent window of the dialog.
76 * @param bridge Bridge to be modified with the dialog.
77 * @param opposite Bridge to be modified having the opposite direction
78 * compared to bridge.
79 */
81 wxWindow* parent,
82 Bridge* bridge,
83 Bridge* opposite):
84 wxDialog(parent, -1, _T(""), wxDefaultPosition),
85 name_(_T("")),
86 oppositeName_(_T("")),
87 oppositeNameCtrl_(NULL),
88 inputBusChoice_(NULL),
89 outputBusChoice_(NULL),
90 bidirectionalBox_(NULL) {
91
92 assert(bridge != NULL);
93
94 // The canvas tool has to disabled.
95 MDFView* view =
96 dynamic_cast<MDFView*>(wxGetApp().docManager()->GetCurrentView());
97 view->canvas()->tool()->deactivate();
98
99
100 // initialize the dialog
101 createContents(this, true, true);
102 FindWindow(wxID_OK)->Disable();
103
104 wxTextCtrl* nameCtrl = dynamic_cast<wxTextCtrl*>(FindWindow(ID_NAME));
105 assert(nameCtrl != 0);
106 nameCtrl->SetValidator(wxTextValidator(wxFILTER_ASCII, &name_));
107
108 oppositeNameCtrl_ =
109 dynamic_cast<wxTextCtrl*>(FindWindow(ID_OPPOSITE_BRIDGE));
110 assert(oppositeNameCtrl_ != 0);
111 oppositeNameCtrl_->SetValidator(wxTextValidator(wxFILTER_ASCII,
112 &oppositeName_));
113
114 inputBusChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_INPUT_BUS));
115 assert(inputBusChoice_ != NULL);
116 outputBusChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_OUTPUT_BUS));
117 assert(outputBusChoice_ != NULL);
118
119 bidirectionalBox_ =
120 dynamic_cast<wxCheckBox*>(FindWindow(ID_BIDIRECTIONAL));
121 assert(bidirectionalBox_ != NULL);
122
123
124 // Machine tester is used to check legality of the bridge modifications.
125 // The modified bridge has to be deleted. Otherwise it will conflict
126 // with the modification legality checks.
127
128 // save bridge information and delete the bridges
129 machine_ = bridge->machine();
130 inputBus_ = WxConversion::toWxString(bridge->sourceBus()->name());
131 outputBus_ = WxConversion::toWxString(bridge->destinationBus()->name());
132 name_ = WxConversion::toWxString(bridge->name());
133 if (opposite != NULL) {
134 bidirectional_ = true;
135 oppositeName_ = WxConversion::toWxString(opposite->name());
136 assert(opposite->sourceBus() == bridge->destinationBus());
137 assert(opposite->destinationBus() == bridge->sourceBus());
138 delete opposite;
139 } else {
140 bidirectional_ = false;
141 }
142 delete bridge;
143
144 // set widget texts
145 setTexts();
146
147 TransferDataToWindow();
148}
149
150
151/**
152 * The Destructor.
153 */
156
157
158/**
159 * Sets texts for widgets.
160 */
161void
195
196
197/**
198 * Transfers data from the bridge object(s) to the dialog widgets.
199 *
200 * @return False, if an error occured in the transfer, true otherwise.
201 */
202bool
204
206 if (bidirectional_) {
207 oppositeNameCtrl_->Enable();
208 } else {
209 oppositeNameCtrl_->Disable();
210 }
211
213
214 bool transferResult = wxWindow::TransferDataToWindow();
215
216 // Force update of the OK-button enabled/disabled state.
217 wxCommandEvent dummy;
218 onName(dummy);
219
220 return transferResult;
221}
222
223
224/**
225 * Updates the bus choicers.
226 */
227void
229
231 MachineTester tester(*machine_);
232 Bus* source = navigator.item(WxConversion::toString(inputBus_));
233
234 // Add input buses which can be bridged.
235 inputBusChoice_->Clear();
236 for (int i = 0;i < navigator.count(); i++) {
237 wxString busName = WxConversion::toWxString(navigator.item(i)->name());
238 for (int j = 0;j < navigator.count(); j++) {
239 if (tester.canBridge(*navigator.item(i), *navigator.item(j))) {
240 inputBusChoice_->Append(busName);
241 break;
242 }
243 }
244 }
245 inputBusChoice_->SetStringSelection(inputBus_);
246
247 // Add outputbuses which are legal for the current input bus.
248 outputBusChoice_->Clear();
249 for (int i = 0;i < navigator.count(); i++) {
250 wxString busName = WxConversion::toWxString(navigator.item(i)->name());
251 if (tester.canBridge(*source, *navigator.item(i))) {
252 outputBusChoice_->Append(busName);
253 }
254 }
255 outputBusChoice_->SetStringSelection(outputBus_);
256}
257
258
259/**
260 * Validates input in the controls, and updates the Bridge object.
261 */
262void
263BridgeDialog::onOK(wxCommandEvent&) {
264
265 if (!Validate()) {
266 return;
267 }
268
269 if (!TransferDataFromWindow()) {
270 return;
271 }
272
273 string trimmedName = WxConversion::toString(name_.Trim(false).Trim(true));
274 string trimmedOppName =
275 WxConversion::toString(oppositeName_.Trim(false).Trim(true));
276
277 // Check the name validity.
278 if (!MachineTester::isValidComponentName(trimmedName) ||
280 !MachineTester::isValidComponentName(trimmedOppName))) {
281
283 format message =
285 InformationDialog warning(
286 this, WxConversion::toWxString(message.str()));
287 warning.ShowModal();
288 return;
289 }
290
291 // Check that the opposing bridge names aren't same.
292 if (bidirectional_ && trimmedName == trimmedOppName) {
294 format message =
296 WarningDialog warning(this, WxConversion::toWxString(message.str()));
297 warning.ShowModal();
298 return;
299 }
300
302
303 // Check that the opposite bridge name is not reserved.
304 if (bidirectional_ && navigator.hasItem(trimmedOppName)) {
305 ProDeTextGenerator* generator =
307 format message =
309 string component =
310 generator->text(ProDeTextGenerator::COMP_A_BRIDGE).str();
311 message % trimmedOppName % component;
312 WarningDialog warning(this, WxConversion::toWxString(message.str()));
313 warning.ShowModal();
314 return;
315 }
316 // Check that the bridge name is not reserved.
317 if (navigator.hasItem(trimmedName)) {
318 ProDeTextGenerator* generator =
320 format message =
322 string acomponent =
323 generator->text(ProDeTextGenerator::COMP_A_BRIDGE).str();
324 string machine =
325 generator->text(ProDeTextGenerator::COMP_MACHINE).str();
326 string component =
327 generator->text(ProDeTextGenerator::COMP_BRIDGE).str();
328
329 message % trimmedName % acomponent % machine % component;
330 WarningDialog warning(this, WxConversion::toWxString(message.str()));
331 warning.ShowModal();
332 return;
333 }
334
336 MachineTester tester(*machine_);
337 Bus* source = busNavigator.item(WxConversion::toString(inputBus_));
338 Bus* destination = busNavigator.item(WxConversion::toString(outputBus_));
339
340 // Add the new/modified bridges to the machine.
341 new Bridge(trimmedName, *source, *destination);
342
343 if (bidirectional_ && tester.canBridge(*destination, *source)) {
344 new Bridge(trimmedOppName, *destination, *source);
345 }
346 MDFView* view =
347 dynamic_cast<MDFView*>(wxGetApp().docManager()->GetCurrentView());
348 view->canvas()->tool()->activate();
349 EndModal(wxID_OK);
350}
351
352
353void
354BridgeDialog::onCancel(wxCommandEvent&) {
355 MDFView* view =
356 dynamic_cast<MDFView*>(wxGetApp().docManager()->GetCurrentView());
357 view->canvas()->tool()->activate();
358 EndModal(wxID_CANCEL);
359}
360
361/**
362 * Checks whether name field is empty and disables OK button of the
363 * dialog if it is.
364 */
365void
366BridgeDialog::onName(wxCommandEvent&) {
367
368 wxTextCtrl* nameCtrl = dynamic_cast<wxTextCtrl*>(FindWindow(ID_NAME));
369 wxTextCtrl* oppNameCtrl =
370 dynamic_cast<wxTextCtrl*>(FindWindow(ID_OPPOSITE_BRIDGE));
371
372 wxString name = nameCtrl->GetValue();
373 wxString trimmedName = name.Trim(false).Trim(true);
374 wxString oppositeName = oppNameCtrl->GetValue();
375 wxString trimmedOppositeName = oppositeName.Trim(false).Trim(true);
376
377 if (trimmedName == _T("") ||
378 (bidirectional_ && trimmedOppositeName == _T(""))) {
379
380 FindWindow(wxID_OK)->Disable();
381 } else {
382 FindWindow(wxID_OK)->Enable();
383 }
384}
385
386
387/**
388 * Handles changes in input bus control.
389 *
390 * Checks that input bus is not the same as output bus. If it is the
391 * output bus is changed to the previous value of the input bus.
392 */
393void
395 wxString outputBus = outputBusChoice_->GetStringSelection();
396 outputBus_ = outputBus;
398}
399
400
401/**
402 * Handles changes in the input bus control.
403 *
404 * Output bus choicer is updated to contain only valid output busses
405 * for the selected input bus.
406 */
407void
408BridgeDialog::onInputBus(wxCommandEvent&) {
409
410 string outputBus =
411 WxConversion::toString(outputBusChoice_->GetStringSelection());
412 string inputBus =
413 WxConversion::toString(inputBusChoice_->GetStringSelection());
414
415 MachineTester tester(*machine_);
417 Bus* source = navigator.item(inputBus);
418 Bus* destination = navigator.item(outputBus);
419
420 if (!tester.canBridge(*source, *destination)) {
421 outputBus = "";
422 for (int i=0; i < navigator.count(); i++) {
423 if (tester.canBridge(*source, *navigator.item(i))) {
424 outputBus = navigator.item(i)->name();
425 break;
426 }
427 }
428 assert(outputBus != "");
430 }
431
434}
435
436
437/**
438 * Handles changes in bidirectional control.
439 *
440 * When bdirectional is on, the opposite bridge name control is
441 * enabled, otherwise it is disabled.
442 */
443void
445 if (bidirectionalBox_->IsChecked()) {
446 oppositeNameCtrl_->Enable();
447 bidirectional_ = true;
448 } else {
449 oppositeNameCtrl_->Disable();
450 bidirectional_ = false;
451 }
452 wxCommandEvent dummy;
453 onName(dummy);
454}
455
456
457/**
458 * Creates the dialog window contents.
459 *
460 * This method was initially generated with wxDesigner, thus the ugly code
461 * and too long lines.
462 *
463 * @return Main sizer of the created contents.
464 * @param parent The dialog window.
465 * @param call_fit If true, fits the contents inside the dialog.
466 * @param set_sizer If true, sets the main sizer as dialog contents.
467 */
468wxSizer*
469BridgeDialog::createContents(wxWindow *parent, bool call_fit, bool set_sizer) {
470
471 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
472
473 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
474
475 wxFlexGridSizer *item2 = new wxFlexGridSizer( 2, 0, 0 );
476
477 wxStaticText *item3 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
478 item2->Add( item3, 0, wxALL, 5 );
479
480 wxTextCtrl *item4 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(120,-1), 0 );
481 item2->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
482
483 wxStaticText *item5 = new wxStaticText( parent, ID_LABEL_INPUT_BUS, wxT("Input Bus:"), wxDefaultPosition, wxDefaultSize, 0 );
484 item2->Add( item5, 0, wxALL, 5 );
485
486 wxString *strs6 = (wxString*) NULL;
487 wxChoice *item6 = new wxChoice( parent, ID_INPUT_BUS, wxDefaultPosition, wxSize(100,-1), 0, strs6, 0 );
488 item2->Add( item6, 0, wxGROW|wxALL, 5 );
489
490 wxStaticText *item7 = new wxStaticText( parent, ID_LABEL_OUTPUT_BUS, wxT("Output Bus:"), wxDefaultPosition, wxDefaultSize, 0 );
491 item2->Add( item7, 0, wxALL, 5 );
492
493 wxString *strs8 = (wxString*) NULL;
494 wxChoice *item8 = new wxChoice( parent, ID_OUTPUT_BUS, wxDefaultPosition, wxSize(100,-1), 0, strs8, 0 );
495 item2->Add( item8, 0, wxGROW|wxALL, 5 );
496
497 item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
498
499 wxBoxSizer *item9 = new wxBoxSizer( wxVERTICAL );
500
501 wxCheckBox *item10 = new wxCheckBox( parent, ID_BIDIRECTIONAL, wxT("Bidirectional"), wxDefaultPosition, wxDefaultSize, 0 );
502 item9->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
503
504 item9->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
505
506 wxStaticText *item11 = new wxStaticText( parent, ID_LABEL_OPPOSITE_NAME, wxT("Opposite Bridge Name:"), wxDefaultPosition, wxDefaultSize, 0 );
507 item9->Add( item11, 0, wxGROW, 15 );
508
509 wxTextCtrl *item12 = new wxTextCtrl( parent, ID_OPPOSITE_BRIDGE, wxT(""), wxDefaultPosition, wxSize(80,-1), 0 );
510 item9->Add( item12, 0, wxGROW|wxALL, 5 );
511
512 item1->Add( item9, 0, wxGROW|wxALL, 5 );
513
514 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
515
516 wxStaticLine *item13 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
517 item0->Add( item13, 0, wxGROW|wxALL, 5 );
518
519 wxGridSizer *item14 = new wxGridSizer( 2, 0, 0 );
520
521 wxButton *item15 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
522 item14->Add( item15, 0, wxALL, 5 );
523
524 wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL );
525
526 wxButton *item17 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
527 item16->Add( item17, 0, wxALIGN_CENTER|wxALL, 5 );
528
529 wxButton *item18 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
530 item16->Add( item18, 0, wxALIGN_CENTER|wxALL, 5 );
531
532 item14->Add( item16, 0, wxALL, 5 );
533
534 item0->Add( item14, 0, wxALIGN_CENTER, 5 );
535
536 if (set_sizer)
537 {
538 parent->SetSizer( item0 );
539 if (call_fit)
540 item0->SetSizeHints( parent );
541 }
542
543 return item0;
544}
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine * machine
the architecture definition of the estimated processor
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
void onBidirectional(wxCommandEvent &)
void onOK(wxCommandEvent &)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onCancel(wxCommandEvent &)
wxChoice * inputBusChoice_
Input bus choice control.
void updateBusChoices()
virtual bool TransferDataToWindow()
void onOutputBus(wxCommandEvent &)
bool bidirectional_
Indicates whether we are modifying a bidirectional bridge or not.
void onName(wxCommandEvent &)
wxString inputBus_
Name of the bridge input bus.
void onInputBus(wxCommandEvent &)
wxString name_
Name of the bridge.
virtual ~BridgeDialog()
TTAMachine::Machine * machine_
Parent machine of the bridge(s).
wxString oppositeName_
Name of the opposite bridge.
wxCheckBox * bidirectionalBox_
Indicates whether the bridge is bidirectional.
wxChoice * outputBusChoice_
Output bus choice control.
wxString outputBus_
Name of the bridge output bus.
wxTextCtrl * oppositeNameCtrl_
Opposite name control.
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
MachineCanvas * canvas() const
Definition MDFView.cc:229
virtual void activate()=0
virtual void deactivate()=0
MachineCanvasTool * tool()
virtual bool canBridge(const TTAMachine::Bus &source, const TTAMachine::Bus &destination)
static bool isValidComponentName(const std::string &name)
static ProDeTextGenerator * instance()
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
@ TXT_LABEL_INPUT_BUS
Label for input bus widget.
@ TXT_LABEL_NAME
Label for component name widget.
@ COMP_A_BRIDGE
Name for bridge (w/ article).
@ TXT_LABEL_OUTPUT_BUS
Label for output bus widget.
@ TXT_LABEL_OPPOSITE_BRIDGE
Label for opposite bridge name.
@ COMP_MACHINE
Text for machine description.
@ TXT_LABEL_BIDIRECTIONAL
Label for bidirectional checkbox.
@ COMP_BRIDGE
Name for bridge component.
@ TXT_BRIDGE_DIALOG_TITLE
Bridge dialog title.
@ MSG_ERROR_BRIDGE_NAMES
Error: Opposing brdgs w/same name.
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual BridgeNavigator bridgeNavigator() const
Definition Machine.cc:404
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
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)