OpenASIP  2.0
ProximExecuteFileCmd.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 ProximExecuteFileCmd.cc
26  *
27  * Implementation of ProximExecuteFileCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <fstream>
34 #include "ProximExecuteFileCmd.hh"
35 #include "ProximConstants.hh"
36 #include "ProximToolbox.hh"
37 #include "ProximLineReader.hh"
38 #include "WxConversion.hh"
39 #include "ErrorDialog.hh"
41 
42 #if wxCHECK_VERSION(3, 0, 0)
43  #define wxOPEN wxFD_OPEN
44 #endif
45 
46 /**
47  * The Constructor.
48  */
50  GUICommand(ProximConstants::COMMAND_NAME_EXECUTE_FILE, NULL) {
51 
53 }
54 
55 /**
56  * The Destructor.
57  */
59 }
60 
61 
62 /**
63  * Executes the command.
64  */
65 bool
67  wxString message = _T("Choose a file.");
68  wxString wildcard = _T("Command history logs (*.log)|*.log|All files|*.*");
69  wxFileDialog dialog(
70  parentWindow(), message, _T(""), _T(""), wildcard, wxOPEN);
71 
72  if (dialog.ShowModal() == wxID_CANCEL) {
73  return false;
74  }
75 
76  std::string filename = WxConversion::toString(dialog.GetPath());
77  std::ifstream file(filename.c_str());
78 
79  if (file.bad()) {
80  wxString message = _T("Error opening file '");
81  message.Append(dialog.GetPath());
82  message.Append(_T("'."));
83  ErrorDialog dialog(parentWindow(), message);
84  dialog.ShowModal();
85  return false;
86  }
87 
89 
90  while (!file.eof()) {
91  std::string command;
92  getline(file, command);
93  lineReader.input(command);
94  }
95 
96  return true;
97 }
98 
99 
100 /**
101  * Returns full path to the command icon file.
102  *
103  * @return Full path to the command icon file.
104  */
105 std::string
107  return "exec.png";
108 }
109 
110 
111 /**
112  * Returns ID of this command.
113  */
114 int
117 }
118 
119 
120 /**
121  * Creates and returns a new isntance of this command.
122  *
123  * @return Newly created instance of this command.
124  */
127  return new ProximExecuteFileCmd();
128 }
129 
130 
131 /**
132  * Returns true if the command is enabled, false otherwise.
133  *
134  * @return True if the simulation is initialized or stopped.
135  */
136 bool
138 
139  if (simulator_ != NULL) {
140  return true;
141  } else {
142  return false;
143  }
144 }
ProximExecuteFileCmd.hh
ProximToolbox::frontend
static TracedSimulatorFrontend * frontend()
Definition: ProximToolbox.cc:223
ProximExecuteFileCmd::isEnabled
virtual bool isEnabled()
Definition: ProximExecuteFileCmd.cc:137
ProximLineReader.hh
ProximExecuteFileCmd
Definition: ProximExecuteFileCmd.hh:43
ProximExecuteFileCmd::create
virtual ProximExecuteFileCmd * create() const
Definition: ProximExecuteFileCmd.cc:126
ProximLineReader::input
void input(std::string command)
Definition: ProximLineReader.cc:131
ProximExecuteFileCmd::Do
virtual bool Do()
Definition: ProximExecuteFileCmd.cc:66
ProximToolbox.hh
GUICommand
Definition: GUICommand.hh:43
ProximConstants::COMMAND_EXECUTE_FILE
@ COMMAND_EXECUTE_FILE
Definition: ProximConstants.hh:70
ErrorDialog
Definition: ErrorDialog.hh:42
ProximExecuteFileCmd::ProximExecuteFileCmd
ProximExecuteFileCmd()
Definition: ProximExecuteFileCmd.cc:49
ErrorDialog.hh
ProximExecuteFileCmd::icon
virtual std::string icon() const
Definition: ProximExecuteFileCmd.cc:106
ProximExecuteFileCmd::~ProximExecuteFileCmd
virtual ~ProximExecuteFileCmd()
Definition: ProximExecuteFileCmd.cc:58
ProximLineReader
Definition: ProximLineReader.hh:60
ProximExecuteFileCmd::simulator_
SimulatorFrontend * simulator_
Definition: ProximExecuteFileCmd.hh:54
ProximExecuteFileCmd::id
virtual int id() const
Definition: ProximExecuteFileCmd.cc:115
TracedSimulatorFrontend.hh
ProximConstants
Definition: ProximConstants.hh:46
ProximConstants.hh
WxConversion.hh
WxConversion::toString
static std::string toString(const wxString &source)
ProximToolbox::lineReader
static ProximLineReader & lineReader()
Definition: ProximToolbox.cc:238
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75