OpenASIP  2.0
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 
44 using std::string;
45 
46 /**
47  * The Constructor.
48  */
50  EditorCommand(ProDeConstants::CMD_NAME_MODIFY_COMP) {
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 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  */
105 int
108 }
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  */
127 string
130 }
131 
132 /**
133  * Returns path to the command's icon file.
134  *
135  * @return Full path to the command's icon file.
136  */
137 string
140 }
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  */
152 bool
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 }
ModifyComponentCmd::id
virtual int id() const
Definition: ModifyComponentCmd.cc:106
ProDeConstants::CMD_SNAME_MODIFY_COMP
static const std::string CMD_SNAME_MODIFY_COMP
Command name for the "Delete Component" command.
Definition: ProDeConstants.hh:265
ModifyComponentCmd::icon
virtual std::string icon() const
Definition: ModifyComponentCmd.cc:138
ModifyComponentCmd::isEnabled
virtual bool isEnabled()
Definition: ModifyComponentCmd.cc:153
ProDeConstants::COMMAND_MODIFY_COMP
@ COMMAND_MODIFY_COMP
Definition: ProDeConstants.hh:431
MDFDocument.hh
ModifyComponentCmd::create
virtual ModifyComponentCmd * create() const
Definition: ModifyComponentCmd.cc:117
ModifyComponentCmd::Do
virtual bool Do()
Definition: ModifyComponentCmd.cc:61
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
ModifyComponentCmd
Definition: ModifyComponentCmd.hh:43
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
Request.hh
ComponentCommand::setParentWindow
void setParentWindow(wxWindow *window)
Definition: ComponentCommand.cc:55
WarningDialog.hh
EditPart.hh
ProDeConstants::CMD_ICON_MODIFY_COMP
static const std::string CMD_ICON_MODIFY_COMP
Icon location for the "Modify Component" command.
Definition: ProDeConstants.hh:316
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
ModifyComponentCmd::shortName
virtual std::string shortName() const
Definition: ModifyComponentCmd.cc:128
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
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition: Request.hh:48
EditorCommand
Definition: EditorCommand.hh:46
ModifyComponentCmd::ModifyComponentCmd
ModifyComponentCmd()
Definition: ModifyComponentCmd.cc:49
ModifyComponentCmd.hh
ProDeConstants
Definition: ProDeConstants.hh:43
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
MDFView
Definition: MDFView.hh:59
ComponentCommand.hh