OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ModifyComponentCmd Class Reference

#include <ModifyComponentCmd.hh>

Inheritance diagram for ModifyComponentCmd:
Inheritance graph
Collaboration diagram for ModifyComponentCmd:
Collaboration graph

Public Member Functions

 ModifyComponentCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual ModifyComponentCmdcreate () 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 modifying components in the Machine.

Definition at line 43 of file ModifyComponentCmd.hh.

Constructor & Destructor Documentation

◆ ModifyComponentCmd()

ModifyComponentCmd::ModifyComponentCmd ( )

The Constructor.

Definition at line 49 of file ModifyComponentCmd.cc.

49 :
51}
static const std::string CMD_NAME_MODIFY_COMP
Command name for the "Modify Component" command.

Referenced by create().

Member Function Documentation

◆ create()

ModifyComponentCmd * ModifyComponentCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 117 of file ModifyComponentCmd.cc.

117 {
118 return new ModifyComponentCmd();
119}

References ModifyComponentCmd().

Here is the call graph for this function:

◆ Do()

bool ModifyComponentCmd::Do ( )
virtual

Executes the command.

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

Implements GUICommand.

Definition at line 61 of file ModifyComponentCmd.cc.

61 {
62
63 assert(parentWindow() != NULL);
64 assert(view() != NULL);
65
66 // send modify request to the selected EditPart
67 Request* modifyRequest = new Request(Request::MODIFY_REQUEST);
68 EditPart* selected = dynamic_cast<MDFView*>(view())->selection();
69 if (selected == NULL) {
70 return false;
71 }
72
73 ComponentCommand* command = selected->performRequest(modifyRequest);
74
75 // execute the returned command
76 if (command == NULL) {
77 return false;
78 } else {
79
80 Model* model = dynamic_cast<MDFDocument*>(
81 wxGetApp().docManager()->GetCurrentDocument())->getModel();
82
83 model->pushToStack();
84
85 dynamic_cast<MDFView*>(view())->clearSelection();
86 command->setParentWindow(parentWindow());
87 bool result = command->Do();
88 if (result) {
89 // Model was modified.
90 model->notifyObservers();
91 } else {
92 // Modification was cancelled.
93 model->popFromStack();
94 }
95 return result;
96 }
97}
#define assert(condition)
virtual bool Do()=0
void setParentWindow(wxWindow *window)
ComponentCommand * performRequest(Request *request) const
Definition EditPart.cc:297
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
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
@ MODIFY_REQUEST
Modfify request.
Definition Request.hh:48

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

Referenced by SelectTool::onMouseEvent().

Here is the call graph for this function:

◆ icon()

string ModifyComponentCmd::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 138 of file ModifyComponentCmd.cc.

138 {
140}
static const std::string CMD_ICON_MODIFY_COMP
Icon location for the "Modify Component" command.

References ProDeConstants::CMD_ICON_MODIFY_COMP.

◆ id()

int ModifyComponentCmd::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 106 of file ModifyComponentCmd.cc.

References ProDeConstants::COMMAND_MODIFY_COMP.

◆ isEnabled()

bool ModifyComponentCmd::isEnabled ( )
virtual

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

This command is executable when a block is selected, and the selected block can handle modify requests.

Returns
True, if a modifyable block is selected.

Reimplemented from EditorCommand.

Definition at line 153 of file ModifyComponentCmd.cc.

153 {
154 wxDocManager* manager = wxGetApp().docManager();
155
156 MDFView* mdfView = dynamic_cast<MDFView*>(manager->GetCurrentView());
157 if (mdfView == NULL) {
158 return false;
159 }
160 Request* modifyRequest = new Request(Request::MODIFY_REQUEST);
161 if (mdfView->selection() == NULL ||
162 !mdfView->selection()->canHandle(modifyRequest)) {
163
164 return false;
165 }
166 return true;
167}
bool canHandle(Request *request) const
Definition EditPart.cc:316
EditPart * selection()
Definition MDFView.cc:169

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

Here is the call graph for this function:

◆ shortName()

string ModifyComponentCmd::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 128 of file ModifyComponentCmd.cc.

128 {
130}
static const std::string CMD_SNAME_MODIFY_COMP
Command name for the "Delete Component" command.

References ProDeConstants::CMD_SNAME_MODIFY_COMP.


The documentation for this class was generated from the following files: