OpenASIP  2.0
OSEdBuildCmd.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 OSEdBuildCmd.cc
26  *
27  * Definition of OSEdBuildCmd 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 "OSEdBuildCmd.hh"
38 #include "OSEdConstants.hh"
39 #include "OSEd.hh"
40 #include "OperationBuilder.hh"
41 #include "OperationContainer.hh"
42 #include "ResultDialog.hh"
43 #include "OSEdTextGenerator.hh"
44 #include "OperationModule.hh"
45 #include "OSEdTreeView.hh"
46 #include "WxConversion.hh"
47 #include "SimulateDialog.hh"
48 
49 using std::string;
50 using std::vector;
51 using boost::format;
52 
53 /**
54  * Constructor.
55  */
57  GUICommand(OSEdConstants::CMD_NAME_BUILD, NULL) {
58 }
59 
60 /**
61  * Destructor.
62  */
64 }
65 
66 /**
67  * Returns the id of the command.
68  *
69  * @return The id of the command.
70  */
71 int
74 }
75 
76 /**
77  * Creates a new command.
78  *
79  * @return A new command.
80  */
83  return new OSEdBuildCmd();
84 }
85 
86 /**
87  * Executes the command.
88  *
89  * @return True if execution is successful.
90  */
91 bool
93 
94  wxWindow* simulateDialog =
95  wxGetApp().mainFrame()->FindWindowByName(SimulateDialog::DIALOG_NAME);
96 
97  if (simulateDialog != NULL) {
98  simulateDialog->Close();
99  }
100 
102  wxStatusBar* statusBar = wxGetApp().mainFrame()->statusBar();
103  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
104 
105  string modName = treeView->selectedModule();
106  wxTreeItemId modId = treeView->selectedModuleId();
107  string pathName = treeView->pathOfModule(modId);
108  OperationModule& module = OperationContainer::module(pathName, modName);
109 
110  format fmt = texts.text(OSEdTextGenerator::TXT_STATUS_COMPILING);
111  fmt % module.name();
112  statusBar->SetStatusText(WxConversion::toWxString(fmt.str()));
113 
114  vector<string> output;
115  output.push_back(module.name() + ":\n");
117  size_t oldSize = output.size();
118 
119  wxStopWatch sw;
120  wxBusyCursor* busy = new wxBusyCursor();
121  builder.buildObject(
122  module.name(), module.behaviorSourceModule(), pathName, output);
123  delete busy;
124  sw.Pause();
125 
126  if (oldSize == output.size()) {
128  fmt % sw.Time();
129  statusBar->SetStatusText(WxConversion::toWxString(fmt.str()));
130  } else {
132  statusBar->SetStatusText(WxConversion::toWxString(fmt.str()));
134  ResultDialog dialog(parentWindow(), output, fmt.str(),
135  module.behaviorSourceModule());
136  dialog.ShowModal();
137  }
138  return true;
139 }
140 
141 /**
142  * Returns true if command is enabled.
143  *
144  * Command is enabled when module with behavior source file has been
145  * selected.
146  *
147  * @return True if command is enabled.
148  */
149 bool
151  OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
152  OSEdTreeView* treeView = mainFrame->treeView();
153  string modName = treeView->selectedModule();
154  if (modName == "") {
155  return false;
156  }
157  wxTreeItemId modId = treeView->selectedModuleId();
158  string pathName = treeView->pathOfModule(modId);
159  OperationModule& module = OperationContainer::module(pathName, modName);
160  return module.hasBehaviorSource();
161 }
162 
163 /**
164  * Returns the icon path.
165  *
166  * @return Empty string (icons not used).
167  */
168 string
170  return "";
171 }
OSEdTreeView::selectedModule
std::string selectedModule()
Definition: OSEdTreeView.cc:513
OSEdTreeView::selectedModuleId
wxTreeItemId selectedModuleId()
Definition: OSEdTreeView.cc:537
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)
OSEdTreeView::pathOfModule
std::string pathOfModule(wxTreeItemId id)
Definition: OSEdTreeView.cc:431
OSEdConstants::CMD_BUILD
@ CMD_BUILD
Build command id.
Definition: OSEdConstants.hh:98
OSEdBuildCmd::Do
virtual bool Do()
Definition: OSEdBuildCmd.cc:92
SimulateDialog.hh
OperationContainer::module
static OperationModule & module(const std::string &path, const std::string &mod)
Definition: OperationContainer.cc:148
OSEdTextGenerator::TXT_STATUS_COMPILING
@ TXT_STATUS_COMPILING
Status bar text when compiling.
Definition: OSEdTextGenerator.hh:219
OSEdBuildCmd::id
virtual int id() const
Definition: OSEdBuildCmd.cc:72
OSEd.hh
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
OSEdMainFrame::treeView
OSEdTreeView * treeView() const
Definition: OSEdMainFrame.cc:241
ResultDialog.hh
OSEdConstants.hh
OSEdBuildCmd::create
virtual GUICommand * create() const
Definition: OSEdBuildCmd.cc:82
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
OSEdBuildCmd::icon
virtual std::string icon() const
Definition: OSEdBuildCmd.cc:169
OSEdTreeView
Definition: OSEdTreeView.hh:54
OperationModule::behaviorSourceModule
virtual std::string behaviorSourceModule() const
Definition: OperationModule.cc:144
OSEdConstants
Definition: OSEdConstants.hh:45
OSEdBuildCmd::OSEdBuildCmd
OSEdBuildCmd()
Definition: OSEdBuildCmd.cc:56
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
SimulateDialog::DIALOG_NAME
static const wxString DIALOG_NAME
Name of the dialog so it can be found with wxWindow::FindWindowByName.
Definition: SimulateDialog.hh:66
OSEdTreeView.hh
OSEdMainFrame
Definition: OSEdMainFrame.hh:49
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
OperationModule
Definition: OperationModule.hh:46
OperationModule::hasBehaviorSource
virtual bool hasBehaviorSource() const
Definition: OperationModule.cc:131
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OSEdBuildCmd.hh
OperationModule::name
virtual std::string name() const
Definition: OperationModule.cc:160
OSEdTextGenerator.hh
OperationBuilder.hh
OSEdBuildCmd::isEnabled
virtual bool isEnabled()
Definition: OSEdBuildCmd.cc:150
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
OperationModule.hh
OperationBuilder::instance
static OperationBuilder & instance()
Definition: OperationBuilder.cc:71
OSEdBuildCmd::~OSEdBuildCmd
virtual ~OSEdBuildCmd()
Definition: OSEdBuildCmd.cc:63
OperationContainer.hh