OpenASIP  2.0
OSEdOptionsDialog.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 src/codesign/osal/OSEd/OSEdOptionsDialog.cc
26  *
27  * Definition of OSEdOptionsDialog class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/valgen.h>
34 #include <wx/filedlg.h>
35 #include <boost/format.hpp>
36 #include <string>
37 
38 #include "OSEdOptionsDialog.hh"
39 #include "WxConversion.hh"
40 #include "GUITextGenerator.hh"
41 #include "OSEdTextGenerator.hh"
42 #include "WidgetTools.hh"
43 #include "OSEd.hh"
44 #include "OSEdOptionsSerializer.hh"
45 #include "ErrorDialog.hh"
46 #include "OSEdConstants.hh"
47 #include "DialogPosition.hh"
48 #include "Environment.hh"
49 #include "FileSystem.hh"
50 #include "OSEdOptions.hh"
51 
52 using boost::format;
53 using std::string;
54 
55 BEGIN_EVENT_TABLE(OSEdOptionsDialog, wxDialog)
56 
57  EVT_BUTTON(ID_BUTTON_SAVE, OSEdOptionsDialog::onSave)
58  EVT_BUTTON(ID_BUTTON_BROWSE, OSEdOptionsDialog::onBrowse)
59 
61 
62 /**
63  * Constructor.
64  *
65  * @param parent The parent window.
66  */
68  wxDialog(parent, -1, _T(""),
69  DialogPosition::getPosition(DialogPosition::DIALOG_OPTIONS),
70  wxSize(400, 200)) {
71 
72  createContents(this, true, true);
73 
74  FindWindow(ID_EDITOR)->
75  SetValidator(wxTextValidator(wxFILTER_ASCII, &editor_));
76 
77  setTexts();
78 }
79 
80 /**
81  * Destructor.
82  */
84  int x, y;
85  GetPosition(&x, &y);
86  wxPoint point(x, y);
88 }
89 
90 /**
91  * Set texts to all widgets.
92  */
93 void
97 
98  // title
100  SetTitle(WxConversion::toWxString(fmt.str()));
101 
104 
105  // buttons
106  WidgetTools::setLabel(&guiText, FindWindow(wxID_CANCEL),
108 
111 
114 }
115 
116 /**
117  * Transfers data to window.
118  *
119  * @return True if all is successful.
120  */
121 bool
123  OSEdOptions* options = wxGetApp().options();
125  return wxWindow::TransferDataToWindow();
126 }
127 
128 /**
129  * Handles the event when Save button is pushed.
130  */
131 void
132 OSEdOptionsDialog::onSave(wxCommandEvent&) {
133  TransferDataFromWindow();
134  wxGetApp().options()->setEditor(WxConversion::toString(editor_));
135  OSEdOptionsSerializer serializer;
137  serializer.setDestinationFile(confFile);
138  try {
139  serializer.writeState(wxGetApp().options()->saveState());
140  } catch (const Exception& e) {
143  ErrorDialog dialog(this, WxConversion::toWxString(fmt.str()));
144  dialog.ShowModal();
145  }
146  EndModal(wxID_OK);
147 }
148 
149 /**
150  * Handles the event when Browse button is pushed.
151  */
152 void
153 OSEdOptionsDialog::onBrowse(wxCommandEvent&) {
154 
156  wxFileDialog dialog(this, _T("Choose a file"),
158  if (dialog.ShowModal() == wxID_OK) {
159  editor_ = dialog.GetPath();
160  wxWindow::TransferDataToWindow();
161  }
162 }
163 
164 /**
165  * Creates the contents of the dialog.
166  *
167  * @param parent Parent window.
168  * @param call_fit If true fits the contents inside the dialog.
169  * @param set_sizer If true sets the main sizer as dialog contents.
170  * @return The created sizer.
171  */
172 wxSizer*
174  wxWindow *parent,
175  bool call_fit,
176  bool set_sizer) {
177 
178  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
179 
180  item0->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
181 
182  wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
183 
184  wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, wxT("Source code editor:"), wxDefaultPosition, wxDefaultSize, 0 );
185  item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
186 
187  wxTextCtrl *item3 = new wxTextCtrl( parent, ID_EDITOR, wxT(""), wxDefaultPosition, wxSize(150,-1), 0 );
188  item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
189 
190  wxButton *item4 = new wxButton( parent, ID_BUTTON_BROWSE, wxT("Browse"), wxDefaultPosition, wxDefaultSize, 0 );
191  item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
192 
193  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
194 
195  item0->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
196 
197  wxBoxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
198 
199  wxButton *item6 = new wxButton( parent, ID_BUTTON_SAVE, wxT("&Save"), wxDefaultPosition, wxDefaultSize, 0 );
200  item5->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
201 
202  wxButton *item7 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
203  item5->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
204 
205  item0->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
206 
207  if (set_sizer)
208  {
209  parent->SetSizer( item0 );
210  if (call_fit)
211  item0->SetSizeHints( parent );
212  }
213 
214  return item0;
215 }
OSEdTextGenerator::TXT_ERROR_CAN_NOT_SAVE
@ TXT_ERROR_CAN_NOT_SAVE
Error when options can not be saved.
Definition: OSEdTextGenerator.hh:142
FileSystem.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
OSEdOptionsDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: OSEdOptionsDialog.cc:173
OSEdOptionsSerializer::writeState
virtual void writeState(const ObjectState *state)
Definition: OSEdOptionsSerializer.cc:55
OSEdOptionsDialog::~OSEdOptionsDialog
virtual ~OSEdOptionsDialog()
Definition: OSEdOptionsDialog.cc:83
OSEdOptionsDialog::setTexts
void setTexts()
Definition: OSEdOptionsDialog.cc:94
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
OSEdOptionsDialog::onSave
void onSave(wxCommandEvent &event)
Definition: OSEdOptionsDialog.cc:132
GUITextGenerator
Definition: GUITextGenerator.hh:46
WidgetTools.hh
OSEd.hh
FindWindow
Definition: FindWindow.hh:49
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
OSEdOptionsDialog::ID_BUTTON_BROWSE
@ ID_BUTTON_BROWSE
Definition: OSEdOptionsDialog.hh:65
DialogPosition::setPosition
static void setPosition(Dialogs dialog, wxPoint point)
Definition: DialogPosition.cc:63
OSEdConstants.hh
OSEdTextGenerator::TXT_OPTIONS_DIALOG_TITLE
@ TXT_OPTIONS_DIALOG_TITLE
Options dialog title.
Definition: OSEdTextGenerator.hh:114
Environment::userConfPath
static TCEString userConfPath(const std::string &fileName)
Definition: Environment.cc:303
OSEdOptionsDialog
Definition: OSEdOptionsDialog.hh:41
OSEdTextGenerator::TXT_BUTTON_BROWSE
@ TXT_BUTTON_BROWSE
Browse button label.
Definition: OSEdTextGenerator.hh:79
OSEdOptionsDialog::ID_TEXT
@ ID_TEXT
Definition: OSEdOptionsDialog.hh:62
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
ErrorDialog
Definition: ErrorDialog.hh:42
ErrorDialog.hh
FileSystem::directoryOfPath
static std::string directoryOfPath(const std::string fileName)
Definition: FileSystem.cc:79
DialogPosition
Definition: DialogPosition.hh:42
Environment.hh
OSEdOptionsSerializer::setDestinationFile
void setDestinationFile(const std::string &fileName)
Definition: OSEdOptionsSerializer.cc:99
OSEdOptionsSerializer
Definition: OSEdOptionsSerializer.hh:44
Exception
Definition: Exception.hh:54
OSEdOptionsDialog.hh
DialogPosition::DIALOG_OPTIONS
@ DIALOG_OPTIONS
Options dialog.
Definition: DialogPosition.hh:53
GUITextGenerator.hh
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
OSEdOptionsDialog::onBrowse
void onBrowse(wxCommandEvent &event)
Definition: OSEdOptionsDialog.cc:153
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
OSEdOptionsSerializer.hh
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTextGenerator::TXT_LABEL_EDITOR
@ TXT_LABEL_EDITOR
Editor label.
Definition: OSEdTextGenerator.hh:58
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OSEdOptionsDialog::editor_
wxString editor_
The name of the editor.
Definition: OSEdOptionsDialog.hh:69
OSEdOptions.hh
OSEdOptions
Definition: OSEdOptions.hh:46
OSEdOptionsDialog::ID_BUTTON_SAVE
@ ID_BUTTON_SAVE
Definition: OSEdOptionsDialog.hh:64
OSEdOptionsDialog::ID_EDITOR
@ ID_EDITOR
Definition: OSEdOptionsDialog.hh:63
OSEdTextGenerator::TXT_BUTTON_SAVE
@ TXT_BUTTON_SAVE
Save button label.
Definition: OSEdTextGenerator.hh:75
WxConversion::toString
static std::string toString(const wxString &source)
OSEdTextGenerator.hh
OSEdConstants::CONF_FILE_NAME
static const std::string CONF_FILE_NAME
Configuration file name.
Definition: OSEdConstants.hh:78
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
OSEdOptionsDialog::TransferDataToWindow
bool TransferDataToWindow()
Definition: OSEdOptionsDialog.cc:122
DialogPosition.hh