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

#include <OSEdAddModuleCmd.hh>

Inheritance diagram for OSEdAddModuleCmd:
Inheritance graph
Collaboration diagram for OSEdAddModuleCmd:
Collaboration graph

Public Member Functions

 OSEdAddModuleCmd ()
 
virtual ~OSEdAddModuleCmd ()
 
virtual int id () const
 
virtual GUICommandcreate () const
 
virtual bool Do ()
 
virtual bool isEnabled ()
 
virtual std::string icon () 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

 OSEdAddModuleCmd (const OSEdAddModuleCmd &)
 Copying not allowed. More...
 
OSEdAddModuleCmdoperator= (const OSEdAddModuleCmd &)
 Assignment not allowed. More...
 

Detailed Description

Command for adding new module to operation set.

Definition at line 43 of file OSEdAddModuleCmd.hh.

Constructor & Destructor Documentation

◆ OSEdAddModuleCmd() [1/2]

OSEdAddModuleCmd::OSEdAddModuleCmd ( )

Constructor.

Definition at line 57 of file OSEdAddModuleCmd.cc.

57  :
59 }

Referenced by create().

◆ ~OSEdAddModuleCmd()

OSEdAddModuleCmd::~OSEdAddModuleCmd ( )
virtual

Destructor.

Definition at line 64 of file OSEdAddModuleCmd.cc.

64  {
65 }

◆ OSEdAddModuleCmd() [2/2]

OSEdAddModuleCmd::OSEdAddModuleCmd ( const OSEdAddModuleCmd )
private

Copying not allowed.

Member Function Documentation

◆ create()

GUICommand * OSEdAddModuleCmd::create ( ) const
virtual

Creates a new command.

Returns
New command.

Implements GUICommand.

Definition at line 83 of file OSEdAddModuleCmd.cc.

83  {
84  return new OSEdAddModuleCmd();
85 }

References OSEdAddModuleCmd().

Here is the call graph for this function:

◆ Do()

bool OSEdAddModuleCmd::Do ( )
virtual

Executes the command.

Returns
True if execution is successful.

Implements GUICommand.

Definition at line 93 of file OSEdAddModuleCmd.cc.

93  {
94 
95  OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
96  OSEdTreeView* treeView = mainFrame->treeView();
97  string path = treeView->selectedPath();
99  wxTreeItemId pathId = treeView->selectedPathId();
101 
102  if (!FileSystem::fileExists(path)) {
103  if (!FileSystem::createDirectory(path)) {
104  format fmt =
106  ErrorDialog error(
107  parentWindow(), WxConversion::toWxString(fmt.str()));
108  error.ShowModal();
109  return false;
110  }
111  index.addPath(path);
112  treeView->SetItemBold(pathId);
113  }
114 
115  AddModuleDialog dialog(parentWindow(), path);
116  if (dialog.ShowModal() == wxID_OK) {
117 
118  OperationModule* module = new OperationModule(dialog.name(), path);
119  OperationSerializer& serializer =
121  serializer.setDestinationFile(module->propertiesModule());
122  ObjectState* root = new ObjectState("osal");
123  try {
124  serializer.writeState(root);
125  } catch (const Exception& e) {
126  format fmt = texts.text(
128 
129  ErrorDialog error(parentWindow(),
130  WxConversion::toWxString(fmt.str()));
131  error.ShowModal();
132  delete root;
133  return false;
134  }
135  delete root;
136  index.addModule(module, path);
137  treeView->addItem(pathId, module->name());
138  treeView->update();
139  }
140 
141  return true;
142 }

References OSEdTreeView::addItem(), OperationIndex::addModule(), OperationIndex::addPath(), FileSystem::createDirectory(), FileSystem::fileExists(), OSEdTextGenerator::instance(), AddModuleDialog::name(), OperationModule::name(), OperationContainer::operationIndex(), OperationContainer::operationSerializer(), GUICommand::parentWindow(), OperationModule::propertiesModule(), OSEdTreeView::selectedPath(), OSEdTreeView::selectedPathId(), OperationSerializer::setDestinationFile(), Texts::TextGenerator::text(), WxConversion::toWxString(), OSEdMainFrame::treeView(), OSEdTextGenerator::TXT_ERROR_CAN_NOT_CREATE_MOD, OSEdTreeView::update(), and OperationSerializer::writeState().

Here is the call graph for this function:

◆ icon()

string OSEdAddModuleCmd::icon ( ) const
virtual

Return icon path.

Returns
Empty string (no icons used).

Implements GUICommand.

Definition at line 181 of file OSEdAddModuleCmd.cc.

181  {
182  return "";
183 }

◆ id()

int OSEdAddModuleCmd::id ( ) const
virtual

Returns the id of the command.

Returns
The id of the command.

Implements GUICommand.

Definition at line 73 of file OSEdAddModuleCmd.cc.

73  {
75 }

References OSEdConstants::CMD_ADD_MODULE.

◆ isEnabled()

bool OSEdAddModuleCmd::isEnabled ( )
virtual

Returns true if command is enabled.

Returns
True if command is enabled.

Implements GUICommand.

Definition at line 150 of file OSEdAddModuleCmd.cc.

150  {
151  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
152  string path = treeView->selectedPath();
153  if (path != "") {
154  if (FileSystem::fileExists(path)) {
155  string dumbFile = path + FileSystem::DIRECTORY_SEPARATOR +
156  "dumb12234";
157  if (FileSystem::createFile(dumbFile)) {
159  return true;
160  } else {
161  return false;
162  }
163  } else {
164  if (FileSystem::createDirectory(path)) {
166  return true;
167  } else {
168  return false;
169  }
170  }
171  }
172  return false;
173 }

References FileSystem::createDirectory(), FileSystem::createFile(), FileSystem::DIRECTORY_SEPARATOR, FileSystem::fileExists(), FileSystem::removeFileOrDirectory(), and OSEdTreeView::selectedPath().

Here is the call graph for this function:

◆ operator=()

OSEdAddModuleCmd& OSEdAddModuleCmd::operator= ( const OSEdAddModuleCmd )
private

Assignment not allowed.


The documentation for this class was generated from the following files:
OperationIndex::addPath
void addPath(const std::string &path)
Definition: OperationIndex.cc:82
WxConversion::toWxString
static wxString toWxString(const std::string &source)
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
FileSystem::createDirectory
static bool createDirectory(const std::string &path)
Definition: FileSystem.cc:400
OperationSerializer::writeState
virtual void writeState(const ObjectState *state)
Definition: OperationSerializer.cc:96
OperationContainer::operationSerializer
static OperationSerializer & operationSerializer()
Definition: OperationContainer.cc:111
OperationSerializer::setDestinationFile
void setDestinationFile(const std::string &filename)
Definition: OperationSerializer.cc:546
OSEdTreeView::addItem
void addItem(wxTreeItemId parent, std::string item)
Definition: OSEdTreeView.cc:573
OSEdAddModuleCmd::OSEdAddModuleCmd
OSEdAddModuleCmd()
Definition: OSEdAddModuleCmd.cc:57
OSEdTreeView::selectedPathId
wxTreeItemId selectedPathId()
Definition: OSEdTreeView.cc:480
ObjectState
Definition: ObjectState.hh:59
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
OSEdMainFrame::treeView
OSEdTreeView * treeView() const
Definition: OSEdMainFrame.cc:241
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:121
OSEdTextGenerator::TXT_ERROR_CAN_NOT_CREATE_MOD
@ TXT_ERROR_CAN_NOT_CREATE_MOD
Error when can not create module.
Definition: OSEdTextGenerator.hh:134
ErrorDialog
Definition: ErrorDialog.hh:42
OperationIndex::addModule
void addModule(OperationModule *module, const std::string &path)
Definition: OperationIndex.cc:193
OSEdTreeView
Definition: OSEdTreeView.hh:54
OSEdTreeView::selectedPath
std::string selectedPath()
Definition: OSEdTreeView.cc:456
OperationSerializer
Definition: OperationSerializer.hh:49
AddModuleDialog
Definition: AddModuleDialog.hh:42
Exception
Definition: Exception.hh:54
FileSystem::createFile
static bool createFile(const std::string &file)
Definition: FileSystem.cc:468
OSEdConstants::CMD_ADD_MODULE
@ CMD_ADD_MODULE
Add module command id.
Definition: OSEdConstants.hh:92
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
OSEdMainFrame
Definition: OSEdMainFrame.hh:49
GUICommand::GUICommand
GUICommand(std::string name, wxWindow *parent)
Definition: GUICommand.cc:42
FileSystem::fileExists
static bool fileExists(const std::string fileName)
OperationModule
Definition: OperationModule.hh:46
OSEdTreeView::update
void update()
Definition: OSEdTreeView.cc:670
OperationIndex
Definition: OperationIndex.hh:58
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
OperationModule::name
virtual std::string name() const
Definition: OperationModule.cc:160
OperationContainer::operationIndex
static OperationIndex & operationIndex()
Definition: OperationContainer.cc:94
OSEdConstants::CMD_NAME_ADD_MODULE
static const std::string CMD_NAME_ADD_MODULE
Add module command name.
Definition: OSEdConstants.hh:55
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75