OpenASIP  2.0
ProximMachineCanvasTool.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 ProximMachineCanvasTool.cc
26  *
27  * Implementation of ProximMachineCanvasTool class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/wx.h>
34 #include <wx/tipwin.h>
35 #include "Application.hh"
37 #include "MachineCanvas.hh"
39 #include "ComponentCommand.hh"
40 #include "Request.hh"
41 #include "EditPart.hh"
42 #include "Proxim.hh"
43 #include "MachinePart.hh"
44 #include "WxConversion.hh"
45 #include "ProximToolbox.hh"
46 
47 /**
48  * The Constructor.
49  *
50  * @param canvas MachineCanvas where the tool is used.
51  */
53  MachineCanvasTool(canvas),
54  canvas_(canvas) {
55 
56 }
57 
58 
59 /**
60  * The Destructor.
61  */
63 }
64 
65 
66 /**
67  * Handles mouse events on the canvas.
68  */
69 void
70 ProximMachineCanvasTool::onMouseEvent(wxMouseEvent& event, wxDC& dc) {
71 
72  // Get event position and translate "raw" coordinates to logical ones.
73  wxPoint position = event.GetPosition();
74  int x = position.x;
75  int y = position.y;
76  long logicalX = dc.DeviceToLogicalX(position.x);
77  long logicalY = dc.DeviceToLogicalY(position.y);
78 
79  // Check if there is an EditPart at the cursor position.
80  EditPart* part = canvas_->findEditPart(logicalX, logicalY);
81 
82 
84  if (part != NULL && part->canHandle(&request)) {
85  ComponentCommand* command = part->performRequest(&request);
86  command->Do();
87  delete command;
88  } else {
90  }
91 
92  if (event.LeftDClick()) {
94  if (part != NULL && part->canHandle(&request)) {
95  ComponentCommand* command = part->performRequest(&request);
96  command->setParentWindow(wxGetApp().GetTopWindow());
97  command->Do();
98  delete command;
99  }
100  }
101 
102  if (event.LeftDown()) {
105  Request statusRequest(Request::DETAILS_REQUEST);
106  if (part != NULL && part->canHandle(&statusRequest)) {
107  canvas_->select(part);
108  ComponentCommand* command = part->performRequest(&statusRequest);
109  command->Do();
110  delete command;
111  }
112  }
113 
114  if (event.RightDown()) {
115  popupMenu(x, y);
116  }
117 }
118 
119 
120 /**
121  * Pops a menu at the given position.
122  *
123  * @param x X-coordinate of the popup location.
124  * @param y Y-coordinate of the popup location.
125  */
126 void
128  wxMenu* popupMenu = new wxMenu();
129  popupMenu->Append(
131  popupMenu->Append(
133  popupMenu->AppendSeparator();
134  popupMenu->AppendCheckItem(
136  _T("Display Unit Info"));
137  popupMenu->AppendSeparator();
138  popupMenu->AppendCheckItem(
140  popupMenu->AppendCheckItem(
142  _T("Display utilizations"));
143 
144  popupMenu->AppendSeparator();
145  popupMenu->Append(
146  ProximMachineStateWindow::COMMAND_EXPORT, _T("Export figure..."));
147 
148  canvas_->PopupMenu(popupMenu, wxPoint(x, y));
149 }
150 
151 /**
152  * Called when the tool is activated.
153  */
154 void
156  // do nothing
157 }
158 
159 
160 /**
161  * Called when the tool is deactivated.
162  */
163 void
165  // do nothing
166 }
MachineCanvas::findEditPart
EditPart * findEditPart(int x, int y)
Definition: MachineCanvas.cc:421
ProximMachineStateWindow::setStatusText
void setStatusText(std::string status)
Definition: ProximMachineStateWindow.cc:274
MachineCanvas
Definition: MachineCanvas.hh:64
ProximMachineStateWindow::COMMAND_ZOOM_OUT
@ COMMAND_ZOOM_OUT
Definition: ProximMachineStateWindow.hh:70
ProximMachineCanvasTool::popupMenu
void popupMenu(int x, int y)
Definition: ProximMachineCanvasTool.cc:127
ProximMachineStateWindow::COMMAND_TOGGLE_MOVES
@ COMMAND_TOGGLE_MOVES
Definition: ProximMachineStateWindow.hh:72
MachineCanvas::clearSelection
void clearSelection()
Definition: MachineCanvas.cc:395
ProximMachineStateWindow.hh
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
ProximMachineCanvasTool::activate
virtual void activate()
Definition: ProximMachineCanvasTool.cc:155
Proxim.hh
MachinePart.hh
ComponentCommand::Do
virtual bool Do()=0
ProximMachineCanvasTool::onMouseEvent
virtual void onMouseEvent(wxMouseEvent &event, wxDC &dc)
Definition: ProximMachineCanvasTool.cc:70
ProximToolbox.hh
Request.hh
ComponentCommand::setParentWindow
void setParentWindow(wxWindow *window)
Definition: ComponentCommand.cc:55
Request::DETAILS_REQUEST
@ DETAILS_REQUEST
Detailed info request.
Definition: Request.hh:53
EditPart.hh
MachineCanvas.hh
ProximMachineCanvasTool::~ProximMachineCanvasTool
virtual ~ProximMachineCanvasTool()
Definition: ProximMachineCanvasTool.cc:62
Application.hh
ProximMachineStateWindow::COMMAND_TOGGLE_UNIT_INFO
@ COMMAND_TOGGLE_UNIT_INFO
Definition: ProximMachineStateWindow.hh:71
ProximMachineStateWindow::COMMAND_EXPORT
@ COMMAND_EXPORT
Definition: ProximMachineStateWindow.hh:74
MachineCanvasTool
Definition: MachineCanvasTool.hh:49
ProximMachineCanvasTool.hh
EditPart
Definition: EditPart.hh:60
ProximMachineCanvasTool::canvas_
MachineCanvas * canvas_
MachineCanvas where the tools is used.
Definition: ProximMachineCanvasTool.hh:56
Request
Definition: Request.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
MachineCanvas::select
void select(EditPart *part)
Definition: MachineCanvas.cc:485
ProximMachineStateWindow::COMMAND_ZOOM_IN
@ COMMAND_ZOOM_IN
Definition: ProximMachineStateWindow.hh:69
ProximToolbox::machineStateWindow
static ProximMachineStateWindow * machineStateWindow()
Definition: ProximToolbox.cc:123
ProximMachineCanvasTool::deactivate
virtual void deactivate()
Definition: ProximMachineCanvasTool.cc:164
EditPart::canHandle
bool canHandle(Request *request) const
Definition: EditPart.cc:316
Request::MODIFY_REQUEST
@ MODIFY_REQUEST
Modfify request.
Definition: Request.hh:48
WxConversion.hh
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
ProximMachineStateWindow::clearDetails
void clearDetails()
Definition: ProximMachineStateWindow.cc:488
ProximMachineCanvasTool::ProximMachineCanvasTool
ProximMachineCanvasTool(MachineCanvas *canvas)
Definition: ProximMachineCanvasTool.cc:52
ProximMachineStateWindow::COMMAND_TOGGLE_UTILIZATIONS
@ COMMAND_TOGGLE_UTILIZATIONS
Definition: ProximMachineStateWindow.hh:73
ComponentCommand.hh