OpenASIP  2.0
OSEdBuildAllCmd.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 OSEdBuildAllCmd.cc
26  *
27  * Definition of OSEdBuildAllCmd class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <vector>
34 #include <boost/format.hpp>
35 #include <wx/timer.h>
36 
37 #include "OSEdBuildAllCmd.hh"
38 #include "OSEdConstants.hh"
39 #include "OperationBuilder.hh"
40 #include "ResultDialog.hh"
41 #include "OperationContainer.hh"
42 #include "OSEdTextGenerator.hh"
43 #include "OperationModule.hh"
44 #include "OperationIndex.hh"
45 #include "WxConversion.hh"
46 #include "OSEd.hh"
47 #include "SimulateDialog.hh"
48 
49 using std::string;
50 using std::vector;
51 using std::map;
52 using boost::format;
53 
54 /**
55  * Constructor.
56  */
58  GUICommand(OSEdConstants::CMD_NAME_BUILD_ALL, NULL) {
59 }
60 
61 /**
62  * Destructor.
63  */
65 }
66 
67 /**
68  * Returns the id of the command.
69  *
70  * @return The id of the command.
71  */
72 int
75 }
76 
77 /**
78  * Returns a new command.
79  *
80  * @return A new command.
81  */
84  return new OSEdBuildAllCmd();
85 }
86 
87 /**
88  * Executes the command.
89  *
90  * @return True if execution is successful.
91  */
92 bool
94 
95  wxWindow* simulateDialog =
96  wxGetApp().mainFrame()->FindWindowByName(SimulateDialog::DIALOG_NAME);
97 
98  if (simulateDialog != NULL) {
99  simulateDialog->Close();
100  }
101 
105  wxStatusBar* statusBar = wxGetApp().mainFrame()->statusBar();
106 
107  vector<OperationModule> buildModules;
108  vector<string> paths;
109  for (int i = 0; i < index.pathCount(); i++) {
110 
111  string path = index.path(i);
112  for (int k = 0; k < index.moduleCount(path); k++) {
113 
114  OperationModule& module = index.module(k, path);
115  if (module.hasBehaviorSource()) {
116  buildModules.push_back(module);
117  paths.push_back(path);
118  }
119  }
120  }
121 
122  vector<string> output;
123  wxStopWatch sw;
124  sw.Pause();
125  wxBusyCursor* busy = new wxBusyCursor();
126  bool compileOk = true;
127  for (size_t i = 0; i < buildModules.size(); i++) {
128  OperationModule module = buildModules[i];
129  string path = paths[i];
130  output.push_back(module.name() + ":\n");
131  size_t oldSize = output.size();
132 
133  sw.Resume();
134  builder.buildObject(module.name(),
135  module.behaviorSourceModule(),
136  path, output);
137  sw.Pause();
138 
139  if (oldSize != output.size()) {
140  compileOk = false;
141  }
142  output.push_back("\n");
143  }
144 
145  delete busy;
146 
147  if (!compileOk) {
149  statusBar->SetStatusText(WxConversion::toWxString(fmt.str()));
151  ResultDialog dialog(parentWindow(), output, fmt.str());
152  dialog.ShowModal();
153  } else {
155  fmt % sw.Time();
156  statusBar->SetStatusText(WxConversion::toWxString(fmt.str()));
157  }
158  return true;
159 }
160 
161 /**
162  * Returns true if command is enabled.
163  *
164  * Command is enabled, if at least one module has behavior source file.
165  *
166  * @return True if command is enabled.
167  */
168 bool
171  for (int i = 0; i < index.moduleCount(); i++) {
172  OperationModule& module = index.module(i);
173  if (module.hasBehaviorSource()) {
174  return true;
175  }
176  }
177  return false;
178 }
179 
180 /**
181  * Returns icon path.
182  *
183  * @return Empty string (icons not used).
184  */
185 string
187  return "";
188 }
OSEdBuildAllCmd::icon
virtual std::string icon() const
Definition: OSEdBuildAllCmd.cc:186
OSEdTextGenerator::TXT_BUILD_RESULT_DIALOG_TITLE
@ TXT_BUILD_RESULT_DIALOG_TITLE
Build result dialog title.
Definition: OSEdTextGenerator.hh:115
WxConversion::toWxString
static wxString toWxString(const std::string &source)
OSEdBuildAllCmd::create
virtual GUICommand * create() const
Definition: OSEdBuildAllCmd.cc:83
SimulateDialog.hh
OSEdBuildAllCmd::Do
virtual bool Do()
Definition: OSEdBuildAllCmd.cc:93
OSEd.hh
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ResultDialog.hh
OSEdConstants.hh
OSEdBuildAllCmd.hh
OSEdBuildAllCmd::isEnabled
virtual bool isEnabled()
Definition: OSEdBuildAllCmd.cc:169
OperationIndex::pathCount
int pathCount() const
GUICommand
Definition: GUICommand.hh:43
OperationBuilder
Definition: OperationBuilder.hh:42
OSEdTextGenerator::TXT_STATUS_COMPILE_FAILED
@ TXT_STATUS_COMPILE_FAILED
Status bar text when compilation failed.
Definition: OSEdTextGenerator.hh:222
OperationModule::behaviorSourceModule
virtual std::string behaviorSourceModule() const
Definition: OperationModule.cc:144
OperationIndex.hh
OSEdConstants
Definition: OSEdConstants.hh:45
OSEdTextGenerator::TXT_STATUS_COMPILE_SUCCESS
@ TXT_STATUS_COMPILE_SUCCESS
Status bar text when compiling was successful.
Definition: OSEdTextGenerator.hh:220
ResultDialog
Definition: ResultDialog.hh:44
OSEdBuildAllCmd::OSEdBuildAllCmd
OSEdBuildAllCmd()
Definition: OSEdBuildAllCmd.cc:57
OSEdBuildAllCmd::~OSEdBuildAllCmd
virtual ~OSEdBuildAllCmd()
Definition: OSEdBuildAllCmd.cc:64
SimulateDialog::DIALOG_NAME
static const wxString DIALOG_NAME
Name of the dialog so it can be found with wxWindow::FindWindowByName.
Definition: SimulateDialog.hh:66
OperationBuilder::buildObject
bool buildObject(const std::string &baseName, const std::string &behaviorFile, const std::string &path, std::vector< std::string > &output)
Definition: OperationBuilder.cc:141
OperationIndex::moduleCount
int moduleCount() const
OperationModule
Definition: OperationModule.hh:46
OperationModule::hasBehaviorSource
virtual bool hasBehaviorSource() const
Definition: OperationModule.cc:131
OperationIndex::path
std::string path(int i) const
OperationIndex
Definition: OperationIndex.hh:58
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdConstants::CMD_BUILD_ALL
@ CMD_BUILD_ALL
Build all command id.
Definition: OSEdConstants.hh:99
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OperationModule::name
virtual std::string name() const
Definition: OperationModule.cc:160
OSEdTextGenerator.hh
OperationBuilder.hh
OperationContainer::operationIndex
static OperationIndex & operationIndex()
Definition: OperationContainer.cc:94
OperationIndex::module
OperationModule & module(int i)
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
OperationModule.hh
OperationBuilder::instance
static OperationBuilder & instance()
Definition: OperationBuilder.cc:71
OSEdBuildAllCmd::id
virtual int id() const
Definition: OSEdBuildAllCmd.cc:73
OperationContainer.hh