OpenASIP 2.2
Loading...
Searching...
No Matches
DeleteComponentCmd.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 DeleteComponentCmd.cc
26 *
27 * Implementation of DeleteComponentCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/docview.h>
34
35#include "DeleteComponentCmd.hh"
36#include "ComponentCommand.hh"
37#include "MDFView.hh"
38#include "Request.hh"
39#include "MDFDocument.hh"
40#include "EditPart.hh"
41#include "ProDeConstants.hh"
42
43using std::string;
44
45/**
46 * The Constructor.
47 */
52
53
54
55/**
56 * Executes the command.
57 *
58 * @return True, if the command was succesfully executed, false otherwise.
59 */
60bool
62
63 assert(parentWindow() != NULL);
64 assert(view() != NULL);
65
66 // send delete request to the selected EditPart
67 Request* deleteRequest = new Request(Request::DELETE_REQUEST);
68 EditPart* selected = dynamic_cast<MDFView*>(view())->selection();
69 if (selected == NULL) {
70 return false;
71 }
72
73 ComponentCommand* command = selected->performRequest(deleteRequest);
74
75 // execute the returned command
76 if (command == NULL) {
77 return false;
78 } else {
79 Model* model = dynamic_cast<MDFDocument*>(
80 wxGetApp().docManager()->GetCurrentDocument())->getModel();
81
82 model->pushToStack();
83
84 dynamic_cast<MDFView*>(view())->clearSelection();
85 bool result = command->Do();
86
87 if (result) {
88 // Model was modified.
89 model->notifyObservers();
90 } else {
91 // Command was cancelled.
92 model->popFromStack();
93 }
94 return result;
95 }
96}
97
98
99/**
100 * Returns command identifier of this command.
101 *
102 * @return ID for this command to be used in menus and toolbars.
103 */
104int
108
109
110/**
111 * Creates and returns a new instance of this command.
112 *
113 * @return Newly created instance of this command.
114 */
117 return new DeleteComponentCmd();
118}
119
120
121/**
122 * Returns short version of the command name.
123 *
124 * @return Short name of the command to be used in the toolbar.
125 */
126string
130
131/**
132 * Returns path to the command's icon file.
133 *
134 * @return Full path to the command's icon file.
135 */
136string
140
141
142
143/**
144 * Returns true when the command is executable, false when not.
145 *
146 * This command is executable when a block is selected, and the
147 * block can handle a delete request.
148 *
149 * @return True, if a deletable block is selected.
150 */
151bool
153 wxDocManager* manager = wxGetApp().docManager();
154
155 MDFView* mdfView = dynamic_cast<MDFView*>(manager->GetCurrentView());
156 if (mdfView == NULL) {
157 return false;
158 }
159 Request* deleteRequest = new Request(Request::DELETE_REQUEST);
160 if (mdfView->selection() == NULL ||
161 !mdfView->selection()->canHandle(deleteRequest)) {
162
163 return false;
164 }
165 delete deleteRequest;
166 return true;
167}
#define assert(condition)
virtual bool Do()=0
virtual int id() const
virtual std::string icon() const
virtual std::string shortName() const
virtual DeleteComponentCmd * create() const
bool canHandle(Request *request) const
Definition EditPart.cc:316
ComponentCommand * performRequest(Request *request) const
Definition EditPart.cc:297
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
EditPart * selection()
Definition MDFView.cc:169
Definition Model.hh:50
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
void popFromStack(bool modified=false)
Definition Model.cc:195
static const std::string CMD_ICON_DELETE_COMP
Icon location for the "Delete Component" command.
static const std::string CMD_SNAME_DELETE_COMP
Command name for the "Modify Component" command.
@ DELETE_REQUEST
Delete request.
Definition Request.hh:49