Added: #1307 Added extraction from primitives

--HG--
branch : gsoc2011-translationovqt
This commit is contained in:
cemycc 2011-07-06 04:56:58 +03:00
parent a4f222c651
commit d54daf3ef2
6 changed files with 292 additions and 65 deletions

View file

@ -25,6 +25,7 @@
#include <QtGui/QCloseEvent> #include <QtGui/QCloseEvent>
#include "extract_bot_names.h" #include "extract_bot_names.h"
#include "translation_manager_constants.h"
using namespace std; using namespace std;
@ -106,7 +107,6 @@ void CEditorWorksheet::open(QString filename)
void CEditorWorksheet::activateWindow() void CEditorWorksheet::activateWindow()
{ {
showMaximized(); showMaximized();
} }
void CEditorWorksheet::save() void CEditorWorksheet::save()
@ -209,7 +209,6 @@ void CEditorWorksheet::insertRow()
for(int j = 0; j < table_editor->columnCount(); j++) for(int j = 0; j < table_editor->columnCount(); j++)
{ {
QTableWidgetItem* item = new QTableWidgetItem(); QTableWidgetItem* item = new QTableWidgetItem();
//item->setText(QString(" "));
table_editor->setItem(last_row, j, item); table_editor->setItem(last_row, j, item);
} }
} }
@ -236,7 +235,8 @@ void CEditorWorksheet::deleteRow()
void CEditorWorksheet::worksheetEditorChanged(int row, int column) void CEditorWorksheet::worksheetEditorChanged(int row, int column)
{ {
if(!isWindowModified())
setWindowModified(true);
} }
void CEditorWorksheet::extractBotNames(list<string> filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig) void CEditorWorksheet::extractBotNames(list<string> filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig)
@ -378,9 +378,73 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis
if(modified) if(modified)
{ {
setWindowModified(true); setWindowModified(true);
table_editor->scrollToBottom();
} }
} }
void CEditorWorksheet::mergeWorksheetFile(QString filename)
{
STRING_MANAGER::TWorksheet wk_file;
if(loadExcelSheet(filename.toStdString(), wk_file, true) == true)
{
bool hasHashValue = false;
if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE"))
{
table_editor->setColumnCount(wk_file.ColCount - 1);
hasHashValue = true;
} else {
table_editor->setColumnCount(wk_file.ColCount);
}
table_editor->setRowCount(wk_file.size() - 1);
// read columns name
for(unsigned int i = 0; i < wk_file.ColCount; i++)
{
if(hasHashValue && i == 0)
{
// we don't show the column with hash value
} else {
QTableWidgetItem *col = new QTableWidgetItem();
ucstring col_name = wk_file.getData(0, i);
col->setText(tr(col_name.toString().c_str()));
if(hasHashValue)
{
table_editor->setHorizontalHeaderItem(i - 1, col);
} else {
table_editor->setHorizontalHeaderItem(i, col);
}
}
}
// read rows
for(unsigned int i = 1; i < wk_file.size(); i++)
{
for(unsigned int j = 0; j < wk_file.ColCount; j++)
{
if(hasHashValue && j == 0)
{
// we don't show the column with hash value
} else {
QTableWidgetItem *row = new QTableWidgetItem();
ucstring row_value = wk_file.getData(i, j);
row->setText(tr(row_value.toString().c_str()));
if(hasHashValue)
{
table_editor->setItem(i - 1, j - 1, row);
} else {
table_editor->setItem(i - 1, j, row);
}
}
}
}
} else {
QErrorMessage error;
error.showMessage("This file is not a worksheet file.");
error.exec();
}
}
void CEditorWorksheet::setCurrentFile(QString filename) void CEditorWorksheet::setCurrentFile(QString filename)
{ {
QFileInfo *file = new QFileInfo(filename); QFileInfo *file = new QFileInfo(filename);
@ -392,9 +456,35 @@ void CEditorWorksheet::setCurrentFile(QString filename)
void CEditorWorksheet::closeEvent(QCloseEvent *event) void CEditorWorksheet::closeEvent(QCloseEvent *event)
{ {
close(); if(isWindowModified())
{
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Save:
save();
event->accept(); event->accept();
close();
break;
case QMessageBox::Discard:
event->accept();
close();
break;
case QMessageBox::Cancel:
event->ignore();
break;
default:
break;
}
} else {
event->accept();
close();
}
} }
bool CEditorWorksheet::isBotNamesTable() bool CEditorWorksheet::isBotNamesTable()
@ -410,6 +500,35 @@ bool CEditorWorksheet::isBotNamesTable()
return status; return status;
} }
bool CEditorWorksheet::isSheetTable(QString type)
{
QString column_name;
if(type.toAscii() == Constants::WK_ITEM)
{
column_name = "item ID";
} else if(type.toAscii() == Constants::WK_CREATURE) {
column_name = "creature ID";
} else if(type.toAscii() == Constants::WK_SBRICK) {
column_name = "sbrick ID";
} else if(type.toAscii() == Constants::WK_SPHRASE) {
column_name = "sphrase ID";
} else if(type.toAscii() == Constants::WK_PLACE) {
column_name = "placeId";
} else if(type.toAscii() == Constants::WK_CONTINENT) {
column_name = "placeId";
} else if(type.toAscii() == Constants::WK_STABLE) {
column_name = "placeId";
}
bool status = true;
if(table_editor->horizontalHeaderItem(0)->text() != column_name
|| table_editor->horizontalHeaderItem(1)->text() != "name")
{
status = false;
}
return status;
}
} }

View file

@ -49,9 +49,11 @@ public:
void save(); void save();
void saveAs(QString filename); void saveAs(QString filename);
void activateWindow(); void activateWindow();
void mergeWorksheetFile(QString filename);
void extractBotNames(list<string> filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig); void extractBotNames(list<string> filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig);
void extractWords(QString filename, QString columnId, IWordListBuilder &wordListBuilder); void extractWords(QString filename, QString columnId, IWordListBuilder &wordListBuilder);
bool isBotNamesTable(); bool isBotNamesTable();
bool isSheetTable(QString type);
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
private Q_SLOTS: private Q_SLOTS:
void worksheetEditorChanged(int,int); void worksheetEditorChanged(int,int);

View file

@ -108,12 +108,12 @@ bool CRegionPrimWordListBuilder::buildWordList(std::vector<string> &allWords, st
// ok, read the file // ok, read the file
CPrimitives PrimDoc; CPrimitives PrimDoc;
CPrimitiveContext::instance().CurrentPrimitive = &PrimDoc; CPrimitiveContext::instance().CurrentPrimitive = &PrimDoc;
// if (!loadXmlPrimitiveFile(PrimDoc, allFiles[i], LigoConfig)) if (!loadXmlPrimitiveFile(PrimDoc, allFiles[i], LigoConfig))
// { {
// nlwarning("Error: cannot open file '%s'. '%s' Aborted", allFiles[i].c_str(), workSheetFileName.c_str()); nlwarning("Error: cannot open file '%s'. '%s' Aborted", allFiles[i].c_str(), workSheetFileName.c_str());
// CPrimitiveContext::instance().CurrentPrimitive = NULL; CPrimitiveContext::instance().CurrentPrimitive = NULL;
// return false; return false;
// } }
CPrimitiveContext::instance().CurrentPrimitive = NULL; CPrimitiveContext::instance().CurrentPrimitive = NULL;
// For all primitives of interest // For all primitives of interest
@ -141,6 +141,7 @@ bool CRegionPrimWordListBuilder::buildWordList(std::vector<string> &allWords, st
// avoid duplicate // avoid duplicate
if(allWordSet.insert(primName).second) if(allWordSet.insert(primName).second)
{ {
nlinfo(primName.c_str()); //TODO: delete
allWords.push_back(primName); allWords.push_back(primName);
} }
} }

View file

@ -60,6 +60,7 @@ struct CRegionPrimWordListBuilder : public IWordListBuilder
{ {
string PrimPath; string PrimPath;
vector<string> PrimFilter; vector<string> PrimFilter;
NLLIGO::CLigoConfig LigoConfig;
virtual bool buildWordList(std::vector<string> &allWords, string workSheetFileName); virtual bool buildWordList(std::vector<string> &allWords, string workSheetFileName);
}; };

View file

@ -16,6 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "translation_manager_main_window.h" #include "translation_manager_main_window.h"
#include "translation_manager_constants.h"
#include "editor_worksheet.h" #include "editor_worksheet.h"
// Project system includes // Project system includes
@ -87,6 +88,8 @@ void CMainWindow::createToolbar()
QAction *extractBotNamesAct = wordsExtractionMenu->addAction("&Extract bot names..."); QAction *extractBotNamesAct = wordsExtractionMenu->addAction("&Extract bot names...");
extractBotNamesAct->setStatusTip(tr("Extract bot names from primitives.")); extractBotNamesAct->setStatusTip(tr("Extract bot names from primitives."));
connect(extractBotNamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); connect(extractBotNamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames()));
// Words extraction
// -----------------------------
// signal mapper for extraction words // signal mapper for extraction words
QSignalMapper *wordsExtractionMapper = new QSignalMapper(this); QSignalMapper *wordsExtractionMapper = new QSignalMapper(this);
connect(wordsExtractionMapper, SIGNAL(mapped(QString)), this, SLOT(extractWords(QString))); connect(wordsExtractionMapper, SIGNAL(mapped(QString)), this, SLOT(extractWords(QString)));
@ -94,23 +97,37 @@ void CMainWindow::createToolbar()
QAction *extractItemWordsAct = wordsExtractionMenu->addAction("&Extract item words..."); QAction *extractItemWordsAct = wordsExtractionMenu->addAction("&Extract item words...");
extractItemWordsAct->setStatusTip(tr("Extract item words")); extractItemWordsAct->setStatusTip(tr("Extract item words"));
connect(extractItemWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); connect(extractItemWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map()));
wordsExtractionMapper->setMapping(extractItemWordsAct, "item"); wordsExtractionMapper->setMapping(extractItemWordsAct, tr(Constants::WK_ITEM));
// extract creature words // extract creature words
QAction *extractCreatureWordsAct = wordsExtractionMenu->addAction("&Extract creature words..."); QAction *extractCreatureWordsAct = wordsExtractionMenu->addAction("&Extract creature words...");
extractCreatureWordsAct->setStatusTip(tr("Extract creature words")); extractCreatureWordsAct->setStatusTip(tr("Extract creature words"));
connect(extractCreatureWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); connect(extractCreatureWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map()));
wordsExtractionMapper->setMapping(extractCreatureWordsAct, "creature"); wordsExtractionMapper->setMapping(extractCreatureWordsAct, tr(Constants::WK_CREATURE));
// extract sbrick words // extract sbrick words
QAction *extractSbrickWordsAct = wordsExtractionMenu->addAction("&Extract sbrick words..."); QAction *extractSbrickWordsAct = wordsExtractionMenu->addAction("&Extract sbrick words...");
extractSbrickWordsAct->setStatusTip(tr("Extract sbrick words")); extractSbrickWordsAct->setStatusTip(tr("Extract sbrick words"));
connect(extractSbrickWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); connect(extractSbrickWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map()));
wordsExtractionMapper->setMapping(extractSbrickWordsAct, "sbrick"); wordsExtractionMapper->setMapping(extractSbrickWordsAct, tr(Constants::WK_SBRICK));
// extract sphrase words // extract sphrase words
QAction *extractSphraseWordsAct = wordsExtractionMenu->addAction("&Extract sphrase words..."); QAction *extractSphraseWordsAct = wordsExtractionMenu->addAction("&Extract sphrase words...");
extractSphraseWordsAct->setStatusTip(tr("Extract sphrase words")); extractSphraseWordsAct->setStatusTip(tr("Extract sphrase words"));
connect(extractSphraseWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); connect(extractSphraseWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map()));
wordsExtractionMapper->setMapping(extractSphraseWordsAct, "sphrase"); wordsExtractionMapper->setMapping(extractSphraseWordsAct, tr(Constants::WK_SPHRASE));
// extract place and region names
QAction *extractPlaceNamesAct = wordsExtractionMenu->addAction("&Extract place and region names...");
extractPlaceNamesAct->setStatusTip(tr("Extract place and region names"));
connect(extractPlaceNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map()));
wordsExtractionMapper->setMapping(extractPlaceNamesAct, tr(Constants::WK_PLACE));
// extract continent names
QAction *extractContinentNamesAct = wordsExtractionMenu->addAction("&Extract continent names...");
extractContinentNamesAct->setStatusTip(tr("Extract continent names"));
connect(extractContinentNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map()));
wordsExtractionMapper->setMapping(extractContinentNamesAct, tr(Constants::WK_CONTINENT));
// extract stable names
QAction *extractStableNamesAct = wordsExtractionMenu->addAction("&Extract stable names...");
extractStableNamesAct->setStatusTip(tr("Extract stable names"));
connect(extractStableNamesAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map()));
wordsExtractionMapper->setMapping(extractStableNamesAct, tr(Constants::WK_STABLE));
// Windows menu // Windows menu
windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar);
windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL));
@ -215,11 +232,7 @@ void CMainWindow::openWorkFile(QString file)
} }
} else { } else {
QErrorMessage error; QErrorMessage error;
QString text; error.showMessage(QString("The %1 file don't exists.").arg(file_path->fileName()));
text.append("The ");
text.append(file_path->fileName());
text.append(" file don't exists.");
error.showMessage(text);
error.exec(); error.exec();
} }
@ -227,12 +240,15 @@ void CMainWindow::openWorkFile(QString file)
void CMainWindow::save() void CMainWindow::save()
{ {
if(_ui.mdiArea->subWindowList().size() > 0)
{
CEditor* current_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow()); CEditor* current_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow());
if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
{ {
current_window->save(); current_window->save();
} }
}
} }
void CMainWindow::saveAs() void CMainWindow::saveAs()
@ -275,35 +291,111 @@ void CMainWindow::initializeSettings(bool georges = false)
} }
} }
void CMainWindow::extractWords(QString type) void CMainWindow::extractWords(QString typeq)
{ {
CEditor* editor_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow()); if(verifySettings() == true)
CEditorWorksheet* current_window = qobject_cast<CEditorWorksheet*>(editor_window);
// initializeSettings(false);
CSheetWordListBuilder builder;
QString column_name;
if(type == "item")
{ {
column_name = "item ID"; CEditorWorksheet* current_window;
builder.SheetExt = "sitem"; if(_ui.mdiArea->subWindowList().size() > 0)
builder.SheetPath = level_design_path + "/game_element/sitem"; {
} else if(type == "creature") { CEditor* editor_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow());
column_name = "creature ID"; if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
builder.SheetExt = "creature"; {
builder.SheetPath = level_design_path + "/Game_elem/Creature/fauna"; current_window = qobject_cast<CEditorWorksheet*>(editor_window);
} else if(type == "sbrick") { QString file_path = current_window->subWindowFilePath();
column_name = "sbrick ID"; if(!current_window->isSheetTable(typeq))
builder.SheetExt = "sbrick"; {
builder.SheetPath = level_design_path + "/game_element/sbrick"; list<CEditor*> subWindows = convertSubWindowList(_ui.mdiArea->subWindowList());
} else if(type == "sphrase") { list<CEditor*>::iterator it = subWindows.begin();
column_name = "sphrase ID"; bool finded = false;
builder.SheetExt = "sphrase";
builder.SheetPath = level_design_path + "/game_element/sphrase"; for(; it != subWindows.end(); ++it)
{
current_window = qobject_cast<CEditorWorksheet*>((*it));
file_path = current_window->subWindowFilePath();
if(current_window->isSheetTable(typeq))
{
finded = true;
current_window->activateWindow();
} }
current_window->extractWords(current_window->windowFilePath(), column_name, builder); }
if(!finded)
{
openWorkFile(typeq);
if(_ui.mdiArea->subWindowList().size() > 0)
{
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow());
QString file_path = current_window->windowFilePath();
} else {
return;
}
}
}
}
} else {
openWorkFile(typeq);
if(_ui.mdiArea->subWindowList().size() > 0)
{
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow());
QString file_path = current_window->windowFilePath();
} else {
return;
}
}
QString column_name;
// Sheet extraction
CSheetWordListBuilder builderS;
// Primitives extraction
CRegionPrimWordListBuilder builderP;
bool isSheet = false;
if(typeq.toAscii() == Constants::WK_ITEM) {
column_name = "item ID";
builderS.SheetExt = "sitem";
builderS.SheetPath = level_design_path + "/game_element/sitem";
isSheet = true;
} else if(typeq.toAscii() == Constants::WK_CREATURE) {
column_name = "creature ID";
builderS.SheetExt = "creature";
builderS.SheetPath = level_design_path + "/Game_elem/Creature/fauna";
isSheet = true;
} else if(typeq.toAscii() == Constants::WK_SBRICK) {
column_name = "sbrick ID";
builderS.SheetExt = "sbrick";
builderS.SheetPath = level_design_path + "/game_element/sbrick";
isSheet = true;
} else if(typeq.toAscii() == Constants::WK_SPHRASE) {
column_name = "sphrase ID";
builderS.SheetExt = "sphrase";
builderS.SheetPath = level_design_path + "/game_element/sphrase";
isSheet = true;
} else if(typeq.toAscii() == Constants::WK_PLACE) {
column_name = "placeId";
builderP.PrimPath = primitives_path;
builderP.PrimFilter.push_back("region_*.primitive");
builderP.PrimFilter.push_back("indoors_*.primitive");
isSheet = false;
} else if(typeq.toAscii() == Constants::WK_CONTINENT) {
column_name = "placeId";
builderP.PrimPath = primitives_path;
builderP.PrimFilter.push_back("continent_*.primitive");
isSheet = false;
} else if(typeq.toAscii() == Constants::WK_STABLE) {
column_name = "placeId";
builderP.PrimPath = primitives_path;
builderP.PrimFilter.push_back("stable_*.primitive");
isSheet = false;
}
if(isSheet)
{
current_window->extractWords(current_window->windowFilePath(), column_name, builderS);
} else {
initializeSettings(false);
current_window->extractWords(current_window->windowFilePath(), column_name, builderP);
}
}
} }
void CMainWindow::extractBotNames() void CMainWindow::extractBotNames()
@ -336,16 +428,26 @@ void CMainWindow::extractBotNames()
} }
if(!finded) if(!finded)
{ {
openWorkFile("bot_names_wk.txt"); openWorkFile(tr(Constants::WK_BOTNAMES));
if(_ui.mdiArea->subWindowList().size() > 0)
{
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow()); current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow());
file_path = current_window->windowFilePath(); QString file_path = current_window->windowFilePath();
} else {
return;
}
} }
} }
} }
} else { } else {
openWorkFile("bot_names_wk.txt"); openWorkFile(tr(Constants::WK_BOTNAMES));
if(_ui.mdiArea->subWindowList().size() > 0)
{
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow()); current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow());
QString file_path = current_window->windowFilePath(); QString file_path = current_window->windowFilePath();
} else {
return;
}
} }
initializeSettings(true); initializeSettings(true);
current_window->extractBotNames(filters, level_design_path, ligoConfig); current_window->extractBotNames(filters, level_design_path, ligoConfig);
@ -363,6 +465,7 @@ void CMainWindow::readSettings()
settings->endGroup(); settings->endGroup();
settings->beginGroup(Core::Constants::DATA_PATH_SECTION); settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString().toStdString(); level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString().toStdString();
primitives_path = QString(Core::Constants::PRIMITIVES_PATH).toStdString();
settings->endGroup(); settings->endGroup();
} }

View file

@ -73,12 +73,13 @@ private:
list<string> filters; list<string> filters;
list<string> languages; list<string> languages;
string level_design_path; string level_design_path;
string primitives_path;
string translation_path; string translation_path;
string work_path; string work_path;
NLLIGO::CLigoConfig ligoConfig; NLLIGO::CLigoConfig ligoConfig;
private Q_SLOTS: private Q_SLOTS:
void extractBotNames(); void extractBotNames();
void extractWords(QString); void extractWords(QString typeq);
void open(); void open();
void save(); void save();
void saveAs(); void saveAs();