OpenASIP  2.0
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.

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 }

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, ObjectState::name(), TTAMachine::Component::name(), Model::notifyObservers(), 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 }

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.

210  {
212 }

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:
MDFDocument::getModel
Model * getModel()
Definition: MDFDocument.cc:229
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::FunctionUnit::hasAddressSpace
virtual bool hasAddressSpace() const
Definition: FunctionUnit.cc:608
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
ProDeConstants::CMD_ICON_PASTE
static const std::string CMD_ICON_PASTE
Icon location for the "Paste" command.
Definition: ProDeConstants.hh:314
ObjectStateLoadingException
Definition: Exception.hh:551
TTAMachine::Bus
Definition: Bus.hh:53
TTAMachine::Socket::loadState
virtual void loadState(const ObjectState *state)
Definition: Socket.cc:502
ObjectState
Definition: ObjectState.hh:59
TTAMachine::FunctionUnit::addressSpace
virtual AddressSpace * addressSpace() const
Definition: FunctionUnit.cc:580
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
PasteComponentCmd::paste
void paste(TTAMachine::Machine &machine, TTAMachine::Component *component, ComponentNavigator &navigator)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ProDeConstants::CMD_NAME_PASTE
static const std::string CMD_NAME_PASTE
Command name for the "Paste" command.
Definition: ProDeConstants.hh:130
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
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::Guard::copyTo
virtual void copyTo(Bus &parentBus) const =0
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
TTAMachine::Machine::immediateUnitNavigator
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition: Machine.cc:416
TTAMachine::ControlUnit
Definition: ControlUnit.hh:50
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
ProDeClipboard::sourceMachine
const TTAMachine::Machine * sourceMachine()
Definition: ProDeClipboard.hh:54
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
TTAMachine::Socket
Definition: Socket.hh:53
TTAMachine::FunctionUnit::setAddressSpace
virtual void setAddressSpace(AddressSpace *as)
Definition: FunctionUnit.cc:594
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
TTAMachine::Machine::socketNavigator
virtual SocketNavigator socketNavigator() const
Definition: Machine.cc:368
ProDeClipboard::isEmpty
bool isEmpty()
Definition: ProDeClipboard.cc:121
ObjectState::name
std::string name() const
TTAMachine::Bus::guardCount
int guardCount() const
Definition: Bus.cc:441
TTAMachine::Bus::guard
Guard * guard(int index) const
Definition: Bus.cc:456
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
MDFDocument
Definition: MDFDocument.hh:51
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
TTAMachine::ControlUnit::setMachine
virtual void setMachine(Machine &mach)
Definition: ControlUnit.cc:119
ProDeClipboard
Definition: ProDeClipboard.hh:47
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
ProDeTextGenerator::MSG_ERROR_ONE_GCU
@ MSG_ERROR_ONE_GCU
Error: Multiple control units.
Definition: ProDeTextGenerator.hh:224
PasteComponentCmd::PasteComponentCmd
PasteComponentCmd()
Definition: PasteComponentCmd.cc:64
ProDeClipboard::copyContents
ObjectState * copyContents()
Definition: ProDeClipboard.cc:104
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
InformationDialog
Definition: InformationDialog.hh:42
ProDeConstants::COMMAND_PASTE
@ COMMAND_PASTE
Definition: ProDeConstants.hh:437
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88
TTAMachine::Machine
Definition: Machine.hh:73
ProDeClipboard::instance
static ProDeClipboard * instance()
Definition: ProDeClipboard.cc:62
MDFView
Definition: MDFView.hh:59
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50