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

#include <AddBridgeCmd.hh>

Inheritance diagram for AddBridgeCmd:
Inheritance graph
Collaboration diagram for AddBridgeCmd:
Collaboration graph

Public Member Functions

 AddBridgeCmd ()
 
virtual ~AddBridgeCmd ()
 
virtual bool Do ()
 
virtual int id () const
 
virtual AddBridgeCmdcreate () 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 bridges to the Machine.

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

Definition at line 43 of file AddBridgeCmd.hh.

Constructor & Destructor Documentation

◆ AddBridgeCmd()

AddBridgeCmd::AddBridgeCmd ( )

The Constructor.

Definition at line 61 of file AddBridgeCmd.cc.

Referenced by create().

◆ ~AddBridgeCmd()

AddBridgeCmd::~AddBridgeCmd ( )
virtual

The Destructor.

Definition at line 69 of file AddBridgeCmd.cc.

69  {
70 }

Member Function Documentation

◆ create()

AddBridgeCmd * AddBridgeCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 166 of file AddBridgeCmd.cc.

166  {
167  return new AddBridgeCmd();
168 }

References AddBridgeCmd().

Here is the call graph for this function:

◆ Do()

bool AddBridgeCmd::Do ( )
virtual

Executes the command.

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

Implements GUICommand.

Definition at line 79 of file AddBridgeCmd.cc.

79  {
80 
81  assert(parentWindow() != NULL);
82  assert(view() != NULL);
83 
84  Model* model =
85  dynamic_cast<MDFDocument*>(view()->GetDocument())->getModel();
86  Machine* machine = model->getMachine();
87 
89 
90  Bus* source = NULL;
91  Bus* destination = NULL;
92  MachineTester tester(*machine);
93 
94  // Check that two buses in the machine can be bridged.
95  int i = 0;
96  while (i < navigator.count() && source == NULL) {
97  for (int j = 0; j < navigator.count(); j++) {
98  if (tester.canBridge(*navigator.item(i), *navigator.item(j))) {
99  source = navigator.item(i);
100  destination = navigator.item(j);
101  break;
102  }
103  }
104  i++;
105  }
106 
107  if (source == NULL) {
108  // It's not possible to create a legal bridge to the machine,
109  // display an error message.
111 
112  boost::format message =
114 
116  WxConversion::toWxString(message.str()));
117  info.ShowModal();
118  return false;
119  }
120 
121 
122  // Generate name for the new FU.
123  Machine::BridgeNavigator bridgeNavigator =
124  model->getMachine()->bridgeNavigator();
125  int suffix = 1;
127  Conversion::toString(suffix);
128  while (bridgeNavigator.hasItem(newName)) {
130  Conversion::toString(suffix);
131  suffix++;
132  }
133 
134  // Create and show bridge dialog.
135  model->pushToStack();
136  Bridge* bridge = new Bridge(newName, *source, *destination);
137  BridgeDialog dialog(parentWindow(), bridge, NULL);
138 
139  if (dialog.ShowModal() == wxID_OK) {
140  model->notifyObservers();
141  } else {
142  // bridge creation was cancelled
143  model->popFromStack();
144  }
145  return false;
146 }

References assert, TTAMachine::Machine::bridgeNavigator(), TTAMachine::Machine::busNavigator(), MachineTester::canBridge(), ProDeConstants::COMP_NEW_NAME_PREFIX_BRIDGE, TTAMachine::Machine::Navigator< ComponentType >::count(), Model::getMachine(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), ProDeTextGenerator::instance(), TTAMachine::Machine::Navigator< ComponentType >::item(), machine, ProDeTextGenerator::MSG_ERROR_CANNOT_BRIDGE, Model::notifyObservers(), GUICommand::parentWindow(), Model::popFromStack(), Model::pushToStack(), Texts::TextGenerator::text(), Conversion::toString(), WxConversion::toWxString(), and EditorCommand::view().

Here is the call graph for this function:

◆ id()

int AddBridgeCmd::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 155 of file AddBridgeCmd.cc.

155  {
157 }

References ProDeConstants::COMMAND_ADD_BRIDGE.

◆ isEnabled()

bool AddBridgeCmd::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 191 of file AddBridgeCmd.cc.

191  {
192  wxDocManager* manager = wxGetApp().docManager();
193  if (manager->GetCurrentView() != NULL) {
194  return true;
195  }
196  return false;
197 }

◆ shortName()

string AddBridgeCmd::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 178 of file AddBridgeCmd.cc.

178  {
180 }

References ProDeConstants::CMD_SNAME_ADD_BRIDGE.


The documentation for this class was generated from the following files:
WxConversion::toWxString
static wxString toWxString(const std::string &source)
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAMachine::Bridge
Definition: Bridge.hh:51
TTAMachine::Bus
Definition: Bus.hh:53
AddBridgeCmd::AddBridgeCmd
AddBridgeCmd()
Definition: AddBridgeCmd.cc:61
TTAMachine::Machine::Navigator::count
int count() const
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
Conversion::toString
static std::string toString(const T &source)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
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
ProDeConstants::COMP_NEW_NAME_PREFIX_BRIDGE
static const std::string COMP_NEW_NAME_PREFIX_BRIDGE
Prefix for new bridge names.
Definition: ProDeConstants.hh:375
TTAMachine::Machine::bridgeNavigator
virtual BridgeNavigator bridgeNavigator() const
Definition: Machine.cc:404
BridgeDialog
Definition: BridgeDialog.hh:46
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants::CMD_NAME_ADD_BRIDGE
static const std::string CMD_NAME_ADD_BRIDGE
Command name for the "Add Bridge" command.
Definition: ProDeConstants.hh:101
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
Model
Definition: Model.hh:50
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
InformationDialog
Definition: InformationDialog.hh:42
ProDeTextGenerator::MSG_ERROR_CANNOT_BRIDGE
@ MSG_ERROR_CANNOT_BRIDGE
Error: Bridge creation impossible.
Definition: ProDeTextGenerator.hh:225
MachineTester
Definition: MachineTester.hh:46
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
ProDeConstants::COMMAND_ADD_BRIDGE
@ COMMAND_ADD_BRIDGE
Definition: ProDeConstants.hh:421
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88
TTAMachine::Machine
Definition: Machine.hh:73
ProDeConstants::CMD_SNAME_ADD_BRIDGE
static const std::string CMD_SNAME_ADD_BRIDGE
Command name for the "Add Bridge" command.
Definition: ProDeConstants.hh:213