OpenASIP 2.2
Loading...
Searching...
No Matches
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 */
64
65
66/**
67 * Handles mouse events on the canvas.
68 */
69void
70ProximMachineCanvasTool::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 */
126void
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 */
154void
156 // do nothing
157}
158
159
160/**
161 * Called when the tool is deactivated.
162 */
163void
165 // do nothing
166}
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
void select(EditPart *part)
EditPart * findEditPart(int x, int y)
virtual void onMouseEvent(wxMouseEvent &event, wxDC &dc)
ProximMachineCanvasTool(MachineCanvas *canvas)
MachineCanvas * canvas_
MachineCanvas where the tools is used.
void setStatusText(std::string status)
static ProximMachineStateWindow * machineStateWindow()
@ DETAILS_REQUEST
Detailed info request.
Definition Request.hh:53
@ STATUS_REQUEST
Status request.
Definition Request.hh:52
@ MODIFY_REQUEST
Modfify request.
Definition Request.hh:48