From d54daf3ef254232a66f56f18fb11f5e7008337c5 Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 6 Jul 2011 04:56:58 +0300 Subject: [PATCH] Added: #1307 Added extraction from primitives --HG-- branch : gsoc2011-translationovqt --- .../translation_manager/editor_worksheet.cpp | 135 +++++++++++- .../translation_manager/editor_worksheet.h | 2 + .../extract_new_sheet_names.cpp | 13 +- .../extract_new_sheet_names.h | 1 + .../translation_manager_main_window.cpp | 203 +++++++++++++----- .../translation_manager_main_window.h | 3 +- 6 files changed, 292 insertions(+), 65 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp index d19d28723..83c67e7a6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -25,6 +25,7 @@ #include #include "extract_bot_names.h" +#include "translation_manager_constants.h" using namespace std; @@ -38,7 +39,7 @@ void CEditorWorksheet::open(QString filename) if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) { bool hasHashValue = false; - table_editor = new QTableWidget(); + table_editor = new QTableWidget(); if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) { table_editor->setColumnCount(wk_file.ColCount - 1); @@ -105,8 +106,7 @@ void CEditorWorksheet::open(QString filename) void CEditorWorksheet::activateWindow() { - showMaximized(); - + showMaximized(); } void CEditorWorksheet::save() @@ -209,7 +209,6 @@ void CEditorWorksheet::insertRow() for(int j = 0; j < table_editor->columnCount(); j++) { QTableWidgetItem* item = new QTableWidgetItem(); - //item->setText(QString(" ")); table_editor->setItem(last_row, j, item); } } @@ -236,7 +235,8 @@ void CEditorWorksheet::deleteRow() void CEditorWorksheet::worksheetEditorChanged(int row, int column) { - + if(!isWindowModified()) + setWindowModified(true); } void CEditorWorksheet::extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig) @@ -378,9 +378,73 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis if(modified) { 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) { QFileInfo *file = new QFileInfo(filename); @@ -392,9 +456,35 @@ void CEditorWorksheet::setCurrentFile(QString filename) void CEditorWorksheet::closeEvent(QCloseEvent *event) { - close(); - event->accept(); - + 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(); + close(); + break; + case QMessageBox::Discard: + event->accept(); + close(); + break; + case QMessageBox::Cancel: + event->ignore(); + break; + default: + break; + } + } else { + event->accept(); + close(); + } } bool CEditorWorksheet::isBotNamesTable() @@ -410,6 +500,35 @@ bool CEditorWorksheet::isBotNamesTable() 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; +} + } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h index 497e23913..39f4aafa1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h @@ -49,9 +49,11 @@ public: void save(); void saveAs(QString filename); void activateWindow(); + void mergeWorksheetFile(QString filename); void extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig); void extractWords(QString filename, QString columnId, IWordListBuilder &wordListBuilder); bool isBotNamesTable(); + bool isSheetTable(QString type); void closeEvent(QCloseEvent *event); private Q_SLOTS: void worksheetEditorChanged(int,int); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp index e881177bb..e0626bc6b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.cpp @@ -108,12 +108,12 @@ bool CRegionPrimWordListBuilder::buildWordList(std::vector &allWords, st // ok, read the file CPrimitives PrimDoc; CPrimitiveContext::instance().CurrentPrimitive = &PrimDoc; - // if (!loadXmlPrimitiveFile(PrimDoc, allFiles[i], LigoConfig)) - // { - // nlwarning("Error: cannot open file '%s'. '%s' Aborted", allFiles[i].c_str(), workSheetFileName.c_str()); - // CPrimitiveContext::instance().CurrentPrimitive = NULL; - // return false; - // } + if (!loadXmlPrimitiveFile(PrimDoc, allFiles[i], LigoConfig)) + { + nlwarning("Error: cannot open file '%s'. '%s' Aborted", allFiles[i].c_str(), workSheetFileName.c_str()); + CPrimitiveContext::instance().CurrentPrimitive = NULL; + return false; + } CPrimitiveContext::instance().CurrentPrimitive = NULL; // For all primitives of interest @@ -141,6 +141,7 @@ bool CRegionPrimWordListBuilder::buildWordList(std::vector &allWords, st // avoid duplicate if(allWordSet.insert(primName).second) { + nlinfo(primName.c_str()); //TODO: delete allWords.push_back(primName); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h index 007018a08..8c9151e2e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/extract_new_sheet_names.h @@ -60,6 +60,7 @@ struct CRegionPrimWordListBuilder : public IWordListBuilder { string PrimPath; vector PrimFilter; + NLLIGO::CLigoConfig LigoConfig; virtual bool buildWordList(std::vector &allWords, string workSheetFileName); }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp index 95a5fe95f..daff3923d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp @@ -16,6 +16,7 @@ // along with this program. If not, see . #include "translation_manager_main_window.h" +#include "translation_manager_constants.h" #include "editor_worksheet.h" // Project system includes @@ -86,7 +87,9 @@ void CMainWindow::createToolbar() // extract bot names QAction *extractBotNamesAct = wordsExtractionMenu->addAction("&Extract bot names..."); 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 QSignalMapper *wordsExtractionMapper = new QSignalMapper(this); connect(wordsExtractionMapper, SIGNAL(mapped(QString)), this, SLOT(extractWords(QString))); @@ -94,23 +97,37 @@ void CMainWindow::createToolbar() QAction *extractItemWordsAct = wordsExtractionMenu->addAction("&Extract item words..."); extractItemWordsAct->setStatusTip(tr("Extract item words")); connect(extractItemWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); - wordsExtractionMapper->setMapping(extractItemWordsAct, "item"); + wordsExtractionMapper->setMapping(extractItemWordsAct, tr(Constants::WK_ITEM)); // extract creature words QAction *extractCreatureWordsAct = wordsExtractionMenu->addAction("&Extract creature words..."); extractCreatureWordsAct->setStatusTip(tr("Extract creature words")); connect(extractCreatureWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); - wordsExtractionMapper->setMapping(extractCreatureWordsAct, "creature"); + wordsExtractionMapper->setMapping(extractCreatureWordsAct, tr(Constants::WK_CREATURE)); // extract sbrick words QAction *extractSbrickWordsAct = wordsExtractionMenu->addAction("&Extract sbrick words..."); extractSbrickWordsAct->setStatusTip(tr("Extract sbrick words")); connect(extractSbrickWordsAct, SIGNAL(triggered()), wordsExtractionMapper, SLOT(map())); - wordsExtractionMapper->setMapping(extractSbrickWordsAct, "sbrick"); + wordsExtractionMapper->setMapping(extractSbrickWordsAct, tr(Constants::WK_SBRICK)); // extract sphrase words QAction *extractSphraseWordsAct = wordsExtractionMenu->addAction("&Extract sphrase words..."); extractSphraseWordsAct->setStatusTip(tr("Extract sphrase words")); 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 windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); @@ -144,7 +161,7 @@ void CMainWindow::setActiveSubWindow(QWidget* window) void CMainWindow::activeSubWindowChanged() { - + } void CMainWindow::updateWindowsList() @@ -215,11 +232,7 @@ void CMainWindow::openWorkFile(QString file) } } else { QErrorMessage error; - QString text; - text.append("The "); - text.append(file_path->fileName()); - text.append(" file don't exists."); - error.showMessage(text); + error.showMessage(QString("The %1 file don't exists.").arg(file_path->fileName())); error.exec(); } @@ -227,11 +240,14 @@ void CMainWindow::openWorkFile(QString file) void CMainWindow::save() { - CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - - if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + if(_ui.mdiArea->subWindowList().size() > 0) { - current_window->save(); + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + + if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + current_window->save(); + } } } @@ -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(_ui.mdiArea->currentSubWindow()); - CEditorWorksheet* current_window = qobject_cast(editor_window); - - // initializeSettings(false); - - CSheetWordListBuilder builder; - QString column_name; - - if(type == "item") - { - column_name = "item ID"; - builder.SheetExt = "sitem"; - builder.SheetPath = level_design_path + "/game_element/sitem"; - } else if(type == "creature") { - column_name = "creature ID"; - builder.SheetExt = "creature"; - builder.SheetPath = level_design_path + "/Game_elem/Creature/fauna"; - } else if(type == "sbrick") { - column_name = "sbrick ID"; - builder.SheetExt = "sbrick"; - builder.SheetPath = level_design_path + "/game_element/sbrick"; - } else if(type == "sphrase") { - column_name = "sphrase ID"; - builder.SheetExt = "sphrase"; - builder.SheetPath = level_design_path + "/game_element/sphrase"; - } - current_window->extractWords(current_window->windowFilePath(), column_name, builder); + if(verifySettings() == true) + { + CEditorWorksheet* current_window; + if(_ui.mdiArea->subWindowList().size() > 0) + { + CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + current_window = qobject_cast(editor_window); + QString file_path = current_window->subWindowFilePath(); + if(!current_window->isSheetTable(typeq)) + { + list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); + list::iterator it = subWindows.begin(); + bool finded = false; + + for(; it != subWindows.end(); ++it) + { + current_window = qobject_cast((*it)); + file_path = current_window->subWindowFilePath(); + if(current_window->isSheetTable(typeq)) + { + finded = true; + current_window->activateWindow(); + } + } + if(!finded) + { + openWorkFile(typeq); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_window->windowFilePath(); + } else { + return; + } + } + } + } + } else { + openWorkFile(typeq); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_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() @@ -336,16 +428,26 @@ void CMainWindow::extractBotNames() } if(!finded) { - openWorkFile("bot_names_wk.txt"); - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - file_path = current_window->windowFilePath(); + openWorkFile(tr(Constants::WK_BOTNAMES)); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_window->windowFilePath(); + } else { + return; + } } } } } else { - openWorkFile("bot_names_wk.txt"); - current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); - QString file_path = current_window->windowFilePath(); + openWorkFile(tr(Constants::WK_BOTNAMES)); + if(_ui.mdiArea->subWindowList().size() > 0) + { + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + QString file_path = current_window->windowFilePath(); + } else { + return; + } } initializeSettings(true); current_window->extractBotNames(filters, level_design_path, ligoConfig); @@ -363,6 +465,7 @@ void CMainWindow::readSettings() settings->endGroup(); settings->beginGroup(Core::Constants::DATA_PATH_SECTION); level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString().toStdString(); + primitives_path = QString(Core::Constants::PRIMITIVES_PATH).toStdString(); settings->endGroup(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h index b0d59fe29..2ee796bd0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h @@ -73,12 +73,13 @@ private: list filters; list languages; string level_design_path; + string primitives_path; string translation_path; string work_path; NLLIGO::CLigoConfig ligoConfig; private Q_SLOTS: void extractBotNames(); - void extractWords(QString); + void extractWords(QString typeq); void open(); void save(); void saveAs();