OpenASIP 2.2
Loading...
Searching...
No Matches
OperationDialog.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 OperationDialog.cc
26 *
27 * Implementation of OperationDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <list>
34#include <boost/format.hpp>
35#include <wx/wx.h>
36#include <wx/listctrl.h>
37#include <wx/statline.h>
38
39#include "OperationDialog.hh"
40#include "FunctionUnit.hh"
41#include "FUPort.hh"
42#include "WxConversion.hh"
43#include "HWOperation.hh"
44#include "ExecutionPipeline.hh"
45#include "PipelineElement.hh"
46#include "InformationDialog.hh"
47#include "WidgetTools.hh"
48#include "WxConversion.hh"
49#include "Conversion.hh"
50#include "GUITextGenerator.hh"
51#include "ProDeTextGenerator.hh"
52#include "ContainerTools.hh"
53#include "WidgetTools.hh"
54#include "WarningDialog.hh"
55#include "ProDeConstants.hh"
56#include "MachineTester.hh"
57#include "ConfirmDialog.hh"
58
59using std::string;
60using boost::format;
61using namespace TTAMachine;
62
64const wxString OperationDialog::READ_MARK = _T("R");
65const wxString OperationDialog::WRITE_MARK = _T("W");
66const wxString OperationDialog::USE_MARK = _T("X");
67
68// too long lines to keep doxygen quiet
69BEGIN_EVENT_TABLE(OperationDialog, wxDialog)
70
71 EVT_TEXT(ID_NAME, OperationDialog::onName)
72 EVT_TEXT(ID_RESOURCE_NAME, OperationDialog::onName)
73
76 EVT_CHOICE(ID_PORT, OperationDialog::onBindOperand)
77
79
82 EVT_MENU(ID_DELETE_RESOURCE, OperationDialog::onDeleteResource)
83
86
87 EVT_GRID_CELL_LEFT_CLICK(OperationDialog::onGridLClick)
88 EVT_GRID_CELL_RIGHT_CLICK(OperationDialog::onGridRClick)
89
90 EVT_GRID_RANGE_SELECT(OperationDialog::onResourceSelection)
92
93
94/**
95 * The Constructor.
96 *
97 * @param parent Parent window of the dialog.
98 * @param operation Operation to modify.
99 */
101 wxWindow* parent,
102 HWOperation* operation) :
103 wxDialog(
104 parent, -1, _T(""), wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER),
105 operation_(operation),
106 name_(_T("")),
107 resourceName_(_T("")),
108 latencyText_(NULL) {
109
110 createContents(this, true, true);
111 initialize();
112 setTexts();
113}
114
115
116
117/**
118 * The Destructor.
119 */
122
123
124/**
125 * Initializes the dialog widgets and some class variables.
126 */
127void
129
130 // Name field validators.
131 FindWindow(ID_NAME)->SetValidator(wxTextValidator(wxFILTER_ASCII, &name_));
132 FindWindow(ID_RESOURCE_NAME)->SetValidator(
133 wxTextValidator(wxFILTER_ASCII, &resourceName_));
134
135 // Set widget pointers.
136 bindList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_BIND_LIST));
137 resourceGrid_ = dynamic_cast<wxGrid*>(FindWindow(ID_RESOURCE_GRID));
138 usageGrid_ = dynamic_cast<wxGrid*>(FindWindow(ID_OPERAND_GRID));
139 portChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_PORT));
140 numberControl_ = dynamic_cast<wxSpinCtrl*>(FindWindow(ID_NUMBER));
141
142 // Operand list.
143 FindWindow(ID_DELETE_OPERAND)->Disable();
144 FindWindow(ID_DELETE_RESOURCE)->Disable();
145
146 // Resource grid.
147 resourceGrid_->EnableEditing(false);
148 resourceGrid_->SetDefaultCellAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
149 resourceGrid_->DisableDragColSize();
150 resourceGrid_->DisableDragRowSize();
151
152 // Operand usage grid.
153 usageGrid_->EnableEditing(false);
154 usageGrid_->DisableDragColSize();
155 usageGrid_->DisableDragRowSize();
156
157 latencyText_ = dynamic_cast<wxStaticText*>(FindWindow(ID_LATENCY));
158}
159
160
161/**
162 * Sets texts for widgets.
163 */
164void
168
169 // Dialog title
170 format fmt = prodeTexts->text(
172 SetTitle(WxConversion::toWxString(fmt.str()));
173
174 // buttons
175 WidgetTools::setLabel(generator, FindWindow(wxID_OK),
177
178 WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
180
183
186
189
192
195
196
197 // widget labels
200
203
206
209
210 // box sizer label
213
216
219
220 // Create bind list columns.
221 wxListCtrl* bindList =
222 dynamic_cast<wxListCtrl*>(FindWindow(ID_BIND_LIST));
224 bindList->InsertColumn(0, WxConversion::toWxString(fmt.str()),
225 wxLIST_FORMAT_LEFT, 80);
226 fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_PORT);
227 bindList->InsertColumn(1, WxConversion::toWxString(fmt.str()),
228 wxLIST_FORMAT_LEFT, 100);
229}
230
231
232/**
233 * Transfers data from the operation object to the dialog widgets.
234 *
235 * @return true, if the transfer was succesful, false otherwise
236 */
237bool
243 return wxDialog::TransferDataToWindow();
244}
245
246
247/**
248 * Updates the operand bind list.
249 */
250void
252
254 for (int cycle = 0; cycle <= pipeline->latency(); cycle++) {
255 // Read operands.
257 pipeline->readOperands(cycle);
258 ExecutionPipeline::OperandSet::const_iterator iter =
259 operands.begin();
260 for (; iter != operands.end(); iter++) {
261 operands_.insert(*iter);
262 }
263 // Written operands.
264 operands = pipeline->writtenOperands(cycle);
265 iter = operands.begin();
266 for (; iter != operands.end(); iter++) {
267 operands_.insert(*iter);
268 }
269 }
270
271 // Search bound operands.
272 for (int i = 0; i < operation_->parentUnit()->operationPortCount(); i++) {
274 if (operation_->isBound(*port)) {
275 int operand = operation_->io(*port);
276 operands_.insert(operand);
277 }
278 }
279
280 // Add operand-port pairs to the operation list.
281 std::set<int>::const_iterator iter = operands_.begin();
282 bindList_->DeleteAllItems();
283 for (; iter != operands_.end(); iter++) {
284 wxString portName = _T("");
285 if (operation_->port(*iter) != NULL) {
286 portName =
288 }
289 bindList_->InsertItem(0, WxConversion::toWxString(*iter));
290 bindList_->SetItem(0, 1, portName);
291 }
292 if (portChoice_->GetCount() > 1) {
293 portChoice_->SetSelection(1);
294 } else {
295 portChoice_->SetSelection(0);
296 }
297 wxListEvent dummy;
300}
301
302
303/**
304 * Updates the list of pipeline resources.
305 */
306void
308
309 int selected = -1;
310
311 if (resourceGrid_->IsSelection()) {
312 selected = resourceGrid_->GetSelectedRows().Item(0);
313 }
314
315 if (resourceGrid_->GetNumberCols() > 0) {
316 resourceGrid_->DeleteCols(0, resourceGrid_->GetNumberCols());
317 }
318 if (resourceGrid_->GetNumberRows() > 0) {
319 resourceGrid_->DeleteRows(0, resourceGrid_->GetNumberRows());
320 }
321
324
325 resourceGrid_->AppendCols(pipeline->latency() + 50);
326 resourceGrid_->AppendRows(parent->pipelineElementCount());
327
328 resourceGrid_->EnableEditing(false);
329
330 // Set column labels (cycle numbers).
331 for (int i = 0; i < pipeline->latency() + 50; i++) {
332 resourceGrid_->SetColLabelValue(i, WxConversion::toWxString(i));
333 resourceGrid_->SetColSize(i, GRID_COLUMN_WIDTH);
334 }
335
336 // Set row labels (resource names).
337 std::list<string> resources;
338 for (int i = 0; i < parent->pipelineElementCount(); i++) {
339 string label = parent->pipelineElement(i)->name();
340 resources.push_back(label);
341 }
342 resources.sort();
343 int row = 0;
344 std::list<string>::const_iterator iter = resources.begin();
345 for (; iter != resources.end(); iter++) {
346 resourceGrid_->SetRowLabelValue(row, WxConversion::toWxString(*iter));
347 row++;
348 }
349
350 // add resource uses to the grid
351 for (int cycle = 0; cycle < (pipeline->latency() + 1); cycle++) {
352 row = 0;
353 for (iter = resources.begin(); iter != resources.end(); iter++) {
354 if (pipeline->isResourceUsed((*iter), cycle)) {
355 resourceGrid_->SetCellValue(row, cycle, USE_MARK);
356 }
357 row++;
358 }
359 }
360
361 // Add resources that are not used
362 newResources_.sort();
363 iter = newResources_.begin();
364 for (; iter != newResources_.end(); iter++) {
365 resourceGrid_->AppendRows();
366 resourceGrid_->SetRowLabelValue(row, WxConversion::toWxString(*iter));
367 row++;
368 }
369
370 if (selected >= 0) {
371 resourceGrid_->SelectRow(selected);
372 }
373
374 resourceGrid_->FitInside();
376}
377
378
379/**
380 * Updates the operand usage grid.
381 *
382 * If a resource is selected in the resource grid, the grid is enabled
383 * for editing and it displays the operand usage only for the selected
384 * resource. If a resource isn't selected, the grid will be disabled,
385 * and it displays summary of the operand use for all resources.
386 */
387void
389
391
392 // Clear grid.
393 if (usageGrid_->GetNumberCols() > 0) {
394 usageGrid_->DeleteCols(0, usageGrid_->GetNumberCols());
395 }
396 if (usageGrid_->GetNumberRows() > 0) {
397 usageGrid_->DeleteRows(0, usageGrid_->GetNumberRows());
398 }
399
400 usageGrid_->AppendCols(pipeline->latency() + 50);
401 usageGrid_->AppendRows(operands_.size());
402
403 // Reset row labels to numbers (clear R/W flags).
404 int i = 0;
405 std::set<int>::const_iterator iter = operands_.begin();
406 for (; iter != operands_.end(); iter++) {
407 usageGrid_->SetRowLabelValue(i, WxConversion::toWxString(*iter));
408 i++;
409 }
410
411 // Update operand uses to the grid
412 for (int cycle = 0; cycle < pipeline->latency() + 50; cycle++) {
413
414 usageGrid_->SetColSize(cycle, GRID_COLUMN_WIDTH);
415 usageGrid_->SetColLabelValue(
416 cycle, WxConversion::toWxString(cycle));
417
418 wxColour na = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
419
420 // Reads
422 pipeline->readOperands(cycle);
423 ExecutionPipeline::OperandSet::const_iterator iter =
424 operands.begin();
425
426 for (; iter != operands.end(); iter++) {
427 int row = operandRow(*iter);
428 assert(row >= 0);
429 setOperandType(*iter, true);
430 // operand read
431 usageGrid_->SetCellValue(row, cycle, READ_MARK);
432 }
433
434 // Writes
435 operands = pipeline->writtenOperands(cycle);
436 iter = operands.begin();
437 for (; iter != operands.end(); iter++) {
438 int row = operandRow(*iter);
439 assert(row >= 0);
440 setOperandType(*iter, false);
441 // operand written
442 usageGrid_->SetCellValue(row, cycle, WRITE_MARK);
443 }
444 }
445
446 usageGrid_->FitInside();
448}
449
450
451/**
452 * Sets operand row label read/write flag.
453 *
454 * @param operand Operand to set the label to.
455 * @param read True if operand is read, false if written.
456 */
457void
458OperationDialog::setOperandType(int operand, bool read) {
459 wxString label = WxConversion::toWxString(operand);
460 label.Append(_T(" ("));
461 if (read) {
462 label.Append(READ_MARK);
463 } else {
464 label.Append(WRITE_MARK);
465 }
466 label.Append(_T(")"));
467 int row = operandRow(operand);
468 assert(row >= 0);
469 usageGrid_->SetRowLabelValue(row , label);
470}
471
472
473/**
474 * Warns if pipeline resources without usages exist
475 */
476void
480 for (std::list<string>::const_iterator iter = newResources_.begin();
481 iter != newResources_.end(); iter++) {
482
483 bool warn = true;
484 for (int cycle = 0; cycle < pipeline->latency(); cycle++) {
485 if (pipeline->isResourceUsed(*iter, cycle)) {
486 warn = false;
487 break;
488 }
489 }
490
491 if (warn) {
492 format fmt = prodeTexts->text(
494 WarningDialog warning(this, WxConversion::toWxString(fmt.str()
495 + *iter));
496 warning.ShowModal();
497 }
498 }
499}
500
501
502/**
503 * Returns row nubmer of the operand in the resource usage grid.
504 *
505 * Returns -1 if the operand is not found.
506 *
507 * @param Operand to search.
508 * @return Operand grid row number of the operand.
509 */
510int
512 int row = 0;
513 std::set<int>::const_iterator iter = operands_.begin();
514 for (; iter != operands_.end(); iter++) {
515 if (*iter == operand) {
516 return row;
517 }
518 row++;
519 }
520 return -1;
521}
522
523/**
524 * Handles the left mouse button event in both grids.
525 *
526 * The event is passed to the grid specific handler.
527 *
528 * @param event The mouse event to handle.
529 */
530void
531OperationDialog::onGridLClick(wxGridEvent& event) {
532 if (event.GetId() == ID_RESOURCE_GRID) {
533 onResourceLClick(event);
534 } else if (event.GetId() == ID_OPERAND_GRID) {
535 onOperandLClick(event);
536 }
537}
538
539/**
540 * Handles the right mouse button event in both grids.
541 *
542 * @param event The mouse event to handle.
543 */
544void
545OperationDialog::onGridRClick(wxGridEvent& event) {
546 if (event.GetId() == ID_RESOURCE_GRID) {
547 resourceGrid_->ClearSelection();
548 }
549}
550
551
552/**
553 * Handles left mouse button cliks in the resource grid.
554 *
555 * @param event The mouse event to handle.
556 */
557void
559
560 if (event.GetCol() < 0 || event.GetRow() < 0) {
561 return;
562 }
563
565 int cycle = event.GetCol();
566 string resource = selectedResource();
567
568 // First click just selects the row.
570 resourceGrid_->GetRowLabelValue(event.GetRow()))) {
571
572 resourceGrid_->SelectRow(event.GetRow());
573 return;
574 }
575
576 if (operation_->pipeline()->isResourceUsed(resource, cycle)) {
577 //Try to remove resource use.
578 try {
579 pipeline->removeResourceUse(resource, cycle);
580 } catch (StartTooLate& e) {
582 format fmt = prodeTexts->text(
584 InformationDialog dialog(
585 this, WxConversion::toWxString(fmt.str()));
586 dialog.ShowModal();
587 return;
588 }
589 if (!operation_->parentUnit()->hasPipelineElement(resource)) {
590 newResources_.push_back(resource);
591 }
592 } else {
593 // Try to add resource use.
594 try {
595 pipeline->addResourceUse(resource, cycle, 1);
596 } catch (StartTooLate& e) {
598 format fmt = prodeTexts->text(
600 InformationDialog dialog(
601 this, WxConversion::toWxString(fmt.str()));
602 dialog.ShowModal();
603 return;
604 }
606 }
608 resourceGrid_->SelectRow(event.GetRow());
609}
610
611/**
612 * Handles left mouse button clicks in the operand usage grid.
613 *
614 * @param event The mouse event to handle.
615 */
616void
618
619 int cycle = event.GetCol();
620
621 std::set<int>::const_iterator iter = operands_.begin();
622 for (int i = 0; i < event.GetRow(); i++) {
623 assert(iter != operands_.end());
624 iter++;
625 }
626 int operand = *iter;
628
629
630 bool read = false;
631 bool written = false;
632
633 // Check if the operand is already being read.
634 ExecutionPipeline::OperandSet readOperands =
635 pipeline->readOperands(cycle);
636 if (ContainerTools::containsValue(readOperands, operand)) {
637 read = true;
638 }
639 // Check if the operand is already being written.
640 ExecutionPipeline::OperandSet writtenOperands =
641 pipeline->writtenOperands(cycle);
642 if (ContainerTools::containsValue(writtenOperands, operand)) {
643 written = true;
644 }
645
646 bool toggled = false;
647 if (written == false && read == false) {
648 try {
649 // not used -> read.
650 pipeline->addPortRead(operand, cycle, 1);
651 toggled = true;
652 } catch (StartTooLate& e) {
654 format fmt = prodeTexts->text(
656 InformationDialog dialog(
657 this, WxConversion::toWxString(fmt.str()));
658 dialog.ShowModal();
659 return;
660 } catch (Exception& e) {
661 // do nothing
662 }
663 }
664 if (toggled == false && read == false && written == false) {
665 try {
666 // not used -> written
667 pipeline->addPortWrite(operand, cycle, 1);
668 toggled = true;
669 } catch (Exception& e) {
670 // do nothing
671 }
672 }
673 if (toggled == false && read == true && written == false) {
674 try {
675 // read -> written
676 pipeline->removeOperandUse(operand, cycle);
677 pipeline->addPortWrite(operand, cycle, 1);
678 toggled = true;
679 } catch (StartTooLate& e) {
681 format fmt = prodeTexts->text(
683 InformationDialog dialog(
684 this, WxConversion::toWxString(fmt.str()));
685 dialog.ShowModal();
686 return;
687 } catch (Exception& e) {
688 // do nothing
689 }
690 }
691 if (toggled == false && (read == true || written == true)) {
692 try {
693 // written/read -> not used
694 pipeline->removeOperandUse(operand, cycle);
695 toggled = true;
696 } catch (StartTooLate& e) {
698 format fmt = prodeTexts->text(
700 InformationDialog dialog(
701 this, WxConversion::toWxString(fmt.str()));
702 dialog.ShowModal();
703 return;
704 } catch (Exception& e) {
705 // do nothing
706 }
707 }
710 usageGrid_->MakeCellVisible(event.GetRow(), event.GetCol());
711}
712
713/**
714 * Checks whether name field is empty and disables OK button of the
715 * dialog if it is.
716 */
717void
718OperationDialog::onName(wxCommandEvent&) {
719
720 if (!TransferDataFromWindow()) {
721 assert(false);
722 }
723
724 // OK-button.
725 wxString trimmedName = name_.Trim(false).Trim(true);
726 if (trimmedName == _T("")) {
727 FindWindow(wxID_OK)->Disable();
728 } else {
729 FindWindow(wxID_OK)->Enable();
730 }
731
732 // Add resource button.
733 wxString trimmedResourceName = resourceName_.Trim(false).Trim(true);
734 if (trimmedResourceName == _T("")) {
735 FindWindow(ID_ADD_RESOURCE)->Disable();
736 } else {
737 FindWindow(ID_ADD_RESOURCE)->Enable();
738 }
739}
740
741
742/**
743 * Handles the Add bind button event.
744 *
745 * Adds a bind to the operation according to the number and port selection
746 * widgets.
747 */
748void
750
751 int number = numberControl_->GetValue();
752
753 std::pair<std::set<int>::iterator, bool> result =
754 operands_.insert(number);
755
756 // Check that the number is not reserved for an operand.
757 if (!result.second) {
759 format fmt = prodeTexts->text(
761 fmt % number;
762 InformationDialog dialog(this, WxConversion::toWxString(fmt.str()));
763 dialog.ShowModal();
764 return;
765 }
766
768 numberControl_->SetValue(number + 1);
769
770/*
771 } else {
772 }
773*/
774}
775
776
777/**
778 * Removes the selected bind from the operation.
779 */
780void
782
784
785 string selected = WidgetTools::lcStringSelection(bindList_, 0);
786 if (selected == "") {
787 return;
788 }
789
790 int operand = Conversion::toInt(selected);
791
792 // If the selected operand is read or written, a dialog is displayed
793 // that allows user to choose if the operand reads and writes are
794 // also cleared.
795 if (ContainerTools::containsValue(pipeline->readOperands(), operand) ||
796 ContainerTools::containsValue(pipeline->writtenOperands(), operand)) {
797
799
800 format msgFmt = prodeTexts->text(
802 msgFmt % operand;
803 ConfirmDialog dialog(this, WxConversion::toWxString(msgFmt.str()));
804
805 int choice = dialog.ShowModal();
806 if (choice == wxID_YES) {
807 try {
808 for (int c = pipeline->latency() - 1; c >= 0; c--) {
809 pipeline->removeOperandUse(operand, c);
810 }
811 } catch (StartTooLate& e) {
812 format fmt = prodeTexts->text(
814 InformationDialog dialog(
815 this, WxConversion::toWxString(fmt.str()));
816 dialog.ShowModal();
817 return;
818 }
819 } else if (choice != wxID_NO) {
820 return;
821 }
822 }
823
825
826 FUPort* port = operation_->port(operand);
827 if (port != NULL) {
828 operation_->unbindPort(*port);
829 }
831}
832
833/**
834 * Event handler for the operand port binding choicer.
835 */
836void
838
839 string selected = WidgetTools::lcStringSelection(bindList_, 0);
840 int number = Conversion::toInt(selected);
841
842 if (portChoice_->GetSelection() > 0) {
843 string portName=
844 WxConversion::toString(portChoice_->GetStringSelection());
845
846 FUPort* port = operation_->parentUnit()->operationPort(portName);
847 operation_->bindPort(number, *port);
848 } else {
849 FUPort* port = operation_->port(number);
850 if (port != NULL) {
851 operation_->unbindPort(*port);
852 }
853 }
855}
856
857
858/**
859 * Handles the bind list item selection events.
860 *
861 * Enables and disables the delete bind button according to the selection.
862 */
863void
865
866 portChoice_->Clear();
867 portChoice_->Append(_T("none"));
868
869 string selected = WidgetTools::lcStringSelection(bindList_, 0);
870
871 if (selected == "") {
872 FindWindow(ID_DELETE_OPERAND)->Disable();
873 FindWindow(ID_PORT)->Disable();
874 return;
875 } else {
876 int selection = 0;
877 int operand = Conversion::toInt(selected);
878 FindWindow(ID_DELETE_OPERAND)->Enable();
879 FindWindow(ID_PORT)->Enable();
880
881 // Search bound operands.
882 for (int i = 0; i < operation_->parentUnit()->operationPortCount();
883 i++) {
884
886
887 if (!operation_->isBound(*port)) {
888 portChoice_->Append(WxConversion::toWxString(port->name()));
889 } else if (operation_->io(*port) == operand) {
890 selection = portChoice_->Append(
892 }
893 }
894 portChoice_->SetSelection(selection);
895 }
896}
897
898
899/**
900 * Handles the resource list item selection events.
901 *
902 * Enables and disables the edit and delete resource buttons
903 * according to the selection.
904 */
905void
906OperationDialog::onResourceSelection(wxGridRangeSelectEvent&) {
907 if (resourceGrid_->IsSelection()) {
909 } else {
910 FindWindow(ID_DELETE_RESOURCE)->Disable();
911 }
913}
914
915
916/**
917 * Returns name of the resource selected in the resource grid.
918 *
919 * If a resource is not selected, an empty string is returned.
920 */
921string
923 if (!resourceGrid_->IsSelection()) {
924 return "";
925 }
926 // Sometimes GetSelectedRows() returns an empty array even if
927 // IsSelection() returns true.
928 if (resourceGrid_->GetSelectedRows().Count() != 1) {
929 resourceGrid_->ClearSelection();
930 return "";
931 }
932 int row = resourceGrid_->GetSelectedRows().Item(0);
933 return WxConversion::toString(resourceGrid_->GetRowLabelValue(row));
934}
935
936
937/**
938 * Handles the Add resource button event.
939 *
940 * Opens pipeline resource dialog for adding a new resource to the operation.
941 */
942void
944
945 string newName = WxConversion::toString(resourceName_);
946
947 // Check the name validity.
950 format message =
952 InformationDialog warning(
953 this, WxConversion::toWxString(message.str()));
954 warning.ShowModal();
955 return;
956 }
957
958 // Check that the resource name is not reserved.
959 if (operation_->parentUnit()->hasPipelineElement(newName) ||
961
963 format message =
965 format component =
967 format functionUnit =
969 message % newName % component.str() % functionUnit.str();
970 component = prodeTexts->text(ProDeTextGenerator::COMP_RESOURCE);
971 message % component.str();
972 WarningDialog warning(this, WxConversion::toWxString(message.str()));
973 warning.ShowModal();
974 return;
975 }
976 newResources_.push_back(newName);
978 dynamic_cast<wxTextCtrl*>(FindWindow(ID_RESOURCE_NAME))->Clear();
979}
980
981
982/**
983 * Handles the delete resource button event.
984 *
985 * Deletes the selected resource usage from the operation.
986 */
987void
989
990 string selected = selectedResource();
991
992 // Search resource from the unused resources.
993 if (selected == "" ||
995
997 return;
998 }
999
1000 // Remove resource from the operation pipeline.
1001 try {
1003 } catch (StartTooLate& e) {
1005 format fmt = prodeTexts->text(
1007 InformationDialog dialog(
1008 this, WxConversion::toWxString(fmt.str()));
1009 dialog.ShowModal();
1010 return;
1011 }
1013}
1014
1015
1016/**
1017 * Handles the OK-button event.
1018 *
1019 * Updates the operation and closes the dialog.
1020 */
1021void
1022OperationDialog::onOK(wxCommandEvent&) {
1023
1024 TransferDataFromWindow();
1025 string newName =
1026 WxConversion::toString(name_.Trim(true).Trim(false));
1027
1028 // Check the name validity.
1031 format message =
1033 InformationDialog warning(
1034 this, WxConversion::toWxString(message.str()));
1035 warning.ShowModal();
1036 return;
1037 }
1038
1039 try {
1040 operation_->setName(newName);
1041 } catch (ComponentAlreadyExists& e) {
1042
1043 // Display an error message indicating that the name is reserved for
1044 // another operation.
1046 format message =
1048 format component =
1050
1051 format bus = prodeTexts->text(ProDeTextGenerator::COMP_MACHINE);
1052 message % newName % component.str() % bus.str();
1053 component = prodeTexts->text(ProDeTextGenerator::COMP_OPERATION);
1054 message % component.str();
1055
1056 InformationDialog dialog(
1057 this, WxConversion::toWxString(message.str()));
1058
1059 dialog.ShowModal();
1060 return;
1061 }
1062
1064
1065 EndModal(wxID_OK);
1066}
1067
1068/**
1069 * Updates the latency information static text widget.
1070 */
1071void
1073 wxString latency = WxConversion::toWxString(operation_->latency());
1074 latencyText_->SetLabel(latency);
1075}
1076
1077/**
1078 * Creates the dialog contents.
1079 *
1080 * This function was generated by wxDesigner.
1081 *
1082 * @return Main sizer of the created contents.
1083 * @param parent The dialog window.
1084 * @param call_fit If true, fits the contents inside the dialog.
1085 * @param set_sizer If true, sets the main sizer as dialog contents.
1086 */
1087wxSizer*
1089 wxWindow *parent, bool call_fit, bool set_sizer) {
1090
1091 wxFlexGridSizer *item0 = new wxFlexGridSizer( 1, 0, 0 );
1092 item0->AddGrowableCol( 0 );
1093 item0->AddGrowableRow( 0 );
1094
1095 wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
1096 item1->AddGrowableCol( 1 );
1097 item1->AddGrowableRow( 0 );
1098
1099 wxFlexGridSizer *item2 = new wxFlexGridSizer( 1, 0, 0 );
1100 item2->AddGrowableRow( 1 );
1101
1102 wxBoxSizer *item3 = new wxBoxSizer( wxHORIZONTAL );
1103
1104 wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
1105 item3->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
1106
1107 wxTextCtrl *item5 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(160,-1), 0 );
1108 item3->Add( item5, 0, wxALIGN_CENTER, 5 );
1109
1110 item2->Add( item3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1111
1112 wxStaticBox *item7 = new wxStaticBox( parent, -1, wxT("Operands:") );
1113 wxStaticBoxSizer *item6 = new wxStaticBoxSizer( item7, wxHORIZONTAL );
1114 operandSizer_ = item6;
1115
1116 wxFlexGridSizer *item8 = new wxFlexGridSizer( 1, 0, 0 );
1117 item8->AddGrowableRow( 0 );
1118
1119 wxListCtrl *item9 = new wxListCtrl( parent, ID_BIND_LIST, wxDefaultPosition, wxSize(200,300), wxLC_REPORT|wxSUNKEN_BORDER );
1120 item8->Add( item9, 0, wxGROW|wxALL, 5 );
1121
1122 wxBoxSizer *item10 = new wxBoxSizer( wxVERTICAL );
1123
1124 wxBoxSizer *item11 = new wxBoxSizer( wxHORIZONTAL );
1125
1126 wxStaticText *item12 = new wxStaticText( parent, ID_LABEL_PORT, wxT("Port:"), wxDefaultPosition, wxDefaultSize, 0 );
1127 item11->Add( item12, 0, wxALL, 5 );
1128
1129 wxString *strs13 = (wxString*) NULL;
1130 wxChoice *item13 = new wxChoice( parent, ID_PORT, wxDefaultPosition, wxSize(100,-1), 0, strs13, 0 );
1131 item11->Add( item13, 0, wxGROW|wxALL, 5 );
1132
1133 wxButton *item14 = new wxButton( parent, ID_DELETE_OPERAND, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
1134 item11->Add( item14, 0, wxALL, 5 );
1135
1136 item10->Add( item11, 0, wxGROW, 5 );
1137
1138 wxStaticLine *item15 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
1139 item10->Add( item15, 0, wxGROW|wxALL, 5 );
1140
1141 wxBoxSizer *item16 = new wxBoxSizer( wxHORIZONTAL );
1142
1143 wxStaticText *item17 = new wxStaticText( parent, ID_LABEL_OPERAND, wxT("New operand:"), wxDefaultPosition, wxDefaultSize, 0 );
1144 item16->Add( item17, 0, wxALL, 5 );
1145
1146 wxSpinCtrl *item18 = new wxSpinCtrl( parent, ID_NUMBER, wxT("1"), wxDefaultPosition, wxSize(-1,-1), 0, 1, 10000, 1 );
1147 item16->Add( item18, 0, wxGROW|wxALL, 5 );
1148
1149 wxButton *item19 = new wxButton( parent, ID_ADD_OPERAND, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 );
1150 item16->Add( item19, 0, wxALL, 5 );
1151
1152 item10->Add( item16, 0, wxALIGN_CENTER, 5 );
1153
1154 item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
1155
1156 item6->Add( item8, 0, wxGROW, 5 );
1157
1158 item2->Add( item6, 0, wxGROW, 5 );
1159
1160 item1->Add( item2, 0, wxGROW|wxALL, 5 );
1161
1162 wxFlexGridSizer *item20 = new wxFlexGridSizer( 1, 0, 0 );
1163 item20->AddGrowableCol( 0 );
1164 item20->AddGrowableRow( 0 );
1165 item20->AddGrowableRow( 1 );
1166
1167 wxStaticBox *item22 = new wxStaticBox( parent, -1, wxT("Pipeline Resources:") );
1168 wxStaticBoxSizer *item21 = new wxStaticBoxSizer( item22, wxHORIZONTAL );
1169 resourceSizer_ = item21;
1170
1171 wxFlexGridSizer *item23 = new wxFlexGridSizer( 1, 0, 0 );
1172 item23->AddGrowableCol( 0 );
1173 item23->AddGrowableRow( 0 );
1174
1175 wxGrid *item24 = new wxGrid( parent, ID_RESOURCE_GRID, wxDefaultPosition, wxSize(400,200), wxWANTS_CHARS );
1176 item24->CreateGrid( 0, 0, wxGrid::wxGridSelectRows );
1177 item23->Add( item24, 0, wxGROW|wxALL, 5 );
1178
1179 wxBoxSizer *item25 = new wxBoxSizer( wxHORIZONTAL );
1180
1181 wxStaticText *item26 = new wxStaticText( parent, ID_LABEL_RESOURCE_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
1182 item25->Add( item26, 0, wxALIGN_CENTER|wxALL, 5 );
1183
1184 wxTextCtrl *item27 = new wxTextCtrl( parent, ID_RESOURCE_NAME, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
1185 item25->Add( item27, 1, wxALIGN_CENTER|wxALL, 5 );
1186
1187 wxButton *item28 = new wxButton( parent, ID_ADD_RESOURCE, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 );
1188 item28->Enable( false );
1189 item25->Add( item28, 0, wxALIGN_CENTER|wxALL, 5 );
1190
1191 wxButton *item29 = new wxButton( parent, ID_DELETE_RESOURCE, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
1192 item29->Enable( false );
1193 item25->Add( item29, 0, wxALIGN_CENTER|wxALL, 5 );
1194
1195 //item25->Add( 30, 20, 0, wxALIGN_CENTER|wxALL, 5 );
1196
1197 item23->Add( item25, 0, wxGROW|wxALL, 5 );
1198
1199 item21->Add( item23, 1, wxGROW, 5 );
1200
1201 item20->Add( item21, 0, wxGROW|wxBOTTOM, 5 );
1202
1203 wxStaticBox *item33 = new wxStaticBox( parent, -1, wxT("Operand usage:") );
1204 wxStaticBoxSizer *item32 = new wxStaticBoxSizer( item33, wxHORIZONTAL );
1205 usageSizer_ = item32;
1206
1207 wxGrid *item34 = new wxGrid( parent, ID_OPERAND_GRID, wxDefaultPosition, wxSize(400,200), wxWANTS_CHARS );
1208 item34->CreateGrid( 0, 0, wxGrid::wxGridSelectCells );
1209 item32->Add( item34, 1, wxGROW|wxALL, 5 );
1210
1211 item20->Add( item32, 0, wxGROW, 5 );
1212
1213 wxBoxSizer *item35 = new wxBoxSizer( wxHORIZONTAL );
1214
1215 wxStaticText *item36 = new wxStaticText( parent, ID_LABEL_LATENCY, wxT("Operation latency:"), wxDefaultPosition, wxDefaultSize, 0 );
1216 item35->Add( item36, 0, wxALIGN_CENTER|wxALL, 5 );
1217
1218 wxStaticText *item37 = new wxStaticText( parent, ID_LATENCY, wxT(" "), wxDefaultPosition, wxDefaultSize, 0 );
1219 item35->Add( item37, 0, wxALIGN_CENTER|wxALL, 5 );
1220
1221 item20->Add( item35, 0, wxGROW|wxALL, 5 );
1222
1223 item1->Add( item20, 0, wxGROW, 5 );
1224
1225 item0->Add( item1, 0, wxGROW|wxALL, 5 );
1226
1227 wxBoxSizer *item38 = new wxBoxSizer( wxVERTICAL );
1228
1229 wxStaticLine *item39 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
1230 item38->Add( item39, 0, wxGROW|wxALL, 5 );
1231
1232 wxGridSizer *item40 = new wxGridSizer( 2, 0, 0 );
1233
1234 wxButton *item41 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
1235 item40->Add( item41, 0, wxALL, 5 );
1236
1237 wxBoxSizer *item42 = new wxBoxSizer( wxHORIZONTAL );
1238
1239 wxButton *item43 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
1240 item42->Add( item43, 0, wxALIGN_CENTER|wxALL, 5 );
1241
1242 wxButton *item44 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
1243 item42->Add( item44, 0, wxALIGN_CENTER|wxALL, 5 );
1244
1245 item40->Add( item42, 0, 0, 5 );
1246
1247 item38->Add( item40, 0, wxGROW, 5 );
1248
1249 item0->Add( item38, 0, wxGROW, 5 );
1250
1251 if (set_sizer) {
1252 parent->SetSizer( item0 );
1253 if (call_fit) {
1254 item0->SetSizeHints( parent );
1255 }
1256 }
1257
1258 return item0;
1259}
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection EVT_LIST_ITEM_DESELECTED(ID_ARCH_PORT_LIST, FUImplementationDialog::onArchPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_ARCH_PORT_LIST
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation EVT_LIST_ITEM_SELECTED(ID_EXTERNAL_PORT_LIST, FUImplementationDialog::onExternalPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_EXTERNAL_PORT_LIST
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
static bool removeValueIfExists(ContainerType &aContainer, const ElementType &aKey)
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
static int toInt(const T &source)
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_DELETE
Label for delete button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
@ TXT_BUTTON_ADD
Label for an add button.
static GUITextGenerator * instance()
static bool isValidComponentName(const std::string &name)
void onAddResource(wxCommandEvent &event)
void onAddOperand(wxCommandEvent &event)
void onOperandSelection(wxListEvent &event)
std::string selectedResource()
wxStaticBoxSizer * usageSizer_
Static boxsizer for the operand usage grid widgets.
TTAMachine::HWOperation * operation_
Operation to edit.
void onGridRClick(wxGridEvent &event)
wxStaticBoxSizer * operandSizer_
Static boxsizer for the operand list widgets.
wxChoice * portChoice_
Choice widget for the port to bind.
static const wxString READ_MARK
Grid marker for a read.
void onName(wxCommandEvent &event)
wxGrid * resourceGrid_
Resource list widget.
wxStaticText * latencyText_
Static text control displaying the operation latency.
void onOK(wxCommandEvent &event)
void onDeleteResource(wxCommandEvent &event)
wxStaticBoxSizer * resourceSizer_
Static boxsizer for the resource grid widgets.
wxSpinCtrl * numberControl_
Spin button control for the bind operand.
void onOperandLClick(wxGridEvent &event)
static const wxString USE_MARK
Grid marker for resource use.
static const wxString WRITE_MARK
Grid marker for a write.
wxString resourceName_
Name of resource to be added.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxString name_
Name of the operation.
void onDeleteOperand(wxCommandEvent &event)
void warnOnResourcesWithoutUsages()
void onResourceLClick(wxGridEvent &event)
void onBindOperand(wxCommandEvent &event)
wxGrid * usageGrid_
Operand usage grid widget.
std::list< std::string > newResources_
List of unused resources.
void setOperandType(int operand, bool read)
static const int GRID_COLUMN_WIDTH
Width of the resource and operand usage grid columns.
int operandRow(int operand)
void onGridLClick(wxGridEvent &event)
wxListCtrl * bindList_
Bind list widget.
std::set< int > operands_
List of unused operands.
void onResourceSelection(wxGridRangeSelectEvent &event)
static ProDeTextGenerator * instance()
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
@ COMP_FUNCTION_UNIT
Name for FU (w/o article).
@ MSG_CONFIRM_OPERAND_DELETION
Confirm: operand deletion.
@ TXT_LABEL_NAME
Label for component name widget.
@ COMP_A_RESOURCE
Name for resource (w/ article).
@ TXT_COLUMN_OPERAND
Label for operand column.
@ TXT_OPERATION_OPERANDS_BOX
Operands box title.
@ TXT_OPERATION_USAGE_BOX
Pipeline usage box title.
@ MSG_ERROR_OPERAND_NUM_RESERVED
Error: Operand number reserved.
@ COMP_MACHINE
Text for machine description.
@ TXT_OPERATION_RESOURCES_BOX
Pipeline resources box title.
@ COMP_OPERATION
Name for operation (w/o article).
@ COMP_AN_OPERATION
Name for operation (w/ article).
@ TXT_LABEL_PORT
Label for port widget.
@ TXT_COLUMN_PORT
Label for port column in a list.
@ COMP_RESOURCE
Name for resource (w/o article).
@ MSG_WARN_RES_WITHOUT_USAGES
Warning: Resources without usages.
@ MSG_ERROR_PIPELINE_START
Error: Pipeline usage start late.
@ TXT_LABEL_OPERAND
Label for operand widget.
@ TXT_OPERATION_DIALOG_TITLE
Operation dialog title.
OperandSet writtenOperands(int cycle) const
void addResourceUse(const std::string &name, int start, int duration)
void addPortRead(int operand, int start, int duration)
void removeOperandUse(int operand, int cycle)
OperandSet readOperands(int cycle) const
std::set< int > OperandSet
Set for operand indexes.
void addPortWrite(int operand, int start, int duration)
void removeResourceUse(const std::string &name)
bool isResourceUsed(const std::string &name, int cycle) const
virtual int pipelineElementCount() const
virtual bool hasPipelineElement(const std::string &name) const
virtual FUPort * operationPort(const std::string &name) const
virtual PipelineElement * pipelineElement(int index) const
ExecutionPipeline * pipeline() const
virtual void bindPort(int operand, const FUPort &port)
virtual void unbindPort(const FUPort &port)
virtual FUPort * port(int operand) const
virtual void setName(const std::string &name)
int io(const FUPort &port) const
const std::string & name() const
bool isBound(const FUPort &port) const
FunctionUnit * parentUnit() const
const std::string & name() const
virtual std::string name() const
Definition Port.cc:141
virtual boost::format text(int textId)
static void setWidgetLabel(wxWindow *widget, std::string text)
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static std::string lcStringSelection(wxListCtrl *list, int column)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)