OpenASIP  2.0
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 
45 using std::string;
46 
47 /**
48  * The Constructor.
49  */
51  EditorCommand(ProDeConstants::CMD_NAME_COPY) {
52 }
53 
54 
55 
56 /**
57  * Executes the command.
58  *
59  * @return True, if the command was succesfully executed, false otherwise.
60  */
61 bool
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  */
96 int
99 }
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  */
119 string
122 }
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  */
134 bool
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 }
ProDe.hh
MDFDocument.hh
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
ProDeConstants::COMMAND_COPY
@ COMMAND_COPY
Definition: ProDeConstants.hh:436
ComponentCommand::Do
virtual bool Do()=0
assert
#define assert(condition)
Definition: Application.hh:86
CopyComponentCmd::create
virtual CopyComponentCmd * create() const
Definition: CopyComponentCmd.cc:108
Request.hh
CopyComponentCmd::isEnabled
virtual bool isEnabled()
Definition: CopyComponentCmd.cc:135
ComponentCommand::setParentWindow
void setParentWindow(wxWindow *window)
Definition: ComponentCommand.cc:55
Request::COPY_REQUEST
@ COPY_REQUEST
Copy request.
Definition: Request.hh:51
EditPart.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
Application.hh
CopyComponentCmd::Do
virtual bool Do()
Definition: CopyComponentCmd.cc:62
EditPart
Definition: EditPart.hh:60
CopyComponentCmd::CopyComponentCmd
CopyComponentCmd()
Definition: CopyComponentCmd.cc:50
ProDeConstants::CMD_ICON_COPY
static const std::string CMD_ICON_COPY
Icon location for the "Copy" command.
Definition: ProDeConstants.hh:310
Request
Definition: Request.hh:43
ProDeConstants.hh
CopyComponentCmd
Definition: CopyComponentCmd.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
MDFView::selection
EditPart * selection()
Definition: MDFView.cc:169
CopyComponentCmd::id
virtual int id() const
Definition: CopyComponentCmd.cc:97
CopyComponentCmd.hh
MDFView.hh
CopyComponentCmd::icon
virtual std::string icon() const
Definition: CopyComponentCmd.cc:120
EditPart::canHandle
bool canHandle(Request *request) const
Definition: EditPart.cc:316
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants
Definition: ProDeConstants.hh:43
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
MDFView
Definition: MDFView.hh:59
ComponentCommand.hh