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

#include <OSEdModifyBehaviorCmd.hh>

Inheritance diagram for OSEdModifyBehaviorCmd:
Inheritance graph
Collaboration diagram for OSEdModifyBehaviorCmd:
Collaboration graph

Public Member Functions

 OSEdModifyBehaviorCmd ()
 
virtual ~OSEdModifyBehaviorCmd ()
 
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

 OSEdModifyBehaviorCmd (const OSEdModifyBehaviorCmd &)
 Copying not allowed. More...
 
OSEdModifyBehaviorCmdoperator= (const OSEdModifyBehaviorCmd &)
 Assignment not allowed. More...
 

Detailed Description

Command for modifying operation behavior.

Definition at line 43 of file OSEdModifyBehaviorCmd.hh.

Constructor & Destructor Documentation

◆ OSEdModifyBehaviorCmd() [1/2]

OSEdModifyBehaviorCmd::OSEdModifyBehaviorCmd ( )

Constructor.

Definition at line 54 of file OSEdModifyBehaviorCmd.cc.

Referenced by create().

◆ ~OSEdModifyBehaviorCmd()

OSEdModifyBehaviorCmd::~OSEdModifyBehaviorCmd ( )
virtual

Destructor.

Definition at line 61 of file OSEdModifyBehaviorCmd.cc.

61  {
62 }

◆ OSEdModifyBehaviorCmd() [2/2]

OSEdModifyBehaviorCmd::OSEdModifyBehaviorCmd ( const OSEdModifyBehaviorCmd )
private

Copying not allowed.

Member Function Documentation

◆ create()

GUICommand * OSEdModifyBehaviorCmd::create ( ) const
virtual

Creates a new command.

Returns
A new command.

Implements GUICommand.

Definition at line 80 of file OSEdModifyBehaviorCmd.cc.

80  {
81  return new OSEdModifyBehaviorCmd();
82 }

References OSEdModifyBehaviorCmd().

Here is the call graph for this function:

◆ Do()

bool OSEdModifyBehaviorCmd::Do ( )
virtual

Executes the command.

Returns
True if execution is successful.

Implements GUICommand.

Definition at line 90 of file OSEdModifyBehaviorCmd.cc.

90  {
91 
93  OSEdOptions* options = wxGetApp().options();
94  string editor = options->editor();
95  if (editor == "") {
96  format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_NO_EDITOR);
98  error.ShowModal();
99  return false;
100  } else if (!FileSystem::fileExists(editor)) {
101  format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_OPEN);
102  fmt % editor;
104  error.ShowModal();
105  return false ;
106  } else {
107 
108  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
109  wxTreeItemId opId = treeView->selectedOperationId();
110  string modName = treeView->moduleOfOperation(opId);
111  wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
112  string pathName = treeView->pathOfModule(modId);
113 
114  OperationModule& module = OperationContainer::module(pathName, modName);
115  string cmd = "";
116  if (module.hasBehaviorSource()) {
117  string code = module.behaviorSourceModule();
118  cmd = editor + " " + code;
119  } else {
120  // new behavior is added for the module
121  string code = module.propertiesModule();
122  size_t pos = code.find_last_of(".");
123  code.erase(pos);
124  code += ".cc";
125 
126  // copy template file as new file
127  string dir = Environment::dataDirPath(
129 
130  string templateFile = dir + FileSystem::DIRECTORY_SEPARATOR +
132 
133  FileSystem::copy(templateFile, code);
134  cmd = editor + " " + code;
135  }
136  // we are using detached thread that will be automatically cleaned
137  CommandThread* thread = new CommandThread(cmd);
138  thread->Create();
139  thread->Run();
140  return true;
141  }
142 
143  assert(false);
144  return false;
145 }

References OSEdConstants::APPLICATION_NAME, assert, OSEdConstants::BEHAVIOR_TEMPLATE_FILE_NAME, OperationModule::behaviorSourceModule(), FileSystem::copy(), Environment::dataDirPath(), FileSystem::DIRECTORY_SEPARATOR, false, FileSystem::fileExists(), OperationModule::hasBehaviorSource(), OSEdTextGenerator::instance(), OperationContainer::module(), OSEdTreeView::moduleIdOfOperation(), OSEdTreeView::moduleOfOperation(), options, GUICommand::parentWindow(), OSEdTreeView::pathOfModule(), OperationModule::propertiesModule(), OSEdTreeView::selectedOperationId(), Texts::TextGenerator::text(), WxConversion::toString(), WxConversion::toWxString(), OSEdTextGenerator::TXT_ERROR_NO_EDITOR, and OSEdTextGenerator::TXT_ERROR_OPEN.

Here is the call graph for this function:

◆ icon()

string OSEdModifyBehaviorCmd::icon ( ) const
virtual

Returns the icon path.

Returns
Empty string (icons not used).

Implements GUICommand.

Definition at line 179 of file OSEdModifyBehaviorCmd.cc.

179  {
180  return "";
181 }

◆ id()

int OSEdModifyBehaviorCmd::id ( ) const
virtual

Returns the id of the command.

Returns
The id of the command.

Implements GUICommand.

Definition at line 70 of file OSEdModifyBehaviorCmd.cc.

70  {
72 }

References OSEdConstants::CMD_MODIFY_BEHAVIOR.

◆ isEnabled()

bool OSEdModifyBehaviorCmd::isEnabled ( )
virtual

Returns true if command is enabled.

Command is enable when path of the selected operation is writable.

Returns
True if command is enabled.

Implements GUICommand.

Definition at line 155 of file OSEdModifyBehaviorCmd.cc.

155  {
156  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
157  if (treeView->isOperationSelected()) {
158  wxTreeItemId opId = treeView->selectedOperationId();
159  string mod = treeView->moduleOfOperation(opId);
160  wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
161  string path = treeView->pathOfModule(modId);
162 
163  if (FileSystem::fileIsWritable(path)) {
164  return true;
165  } else {
166  return false;
167  }
168  } else {
169  return false;
170  }
171 }

References FileSystem::fileIsWritable(), OSEdTreeView::isOperationSelected(), OSEdTreeView::moduleIdOfOperation(), OSEdTreeView::moduleOfOperation(), OSEdTreeView::pathOfModule(), and OSEdTreeView::selectedOperationId().

Here is the call graph for this function:

◆ operator=()

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

Assignment not allowed.


The documentation for this class was generated from the following files:
OSEdConstants::BEHAVIOR_TEMPLATE_FILE_NAME
static const std::string BEHAVIOR_TEMPLATE_FILE_NAME
Name of the behavior template file name.
Definition: OSEdConstants.hh:82
OSEdConstants::APPLICATION_NAME
static const wxString APPLICATION_NAME
The name of the application.
Definition: OSEdConstants.hh:110
WxConversion::toWxString
static wxString toWxString(const std::string &source)
OSEdTreeView::pathOfModule
std::string pathOfModule(wxTreeItemId id)
Definition: OSEdTreeView.cc:431
OSEdModifyBehaviorCmd::OSEdModifyBehaviorCmd
OSEdModifyBehaviorCmd()
Definition: OSEdModifyBehaviorCmd.cc:54
OSEdTreeView::moduleIdOfOperation
wxTreeItemId moduleIdOfOperation(wxTreeItemId id)
Definition: OSEdTreeView.cc:420
OperationContainer::module
static OperationModule & module(const std::string &path, const std::string &mod)
Definition: OperationContainer.cc:148
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
assert
#define assert(condition)
Definition: Application.hh:86
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:121
ErrorDialog
Definition: ErrorDialog.hh:42
FileSystem::fileIsWritable
static bool fileIsWritable(const std::string fileName)
OSEdTreeView
Definition: OSEdTreeView.hh:54
OperationModule::behaviorSourceModule
virtual std::string behaviorSourceModule() const
Definition: OperationModule.cc:144
OSEdTreeView::moduleOfOperation
std::string moduleOfOperation(wxTreeItemId id)
Definition: OSEdTreeView.cc:407
OSEdTreeView::isOperationSelected
bool isOperationSelected() const
Definition: OSEdTreeView.cc:745
OSEdTextGenerator::TXT_ERROR_NO_EDITOR
@ TXT_ERROR_NO_EDITOR
Error when no editor is given.
Definition: OSEdTextGenerator.hh:140
FileSystem::copy
static void copy(const std::string &source, const std::string &target)
Definition: FileSystem.cc:524
OSEdTextGenerator::TXT_ERROR_OPEN
@ TXT_ERROR_OPEN
Error when opening fails.
Definition: OSEdTextGenerator.hh:141
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
CommandThread
Definition: CommandThread.hh:43
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
GUICommand::GUICommand
GUICommand(std::string name, wxWindow *parent)
Definition: GUICommand.cc:42
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
FileSystem::fileExists
static bool fileExists(const std::string fileName)
OperationModule
Definition: OperationModule.hh:46
OperationModule::hasBehaviorSource
virtual bool hasBehaviorSource() const
Definition: OperationModule.cc:131
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTreeView::selectedOperationId
wxTreeItemId selectedOperationId()
Definition: OSEdTreeView.cc:379
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
OSEdConstants::CMD_NAME_MODIFY_BEHAVIOR
static const std::string CMD_NAME_MODIFY_BEHAVIOR
Modify behavior command name.
Definition: OSEdConstants.hh:71
OSEdOptions
Definition: OSEdOptions.hh:46
WxConversion::toString
static std::string toString(const wxString &source)
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
OSEdConstants::CMD_MODIFY_BEHAVIOR
@ CMD_MODIFY_BEHAVIOR
Modify operation behavior command id.
Definition: OSEdConstants.hh:97
Environment::dataDirPath
static std::string dataDirPath(const std::string &prog)
Definition: Environment.cc:176