OpenASIP 2.2
Loading...
Searching...
No Matches
ModifyComponentCmd.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 ModifyComponentCmd.cc
26 *
27 * Implementation of ModifyComponentCmd 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 "ModifyComponentCmd.hh"
36#include "ComponentCommand.hh"
37#include "WarningDialog.hh"
38#include "Request.hh"
39#include "MDFView.hh"
40#include "MDFDocument.hh"
41#include "EditPart.hh"
42#include "ProDeConstants.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(parentWindow() != NULL);
64 assert(view() != NULL);
65
66 // send modify request to the selected EditPart
67 Request* modifyRequest = new Request(Request::MODIFY_REQUEST);
68 EditPart* selected = dynamic_cast<MDFView*>(view())->selection();
69 if (selected == NULL) {
70 return false;
71 }
72
73 ComponentCommand* command = selected->performRequest(modifyRequest);
74
75 // execute the returned command
76 if (command == NULL) {
77 return false;
78 } else {
79
80 Model* model = dynamic_cast<MDFDocument*>(
81 wxGetApp().docManager()->GetCurrentDocument())->getModel();
82
83 model->pushToStack();
84
85 dynamic_cast<MDFView*>(view())->clearSelection();
86 command->setParentWindow(parentWindow());
87 bool result = command->Do();
88 if (result) {
89 // Model was modified.
90 model->notifyObservers();
91 } else {
92 // Modification was cancelled.
93 model->popFromStack();
94 }
95 return result;
96 }
97}
98
99
100/**
101 * Returns command identifier of this command.
102 *
103 * @return ID for this command to be used in menus and toolbars.
104 */
105int
109
110
111/**
112 * Creates and returns a new instance of this command.
113 *
114 * @return Newly created instance of this command.
115 */
118 return new ModifyComponentCmd();
119}
120
121
122/**
123 * Returns short version of the command name.
124 *
125 * @return Short name of the command to be used in the toolbar.
126 */
127string
131
132/**
133 * Returns path to the command's icon file.
134 *
135 * @return Full path to the command's icon file.
136 */
137string
141
142
143
144/**
145 * Returns true when the command is executable, false when not.
146 *
147 * This command is executable when a block is selected, and the
148 * selected block can handle modify requests.
149 *
150 * @return True, if a modifyable block is selected.
151 */
152bool
154 wxDocManager* manager = wxGetApp().docManager();
155
156 MDFView* mdfView = dynamic_cast<MDFView*>(manager->GetCurrentView());
157 if (mdfView == NULL) {
158 return false;
159 }
160 Request* modifyRequest = new Request(Request::MODIFY_REQUEST);
161 if (mdfView->selection() == NULL ||
162 !mdfView->selection()->canHandle(modifyRequest)) {
163
164 return false;
165 }
166 return true;
167}
#define assert(condition)
virtual bool Do()=0
void setParentWindow(wxWindow *window)
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
void popFromStack(bool modified=false)
Definition Model.cc:195
virtual std::string shortName() const
virtual int id() const
virtual ModifyComponentCmd * create() const
virtual std::string icon() const
static const std::string CMD_SNAME_MODIFY_COMP
Command name for the "Delete Component" command.
static const std::string CMD_ICON_MODIFY_COMP
Icon location for the "Modify Component" command.
@ MODIFY_REQUEST
Modfify request.
Definition Request.hh:48