OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdAddModuleCmd.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 OSEdAddModuleCmd.cc
26 *
27 * Definition of OSEdAddModuleCmd 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
35#include "OSEdAddModuleCmd.hh"
36#include "OSEdConstants.hh"
37#include "OSEd.hh"
38#include "ErrorDialog.hh"
39#include "OperationContainer.hh"
40#include "Application.hh"
41#include "AddModuleDialog.hh"
42#include "OSEdTextGenerator.hh"
43#include "WxConversion.hh"
44#include "FileSystem.hh"
45#include "OSEdTreeView.hh"
47#include "OperationIndex.hh"
48#include "OperationModule.hh"
49#include "ObjectState.hh"
50
51using std::string;
52using boost::format;
53
54/**
55 * Constructor.
56 */
58 GUICommand(OSEdConstants::CMD_NAME_ADD_MODULE, NULL) {
59}
60
61/**
62 * Destructor.
63 */
66
67/**
68 * Returns the id of the command.
69 *
70 * @return The id of the command.
71 */
72int
76
77/**
78 * Creates a new command.
79 *
80 * @return New command.
81 */
84 return new OSEdAddModuleCmd();
85}
86
87/**
88 * Executes the command.
89 *
90 * @return True if execution is successful.
91 */
92bool
94
95 OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
96 OSEdTreeView* treeView = mainFrame->treeView();
97 string path = treeView->selectedPath();
99 wxTreeItemId pathId = treeView->selectedPathId();
101
102 if (!FileSystem::fileExists(path)) {
103 if (!FileSystem::createDirectory(path)) {
104 format fmt =
106 ErrorDialog error(
108 error.ShowModal();
109 return false;
110 }
111 index.addPath(path);
112 treeView->SetItemBold(pathId);
113 }
114
115 AddModuleDialog dialog(parentWindow(), path);
116 if (dialog.ShowModal() == wxID_OK) {
117
118 OperationModule* module = new OperationModule(dialog.name(), path);
119 OperationSerializer& serializer =
121 serializer.setDestinationFile(module->propertiesModule());
122 ObjectState* root = new ObjectState("osal");
123 try {
124 serializer.writeState(root);
125 } catch (const Exception& e) {
126 format fmt = texts.text(
128
129 ErrorDialog error(parentWindow(),
130 WxConversion::toWxString(fmt.str()));
131 error.ShowModal();
132 delete root;
133 return false;
134 }
135 delete root;
136 index.addModule(module, path);
137 treeView->addItem(pathId, module->name());
138 treeView->update();
139 }
140
141 return true;
142}
143
144/**
145 * Returns true if command is enabled.
146 *
147 * @return True if command is enabled.
148 */
149bool
151 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
152 string path = treeView->selectedPath();
153 if (path != "") {
154 if (FileSystem::fileExists(path)) {
155 string dumbFile = path + FileSystem::DIRECTORY_SEPARATOR +
156 "dumb12234";
157 if (FileSystem::createFile(dumbFile)) {
159 return true;
160 } else {
161 return false;
162 }
163 } else {
164 if (FileSystem::createDirectory(path)) {
166 return true;
167 } else {
168 return false;
169 }
170 }
171 }
172 return false;
173}
174
175/**
176 * Return icon path.
177 *
178 * @return Empty string (no icons used).
179 */
180string
182 return "";
183}
static bool createFile(const std::string &file)
static bool createDirectory(const std::string &path)
static bool removeFileOrDirectory(const std::string &path)
static const std::string DIRECTORY_SEPARATOR
static bool fileExists(const std::string fileName)
wxWindow * parentWindow() const
Definition GUICommand.cc:75
virtual bool isEnabled()
virtual int id() const
virtual std::string icon() const
virtual GUICommand * create() const
virtual ~OSEdAddModuleCmd()
virtual bool Do()
@ CMD_ADD_MODULE
Add module command id.
OSEdTreeView * treeView() const
static OSEdTextGenerator & instance()
@ TXT_ERROR_CAN_NOT_CREATE_MOD
Error when can not create module.
void addItem(wxTreeItemId parent, std::string item)
std::string selectedPath()
wxTreeItemId selectedPathId()
static OperationSerializer & operationSerializer()
static OperationIndex & operationIndex()
void addModule(OperationModule *module, const std::string &path)
void addPath(const std::string &path)
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)