OpenASIP  2.0
ProximQuitCmd.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 ProximQuitCmd.cc
26  *
27  * Implementation of ProximQuitCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "ProximQuitCmd.hh"
34 #include "ProximConstants.hh"
35 #include "Proxim.hh"
38 #include "ConfirmDialog.hh"
39 #include "GUIOptions.hh"
40 #include "GUIOptionsSerializer.hh"
41 #include "ErrorDialog.hh"
42 #include "WxConversion.hh"
43 #include "Exception.hh"
44 #include "ProximToolbox.hh"
45 #include "Environment.hh"
46 
47 /**
48  * The Constructor.
49  */
51  GUICommand(ProximConstants::COMMAND_NAME_QUIT, NULL) {
52 
54 }
55 
56 /**
57  * The Destructor.
58  */
60 }
61 
62 
63 /**
64  * Executes the command.
65  *
66  * @return True, if the command was succesfully executed.
67  */
68 bool
70 
71  assert(parentWindow() != NULL);
72 
74  wxString message = _T("Simulation is still running.\n");
75  message.Append(_T("Are you sure you want to stop the simulation "));
76  message.Append(_T("and quit?"));
77  ConfirmDialog dialog(parentWindow(), message);
78 
79  if (dialog.ShowModal() != wxID_YES) {
80  return false;
81  }
82 
83  wxGetApp().simulation()->finishSimulation();
84  }
85 
86  GUIOptions& options = wxGetApp().options();
87  if (options.isModified()) {
88  wxString message = _T("Options are modified.\n");
89  message.Append(_T("Do you want to save changes?"));
90  ConfirmDialog dialog(parentWindow(), message);
91 
92  int returnValue = dialog.ShowModal();
93  if (returnValue == wxID_YES) {
94 
96  try {
97  writer.setDestinationFile(
98  Environment::userConfPath("Proxim.conf"));
99  writer.writeOptions(options);
100  options.clearModified();
101  } catch (Exception& e) {
102  wxString message = _T("Error saving options:\n\n");
103  message.Append(WxConversion::toWxString(e.errorMessage()));
104  ErrorDialog errorDialog(parentWindow(), message);
105  errorDialog.ShowModal();
106  return false;
107  }
108  } else if (returnValue == wxID_CANCEL) {
109  return false;
110  }
111  }
112 
114 
115  return true;
116 }
117 
118 
119 /**
120  * Returns full path to the command icon file.
121  *
122  * @return Full path to the command icon file.
123  */
124 std::string
126  return "quit.png";
127 }
128 
129 
130 /**
131  * Returns ID of this command.
132  */
133 int
136 }
137 
138 
139 /**
140  * Creates and returns a new isntance of this command.
141  *
142  * @return Newly created instance of this command.
143  */
146  return new ProximQuitCmd();
147 }
148 
149 
150 /**
151  * Returns true if the command is enabled, false otherwise.
152  *
153  * @return Always true.
154  */
155 bool
157  return true;
158 }
ProximQuitCmd::icon
virtual std::string icon() const
Definition: ProximQuitCmd.cc:125
ProximQuitCmd
Definition: ProximQuitCmd.hh:43
ProximToolbox::frontend
static TracedSimulatorFrontend * frontend()
Definition: ProximToolbox.cc:223
WxConversion::toWxString
static wxString toWxString(const std::string &source)
Exception.hh
ProximConstants::CONFIGURATION_NAME
static const std::string CONFIGURATION_NAME
Configuration file top-level element name.
Definition: ProximConstants.hh:247
GUIOptionsSerializer.hh
SimulatorFrontend::isSimulationStopped
bool isSimulationStopped() const
Definition: SimulatorFrontend.cc:1271
GUIOptions.hh
ProximQuitCmd::simulator_
SimulatorFrontend * simulator_
Definition: ProximQuitCmd.hh:54
ProximSimulationThread.hh
Proxim.hh
ProximLineReader::input
void input(std::string command)
Definition: ProximLineReader.cc:131
Environment::userConfPath
static TCEString userConfPath(const std::string &fileName)
Definition: Environment.cc:303
assert
#define assert(condition)
Definition: Application.hh:86
ProximToolbox.hh
GUICommand
Definition: GUICommand.hh:43
ErrorDialog
Definition: ErrorDialog.hh:42
ProximQuitCmd::create
virtual ProximQuitCmd * create() const
Definition: ProximQuitCmd.cc:145
ErrorDialog.hh
ConfirmDialog.hh
XMLSerializer::setDestinationFile
void setDestinationFile(const std::string &fileName)
Definition: XMLSerializer.cc:142
Environment.hh
Exception
Definition: Exception.hh:54
ProximQuitCmd::Do
virtual bool Do()
Definition: ProximQuitCmd.cc:69
ConfirmDialog
Definition: ConfirmDialog.hh:41
ProximQuitCmd::isEnabled
virtual bool isEnabled()
Definition: ProximQuitCmd.cc:156
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ProximConstants::COMMAND_QUIT
@ COMMAND_QUIT
Definition: ProximConstants.hh:57
SimulatorFrontend::isSimulationRunning
bool isSimulationRunning() const
Definition: SimulatorFrontend.cc:1260
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
GUIOptions
Definition: GUIOptions.hh:58
TracedSimulatorFrontend.hh
ProximConstants
Definition: ProximConstants.hh:46
ProximConstants.hh
ProximConstants::SCL_QUIT
static const std::string SCL_QUIT
Command for quiting the simulation.
Definition: ProximConstants.hh:161
ProximQuitCmd::~ProximQuitCmd
virtual ~ProximQuitCmd()
Definition: ProximQuitCmd.cc:59
ProximQuitCmd::id
virtual int id() const
Definition: ProximQuitCmd.cc:134
ProximQuitCmd::ProximQuitCmd
ProximQuitCmd()
Definition: ProximQuitCmd.cc:50
WxConversion.hh
GUIOptionsSerializer::writeOptions
void writeOptions(const GUIOptions &options)
Definition: GUIOptionsSerializer.cc:163
ProximToolbox::lineReader
static ProximLineReader & lineReader()
Definition: ProximToolbox.cc:238
ProximQuitCmd.hh
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
GUIOptionsSerializer
Definition: GUIOptionsSerializer.hh:52