OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdModifyBehaviorCmd.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 OSEdModifyBehaviorCmd.cc
26 *
27 * Definition of OSEdModifyBehaviorCmd class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <boost/format.hpp>
34
36#include "OSEdConstants.hh"
37#include "OperationContainer.hh"
38#include "FileSystem.hh"
39#include "OSEd.hh"
40#include "WxConversion.hh"
41#include "ErrorDialog.hh"
42#include "OSEdTextGenerator.hh"
43#include "CommandThread.hh"
44#include "OperationModule.hh"
45#include "OSEdTreeView.hh"
46#include "OSEdOptions.hh"
47
48using std::string;
49using boost::format;
50
51/**
52 * Constructor.
53 */
55 GUICommand(OSEdConstants::CMD_NAME_MODIFY_BEHAVIOR, NULL) {
56}
57
58/**
59 * Destructor.
60 */
63
64/**
65 * Returns the id of the command.
66 *
67 * @return The id of the command.
68 */
69int
73
74/**
75 * Creates a new command.
76 *
77 * @return A new command.
78 */
83
84/**
85 * Executes the command.
86 *
87 * @return True if execution is successful.
88 */
89bool
91
93 OSEdOptions* options = wxGetApp().options();
94 string editor = options->editor();
95 if (editor == "") {
98 error.ShowModal();
99 return false;
100 } else if (!FileSystem::fileExists(editor)) {
101 format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_OPEN);
102 fmt % editor;
104 error.ShowModal();
105 return false ;
106 } else {
107
108 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
109 wxTreeItemId opId = treeView->selectedOperationId();
110 string modName = treeView->moduleOfOperation(opId);
111 wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
112 string pathName = treeView->pathOfModule(modId);
113
114 OperationModule& module = OperationContainer::module(pathName, modName);
115 string cmd = "";
116 if (module.hasBehaviorSource()) {
117 string code = module.behaviorSourceModule();
118 cmd = editor + " " + code;
119 } else {
120 // new behavior is added for the module
121 string code = module.propertiesModule();
122 size_t pos = code.find_last_of(".");
123 code.erase(pos);
124 code += ".cc";
125
126 // copy template file as new file
127 string dir = Environment::dataDirPath(
129
130 string templateFile = dir + FileSystem::DIRECTORY_SEPARATOR +
132
133 FileSystem::copy(templateFile, code);
134 cmd = editor + " " + code;
135 }
136 // we are using detached thread that will be automatically cleaned
137 CommandThread* thread = new CommandThread(cmd);
138 thread->Create();
139 thread->Run();
140 return true;
141 }
142
143 assert(false);
144 return false;
145}
146
147/**
148 * Returns true if command is enabled.
149 *
150 * Command is enable when path of the selected operation is writable.
151 *
152 * @return True if command is enabled.
153 */
154bool
156 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
157 if (treeView->isOperationSelected()) {
158 wxTreeItemId opId = treeView->selectedOperationId();
159 string mod = treeView->moduleOfOperation(opId);
160 wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
161 string path = treeView->pathOfModule(modId);
162
163 if (FileSystem::fileIsWritable(path)) {
164 return true;
165 } else {
166 return false;
167 }
168 } else {
169 return false;
170 }
171}
172
173/**
174 * Returns the icon path.
175 *
176 * @return Empty string (icons not used).
177 */
178string
180 return "";
181}
#define assert(condition)
find Finds info of the inner loops in the false
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
static std::string dataDirPath(const std::string &prog)
static const std::string DIRECTORY_SEPARATOR
static void copy(const std::string &source, const std::string &target)
static bool fileIsWritable(const std::string fileName)
static bool fileExists(const std::string fileName)
wxWindow * parentWindow() const
Definition GUICommand.cc:75
static const wxString APPLICATION_NAME
The name of the application.
@ CMD_MODIFY_BEHAVIOR
Modify operation behavior command id.
static const std::string BEHAVIOR_TEMPLATE_FILE_NAME
Name of the behavior template file name.
virtual GUICommand * create() const
virtual std::string icon() const
static OSEdTextGenerator & instance()
@ TXT_ERROR_OPEN
Error when opening fails.
@ TXT_ERROR_NO_EDITOR
Error when no editor is given.
std::string pathOfModule(wxTreeItemId id)
bool isOperationSelected() const
wxTreeItemId selectedOperationId()
wxTreeItemId moduleIdOfOperation(wxTreeItemId id)
std::string moduleOfOperation(wxTreeItemId id)
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)