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

#include <AddBusCmd.hh>

Inheritance diagram for AddBusCmd:
Inheritance graph
Collaboration diagram for AddBusCmd:
Collaboration graph

Public Member Functions

 AddBusCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual AddBusCmdcreate () const
 
virtual std::string shortName () 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
 
virtual std::string icon () 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

Command for adding new buses to the Machine.

Displays a bus dialog and creates a new bus according to the dialog output.

Definition at line 43 of file AddBusCmd.hh.

Constructor & Destructor Documentation

◆ AddBusCmd()

AddBusCmd::AddBusCmd ( )

The Constructor.

Definition at line 56 of file AddBusCmd.cc.

Referenced by create().

Member Function Documentation

◆ create()

AddBusCmd * AddBusCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 130 of file AddBusCmd.cc.

130  {
131  return new AddBusCmd();
132 }

References AddBusCmd().

Here is the call graph for this function:

◆ Do()

bool AddBusCmd::Do ( )
virtual

Executes the command.

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

Implements GUICommand.

Definition at line 68 of file AddBusCmd.cc.

68  {
69 
70  assert(parentWindow() != NULL);
71  assert(view() != NULL);
72 
73  Model* model = dynamic_cast<MDFDocument*>(
74  view()->GetDocument())->getModel();
75 
76  model->pushToStack();
77 
78  // Generate name for the new bus.
79  Machine::BusNavigator navigator =
80  model->getMachine()->busNavigator();
81  int i = 1;
84  while (navigator.hasItem(newName)) {
87  i++;
88  }
89  Bus* bus =
91  ModelConstants::DEFAULT_WIDTH, Machine::ZERO);
92  bus->setMachine(*(model->getMachine()));
93 
94  // Create an always-true guard for the bus by default.
95  new UnconditionalGuard(false, *bus);
96 
97  // Add a default segment to the bus.
99 
100  BusDialog dialog(parentWindow(), bus);
101 
102  if (dialog.ShowModal() == wxID_OK) {
103  model->notifyObservers();
104  return true;
105  } else {
106  // bus creation was cancelled
107  model->popFromStack();
108  return false;
109  }
110 }

References assert, TTAMachine::Machine::busNavigator(), ProDeConstants::COMP_DEFAULT_NAME_SEGMENT, ProDeConstants::COMP_NEW_NAME_PREFIX_BUS, ModelConstants::DEFAULT_WIDTH, Model::getMachine(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), Model::notifyObservers(), GUICommand::parentWindow(), Model::popFromStack(), Model::pushToStack(), TTAMachine::Bus::setMachine(), Conversion::toString(), and EditorCommand::view().

Here is the call graph for this function:

◆ id()

int AddBusCmd::id ( ) const
virtual

Returns id of this command.

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

Implements GUICommand.

Definition at line 119 of file AddBusCmd.cc.

119  {
121 }

References ProDeConstants::COMMAND_ADD_BUS.

◆ isEnabled()

bool AddBusCmd::isEnabled ( )
virtual

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

This command is executable when a document is open.

Returns
True, if a document is open.

Reimplemented from EditorCommand.

Definition at line 154 of file AddBusCmd.cc.

154  {
155  wxDocManager* manager = wxGetApp().docManager();
156  if (manager->GetCurrentView() != NULL) {
157  return true;
158  }
159  return false;
160 }

◆ shortName()

string AddBusCmd::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 141 of file AddBusCmd.cc.

141  {
143 }

References ProDeConstants::CMD_SNAME_ADD_BUS.


The documentation for this class was generated from the following files:
TTAMachine::Segment
Definition: Segment.hh:54
ProDeConstants::CMD_SNAME_ADD_BUS
static const std::string CMD_SNAME_ADD_BUS
Command name for the "Add Bus" command.
Definition: ProDeConstants.hh:209
TTAMachine::Bus
Definition: Bus.hh:53
AddBusCmd::AddBusCmd
AddBusCmd()
Definition: AddBusCmd.cc:56
Conversion::toString
static std::string toString(const T &source)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
EditorCommand::EditorCommand
EditorCommand(std::string name, wxWindow *parent=NULL)
Definition: EditorCommand.cc:42
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::UnconditionalGuard
Definition: Guard.hh:180
ModelConstants::DEFAULT_WIDTH
static const int DEFAULT_WIDTH
Default bit width.
Definition: ModelConstants.hh:46
ProDeConstants::COMP_DEFAULT_NAME_SEGMENT
static const std::string COMP_DEFAULT_NAME_SEGMENT
Name for the default segments of busses.
Definition: ProDeConstants.hh:359
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
ProDeConstants::COMMAND_ADD_BUS
@ COMMAND_ADD_BUS
Definition: ProDeConstants.hh:419
TTAMachine::Bus::setMachine
virtual void setMachine(Machine &mach)
Definition: Bus.cc:671
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
Model
Definition: Model.hh:50
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
BusDialog
Definition: BusDialog.hh:54
ProDeConstants::COMP_NEW_NAME_PREFIX_BUS
static const std::string COMP_NEW_NAME_PREFIX_BUS
Prefix for new bus names.
Definition: ProDeConstants.hh:371
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
ProDeConstants::CMD_NAME_ADD_BUS
static const std::string CMD_NAME_ADD_BUS
Command name for the "Add Bus" command.
Definition: ProDeConstants.hh:97
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88