OpenASIP 2.2
Loading...
Searching...
No Matches
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.

55 :
57
58}
static const std::string CMD_NAME_EXPORT
Command name for the "Export" command.

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}
#define assert(condition)
wxView * view() const
static std::string fileExtension(const std::string &fileName)
wxWindow * parentWindow() const
Definition GUICommand.cc:75
bool savePNG(const std::string &filename)
bool saveEPS(const std::string &filename, const std::string &title, const std::string &creator="")
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)

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.

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: