OpenASIP  2.0
Public Member Functions | List of all members
CutComponentCmd Class Reference

#include <CutComponentCmd.hh>

Inheritance diagram for CutComponentCmd:
Inheritance graph
Collaboration diagram for CutComponentCmd:
Collaboration graph

Public Member Functions

 CutComponentCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual CutComponentCmdcreate () const
 
virtual std::string icon () const
 
virtual bool isEnabled ()
 
- Public Member Functions inherited from EditorCommand
 EditorCommand (std::string name, wxWindow *parent=NULL)
 
virtual ~EditorCommand ()
 
void setView (wxView *view)
 
wxView * view () const
 
- Public Member Functions inherited from GUICommand
 GUICommand (std::string name, wxWindow *parent)
 
virtual ~GUICommand ()
 
virtual bool isChecked () const
 
virtual std::string shortName () const
 
void setParentWindow (wxWindow *view)
 
wxWindow * parentWindow () const
 
std::string name () const
 

Detailed Description

Command for cutting machine components to the clipboard.

Definition at line 43 of file CutComponentCmd.hh.

Constructor & Destructor Documentation

◆ CutComponentCmd()

CutComponentCmd::CutComponentCmd ( )

The Constructor.

Definition at line 49 of file CutComponentCmd.cc.

Referenced by create().

Member Function Documentation

◆ create()

CutComponentCmd * CutComponentCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 121 of file CutComponentCmd.cc.

121  {
122  return new CutComponentCmd();
123 }

References CutComponentCmd().

Here is the call graph for this function:

◆ Do()

bool CutComponentCmd::Do ( )
virtual

Executes the command.

Returns
True, if the command was succesfully executed, false otherwise.

Implements GUICommand.

Definition at line 61 of file CutComponentCmd.cc.

61  {
62 
63  assert(view() != NULL);
64 
65  Request* copyRequest = new Request(Request::COPY_REQUEST);
66  Request* deleteRequest = new Request(Request::DELETE_REQUEST);
67 
68  EditPart* selected = dynamic_cast<MDFView*>(view())->selection();
69  if (selected == NULL) {
70  return false;
71  }
72 
73  // Request copy and delete commands.
74  ComponentCommand* copyCommand = selected->performRequest(copyRequest);
75  ComponentCommand* deleteCommand = selected->performRequest(deleteRequest);
76 
77  // Execute the returned commands.
78  if (copyCommand == NULL || deleteCommand == NULL) {
79  return false;
80  } else {
81 
82  dynamic_cast<MDFView*>(view())->clearSelection();
83 
84  Model* model = dynamic_cast<MDFDocument*>(
85  wxGetApp().docManager()->GetCurrentDocument())->getModel();
86 
87  model->pushToStack();
88 
89  // copy
90  copyCommand->setParentWindow(parentWindow());
91  copyCommand->Do();
92 
93  // delete
94  deleteCommand->setParentWindow(parentWindow());
95  deleteCommand->Do();
96 
97  model->notifyObservers();
98 
99  return false;
100  }
101 }

References assert, Request::COPY_REQUEST, Request::DELETE_REQUEST, ComponentCommand::Do(), Model::notifyObservers(), GUICommand::parentWindow(), EditPart::performRequest(), Model::pushToStack(), ComponentCommand::setParentWindow(), and EditorCommand::view().

Here is the call graph for this function:

◆ icon()

string CutComponentCmd::icon ( ) const
virtual

Returns path to the command's icon file.

Returns
Full path to the command's icon file.

Reimplemented from EditorCommand.

Definition at line 133 of file CutComponentCmd.cc.

133  {
135 }

References ProDeConstants::CMD_ICON_CUT.

◆ id()

int CutComponentCmd::id ( ) const
virtual

Returns command identifier of this command.

Returns
ID for this command to be used in menus and toolbars.

Implements GUICommand.

Definition at line 110 of file CutComponentCmd.cc.

110  {
112 }

References ProDeConstants::COMMAND_CUT.

◆ isEnabled()

bool CutComponentCmd::isEnabled ( )
virtual

Returns true when the command is executable, false when not.

This command is executable when a component is selected, and the selected component can be copied and deleted.

Returns
True, if a component is selected.

Reimplemented from EditorCommand.

Definition at line 148 of file CutComponentCmd.cc.

148  {
149  wxDocManager* manager = wxGetApp().docManager();
150 
151  MDFView* mdfView = dynamic_cast<MDFView*>(manager->GetCurrentView());
152  if (mdfView == NULL) {
153  return false;
154  }
155 
156  EditPart* selected = mdfView->selection();
157  Request* copyRequest = new Request(Request::COPY_REQUEST);
158  Request* deleteRequest = new Request(Request::DELETE_REQUEST);
159  if (selected == NULL ||
160  !(selected->canHandle(copyRequest)) ||
161  !(selected->canHandle(deleteRequest))) {
162 
163  delete copyRequest;
164  return false;
165  }
166  delete copyRequest;
167  delete deleteRequest;
168  return true;
169 }

References EditPart::canHandle(), Request::COPY_REQUEST, Request::DELETE_REQUEST, and MDFView::selection().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
EditorCommand::EditorCommand
EditorCommand(std::string name, wxWindow *parent=NULL)
Definition: EditorCommand.cc:42
ComponentCommand::Do
virtual bool Do()=0
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
ProDeConstants::COMMAND_CUT
@ COMMAND_CUT
Definition: ProDeConstants.hh:435
CutComponentCmd::CutComponentCmd
CutComponentCmd()
Definition: CutComponentCmd.cc:49
ComponentCommand::setParentWindow
void setParentWindow(wxWindow *window)
Definition: ComponentCommand.cc:55
Request::COPY_REQUEST
@ COPY_REQUEST
Copy request.
Definition: Request.hh:51
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
EditPart
Definition: EditPart.hh:60
Request
Definition: Request.hh:43
MDFDocument
Definition: MDFDocument.hh:51
ComponentCommand
Definition: ComponentCommand.hh:46
MDFView::selection
EditPart * selection()
Definition: MDFView.cc:169
Model
Definition: Model.hh:50
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
ProDeConstants::CMD_ICON_CUT
static const std::string CMD_ICON_CUT
Icon location for the "Cut" command.
Definition: ProDeConstants.hh:312
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
MDFView
Definition: MDFView.hh:59