OpenASIP  2.0
ProximOpenMachineCmd.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 ProximOpenMachineCmd.cc
26  *
27  * Implementation of ProximOpenMachineCmd 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/filedlg.h>
34 #include "ProximOpenMachineCmd.hh"
35 #include "WxConversion.hh"
36 #include "ProximConstants.hh"
37 #include "Proxim.hh"
38 #include "FileSystem.hh"
40 
41 #if wxCHECK_VERSION(3, 0, 0)
42  #define wxOPEN wxFD_OPEN
43 #endif
44 
45 /**
46  * The Constructor.
47  */
49  GUICommand(ProximConstants::COMMAND_NAME_OPEN_MACHINE, NULL) {
50 
51  }
52 
53 /**
54  * The Destructor.
55  */
57 }
58 
59 
60 /**
61  * Executes the command.
62  */
63 bool
65  assert(parentWindow() != NULL);
66 
67  wxString wildcard = _T("Architecture Definition Files (*.adf)|*.adf");
68  wildcard.Append(_T("|Processor Configuration Files (*.pcf)|*.pcf"));
69  wildcard.Append(_T("|All files|*.*"));
70  wxFileDialog dialog(
71  parentWindow(), _T("Choose a file."), _T(""), _T(""),
72  wildcard, wxOPEN);
73 
74  if (dialog.ShowModal() == wxID_CANCEL) {
75  return false;
76  }
77 
78  std::string command;
79  std::string file = WxConversion::toString(dialog.GetPath());
80  std::string extension = FileSystem::fileExtension(file);
81 
82  // Simulator interpreter command is chose according to file extension.
83  // Processor configuration files (.pcf), have to be opened using
84  // 'conf' command.
85  if (extension == ".pcf") {
86  command = ProximConstants::SCL_LOAD_CONF + " \"" + file + "\"";
87  } else {
88  command = ProximConstants::SCL_LOAD_MACHINE + " \"" + file + "\"";
89  }
90 
91  wxGetApp().simulation()->lineReader().input(command);
92  return true;
93 }
94 
95 
96 /**
97  * Returns full path to the command icon file.
98  *
99  * @return Full path to the command icon file.
100  */
101 std::string
103  return "open_machine.png";
104 }
105 
106 
107 /**
108  * Returns ID of this command.
109  */
110 int
113 }
114 
115 
116 /**
117  * Creates and returns a new isntance of this command.
118  *
119  * @return Newly created instance of this command.
120  */
123  return new ProximOpenMachineCmd();
124 }
125 
126 
127 /**
128  * Returns true if the command is enabled, false otherwise.
129  *
130  * @return Always true.
131  */
132 bool
134  return true;
135 }
136 
137 /**
138  * Returns shortened name of the command for toolbar button text.
139  *
140  * @return Short version of the command name.
141  */
142 std::string
144  return "Machine";
145 }
ProximOpenMachineCmd
Definition: ProximOpenMachineCmd.hh:43
FileSystem.hh
ProximOpenMachineCmd::id
virtual int id() const
Definition: ProximOpenMachineCmd.cc:111
ProximOpenMachineCmd::create
virtual ProximOpenMachineCmd * create() const
Definition: ProximOpenMachineCmd.cc:122
ProximOpenMachineCmd::ProximOpenMachineCmd
ProximOpenMachineCmd()
Definition: ProximOpenMachineCmd.cc:48
ProximSimulationThread.hh
Proxim.hh
ProximOpenMachineCmd::Do
virtual bool Do()
Definition: ProximOpenMachineCmd.cc:64
assert
#define assert(condition)
Definition: Application.hh:86
ProximConstants::SCL_LOAD_MACHINE
static const std::string SCL_LOAD_MACHINE
Command for loading a new machine in the simulator.
Definition: ProximConstants.hh:147
GUICommand
Definition: GUICommand.hh:43
ProximOpenMachineCmd::~ProximOpenMachineCmd
virtual ~ProximOpenMachineCmd()
Definition: ProximOpenMachineCmd.cc:56
FileSystem::fileExtension
static std::string fileExtension(const std::string &fileName)
Definition: FileSystem.cc:279
ProximConstants
Definition: ProximConstants.hh:46
ProximConstants.hh
ProximOpenMachineCmd.hh
WxConversion.hh
ProximConstants::SCL_LOAD_CONF
static const std::string SCL_LOAD_CONF
Command for loading a new machine configuration file in the simulator.
Definition: ProximConstants.hh:149
ProximOpenMachineCmd::icon
virtual std::string icon() const
Definition: ProximOpenMachineCmd.cc:102
ProximOpenMachineCmd::isEnabled
virtual bool isEnabled()
Definition: ProximOpenMachineCmd.cc:133
WxConversion::toString
static std::string toString(const wxString &source)
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
ProximConstants::COMMAND_OPEN_MACHINE
@ COMMAND_OPEN_MACHINE
Definition: ProximConstants.hh:53
ProximOpenMachineCmd::shortName
virtual std::string shortName() const
Definition: ProximOpenMachineCmd.cc:143