OpenASIP  2.0
ResultDialog.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 ResultDialog.cc
26  *
27  * Definition of ResultDialog class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <boost/format.hpp>
34 
35 #include "ResultDialog.hh"
36 #include "OSEdTextGenerator.hh"
37 #include "GUITextGenerator.hh"
38 #include "WxConversion.hh"
39 #include "WidgetTools.hh"
40 #include "DialogPosition.hh"
41 #include "ErrorDialog.hh"
42 #include "CommandThread.hh"
43 #include "FileSystem.hh"
44 #include "OSEd.hh"
45 #include "OSEdOptions.hh"
46 
47 using boost::format;
48 using std::string;
49 using std::vector;
50 
51 BEGIN_EVENT_TABLE(ResultDialog, wxDialog)
52  EVT_BUTTON(ID_BUTTON_OPEN, ResultDialog::onOpen)
54 
55 /**
56  * Constructor.
57  *
58  * @param parent Parent window.
59  */
61  wxWindow* parent,
62  std::vector<std::string> output,
63  const std::string& title,
64  const std::string& module) :
65  wxDialog(parent, -1, _T(""),
66  DialogPosition::getPosition(DialogPosition::DIALOG_RESULT),
67  wxDefaultSize, wxRESIZE_BORDER),
68  output_(output), module_(module) {
69 
70  createContents(this, true, true);
71  result_ = dynamic_cast<wxTextCtrl*>(FindWindow(ID_RESULT));
72  result_->SetEditable(false);
73 
74  FindWindow(wxID_OK)->SetFocus();
75  SetTitle(WxConversion::toWxString(title));
76  if (module_ == "") {
77  FindWindow(ID_BUTTON_OPEN)->Disable();
78  }
79  setTexts();
80 }
81 
82 /**
83  * Destructor.
84  */
86  int x, y;
87  GetPosition(&x, &y);
88  wxPoint point(x, y);
90 }
91 
92 /**
93  * Set texts to widgets.
94  */
95 void
97 
100 
101  // buttons
102  WidgetTools::setLabel(&guiText, FindWindow(wxID_OK),
104 
107 }
108 
109 /**
110  * Transfer data to window.
111  *
112  * @return True if transfer is successful.
113  */
114 bool
116  for (size_t i = 0; i < output_.size(); i++) {
117  result_->AppendText(WxConversion::toWxString(output_[i]));
118  }
119  return wxWindow::TransferDataToWindow();
120 }
121 
122 /**
123  * Handles the event when Open button is pushed.
124  */
125 void
126 ResultDialog::onOpen(wxCommandEvent&) {
127 
129  OSEdOptions* options = wxGetApp().options();
130  string editor = options->editor();
131  if (editor == "") {
132  format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_NO_EDITOR);
133  ErrorDialog error(this, WxConversion::toWxString(fmt.str()));
134  error.ShowModal();
135  } else {
136  if (FileSystem::fileExists(editor)) {
137  string cmd = editor + " " + module_;
138  CommandThread* thread = new CommandThread(cmd);
139  thread->Create();
140  thread->Run();
141  } else {
142  format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_OPEN);
143  fmt % editor;
144  ErrorDialog dialog(this, WxConversion::toWxString(fmt.str()));
145  dialog.ShowModal();
146  }
147  }
148 }
149 
150 /**
151  * Creates the contents of the dialog.
152  *
153  * NOTE! This function was generated by wxDesigner.
154  *
155  * @param parent Parent window.
156  * @param call_fit If true fits the contents inside the dialog.
157  * @param set_sizer If true, sets the main sizer as contents of dialog.
158  * @return The created sizer.
159  */
160 wxSizer*
162  wxWindow *parent,
163  bool call_fit,
164  bool set_sizer) {
165 
166  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
167 
168  wxTextCtrl *item1 = new wxTextCtrl( parent, ID_RESULT, wxT(""), wxDefaultPosition, wxSize(400,100), wxTE_MULTILINE );
169  item0->Add( item1, 1, wxGROW|wxALL, 5 );
170 
171  wxBoxSizer *item2 = new wxBoxSizer( wxHORIZONTAL );
172 
173  wxButton *item3 = new wxButton( parent, ID_BUTTON_OPEN, wxT("Open"), wxDefaultPosition, wxDefaultSize, 0 );
174  item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
175 
176  wxButton *item4 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
177  item2->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
178 
179  item0->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
180 
181  if (set_sizer)
182  {
183  parent->SetSizer( item0 );
184  if (call_fit)
185  item0->SetSizeHints( parent );
186  }
187 
188  return item0;
189 }
FileSystem.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
CommandThread.hh
WidgetTools::setLabel
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
Definition: WidgetTools.cc:92
GUITextGenerator::instance
static GUITextGenerator * instance()
Definition: GUITextGenerator.cc:67
GUITextGenerator
Definition: GUITextGenerator.hh:46
WidgetTools.hh
OSEd.hh
ResultDialog::output_
std::vector< std::string > output_
Output of compilation.
Definition: ResultDialog.hh:75
FindWindow
Definition: FindWindow.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
DialogPosition::setPosition
static void setPosition(Dialogs dialog, wxPoint point)
Definition: DialogPosition.cc:63
ResultDialog.hh
ResultDialog::~ResultDialog
virtual ~ResultDialog()
Definition: ResultDialog.cc:85
ErrorDialog
Definition: ErrorDialog.hh:42
OSEdTextGenerator::TXT_BUTTON_OPEN
@ TXT_BUTTON_OPEN
Open button label.
Definition: OSEdTextGenerator.hh:71
ErrorDialog.hh
ResultDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: ResultDialog.cc:161
ResultDialog::module_
std::string module_
Module which was compiled or empty string, if all modules were compiled.
Definition: ResultDialog.hh:78
OSEdTextGenerator::TXT_ERROR_NO_EDITOR
@ TXT_ERROR_NO_EDITOR
Error when no editor is given.
Definition: OSEdTextGenerator.hh:140
ResultDialog
Definition: ResultDialog.hh:44
DialogPosition
Definition: DialogPosition.hh:42
ResultDialog::result_
wxTextCtrl * result_
Result window pointer.
Definition: ResultDialog.hh:73
OSEdTextGenerator::TXT_ERROR_OPEN
@ TXT_ERROR_OPEN
Error when opening fails.
Definition: OSEdTextGenerator.hh:141
ResultDialog::setTexts
void setTexts()
Definition: ResultDialog.cc:96
GUITextGenerator.hh
CommandThread
Definition: CommandThread.hh:43
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
ResultDialog::onOpen
void onOpen(wxCommandEvent &event)
Definition: ResultDialog.cc:126
ResultDialog::ID_BUTTON_OPEN
@ ID_BUTTON_OPEN
Definition: ResultDialog.hh:69
DialogPosition::DIALOG_RESULT
@ DIALOG_RESULT
Result dialog.
Definition: DialogPosition.hh:52
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
ResultDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: ResultDialog.cc:115
FileSystem::fileExists
static bool fileExists(const std::string fileName)
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OSEdOptions.hh
OSEdOptions
Definition: OSEdOptions.hh:46
ResultDialog::ID_RESULT
@ ID_RESULT
Definition: ResultDialog.hh:68
OSEdTextGenerator.hh
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59
DialogPosition.hh