OpenASIP 2.2
Loading...
Searching...
No Matches
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.

61 :
63}
static const std::string CMD_NAME_ADD_BRIDGE
Command name for the "Add Bridge" command.

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}
#define assert(condition)
TTAMachine::Machine * machine
the architecture definition of the estimated processor
static std::string toString(const T &source)
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
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static const std::string COMP_NEW_NAME_PREFIX_BRIDGE
Prefix for new bridge names.
static ProDeTextGenerator * instance()
@ MSG_ERROR_CANNOT_BRIDGE
Error: Bridge creation impossible.
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual BridgeNavigator bridgeNavigator() const
Definition Machine.cc:404
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)

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.

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}
static const std::string CMD_SNAME_ADD_BRIDGE
Command name for the "Add Bridge" command.

References ProDeConstants::CMD_SNAME_ADD_BRIDGE.


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