OpenASIP 2.2
Loading...
Searching...
No Matches
CutComponentCmd.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 CutComponentCmd.cc
26 *
27 * Implementation of CutComponentCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 */
31
32#include <wx/docview.h>
33
34#include "Application.hh"
35#include "CutComponentCmd.hh"
36#include "ComponentCommand.hh"
37#include "MDFView.hh"
38#include "MDFDocument.hh"
39#include "EditPart.hh"
40#include "ProDeConstants.hh"
41#include "Request.hh"
42#include "ProDe.hh"
43
44using std::string;
45
46/**
47 * The Constructor.
48 */
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(view() != NULL);
64
65 Request* copyRequest = new Request(Request::COPY_REQUEST);
66 Request* deleteRequest = new Request(Request::DELETE_REQUEST);
67
68 EditPart* selected = dynamic_cast<MDFView*>(view())->selection();
69 if (selected == NULL) {
70 return false;
71 }
72
73 // Request copy and delete commands.
74 ComponentCommand* copyCommand = selected->performRequest(copyRequest);
75 ComponentCommand* deleteCommand = selected->performRequest(deleteRequest);
76
77 // Execute the returned commands.
78 if (copyCommand == NULL || deleteCommand == NULL) {
79 return false;
80 } else {
81
82 dynamic_cast<MDFView*>(view())->clearSelection();
83
84 Model* model = dynamic_cast<MDFDocument*>(
85 wxGetApp().docManager()->GetCurrentDocument())->getModel();
86
87 model->pushToStack();
88
89 // copy
90 copyCommand->setParentWindow(parentWindow());
91 copyCommand->Do();
92
93 // delete
94 deleteCommand->setParentWindow(parentWindow());
95 deleteCommand->Do();
96
97 model->notifyObservers();
98
99 return false;
100 }
101}
102
103
104/**
105 * Returns command identifier of this command.
106 *
107 * @return ID for this command to be used in menus and toolbars.
108 */
109int
113
114
115/**
116 * Creates and returns a new instance of this command.
117 *
118 * @return Newly created instance of this command.
119 */
122 return new CutComponentCmd();
123}
124
125
126
127/**
128 * Returns path to the command's icon file.
129 *
130 * @return Full path to the command's icon file.
131 */
132string
136
137
138
139/**
140 * Returns true when the command is executable, false when not.
141 *
142 * This command is executable when a component is selected, and the
143 * selected component can be copied and deleted.
144 *
145 * @return True, if a component is selected.
146 */
147bool
149 wxDocManager* manager = wxGetApp().docManager();
150
151 MDFView* mdfView = dynamic_cast<MDFView*>(manager->GetCurrentView());
152 if (mdfView == NULL) {
153 return false;
154 }
155
156 EditPart* selected = mdfView->selection();
157 Request* copyRequest = new Request(Request::COPY_REQUEST);
158 Request* deleteRequest = new Request(Request::DELETE_REQUEST);
159 if (selected == NULL ||
160 !(selected->canHandle(copyRequest)) ||
161 !(selected->canHandle(deleteRequest))) {
162
163 delete copyRequest;
164 return false;
165 }
166 delete copyRequest;
167 delete deleteRequest;
168 return true;
169}
#define assert(condition)
virtual bool Do()=0
void setParentWindow(wxWindow *window)
virtual bool isEnabled()
virtual int id() const
virtual std::string icon() const
virtual bool Do()
virtual CutComponentCmd * 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
static const std::string CMD_ICON_CUT
Icon location for the "Cut" command.
@ DELETE_REQUEST
Delete request.
Definition Request.hh:49
@ COPY_REQUEST
Copy request.
Definition Request.hh:51