OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SelectTool Class Reference

#include <SelectTool.hh>

Inheritance diagram for SelectTool:
Inheritance graph
Collaboration diagram for SelectTool:
Collaboration graph

Public Member Functions

 SelectTool (ChildFrame *frame, MDFView *view)
 
virtual ~SelectTool ()
 
virtual void activate ()
 
virtual void deactivate ()
 
virtual void onMouseEvent (wxMouseEvent &event, wxDC &dc)
 
virtual Figurefigure ()
 
- Public Member Functions inherited from MachineCanvasTool
virtual ~MachineCanvasTool ()
 

Private Types

enum  {
  ID_CONTEXT_MODIFY = 11000, ID_CONTEXT_DELETE, ID_CONTEXT_COPY, ID_CONTEXT_CUT,
  ID_ADD_SUBMENU
}
 IDs for the context menu items. More...
 

Private Member Functions

void leftClick (EditPart *part)
 
void popContextMenu (EditPart *part, int x, int y)
 
wxMenu * createDefaultMenu ()
 

Private Attributes

ChildFrameframe_
 Parent frame of the Canvas. More...
 
MDFViewview_
 View displayed on the Canvas. More...
 
bool active_
 Tells if the tool is active or not. More...
 
SelectionFigurefigure_
 Selection figure;. More...
 

Additional Inherited Members

- Protected Member Functions inherited from MachineCanvasTool
 MachineCanvasTool (MachineCanvas *canvas)
 
- Protected Attributes inherited from MachineCanvasTool
MachineCanvascanvas_
 Machine canvas where the tool is used. More...
 

Detailed Description

Tool for selecting components in the canvas.

Definition at line 47 of file SelectTool.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

IDs for the context menu items.

Enumerator
ID_CONTEXT_MODIFY 
ID_CONTEXT_DELETE 
ID_CONTEXT_COPY 
ID_CONTEXT_CUT 
ID_ADD_SUBMENU 

Definition at line 70 of file SelectTool.hh.

70  {
71  ID_CONTEXT_MODIFY = 11000,
76  };

Constructor & Destructor Documentation

◆ SelectTool()

SelectTool::SelectTool ( ChildFrame frame,
MDFView view 
)

The Constructor.

Definition at line 58 of file SelectTool.cc.

59  :
60  MachineCanvasTool(view->canvas()),
61  frame_(frame),
62  view_(view),
63  active_(false) {
64 
65  figure_ = new SelectionFigure(NULL);
66 }

References figure_.

◆ ~SelectTool()

SelectTool::~SelectTool ( )
virtual

The Destructor.

Definition at line 72 of file SelectTool.cc.

72  {
73  delete figure_;
74 }

References figure_.

Member Function Documentation

◆ activate()

void SelectTool::activate ( )
virtual

Activates the tool.

Implements MachineCanvasTool.

Definition at line 81 of file SelectTool.cc.

81  {
82  active_ = true;
83 }

References active_.

◆ createDefaultMenu()

wxMenu * SelectTool::createDefaultMenu ( )
private

Returns a popup menu to be used as a default context menu on the canvas.

Definition at line 238 of file SelectTool.cc.

238  {
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();
280  popupMenu->Append(ProDeConstants::COMMAND_VERIFY_MACHINE,
281  _T("&Verify"));
282 
283  return popupMenu;
284 }

References ProDeConstants::CMD_NAME_PASTE, ProDeConstants::CMD_NAME_REDO, ProDeConstants::CMD_NAME_UNDO, ProDeConstants::COMMAND_ADD_AS, ProDeConstants::COMMAND_ADD_BRIDGE, ProDeConstants::COMMAND_ADD_BUS, ProDeConstants::COMMAND_ADD_FU, ProDeConstants::COMMAND_ADD_GCU, ProDeConstants::COMMAND_ADD_IU, ProDeConstants::COMMAND_ADD_RF, ProDeConstants::COMMAND_ADD_SOCKET, ProDeConstants::COMMAND_EDIT_CONNECTIONS, ProDeConstants::COMMAND_PASTE, ProDeConstants::COMMAND_REDO, ProDeConstants::COMMAND_SELECT, ProDeConstants::COMMAND_UNDO, ProDeConstants::COMMAND_VERIFY_MACHINE, ID_ADD_SUBMENU, and CommandRegistry::isEnabled().

Referenced by popContextMenu().

Here is the call graph for this function:

◆ deactivate()

void SelectTool::deactivate ( )
virtual

Deactivates the tool.

Implements MachineCanvasTool.

Definition at line 90 of file SelectTool.cc.

90  {
91  active_ = false;
92 }

References active_.

◆ figure()

Figure * SelectTool::figure ( )
virtual

Returns figure of the selection.

Returns
Figure of the selection.

Reimplemented from MachineCanvasTool.

Definition at line 100 of file SelectTool.cc.

100  {
101  return NULL;
102 }

◆ leftClick()

void SelectTool::leftClick ( EditPart part)
private

Selects Component at cursor position, if there is a selectable EditPart at the coordinates.

Parameters
partComponent to select.

Definition at line 173 of file SelectTool.cc.

173  {
174  if (part != NULL && part->selectable()) {
175  canvas_->select(part);
176  figure_->setSelection(part->figure());
177  } else {
179  }
180 }

References MachineCanvasTool::canvas_, MachineCanvas::clearSelection(), EditPart::figure(), figure_, MachineCanvas::select(), EditPart::selectable(), and SelectionFigure::setSelection().

Referenced by onMouseEvent().

Here is the call graph for this function:

◆ onMouseEvent()

void SelectTool::onMouseEvent ( wxMouseEvent &  event,
wxDC &  dc 
)
virtual

Handles mouse events on the Canvas.

Parameters
eventMouse event to handle.
dcDevice context.

Implements MachineCanvasTool.

Definition at line 111 of file SelectTool.cc.

111  {
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 = "";
130  Request* request = new Request(Request::STATUS_REQUEST);
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 }

References active_, EditPart::canHandle(), MachineCanvasTool::canvas_, ModifyComponentCmd::Do(), ComponentCommand::Do(), MachineCanvas::findEditPart(), frame_, leftClick(), EditPart::performRequest(), popContextMenu(), GUICommand::setParentWindow(), ChildFrame::setStatus(), EditorCommand::setView(), Request::STATUS_REQUEST, and view_.

Here is the call graph for this function:

◆ popContextMenu()

void SelectTool::popContextMenu ( EditPart part,
int  x,
int  y 
)
private

Pops a context menu for the EditPart at the coordinates;

Parameters
partContext component.
xX-coordinate for the menu.
yY-coordinate for the menu.

Definition at line 191 of file SelectTool.cc.

191  {
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 }

References MDFView::canvas(), ProDeConstants::CMD_NAME_COPY, ProDeConstants::CMD_NAME_CUT, ProDeConstants::CMD_NAME_MODIFY_COMP, ProDeConstants::COMMAND_COPY, ProDeConstants::COMMAND_CUT, ProDeConstants::COMMAND_DELETE_COMP, ProDeConstants::COMMAND_MODIFY_COMP, createDefaultMenu(), CommandRegistry::isEnabled(), and view_.

Referenced by onMouseEvent().

Here is the call graph for this function:

Member Data Documentation

◆ active_

bool SelectTool::active_
private

Tells if the tool is active or not.

Definition at line 65 of file SelectTool.hh.

Referenced by activate(), deactivate(), and onMouseEvent().

◆ figure_

SelectionFigure* SelectTool::figure_
private

Selection figure;.

Definition at line 67 of file SelectTool.hh.

Referenced by leftClick(), SelectTool(), and ~SelectTool().

◆ frame_

ChildFrame* SelectTool::frame_
private

Parent frame of the Canvas.

Definition at line 61 of file SelectTool.hh.

Referenced by onMouseEvent().

◆ view_

MDFView* SelectTool::view_
private

View displayed on the Canvas.

Definition at line 63 of file SelectTool.hh.

Referenced by onMouseEvent(), and popContextMenu().


The documentation for this class was generated from the following files:
MachineCanvasTool::MachineCanvasTool
MachineCanvasTool(MachineCanvas *canvas)
Definition: MachineCanvasTool.cc:41
MachineCanvas::findEditPart
EditPart * findEditPart(int x, int y)
Definition: MachineCanvas.cc:421
GUICommand::setParentWindow
void setParentWindow(wxWindow *view)
Definition: GUICommand.cc:64
ChildFrame::setStatus
void setStatus(const wxString text, int field=0)
Definition: ChildFrame.cc:76
ProDeConstants::COMMAND_UNDO
@ COMMAND_UNDO
Definition: ProDeConstants.hh:433
ProDeConstants::COMMAND_ADD_IU
@ COMMAND_ADD_IU
Definition: ProDeConstants.hh:422
CommandRegistry::isEnabled
bool isEnabled(const std::string command)
Definition: CommandRegistry.cc:210
ProDeConstants::COMMAND_MODIFY_COMP
@ COMMAND_MODIFY_COMP
Definition: ProDeConstants.hh:431
ProDeConstants::COMMAND_EDIT_CONNECTIONS
@ COMMAND_EDIT_CONNECTIONS
Definition: ProDeConstants.hh:439
MachineCanvas::clearSelection
void clearSelection()
Definition: MachineCanvas.cc:395
MDFView::canvas
MachineCanvas * canvas() const
Definition: MDFView.cc:229
SelectTool::ID_CONTEXT_CUT
@ ID_CONTEXT_CUT
Definition: SelectTool.hh:74
ProDeConstants::COMMAND_ADD_GCU
@ COMMAND_ADD_GCU
Definition: ProDeConstants.hh:423
ModifyComponentCmd::Do
virtual bool Do()
Definition: ModifyComponentCmd.cc:61
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
ProDeConstants::COMMAND_ADD_FU
@ COMMAND_ADD_FU
Definition: ProDeConstants.hh:417
ProDeConstants::COMMAND_DELETE_COMP
@ COMMAND_DELETE_COMP
Definition: ProDeConstants.hh:430
ModifyComponentCmd
Definition: ModifyComponentCmd.hh:43
ProDeConstants::CMD_NAME_MODIFY_COMP
static const std::string CMD_NAME_MODIFY_COMP
Command name for the "Modify Component" command.
Definition: ProDeConstants.hh:119
ProDeConstants::COMMAND_ADD_AS
@ COMMAND_ADD_AS
Definition: ProDeConstants.hh:424
EditorCommand::setView
void setView(wxView *view)
Definition: EditorCommand.cc:65
ProDeConstants::CMD_NAME_PASTE
static const std::string CMD_NAME_PASTE
Command name for the "Paste" command.
Definition: ProDeConstants.hh:130
SelectTool::ID_CONTEXT_MODIFY
@ ID_CONTEXT_MODIFY
Definition: SelectTool.hh:71
ProDeConstants::COMMAND_COPY
@ COMMAND_COPY
Definition: ProDeConstants.hh:436
ComponentCommand::Do
virtual bool Do()=0
ProDeConstants::COMMAND_CUT
@ COMMAND_CUT
Definition: ProDeConstants.hh:435
SelectTool::ID_ADD_SUBMENU
@ ID_ADD_SUBMENU
Definition: SelectTool.hh:75
EditPart::selectable
bool selectable() const
SelectTool::figure_
SelectionFigure * figure_
Selection figure;.
Definition: SelectTool.hh:67
ProDeConstants::COMMAND_SELECT
@ COMMAND_SELECT
Definition: ProDeConstants.hh:460
CommandRegistry
Definition: CommandRegistry.hh:47
ProDeConstants::COMMAND_ADD_BUS
@ COMMAND_ADD_BUS
Definition: ProDeConstants.hh:419
SelectTool::leftClick
void leftClick(EditPart *part)
Definition: SelectTool.cc:173
EditPart
Definition: EditPart.hh:60
ProDeConstants::COMMAND_ADD_RF
@ COMMAND_ADD_RF
Definition: ProDeConstants.hh:418
SelectionFigure
Definition: SelectionFigure.hh:45
ProDeConstants::COMMAND_REDO
@ COMMAND_REDO
Definition: ProDeConstants.hh:434
SelectTool::ID_CONTEXT_COPY
@ ID_CONTEXT_COPY
Definition: SelectTool.hh:73
ProDeConstants::CMD_NAME_COPY
static const std::string CMD_NAME_COPY
Command name for the "Copy" command.
Definition: ProDeConstants.hh:128
SelectTool::frame_
ChildFrame * frame_
Parent frame of the Canvas.
Definition: SelectTool.hh:61
Request
Definition: Request.hh:43
ComponentCommand
Definition: ComponentCommand.hh:46
MachineCanvas::select
void select(EditPart *part)
Definition: MachineCanvas.cc:485
ProDeConstants::CMD_NAME_UNDO
static const std::string CMD_NAME_UNDO
Command name for the "Undo" command.
Definition: ProDeConstants.hh:122
EditPart::figure
Figure * figure() const
SelectTool::createDefaultMenu
wxMenu * createDefaultMenu()
Definition: SelectTool.cc:238
SelectTool::view_
MDFView * view_
View displayed on the Canvas.
Definition: SelectTool.hh:63
SelectTool::ID_CONTEXT_DELETE
@ ID_CONTEXT_DELETE
Definition: SelectTool.hh:72
SelectTool::popContextMenu
void popContextMenu(EditPart *part, int x, int y)
Definition: SelectTool.cc:191
ProDeConstants::COMMAND_ADD_SOCKET
@ COMMAND_ADD_SOCKET
Definition: ProDeConstants.hh:420
EditPart::canHandle
bool canHandle(Request *request) const
Definition: EditPart.cc:316
ProDeConstants::CMD_NAME_CUT
static const std::string CMD_NAME_CUT
Command name for the "Cut" command.
Definition: ProDeConstants.hh:126
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
MachineCanvasTool::canvas_
MachineCanvas * canvas_
Machine canvas where the tool is used.
Definition: MachineCanvasTool.hh:77
SelectTool::active_
bool active_
Tells if the tool is active or not.
Definition: SelectTool.hh:65
ProDeConstants::COMMAND_PASTE
@ COMMAND_PASTE
Definition: ProDeConstants.hh:437
ProDeConstants::CMD_NAME_REDO
static const std::string CMD_NAME_REDO
Command name for the "Redo" command.
Definition: ProDeConstants.hh:124
SelectionFigure::setSelection
void setSelection(Figure *selection)
Definition: SelectionFigure.cc:100
ProDeConstants::COMMAND_ADD_BRIDGE
@ COMMAND_ADD_BRIDGE
Definition: ProDeConstants.hh:421
ProDeConstants::COMMAND_VERIFY_MACHINE
@ COMMAND_VERIFY_MACHINE
Definition: ProDeConstants.hh:457