Some structure changes to add exporting questions
This commit is contained in:
@@ -31,6 +31,7 @@ struct WordInfo {
|
||||
struct FilledCrossword {
|
||||
GridType grid;
|
||||
std::vector< WordInfo > words;
|
||||
std::vector< wxString > ques;
|
||||
std::vector< wxString > ans;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@ void fillCross(FilledCrossword &cross){
|
||||
}
|
||||
}
|
||||
|
||||
void exportToString(const FilledCrossword &cross, const bool prn_ans,
|
||||
wxString &str_out, wxChar space = wxT('-')){
|
||||
void exportToString(const FilledCrossword &cross, wxString &str_out, wxChar space = wxT('-')){
|
||||
const wxString LINE_END = wxTextFile::GetEOL();
|
||||
|
||||
FilledCrossword t_cross(cross);
|
||||
if ( prn_ans && (t_cross.ans.size() != 0) ) {
|
||||
if ( t_cross.ans.size() != 0 ) {
|
||||
fillCross(t_cross);
|
||||
}
|
||||
wxLogDebug(wxT("3"));
|
||||
for (size_t i = 0; i < t_cross.grid.at(0).size(); ++i){
|
||||
wxString cur_line;
|
||||
for (size_t j = 0; j < t_cross.grid.size(); ++j){
|
||||
@@ -33,20 +33,37 @@ void exportToString(const FilledCrossword &cross, const bool prn_ans,
|
||||
else
|
||||
cur_line += t_cross.grid.at(j).at(i);
|
||||
}
|
||||
cur_line += wxTextFile::GetEOL();
|
||||
cur_line += LINE_END;
|
||||
|
||||
str_out += cur_line;
|
||||
}
|
||||
if ( cross.ques.size() != 0 ) { // == print questions
|
||||
str_out += _("Vertical words:") + LINE_END;
|
||||
|
||||
for (size_t i = 0; i < cross.words.size(); ++i){
|
||||
if (cross.words.at(i).direct == false)
|
||||
str_out += wxString::Format(wxT("%d. "), cross.words.at(i).ind)
|
||||
+ cross.ques.at(i) + LINE_END;
|
||||
}
|
||||
|
||||
str_out += _("Horisontal words:") + LINE_END;
|
||||
|
||||
for (size_t i = 0; i < cross.words.size(); ++i){
|
||||
if (cross.words.at(i).direct == true)
|
||||
str_out += wxString::Format(wxT("%d. "), cross.words.at(i).ind)
|
||||
+ cross.ques.at(i) + LINE_END;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool exportToFile(const FilledCrossword &cross, const bool prn_ans, const wxString path){
|
||||
bool exportToFile(const FilledCrossword &cross, const wxString path){
|
||||
wxTextFile f(path);
|
||||
if ( f.Exists() )
|
||||
return false;
|
||||
f.Create();
|
||||
f.Open(path);
|
||||
wxString cont;
|
||||
exportToString(cross, prn_ans, cont);
|
||||
exportToString(cross, cont);
|
||||
f.AddLine(cont);
|
||||
f.Write();
|
||||
f.Close();
|
||||
|
||||
@@ -123,6 +123,10 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) {
|
||||
std::vector<WordInfo> winfos;
|
||||
generateWordInfo(_grid, winfos);
|
||||
|
||||
_ques.clear();
|
||||
for (size_t i = 0; i < words_out.size(); ++i)
|
||||
_ques.push_back(_dict[words_out.at(i)]);
|
||||
|
||||
tOutput->Clear();
|
||||
|
||||
tOutput->AppendText(_("Vertical words:\n"));
|
||||
@@ -130,7 +134,7 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) {
|
||||
for (size_t i = 0; i < words_out.size(); ++i){
|
||||
if (winfos.at(i).direct == false)
|
||||
tOutput->AppendText(wxString::Format(wxT("%d. "), winfos.at(i).ind)
|
||||
+ _dict[words_out.at(i)] +wxT("\n"));
|
||||
+ _ques.at(i) + wxT("\n"));
|
||||
}
|
||||
|
||||
tOutput->AppendText(_("Horisontal words:\n"));
|
||||
@@ -138,7 +142,7 @@ void MainFrame::onGenerateClick(wxCommandEvent &event) {
|
||||
for (size_t i = 0; i < words_out.size(); ++i){
|
||||
if (winfos.at(i).direct == true)
|
||||
tOutput->AppendText(wxString::Format(wxT("%d. "), winfos.at(i).ind)
|
||||
+ _dict[words_out.at(i)]+wxT("\n"));
|
||||
+ _ques.at(i) + wxT("\n"));
|
||||
}
|
||||
if (winfos.size() == 0)
|
||||
throw 42;
|
||||
@@ -163,12 +167,13 @@ void MainFrame::onExportClick(wxCommandEvent& event) {
|
||||
FilledCrossword t_cross;
|
||||
t_cross.grid = _grid;
|
||||
t_cross.ans = _ans;
|
||||
t_cross.ques = _ques;
|
||||
generateWordInfo(_grid, t_cross.words);
|
||||
if ( !exportToFile(t_cross, true, dlgSave.GetPath()) ){
|
||||
if ( !exportToFile(t_cross, dlgSave.GetPath()) ){
|
||||
wxLogError(wxT("Cannot save current contents in file '%s'."), dlgSave.GetPath().GetData());
|
||||
return;
|
||||
}
|
||||
wxLogDebug(wxT("Exporting to ") + dlgSave.GetPath() + wxT("is complete"));
|
||||
wxLogDebug(wxT("Exporting to ") + dlgSave.GetPath() + wxT(" is complete"));
|
||||
}
|
||||
|
||||
class MyApp: public wxApp {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
class MainFrame: public VMainFrame {
|
||||
protected:
|
||||
std::vector<wxString> _ans;
|
||||
std::vector<wxString> _ques;
|
||||
DictType _dict;
|
||||
bool _isDictLoaded;
|
||||
AllWordsType _allWords;
|
||||
|
||||
Reference in New Issue
Block a user