OpenASIP 2.2
Loading...
Searching...
No Matches
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"
35IGNORE_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
49using std::string;
50using boost::format;
51
52BEGIN_EVENT_TABLE(AddModuleDialog, wxDialog)
54 EVT_TEXT_ENTER(ID_MODULE_NAME, AddModuleDialog::onOk)
56
57/**
58 * Constructor.
59 *
60 * @parent Parent window.
61 */
62AddModuleDialog::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 */
88void
108
109/**
110 * Handles the event when OK button is pushed.
111 */
112void
113AddModuleDialog::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)) {
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 */
157string
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 */
170wxSizer*
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}
END_EVENT_TABLE() using namespace IDF
#define POP_CLANG_DIAGS
#define IGNORE_CLANG_WARNING(X)
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
wxString name_
Name of the module.
virtual ~AddModuleDialog()
void onOk(wxCommandEvent &event)
std::string path_
Path in which module is added.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
std::string name() const
static void setPosition(Dialogs dialog, wxPoint point)
@ DIALOG_ADD_MODULE
Add module dialog.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
static NullOperationModule & instance()
static OSEdTextGenerator & instance()
@ TXT_ERROR_MODULE_EXISTS
Module exists error.
@ TXT_ERROR_NO_NAME
Error when no name is given.
@ TXT_LABEL_MODULE_NAME
Module name label.
@ TXT_ADD_MODULE_DIALOG_TITLE
Add module dialog title.
@ TXT_ERROR_MOD_NAME
Module name is erronous.
static OperationModule & module(const std::string &path, const std::string &mod)
virtual boost::format text(int textId)
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)