Added exporting.

A lot of changes: GUI changed, added exporting(not completed yet) to txt
This commit is contained in:
2015-06-17 17:21:46 +03:00
parent b4c25c71b7
commit 68376baa4a
8 changed files with 100 additions and 31 deletions

View File

@@ -147,7 +147,7 @@
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_ANY</property>
<property name="id">wxID_EXECUTE</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">&amp;Generate</property>
<property name="name">miGenerate</property>
@@ -157,6 +157,21 @@
<event name="OnMenuSelection">onGenerateClick</event>
<event name="OnUpdateUI"></event>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_EXPORT</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label">&amp;Export</property>
<property name="name">miExport</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">onExportClick</event>
<event name="OnUpdateUI"></event>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
@@ -269,7 +284,7 @@
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="flag">wxALIGN_BOTTOM|wxALIGN_LEFT|wxALIGN_RIGHT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="bg"></property>

View File

@@ -20,9 +20,13 @@ VMainFrame::VMainFrame( wxWindow* parent, wxWindowID id, const wxString& title,
miFile->Append( miOpenGrid );
wxMenuItem* miGenerate;
miGenerate = new wxMenuItem( miFile, wxID_ANY, wxString( _("&Generate") ) , wxEmptyString, wxITEM_NORMAL );
miGenerate = new wxMenuItem( miFile, wxID_EXECUTE, wxString( _("&Generate") ) , wxEmptyString, wxITEM_NORMAL );
miFile->Append( miGenerate );
wxMenuItem* miExport;
miExport = new wxMenuItem( miFile, wxID_EXPORT, wxString( _("&Export") ) , wxEmptyString, wxITEM_NORMAL );
miFile->Append( miExport );
wxMenuItem* miExit;
miExit = new wxMenuItem( miFile, wxID_EXIT, wxString( _("E&xit") ) + wxT('\t') + wxT("Ctrl+Q"), wxEmptyString, wxITEM_NORMAL );
miFile->Append( miExit );
@@ -48,7 +52,7 @@ VMainFrame::VMainFrame( wxWindow* parent, wxWindowID id, const wxString& title,
bSizer4->Add( tPath, 1, wxEXPAND|wxLEFT|wxTOP, 5 );
bPath = new wxButton( this, wxID_ANY, _("..."), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
bSizer4->Add( bPath, 0, wxALL, 5 );
bSizer4->Add( bPath, 0, wxALIGN_BOTTOM|wxALIGN_LEFT|wxALIGN_RIGHT, 5 );
bSizer2->Add( bSizer4, 0, wxEXPAND, 5 );
@@ -81,6 +85,7 @@ VMainFrame::VMainFrame( wxWindow* parent, wxWindowID id, const wxString& title,
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( VMainFrame::onExitClick ) );
this->Connect( miOpenGrid->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onOpenGridClick ) );
this->Connect( miGenerate->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onGenerateClick ) );
this->Connect( miExport->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onExportClick ) );
this->Connect( miExit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onExitClick ) );
this->Connect( miAbout->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onAboutClick ) );
bPath->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( VMainFrame::onOpenGridClick ), NULL, this );
@@ -93,6 +98,7 @@ VMainFrame::~VMainFrame()
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( VMainFrame::onExitClick ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onOpenGridClick ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onGenerateClick ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onExportClick ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onExitClick ) );
this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( VMainFrame::onAboutClick ) );
bPath->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( VMainFrame::onOpenGridClick ), NULL, this );

View File

@@ -27,6 +27,8 @@
///////////////////////////////////////////////////////////////////////////
#define wxID_EXECUTE 1000
#define wxID_EXPORT 1001
///////////////////////////////////////////////////////////////////////////////
/// Class VMainFrame
@@ -50,6 +52,7 @@ class VMainFrame : public wxFrame
virtual void onExitClick( wxCloseEvent& event ) { event.Skip(); }
virtual void onOpenGridClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onGenerateClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onExportClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onExitClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onAboutClick( wxCommandEvent& event ) { event.Skip(); }

View File

@@ -27,9 +27,8 @@ void MainFrame::onOpenGridClick(wxCommandEvent &event) {
return;
}
tPath->SetValue(dlgOpen.GetPath());
GridType grid;
readGrid(tPath->GetValue(), grid);
SetGridImage(grid);
readGrid(tPath->GetValue(), _grid);
SetGridImage(_grid);
}
void MainFrame::SetGridImage(GridType &grid, size_t w) {
@@ -62,7 +61,7 @@ void MainFrame::SetGridImage(GridType &grid, size_t w) {
dc.DrawText(wxString::Format(wxT("%d"),winfos.at(i).ind), sq_w*winfos.at(i).x, sq_h*winfos.at(i).y);
}
if ( _words.size() > 0 ) {
if ( _ans.size() > 0 ) {
using std::vector;
vector< vector< bool > > usedCells(
grid.size(),
@@ -76,7 +75,7 @@ void MainFrame::SetGridImage(GridType &grid, size_t w) {
for (size_t j = 0; j < winfos.at(i).len; ++j)
if ( !usedCells.at(winfos.at(i).x+j).at(winfos.at(i).y) ) {
dc.DrawText(
_words.at(i).at(j),
_ans.at(i).at(j),
sq_w*(winfos.at(i).x+j) + sq_w*0.24,
sq_h*winfos.at(i).y
);
@@ -86,7 +85,7 @@ void MainFrame::SetGridImage(GridType &grid, size_t w) {
for (size_t j = 0; j < winfos.at(i).len; ++j)
if ( !usedCells.at(winfos.at(i).x).at(winfos.at(i).y+j) ) {
dc.DrawText(
_words.at(i).at(j),
_ans.at(i).at(j),
sq_w*winfos.at(i).x + sq_w*0.24,
sq_h*(winfos.at(i).y+j)
);
@@ -112,20 +111,17 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) {
}
std::vector<wxString> words_out;
GridType grid;
if (tPath->GetValue() == wxEmptyString){
wxMessageBox( _("Path to grid is empty"), _("Info"), wxICON_INFORMATION);
if ( _dict.size() == 0 ){
wxMessageBox( _("Crossword grid isn't loaded!"), _("Info"), wxICON_INFORMATION);
return;
}
readGrid(tPath->GetValue(), grid);
try{
generateCross(grid, _allWords, _transType, words_out);
generateCross(_grid, _allWords, _transType, words_out);
_words.clear();
_words = words_out;
_ans = words_out;
std::vector<WordInfo> winfos;
generateWordInfo(grid, winfos);
generateWordInfo(_grid, winfos);
tOutput->Clear();
@@ -146,8 +142,7 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) {
}
if (winfos.size() == 0)
throw 42;
SetGridImage(grid);
_words.clear();
SetGridImage(_grid);
}
catch ( ... ){
tOutput->Clear();
@@ -156,6 +151,25 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) {
this->Refresh();
}
void MainFrame::onExportClick(wxCommandEvent& event) {
if ( _grid.size() == 0 ) {
wxMessageBox( _("Grid isn't loaded now"), _("Info"), wxICON_INFORMATION );
return;
}
wxFileDialog dlgSave(this, _("Exporting crossword"), wxEmptyString, wxEmptyString,
_("txt files (*.txt)|*.txt"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dlgSave.ShowModal() == wxID_CANCEL)
return;
FilledCrossword t_cross;
t_cross.grid = _grid;
t_cross.ans = _ans;
generateWordInfo(_grid, t_cross.words);
if ( !exportToFile(t_cross, true, dlgSave.GetPath()) ){
wxLogError(wxT("Cannot save current contents in file '%s'."), dlgSave.GetPath().GetData());
return;
}
wxLogDebug(wxT("Exporting to ") + dlgSave.GetPath() + wxT("is complete"));
}
class MyApp: public wxApp {
public:

View File

@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Aleksey Lobanov
Date :=16/06/15
Date :=17/06/15
CodeLitePath :="/home/alex/.codelite"
LinkerName :=/usr/bin/g++-4.8
SharedObjectLinkerName :=/usr/bin/g++-4.8 -shared -fPIC

View File

@@ -20,11 +20,12 @@
class MainFrame: public VMainFrame {
protected:
std::vector<wxString> _words;
std::vector<wxString> _ans;
DictType _dict;
bool _isDictLoaded;
AllWordsType _allWords;
CharsTransType _transType;
GridType _grid;
public:
void SetGridImage(GridType &grid, size_t w=400);
@@ -41,11 +42,12 @@ public:
_isDictLoaded = false;
srand(time(NULL));
}
virtual void onExitClick( wxCloseEvent& event ) { event.Skip(); }
virtual void onOpenGridClick( wxCommandEvent& event );
virtual void onGenerateClick( wxCommandEvent& event );
virtual void onExitClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onAboutClick( wxCommandEvent& event ) { event.Skip(); }
void onExitClick( wxCloseEvent& event ) { event.Skip(); }
void onOpenGridClick( wxCommandEvent& event );
void onGenerateClick( wxCommandEvent& event );
void onExportClick( wxCommandEvent& event );
void onExitClick( wxCommandEvent& event ) { event.Skip(); }
void onAboutClick( wxCommandEvent& event ) { event.Skip(); }
};
#endif // WXGUI_HPP