Skip to content

Commit

Permalink
[MT Export/Import] Fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgang-ch committed Apr 1, 2022
1 parent a34f9a9 commit 089ac34
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ private void parseXML_050_Waypoints(final XMLEventReader eventReader) throws XML
private void parseXML_052_Waypoint(final XMLEventReader eventReader,
final StartElement startElement_WayPoint) throws XMLStreamException {

final TourWayPoint tourWayPoint = new TourWayPoint();
final TourWayPoint tourWayPoint = new TourWayPoint(_tourData);

startElement_WayPoint.getAttributes().forEachRemaining(attribute -> setValues_WayPoint_Attributes(tourWayPoint, attribute));

Expand Down
24 changes: 11 additions & 13 deletions bundles/net.tourbook.export/format-templates/mt-1.0.vm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#end

tourStartTime ="$tourData.getTourStartTime()"
timeZoneId ="$tourData.getTimeZoneId()"
#if ($tourData.timeZoneId)
timeZoneId ="$tourData.timeZoneId"
#end
tourComputedTime_Moving ="$tourData.tourComputedTime_Moving"
tourDeviceTime_Elapsed ="$tourData.tourDeviceTime_Elapsed"
tourDeviceTime_Paused ="$tourData.tourDeviceTime_Paused"
Expand Down Expand Up @@ -239,10 +241,9 @@
## WAYPOINTS WAYPOINTS WAYPOINTS WAYPOINTS WAYPOINTS WAYPOINTS WAYPOINTS WAYPOINTS WAYPOINTS
##
##
#if($tourData.getTourWayPoints().size() > 0)
#if($allSorted_WayPoints.size() > 0)
<waypoints>
#set ($allWayPoints = $tourData.getTourWayPoints())
#foreach ($wayPoint in $allWayPoints)
#foreach ($wayPoint in $allSorted_WayPoints)
<waypoint
wayPointId ="$wayPoint.wayPointId"
time ="$wayPoint.time"
Expand All @@ -266,10 +267,9 @@
## TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS TAGS
##
##
#if($tourData.getTourTags().size() > 0)
#if($allSorted_Tags.size() > 0)
<tags>
#set ($tags = $tourData.getTourTags())
#foreach ($tag in $tags)
#foreach ($tag in $allSorted_Tags)
<tag>
<name><![CDATA[$!tag.getTagName()]]></name>
</tag>
Expand All @@ -281,10 +281,9 @@
## PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS PHOTOS
##
##
#if ($tourData.getTourPhotos().size() > 0)
#set ($photos = $tourData.getTourPhotos())
#if ($allSorted_Photos.size() > 0)
<photos>
#foreach ($photo in $photos)
#foreach ($photo in $allSorted_Photos)
<photo
photoId ="$photo.getPhotoId()"
imageExifTime ="$photo.getImageExifTime()"
Expand All @@ -305,10 +304,9 @@
## SENSOR SENSOR SENSOR SENSOR SENSOR SENSOR SENSOR SENSOR SENSOR SENSOR SENSOR SENSOR
##
##
#if ($tourData.getDeviceSensorValues().size() > 0)
#set ($allSensors = $tourData.getDeviceSensorValues())
#if ($allSorted_SensorValues).size() > 0)
<sensorvalues>
#foreach ($sensor in $allSensors)
#foreach ($sensor in $allSorted_SensorValues)
<sensorvalue
sensorValueId ="$sensor.getSensorValueId()"
sensorId ="$sensor.getDeviceSensor().getSensorId()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
Expand All @@ -40,9 +41,12 @@
import net.tourbook.Messages;
import net.tourbook.common.UI;
import net.tourbook.common.util.StatusUtil;
import net.tourbook.data.DeviceSensorValue;
import net.tourbook.data.SerieData;
import net.tourbook.data.TourData;
import net.tourbook.data.TourMarker;
import net.tourbook.data.TourPhoto;
import net.tourbook.data.TourTag;
import net.tourbook.data.TourWayPoint;
import net.tourbook.database.TourDatabase;

Expand All @@ -65,16 +69,11 @@ public class TourExporter {
/*
* Velocity (VC) context values
*/
private static final String VC_HAS_TOUR_MARKERS = "hasTourMarkers"; //$NON-NLS-1$
private static final String VC_HAS_TRACKS = "hasTracks"; //$NON-NLS-1$
private static final String VC_HAS_WAY_POINTS = "hasWayPoints"; //$NON-NLS-1$
private static final String VC_IS_EXPORT_ALL_TOUR_DATA = "isExportAllTourData"; //$NON-NLS-1$

private static final String VC_TOUR_MARKERS = "tourMarkers"; //$NON-NLS-1$
private static final String VC_TRACKS = "tracks"; //$NON-NLS-1$
private static final String VC_WAY_POINTS = "wayPoints"; //$NON-NLS-1$
private static final String VC_LAP = "lap"; //$NON-NLS-1$
private static final String VC_TOUR_DATA = "tourData"; //$NON-NLS-1$

/**
* This is a special parameter to force elevation values from the device and not from the lat/lon
Expand Down Expand Up @@ -190,7 +189,40 @@ public boolean doExport_10_Tour(final List<GarminTrack> tracks,
final List<TourMarker> tourMarkers,
final GarminLap lap,
final String exportFileName) throws IOException {
/*
* Create sorted lists that the comparision of before and after (export and import/export) can
* be done easily
*/
final ArrayList<DeviceSensorValue> allSorted_SensorValues = new ArrayList<>(_tourData.getDeviceSensorValues());
Collections.sort(allSorted_SensorValues, (sensorValue1, sensorValue2) -> {

return sensorValue1.getDeviceSensor().getLabel().compareTo(
sensorValue2.getDeviceSensor().getLabel());
});

final ArrayList<TourWayPoint> allSorted_WayPoints = new ArrayList<>(_tourData.getTourWayPoints());
Collections.sort(allSorted_WayPoints, (item1, item2) -> {

return item1.getName().compareTo(item2.getName());
});

final ArrayList<TourTag> allSorted_Tags = new ArrayList<>(_tourData.getTourTags());
Collections.sort(allSorted_Tags, (item1, item2) -> {

return item1.getTagName().compareTo(item2.getTagName());
});

final ArrayList<TourPhoto> allSorted_Photos = new ArrayList<>(_tourData.getTourPhotos());
Collections.sort(allSorted_Photos, (item1, item2) -> {

return Long.compare(item1.getImageExifTime(), item2.getImageExifTime());
});

final SerieData serieData = _tourData.getSerieData();

/*
* Setup context
*/
final File exportFile = new File(exportFileName);
final VelocityContext vc = new VelocityContext();

Expand All @@ -207,25 +239,28 @@ public boolean doExport_10_Tour(final List<GarminTrack> tracks,
vc.put("coursename", _courseName); //$NON-NLS-1$
}

final SerieData serieData = _tourData.getSerieData();

// SET_FORMATTING_OFF

vc.put(VC_LAP, lap);
vc.put(VC_TRACKS, tracks);
vc.put(VC_WAY_POINTS, wayPoints);
vc.put(VC_TOUR_MARKERS, tourMarkers);
vc.put(VC_TOUR_DATA, _tourData);

vc.put(VC_HAS_TOUR_MARKERS, Boolean.valueOf(tourMarkers.size() > 0));
vc.put(VC_HAS_TRACKS, Boolean.valueOf(tracks.size() > 0));
vc.put(VC_HAS_WAY_POINTS, Boolean.valueOf(wayPoints.size() > 0));

vc.put("dateformat", _dateFormat); // //$NON-NLS-1$
vc.put("dtIso", _dtIso); // //$NON-NLS-1$
vc.put("nf1", _nf1); // //$NON-NLS-1$
vc.put("nf3", _nf3); // //$NON-NLS-1$
vc.put("nf8", _nf8); // //$NON-NLS-1$
vc.put("lap", lap ); //$NON-NLS-1$
vc.put("tracks", tracks ); //$NON-NLS-1$
vc.put("wayPoints", wayPoints ); //$NON-NLS-1$
vc.put("tourMarkers", tourMarkers ); //$NON-NLS-1$
vc.put("tourData", _tourData ); //$NON-NLS-1$

vc.put("hasTourMarkers", Boolean.valueOf(tourMarkers.size() > 0) ); //$NON-NLS-1$
vc.put("hasTracks", Boolean.valueOf(tracks.size() > 0) ); //$NON-NLS-1$
vc.put("hasWayPoints", Boolean.valueOf(wayPoints.size() > 0) ); //$NON-NLS-1$

vc.put("allSorted_Photos", allSorted_Photos ); //$NON-NLS-1$
vc.put("allSorted_SensorValues", allSorted_SensorValues ); //$NON-NLS-1$
vc.put("allSorted_Tags", allSorted_Tags ); //$NON-NLS-1$
vc.put("allSorted_WayPoints", allSorted_WayPoints ); //$NON-NLS-1$

vc.put("dateformat", _dateFormat ); //$NON-NLS-1$
vc.put("dtIso", _dtIso ); //$NON-NLS-1$
vc.put("nf1", _nf1 ); //$NON-NLS-1$
vc.put("nf3", _nf3 ); //$NON-NLS-1$
vc.put("nf8", _nf8 ); //$NON-NLS-1$

/*
* Export raw serie data
Expand Down
12 changes: 12 additions & 0 deletions bundles/net.tourbook/src/net/tourbook/data/TourWayPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ public class TourWayPoint implements Cloneable, Comparable<Object>, IHoveredArea

public TourWayPoint() {}

/**
* Used for MT import/export
*
* @param tourData
*/
public TourWayPoint(final TourData tourData) {

this.tourData = tourData;

_createId = _createCounter.incrementAndGet();
}

public TourWayPoint clone(final TourData wpTourData) {

try {
Expand Down
4 changes: 4 additions & 0 deletions bundles/net.tourbook/src/net/tourbook/map2/view/Map2View.java
Original file line number Diff line number Diff line change
Expand Up @@ -4616,6 +4616,10 @@ private void setVisibleDataPoints(final TourData tourData) {
return;
}

if (tourData == null) {
return;
}

final int[] timeSerie = tourData.timeSerie;
if (timeSerie == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,10 @@ public ColumnManager getColumnManager() {
public ArrayList<TourData> getSelectedTours() {

final ArrayList<TourData> selectedTours = new ArrayList<>();
selectedTours.add(_tourData);

if (_tourData != null) {
selectedTours.add(_tourData);
}

return selectedTours;
}
Expand Down
3 changes: 2 additions & 1 deletion info/release-notes/22.3.0-readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ Improvements

* MT Export/Import https://github.com/mytourbook/mytourbook/issues/493
- Export and import all values of a tour
- Limits:
- Limits/behavior:
- A device sensor is not created, when sensor values for it are available
- Body weight is overwritten when tour is saved and when "Set the persons's weight ..." is selected in the "Import" preferences

Changes
=======
Expand Down

0 comments on commit 089ac34

Please sign in to comment.