OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
MDFViewview_
 View displayed on the Canvas.
 
bool active_
 Tells if the tool is active or not.
 
EditPartsource_
 Source EditPart of the connection.
 
EditParttarget_
 Target EditPart of the connection.
 
Figurefigure_
 Connection 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

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 :
59 frame_(frame),
60 view_(view),
61 active_(false),
62 source_(NULL),
63 target_(NULL),
64 figure_(NULL) {
65
66}
EditPart * source_
Source EditPart of the connection.
Figure * figure_
Connection figure.
ChildFrame * frame_
Parent frame of the canvas.
MDFView * view_
View displayed on the Canvas.
EditPart * target_
Target EditPart of the connection.
bool active_
Tells if the tool is active or not.
MachineCanvas * canvas() const
Definition MDFView.cc:229

◆ ~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}
MachineCanvas * canvas_
Machine canvas where the tool is used.

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 {
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 {
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}
virtual Figure * figure()
Figure * figure() const
TTAMachine::MachinePart * model() const
bool hasEditPart(const EditPart *part) const
virtual bool isConnectedTo(const Socket &socket) const
Definition Port.cc:393
bool isConnectedTo(const Bus &bus) const
Definition Socket.cc:331

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

Referenced by figure().

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}
virtual bool Do()=0
bool canHandle(Request *request) const
Definition EditPart.cc:316
ComponentCommand * performRequest(Request *request) const
Definition EditPart.cc:297
EditPart * selection()
Definition MDFView.cc:169
void clearSelection()
Definition MDFView.cc:182
void select(EditPart *part)
Definition Model.hh:50
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
void popFromStack(bool modified=false)
Definition Model.cc:195

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}
void rightClick(wxMouseEvent &event)
void updateStatusline(EditPart *part)
void leftClick(EditPart *part)
EditPart * selection()
int findEditPartsInRange(int x, int y, int range, std::vector< EditPart * > &found)
EditPart * findEditPart(int x, int y)
void refreshToolFigure()

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}
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 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 = "";
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}
void setStatus(const wxString text, int field=0)
Definition ChildFrame.cc:76
@ STATUS_REQUEST
Status request.
Definition Request.hh:52

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: