From 82f6999b4782408319d4182bd37c96aea5788e55 Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Tue, 16 Aug 2011 19:34:21 +0300 Subject: [PATCH] Changed: #1302 Added save/saveAs action for primitive item. --HG-- branch : gsoc2011-worldeditorqt --- .../plugins/world_editor/primitives_view.cpp | 8 +- .../world_editor/world_editor_actions.cpp | 104 +++++++++++++++++- .../world_editor/world_editor_actions.h | 3 + .../world_editor/world_editor_scene_item.cpp | 14 +++ .../world_editor/world_editor_scene_item.h | 3 + 5 files changed, 127 insertions(+), 5 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp index 0a2851e65..6620411ca 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp @@ -197,7 +197,7 @@ void PrimitivesView::save() QModelIndex index = indexList.first(); RootPrimitiveNode *node = static_cast(index.internalPointer()); - + if (node->data(Constants::PRIMITIVE_FILE_IS_CREATED).toBool()) { if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), node->fileName().toStdString())) @@ -214,8 +214,8 @@ void PrimitivesView::saveAs() nlassert(m_primitivesTreeModel); QString fileName = QFileDialog::getSaveFileName(this, - tr("Save NeL Ligo primitive file"), m_lastDir, - tr("NeL Ligo primitive file (*.primitive)")); + tr("Save NeL Ligo primitive file"), m_lastDir, + tr("NeL Ligo primitive file (*.primitive)")); setCursor(Qt::WaitCursor); if (!fileName.isEmpty()) @@ -224,7 +224,7 @@ void PrimitivesView::saveAs() QModelIndex index = indexList.first(); RootPrimitiveNode *node = static_cast(index.internalPointer()); - + if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), fileName.toStdString())) QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(fileName)); else 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 index 2eaa2a488..2e538748c 100644 --- 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 @@ -121,7 +121,7 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode for (int i = 0; i < sizeVec; ++i) { - polygon << QPointF(vec->x, -vec->y + cellSize); + polygon << QPointF(vec->x, cellSize - vec->y); ++vec; } item = scene->addWorldItemZone(polygon); @@ -216,6 +216,49 @@ QList polygonsFromItems(const QList &items) return result; } +void updateGraphicsData(AbstractWorldItem *item) +{ + float cellSize = Utils::ligoConfig()->CellSize; + Node *node = qvariant_cast(item->data(Constants::WORLD_EDITOR_NODE)); + PrimitiveNode *primitiveNode = static_cast(node); + if (primitiveNode != 0) + { + NLLIGO::IPrimitive *primitive = primitiveNode->primitive(); + + std::vector vPoints; + QPolygonF polygon = item->polygon(); + polygon.translate(item->pos()); + + for (int i = 0; i < polygon.size(); ++i) + { + NLMISC::CVector vec(polygon.at(i).x(), cellSize - polygon.at(i).y(), 0.0); + vPoints.push_back(NLLIGO::CPrimVector(vec)); + } + + switch (primitiveNode->primitiveClass()->Type) + { + case NLLIGO::CPrimitiveClass::Point: + { + NLLIGO::CPrimPoint *point = static_cast(primitive); + point->Point = vPoints.front(); + break; + } + case NLLIGO::CPrimitiveClass::Path: + { + NLLIGO::CPrimPath *path = static_cast(primitive); + path->VPoints = vPoints; + break; + } + case NLLIGO::CPrimitiveClass::Zone: + { + NLLIGO::CPrimZone *zone = static_cast(primitive); + zone->VPoints = vPoints; + break; + } + } + } +} + CreateWorldCommand::CreateWorldCommand(const QString &fileName, PrimitivesTreeModel *model, QUndoCommand *parent) : QUndoCommand(parent), m_fileName(fileName), @@ -451,6 +494,7 @@ void MoveWorldItemsCommand::undo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->moveBy(-m_offset.x(), -m_offset.y()); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } @@ -466,9 +510,20 @@ void MoveWorldItemsCommand::redo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->moveBy(m_offset.x(), m_offset.y()); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } + else + { + for (int i = 0; i < m_listPaths.count(); ++i) + { + Node *node = m_model->pathToNode(m_listPaths.at(i)); + AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); + updateGraphicsData(item); + } + } + m_firstRun = false; } @@ -498,6 +553,7 @@ void RotateWorldItemsCommand::undo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->rotateOn(m_pivot, -m_angle); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } @@ -513,9 +569,20 @@ void RotateWorldItemsCommand::redo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->rotateOn(m_pivot, m_angle); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } + else + { + for (int i = 0; i < m_listPaths.count(); ++i) + { + Node *node = m_model->pathToNode(m_listPaths.at(i)); + AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); + updateGraphicsData(item); + } + } + m_firstRun = false; } @@ -546,6 +613,7 @@ void ScaleWorldItemsCommand::undo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->scaleOn(m_pivot, m_invertFactor); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } @@ -561,9 +629,20 @@ void ScaleWorldItemsCommand::redo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->scaleOn(m_pivot, m_factor); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } + else + { + for (int i = 0; i < m_listPaths.count(); ++i) + { + Node *node = m_model->pathToNode(m_listPaths.at(i)); + AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); + updateGraphicsData(item); + } + } + m_firstRun = false; } @@ -592,6 +671,7 @@ void TurnWorldItemsCommand::undo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->turnOn(-m_angle); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } @@ -607,9 +687,19 @@ void TurnWorldItemsCommand::redo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->turnOn(m_angle); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } + else + { + for (int i = 0; i < m_listPaths.count(); ++i) + { + Node *node = m_model->pathToNode(m_listPaths.at(i)); + AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); + updateGraphicsData(item); + } + } m_firstRun = false; } @@ -642,6 +732,7 @@ void ShapeWorldItemsCommand::undo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->setPolygon(m_redoPolygons.at(i)); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); @@ -659,9 +750,20 @@ void ShapeWorldItemsCommand::redo() Node *node = m_model->pathToNode(m_listPaths.at(i)); AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); item->setPolygon(m_undoPolygons.at(i)); + updateGraphicsData(item); } m_scene->setEnabledEditPoints(pointsMode); } + else + { + for (int i = 0; i < m_listPaths.count(); ++i) + { + Node *node = m_model->pathToNode(m_listPaths.at(i)); + AbstractWorldItem *item = qvariant_cast(node->data(Constants::GRAPHICS_DATA_QT4_2D)); + updateGraphicsData(item); + } + } + m_firstRun = false; } 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 index a8352e2e6..1c77a4ba5 100644 --- 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 @@ -35,6 +35,7 @@ class ZoneBuilderBase; namespace WorldEditor { class WorldEditorScene; +class AbstractWorldItem; // Auxiliary operations @@ -50,6 +51,8 @@ QList graphicsItemsToPaths(const QList &items, Primitives QList polygonsFromItems(const QList &items); +void updateGraphicsData(AbstractWorldItem *item); + /** @class CreateWorldCommand @brief diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp index 9eb8e0717..28c933d39 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.cpp @@ -182,6 +182,17 @@ void WorldItemPoint::setColor(const QColor &color) m_brush.setColor(color); } +void WorldItemPoint::setPolygon(const QPolygonF &polygon) +{ +} + +QPolygonF WorldItemPoint::polygon() const +{ + QPolygonF polygon; + polygon << QPointF(0, 0); + return polygon; +} + void WorldItemPoint::createCircle() { if (m_radius != 0) @@ -339,6 +350,7 @@ void WorldItemPath::moveSubPoint(WorldItemSubPoint *subPoint) m_listLines.at(i).itemPoint->setPos((m_listLines.at(i).lineItem.first->pos() + m_listLines.at(i).lineItem.second->pos()) / 2); m_polygon = polygon; + setShapeChanged(true); update(); } @@ -381,6 +393,7 @@ void WorldItemPath::addSubPoint(WorldItemSubPoint *subPoint) break; } } + setShapeChanged(true); } bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint) @@ -427,6 +440,7 @@ bool WorldItemPath::removeSubPoint(WorldItemSubPoint *subPoint) subPoint->setPos((newLineItem.lineItem.first->pos() + newLineItem.lineItem.second->pos()) / 2); m_listLines.push_back(newLineItem); subPoint->setFlag(ItemSendsScenePositionChanges, false); + setShapeChanged(true); return true; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.h index 54811e271..b42138833 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene_item.h @@ -121,6 +121,9 @@ public: virtual void setColor(const QColor &color); virtual void setEnabledSubPoints(bool enabled) {} + virtual void setPolygon(const QPolygonF &polygon); + virtual QPolygonF polygon() const; + virtual QRectF boundingRect() const; virtual QPainterPath shape() const; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);