OpenASIP  2.0
AddModuleDialog.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 AddModuleDialog.cc
26  *
27  * Definition of AddModuleDialog 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 #include "CompilerWarnings.hh"
35 IGNORE_CLANG_WARNING("-Wkeyword-macro")
36 #include <boost/regex.hpp>
38 
39 #include "AddModuleDialog.hh"
40 #include "ErrorDialog.hh"
41 #include "WxConversion.hh"
42 #include "GUITextGenerator.hh"
43 #include "OSEdTextGenerator.hh"
44 #include "WidgetTools.hh"
45 #include "DialogPosition.hh"
46 #include "OperationContainer.hh"
47 #include "OperationModule.hh"
48 
49 using std::string;
50 using boost::format;
51 
52 BEGIN_EVENT_TABLE(AddModuleDialog, wxDialog)
54  EVT_TEXT_ENTER(ID_MODULE_NAME, AddModuleDialog::onOk)
56 
57 /**
58  * Constructor.
59  *
60  * @parent Parent window.
61  */
62 AddModuleDialog::AddModuleDialog(wxWindow* parent, string path) :
63  wxDialog(parent, -1, _T(""),
64  DialogPosition::getPosition(DialogPosition::DIALOG_ADD_MODULE)),
65  path_(path), name_(_T("")){
66 
67  createContents(this, true, true);
68  FindWindow(ID_MODULE_NAME)->
69  SetValidator(wxTextValidator(wxFILTER_ASCII, &name_));
70 
71  FindWindow(wxID_OK)->SetFocus();
72  setTexts();
73 }
74 
75 /**
76  * Destructor.
77  */
79  int x, y;
80  GetPosition(&x, &y);
81  wxPoint point(x, y);
83 }
84 
85 /**
86  * Set texts to widgets.
87  */
88 void
90 
93 
94  //title
96  SetTitle(WxConversion::toWxString(fmt.str()));
97 
100 
101  // buttons
102  WidgetTools::setLabel(&guiText, FindWindow(wxID_OK),
104 
105  WidgetTools::setLabel(&guiText, FindWindow(wxID_CANCEL),
107 }
108 
109 /**
110  * Handles the event when OK button is pushed.
111  */
112 void
113 AddModuleDialog::onOk(wxCommandEvent&) {
114  TransferDataFromWindow();
116  if (name_ == _T("")) {
117  format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_NO_NAME);
118  fmt % "operation module";
119  ErrorDialog dialog(this, WxConversion::toWxString(fmt.str()));
120  dialog.ShowModal();
121  return;
122  } else {
123  string modName = WxConversion::toString(name_);
124  // let's check that module name is legal
125  const char* regExp = "\\w+";
126  boost::regex expression(regExp);
127  boost::match_results<string::const_iterator> what;
128  if (!boost::regex_match(modName, what, expression)) {
129  format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_MOD_NAME);
130  fmt % modName;
131  ErrorDialog dialog(this, WxConversion::toWxString(fmt.str()));
132  dialog.ShowModal();
133  return;
134  }
135 
136  // let's check there is not already a module by that name
137  if (&OperationContainer::module(path_, modName) !=
139 
140  format fmt =
142  fmt % modName;
143  string msg = fmt.str();
144  ErrorDialog error(this, WxConversion::toWxString(msg));
145  error.ShowModal();
146  } else {
147  EndModal(wxID_OK);
148  }
149  }
150 }
151 
152 /**
153  * Returns the name of the added module.
154  *
155  * @return The name of the added module.
156  */
157 string
160 }
161 
162 /**
163  * Creates the contents of the dialog.
164  *
165  * @param parent Parent window.
166  * @param call_fit If true fits the contents inside the dialog.
167  * @param set_sizer If true sets the main sizer as the contents of the dialog.
168  * @return The created sizer.
169  */
170 wxSizer*
172  wxWindow *parent,
173  bool call_fit,
174  bool set_sizer ) {
175 
176  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
177 
178  wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
179 
180  wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, wxT("Name of the module:"), wxDefaultPosition, wxDefaultSize, 0 );
181  item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
182 
183  wxTextCtrl *item3 = new wxTextCtrl( parent, ID_MODULE_NAME, wxT(""), wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER );
184  item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
185 
186  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
187 
188  wxBoxSizer *item4 = new wxBoxSizer( wxHORIZONTAL );
189 
190  wxButton *item5 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
191  item4->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
192 
193  wxButton *item6 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
194  item4->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
195 
196  item0->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
197 
198  if (set_sizer)
199  {
200  parent->SetSizer( item0 );
201  if (call_fit)
202  item0->SetSizeHints( parent );
203  }
204 
205  return item0;
206 }
AddModuleDialog::name_
wxString name_
Name of the module.
Definition: AddModuleDialog.hh:70
OSEdTextGenerator::TXT_ERROR_MODULE_EXISTS
@ TXT_ERROR_MODULE_EXISTS
Module exists error.
Definition: OSEdTextGenerator.hh:151
AddModuleDialog::ID_MODULE_NAME
@ ID_MODULE_NAME
Definition: AddModuleDialog.hh:64
POP_CLANG_DIAGS
#define POP_CLANG_DIAGS
Definition: CompilerWarnings.hh:96
WxConversion::toWxString
static wxString toWxString(const std::string &source)
AddModuleDialog.hh
AddModuleDialog::ID_TEXT
@ ID_TEXT
Definition: AddModuleDialog.hh:63
OperationContainer::module
static OperationModule & module(const std::string &path, const std::string &mod)
Definition: OperationContainer.cc:148
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
IGNORE_CLANG_WARNING
#define IGNORE_CLANG_WARNING(X)
Definition: CompilerWarnings.hh:85
GUITextGenerator
Definition: GUITextGenerator.hh:46
WidgetTools.hh
FindWindow
Definition: FindWindow.hh:49
AddModuleDialog::~AddModuleDialog
virtual ~AddModuleDialog()
Definition: AddModuleDialog.cc:78
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
AddModuleDialog::onOk
void onOk(wxCommandEvent &event)
Definition: AddModuleDialog.cc:113
AddModuleDialog::setTexts
void setTexts()
Definition: AddModuleDialog.cc:89
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
ErrorDialog
Definition: ErrorDialog.hh:42
ErrorDialog.hh
AddModuleDialog::name
std::string name() const
Definition: AddModuleDialog.cc:158
AddModuleDialog
Definition: AddModuleDialog.hh:42
DialogPosition
Definition: DialogPosition.hh:42
AddModuleDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: AddModuleDialog.cc:171
DialogPosition::DIALOG_ADD_MODULE
@ DIALOG_ADD_MODULE
Add module dialog.
Definition: DialogPosition.hh:54
GUITextGenerator.hh
AddModuleDialog::path_
std::string path_
Path in which module is added.
Definition: AddModuleDialog.hh:68
OSEdTextGenerator::TXT_LABEL_MODULE_NAME
@ TXT_LABEL_MODULE_NAME
Module name label.
Definition: OSEdTextGenerator.hh:53
OSEdTextGenerator::TXT_ADD_MODULE_DIALOG_TITLE
@ TXT_ADD_MODULE_DIALOG_TITLE
Add module dialog title.
Definition: OSEdTextGenerator.hh:112
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
OSEdTextGenerator::TXT_ERROR_NO_NAME
@ TXT_ERROR_NO_NAME
Error when no name is given.
Definition: OSEdTextGenerator.hh:132
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OSEdTextGenerator::TXT_ERROR_MOD_NAME
@ TXT_ERROR_MOD_NAME
Module name is erronous.
Definition: OSEdTextGenerator.hh:155
NullOperationModule::instance
static NullOperationModule & instance()
WxConversion::toString
static std::string toString(const wxString &source)
OSEdTextGenerator.hh
OperationModule.hh
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
CompilerWarnings.hh
OperationContainer.hh
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59
DialogPosition.hh