From 5d451be151b27e9a2632b07f08ff68bc76c57f42 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 7 Jun 2009 20:28:26 +0100 Subject: [PATCH] Saving points to XML --- schemas/map.xsd | 13 +++++++++++-- src/Map.cpp | 19 +++++++++++++++++++ src/Points.cpp | 26 +++++++++++++++++--------- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/schemas/map.xsd b/schemas/map.xsd index 17490af..eeb403d 100644 --- a/schemas/map.xsd +++ b/schemas/map.xsd @@ -9,8 +9,8 @@ - - + + @@ -42,6 +42,15 @@ + + + + + + + setTrackAt(makePoint(myXPtr, myYPtr), + makePoints(dir, reflect)); + } + void handleCurvedTrack(const AttributeSet& attrs) { int startAngle, finishAngle, radius; diff --git a/src/Points.cpp b/src/Points.cpp index 89c3b60..2611c84 100644 --- a/src/Points.cpp +++ b/src/Points.cpp @@ -96,21 +96,23 @@ void Points::render() const double Points::segmentLength() const { - return 2.0; + return 3.0; } void Points::transform(const track::Direction& aDirection, double aDelta) const { - assert(aDelta < 2.0); + assert(aDelta < 3.0); if (aDirection == -myAxis) - aDelta = 2.0 - aDelta; + aDelta = 3.0 - aDelta; const double xTrans = - myAxis == axis::X || myAxis == -axis::X ? aDelta : 0.0; + myAxis == axis::X ? 3.0 - aDelta + : (myAxis == -axis::X ? aDelta : 0.0); const double yTrans = - myAxis == axis::Y || myAxis == -axis::Y ? aDelta : 0.0; + myAxis == axis::Y ? 3.0 - aDelta + : (myAxis == -axis::Y ? aDelta : 0.0); glTranslatef(static_cast(myX) - xTrans, 0.0, @@ -158,13 +160,13 @@ track::Connection Points::nextPosition(const track::Direction& aDirection) const ensureValidDirection(aDirection); if (aDirection == axis::X) - return make_pair(makePoint(myX + 3, myY), axis::X); + return make_pair(makePoint(myX + 1, myY), axis::X); else if (aDirection == -axis::X) return make_pair(makePoint(myX - 3, myY), -axis::X); else if (aDirection == axis::Y) return make_pair(makePoint(myX, myY + 3), axis::Y); else if (aDirection == -axis::Y) - return make_pair(makePoint(myX, myY - 3), -axis::Y); + return make_pair(makePoint(myX, myY - 1), -axis::Y); else assert(false); } @@ -201,8 +203,14 @@ ITrackSegmentPtr Points::mergeExit(const Point& aPoint, } xml::element Points::toXml() const -{ - +{ + return xml::element("points") + .addAttribute("align", + myAxis == axis::X ? "x" + : (myAxis == -axis::X ? "-x" + : (myAxis == axis::Y ? "y" + : (myAxis == -axis::Y ? "-y" : "?")))) + .addAttribute("reflect", amReflected); } ITrackSegmentPtr makePoints(track::Direction aDirection, bool reflect) -- 2.39.2