OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
MDFViewview_
 View displayed on the Canvas.
 
bool active_
 Tells if the tool is active or not.
 
SelectionFigurefigure_
 Selection figure;.
 

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.
 

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.

Constructor & Destructor Documentation

◆ SelectTool()

SelectTool::SelectTool ( ChildFrame frame,
MDFView view 
)

The Constructor.

Definition at line 58 of file SelectTool.cc.

59 :
61 frame_(frame),
62 view_(view),
63 active_(false) {
64
65 figure_ = new SelectionFigure(NULL);
66}
MachineCanvas * canvas() const
Definition MDFView.cc:229
MDFView * view_
View displayed on the Canvas.
Definition SelectTool.hh:63
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

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();
281 _T("&Verify"));
282
283 return popupMenu;
284}
bool isEnabled(const std::string command)
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_PASTE
Command name for the "Paste" command.

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}
bool selectable() const
Figure * figure() const
MachineCanvas * canvas_
Machine canvas where the tool is used.
void select(EditPart *part)
void setSelection(Figure *selection)

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 = "";
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}
void setStatus(const wxString text, int field=0)
Definition ChildFrame.cc:76
virtual bool Do()=0
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
EditPart * findEditPart(int x, int y)
@ STATUS_REQUEST
Status request.
Definition Request.hh:52
void leftClick(EditPart *part)
void popContextMenu(EditPart *part, int x, int y)

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}
static const std::string CMD_NAME_COPY
Command name for the "Copy" 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.
wxMenu * createDefaultMenu()

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: