OpenASIP  2.0
OSEdRemoveModuleCmd.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 OSEdRemoveModuleCmd.cc
26  *
27  * Definition of OSEdRemoveModuleCmd 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 #include <iostream>
35 
36 #include "OSEdRemoveModuleCmd.hh"
37 #include "OSEdConstants.hh"
38 #include "ConfirmDialog.hh"
39 #include "OSEdTextGenerator.hh"
40 #include "OperationContainer.hh"
41 #include "WxConversion.hh"
42 #include "FileSystem.hh"
43 #include "Application.hh"
44 #include "OperationModule.hh"
45 #include "OSEd.hh"
46 #include "OSEdTreeView.hh"
47 #include "OSEdInfoView.hh"
48 #include "OperationIndex.hh"
49 
50 using std::string;
51 using boost::format;
52 using std::cout;
53 using std::endl;
54 
55 /**
56  * Constructor.
57  */
59  GUICommand(OSEdConstants::CMD_NAME_REMOVE_MODULE, NULL) {
60 }
61 
62 /**
63  * Destructor.
64  */
66 }
67 
68 /**
69  * Returns the id of the command.
70  *
71  * @return Id of the command.
72  */
73 int
76 }
77 
78 /**
79  * Returns a new command.
80  *
81  * @return A new command.
82  */
85  return new OSEdRemoveModuleCmd();
86 }
87 
88 /**
89  * Executes the command.
90  *
91  * @return True if execution is successful.
92  */
93 bool
95 
97  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
98  string modName = treeView->selectedModule();
99  wxTreeItemId modId = treeView->selectedModuleId();
100  string path = treeView->pathOfModule(modId);
101 
102  OperationModule& module = OperationContainer::module(path, modName);
103 
105  fmt % modName;
107 
108  if (dialog.ShowModal() == wxID_YES) {
109  bool removed =
111  assert(removed == true);
112 
113  if (module.hasBehaviorSource()) {
114  fmt = texts.text(
116 
118 
119  wxString confText = WxConversion::toWxString(fmt.str());
120  ConfirmDialog confirm(parentWindow(), confText);
121 
122  if (confirm.ShowModal() == wxID_YES) {
124  }
125  }
126 
127  if (module.definesBehavior()) {
129  }
130 
132  index.removeModule(path, modName);
133  treeView->removeItem(modId);
134  treeView->infoView()->moduleView(path);
135  }
136  return true;
137 }
138 
139 /**
140  * Returns true if command is enabled.
141  *
142  * @return True if command is enabled.
143  */
144 bool
146  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
147  if (treeView->isModuleSelected()) {
148  wxTreeItemId modId = treeView->selectedModuleId();
149  string path = treeView->pathOfModule(modId);
150  if (path != "") {
151  return FileSystem::fileIsWritable(path);
152  } else {
153  return false;
154  }
155  } else {
156  return false;
157  }
158 
159  assert(false);
160  return false;
161 }
162 
163 /**
164  * Returns icon path.
165  *
166  * @return Empty string (no icons used).
167  */
168 string
170  return "";
171 }
OSEdTreeView::selectedModule
std::string selectedModule()
Definition: OSEdTreeView.cc:513
OperationModule::definesBehavior
virtual bool definesBehavior() const
Definition: OperationModule.cc:93
OSEdTreeView::selectedModuleId
wxTreeItemId selectedModuleId()
Definition: OSEdTreeView.cc:537
FileSystem.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
OSEdTreeView::removeItem
void removeItem(wxTreeItemId id)
Definition: OSEdTreeView.cc:622
OSEdTreeView::pathOfModule
std::string pathOfModule(wxTreeItemId id)
Definition: OSEdTreeView.cc:431
OperationContainer::module
static OperationModule & module(const std::string &path, const std::string &mod)
Definition: OperationContainer.cc:148
OSEdRemoveModuleCmd::create
virtual GUICommand * create() const
Definition: OSEdRemoveModuleCmd.cc:84
OperationModule::behaviorModule
virtual std::string behaviorModule() const
Definition: OperationModule.cc:105
OSEd.hh
OSEdTreeView::infoView
OSEdInfoView * infoView() const
Definition: OSEdTreeView.cc:662
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
OSEdInfoView.hh
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
OSEdConstants.hh
OSEdInfoView::moduleView
void moduleView(const std::string &name)
Definition: OSEdInfoView.cc:129
assert
#define assert(condition)
Definition: Application.hh:86
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:121
GUICommand
Definition: GUICommand.hh:43
OSEdRemoveModuleCmd::id
virtual int id() const
Definition: OSEdRemoveModuleCmd.cc:74
FileSystem::fileIsWritable
static bool fileIsWritable(const std::string fileName)
OSEdConstants::CMD_REMOVE_MODULE
@ CMD_REMOVE_MODULE
Remove module command id.
Definition: OSEdConstants.hh:95
OSEdTreeView
Definition: OSEdTreeView.hh:54
OperationModule::behaviorSourceModule
virtual std::string behaviorSourceModule() const
Definition: OperationModule.cc:144
OperationIndex.hh
ConfirmDialog.hh
Application.hh
OSEdConstants
Definition: OSEdConstants.hh:45
OSEdTreeView::isModuleSelected
bool isModuleSelected() const
Definition: OSEdTreeView.cc:731
OSEdRemoveModuleCmd::isEnabled
virtual bool isEnabled()
Definition: OSEdRemoveModuleCmd.cc:145
ConfirmDialog
Definition: ConfirmDialog.hh:41
OSEdTreeView.hh
OSEdRemoveModuleCmd::icon
virtual std::string icon() const
Definition: OSEdRemoveModuleCmd.cc:169
OperationModule
Definition: OperationModule.hh:46
OperationModule::hasBehaviorSource
virtual bool hasBehaviorSource() const
Definition: OperationModule.cc:131
OperationIndex
Definition: OperationIndex.hh:58
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdRemoveModuleCmd::~OSEdRemoveModuleCmd
virtual ~OSEdRemoveModuleCmd()
Definition: OSEdRemoveModuleCmd.cc:65
OperationIndex::removeModule
void removeModule(const std::string &path, const std::string &modName)
Definition: OperationIndex.cc:212
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OSEdRemoveModuleCmd::OSEdRemoveModuleCmd
OSEdRemoveModuleCmd()
Definition: OSEdRemoveModuleCmd.cc:58
OSEdRemoveModuleCmd.hh
OSEdTextGenerator.hh
OperationContainer::operationIndex
static OperationIndex & operationIndex()
Definition: OperationContainer.cc:94
OSEdTextGenerator::TXT_QUESTION_REMOVE_MODULE
@ TXT_QUESTION_REMOVE_MODULE
Remove module question.
Definition: OSEdTextGenerator.hh:208
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
OSEdTextGenerator::TXT_QUESTION_REMOVE_BEHAVIOR_FILE
@ TXT_QUESTION_REMOVE_BEHAVIOR_FILE
Remove behavior question.
Definition: OSEdTextGenerator.hh:209
OperationModule.hh
OSEdRemoveModuleCmd::Do
virtual bool Do()
Definition: OSEdRemoveModuleCmd.cc:94
OperationContainer.hh