diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt index 9266a9a8f45..5739e28386c 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxFile.kt @@ -53,6 +53,26 @@ class GpxFile : GpxExtensions { } } + constructor(other: GpxFile) { + this.author = other.author + this.metadata = Metadata(other.metadata) + this.tracks = other.tracks.map { Track(it) }.toMutableList() + this.routes = other.routes.map { Route(it) }.toMutableList() + this.points = other.points.map { WptPt(it) }.toMutableList() + this.pointsGroups = other.pointsGroups.mapValues { PointsGroup(it.value) }.toMutableMap() + this.networkRouteKeyTags.putAll(other.networkRouteKeyTags) + + this.error = other.error + this.path = other.path + this.showCurrentTrack = other.showCurrentTrack + this.hasAltitude = other.hasAltitude + this.modifiedTime = other.modifiedTime + this.pointsModifiedTime = other.pointsModifiedTime + + this.generalTrack = other.generalTrack?.let { Track(it) } + this.generalSegment = other.generalSegment?.let { TrkSegment(it) } + } + fun isShowCurrentTrack() = showCurrentTrack fun hasAltitude() = hasAltitude diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt index bdd2b7a8b58..eacce33bb5c 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/GpxUtilities.kt @@ -202,6 +202,23 @@ object GpxUtilities { var pointTypes: String? = null var names: String? = null + constructor() + + constructor(other: RouteSegment) { + this.id = other.id + this.length = other.length + this.startTrackPointIndex = other.startTrackPointIndex + this.segmentTime = other.segmentTime + this.speed = other.speed + this.turnType = other.turnType + this.turnLanes = other.turnLanes + this.turnAngle = other.turnAngle + this.skipTurn = other.skipTurn + this.types = other.types + this.pointTypes = other.pointTypes + this.names = other.names + } + companion object { const val START_TRKPT_IDX_ATTR = "startTrkptIdx" @@ -245,6 +262,13 @@ object GpxUtilities { var tag: String? = null var value: String? = null + constructor() + + constructor(routeType: RouteType) { + this.tag = routeType.tag + this.value = routeType.value + } + companion object { fun fromStringBundle(bundle: StringBundle): RouteType { val t = RouteType() @@ -283,6 +307,14 @@ object GpxUtilities { backgroundType = point.getBackgroundType() } + constructor(other: PointsGroup) : this(other.name) { + this.iconName = other.iconName + this.backgroundType = other.backgroundType + this.points = other.points.map { WptPt(it) }.toMutableList() + this.color = other.color + this.hidden = other.hidden + } + fun isHidden(): Boolean { return hidden } diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Route.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Route.kt index 8666ae45847..601bff8a82e 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Route.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Route.kt @@ -1,7 +1,16 @@ package net.osmand.shared.gpx.primitives -class Route : GpxExtensions() { +class Route : GpxExtensions { var name: String? = null var desc: String? = null var points = mutableListOf() + + constructor() + + constructor(other: Route) { + this.name = other.name + this.desc = other.desc + this.points = other.points.map { WptPt(it) }.toMutableList() + copyExtensions(other) + } } \ No newline at end of file diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Track.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Track.kt index 190fce6e9ca..4730f52c72d 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Track.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/Track.kt @@ -1,10 +1,19 @@ package net.osmand.shared.gpx.primitives -class Track : GpxExtensions() { +class Track : GpxExtensions { var name: String? = null var desc: String? = null var segments = mutableListOf() var generalTrack = false + constructor() + + constructor(other: Track) : this() { + this.name = other.name + this.desc = other.desc + this.segments.addAll(other.segments.map { TrkSegment(it) }) + this.generalTrack = other.generalTrack + } + fun isGeneralTrack() = generalTrack } \ No newline at end of file diff --git a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/TrkSegment.kt b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/TrkSegment.kt index bf391d32dc4..2533360bb20 100644 --- a/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/TrkSegment.kt +++ b/OsmAnd-shared/src/commonMain/kotlin/net/osmand/shared/gpx/primitives/TrkSegment.kt @@ -5,7 +5,7 @@ import net.osmand.shared.gpx.GpxUtilities import net.osmand.shared.gpx.SplitMetric import net.osmand.shared.gpx.SplitSegment -class TrkSegment : GpxExtensions() { +class TrkSegment : GpxExtensions { var name: String? = null var generalSegment = false var points = mutableListOf() @@ -13,6 +13,17 @@ class TrkSegment : GpxExtensions() { var routeSegments = mutableListOf() var routeTypes = mutableListOf() + constructor() + + constructor(segment: TrkSegment) { + this.name = segment.name + this.generalSegment = segment.generalSegment + this.renderer = segment.renderer + this.routeSegments.addAll(segment.routeSegments.map { GpxUtilities.RouteSegment(it) }) + this.routeTypes.addAll(segment.routeTypes.map { GpxUtilities.RouteType(it) }) + this.points.addAll(segment.points.map { WptPt(it) }) + } + fun isGeneralSegment() = generalSegment fun hasRoute(): Boolean { diff --git a/OsmAnd/src/net/osmand/plus/track/fragments/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/fragments/TrackMenuFragment.java index 1ba78aeb8c1..317fe6b52e3 100644 --- a/OsmAnd/src/net/osmand/plus/track/fragments/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/fragments/TrackMenuFragment.java @@ -151,6 +151,7 @@ import net.osmand.shared.gpx.RouteActivityHelper; import net.osmand.shared.gpx.primitives.Metadata; import net.osmand.shared.gpx.primitives.RouteActivity; +import net.osmand.shared.gpx.primitives.Track; import net.osmand.shared.gpx.primitives.TrkSegment; import net.osmand.shared.gpx.primitives.WptPt; import net.osmand.util.Algorithms; @@ -402,6 +403,10 @@ public LatLon getLatLon() { return latLon; } + public GpxFile getGpxCopy() { + return new GpxFile(getGpx()); + } + public GpxFile getGpx() { return displayHelper.getGpx(); } @@ -1644,7 +1649,7 @@ public void onRouteSelected(@NonNull GpxFile gpxFile, int selectedRoute) { public void openPlanRoute(int segmentIndex, @MeasurementToolMode int mode) { MapActivity activity = getMapActivity(); if (activity != null) { - GpxFile gpxFile = getGpx(); + GpxFile gpxFile = getGpxCopy(); MeasurementToolFragment.showInstance(activity, gpxFile, segmentIndex, mode); } hide();