From 054e5c521cd92fd68db2e5d560f97c5734c7c9bd Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Tue, 16 Aug 2011 01:10:22 +0300 Subject: [PATCH] Changed: #1302 When create zone or path initially has minimal 3 points and path 2 points resp. --HG-- branch : gsoc2011-worldeditorqt --- .../world_editor/world_editor_actions.cpp | 19 ++++++++--- .../world_editor/world_editor_actions.h | 2 ++ .../world_editor/world_editor_misc.cpp | 18 +++++++++-- .../world_editor/world_editor_scene_item.cpp | 6 +++- .../world_editor/world_editor_scene_item.h | 2 +- .../world_editor/world_editor_window.ui | 32 +++++++++++++++---- 6 files changed, 64 insertions(+), 15 deletions(-) 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 45adf49ce..f40e498a1 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 @@ -38,6 +38,7 @@ // Qt includes #include +#include #include namespace WorldEditor @@ -365,6 +366,13 @@ AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, m_model(model) { setText(QString("Add %1").arg(m_className)); + + QGraphicsView *view = m_scene->views().first(); + + // TODO: returns incorrect position when zoom in + QRectF visibleArea = view->mapToScene(view->rect()).boundingRect(); + m_delta = visibleArea.height() / 10.0; + m_initPos = visibleArea.center(); } AddPrimitiveByClassCommand::~AddPrimitiveByClassCommand() @@ -381,6 +389,8 @@ void AddPrimitiveByClassCommand::undo() // set the primitive context NLLIGO::CPrimitiveContext::instance().CurrentPrimitive = node->rootPrimitiveNode()->primitives(); + removeGraphicsItems(index, m_model, m_scene); + Utils::deletePrimitive(node->primitive()); // unset the context @@ -397,7 +407,6 @@ void AddPrimitiveByClassCommand::redo() PrimitiveNode *parentNode = static_cast(parentIndex.internalPointer()); const NLLIGO::CPrimitiveClass *primClass = parentNode->primitiveClass(); - float delta = 10; int id = 0; while (primClass->DynamicChildren[id].ClassName != m_className.toStdString()) ++id; @@ -407,12 +416,14 @@ void AddPrimitiveByClassCommand::redo() QString namePrimititve = QString("%1_%2").arg(m_className).arg(parentNode->childCount()); NLLIGO::IPrimitive *newPrimitive = Utils::createPrimitive(m_className.toStdString().c_str(), namePrimititve.toStdString().c_str(), - NLMISC::CVector(), delta, primClass->DynamicChildren[id].Parameters, parentNode->primitive()); + NLMISC::CVector(m_initPos.x(), -m_initPos.y(), 0.0), m_delta, primClass->DynamicChildren[id].Parameters, parentNode->primitive()); // unset the context NLLIGO::CPrimitiveContext::instance().CurrentPrimitive = NULL; m_newPrimIndex = m_model->createPrimitiveNode(newPrimitive, m_parentIndex); + + addNewGraphicsItems(m_model->pathToIndex(m_newPrimIndex), m_model, m_scene); } MoveWorldItemsCommand::MoveWorldItemsCommand(const QList &items, const QPointF &offset, @@ -471,7 +482,7 @@ RotateWorldItemsCommand::RotateWorldItemsCommand(const QList &i m_scene(scene), m_firstRun(true) { - setText(QString("Rotate item(s) %1").arg(m_angle)); + setText("Rotate item(s)"); } RotateWorldItemsCommand::~RotateWorldItemsCommand() @@ -565,7 +576,7 @@ TurnWorldItemsCommand::TurnWorldItemsCommand(const QList &items m_scene(scene), m_firstRun(true) { - setText(QString("Turn item(s) %1").arg(m_angle)); + setText("Turn item(s)"); } TurnWorldItemsCommand::~TurnWorldItemsCommand() 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 fcb510605..a8352e2e6 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 @@ -147,6 +147,8 @@ public: virtual void redo(); private: + QPointF m_initPos; + float m_delta; const QString m_className; Path m_parentIndex, m_newPrimIndex; WorldEditorScene *m_scene; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_misc.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_misc.cpp index 1f77ee63d..5b5b9540d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_misc.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_misc.cpp @@ -365,11 +365,25 @@ NLLIGO::IPrimitive *createPrimitive(const char *className, const char *primName, } break; case NLLIGO::CPrimitiveClass::Path: - primitive = new NLLIGO::CPrimPath; + { + NLLIGO::CPrimPath *path = new NLLIGO::CPrimPath; + primitive = path; + path->VPoints.push_back(NLLIGO::CPrimVector(initPos)); + NLMISC::CVector secondPos = NLMISC::CVector(initPos.x + deltaPos, initPos.y, 0.0); + path->VPoints.push_back(NLLIGO::CPrimVector(secondPos)); break; + } case NLLIGO::CPrimitiveClass::Zone: - primitive = new NLLIGO::CPrimZone; + { + NLLIGO::CPrimZone *zone = new NLLIGO::CPrimZone; + primitive = zone; + zone->VPoints.push_back(NLLIGO::CPrimVector(initPos)); + NLMISC::CVector secondPos = NLMISC::CVector(initPos.x + deltaPos, initPos.y, 0.0); + zone->VPoints.push_back(NLLIGO::CPrimVector(secondPos)); + secondPos.y = initPos.y + deltaPos; + zone->VPoints.push_back(NLLIGO::CPrimVector(secondPos)); break; + } case NLLIGO::CPrimitiveClass::Alias: primitive = new NLLIGO::CPrimAlias; break; 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 056a4f01e..9eb8e0717 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 @@ -187,7 +187,7 @@ void WorldItemPoint::createCircle() if (m_radius != 0) { // Create circle - int segmentCount = 30; + int segmentCount = 20; QPointF circlePoint(m_radius, 0); m_circle << circlePoint; for (int i = 1; i < segmentCount + 1; ++i) @@ -241,9 +241,13 @@ void WorldItemPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *op painter->setPen(Qt::NoPen); // if (option->state & QStyle::State_Selected) if (isActived()) + { painter->setBrush(m_selectedBrush); + } else + { painter->setBrush(m_brush); + } // Draw point painter->drawRect(m_rect); 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 1b934d77b..54811e271 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 @@ -129,7 +129,7 @@ private: void createCircle(); void updateBoundingRect(); - static const int SIZE_POINT = 3; + static const int SIZE_POINT = 2; QPen m_pen, m_selectedPen; QBrush m_brush, m_selectedBrush; 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 1de6cbdc3..870081d47 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 @@ -6,7 +6,7 @@ 0 0 - 800 + 819 600 @@ -121,8 +121,9 @@ false - - + + + @@ -177,7 +178,7 @@ S/H Land - + true @@ -185,10 +186,13 @@ false - S/H Primitives + S/H Zone primitives + + + S/H Zone Primitives - + true @@ -196,7 +200,7 @@ false - S/H Layers + S/H Path primitives @@ -343,6 +347,20 @@ Project settings + + + true + + + false + + + S/H Points primitives + + + S/H Points primitives + +