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

#include <ConnectTool.hh>

Inheritance diagram for ConnectTool:
Inheritance graph
Collaboration diagram for ConnectTool:
Collaboration graph

Public Member Functions

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

Private Member Functions

void updateStatusline (EditPart *part)
 
void leftClick (EditPart *part)
 
void rightClick (wxMouseEvent &event)
 

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...
 
EditPartsource_
 Source EditPart of the connection. More...
 
EditParttarget_
 Target EditPart of the connection. More...
 
Figurefigure_
 Connection 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

Mouse tool for creating and removing connections between ports, sockets and bus segments.

Definition at line 47 of file ConnectTool.hh.

Constructor & Destructor Documentation

◆ ConnectTool()

ConnectTool::ConnectTool ( ChildFrame frame,
MDFView view 
)

The Constructor.

Definition at line 57 of file ConnectTool.cc.

57  :
58  MachineCanvasTool(view->canvas()),
59  frame_(frame),
60  view_(view),
61  active_(false),
62  source_(NULL),
63  target_(NULL),
64  figure_(NULL) {
65 
66 }

◆ ~ConnectTool()

ConnectTool::~ConnectTool ( )
virtual

The Destructor.

Definition at line 72 of file ConnectTool.cc.

72  {
73  if (figure_ != NULL) {
74  delete figure_;
75  figure_ = NULL;
76  }
77 }

References figure_.

Member Function Documentation

◆ activate()

void ConnectTool::activate ( )
virtual

Activates the tool.

Implements MachineCanvasTool.

Definition at line 84 of file ConnectTool.cc.

84  {
85  wxCursor connectCursor(wxCURSOR_CROSS);
86  canvas_->SetCursor(connectCursor);
87  active_ = true;
88 }

References active_, and MachineCanvasTool::canvas_.

◆ deactivate()

void ConnectTool::deactivate ( )
virtual

Deactivates the tool.

Implements MachineCanvasTool.

Definition at line 95 of file ConnectTool.cc.

95  {
96  canvas_->SetCursor(wxNullCursor);
97  active_ = false;
98 }

References active_, and MachineCanvasTool::canvas_.

◆ figure()

Figure * ConnectTool::figure ( )
virtual

Returns the tool Figure.

Returns
Tool figure.

Reimplemented from MachineCanvasTool.

Definition at line 269 of file ConnectTool.cc.

269  {
270 
271  // Delete old figure.
272  if (figure_ != NULL) {
273  delete figure_;
274  figure_ = NULL;
275  }
276 
278  return NULL;
279  }
280 
281  Socket* socket = NULL;
282  Port* port = NULL;
283  Segment* segment = NULL;
284 
285  // socket
286  socket = dynamic_cast<Socket*>(source_->model());
287  if (socket == NULL) {
288  socket = dynamic_cast<Socket*>(target_->model());
289  }
290 
291  // port
292  port = dynamic_cast<Port*>(source_->model());
293  if (port == NULL) {
294  port = dynamic_cast<Port*>(target_->model());
295  }
296 
297  // segment
298  segment = dynamic_cast<Segment*>(source_->model());
299  if (segment == NULL) {
300  segment = dynamic_cast<Segment*>(target_->model());
301  }
302 
303  // socket - port connection
304  if (socket != NULL && port != NULL) {
306  if (port->isConnectedTo(*socket)) {
307  figure = new SocketPortConnToolFigure(false);
308  } else {
309  figure = new SocketPortConnToolFigure(true);
310  }
311  if (source_->model() == socket) {
312  figure->setSource(target_->figure());
313  figure->setTarget(source_->figure());
314  } else {
315  figure->setSource(source_->figure());
316  figure->setTarget(target_->figure());
317  }
318  figure_ = figure;
319  return figure_;
320  }
321 
322  if (socket != NULL && segment != NULL) {
323  // return SocketBusConnToolFigure
325  if (socket->isConnectedTo(*segment)) {
326  figure = new SocketBusConnToolFigure(false);
327  } else {
328  figure = new SocketBusConnToolFigure(true);
329  }
330  if (source_->model() == segment) {
331  figure->setSource(target_->figure());
332  figure->setTarget(source_->figure());
333  } else {
334  figure->setSource(source_->figure());
335  figure->setTarget(target_->figure());
336  }
337  figure_ = figure;
338  return figure;
339  }
340  target_ = NULL;
341  return NULL;
342 }

References MachineCanvasTool::canvas_, EditPart::figure(), figure_, MachineCanvas::hasEditPart(), TTAMachine::Port::isConnectedTo(), TTAMachine::Socket::isConnectedTo(), EditPart::model(), source_, and target_.

Here is the call graph for this function:

◆ leftClick()

void ConnectTool::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 201 of file ConnectTool.cc.

201  {
202  EditPart* selection = view_->selection();
203  ConnectRequest* request = new ConnectRequest(source_);
204  if (part != NULL && part->canHandle(request)) {
205  if (selection == NULL && source_ == NULL) {
206  canvas_->select(part);
207  } else if(source_ != NULL) {
208  ComponentCommand* cmd = part->performRequest(request);
209 
210  if (cmd != NULL) {
211  Model* model = dynamic_cast<MDFDocument*>(
212  wxGetApp().docManager()->GetCurrentDocument())->getModel();
213  model->pushToStack();
214  if (cmd->Do()) {
215  // conenction was modified
216  model->notifyObservers();
217  target_ = NULL;
218  source_ = NULL;
219  } else {
220  // Modification failed.
221  model->popFromStack();
222  }
223  }
224  delete cmd;
225  }
226  } else {
228  }
229  delete request;
230 }

References EditPart::canHandle(), MachineCanvasTool::canvas_, MDFView::clearSelection(), ComponentCommand::Do(), Model::notifyObservers(), EditPart::performRequest(), Model::popFromStack(), Model::pushToStack(), MachineCanvas::select(), MDFView::selection(), source_, target_, and view_.

Referenced by onMouseEvent().

Here is the call graph for this function:

◆ onMouseEvent()

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

Handles mouse events on the Canvas.

Parameters
eventMouse event to handle.
dcDevice context.

Implements MachineCanvasTool.

Definition at line 108 of file ConnectTool.cc.

108  {
109 
110  if (!active_) {
111  return;
112  }
113 
114  // Get event position and translate "raw" coordinates to logical ones.
115  wxPoint position = event.GetPosition();
116  long logicalX = dc.DeviceToLogicalX(position.x);
117  long logicalY = dc.DeviceToLogicalY(position.y);
118 
119  // Check if there is an EditPart directly at the cursor position.
120  EditPart* toSelect = canvas_->findEditPart(logicalX, logicalY);
121  // Check if there is an EditParts near at the cursor position.
122  std::vector<EditPart*> nearbyParts;
123  canvas_->findEditPartsInRange(logicalX, logicalY, 10, nearbyParts);
124 
125  EditPart* selection = canvas_->selection();
126 
127  vector<EditPart*> sources;
128 
129  source_ = NULL;
130  if(toSelect != NULL) {
131  target_ = toSelect;
133 
134  // This enables single click feature to edit connection between
135  // socket and bus.
136  if((selection == NULL || selection == target_)
137  && !nearbyParts.empty()) {
138  sources = nearbyParts;
139  } else if(selection != target_) {
140  sources.push_back(selection);
141  }
142 
143  if(!sources.empty()) {
144  for(unsigned int i = 0; i < sources.size(); i++) {
145  ConnectRequest* request = new ConnectRequest(sources.at(i));
146  if(target_->canHandle(request)) {
147  source_ = sources.at(i);
148  delete request;
149  break;
150  }
151  delete request;
152  }
153  if(source_ == NULL) {
154  target_ = NULL;
155  }
156  } else {
157  target_ = NULL;
158  source_ = NULL;
159  }
160  }
161 
163 
164  if (event.LeftUp()) {
165  leftClick(toSelect);
166  }
167 
168  if (event.RightUp()) {
169  rightClick(event);
170  }
171 }

References active_, EditPart::canHandle(), MachineCanvasTool::canvas_, MachineCanvas::findEditPart(), MachineCanvas::findEditPartsInRange(), leftClick(), MachineCanvas::refreshToolFigure(), rightClick(), MachineCanvas::selection(), source_, target_, and updateStatusline().

Here is the call graph for this function:

◆ rightClick()

void ConnectTool::rightClick ( wxMouseEvent &  event)
private

Pops a context menu when the right mouse button is clicked on the canvas.

Parameters
eventMouse event containing the cursor location where to pop the menu.

Definition at line 240 of file ConnectTool.cc.

240  {
241  wxMenu* contextMenu = new wxMenu();
242 
243  // Create a context menu.
244  CommandRegistry* registry = wxGetApp().commandRegistry();
245  contextMenu->Append(ProDeConstants::COMMAND_UNDO, _T("&Undo"));
246  contextMenu->Append(ProDeConstants::COMMAND_REDO, _T("&Redo"));
247  contextMenu->Append(ProDeConstants::COMMAND_PASTE, _T("&Paste"));
248  contextMenu->Enable(ProDeConstants::COMMAND_UNDO,
250  contextMenu->Enable(ProDeConstants::COMMAND_REDO,
252  contextMenu->Enable(ProDeConstants::COMMAND_PASTE,
254  contextMenu->AppendSeparator();
255  contextMenu->Append(ProDeConstants::COMMAND_SELECT, _T("&Select Tool"));
256 
257  // Pop the menu at cursor position.
258  wxPoint position = event.GetPosition();
259  view_->canvas()->PopupMenu(contextMenu, wxPoint(position.x, position.y));
260 }

References MDFView::canvas(), ProDeConstants::CMD_NAME_PASTE, ProDeConstants::CMD_NAME_REDO, ProDeConstants::CMD_NAME_UNDO, ProDeConstants::COMMAND_PASTE, ProDeConstants::COMMAND_REDO, ProDeConstants::COMMAND_SELECT, ProDeConstants::COMMAND_UNDO, CommandRegistry::isEnabled(), and view_.

Referenced by onMouseEvent().

Here is the call graph for this function:

◆ updateStatusline()

void ConnectTool::updateStatusline ( EditPart part)
private

Sends a status request to the given EditPart and executes the returned command.

Definition at line 179 of file ConnectTool.cc.

179  {
180  string status = "";
181  Request* request = new Request(Request::STATUS_REQUEST);
182  if (part != NULL && part->canHandle(request)) {
183  ComponentCommand* command = part->performRequest(request);
184  if (command != NULL )
185  {
186  command->Do();
187  }
188  } else {
189  frame_->setStatus(_T(""));
190  }
191 }

References EditPart::canHandle(), ComponentCommand::Do(), frame_, EditPart::performRequest(), ChildFrame::setStatus(), and Request::STATUS_REQUEST.

Referenced by onMouseEvent().

Here is the call graph for this function:

Member Data Documentation

◆ active_

bool ConnectTool::active_
private

Tells if the tool is active or not.

Definition at line 65 of file ConnectTool.hh.

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

◆ figure_

Figure* ConnectTool::figure_
private

Connection figure.

Definition at line 71 of file ConnectTool.hh.

Referenced by figure(), and ~ConnectTool().

◆ frame_

ChildFrame* ConnectTool::frame_
private

Parent frame of the canvas.

Definition at line 61 of file ConnectTool.hh.

Referenced by updateStatusline().

◆ source_

EditPart* ConnectTool::source_
private

Source EditPart of the connection.

Definition at line 67 of file ConnectTool.hh.

Referenced by figure(), leftClick(), and onMouseEvent().

◆ target_

EditPart* ConnectTool::target_
private

Target EditPart of the connection.

Definition at line 69 of file ConnectTool.hh.

Referenced by figure(), leftClick(), and onMouseEvent().

◆ view_

MDFView* ConnectTool::view_
private

View displayed on the Canvas.

Definition at line 63 of file ConnectTool.hh.

Referenced by leftClick(), and rightClick().


The documentation for this class was generated from the following files:
MachineCanvasTool::MachineCanvasTool
MachineCanvasTool(MachineCanvas *canvas)
Definition: MachineCanvasTool.cc:41
ConnectTool::view_
MDFView * view_
View displayed on the Canvas.
Definition: ConnectTool.hh:63
MachineCanvas::findEditPart
EditPart * findEditPart(int x, int y)
Definition: MachineCanvas.cc:421
ChildFrame::setStatus
void setStatus(const wxString text, int field=0)
Definition: ChildFrame.cc:76
ProDeConstants::COMMAND_UNDO
@ COMMAND_UNDO
Definition: ProDeConstants.hh:433
CommandRegistry::isEnabled
bool isEnabled(const std::string command)
Definition: CommandRegistry.cc:210
MDFView::canvas
MachineCanvas * canvas() const
Definition: MDFView.cc:229
TTAMachine::Segment
Definition: Segment.hh:54
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
ConnectTool::leftClick
void leftClick(EditPart *part)
Definition: ConnectTool.cc:201
ProDeConstants::CMD_NAME_PASTE
static const std::string CMD_NAME_PASTE
Command name for the "Paste" command.
Definition: ProDeConstants.hh:130
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ComponentCommand::Do
virtual bool Do()=0
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
ConnectTool::frame_
ChildFrame * frame_
Parent frame of the canvas.
Definition: ConnectTool.hh:61
MachineCanvas::refreshToolFigure
void refreshToolFigure()
Definition: MachineCanvas.cc:164
MachineCanvas::selection
EditPart * selection()
Definition: MachineCanvas.cc:409
ConnectRequest
Definition: ConnectRequest.hh:43
SocketPortConnToolFigure
Definition: SocketPortConnToolFigure.hh:45
ProDeConstants::COMMAND_SELECT
@ COMMAND_SELECT
Definition: ProDeConstants.hh:460
TTAMachine::Port
Definition: Port.hh:54
MDFView::clearSelection
void clearSelection()
Definition: MDFView.cc:182
CommandRegistry
Definition: CommandRegistry.hh:47
TTAMachine::Socket
Definition: Socket.hh:53
EditPart
Definition: EditPart.hh:60
ConnectTool::source_
EditPart * source_
Source EditPart of the connection.
Definition: ConnectTool.hh:67
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
ProDeConstants::COMMAND_REDO
@ COMMAND_REDO
Definition: ProDeConstants.hh:434
ConnectTool::target_
EditPart * target_
Target EditPart of the connection.
Definition: ConnectTool.hh:69
TTAMachine::Socket::isConnectedTo
bool isConnectedTo(const Bus &bus) const
Definition: Socket.cc:331
EditPart::model
TTAMachine::MachinePart * model() const
Request
Definition: Request.hh:43
MDFDocument
Definition: MDFDocument.hh:51
ComponentCommand
Definition: ComponentCommand.hh:46
MDFView::selection
EditPart * selection()
Definition: MDFView.cc:169
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
Model
Definition: Model.hh:50
MachineCanvas::findEditPartsInRange
int findEditPartsInRange(int x, int y, int range, std::vector< EditPart * > &found)
Definition: MachineCanvas.cc:454
ConnectTool::figure_
Figure * figure_
Connection figure.
Definition: ConnectTool.hh:71
EditPart::canHandle
bool canHandle(Request *request) const
Definition: EditPart.cc:316
SocketBusConnToolFigure
Definition: SocketBusConnToolFigure.hh:45
ConnectTool::active_
bool active_
Tells if the tool is active or not.
Definition: ConnectTool.hh:65
Request::STATUS_REQUEST
@ STATUS_REQUEST
Status request.
Definition: Request.hh:52
TTAMachine::Port::isConnectedTo
virtual bool isConnectedTo(const Socket &socket) const
Definition: Port.cc:393
ConnectTool::rightClick
void rightClick(wxMouseEvent &event)
Definition: ConnectTool.cc:240
MachineCanvasTool::canvas_
MachineCanvas * canvas_
Machine canvas where the tool is used.
Definition: MachineCanvasTool.hh:77
MachineCanvas::hasEditPart
bool hasEditPart(const EditPart *part) const
Definition: MachineCanvas.cc:470
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
ConnectTool::figure
virtual Figure * figure()
Definition: ConnectTool.cc:269
ConnectTool::updateStatusline
void updateStatusline(EditPart *part)
Definition: ConnectTool.cc:179