diff --git a/apps/opencs/model/world/columnimp.hpp b/apps/opencs/model/world/columnimp.hpp index 27fc3ad04..70c134e01 100644 --- a/apps/opencs/model/world/columnimp.hpp +++ b/apps/opencs/model/world/columnimp.hpp @@ -2289,6 +2289,28 @@ namespace CSMWorld } }; + template + struct PathgridIndexColumn : public Column + { + PathgridIndexColumn() + : Column (Columns::ColumnId_PathgridIndex, ColumnBase::Display_Integer) + {} + + virtual QVariant get (const Record& record) const + { + return QVariant(); // FIXME + } + + virtual void set (Record& record, const QVariant& data) + { + } + + virtual bool isEditable() const + { + return false; + } + }; + template struct PathgridPointColumn : public Column { @@ -2338,6 +2360,28 @@ namespace CSMWorld }; + template + struct PathgridEdgeIndexColumn : public Column + { + PathgridEdgeIndexColumn() + : Column (Columns::ColumnId_PathgridEdgeIndex, ColumnBase::Display_Integer) + {} + + virtual QVariant get (const Record& record) const + { + return QVariant(); // FIXME + } + + virtual void set (Record& record, const QVariant& data) + { + } + + virtual bool isEditable() const + { + return false; + } + }; + template struct PathgridEdgeColumn : public Column { diff --git a/apps/opencs/model/world/columns.cpp b/apps/opencs/model/world/columns.cpp index db0ebfd86..e6a27138f 100644 --- a/apps/opencs/model/world/columns.cpp +++ b/apps/opencs/model/world/columns.cpp @@ -224,12 +224,14 @@ namespace CSMWorld { ColumnId_BoltSound, "Bolt Sound" }, { ColumnId_PathgridPoints, "Points"}, + { ColumnId_PathgridIndex, "Index"}, { ColumnId_PathgridPosX, "X"}, { ColumnId_PathgridPosY, "Y"}, { ColumnId_PathgridPosZ, "Z"}, { ColumnId_PathgridEdges, "Edges"}, - { ColumnId_PathgridEdge0, "Edge 0"}, - { ColumnId_PathgridEdge1, "Edge 1"}, + { ColumnId_PathgridEdgeIndex, "Index"}, + { ColumnId_PathgridEdge0, "Point 0"}, + { ColumnId_PathgridEdge1, "Point 1"}, { ColumnId_UseValue1, "Use value 1" }, { ColumnId_UseValue2, "Use value 2" }, diff --git a/apps/opencs/model/world/columns.hpp b/apps/opencs/model/world/columns.hpp index e36e29b3b..2cb7101b0 100644 --- a/apps/opencs/model/world/columns.hpp +++ b/apps/opencs/model/world/columns.hpp @@ -213,12 +213,14 @@ namespace CSMWorld ColumnId_BoltSound = 198, ColumnId_PathgridPoints = 199, - ColumnId_PathgridPosX = 200, - ColumnId_PathgridPosY = 201, - ColumnId_PathgridPosZ = 202, - ColumnId_PathgridEdges = 203, - ColumnId_PathgridEdge0 = 204, - ColumnId_PathgridEdge1 = 205, + ColumnId_PathgridIndex = 200, + ColumnId_PathgridPosX = 201, + ColumnId_PathgridPosY = 202, + ColumnId_PathgridPosZ = 203, + ColumnId_PathgridEdges = 204, + ColumnId_PathgridEdgeIndex = 205, + ColumnId_PathgridEdge0 = 206, + ColumnId_PathgridEdge1 = 207, // Allocated to a separate value range, so we don't get a collision should we ever need // to extend the number of use values. diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index ea94fe905..76e34961f 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -262,6 +262,8 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc // new object deleted in dtor of SubCellCollection mPathgrids.addAdapter (std::make_pair(pointList, new PathgridPointListAdapter ())); // new objects deleted in dtor of NestableColumn + // WARNING: The order of the columns below are assumed in PathgridPointListAdapter + mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridIndexColumn ()); mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn (0)); mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn (1)); mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridPointColumn (2)); @@ -269,6 +271,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc PathgridEdgeListColumn *edgeList = new PathgridEdgeListColumn (); mPathgrids.addColumn (edgeList); mPathgrids.addAdapter (std::make_pair(edgeList, new PathgridEdgeListAdapter ())); + mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeIndexColumn ()); mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeColumn (0)); mPathgrids.getNestableColumn(mPathgrids.getColumns()-1)->addColumn(new PathgridEdgeColumn (1)); diff --git a/apps/opencs/model/world/idadapterimp.hpp b/apps/opencs/model/world/idadapterimp.hpp index 510a14f12..f5ed2e6e1 100644 --- a/apps/opencs/model/world/idadapterimp.hpp +++ b/apps/opencs/model/world/idadapterimp.hpp @@ -33,6 +33,9 @@ namespace CSMWorld point.mUnknown = 0; // inserting a point should trigger re-indexing of the edges + // + // FIXME: undo does not restore edges table view + // FIXME: does not auto refresh edges table view std::vector::iterator iter = pathgrid.mEdges.begin(); for (;iter != pathgrid.mEdges.end(); ++iter) { @@ -59,19 +62,25 @@ namespace CSMWorld // deleting a point should trigger re-indexing of the edges // dangling edges are not allowed and hence removed + // + // FIXME: undo does not restore edges table view + // FIXME: does not auto refresh edges table view std::vector::iterator iter = pathgrid.mEdges.begin(); - for (;iter != pathgrid.mEdges.end(); ++iter) + for (; iter != pathgrid.mEdges.end();) { if (((*iter).mV0 == rowToRemove) || ((*iter).mV1 == rowToRemove)) - pathgrid.mEdges.erase(iter); + iter = pathgrid.mEdges.erase(iter); + else + { + if ((*iter).mV0 > rowToRemove) + (*iter).mV0--; - if ((*iter).mV0 >= rowToRemove) - (*iter).mV0--; + if ((*iter).mV1 > rowToRemove) + (*iter).mV1--; - if ((*iter).mV1 >= rowToRemove) - (*iter).mV1--; + ++iter; + } } - points.erase(points.begin()+rowToRemove); pathgrid.mData.mS2 -= 1; // decrement the number of points @@ -95,9 +104,10 @@ namespace CSMWorld ESM::Pathgrid::Point point = record.get().mPoints[subRowIndex]; switch (subColIndex) { - case 0: return point.mX; - case 1: return point.mY; - case 2: return point.mZ; + case 0: return subRowIndex; + case 1: return point.mX; + case 2: return point.mY; + case 3: return point.mZ; default: throw std::logic_error("Pathgrid point subcolumn index out of range"); } } @@ -109,9 +119,10 @@ namespace CSMWorld ESM::Pathgrid::Point point = pathgrid.mPoints[subRowIndex]; switch (subColIndex) { - case 0: point.mX = value.toInt(); break; - case 1: point.mY = value.toInt(); break; - case 2: point.mZ = value.toInt(); break; + case 0: break; + case 1: point.mX = value.toInt(); break; + case 2: point.mY = value.toInt(); break; + case 3: point.mZ = value.toInt(); break; default: throw std::logic_error("Pathgrid point subcolumn index out of range"); } @@ -122,7 +133,7 @@ namespace CSMWorld virtual int getNestedColumnsCount(const Record& record) const { - return 3; + return 4; } virtual int getNestedRowsCount(const Record& record) const @@ -149,8 +160,11 @@ namespace CSMWorld edge.mV0 = 0; edge.mV1 = 0; - // FIXME: inserting a blank edge does not really make sense, perhaps this should be a + // NOTE: inserting a blank edge does not really make sense, perhaps this should be a // logic_error exception + // + // Currently the code assumes that the end user to know what he/she is doing. + // e.g. Edges come in pairs, from points a->b and b->a edges.insert(edges.begin()+position, edge); record.setModified (pathgrid); @@ -187,12 +201,14 @@ namespace CSMWorld ESM::Pathgrid::Edge edge = record.get().mEdges[subRowIndex]; switch (subColIndex) { - case 0: return edge.mV0; - case 1: return edge.mV1; + case 0: return subRowIndex; + case 1: return edge.mV0; + case 2: return edge.mV1; default: throw std::logic_error("Pathgrid edge subcolumn index out of range"); } } + // FIXME: detect duplicates in mEdges virtual void setNestedData(Record& record, const QVariant& value, int subRowIndex, int subColIndex) const { @@ -200,8 +216,9 @@ namespace CSMWorld ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex]; switch (subColIndex) { - case 0: edge.mV0 = value.toInt(); break; - case 1: edge.mV1 = value.toInt(); break; + case 0: break; + case 1: edge.mV0 = value.toInt(); break; + case 2: edge.mV1 = value.toInt(); break; default: throw std::logic_error("Pathgrid edge subcolumn index out of range"); } @@ -212,7 +229,7 @@ namespace CSMWorld virtual int getNestedColumnsCount(const Record& record) const { - return 2; + return 3; } virtual int getNestedRowsCount(const Record& record) const