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

#include <PasteComponentCmd.hh>

Inheritance diagram for PasteComponentCmd:
Inheritance graph
Collaboration diagram for PasteComponentCmd:
Collaboration graph

Public Member Functions

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

Private Member Functions

template<class ComponentNavigator >
void paste (TTAMachine::Machine &machine, TTAMachine::Component *component, ComponentNavigator &navigator)
 
bool setMachine (TTAMachine::Component *component, TTAMachine::Machine *machine)
 

Detailed Description

Command for pasting components from the clipboard to the machine.

Definition at line 49 of file PasteComponentCmd.hh.

Constructor & Destructor Documentation

◆ PasteComponentCmd()

PasteComponentCmd::PasteComponentCmd ( )

The Constructor.

Definition at line 64 of file PasteComponentCmd.cc.

64 :
66}
static const std::string CMD_NAME_PASTE
Command name for the "Paste" command.

Referenced by create().

Member Function Documentation

◆ create()

PasteComponentCmd * PasteComponentCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 221 of file PasteComponentCmd.cc.

221 {
222 return new PasteComponentCmd();
223}

References PasteComponentCmd().

Here is the call graph for this function:

◆ Do()

bool PasteComponentCmd::Do ( )
virtual

Executes the command.

Copies descriptor of a component from the clipboard and adds corresponding component to the machine

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

Implements GUICommand.

Definition at line 79 of file PasteComponentCmd.cc.

79 {
80
82 ObjectState* contents = clipboard->copyContents();
83
84 MDFDocument* document =
85 dynamic_cast<MDFDocument*>(view()->GetDocument());
86 assert(document != NULL);
87 Machine* machine = document->getModel()->getMachine();
88 assert(machine != NULL);
89
90 document->getModel()->pushToStack();
91
92 if (contents->name() == Socket::OSNAME_SOCKET) {
93 // socket
95 Socket* socket = new Socket(contents);
96 paste(*machine, socket, navigator);
97 contents->setAttribute(Socket::OSKEY_NAME, socket->name());
98 // Socket can be pasted only if the target machine has busses with
99 // the same names as the busses where the copied socket was connected
100 // to.
101 try {
102 socket->loadState(contents);
103 } catch (ObjectStateLoadingException& e) {
104 wxString message =
105 _T("The socket cannot be pasted to this machine.\n\n");
106 message.Append(WxConversion::toWxString(e.errorMessage()));
107 InformationDialog dialog(parentWindow(), message);
108 dialog.ShowModal();
109 delete socket;
110 return false;
111 }
112
113 } else if (contents->name() == FunctionUnit::OSNAME_FU) {
114 // function unit
117 TTAMachine::FunctionUnit* copiedFU = new FunctionUnit(contents);
118 std::string fuName = copiedFU->name();
119 paste(*machine, copiedFU, navigator);
120
121 // cannot copy address space from one machien to another.
122 if (clipboard->sourceMachine() == machine) {
123 TTAMachine::FunctionUnit& original =
124 *navigator.item(fuName);
125 // need to do this after paste() as the FU must be registered to
126 // the machine before the address space can be set
127 if (original.hasAddressSpace()) {
128 copiedFU->setAddressSpace(original.addressSpace());
129 }
130 }
131 } else if (contents->name() == ImmediateUnit::OSNAME_IMMEDIATE_UNIT) {
132 // immediate unit
135 paste(*machine, new ImmediateUnit(contents), navigator);
136
137 } else if (contents->name() == RegisterFile::OSNAME_REGISTER_FILE) {
138 // register file
141 paste(*machine, new RegisterFile(contents), navigator);
142
143 } else if (contents->name() == Bus::OSNAME_BUS) {
144 // register file
145 Machine::BusNavigator navigator =
147 TTAMachine::Bus* copiedBus = new Bus(contents);
148
149 // cannot copy guards from one machine into another
150 // plus additional check if oroginal bus has been deleted
151 if (clipboard->sourceMachine() == machine &&
152 navigator.hasItem(copiedBus->name())) {
153
154 TTAMachine::Bus& original =
155 *navigator.item(copiedBus->name());
156
157 // register the bus to the machine, possibly rename it to
158 // avoid name clashes
159 paste(*machine, copiedBus, navigator);
160
161 // also copy the guards from the original Bus
162 assert(copiedBus->guardCount() == 0);
163 for (int i = 0; i < original.guardCount(); ++i) {
164 original.guard(i)->copyTo(*copiedBus);
165 }
166 } else {
167 // register the bus as above
168 paste(*machine, copiedBus, navigator);
169 assert(copiedBus->guardCount() == 0);
170 }
171 } else if (contents->name() == ControlUnit::OSNAME_CONTROL_UNIT) {
172 // control unit
173 if (machine->controlUnit() != NULL) {
174 // Target machine already contained a control unit.
175 // Display error message and pop the machine from undo stack.
177 format fmt =
179 string title = fmt.str();
180 wxString message = WxConversion::toWxString(title);
181 InformationDialog info(parentWindow(), message);
182 info.ShowModal();
183 document->getModel()->popFromStack();
184 delete contents;
185 return false;
186 } else {
187 // Paste control unit.
188 ControlUnit* gcu = new ControlUnit(contents);
189 gcu->setMachine(*machine);
190 }
191 } else {
192 // Unknown component type.
193 assert(false);
194 }
195
196 delete contents;
197
198 document->getModel()->notifyObservers();
199
200 return false;
201}
#define assert(condition)
TTAMachine::Machine * machine
the architecture definition of the estimated processor
wxView * view() const
std::string errorMessage() const
Definition Exception.cc:123
wxWindow * parentWindow() const
Definition GUICommand.cc:75
Model * getModel()
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
void setAttribute(const std::string &name, const std::string &value)
std::string name() const
void paste(TTAMachine::Machine &machine, TTAMachine::Component *component, ComponentNavigator &navigator)
ObjectState * copyContents()
const TTAMachine::Machine * sourceMachine()
static ProDeClipboard * instance()
static ProDeTextGenerator * instance()
@ MSG_ERROR_ONE_GCU
Error: Multiple control units.
Guard * guard(int index) const
Definition Bus.cc:456
static const std::string OSNAME_BUS
ObjectState name for Bus ObjectState.
Definition Bus.hh:116
int guardCount() const
Definition Bus.cc:441
virtual TCEString name() const
static const std::string OSNAME_CONTROL_UNIT
ObjectState name for ControlUnit.
virtual void setMachine(Machine &mach)
virtual AddressSpace * addressSpace() const
virtual void setAddressSpace(AddressSpace *as)
static const std::string OSNAME_FU
ObjectState name for function unit.
virtual bool hasAddressSpace() const
virtual void copyTo(Bus &parentBus) const =0
static const std::string OSNAME_IMMEDIATE_UNIT
ObjectState name for ImmediateUnit.
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual ControlUnit * controlUnit() const
Definition Machine.cc:345
static const std::string OSNAME_REGISTER_FILE
ObjectState name for RegisterFile.
static const std::string OSNAME_SOCKET
ObjectState name for socket.
Definition Socket.hh:100
virtual void loadState(const ObjectState *state)
Definition Socket.cc:502
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)

References TTAMachine::FunctionUnit::addressSpace(), assert, TTAMachine::Machine::busNavigator(), TTAMachine::Machine::controlUnit(), ProDeClipboard::copyContents(), TTAMachine::Guard::copyTo(), Exception::errorMessage(), TTAMachine::Machine::functionUnitNavigator(), Model::getMachine(), MDFDocument::getModel(), TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), TTAMachine::FunctionUnit::hasAddressSpace(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), TTAMachine::Machine::immediateUnitNavigator(), ProDeClipboard::instance(), ProDeTextGenerator::instance(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Socket::loadState(), machine, ProDeTextGenerator::MSG_ERROR_ONE_GCU, TTAMachine::Component::name(), ObjectState::name(), Model::notifyObservers(), TTAMachine::Bus::OSNAME_BUS, TTAMachine::ControlUnit::OSNAME_CONTROL_UNIT, TTAMachine::FunctionUnit::OSNAME_FU, TTAMachine::ImmediateUnit::OSNAME_IMMEDIATE_UNIT, TTAMachine::RegisterFile::OSNAME_REGISTER_FILE, TTAMachine::Socket::OSNAME_SOCKET, GUICommand::parentWindow(), paste(), Model::popFromStack(), Model::pushToStack(), TTAMachine::Machine::registerFileNavigator(), TTAMachine::FunctionUnit::setAddressSpace(), ObjectState::setAttribute(), TTAMachine::ControlUnit::setMachine(), TTAMachine::Machine::socketNavigator(), ProDeClipboard::sourceMachine(), Texts::TextGenerator::text(), WxConversion::toWxString(), and EditorCommand::view().

Here is the call graph for this function:

◆ icon()

string PasteComponentCmd::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 233 of file PasteComponentCmd.cc.

233 {
235}
static const std::string CMD_ICON_PASTE
Icon location for the "Paste" command.

References ProDeConstants::CMD_ICON_PASTE.

◆ id()

int PasteComponentCmd::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 210 of file PasteComponentCmd.cc.

References ProDeConstants::COMMAND_PASTE.

◆ isEnabled()

bool PasteComponentCmd::isEnabled ( )
virtual

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

This command is executable when a document is open and the clipboard is not empty.

Returns
True, if the command is executable.

Reimplemented from EditorCommand.

Definition at line 248 of file PasteComponentCmd.cc.

248 {
249
250 // check that a document is open
251 wxDocManager* manager = wxGetApp().docManager();
252 MDFView* mdfView = dynamic_cast<MDFView*>(manager->GetCurrentView());
253 if (mdfView == NULL) {
254 return false;
255 }
256
257 // check that the clipboard is not empty
259 if (clipboard->isEmpty()) {
260 return false;
261 }
262 return true;
263}

References ProDeClipboard::instance(), and ProDeClipboard::isEmpty().

Here is the call graph for this function:

◆ paste()

template<class ComponentNavigator >
void PasteComponentCmd::paste ( TTAMachine::Machine machine,
TTAMachine::Component component,
ComponentNavigator &  navigator 
)
private

Referenced by Do().

◆ setMachine()

bool PasteComponentCmd::setMachine ( TTAMachine::Component component,
TTAMachine::Machine machine 
)
private

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