OpenASIP 2.2
Loading...
Searching...
No Matches
SelectTool.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 SelectTool.cc
26 *
27 * Definition of SelectTool class.
28 *
29 * @author Veli-Pekka Jääskeläinen (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34#include <wx/event.h>
35#include <wx/gdicmn.h>
36
37#include "SelectTool.hh"
38#include "Conversion.hh"
39#include "WxConversion.hh"
40#include "MDFView.hh"
41#include "EditPart.hh"
42#include "Request.hh"
43#include "ComponentCommand.hh"
44#include "ModifyComponentCmd.hh"
45#include "CommandRegistry.hh"
46#include "ProDeConstants.hh"
47#include "SelectionFigure.hh"
48#include "MachineCanvas.hh"
49#include "ProDe.hh"
50#include "MainFrame.hh"
51
52using std::string;
53
54
55/**
56 * The Constructor.
57 */
59 ChildFrame* frame, MDFView* view):
60 MachineCanvasTool(view->canvas()),
61 frame_(frame),
62 view_(view),
63 active_(false) {
64
65 figure_ = new SelectionFigure(NULL);
66}
67
68
69/**
70 * The Destructor.
71 */
75
76
77/**
78 * Activates the tool.
79 */
80void
82 active_ = true;
83}
84
85
86/**
87 * Deactivates the tool.
88 */
89void
91 active_ = false;
92}
93
94/**
95 * Returns figure of the selection.
96 *
97 * @return Figure of the selection.
98 */
99Figure*
101 return NULL;
102}
103
104/**
105 * Handles mouse events on the Canvas.
106 *
107 * @param event Mouse event to handle.
108 * @param dc Device context.
109 */
110void
111SelectTool::onMouseEvent(wxMouseEvent& event, wxDC& dc) {
112
113 if (!active_) {
114 return;
115 }
116
117 // Get event position and translate "raw" coordinates to logical ones.
118 wxPoint position = event.GetPosition();
119 int x = position.x;
120 int y = position.y;
121 long logicalX = dc.DeviceToLogicalX(position.x);
122 long logicalY = dc.DeviceToLogicalY(position.y);
123
124 // Check if there is an EditPart at the cursor position.
125 EditPart* part = canvas_->findEditPart(logicalX, logicalY);
126
127 // If an EditPart was found at the cursor position, get name of the
128 // Component related to the EditPart.
129 string status = "";
131 if (part != NULL && part->canHandle(request)) {
132 ComponentCommand* command = part->performRequest(request);
133 if (command != NULL) {
134 if(!command->Do())
135 frame_->setStatus(_T(""));
136 }
137 } else {
138 frame_->setStatus(_T(""));
139 }
140
141 // If left mouse button was released, select the EditPart at cursor
142 // position. (if there is a selectable EditPart)
143 if (event.LeftUp()) {
144 leftClick(part);
145 }
146
147 if (event.RightDown()) {
148 // select component
149 leftClick(part);
150 // popup context menu
151 popContextMenu(part, x, y);
152 }
153
154 // left mouse button double click executes ModifyComponentCmd
155 if (event.ButtonDClick(1)) {
156 ModifyComponentCmd* command = new ModifyComponentCmd();
157 command->setParentWindow(frame_);
158 command->setView(view_);
159 command->Do();
160 }
161
162 wxGetApp().mainFrame()->updateUI();
163}
164
165
166/**
167 * Selects Component at cursor position, if there is a selectable
168 * EditPart at the coordinates.
169 *
170 * @param part Component to select.
171 */
172void
174 if (part != NULL && part->selectable()) {
175 canvas_->select(part);
176 figure_->setSelection(part->figure());
177 } else {
179 }
180}
181
182
183/**
184 * Pops a context menu for the EditPart at the coordinates;
185 *
186 * @param part Context component.
187 * @param x X-coordinate for the menu.
188 * @param y Y-coordinate for the menu.
189 */
190void
192
193 wxMenu* contextMenu = NULL;
194
195 if (part == NULL) {
196 contextMenu = createDefaultMenu();
197
198 } else {
199
200 CommandRegistry* registry = wxGetApp().commandRegistry();
201
202 contextMenu = new wxMenu();
203 contextMenu->Append(ProDeConstants::COMMAND_COPY,
204 _T("&Copy"));
205 contextMenu->Append(ProDeConstants::COMMAND_CUT,
206 _T("Cu&t"));
207 contextMenu->AppendSeparator();
208 contextMenu->Append(ProDeConstants::COMMAND_MODIFY_COMP,
209 _T("&Modify..."));
210 contextMenu->Append(ProDeConstants::COMMAND_DELETE_COMP,
211 _T("&Delete"));
212
213 contextMenu->Enable(
216
217 contextMenu->Enable(
220
221 contextMenu->Enable(
224
225 contextMenu->Enable(
228 }
229
230 view_->canvas()->PopupMenu(contextMenu, wxPoint(x,y));
231}
232
233
234/**
235 * Returns a popup menu to be used as a default context menu on the canvas.
236 */
237wxMenu*
239
240 wxMenu* popupMenu = new wxMenu();
241 CommandRegistry* registry = wxGetApp().commandRegistry();
242 popupMenu->Append(ProDeConstants::COMMAND_UNDO, _T("&Undo"));
243 popupMenu->Append(ProDeConstants::COMMAND_REDO, _T("&Redo"));
244 popupMenu->Append(ProDeConstants::COMMAND_PASTE, _T("&Paste"));
245
246 popupMenu->Enable(ProDeConstants::COMMAND_UNDO,
248 popupMenu->Enable(ProDeConstants::COMMAND_REDO,
250 popupMenu->Enable(ProDeConstants::COMMAND_PASTE,
252
253
254 popupMenu->AppendSeparator();
255
256 wxMenu* addSubMenu = new wxMenu;
257 addSubMenu->Append(ProDeConstants::COMMAND_ADD_FU,
258 _T("&Function Unit..."));
259 addSubMenu->Append(ProDeConstants::COMMAND_ADD_RF,
260 _T("&Register File..."));
261 addSubMenu->Append(ProDeConstants::COMMAND_ADD_BUS,
262 _T("&Transport Bus..."));
263 addSubMenu->Append(ProDeConstants::COMMAND_ADD_SOCKET,
264 _T("&Socket..."));
265 addSubMenu->Append(ProDeConstants::COMMAND_ADD_BRIDGE,
266 _T("&Bridge..."));
267 addSubMenu->Append(ProDeConstants::COMMAND_ADD_IU,
268 _T("&Immediate Unit..."));
269 addSubMenu->Append(ProDeConstants::COMMAND_ADD_GCU,
270 _T("&Global Control Unit..."));
271 addSubMenu->Append(ProDeConstants::COMMAND_ADD_AS,
272 _T("&Address Space..."));
273 popupMenu->Append(ID_ADD_SUBMENU, _T("&Add"), addSubMenu);
274
276 _T("Edit &Connections"));
277 popupMenu->Append(ProDeConstants::COMMAND_SELECT,
278 _T("&Select"));
279 popupMenu->AppendSeparator();
281 _T("&Verify"));
282
283 return popupMenu;
284}
find Finds info of the inner loops in the false
void setStatus(const wxString text, int field=0)
Definition ChildFrame.cc:76
bool isEnabled(const std::string command)
virtual bool Do()=0
bool selectable() const
Figure * figure() const
bool canHandle(Request *request) const
Definition EditPart.cc:316
ComponentCommand * performRequest(Request *request) const
Definition EditPart.cc:297
void setView(wxView *view)
void setParentWindow(wxWindow *view)
Definition GUICommand.cc:64
MachineCanvas * canvas() const
Definition MDFView.cc:229
MachineCanvas * canvas_
Machine canvas where the tool is used.
void select(EditPart *part)
EditPart * findEditPart(int x, int y)
static const std::string CMD_NAME_REDO
Command name for the "Redo" command.
static const std::string CMD_NAME_UNDO
Command name for the "Undo" command.
static const std::string CMD_NAME_COPY
Command name for the "Copy" command.
static const std::string CMD_NAME_PASTE
Command name for the "Paste" command.
static const std::string CMD_NAME_CUT
Command name for the "Cut" command.
static const std::string CMD_NAME_MODIFY_COMP
Command name for the "Modify Component" command.
@ STATUS_REQUEST
Status request.
Definition Request.hh:52
wxMenu * createDefaultMenu()
virtual void activate()
Definition SelectTool.cc:81
void leftClick(EditPart *part)
virtual void onMouseEvent(wxMouseEvent &event, wxDC &dc)
void popContextMenu(EditPart *part, int x, int y)
virtual void deactivate()
Definition SelectTool.cc:90
MDFView * view_
View displayed on the Canvas.
Definition SelectTool.hh:63
virtual ~SelectTool()
Definition SelectTool.cc:72
ChildFrame * frame_
Parent frame of the Canvas.
Definition SelectTool.hh:61
bool active_
Tells if the tool is active or not.
Definition SelectTool.hh:65
SelectionFigure * figure_
Selection figure;.
Definition SelectTool.hh:67
virtual Figure * figure()
SelectTool(ChildFrame *frame, MDFView *view)
Definition SelectTool.cc:58
void setSelection(Figure *selection)