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

#include <DeleteComponentCmd.hh>

Inheritance diagram for DeleteComponentCmd:
Inheritance graph
Collaboration diagram for DeleteComponentCmd:
Collaboration graph

Public Member Functions

 DeleteComponentCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual DeleteComponentCmdcreate () const
 
virtual std::string shortName () 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
 
void setParentWindow (wxWindow *view)
 
wxWindow * parentWindow () const
 
std::string name () const
 

Detailed Description

wxCommand for deleting components from the Machine.

Definition at line 43 of file DeleteComponentCmd.hh.

Constructor & Destructor Documentation

◆ DeleteComponentCmd()

DeleteComponentCmd::DeleteComponentCmd ( )

The Constructor.

Definition at line 48 of file DeleteComponentCmd.cc.

Referenced by create().

Member Function Documentation

◆ create()

DeleteComponentCmd * DeleteComponentCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 116 of file DeleteComponentCmd.cc.

116  {
117  return new DeleteComponentCmd();
118 }

References DeleteComponentCmd().

Here is the call graph for this function:

◆ Do()

bool DeleteComponentCmd::Do ( )
virtual

Executes the command.

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

Implements GUICommand.

Definition at line 61 of file DeleteComponentCmd.cc.

61  {
62 
63  assert(parentWindow() != NULL);
64  assert(view() != NULL);
65 
66  // send delete request to the selected EditPart
67  Request* deleteRequest = new Request(Request::DELETE_REQUEST);
68  EditPart* selected = dynamic_cast<MDFView*>(view())->selection();
69  if (selected == NULL) {
70  return false;
71  }
72 
73  ComponentCommand* command = selected->performRequest(deleteRequest);
74 
75  // execute the returned command
76  if (command == NULL) {
77  return false;
78  } else {
79  Model* model = dynamic_cast<MDFDocument*>(
80  wxGetApp().docManager()->GetCurrentDocument())->getModel();
81 
82  model->pushToStack();
83 
84  dynamic_cast<MDFView*>(view())->clearSelection();
85  bool result = command->Do();
86 
87  if (result) {
88  // Model was modified.
89  model->notifyObservers();
90  } else {
91  // Command was cancelled.
92  model->popFromStack();
93  }
94  return result;
95  }
96 }

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

Here is the call graph for this function:

◆ icon()

string DeleteComponentCmd::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 137 of file DeleteComponentCmd.cc.

137  {
139 }

References ProDeConstants::CMD_ICON_DELETE_COMP.

◆ id()

int DeleteComponentCmd::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 105 of file DeleteComponentCmd.cc.

105  {
107 }

References ProDeConstants::COMMAND_DELETE_COMP.

◆ isEnabled()

bool DeleteComponentCmd::isEnabled ( )
virtual

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

This command is executable when a block is selected, and the block can handle a delete request.

Returns
True, if a deletable block is selected.

Reimplemented from EditorCommand.

Definition at line 152 of file DeleteComponentCmd.cc.

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

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

Here is the call graph for this function:

◆ shortName()

string DeleteComponentCmd::shortName ( ) const
virtual

Returns short version of the command name.

Returns
Short name of the command to be used in the toolbar.

Reimplemented from GUICommand.

Definition at line 127 of file DeleteComponentCmd.cc.

127  {
129 }

References ProDeConstants::CMD_SNAME_DELETE_COMP.


The documentation for this class was generated from the following files:
ProDeConstants::CMD_ICON_DELETE_COMP
static const std::string CMD_ICON_DELETE_COMP
Icon location for the "Delete Component" command.
Definition: ProDeConstants.hh:318
EditPart::performRequest
ComponentCommand * performRequest(Request *request) const
Definition: EditPart.cc:297
ProDeConstants::COMMAND_DELETE_COMP
@ COMMAND_DELETE_COMP
Definition: ProDeConstants.hh:430
Request::DELETE_REQUEST
@ DELETE_REQUEST
Delete request.
Definition: Request.hh:49
ProDeConstants::CMD_NAME_DELETE_COMP
static const std::string CMD_NAME_DELETE_COMP
Command name for the "Delete Component" command.
Definition: ProDeConstants.hh:117
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
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
EditPart
Definition: EditPart.hh:60
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
Request
Definition: Request.hh:43
DeleteComponentCmd::DeleteComponentCmd
DeleteComponentCmd()
Definition: DeleteComponentCmd.cc:48
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_SNAME_DELETE_COMP
static const std::string CMD_SNAME_DELETE_COMP
Command name for the "Modify Component" command.
Definition: ProDeConstants.hh:267
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
MDFView
Definition: MDFView.hh:59