diff --git a/apps/opencs/view/render/cell.cpp b/apps/opencs/view/render/cell.cpp index eed394d0b..b408503d1 100644 --- a/apps/opencs/view/render/cell.cpp +++ b/apps/opencs/view/render/cell.cpp @@ -266,29 +266,14 @@ bool CSVRender::Cell::referenceAdded (const QModelIndex& parent, int start, int return addObjects (start, end); } -void CSVRender::Cell::pathgridAdded(const CSMWorld::Pathgrid& pathgrid) +void CSVRender::Cell::pathgridModified() { mPathgrid->recreateGeometry(); } void CSVRender::Cell::pathgridRemoved() { - mPathgrid->recreateGeometry(); -} - -void CSVRender::Cell::pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) -{ - mPathgrid->recreateGeometry(); -} - -void CSVRender::Cell::pathgridRowRemoved(const QModelIndex& parent, int start, int end) -{ - mPathgrid->recreateGeometry(); -} - -void CSVRender::Cell::pathgridRowAdded(const QModelIndex& parent, int start, int end) -{ - mPathgrid->recreateGeometry(); + mPathgrid->removeGeometry(); } void CSVRender::Cell::setSelection (int elementMask, Selection mode) diff --git a/apps/opencs/view/render/cell.hpp b/apps/opencs/view/render/cell.hpp index a2efc0077..523a6bb83 100644 --- a/apps/opencs/view/render/cell.hpp +++ b/apps/opencs/view/render/cell.hpp @@ -111,16 +111,10 @@ namespace CSVRender /// this cell? bool referenceAdded (const QModelIndex& parent, int start, int end); - void pathgridAdded(const CSMWorld::Pathgrid& pathgrid); + void pathgridModified(); void pathgridRemoved(); - void pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); - - void pathgridRowRemoved(const QModelIndex& parent, int start, int end); - - void pathgridRowAdded(const QModelIndex& parent, int start, int end); - void setSelection (int elementMask, Selection mode); // Select everything that references the same ID as at least one of the elements diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 39e7f8361..a01df4392 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -280,38 +280,29 @@ void CSVRender::PagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& t { const CSMWorld::SubCellCollection& pathgrids = mDocument.getData().getPathgrids(); + int rowStart = -1; + int rowEnd = -1; + if (topLeft.parent().isValid()) { - int row = topLeft.parent().row(); - - const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); - CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY); - - std::map::iterator searchResult = mCells.find(coords); - if (searchResult != mCells.end()) - { - searchResult->second->pathgridDataChanged(topLeft, bottomRight); - flagAsModified(); - } + rowStart = topLeft.parent().row(); + rowEnd = bottomRight.parent().row(); } -} - -void CSVRender::PagedWorldspaceWidget::pathgridRemoved (const QModelIndex& parent, int start, int end) -{ - const CSMWorld::SubCellCollection& pathgrids = mDocument.getData().getPathgrids(); - - if (parent.isValid()) + else { - // Pathgrid data was modified - int row = parent.row(); + rowStart = topLeft.row(); + rowEnd = bottomRight.row(); + } + for (int row = rowStart; row <= rowEnd; ++row) + { const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY); std::map::iterator searchResult = mCells.find(coords); if (searchResult != mCells.end()) { - searchResult->second->pathgridRowRemoved(parent, start, end); + searchResult->second->pathgridModified(); flagAsModified(); } } @@ -341,11 +332,10 @@ void CSVRender::PagedWorldspaceWidget::pathgridAboutToBeRemoved (const QModelInd void CSVRender::PagedWorldspaceWidget::pathgridAdded(const QModelIndex& parent, int start, int end) { - const CSMWorld::SubCellCollection& pathgrids = mDocument.getData().getPathgrids(); + const CSMWorld::SubCellCollection& pathgrids = mDocument.getData().getPathgrids(); if (!parent.isValid()) { - // Pathgrid added theoretically, unable to test until it is possible to add pathgrids for (int row = start; row <= end; ++row) { const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); @@ -354,26 +344,11 @@ void CSVRender::PagedWorldspaceWidget::pathgridAdded(const QModelIndex& parent, std::map::iterator searchResult = mCells.find(coords); if (searchResult != mCells.end()) { - searchResult->second->pathgridAdded(pathgrid); + searchResult->second->pathgridModified(); flagAsModified(); } } } - else - { - // Pathgrid data was modified - int row = parent.row(); - - const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); - CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY); - - std::map::iterator searchResult = mCells.find(coords); - if (searchResult != mCells.end()) - { - searchResult->second->pathgridRowAdded(parent, start, end); - flagAsModified(); - } - } } diff --git a/apps/opencs/view/render/pagedworldspacewidget.hpp b/apps/opencs/view/render/pagedworldspacewidget.hpp index c7f035dd9..692000708 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.hpp +++ b/apps/opencs/view/render/pagedworldspacewidget.hpp @@ -54,8 +54,6 @@ namespace CSVRender virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); - virtual void pathgridRemoved (const QModelIndex& parent, int start, int end); - virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end); virtual void pathgridAdded (const QModelIndex& parent, int start, int end); diff --git a/apps/opencs/view/render/pathgrid.cpp b/apps/opencs/view/render/pathgrid.cpp index 2e4ec6a1a..5c8868344 100644 --- a/apps/opencs/view/render/pathgrid.cpp +++ b/apps/opencs/view/render/pathgrid.cpp @@ -18,6 +18,17 @@ namespace CSVRender { + class PathgridNodeCallback : public osg::NodeCallback + { + public: + + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) + { + PathgridTag* tag = dynamic_cast(node->getUserData()); + tag->getPathgrid()->update(); + } + }; + PathgridTag::PathgridTag(Pathgrid* pathgrid) : TagBase(Mask_Pathgrid), mPathgrid(pathgrid) { @@ -49,6 +60,8 @@ namespace CSVRender , mInterior(false) , mConnectionIndicator(false) , mConnectionNode(0) + , mChangeGeometry(true) + , mRemoveGeometry(false) , mParent(parent) , mPathgridGeometry(0) , mSelectedGeometry(0) @@ -59,6 +72,7 @@ namespace CSVRender mBaseNode = new osg::PositionAttitudeTransform (); mBaseNode->setPosition(osg::Vec3f(mCoords.getX() * CoordScalar, mCoords.getY() * CoordScalar, 0.f)); mBaseNode->setUserData(mTag); + mBaseNode->setUpdateCallback(new PathgridNodeCallback()); mBaseNode->setNodeMask(Mask_Pathgrid); mParent->addChild(mBaseNode); @@ -116,7 +130,7 @@ namespace CSVRender for (unsigned short i = 0; i < static_cast(source->mPoints.size()); ++i) mSelected.push_back(i); - recreateSelectedGeometry(*source); + createSelectedGeometry(*source); } else { @@ -136,7 +150,7 @@ namespace CSVRender mSelected.push_back(node); } - recreateSelectedGeometry(); + createSelectedGeometry(); } void Pathgrid::invertSelected() @@ -153,7 +167,7 @@ namespace CSVRender mSelected.push_back(i); } - recreateSelectedGeometry(*source); + createSelectedGeometry(*source); } else { @@ -176,7 +190,7 @@ namespace CSVRender { mConnectionIndicator = true; mConnectionNode = node; - recreateSelectedGeometry(); + createSelectedGeometry(); } void Pathgrid::resetMove() @@ -185,7 +199,7 @@ namespace CSVRender if (mConnectionIndicator) { mConnectionIndicator = false; - recreateSelectedGeometry(); + createSelectedGeometry(); } } @@ -363,7 +377,34 @@ namespace CSVRender void Pathgrid::recreateGeometry() { - // Make new + mChangeGeometry = true; + } + + void Pathgrid::removeGeometry() + { + mRemoveGeometry = true; + + + } + + void Pathgrid::update() + { + if (mRemoveGeometry) + { + removePathgridGeometry(); + removeSelectedGeometry(); + } + else if (mChangeGeometry) + { + createGeometry(); + } + + mChangeGeometry = false; + mRemoveGeometry = false; + } + + void Pathgrid::createGeometry() + { const CSMWorld::Pathgrid* source = getPathgridSource(); if (source) { @@ -371,21 +412,20 @@ namespace CSVRender mPathgridGeometry = SceneUtil::createPathgridGeometry(*source); mPathgridGeode->addDrawable(mPathgridGeometry); - recreateSelectedGeometry(*source); + createSelectedGeometry(*source); } else { - removePathgridGeometry(); - removeSelectedGeometry(); + removeGeometry(); } } - void Pathgrid::recreateSelectedGeometry() + void Pathgrid::createSelectedGeometry() { const CSMWorld::Pathgrid* source = getPathgridSource(); if (source) { - recreateSelectedGeometry(*source); + createSelectedGeometry(*source); } else { @@ -393,7 +433,7 @@ namespace CSVRender } } - void Pathgrid::recreateSelectedGeometry(const CSMWorld::Pathgrid& source) + void Pathgrid::createSelectedGeometry(const CSMWorld::Pathgrid& source) { removeSelectedGeometry(); @@ -438,7 +478,7 @@ namespace CSVRender const CSMWorld::Pathgrid* Pathgrid::getPathgridSource() { int index = mPathgridCollection.searchId(mId); - if (index != -1) + if (index != -1 && !mPathgridCollection.getRecord(index).isDeleted()) { return &mPathgridCollection.getRecord(index).get(); } diff --git a/apps/opencs/view/render/pathgrid.hpp b/apps/opencs/view/render/pathgrid.hpp index 3a83716d8..b192ed31b 100644 --- a/apps/opencs/view/render/pathgrid.hpp +++ b/apps/opencs/view/render/pathgrid.hpp @@ -83,6 +83,9 @@ namespace CSVRender osg::ref_ptr getTag() const; void recreateGeometry(); + void removeGeometry(); + + void update(); private: @@ -96,6 +99,9 @@ namespace CSVRender bool mConnectionIndicator; unsigned short mConnectionNode; + bool mChangeGeometry; + bool mRemoveGeometry; + osg::Group* mParent; osg::ref_ptr mBaseNode; osg::ref_ptr mSelectedNode; @@ -106,8 +112,9 @@ namespace CSVRender osg::ref_ptr mTag; - void recreateSelectedGeometry(); - void recreateSelectedGeometry(const CSMWorld::Pathgrid& source); + void createGeometry(); + void createSelectedGeometry(); + void createSelectedGeometry(const CSMWorld::Pathgrid& source); void removePathgridGeometry(); void removeSelectedGeometry(); diff --git a/apps/opencs/view/render/unpagedworldspacewidget.cpp b/apps/opencs/view/render/unpagedworldspacewidget.cpp index 802194bea..d9a85fe35 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.cpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.cpp @@ -212,32 +212,28 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& { const CSMWorld::SubCellCollection& pathgrids = mDocument.getData().getPathgrids(); + int rowStart = -1; + int rowEnd = -1; + if (topLeft.parent().isValid()) { - int row = topLeft.parent().row(); - - const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); - if (mCellId == pathgrid.mId) - { - mCell->pathgridDataChanged(topLeft, bottomRight); - flagAsModified(); - } + rowStart = topLeft.parent().row(); + rowEnd = bottomRight.parent().row(); + } + else + { + rowStart = topLeft.row(); + rowEnd = bottomRight.row(); } -} - -void CSVRender::UnpagedWorldspaceWidget::pathgridRemoved (const QModelIndex& parent, int start, int end) -{ - const CSMWorld::SubCellCollection& pathgrids = mDocument.getData().getPathgrids(); - - if (parent.isValid()){ - // Pathgrid data was modified - int row = parent.row(); + for (int row = rowStart; row <= rowEnd; ++row) + { const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); if (mCellId == pathgrid.mId) { - mCell->pathgridRowRemoved(parent, start, end); + mCell->pathgridModified(); flagAsModified(); + return; } } } @@ -256,6 +252,7 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridAboutToBeRemoved (const QModelI { mCell->pathgridRemoved(); flagAsModified(); + return; } } } @@ -267,29 +264,17 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridAdded (const QModelIndex& paren if (!parent.isValid()) { - // Pathgrid added theoretically, unable to test until it is possible to add pathgrids for (int row = start; row <= end; ++row) { const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); if (mCellId == pathgrid.mId) { - mCell->pathgridAdded(pathgrid); + mCell->pathgridModified(); flagAsModified(); + return; } } } - else - { - // Pathgrid data was modified - int row = parent.row(); - - const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); - if (mCellId == pathgrid.mId) - { - mCell->pathgridRowAdded(parent, start, end); - flagAsModified(); - } - } } void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons ( diff --git a/apps/opencs/view/render/unpagedworldspacewidget.hpp b/apps/opencs/view/render/unpagedworldspacewidget.hpp index dd4a8a2f7..57e8d1a19 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.hpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.hpp @@ -91,8 +91,6 @@ namespace CSVRender virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); - virtual void pathgridRemoved (const QModelIndex& parent, int start, int end); - virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end); virtual void pathgridAdded (const QModelIndex& parent, int start, int end); diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 64c1be0ee..ec40d880a 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -63,8 +63,6 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg connect (pathgrids, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), this, SLOT (pathgridDataChanged (const QModelIndex&, const QModelIndex&))); - connect (pathgrids, SIGNAL (rowsRemoved (const QModelIndex&, int, int)), - this, SLOT (pathgridRemoved (const QModelIndex&, int, int))); connect (pathgrids, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), this, SLOT (pathgridAboutToBeRemoved (const QModelIndex&, int, int))); connect (pathgrids, SIGNAL (rowsInserted (const QModelIndex&, int, int)), diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index 59aacca29..e6cd7aab0 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -246,8 +246,6 @@ namespace CSVRender virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) = 0; - virtual void pathgridRemoved (const QModelIndex& parent, int start, int end) = 0; - virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end) = 0; virtual void pathgridAdded (const QModelIndex& parent, int start, int end) = 0;