OpenASIP  2.0
WatchPropertiesDialog.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 WatchPropertiesDialog.cc
26  *
27  * Implementation of WatchPropertiesDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/spinctrl.h>
34 #include <wx/statline.h>
35 #include "WatchPropertiesDialog.hh"
36 #include "StopPointManager.hh"
37 #include "Watch.hh"
38 #include "WxConversion.hh"
39 #include "ExpressionScript.hh"
40 #include "ErrorDialog.hh"
41 #include "ProximToolbox.hh"
42 #include "ProximConstants.hh"
43 #include "Conversion.hh"
44 #include "ProximLineReader.hh"
45 
46 BEGIN_EVENT_TABLE(WatchPropertiesDialog, wxDialog)
49 
50 /**
51  * The Constructor.
52  *
53  * @param parent Parent window of the dialog.
54  * @param id Window identifier for the dialog.
55  * @param manager Stoppoint manager of the simulator.
56  * @param handle Watch handle.
57  */
59  wxWindow* parent, wxWindowID id, StopPointManager& manager, int handle) :
60  wxDialog(parent, id, _T("Watch point properties"), wxDefaultPosition),
61  manager_(manager), handle_(handle){
62 
63  createContents(this, true, true);
64 
65  expressionCtrl_ = dynamic_cast<wxTextCtrl*>(FindWindow(ID_EXPRESSION));
66  conditionCtrl_ = dynamic_cast<wxTextCtrl*>(FindWindow(ID_CONDITION));
67  ignoreCtrl_ = dynamic_cast<wxSpinCtrl*>(FindWindow(ID_IGNORE_COUNT));
68 }
69 
70 
71 /**
72  * The Destructor.
73  */
75 }
76 
77 
78 /**
79  * Initializes watch properties in the dialog widgets.
80  *
81  * @return True, if the watch properties were succesfully transfered to
82  * the dialog widgets.
83  */
84 bool
86 
88  const Watch& watch = dynamic_cast<const Watch&>(stoppoint);
89 
90  dynamic_cast<wxStaticText*>(FindWindow(ID_WATCH_HANDLE))->SetLabel(
92 
93  expressionCtrl_->SetValue(
95 
96  if (watch.isConditional()) {
97  conditionCtrl_->SetValue(
99  }
100 
101  ignoreCtrl_->SetValue(watch.ignoreCount());
102 
103  return wxDialog::TransferDataToWindow();
104 }
105 
106 
107 /**
108  * Event handler for the OK-button.
109  *
110  * Updates the watch properties accordign to the values in the dialog widgets.
111  */
112 void
113 WatchPropertiesDialog::onOK(wxCommandEvent&) {
114 
115  wxTextCtrl* conditionCtrl =
116  dynamic_cast<wxTextCtrl*>(FindWindow(ID_CONDITION));
117  std::string condition = WxConversion::toString(
118  conditionCtrl->GetValue().Trim(true).Trim(false));
119 
120  // Test condition script.
121  if (condition != "" && !ProximToolbox::testCondition(this, condition)) {
122  // Invalid condition script.
123  return;
124  }
125 
126  // Set watch condition script.
127  std::string conditionCommand = ProximConstants::SCL_SET_CONDITION +
130  lineReader.input(conditionCommand);
131  lineReader.input(condition);
132 
133  // Set watch ignore count.
134  unsigned ignoreCount = ignoreCtrl_->GetValue();
135  std::string ignoreCommand = ProximConstants::SCL_SET_IGNORE_COUNT +
137  " " + Conversion::toString(ignoreCount);
138  lineReader.input(ignoreCommand);
139 
140  // Close dialog.
141  EndModal(wxID_OK);
142 }
143 
144 
145 /**
146  * Creates the dialog contents.
147  *
148  * Code generated by wxDesgigner. Do not modify manually.
149  *
150  * @param parent Parent window of the widgets.
151  * @param call_fit If true, the dialog is resized to fit the widgets.
152  * @param set_sizer If true, the created widgets are set as the parent window
153  * contents.
154  */
155 wxSizer*
157  wxWindow* parent, bool call_fit, bool set_sizer) {
158 
159  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
160 
161  wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
162 
163  wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_WATCH, wxT("Watch:"), wxDefaultPosition, wxDefaultSize, 0 );
164  item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
165 
166  wxStaticText *item3 = new wxStaticText( parent, ID_WATCH_HANDLE, wxT("??????"), wxDefaultPosition, wxDefaultSize, 0 );
167  item1->Add( item3, 0, wxALL, 5 );
168 
169  wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_EXPRESSION, wxT("Expression:"), wxDefaultPosition, wxDefaultSize, 0 );
170  item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
171 
172  wxTextCtrl *item5 = new wxTextCtrl( parent, ID_EXPRESSION, wxT(""), wxDefaultPosition, wxSize(400,-1), wxTE_READONLY );
173  item1->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
174 
175  wxStaticText *item6 = new wxStaticText( parent, ID_LABEL_CONDITION, wxT("Condition:"), wxDefaultPosition, wxDefaultSize, 0 );
176  item1->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
177 
178  wxTextCtrl *item7 = new wxTextCtrl( parent, ID_CONDITION, wxT(""), wxDefaultPosition, wxSize(400,-1), 0 );
179  item1->Add( item7, 0, wxGROW|wxALL, 5 );
180 
181  wxStaticText *item8 = new wxStaticText( parent, ID_LABEL_IGNORE_COUNT, wxT("Ignore count:"), wxDefaultPosition, wxDefaultSize, 0 );
182  item1->Add( item8, 0, wxALIGN_RIGHT|wxALL, 5 );
183 
184  wxSpinCtrl *item9 = new wxSpinCtrl( parent, ID_IGNORE_COUNT, wxT("0"), wxDefaultPosition, wxSize(-1,-1), 0, 0, 10000, 0 );
185  item1->Add( item9, 0, wxALL, 5 );
186 
187  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
188 
189  wxStaticLine *item10 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
190  item0->Add( item10, 0, wxGROW|wxALL, 5 );
191 
192  wxBoxSizer *item11 = new wxBoxSizer( wxHORIZONTAL );
193 
194  wxButton *item12 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
195  item11->Add( item12, 0, wxALL, 5 );
196 
197  wxButton *item13 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
198  item11->Add( item13, 0, wxALL, 5 );
199 
200  item0->Add( item11, 0, wxALIGN_CENTER, 5 );
201 
202  if (set_sizer)
203  {
204  parent->SetSizer( item0 );
205  if (call_fit)
206  item0->SetSizeHints( parent );
207  }
208 
209  return item0;
210 }
StopPointManager.hh
Script::script
virtual std::vector< std::string > script() const
Definition: Script.cc:106
WatchPropertiesDialog::ID_EXPRESSION
@ ID_EXPRESSION
Definition: WatchPropertiesDialog.hh:62
WxConversion::toWxString
static wxString toWxString(const std::string &source)
WatchPropertiesDialog::handle_
int handle_
Handle of the watch to modify.
Definition: WatchPropertiesDialog.hh:71
WatchPropertiesDialog
Definition: WatchPropertiesDialog.hh:43
Watch
Definition: Watch.hh:48
ProximToolbox::testCondition
static bool testCondition(wxWindow *parent, const std::string &condition)
Definition: ProximToolbox.cc:280
ProximLineReader.hh
StopPoint::ignoreCount
virtual unsigned int ignoreCount() const
Definition: StopPoint.cc:193
WatchPropertiesDialog::ID_LABEL_IGNORE_COUNT
@ ID_LABEL_IGNORE_COUNT
Definition: WatchPropertiesDialog.hh:59
FindWindow
Definition: FindWindow.hh:49
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
Watch::expression
virtual const ExpressionScript & expression() const
Definition: Watch.cc:88
Conversion::toString
static std::string toString(const T &source)
WatchPropertiesDialog::ID_CONDITION
@ ID_CONDITION
Definition: WatchPropertiesDialog.hh:63
WatchPropertiesDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool call_sizer)
Definition: WatchPropertiesDialog.cc:156
ProximToolbox.hh
WatchPropertiesDialog.hh
StopPoint::condition
virtual const ConditionScript & condition() const
Definition: StopPoint.cc:156
WatchPropertiesDialog::ID_WATCH_HANDLE
@ ID_WATCH_HANDLE
Definition: WatchPropertiesDialog.hh:61
StopPointManager::stopPointWithHandleConst
const StopPoint & stopPointWithHandleConst(unsigned int handle) const
Definition: StopPointManager.cc:248
WatchPropertiesDialog::onOK
void onOK(wxCommandEvent &event)
Definition: WatchPropertiesDialog.cc:113
StopPoint
Definition: StopPoint.hh:53
ErrorDialog.hh
Conversion.hh
StopPointManager
Definition: StopPointManager.hh:50
WatchPropertiesDialog::expressionCtrl_
wxTextCtrl * expressionCtrl_
Text widget for the watch expression script.
Definition: WatchPropertiesDialog.hh:74
ProximLineReader
Definition: ProximLineReader.hh:60
WatchPropertiesDialog::ID_IGNORE_COUNT
@ ID_IGNORE_COUNT
Definition: WatchPropertiesDialog.hh:64
WatchPropertiesDialog::ID_LABEL_CONDITION
@ ID_LABEL_CONDITION
Definition: WatchPropertiesDialog.hh:58
WatchPropertiesDialog::ID_LABEL_EXPRESSION
@ ID_LABEL_EXPRESSION
Definition: WatchPropertiesDialog.hh:57
StopPoint::isConditional
virtual bool isConditional() const
Definition: StopPoint.cc:173
WatchPropertiesDialog::manager_
StopPointManager & manager_
Stop point manager of the simulator.
Definition: WatchPropertiesDialog.hh:69
WatchPropertiesDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: WatchPropertiesDialog.cc:85
WatchPropertiesDialog::ID_LABEL_WATCH
@ ID_LABEL_WATCH
Definition: WatchPropertiesDialog.hh:56
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
WatchPropertiesDialog::conditionCtrl_
wxTextCtrl * conditionCtrl_
Text widget fot the watch condition script.
Definition: WatchPropertiesDialog.hh:76
WatchPropertiesDialog::~WatchPropertiesDialog
~WatchPropertiesDialog()
Definition: WatchPropertiesDialog.cc:74
WatchPropertiesDialog::ignoreCtrl_
wxSpinCtrl * ignoreCtrl_
Spin button widget for the watch ignore count.
Definition: WatchPropertiesDialog.hh:78
ProximConstants.hh
WatchPropertiesDialog::ID_LINE
@ ID_LINE
Definition: WatchPropertiesDialog.hh:65
Watch.hh
WxConversion.hh
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
ExpressionScript.hh