OpenASIP  2.0
BreakpointPropertiesDialog.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 BreakpointPropertiesDialog.cc
26  *
27  * Implementation of BreakpointPropertiesDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red.
31  */
32 
33 #include <string>
34 #include <vector>
36 #include "Breakpoint.hh"
37 #include "WxConversion.hh"
38 #include "StopPointManager.hh"
39 #include "ProximToolbox.hh"
40 #include "ProximConstants.hh"
41 #include "ProximLineReader.hh"
42 #include "Conversion.hh"
43 
44 BEGIN_EVENT_TABLE(BreakpointPropertiesDialog, wxDialog)
47 
48 using std::vector;
49 using std::string;
50 
51 /**
52  * The Constructor.
53  *
54  * @param parent Parent window of the dialog.
55  * @param breakpoint Breakpoint to edit.
56  */
58  wxWindow* parent, StopPointManager& manager, unsigned int handle) :
59  wxDialog(parent, -1, _T("Breakpoint properties"), wxDefaultPosition),
60  manager_(manager), handle_(handle) {
61 
62  createContents(this, true, true);
63 
64 }
65 
66 
67 /**
68  * The Destructor.
69  */
71 }
72 
73 
74 /**
75  * Sets the widget values when the dialog is opened.
76  */
77 bool
79 
80  const Breakpoint& breakpoint = dynamic_cast<const Breakpoint&>(
82 
83  if (breakpoint.isConditional()) {
84  wxTextCtrl* conditionCtrl =
85  dynamic_cast<wxTextCtrl*>(FindWindow(ID_CONDITION));
86  for (unsigned i = 0; i < breakpoint.condition().script().size(); i++) {
87  string line = breakpoint.condition().script()[i];
88  conditionCtrl->AppendText(WxConversion::toWxString(line));
89  }
90  }
91 
92  dynamic_cast<wxSpinCtrl*>(FindWindow(ID_IGNORE_CTRL))->SetValue(
93  breakpoint.ignoreCount());
94 
95  dynamic_cast<wxStaticText*>(FindWindow(ID_TEXT_BP_ID))->SetLabel(
97 
98  return wxDialog::TransferDataToWindow();
99 }
100 
101 
102 /**
103  * Handles the dialog OK-button event.
104  *
105  * Breakpoint properties are checked for validity, and the breakpoint is
106  * modified if the properties are valid. An error dialog is displayed if
107  * the breakpoint properties are invalid.
108  */
109 void
111 
112  wxTextCtrl* conditionCtrl =
113  dynamic_cast<wxTextCtrl*>(FindWindow(ID_CONDITION));
114 
115  unsigned ignoreCount =
116  dynamic_cast<wxSpinCtrl*>(FindWindow(ID_IGNORE_CTRL))->GetValue();
117 
118  string condition = WxConversion::toString(
119  conditionCtrl->GetValue().Trim(true).Trim(false));
120 
121  // Check condition script.
122  if (condition != "" && !ProximToolbox::testCondition(this, condition)) {
123  // Invalid condition.
124  return;
125  }
126 
128 
129  // Set ignore count.
130  std::string ignoreCommand = ProximConstants::SCL_SET_IGNORE_COUNT +
132  " " + Conversion::toString(ignoreCount);
133 
134  lineReader.input(ignoreCommand);
135 
136  // Set Condition script.
137  std::string conditionCommand = ProximConstants::SCL_SET_CONDITION + " " +
139 
140  lineReader.input(conditionCommand);
141  lineReader.input(condition);
142 
143  EndModal(wxID_OK);
144 }
145 
146 
147 /**
148  * Creates the dialog contents.
149  */
150 wxSizer*
152  wxWindow *parent, bool call_fit, bool set_sizer) {
153 
154  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
155 
156  wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
157 
158  wxStaticText *item2 = new wxStaticText( parent, ID_TEXT_BREAKPOINT, wxT("Breakpoint"), wxDefaultPosition, wxDefaultSize, 0 );
159  item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
160 
161  wxStaticText *item3 = new wxStaticText( parent, ID_TEXT_BP_ID, wxT(""), wxDefaultPosition, wxDefaultSize, 0 );
162  item1->Add( item3, 0, wxALL, 5 );
163 
164  wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_IGNORE_COUNT, wxT("Ignore count:"), wxDefaultPosition, wxDefaultSize, 0 );
165  item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
166 
167  wxSpinCtrl *item5 = new wxSpinCtrl( parent, ID_IGNORE_CTRL, wxT("0"), wxDefaultPosition, wxSize(-1,-1), 0, 0, 100, 0 );
168  item1->Add( item5, 0, wxALL, 5 );
169 
170  wxStaticText *item6 = new wxStaticText( parent, ID_LABEL_CONDITION, wxT("Condition:"), wxDefaultPosition, wxDefaultSize, 0 );
171  item1->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
172 
173  wxTextCtrl *item7 = new wxTextCtrl( parent, ID_CONDITION, wxT(""), wxDefaultPosition, wxSize(250,-1));
174  item1->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
175 
176  item0->Add( item1, 0, wxGROW, 5 );
177 
178  wxStaticLine *item8 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
179  item0->Add( item8, 0, wxGROW|wxALL, 5 );
180 
181  wxGridSizer *item9 = new wxGridSizer( 2, 0, 0 );
182 
183  wxButton *item10 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
184  item9->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
185 
186  wxButton *item11 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
187  item9->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
188 
189  item0->Add( item9, 0, wxGROW, 5 );
190 
191  if (set_sizer)
192  {
193  parent->SetSizer( item0 );
194  if (call_fit)
195  item0->SetSizeHints( parent );
196  }
197 
198  return item0;
199 }
StopPointManager.hh
BreakpointPropertiesDialog::~BreakpointPropertiesDialog
virtual ~BreakpointPropertiesDialog()
Definition: BreakpointPropertiesDialog.cc:70
Script::script
virtual std::vector< std::string > script() const
Definition: Script.cc:106
BreakpointPropertiesDialog::ID_LABEL_IGNORE_COUNT
@ ID_LABEL_IGNORE_COUNT
Definition: BreakpointPropertiesDialog.hh:61
BreakpointPropertiesDialog::ID_TEXT_BREAKPOINT
@ ID_TEXT_BREAKPOINT
Definition: BreakpointPropertiesDialog.hh:57
WxConversion::toWxString
static wxString toWxString(const std::string &source)
Breakpoint
Definition: Breakpoint.hh:50
ProximToolbox::testCondition
static bool testCondition(wxWindow *parent, const std::string &condition)
Definition: ProximToolbox.cc:280
BreakpointPropertiesDialog
Definition: BreakpointPropertiesDialog.hh:45
ProximLineReader.hh
StopPoint::ignoreCount
virtual unsigned int ignoreCount() const
Definition: StopPoint.cc:193
BreakpointPropertiesDialog::ID_IGNORE_CTRL
@ ID_IGNORE_CTRL
Definition: BreakpointPropertiesDialog.hh:62
FindWindow
Definition: FindWindow.hh:49
BreakpointPropertiesDialog::onOK
void onOK(wxCommandEvent &event)
Definition: BreakpointPropertiesDialog.cc:110
ProximConstants::SCL_SET_IGNORE_COUNT
static const std::string SCL_SET_IGNORE_COUNT
Command for setting stop point ignore count.
Definition: ProximConstants.hh:159
ProximLineReader::input
void input(std::string command)
Definition: ProximLineReader.cc:131
Conversion::toString
static std::string toString(const T &source)
ProximToolbox.hh
StopPoint::condition
virtual const ConditionScript & condition() const
Definition: StopPoint.cc:156
BreakpointPropertiesDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: BreakpointPropertiesDialog.cc:78
StopPointManager::stopPointWithHandleConst
const StopPoint & stopPointWithHandleConst(unsigned int handle) const
Definition: StopPointManager.cc:248
BreakpointPropertiesDialog::handle_
unsigned int handle_
Handle of the breakpoint to modify.
Definition: BreakpointPropertiesDialog.hh:70
Conversion.hh
StopPointManager
Definition: StopPointManager.hh:50
Breakpoint.hh
ProximLineReader
Definition: ProximLineReader.hh:60
BreakpointPropertiesDialog::ID_LINE
@ ID_LINE
Definition: BreakpointPropertiesDialog.hh:63
StopPoint::isConditional
virtual bool isConditional() const
Definition: StopPoint.cc:173
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
ProximConstants.hh
BreakpointPropertiesDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: BreakpointPropertiesDialog.cc:151
BreakpointPropertiesDialog.hh
BreakpointPropertiesDialog::ID_CONDITION
@ ID_CONDITION
Definition: BreakpointPropertiesDialog.hh:60
BreakpointPropertiesDialog::ID_TEXT_BP_ID
@ ID_TEXT_BP_ID
Definition: BreakpointPropertiesDialog.hh:58
BreakpointPropertiesDialog::ID_LABEL_CONDITION
@ ID_LABEL_CONDITION
Definition: BreakpointPropertiesDialog.hh:59
WxConversion.hh
BreakpointPropertiesDialog::manager_
StopPointManager & manager_
Stoppoint manager containing the breakpoint,.
Definition: BreakpointPropertiesDialog.hh:68
WxConversion::toString
static std::string toString(const wxString &source)
ProximToolbox::lineReader
static ProximLineReader & lineReader()
Definition: ProximToolbox.cc:238
ProximConstants::SCL_SET_CONDITION
static const std::string SCL_SET_CONDITION
Command for setting stop point condition in simulator control language.
Definition: ProximConstants.hh:157
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF