Subversion Repositories public

Rev

Rev 280 | Rev 291 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 280 Rev 283
Line 54... Line 54...
54
#if defined HAVE_GDAL
54
#if defined HAVE_GDAL
55
   #include <gdal/ogr_spatialref.h>
55
   #include <gdal/ogr_spatialref.h>
56
   #include <gdal/ogrsf_frmts.h>
56
   #include <gdal/ogrsf_frmts.h>
57
   #include <gdal/gdalwarper.h>
57
   #include <gdal/gdalwarper.h>
58
   #include <gdal/ogrsf_frmts.h>
58
   #include <gdal/ogrsf_frmts.h>
-
 
59
   #include "GDALError.h"
59
#endif
60
#endif
60
 
61
 
61
#include "garmin.h"
62
#include "garmin.h"
62
#include "transform.h"
63
#include "transform.h"
63
#include "import.h"
64
#include "import.h"
Line 76... Line 77...
76
{
77
{
77
	double lon;
78
	double lon;
78
	double lat;
79
	double lat;
79
} posn_type;
80
} posn_type;
80
 
81
 
-
 
82
#if defined HAVE_GDAL
-
 
83
typedef struct ERRMSG
-
 
84
{
-
 
85
	char msg[4096];
-
 
86
	ERRMSG *next;
-
 
87
}ERRMSG;
-
 
88
 
-
 
89
ERRMSG *firstError;
-
 
90
#endif
-
 
91
 
81
sportwatcherWidget::sportwatcherWidget(QWidget *parent)
92
sportwatcherWidget::sportwatcherWidget(QWidget *parent)
82
{
93
{
83
	ui_sportwatcherWidgetBase.setupUi(this);
94
	ui_sportwatcherWidgetBase.setupUi(this);
84
 
95
 
85
#if defined HAVE_GDAL
96
#if defined HAVE_GDAL
86
	mFactor = 10;		// Factor to calculate square pixels
97
	mFactor = 10;		// Factor to calculate square pixels
-
 
98
	firstError = 0;
87
#endif
99
#endif
88
	mama = parent;
100
	mama = parent;
89
	gmn = 0;
101
	gmn = 0;
90
	min_hr = max_hr = avg_hr = 0;
102
	min_hr = max_hr = avg_hr = 0;
91
	min_height = max_height = 0.0;
103
	min_height = max_height = 0.0;
Line 123... Line 135...
123
	Data = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher");
135
	Data = ic.readEntry("Data", QDir::home().absolutePath() + "/.sportwatcher");
124
	HRM = ic.readEntry("HRM", QDir::home().absolutePath() + "/polar");
136
	HRM = ic.readEntry("HRM", QDir::home().absolutePath() + "/polar");
125
	MAP = ic.readEntry("MAP", QDir::home().absolutePath() + "/.sportwatcher/track.wms");
137
	MAP = ic.readEntry("MAP", QDir::home().absolutePath() + "/.sportwatcher/track.wms");
126
	Units = ic.readEntry("Units", 0);
138
	Units = ic.readEntry("Units", 0);
127
	MapType = ic.readEntry("MapType", 7);
139
	MapType = ic.readEntry("MapType", 7);
-
 
140
#ifdef HAVE_GDAL
-
 
141
	// set our own error handler here
-
 
142
	CPLSetErrorHandler((CPLErrorHandler)spwErrorHandler);
-
 
143
#endif
-
 
144
 
128
}
145
}
129
 
146
 
130
sportwatcherWidget::~sportwatcherWidget()
147
sportwatcherWidget::~sportwatcherWidget()
131
{
148
{
132
	destroy();
149
	destroy();
133
	delete kl;
150
	delete kl;
-
 
151
#ifdef HAVE_GDAL
-
 
152
	// destroy the error handler here
-
 
153
	CPLSetErrorHandler(NULL);
-
 
154
#endif
134
}
155
}
135
 
156
 
136
void sportwatcherWidget::destroy()
157
void sportwatcherWidget::destroy()
137
{
158
{
138
	if (gmn)
159
	if (gmn)
Line 673... Line 694...
673
	   return;
694
	   return;
674
 
695
 
675
	// We dont care about page margins of a printer. Instead we assume
696
	// We dont care about page margins of a printer. Instead we assume
676
	// a frame from about 20mm arround the page. European paper size is
697
	// a frame from about 20mm arround the page. European paper size is
677
	// A4 (210x297mm) and the output is optimized for this.
698
	// A4 (210x297mm) and the output is optimized for this.
-
 
699
	totdist = 0;
678
	extMil[0] = 20.0;
700
	extMil[0] = 20.0;
679
	extMil[1] = 20.0;
701
	extMil[1] = 20.0;
680
	extMil[2] = 210.0 - 20.0;
702
	extMil[2] = 210.0 - 20.0;
681
	extMil[3] = 279.0 - 20.0;
703
	extMil[3] = 279.0 - 20.0;
682
	lineH = 4.5;	// The height of a line with 10pt letters
704
	lineH = 4.5;	// The height of a line with 10pt letters
Line 2912... Line 2934...
2912
	   zfactor = zoom;
2934
	   zfactor = zoom;
2913
 
2935
 
2914
	if (mapLap != lap)
2936
	if (mapLap != lap)
2915
	   mapLap = lap;
2937
	   mapLap = lap;
2916
 
2938
 
-
 
2939
	y2 = x2 = 0;
2917
#if defined HAVE_GDAL
2940
#if defined HAVE_GDAL
-
 
2941
	nXSize = nYSize = 0;
2918
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
2942
	KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
2919
	KConfigGroup wms (&cfg, "WMS");
2943
	KConfigGroup wms (&cfg, "WMS");
2920
	bool square = wms.readEntry("Square", false);
2944
	bool square = wms.readEntry("Square", false);
2921
	int CorrX = wms.readEntry("CorrX", 0);
2945
	int CorrX = wms.readEntry("CorrX", 0);
2922
	int CorrY = wms.readEntry("CorrY", 0);
2946
	int CorrY = wms.readEntry("CorrY", 0);
Line 3110... Line 3134...
3110
		 int             bGotMin, bGotMax;
3134
		 int             bGotMin, bGotMax;
3111
		 int		 tTypeLen, tColor, tColorEntrys;
3135
		 int		 tTypeLen, tColor, tColorEntrys;
3112
		 GDALDataType    tRasterType;
3136
		 GDALDataType    tRasterType;
3113
		 double          adfMinMax[2];
3137
		 double          adfMinMax[2];
3114
 
3138
 
-
 
3139
		 pCT = pCTb = pCTr = pCTg = pCTa = 0;
-
 
3140
		 tTypeLen = 0;
3115
		 pafScanlineRed = pafScanlineGreen = pafScanlineBlue = pafScanlineAlpha = 0;
3141
		 pafScanlineRed = pafScanlineGreen = pafScanlineBlue = pafScanlineAlpha = 0;
3116
		 Fgeo = true;
3142
		 Fgeo = true;
3117
		 /*
3143
		 /*
3118
		  * Read every raster band.
3144
		  * Read every raster band.
3119
		  *
3145
		  *
Line 3766... Line 3792...
3766
	else
3792
	else
3767
	   paint.setPen(QPen(barcol, 1, Qt::SolidLine));
3793
	   paint.setPen(QPen(barcol, 1, Qt::SolidLine));
3768
 
3794
 
3769
	// Information on left side
3795
	// Information on left side
3770
	if (cuType == 0)
3796
	if (cuType == 0)
3771
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Elevation (ft)" : "Elevation (m)"));
3797
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
3772
	else if (cuType == 1)
3798
	else if (cuType == 1)
3773
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Speed (mph)" : "Speed (km/h)"));
3799
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
3774
	else
3800
	else
3775
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Elevation (ft)" : "Elevation (m)"));
3801
	   paint.drawText((height + 4) * -1, 3, height - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
3776
 
3802
 
3777
	if (cuType == 2)
3803
	if (cuType == 2)
3778
	   paint.setPen(QPen(red, 1, Qt::SolidLine));
3804
	   paint.setPen(QPen(red, 1, Qt::SolidLine));
3779
	else
3805
	else
3780
	   paint.setPen(QPen(blue, 1, Qt::SolidLine));
3806
	   paint.setPen(QPen(blue, 1, Qt::SolidLine));
3781
 
3807
 
3782
	// Information on right side
3808
	// Information on right side
3783
	if (cuType < 2)
3809
	if (cuType < 2)
3784
	   paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
3810
	   paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
3785
	else
3811
	else
3786
	   paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Speed (mph)" : "Speed (km/h)"));
3812
	   paint.drawText((height + 4) * -1, width - 1 - lineHeight, height - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
3787
 
3813
 
3788
	paint.restore();
3814
	paint.restore();
3789
	paint.setPen(QPen(mark, 1, Qt::SolidLine));
3815
	paint.setPen(QPen(mark, 1, Qt::SolidLine));
3790
	// Draw the time scale on the bottom of the graphic
3816
	// Draw the time scale on the bottom of the graphic
3791
	for (i = 0; (unsigned int)i < (max_time + ds.getPauseTime()); i++)
3817
	for (i = 0; (unsigned int)i < (max_time + ds.getPauseTime()); i++)
Line 4276... Line 4302...
4276
 
4302
 
4277
void sportwatcherWidget::showThreeCurve(int pw, int ph)
4303
void sportwatcherWidget::showThreeCurve(int pw, int ph)
4278
{
4304
{
4279
QPainter ptHR, ptElevation, ptSpeed;
4305
QPainter ptHR, ptElevation, ptSpeed;
4280
int width, height, wdHR, htHR, wdElev, htElev, wdSpeed, htSpeed;
4306
int width, height, wdHR, htHR, wdElev, htElev, wdSpeed, htSpeed;
4281
int i, secs, cuType;
4307
int i, secs;
4282
int lineHeight, margin_left, margin_right, margin_bottom;
4308
int lineHeight, margin_left, margin_right, margin_bottom;
4283
int x1, y1, x2, y2;		// Coordinates
4309
int x1, y1, x2, y2;		// Coordinates
4284
bool meterHR;
-
 
4285
double maxHeight, minHeight, maxSpeed, minSpeed;
4310
double maxHeight, minHeight, maxSpeed, minSpeed;
4286
int maxHr, minHr, rh, rhHR, rhElev, rhSpeed;
4311
int maxHr, minHr, rh, rhHR, rhElev, rhSpeed;
4287
POINT *point;
4312
POINT *point;
4288
RUN_NODE *rn;
4313
RUN_NODE *rn;
4289
LAP *lp;
4314
LAP *lp;
Line 4298... Line 4323...
4298
	   return;
4323
	   return;
4299
 
4324
 
4300
	if (!ActivePrint && (!DIRTY || curTab != 2))
4325
	if (!ActivePrint && (!DIRTY || curTab != 2))
4301
	   return;
4326
	   return;
4302
 
4327
 
-
 
4328
	w_tick = h_tick = 0.0;
-
 
4329
	rh = 0;
-
 
4330
	width = height = 0;
4303
	// Get the dimensions of the available draw area
4331
	// Get the dimensions of the available draw area
4304
	// First for heart rate
4332
	// First for heart rate
4305
	if (!ActivePrint)
4333
	if (!ActivePrint)
4306
	{
4334
	{
4307
	   wdHR = ui_sportwatcherWidgetBase.grHR->width() - 2;
4335
	   wdHR = ui_sportwatcherWidgetBase.grHR->width() - 2;
Line 4517... Line 4545...
4517
	ptSpeed.rotate(270);
4545
	ptSpeed.rotate(270);
4518
	ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
4546
	ptSpeed.setPen(QPen(red, 1, Qt::SolidLine));
4519
 
4547
 
4520
	// Information on right side
4548
	// Information on right side
4521
	ptHR.drawText((htHR + 4) * -1, wdHR - 1 - lineHeight, htHR - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
4549
	ptHR.drawText((htHR + 4) * -1, wdHR - 1 - lineHeight, htHR - 2, lineHeight, Qt::AlignCenter, i18n("Heart Rate (bpm)"));
4522
	ptElevation.drawText((htElev + 4) * -1, wdElev - 1 - lineHeight, htElev - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Elevation (ft)" : "Elevation (m)"));
4550
	ptElevation.drawText((htElev + 4) * -1, wdElev - 1 - lineHeight, htElev - 2, lineHeight, Qt::AlignCenter, i18n("Elevation (%1)").arg((Units == 1) ? "ft" : "m"));
4523
	ptSpeed.drawText((htSpeed + 4) * -1, wdSpeed - 1 - lineHeight, htSpeed - 2, lineHeight, Qt::AlignCenter, i18n((Units == 1) ? "Speed (mph)" : "Speed (km/h)"));
4551
	ptSpeed.drawText((htSpeed + 4) * -1, wdSpeed - 1 - lineHeight, htSpeed - 2, lineHeight, Qt::AlignCenter, i18n("Speed (%1)").arg((Units == 1) ? "mph" : "km/h"));
4524
 
4552
 
4525
	// restore to normal
4553
	// restore to normal
4526
	ptHR.restore();
4554
	ptHR.restore();
4527
	ptHR.setPen(QPen(mark, 1, Qt::SolidLine));
4555
	ptHR.setPen(QPen(mark, 1, Qt::SolidLine));
4528
 
4556
 
Line 4699... Line 4727...
4699
	int ay1, ay2, ay3, ay4, ay5;
4727
	int ay1, ay2, ay3, ay4, ay5;
4700
 
4728
 
4701
	   x1 = margin_left + 1;
4729
	   x1 = margin_left + 1;
4702
	   x2 = wdHR - margin_right - 1;
4730
	   x2 = wdHR - margin_right - 1;
4703
 
4731
 
4704
	   if (meterHR)
-
 
4705
	   {
-
 
4706
	      double hrscale = rh / (double)(maxHr - minHr);
-
 
4707
	      ay1 = (double)rh - (double)(lower1 - minHr) * hrscale;
-
 
4708
	      ay2 = (double)rh - (double)(lower2 - minHr) * hrscale;
-
 
4709
	      ay3 = (double)rh - (double)(lower3 - minHr) * hrscale;
-
 
4710
	      ay4 = (double)rh - (double)(upper3 - minHr) * hrscale;
-
 
4711
	      ay5 = (double)rh - (double)(avg_hr - minHr) * hrscale;
-
 
4712
	   }
-
 
4713
	   else
-
 
4714
	   {
-
 
4715
	      ay1 = (double)rh - (double)(lower1 - minHr) * htiHR;
4732
	   ay1 = (double)rh - (double)(lower1 - minHr) * htiHR;
4716
	      ay2 = (double)rh - (double)(lower2 - minHr) * htiHR;
4733
	   ay2 = (double)rh - (double)(lower2 - minHr) * htiHR;
4717
	      ay3 = (double)rh - (double)(lower3 - minHr) * htiHR;
4734
	   ay3 = (double)rh - (double)(lower3 - minHr) * htiHR;
4718
	      ay4 = (double)rh - (double)(upper3 - minHr) * htiHR;
4735
	   ay4 = (double)rh - (double)(upper3 - minHr) * htiHR;
4719
	      ay5 = (double)rh - (double)(avg_hr - minHr) * htiHR;
4736
	   ay5 = (double)rh - (double)(avg_hr - minHr) * htiHR;
4720
	   }
-
 
4721
 
4737
 
4722
	   ptHR.setPen(QPen(barcol2, 1, Qt::DashLine));	// color for limits
4738
	   ptHR.setPen(QPen(barcol2, 1, Qt::DashLine));	// color for limits
4723
 
4739
 
4724
	   if (lower1 > minHr && lower1 < maxHr)
4740
	   if (lower1 > minHr && lower1 < maxHr)
4725
	      ptHR.drawLine(x1, ay1, x2, ay1);
4741
	      ptHR.drawLine(x1, ay1, x2, ay1);
Line 4799... Line 4815...
4799
	   i++;
4815
	   i++;
4800
	}
4816
	}
4801
 
4817
 
4802
	avgHlast = avgHeight;
4818
	avgHlast = avgHeight;
4803
	// If wanted, even the lines
4819
	// If wanted, even the lines
4804
	if (Contour && hEc > 0 && cuType != 0)
4820
	if (Contour && hEc > 0)
4805
	{
4821
	{
4806
	double alt[100], avg, avg1, avg2, avg3, avg4;
4822
	double alt[100], avg, avg1, avg2, avg3, avg4;
4807
	int a, pos;
4823
	int a, pos;
4808
 
4824
 
4809
	   for (i = 0; i < (hEc + 100); i += 100)
4825
	   for (i = 0; i < (hEc + 100); i += 100)
Line 5855... Line 5871...
5855
	return true;
5871
	return true;
5856
}
5872
}
5857
 
5873
 
5858
#endif
5874
#endif
5859
 
5875
 
-
 
5876
#ifdef HAVE_GDAL
-
 
5877
void spwErrorHandler(CPLErr err, int num, const char *msg)
-
 
5878
{
-
 
5879
ERRMSG *akt;
-
 
5880
char et[32], hv0[4096];
-
 
5881
 
-
 
5882
	if (err == CE_None || !msg)
-
 
5883
	   return;
-
 
5884
 
-
 
5885
	if (err == CE_Fatal)
-
 
5886
	   std::cerr << "ERROR " << num << ": " << msg << endl;
-
 
5887
 
-
 
5888
	if (!firstError)
-
 
5889
	{
-
 
5890
	   firstError = new ERRMSG;
-
 
5891
	   memset (firstError, 0, sizeof(ERRMSG));
-
 
5892
	   akt = firstError;
-
 
5893
	}
-
 
5894
	else
-
 
5895
	{
-
 
5896
	   akt = firstError;
-
 
5897
 
-
 
5898
	   while (akt)
-
 
5899
	   {
-
 
5900
	      if (!akt->next)
-
 
5901
		 break;
-
 
5902
 
-
 
5903
	      akt = akt->next;
-
 
5904
	   }
-
 
5905
 
-
 
5906
	   akt->next = new ERRMSG;
-
 
5907
	   akt = akt->next;
-
 
5908
	   memset (akt, 0, sizeof(ERRMSG));
-
 
5909
	}
-
 
5910
 
-
 
5911
	switch (err)
-
 
5912
	{
-
 
5913
	   case CE_None: strcpy (et, "None"); break;
-
 
5914
	   case CE_Debug: strcpy (et, "DEBUG"); break;
-
 
5915
	   case CE_Warning: strcpy (et, "Warning"); break;
-
 
5916
	   case CE_Failure: strcpy (et, "Failure"); break;
-
 
5917
	   case CE_Fatal: strcpy (et, "Fatal"); break;
-
 
5918
	}
-
 
5919
 
-
 
5920
	memset(hv0, 0, sizeof(hv0));
-
 
5921
	strncpy (hv0, msg, 4000);
-
 
5922
	sprintf (akt->msg, "ERROR TYPE %s - %d: %s", et, num, hv0);
-
 
5923
}
-
 
5924
 
-
 
5925
void destroyErrors()
-
 
5926
{
-
 
5927
ERRMSG *akt;
-
 
5928
 
-
 
5929
	if (!firstError)
-
 
5930
	   return;
-
 
5931
 
-
 
5932
	akt = firstError;
-
 
5933
 
-
 
5934
	while (akt)
-
 
5935
	{
-
 
5936
	   firstError = akt->next;
-
 
5937
	   delete akt;
-
 
5938
	   akt = firstError;
-
 
5939
	}
-
 
5940
 
-
 
5941
	firstError = 0;
-
 
5942
}
-
 
5943
 
-
 
5944
QString catGDALError()
-
 
5945
{
-
 
5946
QString err;
-
 
5947
ERRMSG *akt = firstError;
-
 
5948
 
-
 
5949
	while (akt)
-
 
5950
	{
-
 
5951
	   err += QString(akt->msg) + "\n";
-
 
5952
	   akt = akt->next;
-
 
5953
	}
-
 
5954
 
-
 
5955
	destroyErrors();
-
 
5956
	return err;
-
 
5957
}
-
 
5958
#endif
-
 
5959
 
5860
#include "sportwatcherwidget.moc"
5960
#include "sportwatcherwidget.moc"
5861
 
5961