OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdInfoView.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 OSEdInfoView.cc
26 *
27 * Definition of OSEdInfoView class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <vector>
34#include <boost/format.hpp>
35#include <set>
36
37#include "OSEdInfoView.hh"
38#include "WxConversion.hh"
39#include "OperationContainer.hh"
40#include "OSEdConstants.hh"
41#include "OperationModule.hh"
42#include "Application.hh"
43#include "OSEdTextGenerator.hh"
44#include "Environment.hh"
45#include "WidgetTools.hh"
46#include "DropDownMenu.hh"
47#include "OSEd.hh"
48#include "Operation.hh"
49#include "OperationIndex.hh"
50#include "TCEString.hh"
51#include "Operand.hh"
52
53using std::string;
54using std::vector;
55using std::set;
56using boost::format;
57
58BEGIN_EVENT_TABLE(OSEdInfoView, wxListCtrl)
60 EVT_RIGHT_DOWN(OSEdInfoView::onDropDownMenu)
62
63/**
64 * Constructor.
65 *
66 * @param parent Parent window.
67 */
68OSEdInfoView::OSEdInfoView(wxWindow* parent) :
69 wxListCtrl(
70 parent, OSEdConstants::CMD_INFO_VIEW, wxDefaultPosition,
71 wxSize(400,400),
72 wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER), mode_(MODE_NOMODE) {
73}
74
75
76/**
77 * Destructor.
78 */
81
82/**
83 * Clears the info screen.
84 */
85void
87 int columns = GetColumnCount();
88 for (int i = 0; i < columns; i++) {
89 DeleteColumn(0);
90 }
91 DeleteAllItems();
92}
93
94/**
95 * Shows the search path view.
96 */
97void
99
100 clear();
103 InsertColumn(
104 0, WxConversion::toWxString(fmt.str()), wxLIST_FORMAT_LEFT,
106
107 vector<string> paths = Environment::osalPaths();
108 for (size_t i = 0; i < paths.size(); i++) {
109 wxListItem item;
110 if (FileSystem::fileExists(paths[i])) {
111 // path exists, let's write it bold
112 wxFont boldFont = wxFont(10, wxROMAN, wxNORMAL, wxBOLD);
113 item.SetFont(boldFont);
114 }
115 item.SetId(i);
116 int index = InsertItem(item);
117 SetItemText(index, WxConversion::toWxString(paths[i]));
118 }
119
121}
122
123/**
124 * Shows the module view.
125 *
126 * @param The name of the path.
127 */
128void
129OSEdInfoView::moduleView(const std::string& name) {
130
132 clear();
135 InsertColumn(
136 0, WxConversion::toWxString(fmt.str()), wxLIST_FORMAT_LEFT,
138
139 int modules = 0;
140 try {
141 modules = index.moduleCount(name);
142 } catch (const PathNotFound& p) {
143 // path not found
144 }
145
146 for (int i = 0; i < modules; i++) {
147 OperationModule& module = index.module(i, name);
148 InsertItem(i, WxConversion::toWxString(module.name()));
149 }
150
152}
153
154/**
155 * Shows the operation view.
156 *
157 * @param path The path of the module.
158 * @param mod The name of the module.
159 */
160void
161OSEdInfoView::operationView(const std::string& path, const std::string& mod) {
162
164 OperationModule& module = OperationContainer::module(path, mod);
165 clear();
168 InsertColumn(
169 0, WxConversion::toWxString(fmt.str()), wxLIST_FORMAT_LEFT,
171
172 int operations = 0;
173 try {
174 operations = index.operationCount(module);
175 } catch (const Exception& e) {
176 return;
177 }
178 for (int j = 0; j < operations; j++) {
179 string name = index.operationName(j, module);
180 wxListItem item;
181 if (OperationContainer::isEffective(module, name)) {
182 // operation is effective, let's put it with bold font
183 wxFont boldFont = wxFont(10, wxROMAN, wxNORMAL, wxBOLD);
184 item.SetFont(boldFont);
185 }
186 item.SetId(j);
187 int index = InsertItem(item);
188 SetItemText(index, WxConversion::toWxString(name));
189 }
190
192}
193
194/**
195 * Shows the operation properties of an operation.
196 *
197 * @param opName The name of the operation.
198 * @param modName The name of the module.
199 * @param pathName The name of the path.
200 */
201void
203 const std::string& opName,
204 const std::string& modName,
205 const std::string& pathName) {
206
207 clear();
208
210 format yesFmt = texts.text(OSEdTextGenerator::TXT_ROW_YES);
211 format noFmt = texts.text(OSEdTextGenerator::TXT_ROW_NO);
212 format trueFmt = texts.text(OSEdTextGenerator::TXT_ROW_TRUE);
213 format falseFmt = texts.text(OSEdTextGenerator::TXT_ROW_FALSE);
214
215 Operation* op = OperationContainer::operation(pathName, modName, opName);
216
217 // insert columns
219
220 if (op == NULL) {
221 // operation properties can not be loaded
222 return;
223 }
224
225 // write "static" properties
227
228 format fmt;
229
230 // affected by
231 for (int k = 0; k < op->affectedByCount(); k++) {
232 if (k == 0) {
234 InsertItem(i, WxConversion::toWxString(fmt.str()));
235 } else {
236 InsertItem(i, _T(""));
237 }
238 SetItem(i, 1, WxConversion::toWxString(op->affectedBy(k)));
239 i++;
240 }
241
242 // affects
243 for (int k = 0; k < op->affectsCount(); k++) {
244 if (k == 0) {
246 InsertItem(i, WxConversion::toWxString(fmt.str()));
247 } else {
248 InsertItem(i, _T(""));
249 }
250 SetItem(i, 1, WxConversion::toWxString(op->affects(k)));
251 i++;
252 }
253
255 InsertItem(i, WxConversion::toWxString(fmt.str()));
256 i++;
257
258 // input operands
259 for (int j = 1; j <= op->numberOfInputs(); j++) {
260 Operand& operand = op->operand(j);
261 InsertItem(i, _T(""));
262 wxString index = WxConversion::toWxString(j);
264 index.Prepend(WxConversion::toWxString(fmt.str()));
265 SetItem(i, 1, index);
266 i++;
267
268 InsertItem(i, _T(""));
270 SetItem(i, 1, WxConversion::toWxString(fmt.str()));
271 SetItem(i, 2, WxConversion::toWxString(operand.typeString()));
272 i++;
273
274 InsertItem(i, _T(""));
276 SetItem(i, 1, WxConversion::toWxString(fmt.str()));
277
278 // is operand address?
279 if (operand.isAddress()) {
280 SetItem(i, 2, WxConversion::toWxString(yesFmt.str()));
281 } else {
282 SetItem(i, 2, WxConversion::toWxString(noFmt.str()));
283 }
284 i++;
285
286 InsertItem(i, _T(""));
288 SetItem(i, 1, WxConversion::toWxString(fmt.str()));
289
290 // is operand memory data?
291 if (operand.isMemoryData()) {
292 SetItem(i, 2, WxConversion::toWxString(yesFmt.str()));
293 } else {
294 SetItem(i, 2, WxConversion::toWxString(noFmt.str()));
295 }
296
297 i++;
298 set<int> canSwap = operand.swap();
299 set<int>::iterator it = canSwap.begin();
300
301 // can swap list
302 while (it != canSwap.end()) {
303 wxString opId = WxConversion::toWxString(*it);
304 opId.Prepend(_T("id: "));
305 if (it == canSwap.begin()) {
306 InsertItem(i, _T(""));
308 SetItem(i, 1, WxConversion::toWxString(fmt.str()));
309 SetItem(i, 2, opId);
310
311 } else {
312 InsertItem(i, _T(""));
313 SetItem(i, 2, opId);
314 }
315 i++;
316 it++;
317 }
318 }
319
321 InsertItem(i, WxConversion::toWxString(fmt.str()));
322 i++;
323
324 // outputs
325 for (int j = op->numberOfInputs() + 1;
326 j <= op->numberOfOutputs() + op->numberOfInputs(); j++) {
327
328 Operand& operand = op->operand(j);
329 InsertItem(i, _T(""));
330 wxString opId = WxConversion::toWxString(j);
332 opId.Prepend(WxConversion::toWxString(fmt.str()));
333 SetItem(i, 1, opId);
334 i++;
335
336 InsertItem(i, _T(""));
338 SetItem(i, 1, WxConversion::toWxString(fmt.str()));
339 SetItem(i, 2, WxConversion::toWxString(operand.typeString()));
340 i++;
341
342 InsertItem(i, _T(""));
344 SetItem(i, 1, WxConversion::toWxString(fmt.str()));
345
346 // is operand memory data?
347 if (operand.isMemoryData()) {
348 SetItem(i, 2, WxConversion::toWxString(yesFmt.str()));
349 } else {
350 SetItem(i, 2, WxConversion::toWxString(noFmt.str()));
351 }
352 i++;
353 }
354
356 InsertItem(i, WxConversion::toWxString(fmt.str()));
357
358 if (op->canBeSimulated()) {
359 SetItem(i, 1, WxConversion::toWxString(yesFmt.str()));
360 } else {
361 SetItem(i, 1, WxConversion::toWxString(noFmt.str()));
362 }
363
364 delete op;
366}
367
368/**
369 * Inserts columns in operation property view.
370 */
371void
375 InsertColumn(
376 0, WxConversion::toWxString(fmt.str()), wxLIST_FORMAT_LEFT,
378
380 InsertColumn(
381 1, WxConversion::toWxString(fmt.str()), wxLIST_FORMAT_LEFT,
383
385 InsertColumn(
386 2, WxConversion::toWxString(fmt.str()), wxLIST_FORMAT_LEFT,
388}
389
390/**
391 * Writes the "static" operation properties in operation property view
392 *
393 * @param op Operation which static properties are written.
394 *
395 * @return Number of written properties.
396 */
397int
399
401
402 format trueFmt = texts.text(OSEdTextGenerator::TXT_ROW_TRUE);
403 format falseFmt = texts.text(OSEdTextGenerator::TXT_ROW_FALSE);
404
405 // row counter
406 int i = 0;
407
408 // name of the operation
409 format fmt = texts.text(OSEdTextGenerator::TXT_ROW_NAME);
410 InsertItem(i, WxConversion::toWxString(fmt.str()));
411 SetItem(i, 1, WxConversion::toWxString(op->name()));
412 i++;
413
414 // description of the operation
416 InsertItem(i, WxConversion::toWxString(fmt.str()));
417 SetItem(i, 1, WxConversion::toWxString(op->description()));
418 i++;
419
420 // number of inputs
422 InsertItem(i, WxConversion::toWxString(fmt.str()));
423 SetItem(i, 1, WxConversion::toWxString(op->numberOfInputs()));
424 i++;
425
426 // number of outputs
428 InsertItem(i, WxConversion::toWxString(fmt.str()));
429 SetItem(i, 1, WxConversion::toWxString(op->numberOfOutputs()));
430 i++;
431
432 // reads memory
434 InsertItem(i, WxConversion::toWxString(fmt.str()));
435 if (op->readsMemory()) {
436 SetItem(i, 1, WxConversion::toWxString(trueFmt.str()));
437 } else {
438 SetItem(i, 1, WxConversion::toWxString(falseFmt.str()));
439 }
440 i++;
441
442 // writes memory
444 InsertItem(i, WxConversion::toWxString(fmt.str()));
445 if (op->writesMemory()) {
446 SetItem(i, 1, WxConversion::toWxString(trueFmt.str()));
447 } else {
448 SetItem(i, 1, WxConversion::toWxString(falseFmt.str()));
449 }
450 i++;
451
452 // can trap
454 InsertItem(i, WxConversion::toWxString(fmt.str()));
455 if (op->canTrap()) {
456 SetItem(i, 1, WxConversion::toWxString(trueFmt.str()));
457 } else {
458 SetItem(i, 1, WxConversion::toWxString(falseFmt.str()));
459 }
460 i++;
461
462 // has side effects
464 InsertItem(i, WxConversion::toWxString(fmt.str()));
465 if (op->hasSideEffects()) {
466 SetItem(i, 1, WxConversion::toWxString(trueFmt.str()));
467 } else {
468 SetItem(i, 1, WxConversion::toWxString(falseFmt.str()));
469 }
470 i++;
471
472 // is clocked
474 InsertItem(i, WxConversion::toWxString(fmt.str()));
475 if (op->isClocked()) {
476 SetItem(i, 1, WxConversion::toWxString(trueFmt.str()));
477 } else {
478 SetItem(i, 1, WxConversion::toWxString(falseFmt.str()));
479 }
480 i++;
481
482 return i;
483}
484
485/**
486 * Returns the selected path.
487 *
488 * If path is not selected returns an empty string.
489 *
490 * @return The selected path.
491 */
492string
494
495 if (mode_ != MODE_PATH || GetSelectedItemCount() != 1) {
496 return "";
497 }
498
499 return WidgetTools::lcStringSelection(this, 0);
500}
501
502/**
503 * Returns the selected module.
504 *
505 * If no module is selected, returns an empty string.
506 *
507 * @return The selected module.
508 */
509string
511
512 if (mode_ != MODE_MODULE || GetSelectedItemCount() != 1) {
513 return "";
514 }
515 return WidgetTools::lcStringSelection(this, 0);
516}
517
518/**
519 * Returns the selected operation.
520 *
521 * If no operation is selected, return empty string.
522 *
523 * @return The selected operation.
524 */
525string
527
528 if(mode_ != MODE_OPERATION || GetSelectedItemCount() != 1) {
529 return "";
530 }
531 return WidgetTools::lcStringSelection(this, 0);
532}
533
534/**
535 * Handles the event when list item is selected.
536 */
537void
539 if (GetSelectedItemCount() == 1) {
541 OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
542 mainFrame->updateMenuBar();
543 switch (mode_) {
544 case MODE_PATH: {
545 format fmt =
547 mainFrame->statusBar()->
548 SetStatusText(WxConversion::toWxString(fmt.str()));
549 }
550 break;
551 case MODE_MODULE: {
552 format fmt =
554 mainFrame->statusBar()->
555 SetStatusText(WxConversion::toWxString(fmt.str()));
556 }
557 break;
558 case MODE_OPERATION: {
559 format fmt =
561 mainFrame->statusBar()->
562 SetStatusText(WxConversion::toWxString(fmt.str()));
563 }
564 break;
565 default:
566 break;
567 }
568 }
569}
570
571/**
572 * Handles the event when list item is clicked with right mouse button.
573 *
574 * Then the drop down menu is shown.
575 *
576 * @param event Event to be handled.
577 */
578void
579OSEdInfoView::onDropDownMenu(wxMouseEvent& event) {
580
581 if (GetSelectedItemCount() <= 1 && mode_ != MODE_PROPERTY) {
582 // deselect the selected item
583 long item = -1;
584 item = GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
585 if (item != -1) {
586 SetItemState(item, 0, wxLIST_STATE_SELECTED);
587 }
588
589 wxPoint pos = event.GetPosition();
590 int flags = wxLIST_HITTEST_ONITEMLABEL;
591 item = -1;
592 item = HitTest(pos, flags);
593
595 OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
596 DropDownMenu* menu = NULL;
597 if (item != -1) {
598 // select the item that was clicked
599 SetItemState(item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
600 switch(mode_) {
601 case MODE_PATH: {
602 format fmt =
604 mainFrame->statusBar()->
605 SetStatusText(WxConversion::toWxString(fmt.str()));
607 PopupMenu(menu, pos);
608 }
609 break;
610 case MODE_MODULE: {
611 format fmt =
613 mainFrame->statusBar()->
614 SetStatusText(WxConversion::toWxString(fmt.str()));
616 PopupMenu(menu, pos);
617 }
618 break;
619 case MODE_OPERATION: {
620 format fmt =
622 mainFrame->statusBar()->
623 SetStatusText(WxConversion::toWxString(fmt.str()));
625 PopupMenu(menu, pos);
626 }
627 break;
628 default:
629 break;
630 }
631 }
632 delete menu;
633 }
634}
END_EVENT_TABLE() using namespace IDF
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
@ MENU_MODULE
Module menu.
@ MENU_OPERATION
Operation menu.
@ MENU_PATH
Path menu.
static std::vector< std::string > osalPaths()
static bool fileExists(const std::string fileName)
static const int DEFAULT_COLUMN_WIDTH
Default column width.
@ CMD_INFO_VIEW
Id for list events.
void insertOperationPropertyColumns()
void onDropDownMenu(wxMouseEvent &event)
std::string selectedOperation()
void operationView(const std::string &path, const std::string &mod)
void moduleView(const std::string &name)
std::string selectedModule()
virtual ~OSEdInfoView()
int writeStaticPropertiesOfOperation(Operation *op)
void operationPropertyView(const std::string &opName, const std::string &modName, const std::string &pathName)
void onSelection(wxListEvent &event)
InfoMode mode_
Mode of the info view.
std::string selectedPath()
@ MODE_PATH
Path view.
@ MODE_PROPERTY
Operation property view.
@ MODE_OPERATION
Operation View.
@ MODE_MODULE
Module view.
wxStatusBar * statusBar() const
static OSEdTextGenerator & instance()
@ TXT_ROW_NAME
Name row label.
@ TXT_COLUMN_OPERATIONS
Operations column header.
@ TXT_ROW_HAS_BEHAVIOR
Has behavior row label.
@ TXT_ROW_AFFECTS
Affects row label.
@ TXT_STATUS_MODULE_SELECTED
Status bar text when module is selected.
@ TXT_COLUMN_PROPERTY
Property column header.
@ TXT_ROW_DESCRIPTION
Description row label.
@ TXT_COLUMN_SEARCH_PATHS
Search path column header.
@ TXT_ROW_TYPE
Type row label.
@ TXT_ROW_OUTPUT_OPERANDS
Output operands row label.
@ TXT_ROW_MEMORY_ADDRESS
Memory address row label.
@ TXT_COLUMN_MODULES
Module column header.
@ TXT_ROW_ID
Id row label.
@ TXT_STATUS_OPERATION_SELECTED
Status bar text when operation is selected.
@ TXT_COLUMN_OPERAND_VALUE
Operand value column header.
@ TXT_ROW_CAN_SWAP
Can swap row label.
@ TXT_ROW_CLOCKED
Clocked row label.
@ TXT_ROW_HAS_SIDE_EFFECTS
Has side effects row label.
@ TXT_COLUMN_VALUE
Value column header.
@ TXT_ROW_INPUTS
Inputs row label.
@ TXT_ROW_OUTPUTS
Outputs row label.
@ TXT_STATUS_PATH_SELECTED
Status bar text when path is selected.
@ TXT_ROW_INPUT_OPERANDS
Input operands row label.
@ TXT_ROW_READS_MEMORY
Reads memory row label.
@ TXT_ROW_CAN_TRAP
Can trap row label.
@ TXT_ROW_AFFECTED_BY
Affected by row label.
@ TXT_ROW_WRITES_MEMORY
Writes memory row label.
@ TXT_ROW_MEMORY_DATA
Memory data row label.
virtual const std::string & typeString() const
Definition Operand.cc:185
virtual bool isMemoryData() const
Definition Operand.cc:351
virtual bool isAddress() const
Definition Operand.cc:328
virtual const std::set< int > & swap() const
Definition Operand.cc:361
static bool isEffective(OperationModule &module, const std::string &name)
static Operation * operation(const std::string &path, const std::string &module, const std::string &oper)
static OperationIndex & operationIndex()
std::string operationName(int i, const OperationModule &om)
int operationCount(const OperationModule &om)
int moduleCount() const
virtual bool readsMemory() const
Definition Operation.cc:242
virtual TCEString name() const
Definition Operation.cc:93
virtual int affectedByCount() const
Definition Operation.cc:416
virtual TCEString description() const
Definition Operation.cc:103
virtual TCEString affectedBy(unsigned int i) const
Definition Operation.cc:447
virtual bool canTrap() const
Definition Operation.cc:262
virtual bool hasSideEffects() const
Definition Operation.cc:272
virtual int affectsCount() const
Definition Operation.cc:402
virtual bool isClocked() const
Definition Operation.cc:282
virtual bool writesMemory() const
Definition Operation.cc:252
virtual int numberOfInputs() const
Definition Operation.cc:192
virtual bool canBeSimulated() const
Definition Operation.cc:612
virtual TCEString affects(unsigned int i) const
Definition Operation.cc:431
virtual int numberOfOutputs() const
Definition Operation.cc:202
virtual Operand & operand(int id) const
Definition Operation.cc:541
virtual boost::format text(int textId)
static std::string lcStringSelection(wxListCtrl *list, int column)
static wxString toWxString(const std::string &source)