OpenASIP 2.2
Loading...
Searching...
No Matches
CopyComponentCmd.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 CopyComponentCmd.cc
26 *
27 * Implementation of CopyComponentCmd 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 "CopyComponentCmd.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
44
45using std::string;
46
47/**
48 * The Constructor.
49 */
53
54
55
56/**
57 * Executes the command.
58 *
59 * @return True, if the command was succesfully executed, false otherwise.
60 */
61bool
63
64 assert(view() != NULL);
65
66 // send copy request to the selected EditPart
67 Request* copyRequest = new Request(Request::COPY_REQUEST);
68 EditPart* selected = dynamic_cast<MDFView*>(view())->selection();
69 if (selected == NULL) {
70 return false;
71 }
72 ComponentCommand* command = selected->performRequest(copyRequest);
73
74 // execute the returned command
75 if (command == NULL) {
76 return false;
77 } else {
78 dynamic_cast<MDFView*>(view())->clearSelection();
79 command->setParentWindow(parentWindow());
80
81 // Copying component to clipboard doesn't modify model.
82 // The model is not pushed into the undo stack.
83 bool result = command->Do();
84
85 return result;
86 }
87
88}
89
90
91/**
92 * Returns command identifier of this command.
93 *
94 * @return ID for this command to be used in menus and toolbars.
95 */
96int
100
101
102/**
103 * Creates and returns a new instance of this command.
104 *
105 * @return Newly created instance of this command.
106 */
109 return new CopyComponentCmd();
110}
111
112
113
114/**
115 * Returns path to the command's icon file.
116 *
117 * @return Full path to the command's icon file.
118 */
119string
123
124
125
126/**
127 * Returns true when the command is executable, false when not.
128 *
129 * This command is executable when a component is selected, and the selected
130 * component can be copied.
131 *
132 * @return True, if a component is selected.
133 */
134bool
136 wxDocManager* manager = wxGetApp().docManager();
137
138 MDFView* mdfView = dynamic_cast<MDFView*>(manager->GetCurrentView());
139 if (mdfView == NULL) {
140 return false;
141 }
142
143 EditPart* selected = mdfView->selection();
144 Request* copyRequest = new Request(Request::COPY_REQUEST);
145 if (selected == NULL || !(selected->canHandle(copyRequest))) {
146 delete copyRequest;
147 return false;
148 }
149 delete copyRequest;
150 return true;
151}
#define assert(condition)
virtual bool Do()=0
void setParentWindow(wxWindow *window)
virtual bool Do()
virtual int id() const
virtual std::string icon() const
virtual CopyComponentCmd * create() const
virtual bool isEnabled()
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
static const std::string CMD_ICON_COPY
Icon location for the "Copy" command.
@ COPY_REQUEST
Copy request.
Definition Request.hh:51