OpenASIP  2.0
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 
43 using std::string;
44 
45 /**
46  * The Constructor.
47  */
49  EditorCommand(ProDeConstants::CMD_NAME_DELETE_COMP) {
50 
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(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  */
104 int
107 }
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  */
126 string
129 }
130 
131 /**
132  * Returns path to the command's icon file.
133  *
134  * @return Full path to the command's icon file.
135  */
136 string
139 }
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  */
151 bool
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 }
ProDeConstants::CMD_ICON_DELETE_COMP
static const std::string CMD_ICON_DELETE_COMP
Icon location for the "Delete Component" command.
Definition: ProDeConstants.hh:318
DeleteComponentCmd::icon
virtual std::string icon() const
Definition: DeleteComponentCmd.cc:137
MDFDocument.hh
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
DeleteComponentCmd::Do
virtual bool Do()
Definition: DeleteComponentCmd.cc:61
ProDeConstants::COMMAND_DELETE_COMP
@ COMMAND_DELETE_COMP
Definition: ProDeConstants.hh:430
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
DeleteComponentCmd.hh
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
Request.hh
DeleteComponentCmd::isEnabled
virtual bool isEnabled()
Definition: DeleteComponentCmd.cc:152
EditPart.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
EditPart
Definition: EditPart.hh:60
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
DeleteComponentCmd::shortName
virtual std::string shortName() const
Definition: DeleteComponentCmd.cc:127
Request
Definition: Request.hh:43
DeleteComponentCmd::DeleteComponentCmd
DeleteComponentCmd()
Definition: DeleteComponentCmd.cc:48
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
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants::CMD_SNAME_DELETE_COMP
static const std::string CMD_SNAME_DELETE_COMP
Command name for the "Modify Component" command.
Definition: ProDeConstants.hh:267
ProDeConstants
Definition: ProDeConstants.hh:43
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
DeleteComponentCmd
Definition: DeleteComponentCmd.hh:43
DeleteComponentCmd::create
virtual DeleteComponentCmd * create() const
Definition: DeleteComponentCmd.cc:116
MDFView
Definition: MDFView.hh:59
DeleteComponentCmd::id
virtual int id() const
Definition: DeleteComponentCmd.cc:105
ComponentCommand.hh