From 29f78e79feedf2377599b10a84223cd11ea17654 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Wed, 20 Jul 2011 18:07:46 +0300 Subject: [PATCH] Changed: #1302 Added initial database of primitives (model/view) (loading of *. primitive file) --HG-- branch : gsoc2011-worldeditorqt --- .../src/plugins/world_editor/CMakeLists.txt | 1 + .../plugins/world_editor/primitive_item.cpp | 145 +++++++++++++++ .../src/plugins/world_editor/primitive_item.h | 99 ++++++++++ .../plugins/world_editor/primitives_model.cpp | 172 ++++++++++++++++++ .../plugins/world_editor/primitives_model.h | 65 +++++++ .../world_editor/world_editor_actions.cpp | 47 +++++ .../world_editor/world_editor_actions.h | 48 +++++ .../world_editor/world_editor_constants.h | 4 + .../world_editor/world_editor_plugin.cpp | 34 +++- .../world_editor/world_editor_plugin.h | 2 + .../world_editor/world_editor_window.cpp | 56 ++++-- .../world_editor/world_editor_window.h | 4 + .../world_editor/world_editor_window.ui | 41 ++++- 13 files changed, 701 insertions(+), 17 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/CMakeLists.txt index 784dd6139..c8b034444 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/CMakeLists.txt @@ -11,6 +11,7 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin. SET(OVQT_PLUGIN_WORLD_EDITOR_HDR world_editor_plugin.h world_editor_window.h + primitives_model.h ) SET(OVQT_PLUGIN_WORLD_EDITOR_UIS world_editor_window.ui diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp new file mode 100644 index 000000000..9ec95bdaa --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.cpp @@ -0,0 +1,145 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Project includes +#include "primitive_item.h" + +// Qt includes +#include + +namespace WorldEditor +{ + +BaseTreeItem::BaseTreeItem(BaseTreeItem *parent) +{ + m_parentItem = parent; + m_itemData << QIcon() << "" << "" << ""; +} + +BaseTreeItem::BaseTreeItem(const QList &data, BaseTreeItem *parent) +{ + m_parentItem = parent; + m_itemData = data; +} + +BaseTreeItem::~BaseTreeItem() +{ + qDeleteAll(m_childItems); +} + +void BaseTreeItem::appendChild(BaseTreeItem *item) +{ + m_childItems.append(item); +} + +BaseTreeItem *BaseTreeItem::child(int row) +{ + return m_childItems.value(row); +} + +int BaseTreeItem::childCount() const +{ + return m_childItems.count(); +} + +int BaseTreeItem::columnCount() const +{ + return m_itemData.count(); +} + +QVariant BaseTreeItem::data(int column) const +{ + return m_itemData.value(column); +} + +void BaseTreeItem::setData(int column, const QVariant &data) +{ + m_itemData[column] = data; +} + +BaseTreeItem *BaseTreeItem::parent() +{ + return m_parentItem; +} + +int BaseTreeItem::row() const +{ + if (m_parentItem) + return m_parentItem->m_childItems.indexOf(const_cast(this)); + + return 0; +} + +void BaseTreeItem::setModified(bool value) +{ + m_modified = value; +} + +bool BaseTreeItem::isModified() const +{ + return m_modified; +} + +PrimitiveItem::PrimitiveItem(NLLIGO::IPrimitive *primitive, BaseTreeItem *parent) + : BaseTreeItem(parent), + m_primitive(primitive) +{ + setData(1, QString(m_primitive->getName().c_str())); + setData(2, QString(m_primitive->getClassName().c_str())); + + std::string className; + m_primitive->getPropertyByName("class", className); + + // Set Icon + QIcon icon(QString("./old_ico/%1.ico").arg(className.c_str())); + if (primitive->getParent() == NULL) + icon = QIcon("./old_ico/root.ico"); + if (icon.isNull()) + { + if (primitive->getNumChildren() == 0) + icon = QIcon("./old_ico/property.ico"); + else + icon = QIcon("./old_ico/folder_h.ico"); + } + setData(0, icon); + + setData(3, QString(className.c_str())); +} +/* +PrimitiveItem::PrimitiveItem(const PrimitiveItem &other) +{ +} +*/ +PrimitiveItem::~PrimitiveItem() +{ +} + +PrimitivesItem::PrimitivesItem(const QString &name, NLLIGO::CPrimitives *primitives, BaseTreeItem *parent) + : PrimitiveItem(primitives->RootNode, parent), + m_primitives(primitives) +{ + setData(1, name); +} +/* +PrimitivesItem::PrimitivesItem(const PrimitiveItem &other) +{ +} +*/ +PrimitivesItem::~PrimitivesItem() +{ +} + +} /* namespace WorldEditor */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h new file mode 100644 index 000000000..26ca70670 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitive_item.h @@ -0,0 +1,99 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef PRIMITIVE_ITEM_H +#define PRIMITIVE_ITEM_H + +// Project includes + +// NeL includes +#include + +// Qt includes +#include +#include +#include + +namespace WorldEditor +{ + +/* +@class BaseTreeItem +@brief +@details +*/ +class BaseTreeItem +{ +public: + BaseTreeItem(BaseTreeItem *parent = 0); + BaseTreeItem(const QList &data, BaseTreeItem *parent = 0); + virtual ~BaseTreeItem(); + + void appendChild(BaseTreeItem *child); + + BaseTreeItem *child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column) const; + void setData(int column, const QVariant &data); + int row() const; + BaseTreeItem *parent(); + void setModified(bool value); + bool isModified() const; + +private: + + bool m_modified; + QList m_childItems; + QList m_itemData; + BaseTreeItem *m_parentItem; +}; + +/* +@class PrimitiveItem +@brief +@details +*/ +class PrimitiveItem: public BaseTreeItem +{ +public: + PrimitiveItem(NLLIGO::IPrimitive *primitive, BaseTreeItem *parent); + PrimitiveItem(const PrimitiveItem &other); + virtual ~PrimitiveItem(); + +private: + NLLIGO::IPrimitive *m_primitive; +}; + +/* +@class PrimitivesItem +@brief +@details +*/ +class PrimitivesItem: public PrimitiveItem +{ +public: + PrimitivesItem(const QString &name, NLLIGO::CPrimitives *primitives, BaseTreeItem *parent); + PrimitivesItem(const PrimitiveItem &other); + virtual ~PrimitivesItem(); + +private: + NLLIGO::CPrimitives *m_primitives; +}; + +} /* namespace WorldEditor */ + +#endif // PRIMITIVE_ITEM_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp new file mode 100644 index 000000000..8c5af6229 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp @@ -0,0 +1,172 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include +#include +#include + +#include + +#include "primitive_item.h" +#include "primitives_model.h" + +namespace WorldEditor +{ + +PrimitivesTreeModel::PrimitivesTreeModel(QObject *parent) + : QAbstractItemModel(parent) +{ + QList rootData; + rootData << "Name" << "Class" << "Class"; + m_rootItem = new BaseTreeItem(rootData); +} + +PrimitivesTreeModel::~PrimitivesTreeModel() +{ + delete m_rootItem; +} + +int PrimitivesTreeModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return m_rootItem->columnCount(); +} + +QVariant PrimitivesTreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + BaseTreeItem *item = static_cast(index.internalPointer()); + switch (role) + { +// case Qt::TextAlignmentRole: +// return int(Qt::AlignLeft | Qt::AlignVCenter); + case Qt::DisplayRole: + return item->data(index.column() + 1); + case Qt::DecorationRole: + { + if (index.column() == 0) + return qVariantFromValue(item->data(0)); + else + return QVariant(); + } + default: + return QVariant(); + } +} + +Qt::ItemFlags PrimitivesTreeModel::flags(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QVariant PrimitivesTreeModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return m_rootItem->data(section); + + return QVariant(); +} + +QModelIndex PrimitivesTreeModel::index(int row, int column, const QModelIndex &parent) +const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + BaseTreeItem *parentItem; + + if (!parent.isValid()) + parentItem = m_rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + BaseTreeItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex PrimitivesTreeModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + BaseTreeItem *childItem = static_cast(index.internalPointer()); + BaseTreeItem *parentItem = childItem->parent(); + + if (parentItem == m_rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} + +int PrimitivesTreeModel::rowCount(const QModelIndex &parent) const +{ + BaseTreeItem *parentItem; + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + parentItem = m_rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + return parentItem->childCount(); +} + +void PrimitivesTreeModel::addPrimitives(const QString &name, NLLIGO::CPrimitives *primitives) +{ + beginResetModel(); + PrimitivesItem *newPrimitives = new PrimitivesItem(name, primitives, m_rootItem); + m_rootItem->appendChild(newPrimitives); + for (uint i = 0; i < primitives->RootNode->getNumChildren(); ++i) + { + NLLIGO::IPrimitive *childPrim; + primitives->RootNode->getChild(childPrim, i); + scanPrimitive(childPrim, newPrimitives); + } + endResetModel(); +} + +void PrimitivesTreeModel::scanPrimitive(NLLIGO::IPrimitive *prim, BaseTreeItem *parent) +{ +// const NLLIGO::CPrimitiveClass *primClass = NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig->getPrimitiveClass(*prim); +// nlassert (primClass); +// if (primClass->Type == NLLIGO::CPrimitiveClass::Alias) +// return; + if (prim->getClassName() == "CPrimAlias") + return; + + PrimitiveItem *newItem = new PrimitiveItem(prim, parent); + parent->appendChild(newItem); + for (uint i = 0; i < prim->getNumChildren(); ++i) + { + NLLIGO::IPrimitive *childPrim; + prim->getChild(childPrim, i); + scanPrimitive(childPrim, newItem); + } +} + +} /* namespace WorldEditor */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.h new file mode 100644 index 000000000..5098d1e5e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.h @@ -0,0 +1,65 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef PRIMITIVES_MODEL_H +#define PRIMITIVES_MODEL_H + +#include + +#include +#include +#include + +namespace WorldEditor +{ + +class BaseTreeItem; + +/** +@class PrimitivesTreeModel +@brief +@details +*/ +class PrimitivesTreeModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + PrimitivesTreeModel(QObject *parent = 0); + ~PrimitivesTreeModel(); + + QVariant data(const QModelIndex &index, int role) const; + Qt::ItemFlags flags(const QModelIndex &index) const; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + + void addPrimitives(const QString &name, NLLIGO::CPrimitives *primitives); + +private: + void scanPrimitive(NLLIGO::IPrimitive *prim, BaseTreeItem *parent = 0); + + BaseTreeItem *m_rootItem; +}; + +} /* namespace WorldEditor */ + +#endif // PRIMITIVES_MODEL_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp new file mode 100644 index 000000000..cae402d27 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp @@ -0,0 +1,47 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +// Project includes +#include "world_editor_actions.h" + +// NeL includes +#include + +// Qt includes + +namespace WorldEditor +{ + +OpenLandscapeCommand::OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent) + : QUndoCommand(parent), + m_fileName(fileName) +{ +} + +OpenLandscapeCommand::~OpenLandscapeCommand() +{ +} + +void OpenLandscapeCommand::undo() +{ +} + +void OpenLandscapeCommand::redo() +{ +} + +} /* namespace WorldEditor */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h new file mode 100644 index 000000000..5a1c1ea49 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h @@ -0,0 +1,48 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef WORLD_EDITOR_ACTIONS_H +#define WORLD_EDITOR_ACTIONS_H + +// Project includes + +// NeL includes + +// Qt includes +#include +#include +#include + +namespace WorldEditor +{ + +class OpenLandscapeCommand: public QUndoCommand +{ +public: + OpenLandscapeCommand(const QString &fileName, QUndoCommand *parent = 0); + virtual ~OpenLandscapeCommand(); + + virtual void undo(); + virtual void redo(); +private: + + QString m_fileName; +}; + +} /* namespace WorldEditor */ + +#endif // WORLD_EDITOR_ACTIONS_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h index 644f79b53..a54b82cb1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_constants.h @@ -28,6 +28,10 @@ const char * const WORLD_EDITOR_PLUGIN = "WorldEditor"; const char * const WORLD_EDITOR_SECTION = "WorldEditor"; const char * const WORLD_WINDOW_STATE = "WorldWindowState"; const char * const WORLD_WINDOW_GEOMETRY = "WorldWindowGeometry"; +const char * const WORLD_EDITOR_CELL_SIZE = "WorldEditorCellSize"; +const char * const WORLD_EDITOR_SNAP = "WorldEditorSnap"; +const char * const ZONE_SNAPSHOT_RES = "WorldEditorZoneSnapshotRes"; +const char * const PRIMITIVE_CLASS_FILENAME = "WorldEditorPrimitiveClassFilename"; //resources const char * const ICON_WORLD_EDITOR = ":/icons/ic_nel_world_editor.png"; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.cpp index 494f6e2b6..90d2de6d6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.cpp @@ -24,6 +24,9 @@ // NeL includes #include "nel/misc/debug.h" +#include +#include +#include // Qt includes #include @@ -43,8 +46,35 @@ WorldEditorPlugin::~WorldEditorPlugin() bool WorldEditorPlugin::initialize(ExtensionSystem::IPluginManager *pluginManager, QString *errorString) { - Q_UNUSED(errorString); m_plugMan = pluginManager; + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(Constants::WORLD_EDITOR_SECTION); + m_ligoConfig.CellSize = settings->value(Constants::WORLD_EDITOR_CELL_SIZE, "160").toFloat(); + m_ligoConfig.Snap = settings->value(Constants::WORLD_EDITOR_SNAP, "1").toFloat(); + m_ligoConfig.ZoneSnapShotRes = settings->value(Constants::ZONE_SNAPSHOT_RES, "128").toUInt(); + QString fileName = settings->value(Constants::PRIMITIVE_CLASS_FILENAME, "world_editor_classes.xml").toString(); + settings->endGroup(); + try + { + // Search path of file world_editor_classes.xml + std::string ligoPath = NLMISC::CPath::lookup(fileName.toStdString()); + // Init LIGO + m_ligoConfig.readPrimitiveClass(ligoPath.c_str(), true); + NLLIGO::Register(); + NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig = &m_ligoConfig; + } + catch (NLMISC::Exception &e) + { + *errorString = tr("(%1)").arg(e.what()); + return false; + } + + // Reset + m_ligoConfig.resetPrimitiveConfiguration (); + + // Load + m_ligoConfig.readPrimitiveClass ("world_editor_primitive_configuration.xml", true); + addAutoReleasedObject(new WorldEditorContext(this)); return true; @@ -115,7 +145,7 @@ QUndoStack *WorldEditorContext::undoStack() void WorldEditorContext::open() { - //m_worldEditorWindow->open(); + m_worldEditorWindow->open(); } QWidget *WorldEditorContext::widget() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.h index fdfff7eff..11e2c7871 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_plugin.h @@ -25,6 +25,7 @@ // NeL includes #include "nel/misc/app_context.h" +#include // Qt includes #include @@ -70,6 +71,7 @@ protected: NLMISC::CLibraryContext *m_libContext; private: + NLLIGO::CLigoConfig m_ligoConfig; ExtensionSystem::IPluginManager *m_plugMan; QList m_autoReleaseObjects; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp index 7d6f9dcfd..8d2c0c7f1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp @@ -18,13 +18,25 @@ // Project includes #include "world_editor_window.h" #include "world_editor_constants.h" +#include "primitives_model.h" #include "../core/icore.h" #include "../core/imenu_manager.h" #include "../core/core_constants.h" +// NeL includes +#include +#include +#include + +#include +#include +#include +#include + // Qt includes #include +#include namespace WorldEditor { @@ -32,11 +44,15 @@ QString _lastDir; WorldEditorWindow::WorldEditorWindow(QWidget *parent) : QMainWindow(parent), + m_primitivesModel(0), m_undoStack(0) { m_ui.setupUi(this); m_undoStack = new QUndoStack(this); + m_primitivesModel = new PrimitivesTreeModel(); + m_ui.treePrimitivesView->setModel(m_primitivesModel); + createMenus(); createToolBars(); // readSettings(); @@ -54,20 +70,33 @@ QUndoStack *WorldEditorWindow::undoStack() const void WorldEditorWindow::open() { - /* QStringList fileNames = QFileDialog::getOpenFileNames(this, - tr("Open NeL Ligo land file"), _lastDir, - tr("All NeL Ligo land files (*.land)")); + QStringList fileNames = QFileDialog::getOpenFileNames(this, + tr("Open NeL Ligo primitive file"), _lastDir, + tr("All NeL Ligo primitive files (*.primitive)")); - setCursor(Qt::WaitCursor); - if (!fileNames.isEmpty()) + setCursor(Qt::WaitCursor); + if (!fileNames.isEmpty()) + { + QStringList list = fileNames; + _lastDir = QFileInfo(list.front()).absolutePath(); + Q_FOREACH(QString fileName, fileNames) { - QStringList list = fileNames; - _lastDir = QFileInfo(list.front()).absolutePath(); - Q_FOREACH(QString fileName, fileNames) - { - } + loadPrimitive(fileName); } - setCursor(Qt::ArrowCursor);*/ + } + setCursor(Qt::ArrowCursor); +} + +void WorldEditorWindow::loadPrimitive(const QString &fileName) +{ + NLLIGO::CPrimitives *primitives = new NLLIGO::CPrimitives(); + + // set the primitive context + NLLIGO::CPrimitiveContext::instance().CurrentPrimitive = primitives; + + NLLIGO::loadXmlPrimitiveFile(*primitives, fileName.toStdString(), *NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig); + + m_primitivesModel->addPrimitives(fileName, primitives); } void WorldEditorWindow::createMenus() @@ -82,14 +111,15 @@ void WorldEditorWindow::createToolBars() //m_ui.fileToolBar->addAction(action); QAction *action = menuManager->action(Core::Constants::OPEN); m_ui.fileToolBar->addAction(action); + m_ui.fileToolBar->addSeparator(); action = menuManager->action(Core::Constants::UNDO); if (action != 0) - m_ui.undoToolBar->addAction(action); + m_ui.fileToolBar->addAction(action); action = menuManager->action(Core::Constants::REDO); if (action != 0) - m_ui.undoToolBar->addAction(action); + m_ui.fileToolBar->addAction(action); //action = menuManager->action(Core::Constants::SAVE); //m_ui.fileToolBar->addAction(action); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h index 8efafc48b..8311ffcc6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h @@ -26,6 +26,7 @@ namespace WorldEditor { +class PrimitivesTreeModel; class WorldEditorWindow: public QMainWindow { @@ -48,6 +49,9 @@ private: void readSettings(); void writeSettings(); + void loadPrimitive(const QString &fileName); + + PrimitivesTreeModel *m_primitivesModel; QUndoStack *m_undoStack; Ui::WorldEditorWindow m_ui; }; /* class WorldEditorWindow */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.ui index 86c8a2b11..6f597ca2a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.ui @@ -20,7 +20,7 @@ - + @@ -35,7 +35,7 @@ false - + toolBar @@ -45,8 +45,45 @@ false + + + + + 2 + + + + + 3 + + + 3 + + + + + + + + + + loadPrimitive + + + + + newPrimitive + + + + + LandscapeEditor::LandscapeView + QGraphicsView +
../landscape_editor/landscape_view.h
+
+