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

#include <ProDeExportCmd.hh>

Inheritance diagram for ProDeExportCmd:
Inheritance graph
Collaboration diagram for ProDeExportCmd:
Collaboration graph

Public Member Functions

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

Detailed Description

EditorCommand for exporting machine visualization to an encapsulated postscript file or a bitmap.

Definition at line 43 of file ProDeExportCmd.hh.

Constructor & Destructor Documentation

◆ ProDeExportCmd()

ProDeExportCmd::ProDeExportCmd ( )

The Constructor.

Definition at line 55 of file ProDeExportCmd.cc.

Referenced by create().

◆ ~ProDeExportCmd()

ProDeExportCmd::~ProDeExportCmd ( )
virtual

The Destructor.

Definition at line 64 of file ProDeExportCmd.cc.

64 {}

Member Function Documentation

◆ create()

ProDeExportCmd * ProDeExportCmd::create ( ) const
virtual

Creates and returns a new instance of this command.

Returns
Newly created instance of this command.

Implements GUICommand.

Definition at line 156 of file ProDeExportCmd.cc.

156  {
157  return new ProDeExportCmd();
158 }

References ProDeExportCmd().

Here is the call graph for this function:

◆ Do()

bool ProDeExportCmd::Do ( )
virtual

Executes the command.

Returns
Always false. Returning true here would cause problems with the wxCommandProcessor, and the command is never undoable so it's safe to return false even if the command was succesfully executed.

Implements GUICommand.

Definition at line 75 of file ProDeExportCmd.cc.

75  {
76 
77  wxView* view = wxGetApp().docManager()->GetCurrentView();
78  MachineCanvas* canvas = dynamic_cast<MDFView*>(view)->canvas();
79 
80  assert(view != NULL && canvas != NULL);
81 
82  wxString message = _T("Export processor figure.");
83  wxString defaultDir = _T(".");
84  wxString defaultFile= _T("");
85 #if wxCHECK_VERSION(3, 0, 0)
86  wxString fileTypes = _T("Scalable Vector Graphics (.svg)|*.svg|");
87 #else
88  wxString fileTypes = _T("Encapsulated Postscript (.eps)|*.eps;*.epsi|");
89 #endif
90  fileTypes.Append(_T("Portable Network Graphics (.png)|*.png"));
91 
92  wxFileDialog dialog(
93  parentWindow(), message, defaultDir, defaultFile, fileTypes,
94  wxSAVE | wxOVERWRITE_PROMPT);
95 
96  if (dialog.ShowModal() == wxID_CANCEL) {
97  return false;
98  }
99 
100  std::string filename = WxConversion::toString(dialog.GetPath());
101  std::string extension = FileSystem::fileExtension(filename);
102  std::string creator = "TTA Processor Designer";
103  std::string title =
104  WxConversion::toString(view->GetDocument()->GetTitle());
105 
106 #if wxCHECK_VERSION(3, 0, 0)
107  if (extension == ".svg") {
108  if (!canvas->saveSVG(filename)) {
109 #else
110  if (extension == ".eps" || extension == ".epsi") {
111  if (!canvas->saveEPS(filename, title, creator)) {
112 #endif
113  wxString message = _T("Error saving file '");
114  message.Append(dialog.GetPath());
115  message.Append(_T("'."));
116  ErrorDialog errorDialog(parentWindow(), message);
117  errorDialog.ShowModal();
118  }
119  } else if (extension == ".png") {
120  if (!canvas->savePNG(filename)) {
121  wxString message = _T("Error saving file '");
122  message.Append(dialog.GetPath());
123  message.Append(_T("'."));
124  ErrorDialog errorDialog(parentWindow(), message);
125  errorDialog.ShowModal();
126  }
127  } else {
128  wxString message = _T("File type with extension '");
129  message.Append(WxConversion::toWxString(extension));
130  message.Append(_T("' is not supported."));
131  ErrorDialog dialog(parentWindow(), message);
132  dialog.ShowModal();
133  return false;
134  }
135 
136  return false;
137 }

References assert, FileSystem::fileExtension(), GUICommand::parentWindow(), MachineCanvas::saveEPS(), MachineCanvas::savePNG(), WxConversion::toString(), WxConversion::toWxString(), and EditorCommand::view().

Here is the call graph for this function:

◆ id()

int ProDeExportCmd::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 145 of file ProDeExportCmd.cc.

145  {
147 }

References ProDeConstants::COMMAND_EXPORT.

◆ isEnabled()

bool ProDeExportCmd::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 169 of file ProDeExportCmd.cc.

169  {
170  wxView* view = wxGetApp().docManager()->GetCurrentView();
171  if (view != NULL) {
172  return true;
173  }
174  return false;
175 }

References EditorCommand::view().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
MachineCanvas
Definition: MachineCanvas.hh:64
WxConversion::toWxString
static wxString toWxString(const std::string &source)
ProDeConstants::CMD_NAME_EXPORT
static const std::string CMD_NAME_EXPORT
Command name for the "Export" command.
Definition: ProDeConstants.hh:88
MachineCanvas::saveEPS
bool saveEPS(const std::string &filename, const std::string &title, const std::string &creator="")
Definition: MachineCanvas.cc:617
EditorCommand::EditorCommand
EditorCommand(std::string name, wxWindow *parent=NULL)
Definition: EditorCommand.cc:42
assert
#define assert(condition)
Definition: Application.hh:86
ErrorDialog
Definition: ErrorDialog.hh:42
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
FileSystem::fileExtension
static std::string fileExtension(const std::string &fileName)
Definition: FileSystem.cc:279
MachineCanvas::savePNG
bool savePNG(const std::string &filename)
Definition: MachineCanvas.cc:648
ProDeExportCmd::ProDeExportCmd
ProDeExportCmd()
Definition: ProDeExportCmd.cc:55
ProDeConstants::COMMAND_EXPORT
@ COMMAND_EXPORT
Definition: ProDeConstants.hh:414
WxConversion::toString
static std::string toString(const wxString &source)
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
MDFView
Definition: MDFView.hh:59