34 #include <boost/format.hpp>
36 #include <wx/listctrl.h>
37 #include <wx/statline.h>
104 parent, -1, _T(""), wxDefaultPosition, wxDefaultSize, wxRESIZE_BORDER),
105 operation_(operation),
107 resourceName_(_T("")),
110 createContents(
this,
true,
true);
131 FindWindow(ID_NAME)->SetValidator(wxTextValidator(wxFILTER_ASCII, &name_));
133 wxTextValidator(wxFILTER_ASCII, &resourceName_));
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));
147 resourceGrid_->EnableEditing(
false);
148 resourceGrid_->SetDefaultCellAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE);
149 resourceGrid_->SetDefaultCellBackgroundColour(
150 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
153 resourceGrid_->DisableDragColSize();
154 resourceGrid_->DisableDragRowSize();
157 usageGrid_->EnableEditing(
false);
158 usageGrid_->DisableDragColSize();
159 usageGrid_->DisableDragRowSize();
162 latencyText_ =
dynamic_cast<wxStaticText*
>(
FindWindow(ID_LATENCY));
175 format fmt = prodeTexts->
text(
226 wxListCtrl* bindList =
227 dynamic_cast<wxListCtrl*
>(
FindWindow(ID_BIND_LIST));
230 wxLIST_FORMAT_LEFT, 80);
233 wxLIST_FORMAT_LEFT, 100);
246 updateResourceGrid();
248 return wxDialog::TransferDataToWindow();
259 for (
int cycle = 0; cycle <= pipeline->
latency(); cycle++) {
263 ExecutionPipeline::OperandSet::const_iterator iter =
265 for (; iter != operands.end(); iter++) {
266 operands_.insert(*iter);
270 iter = operands.begin();
271 for (; iter != operands.end(); iter++) {
272 operands_.insert(*iter);
277 for (
int i = 0; i < operation_->parentUnit()->operationPortCount(); i++) {
279 if (operation_->isBound(*port)) {
280 int operand = operation_->io(*port);
281 operands_.insert(operand);
286 std::set<int>::const_iterator iter = operands_.begin();
287 bindList_->DeleteAllItems();
288 for (; iter != operands_.end(); iter++) {
289 wxString portName = _T(
"");
290 if (operation_->port(*iter) != NULL) {
295 bindList_->SetItem(0, 1, portName);
297 if (portChoice_->GetCount() > 1) {
298 portChoice_->SetSelection(1);
300 portChoice_->SetSelection(0);
303 onOperandSelection(
dummy);
316 if (resourceGrid_->IsSelection()) {
317 selected = resourceGrid_->GetSelectedRows().Item(0);
320 if (resourceGrid_->GetNumberCols() > 0) {
321 resourceGrid_->DeleteCols(0, resourceGrid_->GetNumberCols());
323 if (resourceGrid_->GetNumberRows() > 0) {
324 resourceGrid_->DeleteRows(0, resourceGrid_->GetNumberRows());
330 resourceGrid_->AppendCols(pipeline->
latency() + 50);
333 resourceGrid_->EnableEditing(
false);
336 for (
int i = 0; i < pipeline->
latency() + 50; i++) {
338 resourceGrid_->SetColSize(i, GRID_COLUMN_WIDTH);
342 std::list<string> resources;
345 resources.push_back(label);
349 std::list<string>::const_iterator iter = resources.begin();
350 for (; iter != resources.end(); iter++) {
356 for (
int cycle = 0; cycle < (pipeline->
latency() + 1); cycle++) {
358 for (iter = resources.begin(); iter != resources.end(); iter++) {
360 resourceGrid_->SetCellValue(row, cycle, USE_MARK);
367 newResources_.sort();
368 iter = newResources_.begin();
369 for (; iter != newResources_.end(); iter++) {
370 resourceGrid_->AppendRows();
376 resourceGrid_->SelectRow(selected);
379 resourceGrid_->FitInside();
398 if (usageGrid_->GetNumberCols() > 0) {
399 usageGrid_->DeleteCols(0, usageGrid_->GetNumberCols());
401 if (usageGrid_->GetNumberRows() > 0) {
402 usageGrid_->DeleteRows(0, usageGrid_->GetNumberRows());
405 usageGrid_->AppendCols(pipeline->
latency() + 50);
406 usageGrid_->AppendRows(operands_.size());
410 std::set<int>::const_iterator iter = operands_.begin();
411 for (; iter != operands_.end(); iter++) {
417 for (
int cycle = 0; cycle < pipeline->
latency() + 50; cycle++) {
419 usageGrid_->SetColSize(cycle, GRID_COLUMN_WIDTH);
420 usageGrid_->SetColLabelValue(
423 wxColour na = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
428 ExecutionPipeline::OperandSet::const_iterator iter =
431 for (; iter != operands.end(); iter++) {
432 int row = operandRow(*iter);
434 setOperandType(*iter,
true);
436 usageGrid_->SetCellValue(row, cycle, READ_MARK);
441 iter = operands.begin();
442 for (; iter != operands.end(); iter++) {
443 int row = operandRow(*iter);
445 setOperandType(*iter,
false);
447 usageGrid_->SetCellValue(row, cycle, WRITE_MARK);
451 usageGrid_->FitInside();
465 label.Append(_T(
" ("));
467 label.Append(READ_MARK);
469 label.Append(WRITE_MARK);
471 label.Append(_T(
")"));
472 int row = operandRow(operand);
474 usageGrid_->SetRowLabelValue(row , label);
485 for (std::list<string>::const_iterator iter = newResources_.begin();
486 iter != newResources_.end(); iter++) {
489 for (
int cycle = 0; cycle < pipeline->
latency(); cycle++) {
497 format fmt = prodeTexts->
text(
518 std::set<int>::const_iterator iter = operands_.begin();
519 for (; iter != operands_.end(); iter++) {
520 if (*iter == operand) {
537 if (event.GetId() == ID_RESOURCE_GRID) {
538 onResourceLClick(event);
539 }
else if (event.GetId() == ID_OPERAND_GRID) {
540 onOperandLClick(event);
551 if (event.GetId() == ID_RESOURCE_GRID) {
552 resourceGrid_->ClearSelection();
565 if (event.GetCol() < 0 || event.GetRow() < 0) {
570 int cycle =
event.GetCol();
571 string resource = selectedResource();
575 resourceGrid_->GetRowLabelValue(event.GetRow()))) {
577 resourceGrid_->SelectRow(event.GetRow());
581 if (operation_->pipeline()->isResourceUsed(resource, cycle)) {
587 format fmt = prodeTexts->
text(
594 if (!operation_->parentUnit()->hasPipelineElement(resource)) {
595 newResources_.push_back(resource);
603 format fmt = prodeTexts->
text(
612 updateResourceGrid();
613 resourceGrid_->SelectRow(event.GetRow());
624 int cycle =
event.GetCol();
626 std::set<int>::const_iterator iter = operands_.begin();
627 for (
int i = 0; i <
event.GetRow(); i++) {
628 assert(iter != operands_.end());
636 bool written =
false;
651 bool toggled =
false;
652 if (written ==
false && read ==
false) {
659 format fmt = prodeTexts->
text(
669 if (toggled ==
false && read ==
false && written ==
false) {
678 if (toggled ==
false && read ==
true && written ==
false) {
686 format fmt = prodeTexts->
text(
696 if (toggled ==
false && (read ==
true || written ==
true)) {
703 format fmt = prodeTexts->
text(
713 updateResourceGrid();
715 usageGrid_->MakeCellVisible(event.GetRow(), event.GetCol());
725 if (!TransferDataFromWindow()) {
730 wxString trimmedName = name_.Trim(
false).Trim(
true);
731 if (trimmedName == _T(
"")) {
738 wxString trimmedResourceName = resourceName_.Trim(
false).Trim(
true);
739 if (trimmedResourceName == _T(
"")) {
756 int number = numberControl_->GetValue();
758 std::pair<std::set<int>::iterator,
bool> result =
759 operands_.insert(number);
762 if (!result.second) {
764 format fmt = prodeTexts->
text(
773 numberControl_->SetValue(number + 1);
791 if (selected ==
"") {
805 format msgFmt = prodeTexts->
text(
810 int choice = dialog.ShowModal();
811 if (choice == wxID_YES) {
813 for (
int c = pipeline->
latency() - 1; c >= 0; c--) {
817 format fmt = prodeTexts->
text(
824 }
else if (choice != wxID_NO) {
831 FUPort* port = operation_->port(operand);
833 operation_->unbindPort(*port);
847 if (portChoice_->GetSelection() > 0) {
852 operation_->bindPort(number, *port);
854 FUPort* port = operation_->port(number);
856 operation_->unbindPort(*port);
871 portChoice_->Clear();
872 portChoice_->Append(_T(
"none"));
876 if (selected ==
"") {
887 for (
int i = 0; i < operation_->parentUnit()->operationPortCount();
892 if (!operation_->isBound(*port)) {
894 }
else if (operation_->io(*port) == operand) {
895 selection = portChoice_->Append(
899 portChoice_->SetSelection(selection);
912 if (resourceGrid_->IsSelection()) {
928 if (!resourceGrid_->IsSelection()) {
933 if (resourceGrid_->GetSelectedRows().Count() != 1) {
934 resourceGrid_->ClearSelection();
937 int row = resourceGrid_->GetSelectedRows().Item(0);
964 if (operation_->parentUnit()->hasPipelineElement(newName) ||
972 format functionUnit =
974 message % newName % component.str() % functionUnit.str();
976 message % component.str();
981 newResources_.push_back(newName);
982 updateResourceGrid();
983 dynamic_cast<wxTextCtrl*
>(
FindWindow(ID_RESOURCE_NAME))->Clear();
995 string selected = selectedResource();
998 if (selected ==
"" ||
1001 updateResourceGrid();
1007 operation_->pipeline()->removeResourceUse(selected);
1010 format fmt = prodeTexts->
text(
1017 updateResourceGrid();
1029 TransferDataFromWindow();
1040 warning.ShowModal();
1045 operation_->setName(newName);
1057 message % newName % component.str() % bus.str();
1059 message % component.str();
1068 warnOnResourcesWithoutUsages();
1079 latencyText_->SetLabel(latency);
1094 wxWindow *parent,
bool call_fit,
bool set_sizer) {
1096 wxFlexGridSizer *item0 =
new wxFlexGridSizer( 1, 0, 0 );
1097 item0->AddGrowableCol( 0 );
1098 item0->AddGrowableRow( 0 );
1100 wxFlexGridSizer *item1 =
new wxFlexGridSizer( 2, 0, 0 );
1101 item1->AddGrowableCol( 1 );
1102 item1->AddGrowableRow( 0 );
1104 wxFlexGridSizer *item2 =
new wxFlexGridSizer( 1, 0, 0 );
1105 item2->AddGrowableRow( 1 );
1107 wxBoxSizer *item3 =
new wxBoxSizer( wxHORIZONTAL );
1109 wxStaticText *item4 =
new wxStaticText( parent, ID_LABEL_NAME, wxT(
"Name:"), wxDefaultPosition, wxDefaultSize, 0 );
1110 item3->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
1112 wxTextCtrl *item5 =
new wxTextCtrl( parent, ID_NAME, wxT(
""), wxDefaultPosition, wxSize(160,-1), 0 );
1113 item3->Add( item5, 0, wxALIGN_CENTER, 5 );
1115 item2->Add( item3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
1117 wxStaticBox *item7 =
new wxStaticBox( parent, -1, wxT(
"Operands:") );
1118 wxStaticBoxSizer *item6 =
new wxStaticBoxSizer( item7, wxHORIZONTAL );
1119 operandSizer_ = item6;
1121 wxFlexGridSizer *item8 =
new wxFlexGridSizer( 1, 0, 0 );
1122 item8->AddGrowableRow( 0 );
1124 wxListCtrl *item9 =
new wxListCtrl( parent, ID_BIND_LIST, wxDefaultPosition, wxSize(200,300), wxLC_REPORT|wxSUNKEN_BORDER );
1125 item8->Add( item9, 0, wxGROW|wxALL, 5 );
1127 wxBoxSizer *item10 =
new wxBoxSizer( wxVERTICAL );
1129 wxBoxSizer *item11 =
new wxBoxSizer( wxHORIZONTAL );
1131 wxStaticText *item12 =
new wxStaticText( parent, ID_LABEL_PORT, wxT(
"Port:"), wxDefaultPosition, wxDefaultSize, 0 );
1132 item11->Add( item12, 0, wxALL, 5 );
1134 wxString *strs13 = (wxString*) NULL;
1135 wxChoice *item13 =
new wxChoice( parent, ID_PORT, wxDefaultPosition, wxSize(100,-1), 0, strs13, 0 );
1136 item11->Add( item13, 0, wxGROW|wxALL, 5 );
1138 wxButton *item14 =
new wxButton( parent, ID_DELETE_OPERAND, wxT(
"Delete"), wxDefaultPosition, wxDefaultSize, 0 );
1139 item11->Add( item14, 0, wxALL, 5 );
1141 item10->Add( item11, 0, wxGROW, 5 );
1143 wxStaticLine *item15 =
new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
1144 item10->Add( item15, 0, wxGROW|wxALL, 5 );
1146 wxBoxSizer *item16 =
new wxBoxSizer( wxHORIZONTAL );
1148 wxStaticText *item17 =
new wxStaticText( parent, ID_LABEL_OPERAND, wxT(
"New operand:"), wxDefaultPosition, wxDefaultSize, 0 );
1149 item16->Add( item17, 0, wxALL, 5 );
1151 wxSpinCtrl *item18 =
new wxSpinCtrl( parent, ID_NUMBER, wxT(
"1"), wxDefaultPosition, wxSize(-1,-1), 0, 1, 10000, 1 );
1152 item16->Add( item18, 0, wxGROW|wxALL, 5 );
1154 wxButton *item19 =
new wxButton( parent, ID_ADD_OPERAND, wxT(
"Add"), wxDefaultPosition, wxDefaultSize, 0 );
1155 item16->Add( item19, 0, wxALL, 5 );
1157 item10->Add( item16, 0, wxALIGN_CENTER, 5 );
1159 item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
1161 item6->Add( item8, 0, wxGROW, 5 );
1163 item2->Add( item6, 0, wxGROW, 5 );
1165 item1->Add( item2, 0, wxGROW|wxALL, 5 );
1167 wxFlexGridSizer *item20 =
new wxFlexGridSizer( 1, 0, 0 );
1168 item20->AddGrowableCol( 0 );
1169 item20->AddGrowableRow( 0 );
1170 item20->AddGrowableRow( 1 );
1172 wxStaticBox *item22 =
new wxStaticBox( parent, -1, wxT(
"Pipeline Resources:") );
1173 wxStaticBoxSizer *item21 =
new wxStaticBoxSizer( item22, wxHORIZONTAL );
1174 resourceSizer_ = item21;
1176 wxFlexGridSizer *item23 =
new wxFlexGridSizer( 1, 0, 0 );
1177 item23->AddGrowableCol( 0 );
1178 item23->AddGrowableRow( 0 );
1180 wxGrid *item24 =
new wxGrid( parent, ID_RESOURCE_GRID, wxDefaultPosition, wxSize(400,200), wxWANTS_CHARS );
1181 item24->CreateGrid( 0, 0, wxGrid::wxGridSelectRows );
1182 item23->Add( item24, 0, wxGROW|wxALL, 5 );
1184 wxBoxSizer *item25 =
new wxBoxSizer( wxHORIZONTAL );
1186 wxStaticText *item26 =
new wxStaticText( parent, ID_LABEL_RESOURCE_NAME, wxT(
"Name:"), wxDefaultPosition, wxDefaultSize, 0 );
1187 item25->Add( item26, 0, wxALIGN_CENTER|wxALL, 5 );
1189 wxTextCtrl *item27 =
new wxTextCtrl( parent, ID_RESOURCE_NAME, wxT(
""), wxDefaultPosition, wxDefaultSize, 0 );
1190 item25->Add( item27, 1, wxALIGN_CENTER|wxALL, 5 );
1192 wxButton *item28 =
new wxButton( parent, ID_ADD_RESOURCE, wxT(
"Add"), wxDefaultPosition, wxDefaultSize, 0 );
1193 item28->Enable(
false );
1194 item25->Add( item28, 0, wxALIGN_CENTER|wxALL, 5 );
1196 wxButton *item29 =
new wxButton( parent, ID_DELETE_RESOURCE, wxT(
"Delete"), wxDefaultPosition, wxDefaultSize, 0 );
1197 item29->Enable(
false );
1198 item25->Add( item29, 0, wxALIGN_CENTER|wxALL, 5 );
1202 item23->Add( item25, 0, wxGROW|wxALL, 5 );
1204 item21->Add( item23, 1, wxGROW, 5 );
1206 item20->Add( item21, 0, wxGROW|wxBOTTOM, 5 );
1208 wxStaticBox *item33 =
new wxStaticBox( parent, -1, wxT(
"Operand usage:") );
1209 wxStaticBoxSizer *item32 =
new wxStaticBoxSizer( item33, wxHORIZONTAL );
1210 usageSizer_ = item32;
1212 wxGrid *item34 =
new wxGrid( parent, ID_OPERAND_GRID, wxDefaultPosition, wxSize(400,200), wxWANTS_CHARS );
1213 item34->CreateGrid( 0, 0, wxGrid::wxGridSelectCells );
1214 item32->Add( item34, 1, wxGROW|wxALL, 5 );
1216 item20->Add( item32, 0, wxGROW, 5 );
1218 wxBoxSizer *item35 =
new wxBoxSizer( wxHORIZONTAL );
1220 wxStaticText *item36 =
new wxStaticText( parent, ID_LABEL_LATENCY, wxT(
"Operation latency:"), wxDefaultPosition, wxDefaultSize, 0 );
1221 item35->Add( item36, 0, wxALIGN_CENTER|wxALL, 5 );
1223 wxStaticText *item37 =
new wxStaticText( parent, ID_LATENCY, wxT(
" "), wxDefaultPosition, wxDefaultSize, 0 );
1224 item35->Add( item37, 0, wxALIGN_CENTER|wxALL, 5 );
1226 item20->Add( item35, 0, wxGROW|wxALL, 5 );
1228 item1->Add( item20, 0, wxGROW, 5 );
1230 item0->Add( item1, 0, wxGROW|wxALL, 5 );
1232 wxBoxSizer *item38 =
new wxBoxSizer( wxVERTICAL );
1234 wxStaticLine *item39 =
new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
1235 item38->Add( item39, 0, wxGROW|wxALL, 5 );
1237 wxGridSizer *item40 =
new wxGridSizer( 2, 0, 0 );
1239 wxButton *item41 =
new wxButton( parent, ID_HELP, wxT(
"&Help"), wxDefaultPosition, wxDefaultSize, 0 );
1240 item40->Add( item41, 0, wxALL, 5 );
1242 wxBoxSizer *item42 =
new wxBoxSizer( wxHORIZONTAL );
1244 wxButton *item43 =
new wxButton( parent, wxID_OK, wxT(
"&OK"), wxDefaultPosition, wxDefaultSize, 0 );
1245 item42->Add( item43, 0, wxALIGN_CENTER|wxALL, 5 );
1247 wxButton *item44 =
new wxButton( parent, wxID_CANCEL, wxT(
"&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
1248 item42->Add( item44, 0, wxALIGN_CENTER|wxALL, 5 );
1250 item40->Add( item42, 0, 0, 5 );
1252 item38->Add( item40, 0, wxGROW, 5 );
1254 item0->Add( item38, 0, wxGROW, 5 );
1257 parent->SetSizer( item0 );
1259 item0->SetSizeHints( parent );