diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp
index 78cc2f3cd..a19f4550e 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_dialog.cpp
@@ -40,11 +40,12 @@ CBnpDirTreeDialog::CBnpDirTreeDialog(QString bnpPath, QWidget *parent)
// Bnp file: opened and displayed
// all other files: added to the currently opened bnp file
QStringList filter;
- //filter << tr("*.bnp");
+ filter << tr("*.bnp");
// Setup the directory tree model
m_dirModel= new BNPFileSystemModel();
m_proxyModel = new BNPSortProxyModel();
+ m_ui.dirTree->setSortingEnabled(true);
m_dirModel->setRootPath(m_DataPath);
m_dirModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::AllEntries);
m_dirModel->setNameFilters(filter);
@@ -55,7 +56,6 @@ CBnpDirTreeDialog::CBnpDirTreeDialog(QString bnpPath, QWidget *parent)
m_ui.dirTree->setModel(m_proxyModel);
m_ui.dirTree->setRootIndex( m_proxyModel->mapFromSource (m_dirModel->index(m_DataPath) ) );
- m_ui.dirTree->setSortingEnabled(true);
// Trigger if one filename is activated
// In future drag&drop should be also possible
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_form.ui
index 751c4f055..44b39dc54 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_form.ui
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_dirtree_form.ui
@@ -44,6 +44,9 @@
0
+
+ true
+
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.cpp
index d9b2f45c1..e00f777ba 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.cpp
@@ -62,6 +62,15 @@ void BNPFileHandle::releaseInstance()
}
}
// ***************************************************************************
+void BNPFileHandle::createFile(string filePath)
+{
+ // Only set the filepath. Header will be created after files have been added
+ m_openedBNPFile = filePath;
+ m_packedFiles.clear();
+
+ nlinfo("Created file %s.", filePath.c_str() );
+}
+// ***************************************************************************
bool BNPFileHandle::unpack(const string &dirName, const vector& fileList)
{
CIFile bnp;
@@ -231,8 +240,10 @@ void BNPFileHandle::addFiles( const vector &filePathes)
}
writeHeader(m_openedBNPFile + ".tmp", OffsetFromBegining);
-
- CFile::deleteFile( m_openedBNPFile );
+
+ // Delete any previous existing file
+ if (CFile::fileExists( m_openedBNPFile ))
+ CFile::deleteFile( m_openedBNPFile );
string src = m_openedBNPFile + ".tmp";
CFile::moveFile( m_openedBNPFile.c_str(), src.c_str() );
}
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.h
index e03d0e664..7527b5dbd 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_file.h
@@ -88,6 +88,12 @@ public:
*/
void fileNames( std::vector& fileNames );
+ /**
+ * Create a new bnp file
+ * \param string file path
+ */
+ void createFile( std::string filePath );
+
/**
* Add files to the current aktive bnp file
* \param vector of file pathes to add
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.cpp
index 418d7fa04..261175902 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.cpp
@@ -20,10 +20,6 @@
// Qt includes
#include
-#include
-#include
-#include
-#include
// NeL includes
#include
@@ -38,7 +34,6 @@ BnpFileListDialog::BnpFileListDialog(QString bnpPath, QWidget *parent)
m_DataPath(bnpPath)
{
m_ui.setupUi(this);
- setAcceptDrops(true);
}
// ***************************************************************************
BnpFileListDialog::~BnpFileListDialog()
@@ -111,6 +106,14 @@ bool BnpFileListDialog::loadTable(const QString filePath)
return true;
}
// ***************************************************************************
+void BnpFileListDialog::clearTable()
+{
+ // create emtpy table
+ setupTable(0);
+
+ setWindowTitle("BNP File List");
+}
+// ***************************************************************************
void BnpFileListDialog::getSelections(TSelectionList& SelectionList)
{
QModelIndex index;
@@ -125,21 +128,5 @@ void BnpFileListDialog::getSelections(TSelectionList& SelectionList)
SelectionList.push_back( filename.toStdString() );
}
}
-// ***************************************************************************
-void BnpFileListDialog::dragEnterEvent(QDragEnterEvent *event)
-{
- // Accept only one file
- // In the future a tabbed FileListDialog would accept more
- if ( event->mimeData()->hasUrls() && event->mimeData()->urls().count() == 1)
- event->acceptProposedAction();
-}
-// ***************************************************************************
-void BnpFileListDialog::dropEvent(QDropEvent *event)
- {
- // Excraft the local file url from the drop object and fill the table
- const QMimeData *mimeData = event->mimeData();
- QList urlList = mimeData->urls();
- loadTable( urlList.first().toLocalFile() );
- }
} // namespace BNPManager
\ No newline at end of file
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.h
index 5b5491d8f..dbf007fc2 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_filelist_dialog.h
@@ -59,6 +59,11 @@ public:
*/
void setupTable(int nbrows);
+ /**
+ * When BNP files is closed, clear the filelist table
+ */
+ void clearTable();
+
/**
* Fill the files selected in the table view to
* unpack them.
@@ -67,9 +72,6 @@ public:
*/
void getSelections(TSelectionList& SelectionList);
-protected:
- void dragEnterEvent (QDragEnterEvent *event);
- void dropEvent(QDropEvent *event);
private:
Ui::BnpFileListDialog m_ui;
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_constants.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_constants.h
index 7ec5eecd0..609305b7e 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_constants.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_constants.h
@@ -25,6 +25,7 @@ namespace Constants
const char * const BNP_MANAGER_SECTION = "BNPManager";
//resources
+const char *const ICON_NEW = ":/images/ic_nel_new.png";
const char *const ICON_ADD = ":/images/ic_nel_add_item.png";
const char *const ICON_DELETE = ":/images/ic_nel_delete_item.png";
const char *const ICON_UNPACK = ":/images/ic_nel_export.png";
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp
index 4022931d1..3990e70ce 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.cpp
@@ -30,6 +30,10 @@
#include
#include
+// STL includes
+#include
+#include
+
// Qt includes
#include
#include
@@ -37,6 +41,11 @@
#include
#include
#include
+#include
+#include
+#include
+#include
+#include
using namespace std;
using namespace NLMISC;
@@ -53,6 +62,8 @@ BNPManagerWindow::BNPManagerWindow(QWidget *parent)
setCentralWidget(hideWidget);
hideWidget->hide();
+ setAcceptDrops(true);
+
// Read the settings
readSettings();
@@ -98,6 +109,12 @@ void BNPManagerWindow::createDialogs()
// ***************************************************************************
void BNPManagerWindow::createActions()
{
+ // new action
+ m_newAction = new QAction(tr("&New..."), this);
+ m_newAction->setIcon(QIcon(Core::Constants::ICON_NEW));
+ m_newAction->setStatusTip(tr("New file"));
+ connect(m_newAction, SIGNAL(triggered()), this, SLOT( newFile() ));
+
// open action
m_openAction = new QAction(tr("&Open..."), this);
m_openAction->setIcon(QIcon(Core::Constants::ICON_OPEN));
@@ -132,6 +149,7 @@ void BNPManagerWindow::createActions()
void BNPManagerWindow::createToolBars()
{
m_fileToolBar = addToolBar(tr("&File"));
+ m_fileToolBar->addAction(m_newAction);
m_fileToolBar->addAction(m_openAction);
m_fileToolBar->addAction(m_closeAction);
@@ -143,10 +161,36 @@ void BNPManagerWindow::createToolBars()
// ***************************************************************************
bool BNPManagerWindow::loadFile(const QString fileName)
{
+ // Store the filename for later use
+ m_openedBNPFile = fileName;
m_BnpFileListDialog->loadTable(fileName);
return true;
}
// ***************************************************************************
+void BNPManagerWindow::newFile()
+{
+ // reference to the BNPFileHandle singletone instance
+ BNPFileHandle& myBNPFileHandle = BNPFileHandle::getInstance();
+
+ m_openedBNPFile = "";
+ m_BnpFileListDialog->clearTable();
+
+ QString filePath = QFileDialog::getSaveFileName(this, tr("Create File"),QDir::currentPath(),
+ tr("BNP File (*.bnp)"));
+
+ if (filePath.isEmpty() )
+ return;
+
+ if ( !filePath.endsWith(".bnp", Qt::CaseInsensitive) )
+ filePath.append(".bnp");
+
+ m_openedBNPFile = filePath;
+ m_BnpFileListDialog->setWindowTitle (filePath);
+
+ myBNPFileHandle.createFile ( filePath.toStdString() );
+
+}
+// ***************************************************************************
void BNPManagerWindow::open()
{
QString fileName;
@@ -158,13 +202,13 @@ void BNPManagerWindow::open()
if (fileName.isNull())
return;
- m_openedBNPFile = fileName;
loadFile(fileName);
}
// ***************************************************************************
void BNPManagerWindow::close()
{
- //TODO
+ m_openedBNPFile = "";
+ m_BnpFileListDialog->clearTable();
}
// ***************************************************************************
void BNPManagerWindow::addFiles()
@@ -216,6 +260,49 @@ void BNPManagerWindow::addFiles()
loadFile(m_openedBNPFile);
}
// ***************************************************************************
+void BNPManagerWindow::addFiles( QStringList FileList )
+{
+ // reference to the BNPFileHandle singletone instance
+ BNPFileHandle& myBNPFileHandle = BNPFileHandle::getInstance();
+
+ // vector of all current packed filenames
+ vector currentFiles;
+
+ // vector of files to add
+ vector addFiles;
+
+ // get all current filenames from the opened bnp file
+ myBNPFileHandle.fileNames(currentFiles);
+
+ QStringList::iterator it_list = FileList.begin();
+ while (it_list != FileList.end() )
+ {
+ string fileName = CFile::getFilename (it_list->toStdString() );
+ if ( std::find(currentFiles.begin(), currentFiles.end(), fileName ) != currentFiles.end() )
+ {
+ // Ask the user if he wants to override the existing file
+ // atm only warn the user and do not override
+ QMessageBox::warning(this, tr("BNP Manager"),
+ tr("File is already in the list!"),
+ QMessageBox::Ok,
+ QMessageBox::Ok);
+ }
+ else
+ {
+ addFiles.push_back( it_list->toStdString() );
+ // log it
+ nlinfo("Add file %s", fileName.c_str() );
+ }
+ it_list++;
+ }
+
+ if ( !addFiles.empty() )
+ {
+ myBNPFileHandle.addFiles( addFiles );
+ }
+ loadFile(m_openedBNPFile);
+}
+// ***************************************************************************
void BNPManagerWindow::deleteFiles()
{
QFileDialog filedialog(this);
@@ -288,4 +375,70 @@ void BNPManagerWindow::readSettings()
void BNPManagerWindow::writeSettings()
{
}
+
+// ***************************************************************************
+void BNPManagerWindow::dragEnterEvent(QDragEnterEvent *event)
+{
+ // Accept only one file
+ // In the future a tabbed FileListDialog would accept more
+ if ( event->mimeData()->hasUrls() )
+ event->acceptProposedAction();
+}
+// ***************************************************************************
+void BNPManagerWindow::dropEvent(QDropEvent *event)
+{
+ // reference to the BNPFileHandle singletone instance
+ BNPFileHandle& myBNPFileHandle = BNPFileHandle::getInstance();
+
+ // Excraft the local file url from the drop object and fill the table
+ const QMimeData *mimeData = event->mimeData();
+ QList urlList = mimeData->urls();
+ QString filePath;
+ QStringList fileList;
+
+ if ( urlList.count() == 1 )
+ {
+ // If it is a bnp file, open it
+ // If it is not a bnp file add it
+
+ filePath = urlList.first().toLocalFile();
+ if ( filePath.endsWith(".bnp", Qt::CaseInsensitive) )
+ {
+ loadFile(filePath);
+ }
+ else
+ {
+ if ( m_openedBNPFile == "")
+ newFile();
+ // Create a QStringList and pass it to addfiles
+ fileList.push_back( filePath );
+ addFiles( fileList );
+ // Reload current bnp
+ loadFile(m_openedBNPFile);
+ }
+ }
+ else if ( urlList.count() > 1 )
+ {
+ // Dont accept any bnp file
+ QList::iterator it = urlList.begin();
+ while ( it != urlList.end() )
+ {
+ filePath = it->toLocalFile();
+ if ( filePath.endsWith(".bnp") )
+ {
+ nlwarning("Could not add a bnp file!", filePath.toStdString().c_str() );
+ }
+ else
+ {
+ fileList.push_back( filePath );
+ }
+ ++it;
+ }
+ if ( m_openedBNPFile == "")
+ newFile();
+ addFiles( fileList );
+ // Reload current bnp
+ loadFile(m_openedBNPFile);
+ }
+}
} // namespace BNPManager
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.h
index b31d17a09..89bd68a16 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/bnp_manager_window.h
@@ -59,9 +59,14 @@ public:
public Q_SLOTS:
/**
- * Open a file dialog to choose which file should be opened.
+ * Create a new file
* \return Filename string
*/
+ void newFile();
+
+ /**
+ * Open a file dialog to choose which file should be opened.
+ */
void open();
/**
@@ -81,6 +86,7 @@ public Q_SLOTS:
* \param Filelist
*/
void addFiles();
+ void addFiles( QStringList FileList );
/**
* Unpack the files marked in the filelist dialog into user defined
@@ -96,6 +102,10 @@ public Q_SLOTS:
*/
void deleteFiles();
+protected:
+ void dragEnterEvent (QDragEnterEvent *event);
+ void dropEvent(QDropEvent *event);
+
private:
/**
@@ -126,6 +136,7 @@ private:
QToolBar *m_fileToolBar;
QToolBar *m_toolsBar;
+ QAction *m_newAction;
QAction *m_openAction;
QAction *m_closeAction;
QAction *m_addFilesAction;
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/images/ic_nel_new.png b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/images/ic_nel_new.png
new file mode 100644
index 000000000..d45dcb467
Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/plugins/bnp_manager/images/ic_nel_new.png differ