OpenASIP  2.0
ImplementationParameterDialog.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2014 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 FUImplementationParameterDialog.cc
26  *
27  * Implementation of FUImplementationParameterDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/statline.h>
34 #include <wx/valgen.h>
36 #include "WxConversion.hh"
37 #include "ErrorDialog.hh"
38 
39 using namespace HDB;
40 
41 BEGIN_EVENT_TABLE(ImplementationParameterDialog, wxDialog)
44 
45 /**
46  * The Constructor.
47  *
48  * @param parent Parent window of the dialog.
49  * @param id Window identifier for the dialog window.
50  * @param parameter FU implementation parameter to modify.
51  */
53  wxWindow* parent, wxWindowID id, FUImplementation::Parameter& parameter) :
54  wxDialog(parent, id, _T("Parameter")),
55  parameter_(parameter) {
56 
57  createContents(this, true, true);
58 
59  name_ = WxConversion::toWxString(parameter_.name);
60  type_ = WxConversion::toWxString(parameter_.type);
61  value_ = WxConversion::toWxString(parameter_.value);
62 
63  FindWindow(ID_NAME)->SetValidator(wxTextValidator(wxFILTER_ASCII, &name_));
64  FindWindow(ID_TYPE)->SetValidator(wxTextValidator(wxFILTER_ASCII, &type_));
65  FindWindow(ID_VALUE)->SetValidator(
66  wxTextValidator(wxFILTER_ASCII, &value_));
67 
68  TransferDataToWindow();
69 }
70 
71 /**
72  * The Destructor.
73  */
75 }
76 
77 
78 /**
79  * Event handler for the dialog OK-button.
80  */
81 void
83 
84  TransferDataFromWindow();
85 
86  name_ = name_.Trim(true).Trim(false);
87  type_ = type_.Trim(true).Trim(false);
88  value_ = value_.Trim(true).Trim(false);
89 
90 
91  if (name_.IsEmpty()) {
92  wxString message = _T("Name field must not be empty.");
93  ErrorDialog dialog(this, message);
94  dialog.ShowModal();
95  return;
96  }
97 
98  if (type_.IsEmpty()) {
99  wxString message = _T("Type field must not be empty.");
100  ErrorDialog dialog(this, message);
101  dialog.ShowModal();
102  return;
103  }
104 
105  parameter_.name = WxConversion::toString(name_);
106  parameter_.type = WxConversion::toString(type_);
107  parameter_.value = WxConversion::toString(value_);
108 
109  EndModal(wxID_OK);
110 }
111 
112 /**
113  * Creates the dialog contents.
114  */
115 wxSizer*
117  wxWindow *parent, bool call_fit, bool set_sizer) {
118 
119  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
120 
121  wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
122 
123  wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
124  item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
125 
126  wxTextCtrl *item3 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
127  item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
128 
129  wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_TYPE, wxT("Type:"), wxDefaultPosition, wxDefaultSize, 0 );
130  item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
131 
132  wxTextCtrl *item5 = new wxTextCtrl( parent, ID_TYPE, wxT(""), wxDefaultPosition, wxSize(80,-1), 0 );
133  item1->Add( item5, 0, wxGROW|wxALL, 5 );
134 
135  wxStaticText *item6 = new wxStaticText( parent, ID_LABEL_VALUE, wxT("Value:"), wxDefaultPosition, wxDefaultSize, 0 );
136  item1->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
137 
138  wxTextCtrl *item7 = new wxTextCtrl( parent, ID_VALUE, wxT(""), wxDefaultPosition, wxSize(80,-1), 0 );
139  item1->Add( item7, 0, wxGROW|wxALL, 5 );
140 
141  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
142 
143  wxStaticLine *item8 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
144  item0->Add( item8, 0, wxGROW|wxALL, 5 );
145 
146  wxBoxSizer *item9 = new wxBoxSizer( wxHORIZONTAL );
147 
148  wxButton *item10 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
149  item9->Add( item10, 0, wxALIGN_CENTER, 5 );
150 
151  wxButton *item11 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
152  item9->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
153 
154  item0->Add( item9, 0, wxALL, 5 );
155 
156  if (set_sizer)
157  {
158  parent->SetSizer( item0 );
159  if (call_fit)
160  item0->SetSizeHints( parent );
161  }
162 
163  return item0;
164 }
ImplementationParameterDialog
Definition: ImplementationParameterDialog.hh:44
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDB
Definition: CostDatabase.hh:49
FindWindow
Definition: FindWindow.hh:49
ImplementationParameterDialog.hh
ErrorDialog
Definition: ErrorDialog.hh:42
ErrorDialog.hh
ImplementationParameterDialog::onOK
void onOK(wxCommandEvent &event)
Definition: ImplementationParameterDialog.cc:82
HDB::FUImplementation
Definition: FUImplementation.hh:53
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
ImplementationParameterDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Creates the dialog contents.
Definition: ImplementationParameterDialog.cc:116
WxConversion.hh
HDB::Parameter
Definition: HDBTypes.hh:46
ImplementationParameterDialog::~ImplementationParameterDialog
virtual ~ImplementationParameterDialog()
Definition: ImplementationParameterDialog.cc:74
WxConversion::toString
static std::string toString(const wxString &source)
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF