OpenASIP  2.0
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 
44 using std::string;
45 
46 /**
47  * The Constructor.
48  */
50  EditorCommand(ProDeConstants::CMD_NAME_CUT) {
51 }
52 
53 
54 
55 /**
56  * Executes the command.
57  *
58  * @return True, if the command was succesfully executed, false otherwise.
59  */
60 bool
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  */
109 int
112 }
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  */
132 string
135 }
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  */
147 bool
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 }
CutComponentCmd
Definition: CutComponentCmd.hh:43
ProDe.hh
MDFDocument.hh
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ComponentCommand::Do
virtual bool Do()=0
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
ProDeConstants::COMMAND_CUT
@ COMMAND_CUT
Definition: ProDeConstants.hh:435
CutComponentCmd::CutComponentCmd
CutComponentCmd()
Definition: CutComponentCmd.cc:49
Request.hh
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
CutComponentCmd.hh
Application.hh
CutComponentCmd::isEnabled
virtual bool isEnabled()
Definition: CutComponentCmd.cc:148
EditPart
Definition: EditPart.hh:60
CutComponentCmd::Do
virtual bool Do()
Definition: CutComponentCmd.cc:61
CutComponentCmd::id
virtual int id() const
Definition: CutComponentCmd.cc:110
Request
Definition: Request.hh:43
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
ComponentCommand
Definition: ComponentCommand.hh:46
MDFView::selection
EditPart * selection()
Definition: MDFView.cc:169
MDFView.hh
Model
Definition: Model.hh:50
EditPart::canHandle
bool canHandle(Request *request) const
Definition: EditPart.cc:316
ProDeConstants::CMD_ICON_CUT
static const std::string CMD_ICON_CUT
Icon location for the "Cut" command.
Definition: ProDeConstants.hh:312
EditorCommand
Definition: EditorCommand.hh:46
CutComponentCmd::create
virtual CutComponentCmd * create() const
Definition: CutComponentCmd.cc:121
ProDeConstants
Definition: ProDeConstants.hh:43
CutComponentCmd::icon
virtual std::string icon() const
Definition: CutComponentCmd.cc:133
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
MDFView
Definition: MDFView.hh:59
ComponentCommand.hh